Merge branch 'master' into 'moreitems'
# Conflicts: # squirrelbattle/entities/items.py # squirrelbattle/interfaces.py # squirrelbattle/tests/game_test.py
This commit is contained in:
@ -7,6 +7,7 @@ from random import choice, choices, randint
|
||||
from typing import List, Optional, Any, Dict, Tuple
|
||||
from queue import PriorityQueue
|
||||
from functools import reduce
|
||||
from copy import deepcopy
|
||||
|
||||
from .display.texturepack import TexturePack
|
||||
from .translations import gettext as _
|
||||
@ -80,18 +81,18 @@ class Map:
|
||||
currentx: int
|
||||
currenty: int
|
||||
|
||||
def __init__(self, width: int, height: int, tiles: list,
|
||||
start_y: int, start_x: int):
|
||||
def __init__(self, width: int = 0, height: int = 0, tiles: list = None,
|
||||
start_y: int = 0, start_x: int = 0):
|
||||
self.floor = 0
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.start_y = start_y
|
||||
self.start_x = start_x
|
||||
self.tiles = tiles
|
||||
self.visibility = [[False for _ in range(len(tiles[0]))]
|
||||
for _ in range(len(tiles))]
|
||||
self.tiles = tiles or []
|
||||
self.visibility = [[False for _ in range(len(self.tiles[0]))]
|
||||
for _ in range(len(self.tiles))]
|
||||
self.seen_tiles = [[False for _ in range(len(tiles[0]))]
|
||||
for _ in range(len(tiles))]
|
||||
for _ in range(len(self.tiles))]
|
||||
self.entities = []
|
||||
self.logs = Logs()
|
||||
|
||||
@ -193,6 +194,14 @@ class Map:
|
||||
entity.move(y, x)
|
||||
self.add_entity(entity)
|
||||
|
||||
def is_visible_from(self, starty: int, startx: int, desty: int, destx: int,
|
||||
max_range: int) -> bool:
|
||||
oldvisibility = deepcopy(self.visibility)
|
||||
self.compute_visibility(starty, startx, max_range)
|
||||
result = self.visibility[desty][destx]
|
||||
self.visibility = oldvisibility
|
||||
return result
|
||||
|
||||
def compute_visibility(self, y: int, x: int, max_range: int) -> None:
|
||||
"""
|
||||
Sets the visible tiles to be the ones visible by an entity at point
|
||||
@ -245,10 +254,12 @@ class Map:
|
||||
if x + y > max_range:
|
||||
continue
|
||||
is_opaque = self.is_wall(y, x, octant, origin)
|
||||
if y == top_y and octant == 7 and x == 4:
|
||||
self.logs.add_message(f"{x}, {y}, {top.X}, {top.Y}")
|
||||
is_visible = is_opaque\
|
||||
or ((y != top_y or top > Slope(y * 4 - 1, x * 4 + 1))
|
||||
or ((y != top_y or top >= Slope(y, x))
|
||||
and (y != bottom_y
|
||||
or bottom < Slope(y * 4 + 1, x * 4 - 1)))
|
||||
or bottom <= Slope(y, x)))
|
||||
# is_visible = is_opaque\
|
||||
# or ((y != top_y or top >= Slope(y, x))
|
||||
# and (y != bottom_y or bottom <= Slope(y, x)))
|
||||
@ -338,9 +349,10 @@ class Map:
|
||||
for enti in self.entities:
|
||||
d["entities"].append(enti.save_state())
|
||||
d["map"] = self.draw_string(TexturePack.ASCII_PACK)
|
||||
d["seen_tiles"] = self.seen_tiles
|
||||
return d
|
||||
|
||||
def load_state(self, d: dict) -> None:
|
||||
def load_state(self, d: dict) -> "Map":
|
||||
"""
|
||||
Loads the map's attributes from a dictionary.
|
||||
"""
|
||||
@ -351,11 +363,16 @@ class Map:
|
||||
self.currentx = d["currentx"]
|
||||
self.currenty = d["currenty"]
|
||||
self.tiles = self.load_dungeon_from_string(d["map"])
|
||||
self.seen_tiles = d["seen_tiles"]
|
||||
self.visibility = [[False for _ in range(len(self.tiles[0]))]
|
||||
for _ in range(len(self.tiles))]
|
||||
self.entities = []
|
||||
dictclasses = Entity.get_all_entity_classes_in_a_dict()
|
||||
for entisave in d["entities"]:
|
||||
self.add_entity(dictclasses[entisave["type"]](**entisave))
|
||||
|
||||
return self
|
||||
|
||||
|
||||
class Tile(Enum):
|
||||
"""
|
||||
@ -636,32 +653,34 @@ class Entity:
|
||||
Trumpet, Chest
|
||||
from squirrelbattle.entities.items import BodySnatchPotion, Bomb, \
|
||||
Heart, Sword, Shield, Chestplate, Helmet, RingCritical, RingXP, \
|
||||
ScrollofDamage, ScrollofWeakening, Ruler, Bow, FireBallStaff
|
||||
ScrollofDamage, ScrollofWeakening, Ruler, Bow, FireBallStaff, \
|
||||
Monocle
|
||||
return {
|
||||
"Tiger": Tiger,
|
||||
"Bomb": Bomb,
|
||||
"Heart": Heart,
|
||||
"BodySnatchPotion": BodySnatchPotion,
|
||||
"Hedgehog": Hedgehog,
|
||||
"Rabbit": Rabbit,
|
||||
"TeddyBear": TeddyBear,
|
||||
"Player": Player,
|
||||
"Merchant": Merchant,
|
||||
"Sunflower": Sunflower,
|
||||
"Sword": Sword,
|
||||
"Trumpet": Trumpet,
|
||||
"Eagle": GiantSeaEagle,
|
||||
"Shield": Shield,
|
||||
"Bomb": Bomb,
|
||||
"Bow": Bow,
|
||||
"Chest": Chest,
|
||||
"Chestplate": Chestplate,
|
||||
"Eagle": GiantSeaEagle,
|
||||
"FireBallStaff": FireBallStaff,
|
||||
"Heart": Heart,
|
||||
"Hedgehog": Hedgehog,
|
||||
"Helmet": Helmet,
|
||||
"Merchant": Merchant,
|
||||
"Monocle": Monocle,
|
||||
"Player": Player,
|
||||
"Rabbit": Rabbit,
|
||||
"RingCritical": RingCritical,
|
||||
"RingXP": RingXP,
|
||||
"Ruler": Ruler,
|
||||
"ScrollofDamage": ScrollofDamage,
|
||||
"ScrollofWeakening": ScrollofWeakening,
|
||||
"Bow": Bow,
|
||||
"FireBallStaff": FireBallStaff,
|
||||
"Chest": Chest,
|
||||
"Shield": Shield,
|
||||
"Sunflower": Sunflower,
|
||||
"Sword": Sword,
|
||||
"Trumpet": Trumpet,
|
||||
"TeddyBear": TeddyBear,
|
||||
"Tiger": Tiger,
|
||||
}
|
||||
|
||||
def save_state(self) -> dict:
|
||||
|
Reference in New Issue
Block a user