Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. room = Object:extend()
  2. require 'Ball'
  3.  
  4.  
  5. function room:new()
  6.  
  7.  self.game_objects = {}
  8.  Ball1 = Ball(love.graphics.getWidth()/2,love.graphics.getHeight()/2)
  9.  table.insert(self.game_objects,Ball1)
  10.  
  11. end
  12.  
  13. function room:update(dt)
  14.  
  15.   for i = #self.game_objects, 1, -1 do
  16.     active_object = self.game_objects[i]
  17.     active_object:update(dt)
  18.    
  19.   if self.detectOutOfBounds(active_object) then active_object:collision() end
  20.    
  21.   end
  22.  
  23. end
  24.  
  25. function room:draw()
  26.  
  27.   for _, game_object in ipairs(self.game_objects) do game_object:draw() end
  28.  
  29. end
  30.  
  31. function room:detectCollison(game_objectA, game_objectB)
  32.  
  33.   local aw, ah = game_objectA.image:getDimensions()
  34.   local bw, bh = game_objectB.image:getDimensions()
  35.  
  36.   return game_objectA.x < (game_objectB.x + bw) and
  37.   game_objectB.x < (game_objectA.x + aw) and
  38.   game_objectA.y < (game_objectB.y + bh) and
  39.   game_objectB.y < (game_objectA.y + ah)
  40.  
  41. end
  42.  
  43. function room:detectOutOfBounds(active_object)
  44.  
  45.   local aw, ah = active_object:getSize()
  46.    
  47.   return active_object.x > (love.graphics.getWidth() + aw) and
  48.   active_object.y > (love.graphics.getHeight() + ah) and
  49.   active_object.x < 0 and
  50.   active_object.y < 0
  51.  
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement