1platform = class:new() 2 3function platform:init(x, y, dir, size) 4 --PHYSICS STUFF 5 self.size = size or 2 6 if (self.size ~= math.floor(self.size)) then 7 self.x = x-self.size/2-0.5 8 else 9 self.x = x-1 10 end 11 self.y = y-15/16 12 self.startx = self.x 13 self.starty = self.y 14 self.speedx = 0 --! 15 self.speedy = 0 16 self.width = self.size 17 self.height = 8/16 18 self.static = true 19 self.active = true 20 self.category = 15 21 self.mask = {true} 22 self.gravity = 0 23 24 --IMAGE STUFF 25 self.drawable = false 26 27 self.rotation = 0 28 29 self.dir = dir --(Right, up, Justup, Justdown, justright(bonus stage), fall) 30 self.timer = 0 31 32 if self.dir == "justup" then 33 self.speedy = -platformjustspeed 34 elseif self.dir == "justdown" then 35 self.speedy = platformjustspeed 36 end 37end 38 39function platform:func(i) -- 0-1 in please 40 return (-math.cos(i*math.pi*2)+1)/2 41end 42 43function platform:update(dt) 44 if self.dir == "right" or self.dir == "up" then 45 self.timer = self.timer + dt 46 47 if self.dir == "right" then 48 while self.timer > platformhortime do 49 self.timer = self.timer - platformhortime 50 end 51 local newx = (self.startx) - self:func(self.timer/platformhortime)*platformhordistance 52 self.speedx = (newx-self.x)/dt 53 end 54 55 if self.dir == "up" then 56 while self.timer > platformvertime do 57 self.timer = self.timer - platformvertime 58 end 59 local newy = self:func(self.timer/platformvertime)*platformverdistance + (self.starty-15/16) 60 self.speedy = (newy-self.y)/dt 61 end 62 end 63 64 if self.dir == "right" or self.dir == "justright" then 65 self.x = self.x + self.speedx*dt 66 local checktable = {} 67 for i, v in pairs(enemies) do 68 if objects[v] and underwater == false then 69 table.insert(checktable, v) 70 end 71 end 72 table.insert(checktable, "player") 73 74 for i, v in pairs(checktable) do 75 for j, w in pairs(objects[v]) do 76 if inrange(w.x, self.x-w.width, self.x+self.width) then 77 if w.y == self.y - w.height then 78 if #checkrect(w.x+self.speedx*dt, w.y, w.width, w.height, {"exclude", w}, true) == 0 then 79 w.x = w.x + self.speedx*dt 80 end 81 end 82 end 83 end 84 end 85 elseif self.dir == "up" or self.dir == "justup" or self.dir == "justdown" then 86 if self.dir == "justup" then 87 self.speedy = -platformjustspeed 88 end 89 90 local checktable = {} 91 for i, v in pairs(enemies) do 92 if objects[v] and underwater == false then 93 table.insert(checktable, v) 94 end 95 end 96 table.insert(checktable, "player") 97 98 for i, v in pairs(checktable) do 99 for j, w in pairs(objects[v]) do 100 if not w.jumping and inrange(w.x, self.x-w.width, self.x+self.width) then 101 if inrange(w.y, self.y - w.height - 0.1, self.y - w.height + 0.1) then 102 w.y = self.y - w.height + self.speedy*dt 103 end 104 end 105 end 106 end 107 108 self.y = self.y + self.speedy*dt 109 elseif self.dir == "fall" then 110 local checktable = {} 111 for i, v in pairs(enemies) do 112 if objects[v] and underwater == false then 113 table.insert(checktable, v) 114 end 115 end 116 table.insert(checktable, "player") 117 118 local numberofobjects = 0 119 for i, v in pairs(checktable) do 120 for j, w in pairs(objects[v]) do 121 if not w.jumping and inrange(w.x, self.x-w.width, self.x+self.width) then 122 if inrange(w.y, self.y - w.height - 0.1, self.y - w.height + 0.1) then 123 numberofobjects = numberofobjects + 1 124 if #checkrect(w.x, w.y, w.width, w.height, {"exclude", w}) == 0 then 125 w.y = self.y - w.height + self.speedy*dt 126 end 127 end 128 end 129 end 130 end 131 132 self.speedy = numberofobjects*4 133 134 self.y = self.y + self.speedy*dt 135 end 136 137 if self.dir == "justup" and self.y < -1 then 138 return true 139 elseif (self.dir == "justdown" or self.dir == "fall") and self.y > 16 then 140 return true 141 end 142 143 return false 144end 145 146function platform:draw() 147 for i = 1, self.size do 148 if self.dir ~= "justright" then 149 love.graphics.draw(platformimg, math.floor((self.x+i-1-xscroll)*16*scale), math.floor((self.y-8/16)*16*scale), 0, scale, scale) 150 else 151 love.graphics.draw(platformbonusimg, math.floor((self.x+i-1-xscroll)*16*scale), math.floor((self.y-8/16)*16*scale), 0, scale, scale) 152 end 153 end 154 155 if math.ceil(self.size) ~= self.size then --draw 1 more on the rightest 156 love.graphics.draw(platformimg, math.floor((self.x+self.size-1-xscroll)*16*scale), math.floor((self.y-8/16)*16*scale), 0, scale, scale) 157 end 158end 159 160function platform:rightcollide(a, b) 161 return false 162end 163 164function platform:leftcollide(a, b) 165 return false 166end 167 168function platform:ceilcollide(a, b) 169 if self.dir == "justright" then 170 self.speedx = platformbonusspeed 171 end 172 return false 173end 174 175function platform:floorcollide(a, b) 176 return false 177end 178 179function platform:passivecollide(a, b) 180 return false 181end