I have been working on a 2D platformer for the fun of it for a while. I made a few games, but none quite like this.
I am however lost when it comes to collision. I have made some collision, but its absolutely miserable, so I want to do it a different way. I’ll describe what I’m doing, but since code is what really shows what happens, the github is https://github.com/andreja6/Platformer. I will have any classes clickable as well.
So the Level is based on a 2D array of bricks, which have a collision boolean either enabled or disabled. They also have a collectable boolean which I may just do another way. The 2D array is mapped exactly like the map, but x16 in scale when drawn on map, so each block is 16x16 pixels wide, and that is scaled further to fit the GamePanel. For instance, level.block[0][0] starts at position 0,0 and is drawn to 16,16. level.block[1][0] starts at position 16,0 and is drawn to 32,16.
The collision is currently done by checking if any blocks come in between the path of the user, which is calculated in GameTick and GamePanel,
This seemed like an OK way of doing this at first, but with implementation it is incredibly glitchy and I ended up writing more code than I’d expect something like this to require. By the end the amount of times functions are called and the amount of variables make it seem inefficient, but more importantly make it nearly impossible to figure out why something wont work.
One idea I have is generating a collision map using polygons on start, and having blocks return their own collision map, so tilted blocks and round blocks would actually be possible, and then checking whether the players movement would intersect. This is only an idea and i’m not sure how to implement it yet.
Does anyone have any better suggestions or how to improve? This is my first time doing something like this so just a warning, you may facepalm so hard that your hand phases through you, just like my awful collision
Any suggestions would be greatly appreciated