mirror of
https://github.com/n0remac/2020GameJamPractice.git
synced 2025-12-06 01:13:10 -06:00
Merge pull request #3 from n0remac/UserControls
Added movement and crate tile
This commit is contained in:
BIN
images/Tiles/platformPack_tile028.png
Normal file
BIN
images/Tiles/platformPack_tile028.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
@@ -13,6 +13,9 @@ CHARACTER_SCALING = 1
|
||||
TILE_SCALING = 1
|
||||
COIN_SCALING = 0.5
|
||||
|
||||
# Movement speed of player, in pixels per frame
|
||||
PLAYER_MOVEMENT_SPEED = 5
|
||||
|
||||
|
||||
class MyGame(arcade.Window):
|
||||
"""
|
||||
@@ -33,6 +36,9 @@ class MyGame(arcade.Window):
|
||||
# Separate variable that holds the player sprite
|
||||
self.player_sprite = None
|
||||
|
||||
# Our physics engine
|
||||
self.physics_engine = None
|
||||
|
||||
arcade.set_background_color(arcade.csscolor.CORNFLOWER_BLUE)
|
||||
|
||||
def setup(self):
|
||||
@@ -69,6 +75,9 @@ class MyGame(arcade.Window):
|
||||
wall.position = coordinate
|
||||
self.wall_list.append(wall)
|
||||
|
||||
# Create the 'physics engine'
|
||||
self.physics_engine = arcade.PhysicsEngineSimple(self.player_sprite, self.wall_list)
|
||||
|
||||
def on_draw(self):
|
||||
""" Render the screen. """
|
||||
|
||||
@@ -80,6 +89,36 @@ class MyGame(arcade.Window):
|
||||
self.coin_list.draw()
|
||||
self.player_list.draw()
|
||||
|
||||
def on_key_press(self, key, modifiers):
|
||||
"""Called whenever a key is pressed. """
|
||||
|
||||
if key == arcade.key.UP or key == arcade.key.W:
|
||||
self.player_sprite.change_y = PLAYER_MOVEMENT_SPEED
|
||||
elif key == arcade.key.DOWN or key == arcade.key.S:
|
||||
self.player_sprite.change_y = -PLAYER_MOVEMENT_SPEED
|
||||
elif key == arcade.key.LEFT or key == arcade.key.A:
|
||||
self.player_sprite.change_x = -PLAYER_MOVEMENT_SPEED
|
||||
elif key == arcade.key.RIGHT or key == arcade.key.D:
|
||||
self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED
|
||||
|
||||
def on_key_release(self, key, modifiers):
|
||||
"""Called when the user releases a key. """
|
||||
|
||||
if key == arcade.key.UP or key == arcade.key.W:
|
||||
self.player_sprite.change_y = 0
|
||||
elif key == arcade.key.DOWN or key == arcade.key.S:
|
||||
self.player_sprite.change_y = 0
|
||||
elif key == arcade.key.LEFT or key == arcade.key.A:
|
||||
self.player_sprite.change_x = 0
|
||||
elif key == arcade.key.RIGHT or key == arcade.key.D:
|
||||
self.player_sprite.change_x = 0
|
||||
|
||||
def on_update(self, delta_time):
|
||||
""" Movement and game logic """
|
||||
|
||||
# Move the player with the physics engine
|
||||
self.physics_engine.update()
|
||||
|
||||
|
||||
def main():
|
||||
""" Main method """
|
||||
|
||||
Reference in New Issue
Block a user