Skip to content

Commit

Permalink
Added random treasure chest mechanics and indestructable blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
abbyssoul committed Dec 6, 2020
1 parent efdcc34 commit a901402
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 180 deletions.
10 changes: 9 additions & 1 deletion coderone/dungeon/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

class EntityTags(Enum):
Ammo = "a"
Treasure = 't'
Bomb = "b"
SoftBlock = 'sb'
MetalBlock = 'mb'
OreBlock = 'ob'
IndestructibleBlock = 'ib'

class GameState:
""" A state of the game as viewed by an agent.
Expand All @@ -18,6 +20,7 @@ class GameState:

def __init__(self, is_over:bool, tick_number:int, size:Point,
game_map:Dict,
treasure:List[Point],
ammo:List[Point],
bombs:List[Point],
blocks,
Expand All @@ -27,6 +30,7 @@ def __init__(self, is_over:bool, tick_number:int, size:Point,
self.tick_number = tick_number
self.size = size
self._game_map = game_map
self._treasure = treasure
self._ammo = ammo
self._bombs = bombs
self._blocks = blocks
Expand All @@ -49,6 +53,10 @@ def bombs(self):
def ammo(self) -> List[Point]:
return self._ammo

@property
def treasure(self) -> List[Point]:
return self._treasure

@property
def all_blocks(self) -> List[Point]:
return [pos for tag, pos in self._blocks]
Expand Down
13 changes: 8 additions & 5 deletions coderone/dungeon/arcade_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ def _map_game(self):
# Create player sprites
self.player_list.extend([Player(self.asset_man.player_avatar(pid), player) for pid, player in self.game.players.items()])

self.block_list.extend(map(lambda block: StaticSprite(self.asset_man.metal_block if block.hp > 1 else self.asset_man.crate, block, 4.0), self.game.block_list))
self._add_blocks(self.asset_man.indestructible_block, self.game.static_block_list)
self.block_list.extend(map(lambda block: StaticSprite(self.asset_man.ore_block if block.hp > 1 else self.asset_man.soft_block, block, 4.0), self.game.value_block_list))

self._add_blocks(self.asset_man.ammunition, self.game.ammunition_list, 1)
self._add_blocks(self.asset_man.treasure, self.game.treasure_list)
self._add_blocks(self.asset_man.bomb, self.game.bomb_list, 1)
self._add_blocks(self.asset_man.ammunition, self.game.ammunition_list)
self._add_blocks(self.asset_man.fire, self.game.fire_list)
self._add_blocks(self.asset_man.skeleton, self.game.dead_player_list)

Expand All @@ -167,8 +169,9 @@ def _update_map(self):
sprite.remove_from_sprite_lists()

all_block_owner = [sprite.owner for sprite in self.block_list]
self._add_blocks(self.asset_man.ammunition, [block for block in self.game.ammunition_list if block not in all_block_owner], 1)
self._add_blocks(self.asset_man.treasure, [block for block in self.game.treasure_list if block not in all_block_owner])
self._add_blocks(self.asset_man.bomb, [block for block in self.game.bomb_list if block not in all_block_owner], 1)
self._add_blocks(self.asset_man.ammunition, [block for block in self.game.ammunition_list if block not in all_block_owner])
self._add_blocks(self.asset_man.fire, [block for block in self.game.fire_list if block not in all_block_owner])
self._add_blocks(self.asset_man.skeleton, [block for block in self.game.dead_player_list if block not in all_block_owner])

Expand Down Expand Up @@ -218,7 +221,7 @@ def on_draw(self):
font_name='arial',
align="center", anchor_x="center", anchor_y="center")

if self.game.game_ended:
if self.game.is_over:
progress = 360*(1 - self.end_game_timer / self.end_game_wait_time)
sq_size = self.height / 4
width = sq_size / 4
Expand All @@ -241,7 +244,7 @@ def on_update(self, delta_time):
if self.paused: # if game has paused then don't update it
return

game_over = self.game.game_ended
game_over = self.game.is_over
if game_over: # Game over count-down
self.end_game_timer -= delta_time

Expand Down
36 changes: 26 additions & 10 deletions coderone/dungeon/asset_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ class AssetType(Enum):
class AssetManager:

# Images
AMMUNITION_IMAGE = "ammo.png"
TREASURE_CHEST_IMAGE = "chest.png"
BOMB_IMAGE = "bomb_64px.png"
AMMUNITION_IMAGE = "chest.png"
CRATE_IMAGE = "crate.png"
METAL_BLOCK_IMAGE = "metal_block.png"

SOFT_BLOCK_IMAGE = "crate.png"
ORE_BLOCK_IMAGE = "ore_block.png"
INDESTRUCTABLE_BLOCK_IMAGE = "metal_block.png"

SKELETON_IMAGE = "skelet_run_anim_f1.png"
FIRE_IMAGE = "coin_anim_f0.png"
EXPLOSION_IMAGE = "explosion.png"
Expand All @@ -23,7 +27,9 @@ class AssetManager:

FLOOR_TILES = ["floor_1.png", "floor_2.png", "floor_3.png", "floor_4.png", "floor_5.png", "floor_6.png", "floor_7.png", "floor_8.png"]
PLAYER_AVATARS = [
"wizard_m_64px.png",
"p1_knight_64px.png",
"wizard_f_64px.png",
"p2_knight_64px_flipped.png",
"p2_knight_64px.png",
"p2_knight_orange_64px_flipped.png",
Expand All @@ -42,20 +48,28 @@ def floor_tile(self):
return self.asset(tile, AssetType.IMAGE)

@property
def metal_block(self):
return self.asset(self.METAL_BLOCK_IMAGE, AssetType.IMAGE)
def ammunition(self):
return self.asset(self.AMMUNITION_IMAGE, AssetType.IMAGE)

@property
def crate(self):
return self.asset(self.CRATE_IMAGE, AssetType.IMAGE)
def treasure(self):
return self.asset(self.TREASURE_CHEST_IMAGE, AssetType.IMAGE)

@property
def bomb(self):
return self.asset(self.BOMB_IMAGE, AssetType.IMAGE)

@property
def ammunition(self):
return self.asset(self.AMMUNITION_IMAGE, AssetType.IMAGE)
def indestructible_block(self):
return self.asset(self.INDESTRUCTABLE_BLOCK_IMAGE, AssetType.IMAGE)

@property
def soft_block(self):
return self.asset(self.SOFT_BLOCK_IMAGE, AssetType.IMAGE)

@property
def ore_block(self):
return self.asset(self.ORE_BLOCK_IMAGE, AssetType.IMAGE)

@property
def skeleton(self):
Expand All @@ -69,10 +83,12 @@ def fire(self):
def explosion_sound(self):
return self.asset(self.EXP_SOUND, AssetType.SOUND)

def player_avatar(self, pid):

def player_avatar(self, pid:int):
avatar = self.PLAYER_AVATARS[pid % len(self.PLAYER_AVATARS)]
return self.asset(avatar, AssetType.IMAGE)


def asset(self, name, assetType: AssetType):
# data = pkgutil.get_data(__name__, "templates/temp_file")
return os.path.join(self.asset_dir, assetType.value, name)
Binary file added coderone/dungeon/assets/images/ammo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added coderone/dungeon/assets/images/ore_block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a901402

Please sign in to comment.