Computer Science Canada

Setting borders

Author:  Tallguy [ Tue Apr 22, 2008 12:06 pm ]
Post subject:  Setting borders

hello, i'm making a maze type game, with obstaclesin the way, if i make the background as a pic, wat is the best way to make the boarders without using like 100 different for staements.

below is an example of my final lvl on my game, anything white the user can't touch, how would i make it so?

on red box is the begining the other is the destination point

Author:  Tony [ Tue Apr 22, 2008 12:09 pm ]
Post subject:  RE:Setting borders

use 2D array as a grid/map

Author:  Tallguy [ Tue Apr 22, 2008 12:11 pm ]
Post subject:  RE:Setting borders

how does that work?, i now 2d, but unsure how to do that . . .

Author:  Tony [ Tue Apr 22, 2008 12:33 pm ]
Post subject:  RE:Setting borders

for any location where the user is, or wants to go (x,y) you look up if it's a valid location/move on your map (true/false).

Author:  syntax_error [ Tue Apr 22, 2008 6:33 pm ]
Post subject:  RE:Setting borders

if you ever made a tetris game its the same principal.

Author:  Sean [ Tue Apr 22, 2008 7:40 pm ]
Post subject:  RE:Setting borders

I could be wrong from what you guys mean, but you are looking at doing Multidimental Arrays?

Mackie tried to discuss this, I believe.

Author:  Tallguy [ Wed Apr 23, 2008 9:33 am ]
Post subject:  RE:Setting borders

so when using a 2d array i have to put it so that every white box is 'false'? thats gonna be a very loing array

Author:  Tony [ Wed Apr 23, 2008 9:56 am ]
Post subject:  RE:Setting borders

You don't have to have a 1x1px resolution, you could use larger boxes for a smaller array map.

You also don't have to enter it all manually -- you can load it from a data file, possible the image that you already have. This is just how "whatdotcolour" works, except that it's more stable since you don't share the space with the screen, and you have a better idea of what you are doing.

Author:  Tallguy [ Wed Apr 23, 2008 10:00 am ]
Post subject:  RE:Setting borders

so i would have 'if whatdotcolor = white then"... basically? where would the 'whatdotcolor' be located? on the cursor itself?

Author:  Zampano [ Wed Apr 23, 2008 10:06 am ]
Post subject:  Re: Setting borders

Yes, the int whatdotcolour (int, int) function should have as arguments the position of the mouse. If the point is a wall, then the whatdotcolour of that point will return the number of white, and you will know that it is a wall.

Author:  I Smell Death [ Wed Apr 23, 2008 10:07 am ]
Post subject:  Re: Setting borders

i did something along these lines once. Each picture had a corresponding data file. It would contain lines like this
(1,10,40,30)
the program would store these coordinates as x and y values and the character would not be able to go within those areas.
To make it so that i didn't have to write every area by hand, i wrote a short program that would display the image and allow you to draw red boxes where you do not want the user to go.
here's a copy of the map editor that i wrote.

In the main program you would have it read the lines and store them as x1, y1, x2, y2
then just have the program check if the user is within that area and move them out if they are.

Author:  Tony [ Wed Apr 23, 2008 10:34 am ]
Post subject:  Re: RE:Setting borders

Tallguy @ Wed Apr 23, 2008 10:00 am wrote:
so i would have 'if whatdotcolor = white then"... basically?

Almost. Except that instead of
code:

if whatdotcolor(x,y) = white then

You will do
code:

if map(x,y) = true then

Which could be shortened to simply if map(x,y) then

X and Y will likely be the position of your mouse or character

Author:  Tallguy [ Wed Apr 23, 2008 12:48 pm ]
Post subject:  RE:Setting borders

'map' would be my pic that i'm using for the maze?


: