Well, you could do it a pratically infinite number of different ways, it just depends on what suits your situation best.
Taking your example of:
a character that's 80x80 pixels
wall that's 10x60 pixels
enemy that's 20x20 pixels
Looks like the number 10 evenly divides into all of those images, so a grid that has elements that each represent a 10x10 pixel square could be a good choice.
Assuming your game was on a 640x480 screen, that would require an Array with 64 x 48 elements (3072).
To check if your character collided with an obstacle, you would perform a check between the characters X,Y coordinate and whatever 'block' would be behind the character.
For example, assume that you have a 64x48 grid (made up of 10x10 squares).
Assume that the character is at the location 118, 30.
Assume that the grid coordinate 19,3 is empty.
Assume that the grid coordinate 20,3 is a wall.
If you want to move the character 1 pixel to the right (location 119) then check if grid 19,3
If you want to move the character 1 more pixel to the right (location 120) then check if grid 20,3
How it works:
Floor removes any decimals left from the division
119 is the location you want to check
80 is the width of your character (since you are moving right, you need to check the right side)
10 is the width of each grid space
Taking your example of:
a character that's 80x80 pixels
wall that's 10x60 pixels
enemy that's 20x20 pixels
Looks like the number 10 evenly divides into all of those images, so a grid that has elements that each represent a 10x10 pixel square could be a good choice.
Assuming your game was on a 640x480 screen, that would require an Array with 64 x 48 elements (3072).
Dim Board(64, 48)Of course, you aren't limited to 10x10 squares. You could use 5x5 squares to gain more 'resolution' to your game if you desired, but the memory requirements would be 4 times as much {12,288 elements}...
Dim Board(128, 96)
To check if your character collided with an obstacle, you would perform a check between the characters X,Y coordinate and whatever 'block' would be behind the character.
For example, assume that you have a 64x48 grid (made up of 10x10 squares).
Assume that the character is at the location 118, 30.
Assume that the grid coordinate 19,3 is empty.
Assume that the grid coordinate 20,3 is a wall.
If you want to move the character 1 pixel to the right (location 119) then check if grid 19,3
Floor((119+80)/10)
If Board(Floor((PlayerX+80)/10), Floor((PlayerY)/10)) <> wall Then ...is OK to move to. Since it is, allow the move.
If you want to move the character 1 more pixel to the right (location 120) then check if grid 20,3
Floor((120+80)/10)
is OK to move to. Since it isn't, don't allow the move to occur.How it works:
Floor removes any decimals left from the division
119 is the location you want to check
80 is the width of your character (since you are moving right, you need to check the right side)
10 is the width of each grid space