Hello, everyone. I have a little bit of programming experience, having messed with Python on and off over the years. I'm just now getting my feet wet in game development, and I've already run into a problem.
I want to make a simple maze game. The object of the game will be to navigate a white square from the upper-left corner of the screen to the bottom-right corner, through a simple maze. The problem I am having is this: how can I prevent the square from simply passing through the walls of the maze? Clearly, I need some way to make the walls "solid" so that the square cannot pass through them.
My first solution was this: every pixel occupied by a wall is stored in a huge list, as is every pixel occupied by the square. Each time the player presses an arrow key, the game checks to see if the pixel that the square is about to move into is occupied by a wall. It does this by taking each pixel occupied by the square, and checking it against each pixel occupied by any wall. If there are no "matches," the square moves. So, in pseudocode:
list1 = list of all pixels occupied by square
list2 = list of all pixels occupied by maze walls
if the user presses the "left" button:
Check to see if there are any "matches" between any pixel to the left of a pixel in list 1 and any pixel in list2
If there are any matches: the square stays stationary
Otherwise: the square moves
Although I got it to work, it was very slow. Can anyone give me a better method to keep track of where the walls and square are? More importantly, can anyone share some general principles for keeping track of objects on screen?
Edited by Pneum, 14 May 2014 - 06:43 PM.