ok... i tried to do that with my program but im not sure i understand everything that i did (a small amount of copy and past).
Before i read your post i figured out how to fire a missle from the ship... i only want one missle on the screen at once so i got it to work well... then i tried to do the same thing with a laser but i want more than 1 on the screen at once... so i tried the array for that... heres the problem....
When the program starts and i want to fire a missle it works fine... then when i want to fire the laser i get problems
first problem is that it is not the image of the laser that i drew it is the image of the missle
second it fires off to the right and i want it to go up... heres the code that i used
Rem Project: ProjectX
Rem Created: 8/31/2006 12:30:36 AM
Rem ***** Main Source File *****
REM Set Screen
Set Display Mode 640, 480, 16
sync on
sync rate 0
Hide Mouse
cls
Print " ProjectX v0.1"
Print " By Chris Fodge"
REM Variables
MainX = 320
MainY = 445
REM Load Theme Music
Load Music "ProjectX Theme.MID", 1
Loop Music 1
REM create a border
LINE 0,0,639,0
LINE 639,0,639,479
LINE 639,479,0,479
LINE 0,479,0,0
REM Set up array for bullets
#constant PLYR 1
#constant BUL 2
type bullet
x as integer
y as integer
ang as float
endtype
DIM bullets(-1) as bullet
Global LS as integer = 10
REM Load Main Ship sprite
load image "ship2.bmp", 1
sprite PLYR, MainX, MainY,1
set sprite 1, 1, 1
Size Sprite 1,30,30
Rotate sprite 1, 90
REM Load laser sprite
load image "laser.bmp",3
sprite BUL,0,0,3
size sprite BUL,30,30
REM Main Loop
time = timer()
DO
REM Move sprite left
IF Leftkey() THEN MOVE SPRITE PLYR, -4
REM Move sprite right
IF Rightkey() THEN MOVE SPRITE PLYR, 4
REM Fire a missle
if spacekey() then firemissle()
REM Fire a laser
if upkey() then firelaser()
REM Set border on the X axis
if sprite x(PLYR) < 30 then sprite PLYR, 30, sprite y(1), 1
if sprite x(PLYR) > screen width() then sprite PLYR, screen width(), sprite y(PLYR), 1
REM Set border on the Y axis (not used by Main Ship)
if sprite y(PLYR) < 0 then sprite PLYR, sprite x(PLYR), 0, 1
if sprite y(PLYR) > screen height() then sprite PLYR, sprite x(PLYR),screen height(), 1
Drawlaser()
ink 0,0
text 0,0,str$(array count(Bullets())) `this prints thesize of the array, -1 means nothing there
sync
LOOP
REM Functions
function firemissle
REM Load Missle sprite
load image "missle.bmp", 2
sprite 2,sprite x(PLYR)- 18,sprite y(PLYR),2
set sprite 2,1,1
size sprite 2,7,10
Rotate sprite 2, 360
Hide sprite 2
REM Display missle
show sprite 2
Repeat
REM Allow sprite(1) to move while firing
IF Leftkey() THEN MOVE SPRITE PLYR, -4
IF Rightkey() THEN MOVE SPRITE PLYR, 4
REM Set Borders for sprite(1) while fireing
if sprite x(PLYR) < 30 then sprite PLYR, 30, sprite y(PLYR), 1
if sprite x(PLYR) > screen width() then sprite PLYR, screen width(), sprite y(PLYR), 1
if sprite y(PLYR) < 0 then sprite PLYR, sprite x(PLYR), 0, 1
if sprite y(PLYR) > screen height() then sprite PLYR, sprite x(PLYR),screen height(), 1
REM Update the Y Position
if sprite y(2) > -10 then move sprite 2, 4
sync
until sprite y(2) < -10
endfunction
function drawlaser
REM Fire a missle
if spacekey() then firemissle()
ind = array count (Bullets())
if ind <> -1
for i = 0 to ind
if i <= array count (Bullets())
sprite BUL,Bullets(i).x, Bullets(i).y, BUL `position the bullet sprite to the bullet
rotate sprite BUL, Bullets(i).ang
move sprite BUL, 4 `move it
Bullets(i).x = sprite x(BUL) `update the position to the array
Bullets(i).y = sprite y(BUL)
paste sprite BUL, Bullets(i).x, Bullets(i).y `draw the bullet
if Bullets(i).x < 0 or Bullets(i).x > screen width() or Bullets(i).y < 0 or Bullets(i).y > screen height()
array delete element Bullets(), i `if it's out-of-bounds then delete it
endif
endif
next
endif
endfunction
function firelaser
LS = LS - 1
`this is so that it wont shoot every flick, try changing LS = 10 to LS = 1 to see why this is needed
if LS < 1
array insert at bottom Bullets() ` add an empty space at the end of the array
ind = array count(Bullets()) ` this is the newly added space in Bullets
Bullets(ind).x = sprite x(PLYR)
Bullets(ind).y = sprite y(PLYR)
Bullets(ind).ang = sprite angle(PLYR)
LS = 10
endif
endfunction
thanks in advance