forums

TNT Basic Forums > Programming Q&A
multiple bullet sprites
< Last Thread     Next Thread >
Author
Thread        Post A Reply

11-12-2003 20:57

Posted by:
madscientist

Location:
n.ireland

Click Here to Email madscientist   Find more posts by madscientist

ive got a quite qierd problem on the game im working on. i have a ship running about a map which fires bullets each time you hit a button. the ship is pointing in a direction from 0 to 360 and uses trig functions to move the sprite approprietly.
when i fire a bullet it places a sprite at the players coordinates and moves it in the same direction using the same concept. when use print playerx and print bx[6] they will start off the same and prining their directions starts off the same.
unfortunatly, when they draw, the bullets always start of from the positions the ship is in when it starts the game and moves in a diagonal to top left or bottom right.
this makes no sense to me as the ship and the bullet have the same coordinates and so should start in the same place......
anyhow, heres the code if anyone can see whats wrong

----------

graphics mode hardware 800, 600
frame rect 0,0 to 800,600
hide mouse
load images 129
set image bank 0,1
open canvas 1,800,600

global int over=0, hit=-1, fireup
global int direction=0, fire=0
global int bulletexists[50]
global float bx[50],by[50]
global float speed=0
global float playerx=600, playery=500, xvel, yvel
global float bxvel[50],byvel[50],bulletdirection[50]
global int n
set framerate 25
load map 128

set current map 128
open map viewport 1,0, 0,0 to 800,600
set viewport offset 1,0,0
canvas 1
vbl sync off
print "new"

while not over=1
if pressed(55) and fireup=true
n=5

spawnbullet()

end if
if not pressed(55) then fireup=true

movement()

if bulletexists[8]
print "bx";bx[8];" ";by[8];" ";bulletdirection[8]
print "px";playerx;" ";playery;" ";direction
end if
movebullet()
set viewport offset 1,(playerx-400),(playery-300)
draw frame
wend



procedure movement()
sprite 1,playerx,playery,000
if right then direction=direction-4
if left then direction=direction+4
set sprite rotation 1,-direction


if direction>360 then direction=mod(direction,360)
if direction<0 then direction=direction+360*(floor(abs(direction)/360)+1 )

if up
xvel=xvel -(sin (direction))
yvel=yvel +(cos (direction))
end if

if pressed (49)
xvel=0
yvel=0
end if



if xvel>10 then xvel=10
if xvel<-10 then xvel=-10
if yvel>10 then yvel=10
if yvel<-10 then yvel=-10



playerx=playerx+xvel
playery=playery-yvel


if playerx<410 then playerx = 410
if playerx>((map width * map tile width) - 401) then playerx =((map width * map tile width) - 401)
if playery<310 then playery = 301
if playery>((map height * map tile height) - 301) then playery =((map height * map tile height) - 301)


end proc


procedure spawnbullet()
n=5
repeat
n=n+1
until bulletexists[n]=false or n>48

bulletexists[n]=true
bx[n]= playerx
by[n]= playery
fireup=false
bulletdirection[n]=direction
set sprite rotation n,-bulletdirection[n]
bxvel[n] =( -(sin (bulletdirection[n])))'*25
byvel[n] =( (cos (bulletdirection[n])))
end proc

procedure movebullet()
for n=5 to 49
if bulletexists[n]
bx[n]=bx[n] + bxvel[n]
by[n]=bx[n] + byvel[n]
sprite n,bx[n],by[n],001
end if
next
end proc

11-13-2003 12:42

Posted by:
-wyvern

Location:
Bedroom

Find more posts by -wyvern

Look in the directory section for my spacetest file. It has a firing routine and describes how to implement one.

Good luck.

11-13-2003 17:44

Posted by:
madscientist

Location:
n.ireland

Click Here to Email madscientist   Find more posts by madscientist

humble apologies

having spent a week trying to fix this bug (and the last couple of hours searching through that example-which i might add is quite excellent, particularly the comments) i as usual found my own stupid mistake after posting the problem.

can anyone see my incompetence from the source?
try looking at the movebullet() procedure...
specificaly look at the line by[n]=bx[n] +byvel[n]
then notice the x....

i hang my head in shame......

11-13-2003 17:53

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

hmmm... as the old chinese hermit says...

1% of the bugs are hardware bugs

5% of the bugs are compiler bugs (ok, maybe 10% in TNT ;-)

94% of the bugs are bugs in the code, that is, in your brain... ;-)

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.