# Board index » delphi » !!!!HELP with game programming

## !!!!HELP with game programming

Hello, this is Royous.  I have been programming a game.  It is a game like
space invaders.  There is a player ship at the bottom with a bunch of enemy
ships at the top. How would I make the enemy ships explode whenever the bullet
reaches it?  There is an array of enemies called Enemy2 which contains 48
enemies positions.  To access the x position of the enemy do this:
Enemy2[i].x;
To access the y position of the enemy do this:
Enemy2[i].y;
The positions of the bullet is:
BulletX; //for the x position
BulletY; //for the y position

How would I make the enemy ship explode whenever the bullet reaches it?
Thanks.

Royous
royo...@aol.com

## Re:!!!!HELP with game programming

just say :

if (bulletX>=enemy2[i].x) and (bulletX<=enemy2[i].x+enemywidth) and
(bulletY>=enemy2[i].y) and (bulletY<=enemy2[i].y+enemyheight) then
killenemy;

## Re:!!!!HELP with game programming

RoyousZ <royo...@aol.com> wrote in article

##### Quote
> Hello, this is Royous.  I have been programming a game.  It is a game
like
> space invaders.  There is a player ship at the bottom with a bunch of
enemy
> ships at the top. How would I make the enemy ships explode whenever the
bullet
> reaches it?  There is an array of enemies called Enemy2 which contains 48
> enemies positions.  To access the x position of the enemy do this:
> Enemy2[i].x;
> To access the y position of the enemy do this:
> Enemy2[i].y;
> The positions o

[..]
Hi!
Okay, you have to chase the positions of the bullet.Then do something like
this.

If (BulletX>Enemy[?]X) and (BulletX<Enemy[?]X+20) and
(BulletY>Enemy[?]Y) and (BulletY<Enemy[?]+20) then
KillSprite;

+20 means the x and y length of the sprite, you should change
EnemyX++++
+Here   is
+ship, or
+something
Dont forget the Brackets and perhaps you can do a loop for all
sprites like:

For i:=0 to NumberOfEnemies do
[..]
End;
And use EnemyX[i]

## Re:!!!!HELP with game programming

##### Quote
RoyousZ wrote:

> How would I make the enemy ship explode whenever the bullet reaches it?
> Thanks.

I used dynamite once. It was awesome.

Just kidding. I really didn't. All the exclamation points in the subject
brought back memories of trying to code something similar.

The simplest thing I can think of: (pseudo-code)

track the missles x&y coordinates.
{assuming missle is fired 'up'?)

if (y <= ship.y) AND
( (x >= ship.x + shipwidth) and (x <= ship.x - shipwidth) ) then
blowup;

In other words, if the missle gets near (enough) to the ship,
it goes ka-blooey. Or was that kla-booey? Oh well.

## Re:!!!!HELP with game programming

The only solution I can think of by that short information is
if (BulletX = Enemy2[x].x) and (BulletY = Enemy2[x].y) then
{change sprite (the explosion animation)} but that information is
to short and so you wont probably be pleased with that answer
(since the enemyes are bigger than a point with x,y coordinates ;).
With other words send as much info. as you can think of or even
bether - the code it's self.

Moraliyski

P.S. I want to write a jump & run game (like Abuse) and need a graphic
designer.If you're interested, mail me!

##### Quote
RoyousZ wrote:
> Hello, this is Royous.  I have been programming a game.  It is a game like
> space invaders.  There is a player ship at the bottom with a bunch of enemy
> ships at the top. How would I make the enemy ships explode whenever the bullet
> reaches it?  There is an array of enemies called Enemy2 which contains 48
> enemies positions.  To access the x position of the enemy do this:
> Enemy2[i].x;
> To access the y position of the enemy do this:
> Enemy2[i].y;
> The positions of the bullet is:
> BulletX; //for the x position
> BulletY; //for the y position

> How would I make the enemy ship explode whenever the bullet reaches it?
> Thanks.

> Royous
> royo...@aol.com

## Re:!!!!HELP with game programming

##### Quote
RoyousZ wrote:
> Hello, this is Royous.  I have been programming a game.  It is a game like
> space invaders.  There is a player ship at the bottom with a bunch of enemy
> ships at the top. How would I make the enemy ships explode whenever the bullet
> reaches it?  There is an array of enemies called Enemy2 which contains 48
> enemies positions.  To access the x position of the enemy do this:
> Enemy2[i].x;
> To access the y position of the enemy do this:
> Enemy2[i].y;
> The positions of the bullet is:
> BulletX; //for the x position
> BulletY; //for the y position

> How would I make the enemy ship explode whenever the bullet reaches it?
> Thanks.

> Royous
> royo...@aol.com

Well, it should look like this

Repeat
Time := Time + 1 ;
Case Action of
Shoot : Begin                { The player just shot a bullet! }
For i:= 0 to i do
If ((Bulletx := Enemy2[i].x) and (Bullety := Enemy2[i].y)) then
Explode(Enemy2[i])
Else Bulletx:=Bulletx-1; {The bullet continues to the top of the
screen...}
End;

I hope I haven't made it more complex for you! ;}

Yannis Rizos (yan...@usa.net)

## Re:!!!!HELP with game programming

##### Quote
> .... a bunch of enemy
> ships at the top. How would I make the enemy ships explode whenever the
bullet
> reaches it? .....

I suppose you would use explosive charges in the bullets.

See alt.exploding.bullets  ;-)