trimill.xyz/flaskr/templates/projects/flappy/bird.js

31 lines
719 B
JavaScript
Raw Normal View History

2022-06-23 05:58:54 +00:00
function Bird() {
this.width = birdHitboxSize;
this.height = birdHitboxSize;
this.iconwidth = birdDrawSize;
this.iconheight = birdDrawSize;
this.pos = height/2-this.height/2;
this.vel = 0;
this.acc = initialAcceleration;
this.xpos = birdXPosition;
this.show = function() {
image(birdImage, this.xpos, this.pos, this.iconwidth, this.iconheight);
}
this.update = function() {
this.vel += this.acc;
this.vel = constrain(this.vel, -termVel, termVel);
this.pos += this.vel;
this.acc = 0;
}
this.applyForce = function(force, type) {
if(type === 'flap' && cancelVelocity == 1) {
this.vel = 0;
this.acc = force;
} else {
this.acc += force;
}
}
}