X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=engine.js;h=c769ccab2a3a9acdb9d333bf80cdf93a17021cec;hb=21be08a919cb5df4a62a4b480e17683a2d23187f;hp=c83911cbbcfc9e99229a15421794ede8ac1d34d7;hpb=58ce9fb28cd30838ff0d7ea75860223c683ae8e4;p=flarejs diff --git a/engine.js b/engine.js index c83911c..c769cca 100644 --- a/engine.js +++ b/engine.js @@ -7,12 +7,13 @@ function Mob(textdef) { this.frametime = performance.now(); this.image = document.querySelector("img[src='"+ this.info.image +"']"); - this.place = function(x, y) { this.position = [x, y]; } - this.direct = function(d) { this.direction = d % 8; } + this.place = function(x, y) { this.position = [x, y]; return this; } + this.direct = function(d) { this.direction = d % 8; return this; } this.animate = function(a) { this.previous_animation = this.animation; this.animation = a; this.frametime = performance.now(); + return this; } this.draw = function(){ @@ -42,7 +43,6 @@ function Mob(textdef) { } f = a.frames[frame][this.direction]; - canvas.clearRect(0,0, 640, 480); canvas.drawImage(this.image, f[0], f[1], f[2], f[3], this.position[0] - f[4], this.position[1] - f[5], f[2], f[3]); @@ -53,8 +53,40 @@ function Mob(textdef) { } } +function Player(gender = "female", hair = "short"){ + this.x=0; this.y=0; this.direction=0; + this.limbs = { + head : (gender == "female")?new Mob("/animations/avatar/female/head_long.txt"):new Mob("/animations/avatar/male/head_"+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"), + feet : new Mob("/animations/avatar/"+gender+"/default_feet.txt"), + main : new Mob("/animations/avatar/"+gender+"/club.txt"), + off : new Mob("/animations/avatar/"+gender+"/shield.txt") + } + + this.place = function(x,y) { + this.x = x; this.y = y; + for (var limb in this.limbs) this.limbs[limb].place(x,y); + return this; + } + this.direct = function(d) { + this.direction = d; + for (var limb in this.limbs) this.limbs[limb].direct(d); + return this; + } + this.animate = function(anim){ + for (var limb in this.limbs) this.limbs[limb].animate(anim); + return this; + } + this.draw = function(){ + gamedata["/engine/hero_layers.txt"].layers[this.direction].forEach(limb => this.limbs[limb].draw()); + return this; + } +} + canvas = document.getElementById("view").getContext("2d"); -player = new Mob("/animations/avatar/male/clothes.txt"); -player.place(320, 240); +// player = new Mob("/animations/avatar/male/clothes.txt"); +player = new Player().place(240, 160).direct(5); -setInterval( function() { player.draw(); }, 33); +setInterval( function() { canvas.clearRect(0,0, 480, 320); player.draw(); }, 50);