|
|
|
|
@ -2,9 +2,10 @@ from sdl2_wrapper import SDL2Wrapper
|
|
|
|
|
from pyglet_wrapper import PygletWrapper |
|
|
|
|
from controls import UserControls |
|
|
|
|
import sys |
|
|
|
|
import random |
|
|
|
|
import os |
|
|
|
|
|
|
|
|
|
from Entities.entity import Entity |
|
|
|
|
|
|
|
|
|
class GameEngine(UserControls): |
|
|
|
|
def __init__(self): |
|
|
|
|
super().__init__() |
|
|
|
|
@ -12,23 +13,27 @@ class GameEngine(UserControls):
|
|
|
|
|
self.graphics = PygletWrapper() |
|
|
|
|
else: |
|
|
|
|
self.graphics = SDL2Wrapper() |
|
|
|
|
|
|
|
|
|
self.map = [[1, 1, 0, 0, 1,0, 0, 0, 0, 1], |
|
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
|
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
|
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
|
|
|
|
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0], |
|
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1], |
|
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
|
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
|
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
|
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] |
|
|
|
|
self.map = [ |
|
|
|
|
[{ 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }], |
|
|
|
|
[{ 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }], |
|
|
|
|
[{ 'wall': True, 'tile': "landscapeTiles_066" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': True, 'tile': "landscapeTiles_066" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }], |
|
|
|
|
[{ 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': True, 'tile': "landscapeTiles_066" }], |
|
|
|
|
[{ 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }], |
|
|
|
|
[{ 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }], |
|
|
|
|
[{ 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }], |
|
|
|
|
[{ 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': False, 'tile': "landscapeTiles_067" }, { 'wall': True, 'tile': "landscapeTiles_066" }] |
|
|
|
|
] |
|
|
|
|
self.frame_time = 0 |
|
|
|
|
self.cursor_pos = (0, 0) |
|
|
|
|
|
|
|
|
|
self.load_assets() |
|
|
|
|
self.entities = [] |
|
|
|
|
|
|
|
|
|
def run(self): |
|
|
|
|
running = True |
|
|
|
|
self.graphics.create_background(self.map, "tiles") |
|
|
|
|
next = 0 |
|
|
|
|
self.entities.append(Entity("knight", 0, 0, "idle", 1, 1, self)) |
|
|
|
|
|
|
|
|
|
while running: |
|
|
|
|
perf_counter = self.graphics.get_perf_counter() |
|
|
|
|
event = self.graphics.handle_events() |
|
|
|
|
@ -37,28 +42,37 @@ class GameEngine(UserControls):
|
|
|
|
|
running = False if event == "QUIT" else True |
|
|
|
|
self.graphics.clear_screen() |
|
|
|
|
self.graphics.render_background() |
|
|
|
|
pos = 0 |
|
|
|
|
for animation in ["walk"]: |
|
|
|
|
n = self.graphics.render_sprite(f"knight_{animation}_dir1", |
|
|
|
|
100+pos, 100, next) |
|
|
|
|
pos += 100 |
|
|
|
|
next += 1 |
|
|
|
|
self.cursor_pos = self.graphics.draw_cursor() |
|
|
|
|
for entity in self.entities: |
|
|
|
|
entity.update() |
|
|
|
|
self.graphics.update_status(f"Frame time: {round(self.frame_time)}ms - FPS: {round(1000/self.frame_time if self.frame_time != 0 else 1)}") |
|
|
|
|
self.graphics.present_renderer() |
|
|
|
|
self.frame_time = self.graphics.get_frame_time(perf_counter) |
|
|
|
|
self.graphics.delay_frame(self.frame_time,50) |
|
|
|
|
#self.frame_time = self.graphics.get_frame_time(perf_counter) |
|
|
|
|
self.graphics.quit() |
|
|
|
|
|
|
|
|
|
def set_cursor(self, x, y): |
|
|
|
|
self.graphics.cursor = (x, y) |
|
|
|
|
|
|
|
|
|
def render_background(self): |
|
|
|
|
for y, row in enumerate(self.map): |
|
|
|
|
for x, tile_name in enumerate(row): |
|
|
|
|
if self.map[y][x] == 1: |
|
|
|
|
self.graphics.render_tile("tiles", "landscapeTiles_066", x, y) |
|
|
|
|
else: |
|
|
|
|
variation = random.choice(["067", "083", "075", "081"]) |
|
|
|
|
self.graphics.render_tile("tiles", f"landscapeTiles_{variation}", x, y) |
|
|
|
|
|
|
|
|
|
for x, cell in enumerate(row): |
|
|
|
|
cell["occlusion"] = self.get_occlusion(x, y) |
|
|
|
|
if cell['occlusion']==1: |
|
|
|
|
continue |
|
|
|
|
self.graphics.render_tile("tiles", cell, x, y) |
|
|
|
|
|
|
|
|
|
def get_occlusion(self, x, y): |
|
|
|
|
if (x, y) == self.cursor_pos: |
|
|
|
|
return 0 |
|
|
|
|
distance = self.graphics.get_distance((x, y), self.cursor_pos) |
|
|
|
|
if distance <2: |
|
|
|
|
return 0.2 |
|
|
|
|
elif distance < 3: |
|
|
|
|
return 0.5 |
|
|
|
|
else: |
|
|
|
|
return 0.8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_assets(self): |
|
|
|
|
self.graphics.load_tilesheet("tiles", "assets/tiles/landscapeTiles_sheet.png") |
|
|
|
|
for dir in os.listdir("assets/KnightBasic"): |
|
|
|
|
@ -70,5 +84,4 @@ class GameEngine(UserControls):
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
engine = GameEngine() |
|
|
|
|
engine.load_assets() |
|
|
|
|
engine.run() |