REM Project: Asteroids REM Created: 13-02-2006 12:01:43 REM REM ***** Main Source File ***** REM `Purpose : Entry in the dbp-challenge thread, aaaan to get me started with dbp again. `Settings sync on sync rate 60 hide mouse set display mode 1024, 768, 32 disable escapekey set image colorkey 0, 0, 0 color backdrop rgb(0, 0, 0) `\\\\ `Constants #constant thingy = 120 #constant backGrnd = 1 #constant laserImg = 3 #constant fireImg = 4 #constant fireSpr = 25 #constant maxLaser = 24 #constant minLaser = 4 #constant coolDown = 3.25 #constant laserSpeed = 5 `\\\\ `Setup vectors movement=1 thrust=2 currentPos=3 newPos=4 tmpMovement=5 null=make vector2(movement) null=make vector2(thrust) null=make vector2(currentPos) null=make vector2(newPos) null=make vector2(tmpMovement) `\\\\ `And type(s) type spr nr AS integer xPos AS integer yPos AS integer ang AS float endtype `\\\\ `Variables plr AS spr fAngles AS float plr.nr=2 plr.xPos=0 plr.yPos=0 nextLaser AS integer nextLaser=4 time AS float `\\\\ `Self explanatory... drawBackground( thingy, backGrnd ) set sprite backGrnd, 0, 0 sprite backGrnd, 0, 0, backGrnd cls drawShip(plr.nr) set sprite plr.nr, 0, 1 sprite plr.nr, screen width()/2, screen height()/2, plr.nr offset sprite plr.nr, 10, 10 cls drawLaser( laserImg ) set sprite laserImg, 0, 1 cls drawFire( fireImg ) set sprite fireSpr, 0, 0 sprite fireSpr, 0, 0, fireImg offset sprite fireSpr, 8, 4 cls `\\\\ `**** ENTER LOOP **** repeat plr.xPos=sprite x(plr.nr) plr.yPos=sprite y(plr.nr) if plr.xPos>1024 plr.xPos=0 sprite plr.nr, plr.xPos, plr.yPos, plr.nr endif if plr.xPos<0 plr.xPos=1024 sprite plr.nr, plr.xPos, plr.yPos, plr.nr endif if plr.yPos>768 plr.yPos=0 sprite plr.nr, plr.xPos, plr.yPos, plr.nr endif if plr.yPos<0 plr.yPos=768 sprite plr.nr, plr.xPos, plr.yPos, plr.nr endif if mouseclick()=1 or mouseclick()=3 if time>coolDown sprite nextLaser, sprite x(plr.nr), sprite y(plr.nr), laserImg set sprite nextLaser, 0, 1 offset sprite nextLaser, 1, 4 rotate sprite nextLaser, sprite angle( plr.nr ) inc nextLaser, 1 time=0 endif endif if mouseclick()=2 or mouseclick()=3 show sprite fireSpr x# = sin(fAngle) y# = cos(fAngle + 180) set vector2 thrust, x#, y# scale vector2 thrust, thrust, 0.1 add vector2 tmpMovement, thrust, movement if length vector2(tmpMovement)<8 add vector2 movement, thrust, movement endif else hide sprite fireSpr endif fAngle=wrapvalue( fAngle+mousemovex()/2 ) rotate sprite plr.nr, fAngle set vector2 currentPos, sprite x(plr.nr), sprite y(plr.nr) add vector2 newPos, movement, currentPos plr.xPos=x vector2(newPos) plr.yPos=y vector2(newPos) gosub update sync until escapekey() `**** END OF LOOP **** `Clean up when app exits: null=delete vector2(movement) null=delete vector2(thrust) null=delete vector2(currentPos) null=delete vector2(newPos) null=delete vector2(tmpMovement) `\\\\ update: updateLasers(laserSpeed) sprite plr.nr, plr.xPos, plr.yPos, plr.nr inc time, 0.1 if nextLaser>maxLaser nextLaser=minLaser endif sprite fireSpr, sprite x( plr.nr ), sprite y( plr.nr ), fireImg rotate sprite fireSpr, sprite angle( plr.nr ) move sprite fireSpr, -20 return function drawBackground( stars, imgNr ) for x=0 to stars dot rnd(screen width()), rnd(screen height()), rgb(220, 220, 220) next x get image imgNr, 0, 0, screen width(), screen height() endfunction function drawShip( imgNr ) `left line line 0, 20, 10, 0 `right line line 20, 20, 10, 0 `bottom line line 0,20, 20, 20 get image imgNr, 0, 0, 21, 21 endfunction function drawLaser( imgNr ) for x=0 to 1 line x, 0, x, 8 next x get image imgNr, 0, 0, 2, 8 endfunction function drawFire( imgNr ) for x=0 to 16 if y=3 line 8, 0, x, 8 y=0 endif inc y next x get image imgNr, 0, 0, 16, 8 endfunction function updateLasers(speed) for x= minLaser to maxLaser if sprite exist( x ) move sprite x, speed `collision endif if sprite exist( x ) if sprite x( x )>1024 delete sprite x endif endif if sprite exist( x ) if sprite x( x )<0 delete sprite x endif endif if sprite exist( x ) if sprite y( x )>768 delete sprite x endif endif if sprite exist( x ) if sprite y( x )<0 delete sprite x endif endif next x endfunction