|
|
|
|
@ -3,26 +3,24 @@ from enne2engine.pyglet_wrapper import PygletWrapper
|
|
|
|
|
from enne2engine.controls import UserControls |
|
|
|
|
import sys |
|
|
|
|
import os |
|
|
|
|
import json |
|
|
|
|
from Entities.Units.marine import Marine |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GameEngine(UserControls): |
|
|
|
|
def __init__(self): |
|
|
|
|
super().__init__() |
|
|
|
|
if "--pyglet" in sys.argv: |
|
|
|
|
self.graphics = PygletWrapper() |
|
|
|
|
else: |
|
|
|
|
self.graphics = SDL2Wrapper(self) |
|
|
|
|
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_001" }, { '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.graphics = SDL2Wrapper(self) |
|
|
|
|
|
|
|
|
|
# Load map from JSON file |
|
|
|
|
try: |
|
|
|
|
with open("assets/maps/map.json", "r") as map_file: |
|
|
|
|
self.map = json.load(map_file) |
|
|
|
|
except (FileNotFoundError, json.JSONDecodeError) as e: |
|
|
|
|
print(f"Error loading map file: {e}") |
|
|
|
|
print("Exiting program.") |
|
|
|
|
sys.exit(0) |
|
|
|
|
|
|
|
|
|
self.frame_time = 0 |
|
|
|
|
self.cursor_pos = (0, 0) |
|
|
|
|
|
|
|
|
|
@ -33,32 +31,48 @@ class GameEngine(UserControls):
|
|
|
|
|
def run(self): |
|
|
|
|
running = True |
|
|
|
|
# Set a custom scale if needed |
|
|
|
|
self.graphics.set_scaling_factor(0.5) # 50% scale |
|
|
|
|
self.graphics.set_scaling_factor(0.50) # 50% scale |
|
|
|
|
|
|
|
|
|
self.entities.append(Marine("knight", 0, 0, "idle", 1, 1, self)) |
|
|
|
|
self.graphics.create_background(self.map, "tiles") |
|
|
|
|
self.entities.append(Marine("knight", 5, 0, "idle", 1, 1, self)) |
|
|
|
|
while running: |
|
|
|
|
# Start the frame timer |
|
|
|
|
perf_counter = self.graphics.get_perf_counter() |
|
|
|
|
# Initialize the map shadow and entities positions |
|
|
|
|
self.map_shadow = [ [0 for _ in range(len(self.map[0]))] for _ in range(len(self.map)) ] |
|
|
|
|
self.entities_positions.clear() |
|
|
|
|
for entity in self.entities: |
|
|
|
|
self.entities_positions[entity.next_cell] = entity |
|
|
|
|
self.entities_positions[(entity.x, entity.y)] = entity |
|
|
|
|
self.graphics.create_background(self.map, "tiles") |
|
|
|
|
# Create the map background texture with tiles |
|
|
|
|
self.graphics.create_background(self.map, "tiles", self.map_shadow) |
|
|
|
|
|
|
|
|
|
# Handle events |
|
|
|
|
event = self.graphics.handle_events() |
|
|
|
|
if event: |
|
|
|
|
#print(f"Event detected: {event}") |
|
|
|
|
if event.startswith("MOUSEDOWN"): |
|
|
|
|
pass |
|
|
|
|
print(f"Mouse down event: {event}") |
|
|
|
|
print(f"Button pressed: {event[-1]}") |
|
|
|
|
if event[-1] == "3": |
|
|
|
|
print("Right mouse button pressed") |
|
|
|
|
for entity in self.entities: |
|
|
|
|
if entity.selected: |
|
|
|
|
entity.set_target_cell(self.cursor_pos) |
|
|
|
|
elif event.startswith("SELECTION"): |
|
|
|
|
# Handle multiple unit selection |
|
|
|
|
self.select_units_in_area(event) |
|
|
|
|
elif event.startswith("MOUSEUP"): |
|
|
|
|
self.select_entity_at_cursor() |
|
|
|
|
if event[-1] == "1": |
|
|
|
|
self.select_entity_at_cursor() |
|
|
|
|
self.handle_events("keymap_game", event) |
|
|
|
|
|
|
|
|
|
running = False if event == "QUIT" else True |
|
|
|
|
|
|
|
|
|
self.graphics.clear_screen() |
|
|
|
|
self.graphics.render_background() |
|
|
|
|
#self.graphics.render_tile(spritesheet_name="tiles", tile="landscapeTiles_064", x=0, y=0) |
|
|
|
|
#self.graphics.draw_square(0,0) |
|
|
|
|
self.cursor_pos = self.graphics.draw_cursor() |
|
|
|
|
|
|
|
|
|
# Draw the selection rectangle if selecting |
|
|
|
|
if self.graphics.is_mouse_button_pressed(1): |
|
|
|
|
self.graphics.draw_selection_rectangle() |
|
|
|
|
|