gnd animation updated

This commit is contained in:
Darkin 2019-10-19 13:10:00 +02:00
parent 73ba70e25b
commit dbb6ff2aa8
2 changed files with 8 additions and 13 deletions

21
game.js
View file

@ -1,4 +1,5 @@
const RAD = Math.PI/180; const RAD = Math.PI/180;
const dx = 2;
const scrn = document.getElementById('canvas'); const scrn = document.getElementById('canvas');
const sctx = scrn.getContext("2d"); const sctx = scrn.getContext("2d");
scrn.addEventListener("click",()=>{ scrn.addEventListener("click",()=>{
@ -25,32 +26,27 @@
} }
const gnd = { const gnd = {
animations : sprite : new Image(),
[
{sprite : new Image()},
{sprite : new Image()},
],
x : 0, x : 0,
y :0, y :0,
frame : 0,
draw : function() { draw : function() {
this.y = parseFloat(scrn.height-this.animations[this.frame].sprite.height); this.y = parseFloat(scrn.height-this.sprite.height);
sctx.drawImage(this.animations[this.frame].sprite,this.x,this.y); sctx.drawImage(this.sprite,this.x,this.y);
}, },
update : function() { update : function() {
switch (state.curr) { switch (state.curr) {
case state.getReady : case state.getReady :
this.frame += (frames%10==0) ? 1 : 0; this.x -= dx/2;
break; break;
case state.Play : case state.Play :
this.frame += (frames%5==0) ? 1 : 0; this.x -= dx
break; break;
case state.gameOver : case state.gameOver :
this.frame = 0; this.frame = 0;
break; break;
} }
this.frame = this.frame%this.animations.length; this.x = this.x % (this.sprite.width/2);
} }
}; };
const bg = { const bg = {
@ -146,8 +142,7 @@
}; };
gnd.animations[0].sprite.src="img/ground/g0.png"; gnd.sprite.src="img/ground.png";
gnd.animations[1].sprite.src="img/ground/g1.png";
bg.sprite.src="img/BG.png"; bg.sprite.src="img/BG.png";
UI.getReady.sprite.src="img/getready.png"; UI.getReady.sprite.src="img/getready.png";
UI.gameOver.sprite.src="img/gameOver.png"; UI.gameOver.sprite.src="img/gameOver.png";

BIN
img/ground.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB