From: Paul Hänsch Date: Sat, 8 Feb 2020 03:06:20 +0000 (+0100) Subject: shortcut functions for animation and dressing X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=d71e8fb344ed2b3eb6db94e0df3d4b294904104c;p=flarejs shortcut functions for animation and dressing --- diff --git a/engine.js b/engine.js index 3bdf87b..5f2c209 100644 --- a/engine.js +++ b/engine.js @@ -93,18 +93,27 @@ function Mob(textdef) { 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"), @@ -113,6 +122,13 @@ function Hero(gender = "female", hair = "short"){ 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); @@ -124,6 +140,7 @@ function Hero(gender = "female", hair = "short"){ return this; } this.animate = function(anim){ + this.animation = anim; for (var limb in this.limbs) this.limbs[limb].animate(anim); return this; } @@ -131,9 +148,18 @@ function Hero(gender = "female", hair = "short"){ 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);