mirror of
https://github.com/danbulant/bobek
synced 2026-06-15 04:21:02 +00:00
update method
This commit is contained in:
parent
858339515a
commit
a73e672ea9
3 changed files with 23 additions and 9 deletions
32
game.js
32
game.js
|
|
@ -2,16 +2,25 @@
|
|||
const sctx = scrn.getContext("2d");
|
||||
sctx.fillStyle = "#30c0df";
|
||||
let frames = 0;
|
||||
const gnd = {
|
||||
sprite : new Image(),
|
||||
const gnd = {
|
||||
animations :
|
||||
[
|
||||
{sprite : new Image()},
|
||||
{sprite : new Image()},
|
||||
],
|
||||
x : 0,
|
||||
y :0,
|
||||
frame : 0,
|
||||
draw : function() {
|
||||
y = parseFloat(scrn.height-this.sprite.height);
|
||||
sctx.drawImage(this.sprite,this.x,y);
|
||||
y = parseFloat(scrn.height-this.animations[this.frame].sprite.height);
|
||||
sctx.drawImage(this.animations[this.frame].sprite,this.x,y);
|
||||
},
|
||||
update : function(){
|
||||
this.frame += (frames%10==0) ? 1 : 0;
|
||||
this.frame = this.frame%this.animations.length;
|
||||
}
|
||||
};
|
||||
const bg = {
|
||||
const bg = {
|
||||
sprite : new Image(),
|
||||
x : 0,
|
||||
y :0,
|
||||
|
|
@ -43,11 +52,17 @@ const bird = {
|
|||
frame:0,
|
||||
draw : function() {
|
||||
sctx.drawImage(this.animations[this.frame].sprite,this.x,this.y);
|
||||
},
|
||||
update : function() {
|
||||
this.frame += (frames%10==0) ? 1 : 0;
|
||||
this.frame = this.frame%this.animations.length;
|
||||
this.y += (frames%10==0) ? (Math.random()-0.5)*2 : 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
gnd.sprite.src="img/ground.png";
|
||||
gnd.animations[0].sprite.src="img/ground/g0.png";
|
||||
gnd.animations[1].sprite.src="img/ground/g1.png";
|
||||
bg.sprite.src="img/BG.png";
|
||||
gr.sprite.src="img/getready.png";
|
||||
bird.animations[0].sprite.src="img/bird/b0.png";
|
||||
|
|
@ -68,9 +83,8 @@ gameLoop();
|
|||
|
||||
function update()
|
||||
{
|
||||
bird.frame += (frames%5==0) ? 1 : 0;
|
||||
bird.frame = bird.frame%4;
|
||||
bird.y += (frames%5==0) ? (Math.random()-0.5)*2 : 0;
|
||||
bird.update();
|
||||
gnd.update();
|
||||
}
|
||||
function draw()
|
||||
{
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
BIN
img/ground/g1.png
Normal file
BIN
img/ground/g1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Loading…
Reference in a new issue