Better Way For Collision In Lua?
The way I'm using collision for walls so far is this. I've made a function which is:
So basicly it creates a square or rectangle area which cannot be walked through by the player. It is called in the game like so:
if x > x1 and x < x2 and y > y1 and y < y2 then
x = oldx
y = oldy
The annoying part is that for every single wall I have to manually get the coordinates to make collision for that wall. I'm sure someone has a better and quicker way, if so I'd like to know.
wallcollision(0,450,0,14) -- top wall
wallcollision(87,123,0,93) -- top up and down left side
wallcollision(337,374,0,92) -- top up and down right side
wallcollision(0,15,0,271) -- left side wall
wallcollision(0,166,162,196) -- mid wall left to right left side
wallcollision(0,470,243,271) -- bottom wall
wallcollision(224,262,56,97) -- middle square piece
wallcollision(205,275,95,182) -- middle round piece
wallcollision(447,480,0,280) -- right side wall