-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·59 lines (41 loc) · 1.54 KB
/
Copy pathmain.py
File metadata and controls
executable file
·59 lines (41 loc) · 1.54 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
#!/usr/bin/env python
import os
import pygame
from pygame.locals import *
import pygame.mixer
from configs import *
class Main:
class States:
Menu, Game, HighScore = range(3)
def __init__(self):
pygame.init()
pygame.display.set_caption('Ants')
self.screen = pygame.display.set_mode((screen_width, screen_height))
self.background = pygame.image.load(os.path.join("images", "soil.jpg"))
# self.background = pygame.Surface((self.screen.get_width(), self.screen.get_height()))
# self.background.fill((0, 0, 0))
self.now_state = Main.States.Menu
import game
import menu
import highscore
self.game = game.Game()
self.menu = menu.Menu()
self.highscore = highscore.HighScore()
self.soundtrack = pygame.mixer.Sound(os.path.join("sounds", "soundtrack.wav"))
self.start()
def start(self):
self.soundtrack.play(-1)
while True:
if self.now_state == Main.States.Menu:
self.menu.update(self.screen, self.background, self)
elif self.now_state == Main.States.Game:
self.game.update(self.screen, self.background, self)
elif self.now_state == Main.States.HighScore:
self.highscore.update(self.screen, self.background, self)
pygame.display.update()
def set_state(self, new_state):
self.now_state = new_state
if new_state == Main.States.Game:
self.game.reset()
if __name__ == "__main__":
Main()