mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-07 03:13:15 -06:00
create draw and get path methodology
This commit is contained in:
@@ -8,6 +8,7 @@ import collections
|
|||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
from typing import Tuple, List
|
||||||
|
|
||||||
import arcade
|
import arcade
|
||||||
from config import Config
|
from config import Config
|
||||||
@@ -111,11 +112,25 @@ class Game(arcade.Window):
|
|||||||
arcade.draw_text(str((x, y)), x - 40, y + 50, arcade.color.WHITE, 15, font_name='Arial')
|
arcade.draw_text(str((x, y)), x - 40, y + 50, arcade.color.WHITE, 15, font_name='Arial')
|
||||||
arcade.draw_text(f"FPS: {self.fps.get_fps():3.0f}", self.view_left + 50, self.view_bottom + 30,
|
arcade.draw_text(f"FPS: {self.fps.get_fps():3.0f}", self.view_left + 50, self.view_bottom + 30,
|
||||||
arcade.color.WHITE, 16, font_name='Arial')
|
arcade.color.WHITE, 16, font_name='Arial')
|
||||||
|
|
||||||
|
# Draw paths for all mobs
|
||||||
|
for mob in self.enemy_list:
|
||||||
|
if mob.target is not None:
|
||||||
|
self.draw_path(mob.mob.get_path())
|
||||||
|
|
||||||
self.fps.tick()
|
self.fps.tick()
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
def draw_path(self, path: List[Tuple[int, int]]) -> None:
|
||||||
|
"""
|
||||||
|
Draws a line between positions in a list of tuple, also known as the path.
|
||||||
|
:param path: A list of tuple positions defining a path that can be traversed.
|
||||||
|
"""
|
||||||
|
print(path)
|
||||||
|
pass
|
||||||
|
|
||||||
def on_key_press(self, key, modifiers):
|
def on_key_press(self, key, modifiers):
|
||||||
"""Called whenever a key is pressed. """
|
"""Called whenever a key is pressed. """
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,15 @@ class Mob(arcade.Sprite):
|
|||||||
self.dungeon = dungeon
|
self.dungeon = dungeon
|
||||||
self.target = None
|
self.target = None
|
||||||
|
|
||||||
|
def nearestPosition(self) -> Tuple[int, int]:
|
||||||
|
"""
|
||||||
|
Returns the nearest absolute dungeon tile the Mob is placed on.
|
||||||
|
|
||||||
|
:return: A tuple containing the Mob's dungeon tile position.
|
||||||
|
"""
|
||||||
|
return (round(self.center_x / Config.TILE_SIZE) * Config.TILE_SIZE,
|
||||||
|
round(self.center_y / Config.TILE_SIZE) * Config.TILE_SIZE)
|
||||||
|
|
||||||
def tick(self) -> None:
|
def tick(self) -> None:
|
||||||
"""
|
"""
|
||||||
A on_update function, the Mob should decide it's next actions here.
|
A on_update function, the Mob should decide it's next actions here.
|
||||||
@@ -38,22 +47,17 @@ class Mob(arcade.Sprite):
|
|||||||
|
|
||||||
if Config.DEBUG:
|
if Config.DEBUG:
|
||||||
if self.target is not None:
|
if self.target is not None:
|
||||||
x, y = self.target.position
|
|
||||||
self.draw_path(self.get_path(
|
|
||||||
(round(x / Config.TILE_SIZE) * Config.TILE_SIZE, round(y / Config.TILE_SIZE) * Config.TILE_SIZE)
|
|
||||||
))
|
|
||||||
|
|
||||||
def draw_path(self, path: List[Tuple[int, int]]) -> None:
|
def get_path(self, end: Tuple[int, int] = None) -> List[Tuple[int, int]]:
|
||||||
pass
|
|
||||||
|
|
||||||
def get_path(self, end: Tuple[int, int]) -> List[Tuple[int, int]]:
|
|
||||||
"""
|
"""
|
||||||
Returns the path to get to the Mob's target in absolute integer positions.
|
Returns the path to get to the Mob's target in absolute integer positions.
|
||||||
|
|
||||||
:param matrix:
|
:param end: A the endpoint tuple. Must be a valid position within the matrix.
|
||||||
:param end:
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
if end is None:
|
||||||
|
x, y = self.target.position
|
||||||
|
x, y = (round(x / Config.TILE_SIZE) * Config.TILE_SIZE, round(y / Config.TILE_SIZE) * Config.TILE_SIZE)
|
||||||
|
|
||||||
|
|
||||||
class Player(Mob):
|
class Player(Mob):
|
||||||
|
|||||||
Reference in New Issue
Block a user