27 changed files with 426 additions and 192 deletions
@ -1,2 +1,36 @@
|
||||
.venv |
||||
__pycache__ |
||||
# Virtual Environment |
||||
.venv/ |
||||
venv/ |
||||
ENV/ |
||||
|
||||
# Python cache files |
||||
__pycache__/ |
||||
*.py[cod] |
||||
*$py.class |
||||
.pytest_cache/ |
||||
|
||||
# Distribution / packaging |
||||
dist/ |
||||
build/ |
||||
*.egg-info/ |
||||
*.egg |
||||
|
||||
# IDE specific files |
||||
.idea/ |
||||
.vscode/ |
||||
*.swp |
||||
*.swo |
||||
|
||||
# OS specific files |
||||
.DS_Store |
||||
Thumbs.db |
||||
|
||||
# Logs |
||||
*.log |
||||
logs/ |
||||
|
||||
# Local configuration |
||||
.env |
||||
.env.local |
||||
*.local.py |
||||
engine_demo |
||||
@ -0,0 +1,43 @@
|
||||
import random |
||||
from Entities.entity import Entity |
||||
|
||||
class Marine(Entity): |
||||
|
||||
next_cell = (1,1) |
||||
movement = 0 |
||||
|
||||
|
||||
def update(self): |
||||
self.move() |
||||
super().update() |
||||
|
||||
def select_unit(self): |
||||
self.selected = True |
||||
# Play a random voice response when selected |
||||
sound_file = f"marine/tmawht0{random.randint(0, 4)}.wav" |
||||
print(f"Playing sound: {sound_file}") |
||||
self.graphics.play_sound(sound_file) |
||||
|
||||
def move(self): |
||||
if (self.x, self.y) != self.next_cell: |
||||
# Set walking animation and direction |
||||
self.action = "walk" |
||||
self.direction = self.graphics.get_direction((self.x, self.y), self.next_cell) |
||||
self.moving = True |
||||
|
||||
# Calculate target coordinates |
||||
target_x, target_y = self.graphics.iso_transform(self.next_cell[0], self.next_cell[1]) |
||||
|
||||
# Increment movement counter |
||||
self.movement += 0.01 |
||||
|
||||
# Calculate how far we've moved (0.0 to 1.0) |
||||
move_progress = min(self.movement, 1.0) |
||||
# Calculate new position based on progress between cells |
||||
self.iso_x = self.iso_x + (target_x - self.iso_x) * move_progress |
||||
self.iso_y = self.iso_y + (target_y - self.iso_y) * move_progress |
||||
print(f"Moving to {self.iso_x}, {self.iso_y} with progress {move_progress}") |
||||
if self.movement >= 1.0: |
||||
# Reset movement and set to idle |
||||
self.movement = 0 |
||||
self.iso_x, self.iso_y = self.graphics.iso_transform(self.x, self.y) |
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,87 +0,0 @@
|
||||
from sdl2_wrapper import SDL2Wrapper |
||||
from pyglet_wrapper import PygletWrapper |
||||
from controls import UserControls |
||||
import sys |
||||
import os |
||||
|
||||
from Entities.entity import Entity |
||||
|
||||
class GameEngine(UserControls): |
||||
def __init__(self): |
||||
super().__init__() |
||||
if "--pyglet" in sys.argv: |
||||
self.graphics = PygletWrapper() |
||||
else: |
||||
self.graphics = SDL2Wrapper() |
||||
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") |
||||
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() |
||||
if event: |
||||
self.handle_events("keymap_game", event) |
||||
running = False if event == "QUIT" else True |
||||
self.graphics.clear_screen() |
||||
self.graphics.render_background() |
||||
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.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, 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"): |
||||
for file in os.listdir(f"assets/KnightBasic/{dir}"): |
||||
if file.endswith(".json"): |
||||
self.graphics.load_spritesheet(file[:-5].lower(), f"assets/KnightBasic/{dir}/{file}") |
||||
|
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
engine = GameEngine() |
||||
engine.run() |
||||
Loading…
Reference in new issue