-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (47 loc) · 1.32 KB
/
main.py
File metadata and controls
63 lines (47 loc) · 1.32 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
52
53
54
55
56
57
58
59
60
61
62
63
import time
from random import randint
from src.window import Window
from src.player import Player
from src.ball import Ball
from src.powerup import Powerup
class Game:
def __init__(self):
# Options
self.tps = 80
self.max_lives = 3
# Game data
self.score = 0
self.lives = self.max_lives
self.balls = []
self.max_powerups = 2
self.powerups = []
# Window
self.window = Window(self)
self.window.start_menu()
# Player
self.player = Player(self.window.window)
def tick(self):
self.player.tick()
for ball in self.balls:
ball.tick(self)
# powerup spawn
if (len(self.powerups) < self.max_powerups):
self.powerups.append(Powerup(self, randint(30, self.window.width - 60), randint(30, self.window.height - 30)))
def main():
game = Game()
# Ball
game.balls.append(Ball(game.window))
tps_wait_time = 1/game.tps
while True:
start = time.time() # Tick Start time
# Tick
game.tick()
# Window is closed
if (game.window.window.isClosed()):
break
# TPS
wait = (tps_wait_time - (time.time() - start))
if (wait > 0):
time.sleep(wait)
if (__name__ == "__main__"):
main()