Entity
Bases: pygame.sprite.Sprite
Finite State Machine:
self.state
is executed every tickself.tick
is incremented every time the main game loop executes- when
self.state
changes,self.tick
is set to 0, so you can track how long the entity has been in its current state
Hierarchical structure:
Entities
can be added toGroups
to create a hierarchical structure- The order of groups in the .child_groups attribute determines the draw order; it's basically the layers
Example game structure:
Game: Entity
└── scenes: Group
└── MainMenu: Entity
├── buttons: Group
│ ├── Button: Entity
│ ├── Button: Entity
│ └── Button: Entity
└── sliders: Group
├── Slider: Entity
└── Slider: Entity
Source code in robingame/objects/entity.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
state
property
writable
Execute the current state function.
draw(surface, debug=False)
Draw all child groups. This allows the entire tree of objects to draw by only calling the .draw() method of the root object.
Parameters: |
|
---|
robingame/objects/entity.py
65 66 67 68 69 70 71 72 73 74 75 76 |
|
kill()
Removes self from all groups.
robingame/objects/entity.py
78 79 80 81 82 |
|
update()
Execute self.state
.
Call .update()
on all child groups. This allows the entire tree of objects to update by
only calling the .update()
method of the root object.
Subclasses can override this method to provide subclass-specific behaviour. However, it's generally a better idea to write state functions and allow the Entity's Finite State Machine mechanism to execute them.
Increment self.tick
to keep track of how long we've been in the current state.
robingame/objects/entity.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|