Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arcade Collision Problem
#1
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..
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [PyGame] Problem with collision of player and enemy Nekotrooper 1 600 Dec-08-2023, 03:29 PM
Last Post: deanhystad
  can't get collision detection to work in platform game chairmanme0wme0w 10 3,660 Aug-19-2022, 03:51 PM
Last Post: deanhystad
  [PyGame] Collision in not happening onizuka 3 3,359 Sep-07-2020, 11:30 AM
Last Post: metulburr
  [PyGame] No collision detection onizuka 6 3,596 Aug-18-2020, 01:29 PM
Last Post: onizuka
  Problem with collision detection... michael1789 4 3,218 Nov-12-2019, 07:49 PM
Last Post: michael1789
  Multiple wall collision in pacman rustyjoe 4 4,029 Aug-11-2019, 08:08 AM
Last Post: rustyjoe
  drawing, moving, and collision problems (pygame) SheeppOSU 26 14,429 Apr-22-2019, 03:09 AM
Last Post: SheeppOSU
  [PyGame] Community Project: Python Arcade Collab Mekire 3 3,756 Mar-26-2018, 01:12 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020