Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Game Programming By Example

You're reading from   Python Game Programming By Example A pragmatic guide for developing your own games with Python

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781785281532
Length 230 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Gravitation game

To put into practice what you have learned about steering behaviors, we will build a basic game. The player's objective is to collect some pickup items that rotate around different planets placed in the world, while escaping from enemies. The enemies are non-playable characters that seek the playable character and avoid the planets.

We will represent the characters as particle systems, and the final version of the game will look like this:

Gravitation game

Basic game objects

As usual, we will define a base class that wraps the access to the CircleShape attribute with the updated center:

from cocos.cocosnode import CocosNode
from cocos.director import director
import cocos.collision_model as cm

class Actor(CocosNode):
    def __init__(self, x, y, r):
        super(Actor, self).__init__()
        self.position = (x, y)
        self._cshape = cm.CircleShape(self.position, r)

    @property
    def cshape(self):
        self._cshape.center = eu.Vector2(self.x, self.y)
        return self...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime