Is there a way to disable collisions?

176 views Asked by At

I'm building a game in Python Arcade which will have a NEAT AI run through the level. I am trying to find a way for the multiple instances of the player to run at the same time but without colliding. Is there a way to do this? Collision types just seem to handle the collisions once they happen, instead of preventing them. I need them to be able to collide with the floor and items, without colliding with other "players".

1

There are 1 answers

0
Alderven On

You can create two SpriteLists: one for players and one for items and then check collisions for players vs items and not between players.

Example:

import arcade

class Collision(arcade.Window):
    def __init__(self):
        super().__init__(600, 200, 'Collision!')
        self.text = ''
        self.players = arcade.SpriteList()
        self.player1 = arcade.Sprite(':resources:images/animated_characters/male_person/malePerson_idle.png', center_x=50, center_y=100)
        player2 = arcade.Sprite(':resources:images/animated_characters/female_person/femalePerson_idle.png', center_x=200, center_y=100)
        self.players.extend([player2, self.player1])
        self.items = arcade.SpriteList()
        item = arcade.Sprite(':resources:images/items/star.png', center_x=400, center_y=90)
        self.items.append(item)

    def on_draw(self):
        arcade.start_render()
        self.items.draw()
        self.players.draw()
        arcade.draw_text(self.text, 250, 160, arcade.color.RED, 24)

    def update(self, delta_time: float):
        self.player1.center_x += 2

        if arcade.check_for_collision_with_list(self.player1, self.items):
            self.text = 'Collide!'
        else:
            self.text = ''

Collision()
arcade.run()

Output:

enter image description here