Help With A Shooting Function


moi

Still Fresh
Joined
Jul 12, 2006
Messages
13
Hi, I'm new at this board.I'm quite new to the fenix scripting language and at the moment I'm working on a clone of the NES game "Battle City" by Konami. I'm hoping to port this game to the Dreamcast and maybe for the GP32 btw.

My problem is: I cant get a proper shooting function tu run. My process tank() calls the process tank_shoots() when the player presses the A key. tank_shoots gets the x/y-coordinates of the player's position und the direction tank() is looking at. Then a bullet flies in that direction.
If an enemy() and the bullet collid, the bullet and the enemy() both should be removed. Unfortunatelly this doesn't happen, instead the bullet goes through the enemy(which disappears, which is needed) but does not disappear. This way I can "kill" more enemies than one :/
Sometimes one the collision the bullet disappears but the enemy still is alive.
I guess the problem is caused by "collision(type player_shoots)" and "collision(type enemy)", that both are called within the processes. I've tried several combinations already such as removing the processes using REPEAT/UNTIL and LOOP/IF/END without succes :(

my code snippet from both processes:
Any help is appreciated. If anybody wants to see my full sourcecode or wants me to translate my full comments to english, I'll surely do so.

EDIT: BUG WAS FIXED BY GOITY!

EDIT2: A new problem appeared see my other reply
 
moi posted on Jul 12 2006 at 05:24 PM said:
Hi at I'm new at this board.I'm quite new to the fenix scripting language and at the moment I'm working on a clone of the NES game "Battle City" by Konami. I'm hoping to port this game to the Dreamcast and maybe for the GP32 btw.

My problem is: I cant get a proper shooting function tu run. My process tank() calls the process tank_shoots() when the player presses the A key. tank_shoots gets the x/y-coordinates of the player's position und the direction tank() is looking at. Then a bullet flies in that direction.
If an enemy() and the bullet collid, the bullet and the enemy() both should be removed. Unfortunatelly this doesn't happen, instead the bullet goes through the enemy(which disappears, which is needed) but does not disappear. This way I can "kill" more enemies than one :/
Sometimes one the collision the bullet disappears but the enemy still is alive.
I guess the problem is caused by "collision(type player_shoots)" and "collision(type enemy)", that both are called within the processes. I've tried several combinations already such as removing the processes using REPEAT/UNTIL and LOOP/IF/END without succes :(



my code snippet from both processes:

Code:
PROCESS tank_shoots(x,y,direction)


BEGIN
graph=4;

yy=y+23; //little optical hack



REPEAT

//sollte der panzer nach oben gucken und keine kugel auf dem screen
IF ( (direction==30 ) )
y-=shotspd;  //kugel fliegt nach oben
kugelda=1; //sichert 
END

