-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_driver.py
60 lines (49 loc) · 1.69 KB
/
player_driver.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
import traceback
import client
import pygame
from pygame.locals import *
import settings
import car as c
import camera as cam
def game_loop(client, game_map):
clock = pygame.time.Clock()
WIN_WIDTH = settings.screen_width
WIN_HEIGHT = settings.screen_height
pygame.display.init()
screen = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
car = c.Car(settings.car_x, settings.car_y)
camera = cam.Camera(WIN_WIDTH, WIN_HEIGHT)
game_map.scale(4)
car.scale(2)
entities = pygame.sprite.Group()
entities.add(game_map)
entities.add(car)
running = True
update = 0
while (running):
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if not hasattr(event,'key'): continue
down = event.type == KEYDOWN
#CHANGE THESE SCALARS TO CHANGE ACCELERATIONS AND ROTATION SPEED
if event.key==K_RIGHT: car.updateRight(down * -2)
elif event.key==K_LEFT: car.updateLeft(down * 2)
elif event.key==K_UP: car.updateUp(down * 0.5)
elif event.key==K_DOWN: car.updateDown(down * -0.3)
car.drive(game_map)
client.send_metrics(car.x, car.y, car.direction)
print("X: " + str(car.x) + " Y: " + str(car.y) + " Direction: " + str(car.direction))
camera.update(car)
#Draw the images (KEEP SCREEN INFRONT OF ANYTHING DRAWN ON TOP)
screen.fill((90,90,90))
for e in entities:
e.draw(screen, camera)
pygame.display.update()
pygame.quit()
if __name__ == "__main__":
try:
client.run(game_loop)
except:
traceback.print_exc()