-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
134 lines (104 loc) · 3.6 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import sys
import pygame
import pymunk
from pymunk import Vec2d
import pymunk.pygame_util
from frame import Frame
from map import Camera, Map
class Game:
def __init__(self):
pygame.init()
self.size = width, height = [1024,567]
self.screen = pygame.display.set_mode(self.size)
self.clock = pygame.time.Clock()
self.space = pymunk.Space()
self.space.gravity = Vec2d(0.0, 0.0)
self.map = Map("map01", self.space)
self.camera = Camera(self.map.borderWidth,self.map.borderHeight)
self.world = self.map.world
testFrame = Frame(self.space)
testFrame.addFrame(self.world)
self.options = pymunk.pygame_util.DrawOptions(self.world)
self.space.debug_draw(self.options)
moveForward = False
moveBack = False
moveUp = False
moveDown = False
rotateRight = False
rotateLeft = False
while True:
for event in pygame.event.get():
# print(event.type)
# testFrame.addForwardForce()
if event.type == pygame.QUIT:
sys.exit(0)
elif event.type == pygame.KEYDOWN:
print(event.key)
if event.key == pygame.K_ESCAPE:
sys.exit(0)
elif event.key == pygame.K_d:
moveForward = True
elif event.key == pygame.K_a:
moveBack = True
elif event.key == pygame.K_w:
moveUp = True
elif event.key == pygame.K_s:
moveDown = True
elif event.key == pygame.K_e:
rotateRight = True
elif event.key == pygame.K_q:
rotateLeft = True
elif event.type == pygame.KEYUP:
if event.key == pygame.K_d:
moveForward = False
elif event.key == pygame.K_a:
moveBack = False
elif event.key == pygame.K_w:
moveUp = False
elif event.key == pygame.K_s:
moveDown = False
elif event.key == pygame.K_e:
rotateRight = False
elif event.key == pygame.K_q:
rotateLeft = False
output = Vec2d()
if moveForward == True:
output = testFrame.addForwardForce()
pos = pymunk.pygame_util.to_pygame(testFrame.mainBody.position , self.world)
end = [pos[0]+output.x,pos[0]-output.y]
pygame.draw.lines(self.screen, [255,255,255], False, [pos,end], 1)
if moveBack == True:
output = testFrame.addBackForce()
pos = pymunk.pygame_util.to_pygame(testFrame.mainBody.position , self.world)
end = [pos[0]+output.x,pos[0]-output.y]
pygame.draw.lines(self.screen, [255,255,255], False, [pos,end], 1)
if moveUp == True:
output = testFrame.addUpForce()
pos = pymunk.pygame_util.to_pygame(testFrame.mainBody.position , self.world)
end = [pos[0]+output.x,pos[0]-output.y]
pygame.draw.lines(self.screen, [255,255,255], False, [pos,end], 1)
if moveDown == True:
output = testFrame.addDownForce()
pos = pymunk.pygame_util.to_pygame(testFrame.mainBody.position , self.world)
end = [pos[0]+output.x,pos[0]-output.y]
pygame.draw.lines(self.screen, [255,255,255], False, [pos,end], 1)
if rotateRight == True:
testFrame.rotateRight()
if rotateLeft == True:
testFrame.rotateLeft()
#If not actively moving begin slowing down
if not( moveForward or moveBack or moveUp or moveDown or rotateLeft or rotateRight ):
testFrame.applyDamping()
self.world.fill((0,0,0))
self.map.updateBackground(self.world)
#draw everything in the world
# self.space.debug_draw(self.options)
testFrame.draw(self.world)
self.camera.update(self.world, self.screen, testFrame.getRect(self.world,self.size))
# worldOutput = self.world.subsurface(testFrame.getRect(self.world,self.size))
# self.screen.blit(worldOutput, (0,0) )
self.space.step(1/50.0)
pygame.display.flip()
self.clock.tick(50)
if __name__ == '__main__':
game = Game()