//sollte der panzer nach oben gucken
IF ( (direction==31  )
kugelda=1;
y+=shotspd;  //kugel fliegt nach oben
END

//sollte der panzer nach oben gucken
IF (direction==41   )
y=yy;
x-=shotspd;  //kugel fliegt nach oben
kugelda=1;
END

//sollte der panzer nach oben gucken
IF (direction==48 &&  !collision(type enemy)  )
y=yy;
x+=shotspd; //kugel fliegt nach oben
kugelda=1;
END

IF (collision(TYPE enemy));
score+=1000;
y=1000; //removing the bullet from screen
END

FRAME;
//the bullet flies until it gets out of the screen or hits adler() or mauer()
UNTIL (	  (y<=0||y=>485||x<=10||x>620)  ||   collision(type adler) || collision (type mauer)   );
END

Code:
PROCESS enemy(x,y, where)
BEGIN
graph=20;


REPEAT


//wenn berührung mit anderen enemys
if(collision(TYPE enemy) )
where=rand(1,4); 		//neue fahrtrichtung auswürfeln
end

//bewegung der gegner nach unten
IF (where==1) 
graph=20;
y=y+enemyspeed;
if(y>=460)
//tank_shoots(x,y,31);
y-=5;
where=rand(2,4);
end
end

//bewegung der gegner nach oben
IF (where==2) 
graph=22;
y=y-enemyspeed;
if(y<=20)
y+=5;
//tank_shoots(x,y,30);
where=rand(1,4);
end
end

//bewegung der gegner nach links
IF (where==3) 
x=x-enemyspeed;
graph=21;
if(x<=20)
x+=5;
//tank_shoots(x,y,41);
where=rand(1,4);
end
end

//bewegung der gegner nach rechts
IF (where==4) 
graph=23;
x=x+enemyspeed;
if(x>=620)
x-=5;
//tank_shoots(x,y,48);
where=rand(1,3);
end
end

//was passiert wenn Enemy auf ne mauer trifft:
if ( collision(type mauer) )

if(where==1)
y-=5; //spieler in die gegenrichtung schieben
where=rand(2,4); //neue fahrtrichtung würfeln
end

if(where==2)
y+=5;
where=rand(1,4);
end

if(where==3)
x+=5;
where=rand(1,4);
end

if(where==4)
x-=5;
where=rand(1,3);
end

end//was passiert wenn Enemy auf ne mauer trifft - ende

if(collision (type tank_shoots))
y=1010; //removing the enemy from screen

end

FRAME;


UNTIL ( y>=1000  ); //enemy is alive until it is visble
score+=100;
end

Any help is appreciated. If anybody wants to see my full sourcecode or wants me to translate my full comments to english, I'll surely do so.

Couldn't be bothered to read through it all, but instead of moving the enemies and bullets off screen, why not just use the Return; function? Just type Return; and it'll kill the process.
 
Last edited by a moderator:
Goity posted on Jul 12 2006 at 07:34 PM said:
Couldn't be bothered to read through it all, but instead of moving the enemies and bullets off screen, why not just use the Return; function? Just type Return; and it'll kill the process.

well putting return into player_shoots process, will refuse shooting more then one bullet. I will cut my source down to show where exactely the error that i can't fix is.

Code:
PROCESS tank_shoots(x,y,direction)

BEGIN
graph=4;

REPEAT

//only one case for a moving bullet
IF ( (direction==30 ) )
y-=shotspd;  //makes the bullet fly to the top
bulletonscreen=1; //remember that there's a bullet, to avoid more than one bullet on the screen
END
/*3 other IFs for the 3 other directions are cut*/


//if the bullet hits an enemy
IF (collision(TYPE enemy));
score+=1000;  //increase score
y=1000; //put the bullet outside the screen
END

FRAME;

UNTIL (	  (y<=0||y=>485||x<=10||x>620)  ||   collision(type adler) ||collision (type mauer)	   );
bulletonscreen=0; // allow new bullet to shoot

END


Code:
PROCESS enemy(x,y, where)
BEGIN
graph=20;


loop 
...
/*cut down if clauses*/
...


if(collision (type tank_shoots))
gegnermax++;			 //allows the creation of new enemys
score+=100;
return;

end

FRAME;
end

end


I am not able to kill BOTH the tank_shoots() AND the enemy() processes at the same time.
All i get is the enemy() process is running while the tank_shoots() is killed OR
the enemy() process is killed while the tank_shoots() is still running (the bullet flies).
 
Last edited by a moderator:
Goity posted on Jul 12 2006 at 09:56 PM said:
I've sorted it. I'll put it up in a sec.
http://l33t.spod.org/~goity/tankbeta3.rar
thank you very much! I really wouldn't have figured this out by myself and probably I'd have stopped working on this game without your help!! :D :D


Code:
IF (collisions)
score+=1000;
kugelda=0; 
Signal(collisions,S_kill);	   
Return;   
END
So do I understand this correctly... this IF looks if a collision is happening and incase of yes both IDs are getting killed?
 
Last edited by a moderator:
moi posted on Jul 12 2006 at 09:10 PM said:
Goity posted on Jul 12 2006 at 09:56 PM said:
I've sorted it. I'll put it up in a sec.
http://l33t.spod.org/~goity/tankbeta3.rar
thank you very much! I really wouldn't have figured this out by myself and probably I'd have stopped working on this game without your help!! :D :D


Code:
IF (collisions)
score+=1000;
kugelda=0; 
Signal(collisions,S_kill);	   
Return;   
END
So do I understand this correctly... this IF looks if a collision is happening and incase of yes both IDs are getting killed?
basically it kills everything involved with that local collision. collisions is set as the collision variable earlier in that process.
 
Last edited by a moderator:
Well now there's another problem I'm not able to fix by myself.

Is it actually possible to use map_get_pixel with processes?
In my game I use mauer() as a wall process. The player is able to "kill" it, otherwise he wont be able to pass through. For this I've been using the collision() function. Unfortunatelly the player tends to do "moonwalking" if there are too many wall processes in a row.
For this reason I wanted to fix this using map_get_pixel. I converted my FPG-File to 8bit since I had heard that 16bit wouldnt work. Goity told me in another topic that it's easier to check for 0 since it's the number for black color. But all my tries ended without success. The player just drives through the walls...

my code looked like this:
Code:
IF (key(_DOWN)&&lives>=0&& (!map_get_pixel(data,200,x/1.01,y/1.01)==0) )
angle=2700000;  //rotating the player graph

direction=31;
y=y+6;
	IF(y>460) // player about to left the screen?
	y=460;//stop him
	END
END
changing x/number and y/number to x/2 and y/2 didnt make any difference:
(!map_get_pixel(data,200,x/1.01,y/1.01)


Any help is apreciated!
 
Back
Top