/zoeplat

To get this branch, use:
bzr branch http://9ix.org/bzr/zoeplat

« back to all changes in this revision

Viewing changes to zoetrope/core/sprite.lua

  • Committer: Josh C
  • Date: 2013-04-21 20:40:19 UTC
  • Revision ID: josh@9ix.org-20130421204019-14mx4bztdt4wnbg6
automated build script - pull love win/mac & assemble the parts

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
-- Extends:
16
16
--              <Class>
17
17
--
18
 
--
19
18
-- Event: onUpdate
20
19
-- Called once each frame, with the elapsed time since the last frame in seconds.
21
20
--
204
201
        end,
205
202
 
206
203
        -- Method: collide
207
 
        -- Checks whether sprites collide by checking rectangles. If a collision is detected,
 
204
        -- Checks whether this sprite collides with other <Sprite>s ad <Group>s. If a collision is detected,
208
205
        -- onCollide() is called on both this sprite and the one it collides with, passing
209
206
        -- the amount of horizontal and vertical overlap between the sprites in pixels.
210
207
        --
211
208
        -- Arguments:
212
 
        --              other - <Sprite> or <Group> to collide
 
209
        --              ... - any number of <Sprite>s or <Group>s to collide with.
213
210
        --
214
211
        -- Returns:
215
 
        --              boolean, whether any collision was detected
216
 
 
217
 
        collide = function (self, other)
218
 
                if not self.solid or not other.solid or self == other then return false end
219
 
 
220
 
                if other.sprites then
221
 
                        return other:collide(self)
222
 
                else
223
 
                        local xOverlap, yOverlap = self:overlap(other.x, other.y, other.width, other.height)
224
 
 
225
 
                        if xOverlap ~= 0 or yOverlap ~= 0 then  
226
 
                                if self.onCollide then
227
 
                                        self:onCollide(other, xOverlap, yOverlap)
228
 
                                end
229
 
                                
230
 
                                if other.onCollide then
231
 
                                        other:onCollide(self, xOverlap, yOverlap)
232
 
                                end
233
 
 
234
 
                                return true
235
 
                        end
236
 
                end
237
 
 
238
 
                return false
 
212
        --              nothing
 
213
 
 
214
        collide = function (self, ...)
 
215
                Collision:check(self, ...)
239
216
        end,
240
217
 
241
218
        -- Method: displace
457
434
        end,
458
435
 
459
436
        draw = function (self, x, y)
460
 
                if self.onDraw then self:onDraw(x, y) end
 
437
                -- subclasses do interesting things here
 
438
        end,
 
439
 
 
440
        collidedWith = function (self, other, xOverlap, yOverlap)
 
441
                if self.onCollide then self:onCollide(other, xOverlap, yOverlap) end
461
442
        end
462
443
}