fix mob movement

This commit is contained in:
Xevion
2020-04-21 18:44:54 -05:00
parent 9b133749af
commit 3d5b0f636c
3 changed files with 20 additions and 11 deletions

View File

@@ -28,14 +28,14 @@ class Config(object):
# Constants used to scale our sprites from their original size
CHARACTER_SCALING = 1
TILE_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
# Movement speed of player, in pixels per frame
PLAYER_MOVEMENT_SPEED = 7
PLAYER_MOVEMENT_SPEED = 14
# How many pixels to keep as a minimum margin between the characters and the edge of the screen.
LEFT_VIEWPORT_MARGIN = 250

View File

@@ -186,6 +186,10 @@ class Game(arcade.Window):
"""
Called whenever the mouse is clicked.
"""
for mob in self.enemy_list:
mob.center_x, mob.center_y = random.choice(self.dungeon.levelList).center()
# Create a bullet TEMP SPRITE, currently wielding frog slingshot
bullet = Temp()
# Position the bullet at the player's current location
@@ -259,6 +263,8 @@ class Game(arcade.Window):
self.view_bottom,
Config.SCREEN_HEIGHT + self.view_bottom)
self.enemy_list.update()
# Projectile updates
self.bullet_list.update()
for bullet in self.bullet_list:

View File

@@ -44,22 +44,25 @@ class Mob(arcade.Sprite):
"""
A on_update function, the Mob should decide it's next actions here.
"""
pos, next = self.nearestPosition(), path[0]
curpos, nextpos = self.nearestPosition(), path[1]
print(curpos, nextpos)
if next[0] > pos[0]:
self.change_x = Config.PLAYER_MOVEMENT_SPEED
elif next[0] < pos[0]:
self.change_x = -Config.PLAYER_MOVEMENT_SPEED
if nextpos[0] > curpos[0]:
self.change_x = Config.PLAYER_MOVEMENT_SPEED - 3
elif nextpos[0] < curpos[0]:
self.change_x = -Config.PLAYER_MOVEMENT_SPEED + 3
else:
self.change_x = 0
if next[1] > pos[1]:
self.change_y = Config.PLAYER_MOVEMENT_SPEED
elif next[1] < pos[1]:
self.change_y = Config.PLAYER_MOVEMENT_SPEED
if nextpos[1] > curpos[1]:
self.change_y = Config.PLAYER_MOVEMENT_SPEED - 3
elif nextpos[1] < curpos[1]:
self.change_y = -Config.PLAYER_MOVEMENT_SPEED + 3
else:
self.change_y = 0
print(self.change_x, self.change_y)
def get_path(self, end: Tuple[int, int] = None) -> List[Tuple[int, int]]:
"""
Returns the path to get to the Mob's target in absolute integer positions.