1door = class:new() 2 3function door:init(x, y, r, dir) 4 self.cox = x 5 self.coy = y 6 self.r = r 7 self.dir = dir 8 9 self.open = false 10 self.timer = 0 11 12 --PHYSICS STUFF 13 if self.dir == "hor" then 14 self.x = x-1 15 self.y = y-12/16 16 self.width = 32/16 17 self.height = 8/16 18 else 19 self.x = x-12/16 20 self.y = y-2 21 self.width = 8/16 22 self.height = 32/16 23 end 24 self.category = 25 25 26 self.mask = {true} 27 28 self.static = true 29 self.active = true 30 31 self.drawable = false 32 self.firstupdate = true 33end 34 35function door:link() 36 self.outtable = {} 37 if #self.r > 2 then 38 for j, w in pairs(outputs) do 39 for i, v in pairs(objects[w]) do 40 if tonumber(self.r[4]) == v.cox and tonumber(self.r[5]) == v.coy then 41 v:addoutput(self) 42 end 43 end 44 end 45 end 46end 47 48function door:update(dt) 49 if self.firstupdate then 50 self.firstupdate = false 51 for i, v in pairs(objects["laser"]) do 52 v:updaterange() 53 end 54 for i, v in pairs(objects["lightbridge"]) do 55 v:updaterange() 56 end 57 end 58 59 if self.open then 60 if self.timer < 1 then 61 self.timer = self.timer + doorspeed*dt 62 if self.timer >= 1 then 63 self.timer = 1 64 self.active = false 65 for i, v in pairs(objects["laser"]) do 66 v:updaterange() 67 end 68 for i, v in pairs(objects["lightbridge"]) do 69 v:updaterange() 70 end 71 end 72 end 73 else 74 if self.timer > 0 then 75 self.timer = self.timer - doorspeed*dt 76 if self.timer <= 0 then 77 self.timer = 0 78 end 79 end 80 end 81end 82 83function door:draw() 84 local ymod = 0 85 local rot = math.pi/2 86 if self.timer > 0.5 then 87 ymod = (self.timer - 0.5) * 2 88 else 89 rot = self.timer * math.pi 90 end 91 92 if self.dir == "hor" then 93 love.graphics.draw(doorpieceimg, math.floor((self.x+14/16-xscroll-ymod)*16*scale), (self.y-4/16)*16*scale, math.pi*.5, scale, scale, 4, 0) 94 love.graphics.draw(doorpieceimg, math.floor((self.x+18/16-xscroll+ymod)*16*scale), (self.y-4/16)*16*scale, math.pi*1.5, scale, scale, 4, 0) 95 love.graphics.draw(doorcenterimg, math.floor((self.x+16/16-xscroll-ymod)*16*scale), (self.y-4/16)*16*scale, math.pi*.5-rot, scale, scale, 4, 2) 96 love.graphics.draw(doorcenterimg, math.floor((self.x+16/16-xscroll+ymod)*16*scale), (self.y-4/16)*16*scale, math.pi*1.5-rot, scale, scale, 4, 2) 97 else 98 love.graphics.draw(doorpieceimg, math.floor((self.x+0.25-xscroll)*16*scale), (self.y+6/16-ymod)*16*scale, math.pi, scale, scale, 4, 0) 99 love.graphics.draw(doorpieceimg, math.floor((self.x+0.25-xscroll)*16*scale), (self.y+10/16+ymod)*16*scale, 0, scale, scale, 4, 0) 100 love.graphics.draw(doorcenterimg, math.floor((self.x+0.25-xscroll)*16*scale), (self.y+8/16-ymod)*16*scale, rot, scale, scale, 4, 2) 101 love.graphics.draw(doorcenterimg, math.floor((self.x+0.25-xscroll)*16*scale), (self.y+8/16+ymod)*16*scale, math.pi+rot, scale, scale, 4, 2) 102 end 103end 104 105function door:pushstuff() 106 local col = checkrect(self.x, self.y, self.width, self.height, "all") 107 for i = 1, #col, 2 do 108 local v = objects[col[i]][col[i+1]] 109 if self.dir == "ver" then 110 if v.speedx >= 0 then 111 v.x = self.x - v.width 112 else 113 v.x = self.x + self.width 114 end 115 elseif self.dir == "hor" then 116 if v.speedy >= 0 then 117 v.y = self.y - v.height 118 else 119 v.y = self.y + self.height 120 end 121 end 122 end 123end 124 125function door:input(t) 126 local prev = self.open 127 if t == "on" then 128 self.open = true 129 if self.timer == 1 then 130 self.active = false 131 end 132 elseif t == "off" then 133 self.open = false 134 self.active = true 135 self:pushstuff() 136 elseif t == "toggle" then 137 self.open = not self.open 138 139 if self.open then 140 if self.timer == 1 then 141 self.active = false 142 end 143 else 144 self.active = true 145 self:pushstuff() 146 end 147 end 148 149 if self.open ~= prev then 150 for i, v in pairs(objects["laser"]) do 151 v:updaterange() 152 end 153 for i, v in pairs(objects["lightbridge"]) do 154 v:updaterange() 155 end 156 end 157end