Merge pull request #31 from n0remac/positions-fix

Player Initial Position
This commit is contained in:
Cameron
2020-04-20 17:11:14 -07:00
committed by GitHub
3 changed files with 40 additions and 23 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ class Enums(Enum):
A simple class used for tracking different simple
"""
# Play Direction Enums
# Player Direction Enums
RIGHT = 0
LEFT = 1
UP = 2
+21 -10
View File
@@ -26,8 +26,6 @@ class Game(arcade.Window):
# These are 'lists' that keep track of our sprites. Each sprite should
# go into a list.
self.wall_list = None
self.floor_list = None
self.enemy_list = None
self.bullet_list = None
self.player = None
@@ -53,17 +51,25 @@ class Game(arcade.Window):
self.enemy_list = arcade.SpriteList()
self.bullet_list = arcade.SpriteList()
# Set up the player, specifically placing it at these coordinates.
self.player = Player()
self.player.scale = 1
# Create the dungeon
self.dungeon = Dungeon(0, 3)
self.player.center_x, self.player.center_y = random.choice(self.dungeon.levelList).center()
# Set up the player, specifically placing it at these coordinates.
self.player = Player()
self.player.scale = 1
level = random.choice(self.dungeon.levelList)
self.player.center_x, self.player.center_y = level.center()
# x, y = level.center()
# Setup viewport
self.view_bottom = self.player.center_x - (0.5 * Config.SCREEN_WIDTH) + 300
self.view_left = self.player.center_x - (0.5 * Config.SCREEN_WIDTH)
arcade.set_viewport(self.view_left,
Config.SCREEN_WIDTH + self.view_left,
self.view_bottom,
Config.SCREEN_HEIGHT + self.view_bottom)
# Create monsters
# This needs to be updated to comply with the new mobs.py code
# self.enemy_list.append(Enemy("resources/images/monsters/ghost/ghost1.png", 200, 200, 4))
# self.enemy_list.append(Enemy("resources/images/monsters/frog/frog1.png", 200, 1000, 4))
@@ -72,6 +78,7 @@ class Game(arcade.Window):
def on_draw(self):
""" Render the screen. """
try:
# Clear the screen to the background color
arcade.start_render()
@@ -82,8 +89,12 @@ class Game(arcade.Window):
self.enemy_list.draw()
self.bullet_list.draw()
x, y = self.player.center_x, self.player.center_y + 100
# arcade.draw_text(f"({x}, {y})", x, y, arcade.color.WHITE, 15)
self.player.draw_hit_box()
x, y = self.player.center_x, self.player.center_y
arcade.draw_text(str((x, y)), x - 40, y + 50, arcade.color.WHITE, 15)
except Exception:
import traceback
traceback.print_exc()
def on_key_press(self, key, modifiers):
"""Called whenever a key is pressed. """
+11 -5
View File
@@ -142,21 +142,27 @@ class Level:
level.floorSprites.append(sprite)
elif 'wall' in tilePath:
level.wallSprites.append(sprite)
else:
print(f'Could not handle Tile: {tilePath}')
# Move everything into correct positions
level.floorSprites.move(*level.center())
level.wallSprites.move(*level.center())
level.floorSprites.move(*level.bottomLeft())
level.wallSprites.move(*level.bottomLeft())
return level
def bottomLeft(self) -> tuple:
"""
Return the pixel bottom left corner of a Level.
:return: A tuple containing the X and Y coordinates of the level's bottom left corner.
"""
return Config.LEVEL_SIZE * self.x, Config.LEVEL_SIZE * self.y
def center(self) -> tuple:
"""
Returns the pixel center of the level.
:return: A tuple containing the X and Y coordinates of the level's center
"""
return self.x * Config.LEVEL_SIZE, self.y * Config.LEVEL_SIZE
return int((self.x + 0.5) * Config.LEVEL_SIZE), int((self.y + 0.5) * Config.LEVEL_SIZE)
def rotate_level(self, times_rotated):
"""