Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Setting borders
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tallguy




PostPosted: 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



lvl5.JPG
 Description:
lvl5 on my game
 Filesize:  15.19 KB
 Viewed:  67 Time(s)

lvl5.JPG


Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Apr 22, 2008 12:09 pm   Post subject: RE:Setting borders

use 2D array as a grid/map
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Tallguy




PostPosted: 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 . . .
Tony




PostPosted: 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).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
syntax_error




PostPosted: Tue Apr 22, 2008 6:33 pm   Post subject: RE:Setting borders

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




PostPosted: 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.
Tallguy




PostPosted: 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
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Tallguy




PostPosted: 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?
Zampano




PostPosted: 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.
I Smell Death




PostPosted: 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.



mapeditor.t
 Description:

Download
 Filename:  mapeditor.t
 Filesize:  9.16 KB
 Downloaded:  58 Time(s)

Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Tallguy




PostPosted: Wed Apr 23, 2008 12:48 pm   Post subject: RE:Setting borders

'map' would be my pic that i'm using for the maze?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: