Chapter 11. Modeling Enemies

The “game” as it stands is probably more fun for you to play, since you wrote it, than for anyone else. Truth be told, it’s kind of boring. What it needs is a little anxiety, a thrill of the chase, and a way to keep score.

The behavior of enemies should be relatively straightforward. Each one will start somewhere off the screen and then drift toward the character in the center at a constant rate of speed. Eventually, the growing character and the moving enemy collide. Depending on whether the character is safe or not, the enemies’ points will be absorbed by the player, or the player will die. The enemy will also have a score associated with it; the farther it is from the center of the screen, the higher the score.

Periodic Random Enemies

The enemy will be a FloatLayout with some basic graphics and a label with the current score. Start by creating this class in As shown in Example 11-1, you should put a couple properties on the class. The first represents the current score the player can achieve by killing this enemy. Later you’ll set this score depending on the distance the enemy is from the center. The second is the velocity at which the enemy is approaching you. We’ll discuss why the velocity is a list of two values shortly.

You’ll need to import the base class using from kivy.uix.floatlayout import FloatLayout, and the ListProperty using from import ListProperty.

Example 11-1. Enemy class with a score property
class Enemy(FloatLayout ...

Get Creating Apps in Kivy now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.