Skip to content

Commit 2bfb807

Browse files
author
Aaron Titus
committed
updated lunar lander
1 parent dae7663 commit 2bfb807

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

asteroids/.DS_Store

6 KB
Binary file not shown.

lunarLander/lunarLander.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def getData():
3131

3232
time.sleep(2)
3333

34-
scene.width=700
35-
scene.height=700
34+
scene.width=1300
35+
scene.height=1000
3636
scene.range=20
3737

3838
ground = box(pos=vector(0,-10.05,0), size=(40.0,1,1), color=color.white)
@@ -52,7 +52,11 @@ def getData():
5252
FgravArrow = arrow(pos=spaceship.pos, axis=scale*spaceship.m*g, color=color.red)
5353
FthrustArrow = arrow(pos=spaceship.pos, axis=Fthrust, color=color.cyan)
5454

55+
safespeed=2
56+
5557
voltage=[]
58+
scene.waitfor('click')
59+
5660

5761
while 1:
5862
rate(100)
@@ -65,8 +69,22 @@ def getData():
6569
spaceship.v = spaceship.v + (Fnet/spaceship.m)*dt
6670
spaceship.pos = spaceship.pos + spaceship.v*dt
6771
if(spaceship.pos.y-spaceship.height/2<ground.pos.y+ground.height/2):
68-
print("spaceship has landed, v= ", mag(spaceship.v))
69-
break
72+
print("spaceship has landed, v= ",spaceship.v, "speed= ", mag(spaceship.v))
73+
if(spaceship.pos.x>target.pos.x-target.size.x/2 and spaceship.pos.x<target.pos.x+target.size.x/2 and mag(spaceship.v)<safespeed and abs(spaceship.v.x)<0.5):
74+
message=label(pos=vector(0,0,0), text="You Win! The spaceship landed safely!")
75+
else:
76+
message=label(pos=vector(0,0,0), text="The spaceship crashed! Bummer!")
77+
if(abs(spaceship.v.x)>1):
78+
message.text=message.text+"\nYour lateral landing speed was too large."
79+
elif(mag(spaceship.v)>safespeed):
80+
message.text=message.text+"\nYour landing speed was too large."
81+
scene.waitfor('click')
82+
message.visible=0
83+
spaceship.v = vector(0,0,0)
84+
spaceship.pos=vector(-10,8,0)
85+
Fthrust=vector(0,0,0)
86+
F=vector(0,0,0)
87+
t=0
7088
t = t+dt
7189
FgravArrow.pos=spaceship.pos
7290
FgravArrow.axis=scale*Fgrav

0 commit comments

Comments
 (0)