-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlander.py
66 lines (55 loc) · 1.79 KB
/
lander.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pygame
import math
class Lander:
width = 40
height = 60
landerColor = (0, 255, 255)
thrustColor = (255, 255, 0)
gravity = 25
def __init__(self, screen, x, y):
self.screen = screen
self.x = x
self.y = y
self.vx = 0
self.vy = 0
self.tx = 0
self.ty = 0
self.clock = pygame.time.Clock()
def setThrustX(self, tx):
self.tx = tx
def setThrustY(self, ty):
self.ty = ty
def getVelocity(self):
return math.hypot(self.vx, self.vy)
def update(self):
dt = 0.001 * self.clock.tick()
self.vx += self.tx * dt * 50
self.vy += self.ty * dt * 50
self.vy += self.gravity * dt
self.x += self.vx * dt
self.y += self.vy * dt
pass
def draw(self):
rect = (self.x - self.width / 2, self.y, self.width, -self.height)
pygame.draw.rect(self.screen, self.landerColor, rect, 0)
if(self.tx < 0):
triangle = [
(self.x + 20, self.y - 20),
(self.x + 30, self.y - 15),
(self.x + 20, self.y - 10),
]
pygame.draw.polygon(self.screen, self.thrustColor, triangle)
elif(self.tx > 0):
triangle = [
(self.x - 20, self.y - 20),
(self.x - 30, self.y - 15),
(self.x - 20, self.y - 10),
]
pygame.draw.polygon(self.screen, self.thrustColor, triangle)
if(self.ty < 0):
triangle = [
(self.x - 10, self.y),
(self.x, self.y + 20),
(self.x + 10, self.y),
]
pygame.draw.polygon(self.screen, self.thrustColor, triangle)