Repository navigation
Expand file tree
/
Copy pathplayer.js
More file actions
110 lines (91 loc) · 2.23 KB
/
Copy pathplayer.js
File metadata and controls
110 lines (91 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var px = 0
var py = 0
var itemID = 0
var bagCapacity = 10
var curBagCapacity = 0
var storageState = "closed"
var playerMoney = 20
var inventoryState = "open"
playerStats = {
"px":px,
"py":py,
"hp":20,
"maxhp":20,
"str":1,
"def":3,
"spd":2,
"chr":0,
"pwr":5
}
playerEquipmentStats = {
"str":0,
"def":0,
"spd":0,
"chr":0,
}
playerEquipment = {
"hat":null,
"hand":null,
"torso":null,
"pants":null,
"shoes":null
}
function updateMoney(){
let span = document.getElementById("playermoney")
span.innerHTML = playerMoney
}
updateMoney()
//write code to take stats from the dictionary and place them onto the html elements
function updateStats(){
/** Must call this function to update the display whenever the player's stats change */
for(var key in playerStats){
if (key =="px" || key == "py"){
continue
}
if(playerStats.hasOwnProperty(key)){
if (key == "hp"){
let e = document.getElementById(key)
e.innerText = `${playerStats["hp"]} / ${playerStats["maxhp"]}`
}else if (key == "pwr" || key == "maxhp"){
continue
}else{
let e = document.getElementById(key)
e.innerText = playerStats[key] + playerEquipmentStats[key]
}
}
}
}
updateStats()
var inventory = [] // ["i0", "i1"..]
var chestinventory = [] // ["i0", "i1"..]
function modifyWeight(itemString, symbol) {
/**
* This function is responsible for changing the weight
* capacity and updating the graphics
*/
console.log(itemString, symbol)
if (symbol == "-"){
curBagCapacity -= ITEM_WEIGHTS[itemString]
}else{
curBagCapacity += ITEM_WEIGHTS[itemString]
}
let weightbar = document.getElementById("inventory-weight")
weightbar.style.width = (curBagCapacity/bagCapacity)*100 +"%"
if(curBagCapacity == bagCapacity){
weightbar.style.backgroundColor = "darkred"
}else{
weightbar.style.backgroundColor = "gray"
}
}
function modifyStats(itemString, symbol) {
if (symbol == "-"){
for (let stat in ITEM_STATS[itemString]){
playerEquipmentStats[stat] -= ITEM_STATS[itemString][stat]
}
}else{
for (let stat in ITEM_STATS[itemString]){
playerEquipmentStats[stat] += ITEM_STATS[itemString][stat]
}
}
updateStats()
}