-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
63 lines (51 loc) · 1.7 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
# from ssTiles import SsTiles
# from tiles import *
# from player import Player
from enemy import Enemy
from handler import Handler
import pygame
import sys
from assets import Assets
from character import Character
from gameCamera import GameCamera
from gameState import GameState
from menuState import MenuState
pygame.init()
class Game:
def __init__(self):
pygame.display.set_caption("My Game")
self.FPS = 60
self.WIDTH = 900
self.HEIGHT = 500
self.WIN = pygame.display.set_mode((self.WIDTH,self.HEIGHT))
self.BLACK = (0,0,0)
self.WHITE = (255,255,255)
self.dest = (100, 100)
self.handler = Handler(self)
# should be before any other object that have handler in its constr.
# Handler(self) current instance in the current class
self.assets = Assets(self.handler)
self.gameState = GameState(self.handler)
self.gameState.init()
self.menuState = MenuState(self.handler)
self.menuState.init()
self.currentState = self.menuState
# self.ssTile = SsTiles('spritesheet.png')
# self.map = TileMap('test_level.csv', self.ssTile)
# self.bg = pygame.transform.rotate(self.bg, -90)
# draw everything here:
def draw_window(self):
self.WIN.fill(self.BLACK)
self.currentState.draw()
# end of drawing
pygame.display.flip()
def tick(self):
self.currentState.tick()
def run(self):
clock = pygame.time.Clock()
running = True
while running:
clock.tick(self.FPS)
self.handler.inputManager.tick()
self.tick()
self.draw_window()