Adding Enemies

To add enemy to our game we are going to follow the below steps:

  • First, we will create a variable to store the enemy sprite.

Syntax:

 self.enemy = None
  • After that, we will create one more variable to store the velocity of the enemy.

Syntax:

self.enemy_move = velocity
  • Store our enemy sprite in the enemy variable.

Syntax:

self.enemy = arcade.Sprite("path",1)
  • Set the initial coordinates.

Syntax:

self.enemy.center_x = value
self.enemy.center_y = value
  • Add the enemy sprite in the scene.

Syntax:

self.scene.add_sprite("Enemy", self.enemy)
  • Move the enemy by changing the x coordinate.

Syntax:

self.enemy.center_x += self.enemy_move
  • Check for collisions between the player and enemy.

Syntax:

enemy_collide = arcade.check_for_collision_with_list(

            self.player_sprite, self.scene.get_sprite_list(“Enemy”)

        )

  • If they are colliding then remove the player sprite.

Syntax:

for enemy in enemy_collide:

      self.player_sprite.remove_from_sprite_lists()

Python Arcade – Adding Enemies

In this article, we will learn How we can add enemies in arcade.

Similar Reads

Adding Enemies

To add enemy to our game we are going to follow the below steps:...

Functions Used:

draw_text(): This function is used to draw text to the screen using Pyglet’s label....

Sprites Used:

...

Killing the Enemy

...

Contact Us