MyObj = Object:new() MyObj.attr1 = 4 MyObj.attr2 = "some value" --constructor function MyObj:new(o) o = o or {} setmetatable(o, self) self.__index = self return o end --other methods defined here
Italics means private (in the sense that they shouldn't be set manually).
| Attribute | Description |
|---|---|
| x | x position (on screen) |
| y | y position (on screen) |
| w | width |
| h | height |
| x_offset | drawing offset |
| y_offset | drawing offset |
| angle | movement heading in degrees |
| speed | speed (in pixels/update) |
| image | image of the Object |
| rects | list of collision Rects |
| type | type of Object (for collision) |
| max_updates | maximum number of updates before Object self collects |
| num_updates | current number of updates |
| death_anim | flag for if Object is in death animation (affects collision) |
| collect | flag to indicate if an Object should be collected |
| Method | Description |
|---|---|
| new(o) | constructor |
| update() | updates the Object's state |
| draw() | draws the Object's image at (x, y) |
| collide(ids, object) | method executed upon collision (undefined for base class) |
| get_center() | returns the center coordinates of the Object |
| set_origin() | sets the drawing offset (sprite is offset by these amounts to the upper left) |
This class is not designed to be instantiated directly, instead it should be extended and serve as the base for all in-game objects. An example object definition is as follows:
MyObj = Object:new() MyObj.attr1 = 4 MyObj.attr2 = "some value" --constructor function MyObj:new(o) o = o or {} setmetatable(o, self) self.__index = self return o end --other methods defined here