2024-07-18 10:53:51 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import sys
|
2024-07-19 18:24:45 +02:00
|
|
|
from sprite_stacking_engine.settings import *
|
|
|
|
from sprite_stacking_engine.cache import Cache
|
|
|
|
from sprite_stacking_engine.player import Player
|
|
|
|
from sprite_stacking_engine.scene import Scene
|
2024-07-18 10:53:51 +02:00
|
|
|
|
|
|
|
|
2024-07-19 18:24:45 +02:00
|
|
|
class Engine:
|
|
|
|
def __init__(self, app):
|
|
|
|
self.app = app
|
|
|
|
self.surface = pygame.Surface(self.app.screen.get_size()) # surface to draw the sprites on
|
2024-07-18 10:53:51 +02:00
|
|
|
# groups
|
|
|
|
self.main_group = pygame.sprite.LayeredUpdates()
|
|
|
|
# game objects
|
|
|
|
self.cache = Cache()
|
|
|
|
self.player = Player(self)
|
|
|
|
self.scene = Scene(self)
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self.main_group.update()
|
|
|
|
|
|
|
|
def draw(self):
|
2024-07-19 18:24:45 +02:00
|
|
|
self.surface.fill(BG_COLOR)
|
|
|
|
self.main_group.draw(self.surface)
|
2024-07-18 10:53:51 +02:00
|
|
|
|
|
|
|
def check_events(self):
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
|
|
|
|
pygame.quit()
|
|
|
|
sys.exit()
|
|
|
|
|
2024-07-19 18:24:45 +02:00
|
|
|
def tick(self):
|
|
|
|
self.check_events()
|
|
|
|
self.update()
|
|
|
|
self.draw()
|