xxxxxxxxxx
60
x = 0;
y = 250;
vx = 25;
vy = 0;
deltaVx = 0;
deltaVy = 0;
theta = 0;
Fthrust = 30.0;
mass = 3.0;
dt = 0.1;
function draw() {
// Update velocities
vx += deltaVx;
vy += deltaVy;
// Update location
x += vx * dt;
y += vy * dt;
// velocity is unchanged if there are no forces
deltaVx = 0;
deltaVy = 0;
// Turn or thrust the ship depending on what key is pressed
if (keyIsDown(LEFT_ARROW)) {
theta += 0.1;
}
if (keyIsDown(RIGHT_ARROW)) {
theta -= 0.1;
}
if (keyIsDown(UP_ARROW)) {
// Rockets on!
accelx = Fthrust * cos(theta) / mass;
deltaVx = accelx * dt;
accely = Fthrust * sin(theta) / mass;
deltaVy = accely * dt;
}
if (keyIsDown(DOWN_ARROW)) {
accelx = -Fthrust * cos(theta) / mass;
deltaVx = accelx * dt;
accely = -Fthrust * sin(theta) / mass;
deltaVy = accely * dt;
}
if (keyIsPressed && key == ' ') { //spacebar
// Do nothing!
}
// Draw ship and other stuff
// This will clear the screen and re-draw it
display();
// Add more graphics here before the end of draw()
for (i = 0; i < xhistory.length; i += 1) {
drawPoint(xhistory[i], yhistory[i]);
}
} // end draw()