-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
63 lines (55 loc) · 1.92 KB
/
game.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
"""This file contains the main game class"""
import pygame as pg
from env import Env
pg.init()
class Game():
"""This is the main game class"""
def __init__(self, args):
"""Constructor"""
self.args = args
self.set_up_pylint()
self.env = Env(args)
# TODO: Add paused, adding <06-11-19, astadnik> #
self.reset_params()
self.paused = False
self.standart_obs_added = True
self.env.add_standart_obstackles()
def set_up_pylint(self):
"""Set up everything that is needed for pylint"""
self.fps = 60
self.clock = pg.time.Clock()
pg.display.set_caption("Smart Rockets")
self.screen = pg.display.set_mode((700, 700))
def reset_params(self):
self.paused = True
self.adding = False
self.standart_obs_added = False
def run(self):
"""Combine everything together"""
while True:
self.screen.fill(pg.Color('darkturquoise'))
if not self.paused:
self.env.update()
self.env.draw()
if self.handle_input():
return
pg.display.flip()
self.clock.tick(self.fps)
def handle_input(self):
"""Handles input"""
# TODO: Add more controls <06-11-19, astadnik> #
for event in pg.event.get():
if event.type == pg.QUIT:
return True
if event.type == pg.KEYDOWN:
if event.key == pg.K_q:
return True
if event.key == pg.K_p:
self.paused = not self.paused
if event.key == pg.K_s and not self.standart_obs_added:
self.standart_obs_added = True
self.env.add_standart_obstackles()
if event.key == pg.K_r:
self.reset_params()
self.env = Env(self.args)
return False