Which Side Is Open?

Talk about making games.

Which Side Is Open?

Postby jimmynewguy » Wed May 25, 2011 11:11 am

I have this "control" actor and when a certain time limit goes by I want him to keep picking random sides until one is open. But for some reason it only seems to work some times? I have this code:

Code: Select all
SPOT:
i = rand(5);
switch(i)
{
case 1:
if(CollisionFree("Event Actor", x+25,y))
CreateActor("virus", "virus", "(none)", "(none)", 0, 0, false);
else
goto SPOT;
break;
case 2:
if(CollisionFree("Event Actor", x+2,y+25))
CreateActor("virus", "virus", "(none)", "(none)", 0, 0, false);
else
goto SPOT;
break;
case 3:
if(CollisionFree("Event Actor", x-25,y))
CreateActor("virus", "virus", "(none)", "(none)", 0, 0, false);
else
goto SPOT;
break;
case 4:
if(CollisionFree("Event Actor", x+2,y-25))
CreateActor("virus", "virus", "(none)", "(none)", 0, 0, false);
else
goto SPOT;
break;
}


which is GOD AWFUL. I really should have done a loop, but that's only a minor problem. When the actors are created they don't really fit to the 25 X 25 grid they should... hence the +/- 2's in there at random spots (which still don't help enough)

Does anyone have any idea why this would be/how to fix it? The actor created is a square 25 X 25 and so is the control actor, and it's positioned on the grid. The created actors also use this code and the closer to the middle it is the more it seems to be messed up...? Oh well, cheers and thanks for at least reading this.
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Which Side Is Open?

Postby skydereign » Wed May 25, 2011 11:21 am

First off, rand(5) will return a random number between 0 and 5. That means... if set to an int, your range is 0-4. So... you are skipping 0 in your switch statement. I'd use rand(4)+1 as the rand statement, or just use 0-3 for your case statements. For the +/-2, I wouldn't suggest that, even if that was fixing it. Not sure what is causing the problem, but removing them seems to work fine for me. Remembering of course CollisionFree means it is actually collision free. Also.... http://xkcd.com/292/
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Which Side Is Open?

Postby jimmynewguy » Wed May 25, 2011 7:29 pm

Thanks sky, I just found this game and wanted to continue working on it. I coded this quite a while back and I think I'm just going to start over completely. I'll watch my back for dinosaurs though...
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest