-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (58 loc) · 2.01 KB
/
main.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
68
69
70
71
72
import pygame, sys
from settings import *
from level import Level
from overworld import Overworld
from ui import UI
class Game:
def __init__(self):
#game attributes
self.max_level = 1
self.max_health = 100
self.current_health = 100
self.coins = 0
#overworld
self.overworld = Overworld(1, self.max_level, screen, self.create_level)
self.status = "overworld"
#user interface
self.ui = UI(screen)
def create_level(self, current_level):
self.level = Level(current_level, screen, self.create_overworld, self.change_coins, self.change_health)
self.status = "level"
def create_overworld(self, current_level, new_max_level):
if new_max_level > self.max_level:
self.max_level = new_max_level
self.overworld = Overworld(current_level, self.max_level, screen, self.create_level)
self.status = "overworld"
def change_coins(self, amount):
self.coins += amount
def change_health(self, amount):
self.current_health += amount
def check_game_over(self):
if self.current_health < 0:
self.current_health = 100
self.coins = 0
self.max_level = 1
self.overworld = Overworld(1, self.max_level, screen, self.create_level)
self.status = "overworld"
def run(self):
if self.status == "overworld":
self.overworld.run()
else:
self.level.run()
self.ui.show_health(self.current_health, self.max_health)
self.ui.show_coins(self.coins)
self.check_game_over()
pygame.init()
screen = pygame.display.set_mode((screen_width, screen_height))
#background = pygame.image.load("./graphics/BG/BG2r.png")
clock = pygame.time.Clock()
game = Game()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill('grey')
game.run()
pygame.display.update()
clock.tick(60)