xxxxxxxxxx
59
x = 375;
y = 250;
vx = 0;
vy = 0;
v0x = 20; // launch velocity
v0y = 10;
ax = 0;
ay = 0;
g = -1.63;
mass = 3.0;
dt = 0.1;
function draw(){
// Update velocity
vx += ax*dt;
vy += ay*dt;
// Update location
x += vx*dt;
y += vy*dt;
// Check if arrow keys are pressed
if (keyIsDown(LEFT_ARROW)) {
v0x += -1.0;
}
if (keyIsDown(RIGHT_ARROW)) {
v0x += 1.0;
}
if (keyIsDown(UP_ARROW)) {
v0y += 1.0;
}
if (keyIsDown(DOWN_ARROW)) {
v0y += -1.0;
}
Fnety = mass*g;
ay = Fnety/mass;
// Draw axes and other stuff
// This will clear the screen and re-draw it
display();
drawBird(x,y,vx,vy,ax,ay);
drawForce(x,y,0,mass*g);
if (y < 0) {
drawText('Game Over!',0.45*width,height/2);
exit();
}
// Add more graphics here before the end of draw()
} // end draw() DO NOT ADD ANYTHING AFTER THIS LINE!!!