forums

TNT Basic Forums > Programming Q&A
Bullet fire?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

02-22-2003 15:15

Posted by:
Simon

Click Here to Email Simon   Find more posts by Simon

I've got a ship on the bottom of the screen that goes back and forth. How in the world do I make the bullet, the second sprite in the code, come out and act like a bullet? All it does now is go forward whenever I hit the space bar. Here's the code and thanx in advance:

Graphics Mode 640, 480
Set Pen Colour Black
Paint Canvas
Draw Frame

Load Images 128

int x=320,y=430

while not Mouse Button
sprite 1,x,430,0
if left then x=x-3
draw frame
if right then x=x+3
draw frame
if x<10 then x=10
if x>630 then x=630
draw frame

if space then sprite 1,x-10,y,1
y=y-3
draw frame

wend

02-22-2003 23:19

Posted by:
ERaZer

Click Here to Email ERaZer   Find more posts by ERaZer

You need to make it go forward in every frame.

And why so many draw frame commands, one would suffice.

02-23-2003 15:00

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

You need a boolean fire. The bullet must have a different ID than the main sprite. You need ONE drawrame per loop or it'll slow down your game.Try:

Graphics Mode 640, 480
Set Pen Colour Black
Paint Canvas
Draw Frame

Load Images 128

int x=320,y=430
int fire=false,bulletX,bulletY

while not Mouse Button

sprite 1,x,430,0

' moving
if left then x=x-3
if right then x=x+3

'collision with screen bounds
if x<10 then x=10
if x>630 then x=630

' prepare a shot
if space
fire=true
bulletX=x-10
bulletY=430
end if

if fire=true 'actions to do if there is bullet
sprite 2,bulletX,bulletY,1
bulletY = bulletY-3

if bulletY<-50 then fire=0

end if

draw frame

wend

02-23-2003 22:04

Posted by:
Simon

Click Here to Email Simon   Find more posts by Simon

Thanx, that works perfectly, but now I have another problem. The bullet fires but then disappears when I fire again. How exactly do I fire, then fire again, without having the other disappear? It probably has to have it recognize two different sprites but how do I do that?

02-23-2003 23:00

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

I sent you the code days ago! read your mail!

02-26-2003 13:56

Posted by:
Simon

Click Here to Email Simon   Find more posts by Simon

you did? Where did you send it? I check my hotmail every day, and probably more than once....

02-28-2003 00:47

Posted by:
Simon

Click Here to Email Simon   Find more posts by Simon

I'm still having trouble; I've been working forever on how to have the original bullet continue on if i fire again, but I can't figure it out. Right now, the second bullet fired gets rid of the first one fired, and if I fire again, the third gets rid of the second and so on... Here's the code, I appreciate the help:


Graphics Mode 640, 480
Set Pen Colour Black
Paint Canvas
Draw Frame

Load Images 128

int x=315,y=430
int fire=false,bulletX,bulletY
while not Mouse Button

sprite 1,x,435,0

' moving
if left then x=x-3
if right then x=x+3

'collision with screen bounds
if x<10 then x=10
if x>630 then x=630


' prepare a shot
if space
fire=true
bulletX=x-10
bulletY=415
end if


if fire=true
sprite 2,bulletX,bulletY,1
bulletY = bulletY-3
end if

draw frame

wend

02-28-2003 10:54

Posted by:
No Frills

Click Here to Email No Frills   Find more posts by No Frills

Bullet Firing Help

Quote:

' prepare a shot
if space
fire=true
bulletX=x-10
bulletY=415
end if


if fire=true
sprite 2,bulletX,bulletY,1
bulletY = bulletY-3
end if

Endquote:


While not a TNT expert by any means - I think I can see where your problem lies.

You need to work out how many bullets you want to be able to appear on screen at one time and call it a varialbe (say 'max_bullet')

At the start of your program, no bullets are being fired, so set another variable like this 'bullets_on_screen=0'.

Then when you test for fire=true, increment the value of 'bullets_on_screen' and make your last sprite command thus: sprite bullets_on_screen,bulletX,bulletY,1

If you're going to need different X and Y positions for each bullet - then you'll have to store the bulletx and bullety in an array of 'max_bullet'.

Hope that helps.

03-01-2003 03:45

Posted by:
Simon

Click Here to Email Simon   Find more posts by Simon

I tried that and the same thing is happening. Could someone give me some code on how this might work? I don't know, maybe my code is just not how it should be... Thanx

03-01-2003 22:35

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

I think this will work:

'declare Arrays

int shot[5]=0,shotX[5],shotY[5]
int time=50

'( the variable <time> makes
' sure all bullets won't be
'shot all at the same time )

time = time-1

for i=0 to 4
if space and shot=true and time <1 and shot=false
shotX=shipX
shotY=shipY
shot=true
time=50 ' 50 frames before the next shot
end if

