Hey! I am new to Darkbasic. I did a tutorial and modified it a little. Before I modded it, it was a shoot em up game like when plane was flying to right, and the background was scrolling.
after I modified it I made it scroll down and plane face up like a game called Swarm.
But now I got problems with shooting.
For somereason, when game starts, and i move the plane, and press 'z' to shoot, the laser shoots from where my plane started, and also it only shoots once, if I press z again nothing happens. heres the code
`Getting Game Ready
SYNC ON
SYNC RATE 30
HIDE MOUSE
`Loading Images.
load image "C:\Program Files\The Game Creators\Dark Basic Professional Trial\Projects\Alien Hunter\Images\YourShip.jpg",1
load image "C:\Program Files\The Game Creators\Dark Basic Professional Trial\Projects\Alien Hunter\Images\AlienShip.jpg",2
load image "C:\Program Files\The Game Creators\Dark Basic Professional Trial\Projects\Alien Hunter\Images\GreenLaser.jpg",4
load image "C:\Program Files\The Game Creators\Dark Basic Professional Trial\Projects\Alien Hunter\Images\RedLaser.jpg",5
load image "C:\Program Files\The Game Creators\Dark Basic Professional Trial\Projects\Alien Hunter\Images\Stars.jpg",50
`Loading Sounds.
load sound "C:\Program Files\The Game Creators\Dark Basic Professional Trial\Projects\Alien Hunter\Sounds\Cannon.wav",1
`Make Background
MAKE OBJECT PLAIN 4,127,90
ghost object on 4
POSITION OBJECT 4,0,-4,80
TEXTURE OBJECT 4,50
LOCK OBJECT ON 4
`Color background black
color backdrop rgb(0,0,0)
`Playerfire Score Level and Lives Variables
pf=0:score=0:Level=1:lives=3
`Your Ship X and Y coords
ysx=265:ysy=350
`Places your ship on map
sprite 1,ysx,ysy,1
`Where lazer shoots from
lx=SPRITE X(1)+23
ly=SPRITE Y(1)-60
`Start Main Loop
do
`Print Score Level and Lives on screen
set cursor 10,10: Print "SCORE:";score; " LEVEL:";level;" LIVES:";lives
`Left Key Control
if leftKEY()=1 and ysx>20
dec ysx,10
endif
`Right Key Control
if rightKEY()=1 and ysx<545
inc ysx,10
endif
`Start Shoot Routine
if inkey$()="z" and pf=0 then gosub shoot:pf=1
`If Alien Ship Exists, activate blowitup routine.
if SPRITE EXIST(2)=1
if SPRITE HIT(2,3)=1 then gosub blowitup
endif
`Refresh Your Ship Position
sprite 1,ysx,ysy,1
`Activate Moveall Routine
gosub moveall
`Activate Movestars Routine
gosub movestars
`Refresh Screen
sync
`End of Loop
loop
`Movestars Routine
movestars:
SCROLL OBJECT TEXTURE 4,0.00,-0.01
return
`Shoot Routine
shoot:
sprite 2,lx,ly,4
PLAY SOUND 1
return
`Moveall Routine
moveall:
if SPRITE EXIST(2)=1
If sprite y(2)<300
ly=ly-30
sprite 2,lx,ly,4
endif
endif
if SPRITE EXIST(2)=1
If sprite y(2)>300
pf=0
lx=SPRITE y(1)+23
ly=SPRITE x(1)-60
endif
endif
return
`Blow it Up routine
blowitup:
delete sprite 2
for t=6 to 11
sprite 3,500,200,t
wait 1
next t
delete sprite 3
sleep 500
end
sleep 500
return
-If Practice makes Perfect, and nobody is perfect, why practice?-