1cubedispenser = class:new() 2 3function cubedispenser:init(x, y, r) 4 --PHYSICS STUFF 5 self.cox = x 6 self.coy = y 7 self.x = x-1 8 self.y = y-1 9 self.speedy = 0 10 self.speedx = 0 11 self.width = 2 12 self.height = 2 13 self.static = true 14 self.active = true 15 self.category = 7 16 self.mask = {true, false, false, false, false, false, false, false, true} 17 18 self.r = r 19 self.timer = cubedispensertime 20 self.inputactive = false 21 self.boxexists = false 22 self.box = nil 23end 24 25function cubedispenser:input(t) 26 if t == "on" or t == "toggle" then 27 if self.boxexists then 28 self.boxexists = false 29 self:removebox() 30 end 31 32 if self.timer == cubedispensertime then 33 self.timer = 0 34 end 35 end 36end 37 38function cubedispenser:link() 39 self.outtable = {} 40 if #self.r > 2 then 41 for j, w in pairs(outputs) do 42 for i, v in pairs(objects[w]) do 43 if tonumber(self.r[4]) == v.cox and tonumber(self.r[5]) == v.coy then 44 v:addoutput(self) 45 if entityquads[map[v.cox][v.coy][2]].t == "box" then 46 self.boxexists = true 47 end 48 end 49 end 50 end 51 end 52end 53 54function cubedispenser:update(dt) 55 if self.timer < cubedispensertime then 56 self.timer = self.timer + dt 57 58 if self.timer > 0.1 and self.timer <= 0.4 and self.active == true then 59 self.active = false 60 elseif self.timer > 0.4 and self.timer <= 0.6 and self.active == false then 61 self.active = true 62 elseif self.timer > 0.6 and self.boxexists == false then 63 local temp = box:new(self.cox+.5, self.coy) 64 table.insert(objects["box"], temp) 65 self.box = temp 66 objects["box"][#objects["box"]]:addoutput(self) 67 self.boxexists = true 68 elseif self.timer > 1 then 69 self.timer = 1 70 end 71 end 72 return false 73end 74 75function cubedispenser:draw() 76 love.graphics.draw(cubedispenserimg, math.floor((self.cox-xscroll-1)*16*scale), (self.coy-1.5)*16*scale, 0, scale, scale, 0, 0) 77end 78 79function cubedispenser:removebox() 80 if self.box then 81 self.box.userect.delete = true 82 self.box.destroying = true 83 end 84end