Spel6: Flight Simulator Easy

Boeing737_flightsimulator_129                                                  Boeing 737 flight simulator.

Vi programmerar en första flight simulator där flygplanet styrs av via horisontell kraft)  Fx och vertikal kraft Fy som styrs via två parameter-slides på skärmen genom uppdatering av Newton’s rörelseekvationer

  • x = x + vx*dt
  • y = y + vy*dt
  • vx = vx + ax*dt
  • vy = vy + ay*dt
  • ax = Fx
  • ay = Fy.

Template 1: (Följ pilotens ändring kraften från jetmotorn)

function setup()

parameter.number(“vx”, -100, 100, 0)
parameter.number(“vy”, -100, 100, 0)
parameter.number(“Fx”, -100, 100, 0)
parameter.number(“Fy”, -100, 100, 0)
dt = 0.01
x=WIDTH/2
y=HEIGHT/2
ax=0
ay=0

end

function draw()

background(40, 40, 50)

ax=Fx
ay=Fy
vx=vx+ax*dt
vy=vy+ay*dt
x=x+vx*dt
y=y+vy*dt

sprite(“SpaceCute:Beetle Ship”,x,y,50)

stroke(251, 255, 0, 255)
strokeWidth(5)
strokeWidth(10)
line(x,y,x-ax,y-ay)
end

function touched(touch)

if touch.state == ENDED then
x = touch.x
y= touch.y
end

end

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s