2 --all objects should descend from this
14 Object
.heading
= 0 --heading in degrees
15 Object
.speed
= 0 --speed in pixels
19 Object
.angular_velocity
= 0
21 Object
.image
= nil --this should hold the image of the Object
22 Object
.rects
= ObjectList
:new() --this field should hold the collision Rect objects
24 Object
.type = "Object" --for each class, this should be set to a unique identifier. it is used in collision detection
26 Object
.max_updates
= -1 --if set to a non-negative, non-zero number, object will automatically collect itself after this many updates
27 Object
.num_updates
= 0 --current count of updates
29 Object
.no_collide
= false --setting this to true will prevent it from colliding
30 Object
.collect
= false --set to true to cause resource manager to collect this object
32 function Object
:new(o
)
39 --updates the object's state
40 function Object
:update(delta
)
45 self
.x
= self
.x
+ math
.cos(math
.rad(self
.heading
)) * (self
.speed
* (delta
or 1))
46 self
.y
= self
.y
+ math
.sin(math
.rad(-1 * self
.heading
)) * (self
.speed
* (delta
or 1))
47 self
.rotation
= (self
.rotation
+ (self
.angular_velocity
* (delta
or 1))) % 360
49 --Object self-collect check (mostly for particle systems)
50 if self
.max_updates
> 0 then
51 self
.num_updates
= self
.num_updates
+ 1
52 if self
.num_updates
>= self
.max_updates
then
59 --default draw routine
60 function Object
:draw()
61 display(self
.image
, self
.x
-self
.x_offset
, self
.y
-self
.y_offset
, self
.rotation
, 1, 1)
64 --there is no predefined collision behavior
65 -- "ids" is the list of Rect ids that have been collided with
66 -- "object" is the Object that is colliding with this one
67 function Object
:collide(ids
, object
)
71 --returns the coordinate of the center
72 function Object
:get_center()
73 return math
.floor(self
.x
+ (self
.w
/2)), math
.floor(self
.y
+ (self
.h
/2))
76 --sets the drawing offset of the sprite
77 function Object
:set_origin(x
,y
)
82 --unloads resources and nils out the class' table
83 -- There is no defined behavior for this function in the Object class.
84 function Object
:unload()
85 --normally, resources would be unloaded here
86 --and one would put a line such as
87 --ClassName = nil at the end