Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / need help shooting a bullet :) plz help ( sprite game )

Author
Message
The Core
20
Years of Service
User Offline
Joined: 1st Aug 2005
Location: mother ship
Posted: 10th Feb 2006 18:52 Edited at: 10th Feb 2006 18:53
ok so hands down i'm new i've been working on my first game which is called system reflex. SO far i have produced a comp ai that follows you as a player but i would like help on making a bullet fire from my player and hits the enemys.

ok here is a pic of the game so far the player is the little red,blue,yellow and green box to the left of this picture and the enemys are the green virus things giving chase.

the player is on the move constantly so that they dont get hit by the enemy.

can anyone give me any advise on the bullet sprite.

thanx so much

i'm E.T i have so much tech but yet i dont have a mobile phone! where is a land line when you need one
The Core
20
Years of Service
User Offline
Joined: 1st Aug 2005
Location: mother ship
Posted: 10th Feb 2006 21:14
noone wants to help

i'm E.T i have so much tech but yet i dont have a mobile phone! where is a land line when you need one
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Feb 2006 00:56
Load of ways you can do it. easiest way is with sprites. Your images are square so sprite collision will be pretty accurate even in DB Pro.

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 14th Feb 2006 11:15 Edited at: 14th Feb 2006 13:02
There's no straightforward method, really a bullet has some minimum requirements in order to work. Like:

X Position
Y Position
X Speed
Y Speed

Every bullet will need to track it's location, and change it's location depending on it's speed, so if you want 100 bullets, make 5 arrays like this with 100 indices:

Dim Bul_x#(100)
Dim Bul_y#(100)
Dim Bul_xs#(100)
Dim Bul_ys#(100)
Dim Bul_mode(100)

By default, all the Bul_mode settings will be at 0, which is a good way to signify a dead bullet, so that your update loop can ignore it. You should also get a global set up to track your current bullet number, like the seed.

Global Bul_pos

Now to give the bullet a visible indicator, you can use sprites like Pincho suggests, but really once the maths is sorted that could be changed to plains quite easily if your engine demands it. I'll assume your using sprites for now, and your bullet image is number 10. This subroutine would create and prep all your bullet sprites:

make_bullets:

For n=0 to 100
SPR=n+50
Sprite SPR,0,0,10
Hide sprite SPR
Next n

return

That just makes the sprites and hides them so they're ready for the bullet function...

Function Bullet(x#,y#,xs#,ys#)

Bul_x#(Bul_pos)=x#
Bul_y#(Bul_pos)=y#
Bul_xs#(Bul_pos)=xs#
Bul_ys#(Bul_pos)=ys#
Bul_mode(Bul_pos)=1
Sprite Bul_pos+50,Bul_x#(Bul_pos),Bul_y#(Bul_pos),10
show sprite Bul_pos+50

inc Bul_pos,1
if Bul_pos>100 then Bul_pos=0

Endfunction

I'd suggest making a few different types of bullet spawn function - that one uses and X and Y location plus an X and Y speed, but you'll probably find it useful to have one that uses angles too, like you can specify the angle then the speeds are set with SIN and COS, makes it nice and easy to add enemy types.

Now with these active bullets you have to update them, maybe something like:

Update_bullets:

for bul=0 to 100
if Bul_mode(bul)>0
Bul_x#(bul)=Bul_x#(bul)+Bul_xs#(bul)
Bul_y#(bul)=Bul_y#(bul)+Bul_ys#(bul)
Sprite bul+50,Bul_x#(bul),Bul_y#(bul),10
`Note that in here you should also set it so once the bullet is off screen you set the bul_mode to 0
endif
next bul

return

So...

Dimension your arrays.
Make your bullet sprites.
Call the bullet spawn function when firing.
Call the bullet update routine every loop.
Remember to kill your bullets when they are off screen, so they're ready for re-using.


Van-B

Put away, those fiery biscuits!
The Core
20
Years of Service
User Offline
Joined: 1st Aug 2005
Location: mother ship
Posted: 14th Feb 2006 12:47
van - b you're the man thankx so much : > that as helped me alot

i'm E.T i have so much tech but yet i dont have a mobile phone! where is a land line when you need one

Login to post a reply

Server time is: 2026-06-12 23:24:01
Your offset time is: 2026-06-12 23:24:01