<script src="http://spelprogrammering.nu/simple.js">
function start()
{
icbm = {sx: 0,
sy: 0,
v0: 100,
alpha: pi/4};
world = {g: -9.8,
t: 0};
icbm.v0x = icbm.v0 * cos(icbm.alpha);
icbm.v0y = icbm.v0 * sin(icbm.alpha);
}
function update()
{
world.t += 0.1;
var prevX = icbm.sx;
var prevY = icbm.sy;
icbm.sy = totalHeight-(icbm.v0y*world.t + world.g*world.t*world.t/2);
icbm.sx = icbm.v0x*world.t;
var angle = atan((icbm.sy-prevY) / (icbm.sx-prevX)) * 180/pi;
clearScreen();
save();
translate(icbm.sx, icbm.sy);
rotate(angle);
rectangle(0, 0, 40, 20, "silver");
triangle(40, 0, 40, 20, 50, 10, "red");
restore();
}
</script>
Gå tillbaka