Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- room = Object:extend()
- require 'Ball'
- function room:new()
- self.game_objects = {}
- Ball1 = Ball(love.graphics.getWidth()/2,love.graphics.getHeight()/2)
- table.insert(self.game_objects,Ball1)
- end
- function room:update(dt)
- for i = #self.game_objects, 1, -1 do
- active_object = self.game_objects[i]
- active_object:update(dt)
- if self.detectOutOfBounds(active_object) then active_object:collision() end
- end
- end
- function room:draw()
- for _, game_object in ipairs(self.game_objects) do game_object:draw() end
- end
- function room:detectCollison(game_objectA, game_objectB)
- local aw, ah = game_objectA.image:getDimensions()
- local bw, bh = game_objectB.image:getDimensions()
- return game_objectA.x < (game_objectB.x + bw) and
- game_objectB.x < (game_objectA.x + aw) and
- game_objectA.y < (game_objectB.y + bh) and
- game_objectB.y < (game_objectA.y + ah)
- end
- function room:detectOutOfBounds(active_object)
- local aw, ah = active_object:getSize()
- return active_object.x > (love.graphics.getWidth() + aw) and
- active_object.y > (love.graphics.getHeight() + ah) and
- active_object.x < 0 and
- active_object.y < 0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement