-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_api.py
67 lines (48 loc) · 1.57 KB
/
game_api.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
import sys
import flask
import pygame
from core.utils.game import Game
def dino_vs_robots() -> None:
"""This function executes the game."""
screen_width = 600
screen_height = 600
dinosaur_shooting_timer = 800
number_of_dinosaur_rows = 3
number_of_dinosaur_cols = 4
obstacle_amount = 4
moving_dinosaurs = False
pygame.init()
screen = pygame.display.set_mode((screen_width, screen_height))
clock = pygame.time.Clock()
game = Game(
screen=screen,
screen_width=screen_width,
screen_height=screen_height,
number_of_dinosaur_rows=number_of_dinosaur_rows,
number_of_dinosaur_cols=number_of_dinosaur_cols,
obstacle_amount=obstacle_amount,
moving_dinosaurs=moving_dinosaurs,
)
DINOSAURLASER = pygame.USEREVENT + 1
pygame.time.set_timer(DINOSAURLASER, dinosaur_shooting_timer)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
break
if event.type == DINOSAURLASER:
game.dinosaur_shoot()
screen.fill((30, 30, 30))
game.run()
print(f"Final Score:{game.score}")
pygame.display.flip()
clock.tick(60)
flask_app = flask.Flask(__name__)
@flask_app.route("/")
def api_start() -> None:
"""This function starts the game API."""
print("WELCOME TO ROBOTS VS DINOSAURS game!")
dino_vs_robots()
if __name__ == "__main__":
flask_app.run(host="0.0.0.0", port=3000, debug=True, use_reloader=False)