; ; Space Pirates ; Created by: Ian Stait-Gardner, Javier Bravo and Lexee Munoz ; ;CONST Const SPACEKEY = 57 Const UPKEY = 200 Const DOWNKEY = 208 Const RIGHTKEY = 205 Const LEFTKEY = 203 Const ESCKEY = 1 Const SPRITESIZE = 50 Const SCREENWIDTH = 800 Const SCREENHEIGHT = 600 Const MAXROCKETS = 7 Const ROCKETDMG = 20 ;TYPE Type Friendly Field Health ;Current player health Field X, Y ; Field RCount ;Rockets fired End Type Type Enemy Field Health ; Field X, Y ; Field XVel, YVel ; Field LoadX, LoadY ; Field Action ;0 = Normal, 1 = Load Field Interval ;Number of milliseconds between given action Field LastAct ;Time of last action Field Frame ;Frame to be used End Type Type Attack Field Who ;0 = Player, 1 = Computer Field X, Y, Vel ; End Type Type Explosion Field X, Y Field Size Field Frame End Type ;INITIALIZATION Graphics SCREENWIDTH, SCREENHEIGHT, 0, 1 SeedRnd MilliSecs() ;GLOBAL Global Player.friendly = New friendly Global TCount ;Max Enemies Global KCount ;Enemies Killed Global Ship.Enemy ; Global Rocket.Attack ; ;IMAGES Global imgPlayer = LoadImage("./PLAYER.bmp") Global imgShip = LoadAnimImage("./ENEMY.bmp", 50, 50, 0, 4) Global imgRocket = LoadAnimImage("./ROCKET.bmp", 20, 33, 0, 2) Global imgSmExplode = LoadAnimImage("./SmExpl.bmp", 21, 22, 0, 9) Global imgLgExplode = LoadAnimImage("./LgExpl.bmp", 50, 50, 0, 9) Global imgLoad = LoadImage("./LOAD.bmp") Global imgFG = LoadImage("./FG.bmp") Global imgBG = LoadImage("./BG.bmp") Global imgEND1 = LoadImage("./END1.bmp") Global imgEND2 = LoadImage("./END2.bmp") ;SOUNDS Global sndExplode = LoadSound("BOOM.wav") ;Pre-Game Routines NewLevel() ;Set start Level and Ship Data Player\X = 385 Player\Y = 550 Player\Health = 100 Global Level = 1 ; Global Score = 0 ; Global iBGShift = 0 ; ;LOADING SCREEN DrawImage imgLoad, 12, 0, 0 Repeat Until KeyHit(SPACEKEY) ;Main Loop While Not KeyDown(ESCKEY) ;Check for Key Presses in order to move Player If KeyDown(DOWNKEY) Then Player\Y = Player\Y + 4 If KeyDown(UPKEY) Then Player\Y = Player\Y - 4 If KeyDown(RIGHTKEY) Then Player\X = Player\X + 5 If KeyDown(LEFTKEY) Then Player\X = Player\X - 5 ;Check for SPACE press to fire rocket If KeyHit(SPACEKEY) Then If Player\RCount <= MAXROCKETS Then Rocket.Attack = New Attack Rocket\Who = 0 Player\RCount = Player\RCount + 1 Rocket\X = Player\X + 15 Rocket\Y = Player\Y - 25 Rocket\Vel = -6 End If End If ;Move Rockets ;Moved to CheckCollide Rockets section ;Process Enemy actions ;Moved to CheckCollide Enemies section ;Check for Enemies If KCount >= TCount Then NewLevel() Cls SetBuffer BackBuffer() DoParalax DrawBG DrawHUD CheckCollide DrawExplosions DrawShips Flip Delay 20 If Player\Health <= 0 Then EndGame Wend End Function DrawBG() ;This function Paralaxes the Background layers to present ;the appearance of motion through 3-Dimensional space. End Function Function DrawHUD() ;Draw Level and Score information to the screen. Text 10, 10, "Level: " + Level Text 10, 23, "Score: " + Score Text 10, 580, "Health :" + Player\Health End Function Function CheckCollide() ;Check Ship-Edge collisions. If Player\X <= 0 Then Player\X = 0 If Player\X + 45 >= SCREENWIDTH Then Player\X = SCREENWIDTH - SPRITESIZE If Player\Y <= 0 Then Player\Y = 0 If Player\Y + 50 >= SCREENHEIGHT Then Player\Y = SCREENHEIGHT - SPRITESIZE ;Check Player-Alien, Player-Rocket and Rocket-Alien collisions. For Ship.Enemy = Each Enemy ;Alien-Edge If Ship\X <= 0 Then Ship\XVel = Rnd(1, 5) ElseIf Ship\X >= SCREENWIDTH - SPRITESIZE Then Ship\XVel = Rnd(-1, -5) End If If Ship\Y <= 0 Then Ship\YVel = Rnd(1, 5) ElseIf Ship\Y >= SCREENHEIGHT - SPRITESIZE Then Ship\YVel = Rnd(-1, -5) End If ;Alien-Player If ImagesCollide(imgPlayer, Player\X, Player\Y, 0, imgShip, Ship\X, Ship\Y, Ship\Frame) Then Player\Health = Player\Health - 30 CreateExplosion(Ship\X, Ship\Y, 1) Delete Ship KCount = KCount + 1 Return End If ; ;Process Enemy Action ; Ship\X = Ship\X + Ship\XVel Ship\Y = Ship\Y + Ship\YVel If MilliSecs() >= Ship\Interval + Ship\LastAct Then ;Fire Rocket Rocket.Attack = New Attack Rocket\Who = 1 Ship\LastAct = MilliSecs() Rocket\X = Ship\X + 15 Rocket\Y = Ship\Y + 25 Rocket\Vel = 5 ;Change Direction Ship\XVel = Rnd(-5, 5) Ship\YVel = Rnd(-3, 3) End If Next For Rocket.Attack = Each Attack ; ;Move Rockets ; Rocket\Y = Rocket\Y + Rocket\Vel ;Rocket-Edge If Rocket\Y < -15 Or Rocket\Y > SCREENHEIGHT Then If Rocket\Who = 0 Then Player\RCount = Player\RCount - 1 Delete Rocket Return End If ;Rocket-Player If Rocket\Who = 1 Then If ImagesCollide(imgPlayer, Player\X, Player\Y, 0, imgRocket, Rocket\X, Rocket\Y, 0) Then Player\Health = Player\Health - ROCKETDMG CreateExplosion(Rocket\X, Rocket\Y, 0) Delete Rocket End If Else ;Rocket-Alien For Ship.Enemy = Each Enemy If ImagesCollide(imgShip, Ship\X, Ship\Y, 0, imgRocket, Rocket\X, Rocket\Y, 0) Then Ship\Health = Ship\Health - ROCKETDMG If Ship\Health <= 0 Then CreateExplosion(Ship\X, Ship\Y, 1) Delete Ship Score = Score + 100 KCount = KCount + 1 Else CreateExplosion(Rocket\X, Rocket\Y, 0) End If Delete Rocket Player\RCount = Player\RCount - 1 Return End If Next End If Next End Function ;Draw Rocket, Aliens and Player Function DrawShips() DrawImage imgPlayer, Player\X, Player\Y For Rocket.Attack = Each Attack DrawImage imgRocket, Rocket\X, Rocket\Y, Rocket\Who Next For Ship.Enemy = Each Enemy DrawImage imgShip, Ship\X, Ship\Y, Ship\Frame Next End Function Function NewLevel() Level = Level + 1 ;Reward player with extra health for completing a level Player\Health = Player\Health + (Level * 5) KCount = 0 TCount = Level * 5 ;Set Enemies For e = 1 To TCount Ship.Enemy = New Enemy Ship\Health = Level * 15 Ship\X = Rnd(100, 700) Ship\Y = Rnd(30, 230) Ship\Interval = Rnd(2500, 4000) Ship\LastAct = MilliSecs() Ship\XVel = Rnd(-5, 5) Ship\YVel = Rnd(-3, 3) Ship\Frame = Rnd(0, 3) Next End Function ;Update explosion Function DrawExplosions() For Explode.Explosion = Each Explosion Explode\Frame = Explode\Frame + 1 If Explode\Frame > 8 Then Delete Explode Return End If If Explode\Size = 0 Then DrawImage imgSmExplode, Explode\X, Explode\Y, Explode\Frame Else DrawImage imgLgExplode, Explode\X, Explode\Y, Explode\Frame End If Next End Function ;Create a new explosion at given coordinates Function CreateExplosion(X, Y, Size) Explode.Explosion = New Explosion Explode\Size = Size Explode\X = X Explode\Y = Y Explode\Frame = 0 PlaySound sndExplode End Function ;Draw Game Over screen Function EndGame() Cls DrawImage imgEND1, 225, 50, 0 DrawImage imgEND2, 215, 200, 0 Text 360, 525, "GAME OVER!" Text 340, 555, "Hit ESC to Exit." Flip Repeat Until KeyHit(1) End End Function ;Paralax background to simulate movement through space Function DoParalax() TileBlock imgBG, 0, 0 + BGShift/2 TileImage imgFG, 0, 0 + iBGShift iBGShift = iBGShift + 1 End Function