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! / 2d Shooter Code Problem

Author
Message
GLIM
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location:
Posted: 22nd Sep 2004 14:04
I am working on a 2d Shooter. I am having trouble with my hero's shooting code. I want it to work like this:
When the spacebar is pressed the sprite shows up, it moves to the top of the screen and is deleted. However, when this is going on i want to be able to press space bar again and make another bullet sprite show up. I would like it to work like galaga where if i held down the space bar it would fire repeatedly. I have added my code. I would like to limit the number of bullet sprites at any one time to be 50.

if you are interested in my game project check it out here:

[href]http://www.frozenpalmstudio.gametruth.org/phantomindex.htm
[/href]

GameTruth.org
See the Light...
GLIM
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location:
Posted: 22nd Sep 2004 14:07
ok apparently the code didnt load, im trying again

GameTruth.org
See the Light...
Skeletor
21
Years of Service
User Offline
Joined: 21st Jun 2004
Location: florida
Posted: 22nd Sep 2004 23:06 Edited at: 22nd Sep 2004 23:08
This is probably the most common problem I see with 2d shooters. Unfortunatly I do not have a solution except to tell you that you will need to ready 50 different bullet sprites if the max bullets you want on screen will be 50.

Other than that you will need to figure a way that when the first bullet is shot and its Y position equals the playerY position - 20 or something(Assuming you game is played like centipede/space invaders)
and your space key is still pressed then fire bullet 2 and so on. I am sure if you think long and hard that you will find a way to use what I told you.

Note: Now that I think of it I might add a machine gun into my 2d shoot 'em up engine.


http://www.angelfire.com/games5/db_games/
Flashing Blade
23
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 22nd Sep 2004 23:41
I done this with dbpro (source button)

Just exchange my text ship and bullits for sprites.


The word "Gullible" cannot be found in any English Dictionary.
GLIM
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location:
Posted: 23rd Sep 2004 12:31
Thanks, it works great.

GameTruth.org
See the Light...
GLIM
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location:
Posted: 25th Sep 2004 13:21
I have it essentially working. I was just wondering if there was a way to control the count number so that it does not start at zero. I am using a type variable for the sprite number but since it starts at zero i keep getting an error.

GameTruth.org
See the Light...
Flashing Blade
23
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 25th Sep 2004 20:38
Do you mean the count variable in my source? That starts at 1 and goes to 50.

Don't know how you doing it but I've altered my code to use sprites.

Cick sourse:


The word "Gullible" cannot be found in any English Dictionary.
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 25th Sep 2004 22:33 Edited at: 25th Sep 2004 22:34
IF sprite_number < 1 THEN sprite_number = 1

or something, sprite_number is a variable, tell me if you want me to make your shooting code come out right, is it dbpro or classic?
GLIM
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location:
Posted: 27th Sep 2004 12:26
I have messed with the code a little and got it to work. My only problem is that the sprites are not deleting right away when they reach the top of the screen. Any help with that would be great. Check out the code.

GameTruth.org
See the Light...
Flashing Blade
23
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 27th Sep 2004 20:08
After this line:
if bullit(count).bullety<10 then bullit(count).alive=0
put:
delete sprite count

Also you don't need cls when using sprites as backdrop will sort that out. And you don't need the line bacdrop on as the backdrop is on by default, But even if you did need it it shouldn't go inside your do-loop.

Good luck with you game hope to see a demo on the WIP board soon


The word "Gullible" cannot be found in any English Dictionary.
GLIM
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location:
Posted: 29th Sep 2004 06:45
I have been messing with this code but i can not get the bullet sprites to delete properly. When i use the mod to the code you provided no sprite show up. I think it is because as soon as i create a sprite it gets deleted. I think i should just make a sub for the destruction of the sprite because i think it will help when i get into the collisions. Does anyone have any input?

GameTruth.org
See the Light...
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 29th Sep 2004 07:11 Edited at: 29th Sep 2004 07:12
here is something to start with

LOAD BITMAP "widebitmapx640-y10.bmp",1
GET IMAGE 1,0,0,640,10
SPRITE 60000,0,-10,1
DELETE BITMAP 1

FOR sprite_collision = 1 TO 50
sprite_to_delete = SPRITE COLLISION(sprite_collision,60000)
IF sprite_to_delete = 1 THEN DELETE SPRITE sprite_collision
NEXT sprite_collision

and then you will need some code to test for which sprite number is available for new bullets. tell me if you dont understand the code or it runs too slobby, I have not tested it.
Flashing Blade
23
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 29th Sep 2004 08:43
Quote: " When i use the mod to the code you provided no sprite show up."


Thats cus I gave you a slightly wrong solution when I said:
Quote: "After this line:
if bullit(count).bullety<10 then bullit(count).alive=0
put:
delete sprite count"


I should have said change to this:
if bullit(count).bullety<10
bullit(count).alive=0
delete sprite count
endif

working source attatched


The word "Gullible" cannot be found in any English Dictionary.
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 29th Sep 2004 18:55
I came up with a simpler routine, (probarbly much like flashing blades routine)

FOR sprite_number = 1 TO 50
IF SPRITE Y(sprite_number) < 0 THEN DELETE SPRITE sprite_number
NEXT sprite_number
GLIM
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location:
Posted: 30th Sep 2004 06:30
thanks for the help. the code works now and i am currently working on the collisions. I will put up a work in progress post soon.

GameTruth.org
See the Light...
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 30th Sep 2004 07:08
did you use my little snippet? did you? did you? tell me if it worked or you used flashing blade's routines.
GLIM
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location:
Posted: 30th Sep 2004 10:13
See the code snippet, i used a little hybrid thing.

GameTruth.org
See the Light...
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 1st Oct 2004 04:44
good, the only gripe I have about making other peoples code is that they don't learn much then, but I am glad you combined it

Login to post a reply

Server time is: 2026-06-12 03:34:28
Your offset time is: 2026-06-12 03:34:28