![]() |
|
Arcade Collision Problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: Arcade Collision Problem (/thread-22083.html) |
Arcade Collision Problem - randor - Oct-28-2019 Hello all, Ok, I found Python Arcade and wanted to play and see what I could come up with. I have been following some tutorials and videos but most of the ones I found are using the platform physics engine, I want to use the simple and do an overhead with character animation moving in 4 directions. I got as far as below, but for some reason, if i move left or right until i hit a wall, then try to go up or down it shoots the player off the screen and gives me : Quote:Error, collision while player wasn't moving. I found another thread that was similar but his issue was fixed by not calling the player.update() method, which I also took out, but it still happens. the weird thing is it only happens when i go left or right then up or down. If i go up or down to the wall, then left or right it works fine. import arcade
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 700
class MyGame(arcade.Window):
""" Main application class. """
def __init__(self, width, height):
super().__init__(width, height)
self.player_list = None
self.player = None
self.dt = None
self.player_list = arcade.SpriteList()
self.player = arcade.AnimatedWalkingSprite()
self.player_speed = 150
self.player.set_position(300, 300)
self.right = False
self.left = False
self.up = False
self.down = False
self.ground_list = None
self.wall_list = None
self.physics_engine = None
arcade.set_background_color(arcade.color.BLACK)
def setup(self):
my_map = arcade.read_tiled_map("Maps/MyMap2.tmx")
self.ground_list = arcade.generate_sprites(my_map, "Ground", 1)
self.wall_list = arcade.generate_sprites(my_map, "Walls", 1)
self.player.stand_right_textures = []
self.player.stand_right_textures.append(arcade.load_texture("Player/R_1.png"))
self.player.stand_left_textures = []
self.player.stand_left_textures.append(arcade.load_texture("Player/L_1.png"))
self.player.stand_up_textures = []
self.player.stand_up_textures.append(arcade.load_texture("Player/U_1.png"))
self.player.stand_down_textures = []
self.player.stand_down_textures.append(arcade.load_texture("Player/D_1.png"))
self.player.walk_right_textures = []
self.player.walk_right_textures.append(arcade.load_texture("Player/R_1.png"))
self.player.walk_right_textures.append(arcade.load_texture("Player/R_2.png"))
self.player.walk_right_textures.append(arcade.load_texture("Player/R_3.png"))
self.player.walk_right_textures.append(arcade.load_texture("Player/R_4.png"))
self.player.walk_left_textures = []
self.player.walk_left_textures.append(arcade.load_texture("Player/L_1.png"))
self.player.walk_left_textures.append(arcade.load_texture("Player/L_2.png"))
self.player.walk_left_textures.append(arcade.load_texture("Player/L_3.png"))
self.player.walk_left_textures.append(arcade.load_texture("Player/L_4.png"))
self.player.walk_up_textures = []
self.player.walk_up_textures.append(arcade.load_texture("Player/U_1.png"))
self.player.walk_up_textures.append(arcade.load_texture("Player/U_2.png"))
self.player.walk_up_textures.append(arcade.load_texture("Player/U_3.png"))
self.player.walk_up_textures.append(arcade.load_texture("Player/U_4.png"))
self.player.walk_down_textures = []
self.player.walk_down_textures.append(arcade.load_texture("Player/D_1.png"))
self.player.walk_down_textures.append(arcade.load_texture("Player/D_2.png"))
self.player.walk_down_textures.append(arcade.load_texture("Player/D_3.png"))
self.player.walk_down_textures.append(arcade.load_texture("Player/D_4.png"))
self.player_list.append(self.player)
self.physics_engine = arcade.PhysicsEngineSimple(self.player, self.wall_list)
def on_draw(self):
""" Render the screen. """
arcade.start_render()
self.ground_list.draw()
self.wall_list.draw()
self.player_list.draw()
def update(self, delta_time):
""" All the logic to move, and the game logic goes here. """
self.dt = delta_time
self.physics_engine.update()
self.player_list.update_animation()
def on_key_press(self, symbol, modifiers):
if symbol == arcade.key.RIGHT:
self.player.change_x = self.player_speed * self.dt
if symbol == arcade.key.LEFT:
self.player.change_x = -self.player_speed * self.dt
if symbol == arcade.key.UP:
self.player.change_y = self.player_speed * self.dt
if symbol == arcade.key.DOWN:
self.player.change_y = -self.player_speed * self.dt
def on_key_release(self, symbol, modifiers):
if symbol == arcade.key.RIGHT or arcade.key.LEFT:
self.player.change_x = 0
if symbol == arcade.key.UP or arcade.key.DOWN:
self.player.change_y = 0
def main():
game = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT)
game.setup()
arcade.run()
if __name__ == "__main__":
main()I appreciate any help and if you know of any overhead tutorials out there, i am pretty desperate to watch someone do it to learn from.Thanks.. |