canvas.drawImage(gfx[this.info.image], f[0], f[1], f[2], f[3],
this.position[0] - f[4], this.position[1] - f[5],
f[2], f[3]);
-
}
+
+ this.block = function() { this.animate("block" ); return this; };
+ this.cast = function() { this.animate("cast" ); return this; };
+ this.die = function() { this.animate("die" ); return this; };
+ this.hit = function() { this.animate("hit" ); return this; };
+ this.run = function() { this.animate("run" ); return this; };
+ this.shoot = function() { this.animate("shoot" ); return this; };
+ this.stance = function() { this.animate("stance"); return this; };
+ this.swing = function() { this.animate("swing" ); return this; };
}
function Hero(gender = "female", hair = "short"){
this.position = [0,0]; this.direction = 0;
+ this.hair = (gender == "female")?"long":hair;
+ this.animation = "stance";
if (! gamedata["/engine/hero_layers.txt"])
gamedata["/engine/hero_layers.txt"] = new Textfile("/engine/hero_layers.txt");
this.limbs = {
- head : (gender == "female")?new Mob("/animations/avatar/female/head_long.txt")
- :new Mob("/animations/avatar/male/head_"+hair+".txt"),
+ head: new Mob("/animations/avatar/"+gender+"/head_"+this.hair+".txt"),
chest: new Mob("/animations/avatar/"+gender+"/default_chest.txt"),
hands: new Mob("/animations/avatar/"+gender+"/default_hands.txt"),
legs : new Mob("/animations/avatar/"+gender+"/default_legs.txt"),
off : new Mob("/animations/avatar/"+gender+"/shield.txt")
}
+ this.dress = function(limb, item) {
+ this.limbs[limb] = new Mob("/animations/avatar/"+gender+"/"+item+".txt")
+ this.limbs[limb].place(this.position[0], this.position[1]).direct(this.direction);
+ this.animate(this.animation);
+ return this;
+ }
+
this.place = function(x,y) {
this.position = [x,y];
for (var limb in this.limbs) this.limbs[limb].place(x,y);
return this;
}
this.animate = function(anim){
+ this.animation = anim;
for (var limb in this.limbs) this.limbs[limb].animate(anim);
return this;
}
gamedata["/engine/hero_layers.txt"].layer[this.direction].forEach(limb => this.limbs[limb].draw());
return this;
}
+
+ this.block = function() { this.animate("block" ); return this; };
+ this.cast = function() { this.animate("cast" ); return this; };
+ this.die = function() { this.animate("die" ); return this; };
+ this.hit = function() { this.animate("hit" ); return this; };
+ this.run = function() { this.animate("run" ); return this; };
+ this.shoot = function() { this.animate("shoot" ); return this; };
+ this.stance = function() { this.animate("stance"); return this; };
+ this.swing = function() { this.animate("swing" ); return this; };
}
canvas = document.getElementById("view").getContext("2d");
player = new Hero().place(240, 160).direct(5);
-setInterval( function() { canvas.clearRect(0,0, 480, 320); player.draw(); }, 50);
+setInterval( function() { canvas.clearRect(0,0, 480, 320); player.draw(); }, 33.33);