Rand Isn't Working In My Code


Atari

Still Fresh
Joined
Aug 9, 2005
Messages
30
Here is my code:

Code:
PROGRAM ship_shoot;

GLOBAL
sprites;
shotflag;
score=0;
lives=3;
seedfire=0;
enfireflag=0;

PRIVATE

Begin
graph_mode=mode_16bits;
set_mode(m640x480);
sprites=load_fpg("new.fpg");
write_int(0,10,25,0,offset score);
write_int(0,10,35,0,offset enfireflag);
write_int(0,10,45,0,offset seedfire);
ship(320,420);
enemy();
end

process ship(x,y);

private

begin
graph=1;
	loop
  if (key(_left) and x>=30)
  	x-=20;
  end
  if (key(_right) and x<=610)
  	x+=20;
  end
  if (key(_esc))
  	exit();
  end
  if (key(_control)and NOT shotflag)
  	shot(x,y);
  end
	frame;
	end
end

process shot(x,y);

private
collflag;

begin
graph=5;
shotflag=1;
Loop
y-=40;
collflag=collision(type enemy);
  if(y<-10)
  	shotflag=0;
  return;
  end
  if (collflag)
  	signal(collflag,s_kill);
  	shotflag=0;
  	score+=100;
  signal(type shot,s_kill);
  end
	frame;
	end
end

process enemy();
private

begin
graph=2;
x=10;
y=100;
loop
x=x+15;
  if (x>640)
  	x=10;
  end
  if (seedfire=45 and NOT enfireflag)
  	enfireflag=1;
  	enemyfire(x,y);
  	seedfire=rand(1,50);
  end
	frame;
	end
end

process enemyfire(x,y);
begin
graph=5;
loop
y=y+20;
  if (y>420)
  	signal(type enemyfire,s_kill);
  	enfireflag=0;
  	return;
  end
  if (collision (type ship))
  	signal(type ship, s_kill);
  	return;
  end
	frame;
	end
end

In the process enemy(), there is a random number generator that picks a number between 1 and 50. If that number ends up at 45, the enemy is supposed to fire. What happens here is, the enemy continuously fires. enfireflag always gets set, but seedfire always ends up at 45, regardless of what number I put in the rand() function. For example, I put 1,30 in rand() and the enemy STILL fires. seedfire STILL ends up as 45!

I've been staring at this for a few hours now and have tried a number of attempted fixes with no luck. Is there something wrong with the code that I cannot see?

Any help would be greatly appreciated.
 
I am not familiar with Fenix. The only thing I can think of is that, as in C, you may need to distinguish between assignment (=) and equivalence (==). I can only guess that where you are checking the value with 'if (seedfire=45 and NOT enfireflag)' you are actually giving seedfire the value 45 rather than comparing it. I think you will then need to to move the RAND statement to outside of the 'if' condition or it will never fire. RAND will never be executed because seedfire will always be 0. Hope this helps.
 
Yup, both are right.

And if this game is gonna be for the gp32, I recommend you to use 320x240 resolution :D
 
KidQuaalude posted on Aug 9 2005 at 04:14 AM said:
change it to

if (seedfire == 45 and NOT enfireflag)

== is a compare
= is an assignment

so you are setting seedfire to 45 every time

That was one of the fixes that I tried originally, and it didn't work. Even if I set rand to (45,45). But I just moved rand out of the if...end and put it before the check, and now it works! The funny thing is, I went to bed last night, dreamt up the fix, and voila!

Thanks for the help.
 
Last edited by a moderator:
Quiest posted on Aug 9 2005 at 05:32 AM said:
Yup, both are right.

And if this game is gonna be for the gp32, I recommend you to use 320x240 resolution :D

That will happen once I finish the game. I'm writing it for three different platforms; the main one being Dreamcast :)
 
Last edited by a moderator:
Okidoki!

Erm, could someone maybe tell me what I need to get my Fenix games running on my DC?

Also can it run 320x240 in fullscreen (I mean, does it automatically scale to fullscreen?)
 
Quiest posted on Aug 9 2005 at 03:32 PM said:
Okidoki!

Erm, could someone maybe tell me what I need to get my Fenix games running on my DC?

Also can it run 320x240 in fullscreen (I mean, does it automatically scale to fullscreen?)

It should. The Dreamcast can run games in both 320x240 and 640x480, in both 8 and 16-bit modes.

All you would have to do to your code is make sure that your controls match the Dreamcasts. The key mappings are:

Start = Enter
A = Control
B = Alt
X = ESC (this will reboot the Dreamcast if used with exit)
Y = Spacebar

So in your program, use "_control", "_enter", "_esc", and "_space" for the keys that they're mapped to. The digital pad on the DC corresponds to the arrow keys on the keyboard, just as the GP32 does.

If you wish to use the analog stick, that requires the get_joy_position commands. Mouse also works, but is quite jerky. pauljake (Space Dodger) put together an excellent post on the dcemu.co.uk fenix board that describes how this is done, among other tests. I refer back to it constantly as I learn. View it here.

I've converted a few games from DIV and GP32 to run on the Dreamcast, but am still somewhat new to writing my own games using Fenix :)

Now, to burn isos of your game- you'll need this. Just unzip it and follow the directions in the various readmes within the archive.

Other than that, you can use the dcb from your GP32 compile. No other changes are necessary, with the exception that you don't need the GP32 runtime.

Good luck!
 
Last edited by a moderator:
Oh, hey, Paul? I helped him porting Space Dodger to the gp32 :)
I think I`m gonna contact him for this.

Anyways, thanks for the info.

And you can only use 5 buttons? Porting my minigame project will get quite hard then, there is no select button... why can`t you use L & R?
 
Quiest posted on Aug 9 2005 at 04:17 PM said:
Oh, hey, Paul? I helped him porting Space Dodger to the gp32 :)
I think I`m gonna contact him for this.

Anyways, thanks for the info.

And you can only use 5 buttons? Porting my minigame project will get quite hard then, there is no select button... why can`t you use L & R?

Yeah that's a bummer. L & R could come in handy. Unless Chui isn't telling us something... hmmm...

I discovered that my old Fenix Dreamcast dev environment help page is gone, so I re-upped it. Check it out here.
 
Last edited by a moderator:
Back
Top