if shot=true
shotY=shotY-5
sprite 2,shotX,shotY,image
if shotY<-50 then shot=false
end if

next i

03-02-2003 14:59

Posted by:
Simon

Click Here to Email Simon   Find more posts by Simon

It's not working correctly as an array. Tnt just keeps giving me an array incorrect pop-up. So I'm attempting to make this work differently. I want the bullet movement to work off of it's individual sprite, but, as you'll see in the code, when the sprite index changes, the original sprite quits moving. I believe that if I can get the sprite to move individually then that problem should be solved. Here's the code:


Graphics Mode 640, 480
Set Pen Colour Black
Paint Canvas
Draw Frame

Load Images 128

int x=315,y=430
int fire=false,bulletX,bulletY
int max_bullets=4

while not Mouse Button

sprite 1,x,435,0

' moving
if left then x=x-3
if right then x=x+3

'collision with screen bounds
if x<10 then x=10
if x>630 then x=630

' prepare a shot
if space
fire=true
if bulletY<410 then max_bullets=max_bullets+1*
bulletX=x-7
bulletY=415
end if

if fire=true
sprite max_bullets,bulletX,bulletY,1
bulletY=bulletY-3 'if I can get this to work independently with a sprite 'before and after that sprite changes up here *, then the original bullet 'should continue on, and another bullet should fire. If anyone has a way 'to do this, or better yet, if anyone has a bullet system that works, please 'give a little love here and help a brother out. Peace, and thanx in 'advance.
end if

draw frame

wend

03-02-2003 19:44

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

aaargh!!!

I sent you the stuff twice... write your e-mail at once, cause you don' t seem to read the one you gave for this forum.

Anyway, it' s not a good idea to write all your code and hoping someone tells you what' s wrong, cause after 10 long posts of people trying to tell you what to do you' re at the starting point: what you need is somebody that writes a working code and sends it to you.

03-02-2003 19:56

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

Ok, ok, here 's the code

Hmm... just try this stuff... hope you manage to copy it and paste it, and to put a picture in the images archive 128...
oh, you shoot with ``space'' and quit with ``up''


int bulletexists[50]
float bx[50]
float by[50]
int i
int n
int spaceup
graphics mode 800,600
load images 128
set framerate 60
repeat
draw frame
if space and spaceup=true
n=0
repeat
n=n+1
until bulletexists[n]=false or n>48
bulletexists[n]=true
bx[n]=0
by[n]=0
spaceup=false
end if

if not space then spaceup=true

for i=0 to 49

if bulletexists=true
bx=bx+3
by=by+3
sprite i,bx,by,0
if bx>800 or by>600
sprite off i
bulletexists=false
end if
end if
next
until up

04-27-2003 00:23

Posted by:
Ashlin Aronin

Click Here to Email Ashlin Aronin   Find more posts by Ashlin Aronin

Thanks matteo for your code. I was stuck too.
I changed a few things around, and here it is:
int bulletexists[50]
float bx[50]
float by[50]
int spriteName
int n 'current bullet sprite
int spaceup
graphics mode 800,600
load images 128
set framerate 60
repeat
draw frame
if space and spaceup=true
n=0

repeat
n=n+1
until bulletexists[n]=false or n>48

bulletexists[n]=true
bx[n]=0
by[n]=0
spaceup=false
end if

if not space then spaceup=true

for spriteName=0 to 49

if bulletexists[n] =true
bx[n] =bx[n] +0.1
by[n] =by[n] +0
sprite spriteName,bx[n] ,by[n] ,0
if bx[n] >800 or by[n] >600
sprite off spriteName
bulletexists[n] =false
end if
end if
next
until up

But whenever space is pressed while the bullet is moving, the bullet reappears at the top left corner of the screen and the previous bullet is deleted. I want it to keep it!

Sorry for being such a beginner.

Thanks so much,
Ashlin

04-27-2003 01:01

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

oh, no, something chewed up my code, that' s why it does not work!!
when you put open bracket -i-close bracket it takes it as a text format stuff!! oh well, this is it again:

int bulletexists[50]
float bx[50]
float by[50]
int spriteName
int n 'current bullet sprite
int spaceup
graphics mode 800,600
load images 128
set framerate 60
repeat
draw frame
if space and spaceup=true
n=0

repeat
n=n+1
until bulletexists[n]=false or n>48

print(n)

bulletexists[n]=true
bx[n]=0
by[n]=0
spaceup=false
end if

if not space then spaceup=true

for n=0 to 49

if bulletexists[n] =true
bx[n] =bx[n] +5
by[n] =by[n] +5
sprite n,bx[n] ,by[n] ,0
if bx[n] >800 or by[n] >600
sprite off n
bulletexists[n] =false
end if
end if
next
until up

04-27-2003 01:22

Posted by:
Ashlin Aronin

Click Here to Email Ashlin Aronin   Find more posts by Ashlin Aronin

Thanks so much, matteo!

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.