New To Fenix And I Need Some Programming Help


Dull Blade

Still Fresh
Joined
May 12, 2007
Messages
3
Hello this is my first post and hopefully not my last post.

Here's what I want to do:

I am wanting to write a shmup in fenix so that I can use the source to compile a file that can be played in a sega Dreamcast (yes Dreamcast is fenix compatible too). Anyways I've been learning fenix for the last few day and have come up with some code for a SHMUP.

Here is my current problems:

-the bullet fire is way too fast, I need to find some way so that it will ony shoot 1 bullet every like 1/3 second (some sort of delay command is needed)

there is to alot more work to be done, I've still got to add collisions and lives but I was hoping some one could help me along the way. As of what I've hear, this i the best fenix forum about and I hope i've come to the right place for help.

here is my code:

CODE

//-----------------------------------------------------------------------
// Program: DC Shmup
// AUTHOR: Dull Blade / SKullinator (same guy depending on forum)
//-----------------------------------------------------------------------

PROGRAM SHMUP;
GLOBAL;
int steps = 0;
int shipx = 160;
int shipy = 180;
end
BEGIN


load_fpg("images\SHMUP.fpg"); // loads FPG file
SET_FPS(40,2);
SET_MODE(320,240,16);
Ship();
Quit();


loop
steps++;
enemy1(100,-20,50);
enemy2(150,-20,80);
enemy1(200,-20,100);
enemy2(80,-20,110);
enemy1(60,-20,115);
enemy2(50,-20,120);
enemy1(180,-20,300);
enemy2(140,-20,350);


FRAME;
end


END


PROCESS Quit();
begin
loop
if (key(_esc)) exit(); end;
frame;
end
end


//-----------------------------------------------------------------------
// Key input
//-----------------------------------------------------------------------

PROCESS Ship()

BEGIN
graph=2; x=160; y=180;
LOOP
if(key(_left)) x-=4; end
if(key(_right)) x+=4; end
if(key(_up)) y-=4; end
if(key(_down)) y+=4; end
if(key(_space))
shoot(x-10,y);
shoot(x+10,y);
end


FRAME;
END
END

//-----------------------------------------------------------------------
// Shoot
//-----------------------------------------------------------------------

PROCESS shoot(x,y)
BEGIN
graph=1; // loads bullet GFX

REPEAT
y-=5; //advances bullet
FRAME;
UNTIL (y<0) // will advance bullet until its y is < 0

END


//-----------------------------------------------------------------------
// ENEMYS type 1
//-----------------------------------------------------------------------

PROCESS enemy1(x,y, go);
BEGIN

if (steps == go)
graph=3;//Graphic number 3.
LOOP

y+=6; //Moves down 6 pixels every cycle

if(y>240)return;end//If the enemy is off screen, break loop.

FRAME;
END
END
END

//-----------------------------------------------------------------------
// ENEMYS type 2
//-----------------------------------------------------------------------

PROCESS enemy2(x,y, go)//peramiters are the x, the y, and at what frame it should be created
private
int orgx = 0;
boolean way = false;
BEGIN

if (steps == go)
graph=4;//Graphic number 4.
orgx = x;
LOOP

If (x == orgx+40) // determines to go left or right
way = false;
end
if (x == orgx)
way = true;
end

if (way == true) // determines to increment + or negative according to determined direction
x++;
end
if(way == false)
x--;

end
y+=3; //Moves down 3 pixels every cycle

if(y>240)return;end//If the enemy is off screen, break loop.

FRAME;
END
END
END
 

sam fisher

Well-Known Member
Joined
Apr 11, 2004
Messages
9,452
Location
Bristol, UK
Website
blog.peter-r.co.uk
For the shooting you could have something like

CODE

PROCESS Ship()

BEGIN
graph=2; x=160; y=180; timer[0] = 0;
LOOP
if(key(_left)) x-=4; end
if(key(_right)) x+=4; end
if(key(_up)) y-=4; end
if(key(_down)) y+=4; end
if(key(_space) && timer[0]>= 333)
shoot(x-10,y);
shoot(x+10,y);
timer[0] = 0;
end


FRAME;
END
END



Edited: as I addressed something totally different :p
 

Alex.

Retired
Joined
Aug 24, 2005
Messages
4,617
Well the simplest shoot delay would be something like this:

CODE
// a global variable
// only shoots ~4 times/second, considering you run at 40fps
int delay = 0

...

if(key(_space) && delay == 0)
shoot(x-10,y);
shoot(x+10,y);
delay = 10;
else if(delay > 0)
delay--;
end


I'm looking forward to playing your game, the GP2X has very few original shooters :)

Edit: Sam beat me to it ;)
 

Dull Blade

Still Fresh
Joined
May 12, 2007
Messages
3
wow, that was quick. Thanks for the help, I'm going to give it a try. After I complete this game, I'm going to leave it open source so it can be altered to run on a multiple of platforms. Thanks again.
 

sam fisher

Well-Known Member
Joined
Apr 11, 2004
Messages
9,452
Location
Bristol, UK
Website
blog.peter-r.co.uk
Alex. said:
Well the simplest shoot delay would be something like this:

CODE
// a global variable
// only shoots ~4 times/second, considering you run at 40fps
int delay = 0

...

if(key(_space) && delay == 0)
shoot(x-10,y);
shoot(x+10,y);
delay = 10;
else if(delay > 0)
delay--;
end
I'm looking forward to playing your game, the GP2X has very few original shooters :)

Edit: Sam beat me to it ;)

The benefit to mine is that if the framerate drops the game doesn't slow down :p I don't actually use timers in my fenix apps, I handle it myself based on my target framerate which I #define at the top of the source.
 
Last edited by a moderator:

Alex.

Retired
Joined
Aug 24, 2005
Messages
4,617
Well I'm not so hot on timer-based programming. If it'll lag, let it lag as a whole, not just some parts of it.
 

Dull Blade

Still Fresh
Joined
May 12, 2007
Messages
3
I dont tink i'll have to worry about it lagging too much, because i'm doing it in 8-bit mode. As of what I've heard, the gpx2 gp32 and dreamcast can all run in this mode without problem.
 

sam fisher

Well-Known Member
Joined
Apr 11, 2004
Messages
9,452
Location
Bristol, UK
Website
blog.peter-r.co.uk
Depends how many sprites are on screen at once, don't forget to kill the bullets after they are off screen, else they will slowly build up and slow the game down.

Edit: Oh yes, you've done that :p
 

Quiest

I like turtles!
Joined
Sep 2, 2004
Messages
3,411
Age
37
Location
Dteuschland ;)
I`d also stick to Alex' version, if there is a slowdown, let everything slow down... this could result in some strange effects otherwise.

I don`t like timer based programming much, cause of that effect... very often seen in games from the Click community for example, where games get rendered unplayable because of this (on slower maschines).

And if you are looking for a great Fenix community, check www.booleansoup.com

Oh, and feel free to add me in ICQ or MSN (check my profile here) if you would ever need some help ^^
 
Top