Up to this point, I have been able to do background collision in a fairly simple way, which in turn actually simplifies the game itself, but lends to it too many restrictions. Here is how I have handled background collision for games that have more than one screen of gameplay:
1.) Have four corners of player, each with its own X and Y (define these before gameplay)
2.) Have an X and Y fine movement
3.) If player moves left or right, decrement or increment the X fine movement respectively. The same goes with moving up or down, except it's the Y fine movement.
Now assume that the player has been moving left (at one pixel per frame). Also assume the collision table is in 16x16 tile representation.
4.) If the X fine movement hits 0, look up the tile that is NEXT to the top left corner on the left, and if it is solid, do not allow them to move. If that is clear, check the bottom left corner. If that is also clear, allow them to move and set the X fine movement to #$0f (if moving to the right, instead of checking for 0, you would check for #$0f before checking the tiles to the right).
If you want the player to move at a speed of 2, then it still would work, decrementing and incrementing the X and Y fine by 2 each time.
So, this method works fine for standard, basic games and purposes, but is not at all suited for variable speeds of the player. If I want the player to move at a speed of 1.5 pixels per frame, then I have to come up with another variable of something like... x_fine_extra and y_fine_extra or something. And then the code just starts getting carried away and almost illegible to even myself, the one who wrote it! haha
I have been looking at the page where tepples describes pushing a sprite out of solid walls, but can't for the life of me figure out how that is actually employed. I understand the concept of letting the player move, then after the fact, and before the frame is done, check if they are in a wall, and then push them out if they are. What I don't get is how to know how much to push them out, especially if you are using 16bit movement. And also, if you don't know what direction they were coming from, how to know what direction to push them out.
This feels like the biggest obstacle for me to being able to make slightly more complex games, but I just can't wrap my head around it.
1.) Have four corners of player, each with its own X and Y (define these before gameplay)
2.) Have an X and Y fine movement
3.) If player moves left or right, decrement or increment the X fine movement respectively. The same goes with moving up or down, except it's the Y fine movement.
Now assume that the player has been moving left (at one pixel per frame). Also assume the collision table is in 16x16 tile representation.
4.) If the X fine movement hits 0, look up the tile that is NEXT to the top left corner on the left, and if it is solid, do not allow them to move. If that is clear, check the bottom left corner. If that is also clear, allow them to move and set the X fine movement to #$0f (if moving to the right, instead of checking for 0, you would check for #$0f before checking the tiles to the right).
If you want the player to move at a speed of 2, then it still would work, decrementing and incrementing the X and Y fine by 2 each time.
So, this method works fine for standard, basic games and purposes, but is not at all suited for variable speeds of the player. If I want the player to move at a speed of 1.5 pixels per frame, then I have to come up with another variable of something like... x_fine_extra and y_fine_extra or something. And then the code just starts getting carried away and almost illegible to even myself, the one who wrote it! haha
I have been looking at the page where tepples describes pushing a sprite out of solid walls, but can't for the life of me figure out how that is actually employed. I understand the concept of letting the player move, then after the fact, and before the frame is done, check if they are in a wall, and then push them out if they are. What I don't get is how to know how much to push them out, especially if you are using 16bit movement. And also, if you don't know what direction they were coming from, how to know what direction to push them out.
This feels like the biggest obstacle for me to being able to make slightly more complex games, but I just can't wrap my head around it.