source: skaapsteker/physics.py @ 23:5c9f2eeeb629

Last change on this file since 23:5c9f2eeeb629 was 23:5c9f2eeeb629, checked in by Simon Cross <hodgestar@…>, 10 years ago

Very start of world / physics engine.

File size: 674 bytes
Line 
1"""Model of gravity, acceleration, velocities and collisions.
2
3   Works very closely with sprites/base.py.
4   """
5
6import pygame.sprite
7
8
9class Sprite(pygame.sprite.Sprite):
10
11    mobile = True # whether the velocity may be non-zero
12    gravitates = True # whether gravity applies to the sprite
13
14
15class World(object):
16
17    def __init__(self):
18        self._all = pygame.sprite.Group()
19        self._mobiles = pygame.sprite.Group()
20        self._gravitators = pygame.sprite.Group()
21
22    def add(self, sprite):
23        self._all.add(sprite)
24        if sprite.mobile:
25            self._mobiles.add(sprite)
26        if sprite.gravitates:
27            self._gravitators.add(sprite)
Note: See TracBrowser for help on using the repository browser.