forked from sd18spring/InteractiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (50 loc) · 1.74 KB
/
main.py
File metadata and controls
51 lines (50 loc) · 1.74 KB
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
import GameView
import model
import pygame
from pygame.locals import *
import time
if __name__ == "__main__":
model = model.Model()
view = GameView.GameView(model, (1000,1000))
running = True
left, up, down, right = False, False, False, False
while running:
for event in pygame.event.get():
if event.type == QUIT:
running = False
time.sleep(.001)
view.draw()
if event.type == KEYDOWN:
if event.key == pygame.K_LEFT:
left = True
if event.key == pygame.K_RIGHT:
right = True
if event.key == pygame.K_UP:
up = True
if event.key == pygame.K_DOWN:
down = True
if event.type == KEYUP:
if event.key == pygame.K_LEFT:
left = False
if event.key == pygame.K_RIGHT:
right = False
if event.key == pygame.K_UP:
up = False
if event.key == pygame.K_DOWN:
down = False
if(left):
model.char.accelerate(-1)
if(right):
model.char.accelerate(1)
if(right == False and left == False):
if(model.char.vel_x > 0):
model.char.accelerate(-1)
if(model.char.vel_x < 0):
model.char.vel_x = 0
elif(model.char.vel_x < 0):
model.char.accelerate(1)
if(model.char.vel_x < 0):
model.char.vel_x = 0
print(model.char.vel_x)
model.char.move()
pygame.quit