mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-09 14:05:20 -06:00
skeleton functions for pathing in Mobs using target attribute and target and dungeon references, create new TILE_SIZE config option
This commit is contained in:
@@ -29,6 +29,7 @@ class Config(object):
|
||||
# Constants used to scale our sprites from their original size
|
||||
CHARACTER_SCALING = 1
|
||||
TILE_SCALING = 2
|
||||
TILE_SIZE = TILE_WIDTH * TILE_SCALING
|
||||
|
||||
# The number of pixels across the level
|
||||
LEVEL_SIZE = 10 * TILE_SCALING * TILE_WIDTH
|
||||
|
||||
@@ -10,7 +10,6 @@ import random
|
||||
import time
|
||||
|
||||
import arcade
|
||||
|
||||
from config import Config
|
||||
from map import Dungeon
|
||||
from mobs import Player
|
||||
@@ -70,7 +69,7 @@ class Game(arcade.Window):
|
||||
self.dungeon = Dungeon(0, 3)
|
||||
|
||||
# Set up the player, specifically placing it at these coordinates.
|
||||
self.player = Player()
|
||||
self.player = Player(self.dungeon)
|
||||
self.player.scale = 1
|
||||
level = random.choice(self.dungeon.levelList)
|
||||
self.player.center_x, self.player.center_y = level.center()
|
||||
@@ -105,9 +104,9 @@ class Game(arcade.Window):
|
||||
|
||||
if Config.DEBUG:
|
||||
x, y = self.player.position
|
||||
tile = Config.TILE_WIDTH * Config.TILE_SCALING
|
||||
arcade.draw_rectangle_outline(round(x / tile) * tile, round(y / tile) * tile, tile, tile,
|
||||
arcade.color.RED)
|
||||
arcade.draw_rectangle_outline(round(x / Config.TILE_SIZE) * Config.TILE_SIZE,
|
||||
round(y / Config.TILE_SIZE) * Config.TILE_SIZE,
|
||||
Config.TILE_SIZE, Config.TILE_SIZE, arcade.color.RED)
|
||||
self.player.draw_hit_box()
|
||||
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,
|
||||
|
||||
@@ -3,9 +3,11 @@ mobs.py
|
||||
Organizes all classes related to Mobs, Entities, Enemies, Players and Items.
|
||||
"""
|
||||
|
||||
import arcade
|
||||
from typing import List, Tuple
|
||||
|
||||
import arcade
|
||||
from config import Config, Enums, SpritePaths
|
||||
from map import Dungeon
|
||||
from sprites import PlayerAnimations
|
||||
|
||||
|
||||
@@ -14,7 +16,7 @@ class Mob(arcade.Sprite):
|
||||
Represents a Mob. No defined behaviour, it has no intelligence.
|
||||
"""
|
||||
|
||||
def __init__(self, max_health=100, max_armor=0, *args, **kwargs) -> None:
|
||||
def __init__(self, dungeon: Dungeon, max_health=100, max_armor=0, *args, **kwargs) -> None:
|
||||
# Set up parent class
|
||||
super().__init__()
|
||||
|
||||
@@ -26,12 +28,33 @@ class Mob(arcade.Sprite):
|
||||
self.down_textures = []
|
||||
self.cur_texture = 0
|
||||
|
||||
self.dungeon = dungeon
|
||||
self.target = None
|
||||
|
||||
def tick(self) -> None:
|
||||
"""
|
||||
A on_update function, the Mob should decide it's next actions here.
|
||||
"""
|
||||
|
||||
if Config.DEBUG:
|
||||
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:
|
||||
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.
|
||||
|
||||
:param matrix:
|
||||
:param end:
|
||||
:return:
|
||||
"""
|
||||
|
||||
|
||||
class Player(Mob):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user