MainGame1:
cls
rem Main Game loop
rem Setting up variables/star field background
sprite 30,0,0,40
GLOBAL px=450
GLOBAL py=650
GLOBAL firerocket1=0
GLOBAL firerocket2=0
GLOBAL firelasers=0
GLOBAL rx1
GLOBAL rx2
GLOBAL ry1
GLOBAL ry2
GLOBAL lx
GLOBAL ly
GLOBAL redmax=50
GLOBAL yellowmax=3
GLOBAL Score=0
GLOBAL Health=10
dim EnemyID(1000)
dim EnemyY(1000)
for a=1 to 1000
EnemyID(a)=a+60
next a
set sound volume 1,40
set sound volume 2,40
set sound volume 3,40
set sound volume 4,40
set animation speed 1,30
do
text 50,50,"Score: " + str$(Score)
if Health=>1
sprite 5,px,py,1
endif
if Health=0
exit
endif
if Score>10000
endif
MakeEnemy()
MoveEnemy()
MoveEnemies()
DeleteEnemy()
EnemySuicide()
if sprite exist(10)=1
LaserHit()
endif
if sprite exist(11)=1
Rocket1Hit()
endif
if sprite exist(12)=1
Rocket2Hit()
endif
if LeftKey()=1
MoveLeft()
endif
if RightKey()=1
MoveRight()
endif
if inkey$()="q"
FireRockets()
endif
if inkey$()="w"
FireLasers()
endif
if Sprite Exist(10)=1
MoveLasers()
endif
if SPRITE EXIST(11)=1 or SPRITE EXIST(12)=1
MoveRockets()
endif
sync
loop
exit
Function MoveLeft()
if px>60
dec px,10
endif
endfunction
Function MoveRight()
if px<950
inc px,10
endif
endfunction
Function FireRockets()
if firerocket1=0
SetRocketCoord()
sprite 11,rx1,ry1,11
play sound 3
firerocket1=1
endif
if firerocket2=0
SetRocketCoord()
sprite 12,rx2,ry2,11
play sound 3
firerocket2=1
endif
endfunction
Function FireLasers()
if firelasers=0
SetLaserCoord()
sprite 10,lx,ly,10
play sound 2
firelasers=1
endif
endfunction
Function SetRocketCoord()
rx1=SPRITE X(5)+34
rx2=SPRITE X(5)+100
ry1=SPRITE Y(5)+20
ry2=SPRITE Y(5)+20
endfunction
Function SetLaserCoord()
lx=SPRITE X(5)+50
ly=SPRITE Y(5)+20
endfunction
Function MoveLasers()
if sprite exist(10)=1
if ly>10
dec ly,30
Sprite 10,lx,ly,10
endif
if ly=<10
delete sprite 10
firelasers=0
endif
endif
endfunction
Function MoveRockets()
if sprite exist(11)=1
if ry1>10
dec ry1,45
sprite 11,rx1,ry1,11
endif
if ry1<10
delete sprite 11
firerocket1=0
endif
endif
if sprite exist(12)=1
if ry2>10
dec ry2,45
sprite 12,rx2,ry2,11
endif
if ry2<10
delete sprite 12
firerocket2=0
endif
endif
endfunction
rem Makes the enemy(10 at a time)
Function MakeEnemy()
for a=1 to redmax
if Sprite Exist(enemyID(a))=0
EnemyY(a)=rnd(800)-1000
sprite enemyID(a),rnd(800)+70,EnemyY(a),3
endif
next a
for a=redmax+1 to redmax+yellowmax
if Sprite Exist(enemyID(a))=0
EnemyY(a)=rnd(500)-1500
sprite enemyID(a),rnd(800)+70,EnemyY(a),4
endif
next a
endfunction
rem Increases the y coordinate of all the enemies
Function MoveEnemies()
for a=1 to redmax
inc EnemyY(a),5
next a
for a=redmax+1 to redmax+yellowmax
inc EnemyY(a),15
next a
endfunction
rem Resets the position of the enemies with a new y coordinate
Function MoveEnemy()
for a=1 to redmax
if Sprite Exist(enemyID(a))=1
enemyx=Sprite X(enemyID(a))
sprite enemyID(a),enemyx,EnemyY(a),3
endif
next a
for a=redmax+1 to redmax+yellowmax
if Sprite Exist(enemyID(a))=1
enemyx=Sprite X(enemyId(a))
sprite enemyID(a),enemyx,EnemyY(a),4
endif
next a
endfunction
rem Deletes the Enemy if it goes past a certain point on the y axis
Function DeleteEnemy()
for a=1 to 1000
if sprite exist(enemyID(a))=1
if Sprite Y(enemyID(a))>800
delete sprite enemyID(a)
endif
endif
next a
endfunction
rem If an enemy sprite hits the player sprite, deletes the enemy sprite and decreases health by 1
Function EnemySuicide()
for a=1 to redmax+yellowmax
if Sprite Exist(enemyID(a))=1
if sprite hit(5,enemyID(a))
delete sprite enemyID(a)
dec Health
play sound 4
endif
endif
next a
endfunction
rem Responsible for weapons destroying things
Function LaserHit()
for a=1 to redmax+yellowmax
if Sprite Exist(enemyID(a))=1
if sprite hit(10,enemyID(a))
play animation 1,SPRITE X(enemyID(a)),SPRITE Y(enemyID(a))
delete sprite enemyID(a)
inc Score,100
play sound 4
endif
endif
next a
endfunction
Function Rocket1Hit()
for a=1 to redmax+yellowmax
if sprite exist(11)=1
if Sprite Exist(enemyID(a))=1
if sprite hit(11,enemyID(a))
play animation 1,SPRITE X(enemyID(a)),SPRITE Y(enemyID(a))
delete sprite enemyID(a)
delete sprite 11
firerocket1=0
inc Score,100
play sound 4
endif
endif
endif
next a
endfunction
Function Rocket2Hit()
for a=1 to redmax+yellowmax
if sprite exist(12)=1
if Sprite Exist(enemyID(a))=1
if sprite hit(12,enemyID(a))
play animation 1,SPRITE X(enemyID(a)),SPRITE Y(enemyID(a))
delete sprite enemyID(a)
delete sprite 12
firerocket2=0
inc Score,100
play sound 4
endif
endif
endif
next a
endfunction
Me and 2 of my friends decided we want to try making some games, so i'm currently trying to learn 3d modelling and also DarkBASIC pro, and i've been using darkbasic for about 4 days or so now. For some reason the text and print commands won't show up, and also i can't get animations to work. Above is part of my code which i'm having the problems with and if you see anything else i can correct please let me know. And also, if anyone can direct me to a decent tutorial on making a basic 3d game it will be appreciated.
Thanks