AI-Project/survival/game_map.py

30 lines
958 B
Python
Raw Normal View History

2021-03-28 18:05:52 +02:00
from survival.entity_layer import EntityLayer
2021-03-14 17:12:11 +01:00
from survival.tile_layer import TileLayer
2021-03-04 14:07:44 +01:00
class GameMap:
def __init__(self, width, height):
self.width = width
self.height = height
2021-03-28 18:05:52 +02:00
self.tile_layer = TileLayer(width, height)
self.entity_layer = EntityLayer(width, height)
2021-03-04 14:07:44 +01:00
def draw(self, camera):
2021-03-15 14:10:19 +01:00
visible_area = camera.get_visible_area()
2021-03-28 18:05:52 +02:00
self.tile_layer.draw(camera, visible_area)
2021-03-04 14:07:44 +01:00
2021-03-28 18:05:52 +02:00
def add_entity(self, entity, pos):
self.entity_layer.add_entity(entity, pos.grid_position)
def move_entity(self, from_pos, to_pos):
self.entity_layer.move_entity(from_pos, to_pos)
def remove_entity(self, pos):
self.entity_layer.remove_entity(pos)
def is_colliding(self, pos):
return pos[0] < 0 or pos[0] >= self.width or pos[1] < 0 or pos[1] >= self.height or self.entity_layer.is_colliding(pos)
2021-05-09 18:11:25 +02:00
def get_cost(self, pos):
return self.tile_layer.get_cost(pos)