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! / Bullets, 2D Engine-open source project

Author
Message
DivW
20
Years of Service
User Offline
Joined: 31st Jul 2003
Location: Scotland
Posted: 28th Aug 2003 03:20
I'm writting a tutorial about 2D gameing as well as making an open-source Space Shooting Game. However i'm having a lot of trouble with bullets. I have made 20 sprites to use as bullets but i know im not doing it right. How do i make my spaceship fire a stream of bullets? I'm just making the engine just now but when this part is finished then my whole engine is finished and i can start to work on actually making the game. I'm a newbie myself, 3 weeks in, but i'm getting the hang of this really fast. This problems been plaguing me for days now and i know when to ask for help. I'll post my code if anyone needs to see it but it's really untidy at the o due to testing so i'll repost it later if i can. So dont me mean, share your code, cos i'll share all of mine. I promise! -DivW

Your soul...it tastes like chicken
Mentor
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 28th Aug 2003 19:45 Edited at: 28th Aug 2003 19:49
make some arrays from 1 to 20 do....

dim xpos(20):dim ypos(20): dim bullet(20)

right at the start of the code, then do.......

if spacekey()
for i=1 to 20
if bullet(i)=0
bullet(i)=100
xpos(i)=fireposx
ypos(i)=fireposy
endif
next i
endif

inside the gameloop, then at the bottom of the game loop do........

for i=1 to 20
if bullet(i)>0
dec ypos(i) : rem bullet y position (in an array since you need to update 20 seperate bullets)
endif
sprite i,xpos(i),ypos(i),bullet_piccy
next i

you have 3 arrays, bullet(20) holds how long the bullets where alive, this gets reduced by one every loop, when it hits zero then the bullet can be used again since it died, you have to set the initial value to something large enough to last until the bullet is offscreen, xpos(20) holds the position of bullets across the screen, one x position for each bullet, and ypos(20) holds the position of the bullet up the screen, again you have one position for each bullet, the first bit of code detects the spacekey being pressed and then scans through all the bullet positions and when it finds one empty it will set the bullet life to 100, if they are all active (more than 0) then you can`t fire any more bullets until one dies, the second bit of code scans all the bullets and updates their height from the bottom of the screen if they are still alive, and reduces their life by one, when they reach zero then they get ignored until they get set to 100 and start counting down again, fireposx and fireposy are the positions where the bullet starts from (normaly just in front of the ship), cheers.

Mentor.
DivW
20
Years of Service
User Offline
Joined: 31st Jul 2003
Location: Scotland
Posted: 29th Aug 2003 12:43
Thanks Mentor! You're a gem. Well anywho i'm making this game called Spaceman as an Advanced Higher computing project. I'm currently halfway through an engine demo where i'll put in power ups, multiplying baddies, a points system, etc. But every time i figure something out i'll write it down to explain it to myself and anyone else who wants to read it. It's just a thing i do. But anyway, i decided i'd make this one into a tutorial anyway, because i'd get more marks in the exam for doing it. Well i figured when i finished the tutorial i'd trade all the rights for a copy of Cartography Shop, Texture Maker, and 3D canvas, because ican't afford them but i could really use them. Well anyway i don't know if the peeps at DBP would be interested, but i'll be making the tutorial anyway so it doesn't realy matter if i get nothing back for it. When my website is finished and me Dev Team sort themselves out i'll get back everyone on the boards with URL's and Demo's. Till then i'll just keep poosting what i know, and what i need help with. See ya -DivW

Your soul...it tastes like chicken
DivW
20
Years of Service
User Offline
Joined: 31st Jul 2003
Location: Scotland
Posted: 30th Aug 2003 16:14
Here is my code, i get an error message saying Parameter Mismatch at command line 98, but the dec command is on line 99, so i'm a little confused. Is this just a bug, or a problem with my layout, or a problem with the implimentation of my code?

Your soul...it tastes like chicken
Sync
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hungary
Posted: 2nd Sep 2003 19:36
There's a line in your code: dec ypos(i)
Change it to: dec bulletypos(i)

Login to post a reply

Server time is: 2024-03-03 01:59:15
Your offset time is: 2024-03-03 01:59:15