Pythonista: animation and sounds

The Alien walks better

In this video we will see how to animate the alien while he moves.

Let’s continue our video game made with Pythonista, app for Ipad.

How to flip an image so that you need the half of texture for a Sprite? Withthe x_scale parameter that if is -1 will flip the image. So the problem is how to assign -1 when he goes towards left. We will use the g.x value, that is negative when we tilt the Ipad towards left. The logic is this

((g.x >0) – (gx <0))

Let’s see the possible scenarios:

  1. g.x is tilted to the right
    1. g.x is positive
    2. g.x > 0 is True = 1
    3. g.x < 0 is False = 0
    4. (g.x. >0) – (g.x <0) = 1 – 0 = 1 aka No FLIP of image
  2. g.x is tilted to the left
    1. g.x is negative
    2. g.x > 0 is False = 0
    3. g.x < 0 is True = 1
    4. (g.x. >0) – (g.x <0) = 0 – 1 = -1 aka FLIP the image!

So this is the logic that makes the image flip when you go left.

self.player.x_scale = ((g.x >0) – (g.x <0))

The video will explain better where to put this line of code in the game code.

Adding the sound when he walks

Now let’s add the sound of the steps when he walks.

External links

Video about pythonista in classroom

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.