-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcharacters.js
68 lines (59 loc) · 1.72 KB
/
characters.js
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
Character.equipSlots = [
"bag",
"right-hand",
"left-hand",
"head",
"neck",
"body",
"legs",
"feet",
];
Character.copy = function copy(to, from) {
for(var prop in from) {
if(from[prop] instanceof Object && !Array.isArray(from[prop])) {
to[prop] = {};
copy(to[prop], from[prop]);
} else {
to[prop] = from[prop];
}
}
};
Character.sync = function(data, remove) {
remove && remove.forEach(game.removeCharacterById);
for (var id in data) {
var from = data[id];
var to = game.entities.get(id);
if(!to) {
to = new Character(id, from.Name);
game.addCharacter(to);
if(from.Name == game.login)
game.player = to;
to.init(from)
} else {
to.sync(from);
}
game.map.updateObject(to);
}
game.player.updateEffects();
};
Character.drawActions = function() {
for(var name in game.characters) {
game.characters[name].drawAction();
}
};
Character.spriteDir = "characters/";
Character.animations = ["idle", "run", "dig", "craft", "attack", "sit"];
Character.parts = ["feet", "legs", "body", "head"];
Character.nakedSprites = {};
Character.weaponSprites = {}
Character.initSprites = function() {
Character.animations.forEach(function(animation) {
var path = Character.spriteDir + "/man/" + animation + "/naked.png";
var sprite = new Sprite(path);
Character.nakedSprites[animation] = sprite;
});
["sword"].forEach(function(weapon) {
var sprite = new Sprite(Character.spriteDir + "/man/weapon/" + weapon + ".png");
Character.weaponSprites[weapon] = sprite;
})
};