Although the game isnt finished, it still proves somewhat entertaining, and was made to help bug squashing to be more fun.
It uses FMOD for sound and a custom GL engine in progress.
Any Bugs are welcome for reporting.
Edit, esc Quits, left right move ship, space shoot. Other commands on screen.
http://www.mediafire.com/file/mda1wg4nm ... vaders.rar Link for Unfinished Game exe
And for those who beleive in silly Sonar Type Technology, the Main Source for the Game.
Code: Select all
;****************************************************************
;Space Invaders
;by Booger and Epidemicz
;Started 10/2010
;****************************************************************
CompilerIf #PB_Compiler_Thread = 0
CompilerError "Must be compiled in ThreadSafe Mode, no exceptions..."
CompilerEndIf
IncludeFile "MediaPacker.pbi";Packs media into exe
IncludeFile "DumpFiles.pbi"; Dumps files to Temp Directory. Needs to be before FmodSoundLibrary.pb
IncludeFile "..\fmod\FmodSoundLibrary.pb";Sound Functions
IncludeFile "..\OpenGLEngine\openglGlobals.pb"
IncludeFile "..\OpenGLEngine\OpenGLSpriteEngine.pb"
IncludeFile "MediaUnpacker.pbi";Functions to unpack media from exe
;Global screenid ;Window hwnd (Idenity)
;***************************************************************************************
;-Define window parameters
GLWindow\x = 800
GLwindow\y = 600
GLwindow\bits = 32
GLWindow\Name = "GL Invaders"
GlWindow\Fullscreen = #False
;***************************************************************************************
;Set Process Priority and create Window
SetPriorityClass_(GetCurrentProcess_(), 32) ; Real Time process priority 32=normal
Global thread = CreateThread(@CreateGLWindow(), 0); The parameter here is a dummy, it doesnt pass
;***************************************************************************************
;Make sure window creation calls have finished before trying to get contexts'uals etc...
Repeat
Sleep_(1)
Until WindowCreated = #True
;**************************************************************************************************
; Sets up our threaded window so we can draw on it.(OpenGLBackBone2.pb)
GetWindowGoodies()
;**************************************************************************************************
;clear screen (rgb value)
glClearScreen(0)
;**************************************************************************************************
;Initialize Sound engine and load Sounds
FmodInit(255)
FmodLoadSoundMem(1, ?SpaceInvaders_AlienSXwav, ?SpaceInvaders_AlienSXwavEnd)
FmodLoadSoundMem(2, ?SpaceInvaders_Bass01Xwav, ?SpaceInvaders_Bass01XwavEnd)
FmodLoadSoundMem(3, ?SpaceInvaders_Bass02Xwav, ?SpaceInvaders_Bass02XwavEnd)
FmodLoadSoundMem(4, ?SpaceInvaders_Bass03Xwav, ?SpaceInvaders_Bass03XwavEnd)
FmodLoadSoundMem(5, ?SpaceInvaders_Bass04Xwav, ?SpaceInvaders_Bass04XwavEnd)
FmodLoadSoundMem(6, ?SpaceInvaders_BassLoXwav, ?SpaceInvaders_BassLoXwavEnd)
FmodLoadSoundMem(7, ?SpaceInvaders_DeathXwav, ?SpaceInvaders_DeathXwavEnd)
FmodLoadSoundMem(8, ?SpaceInvaders_FireXwav, ?SpaceInvaders_FireXwavEnd)
FmodLoadSoundMem(9, ?SpaceLoopXogg, ?SpaceLoopXoggEnd)
FmodLoadSoundMem(10, ?ZMotherShipDieXwav, ?ZMotherShipDieXwavEnd)
FmodLoadSoundMem(11, ?zSpaceInvaderMobDieXwav, ?zSpaceInvaderMobDieXwavEnd)
FmodLoadSoundMem(12, ?ZSpaceInvaders_AlienSDieXwav, ?ZSpaceInvaders_AlienSDieXwavEnd)
FmodLoadSoundMem(13, ?zzzPlayerDeathXwav, ?zzzPlayerDeathXwavEnd)
FmodLoadSoundMem(14, ?zzzzExtraGuyXwav, ?zzzzExtraGuyXwavEnd)
;**************************************************************************************************
;Test sound loop thread
FmodSetSoundLooping(1, #True)
;FmodSetSoundLooping(9, #True)
;FmodPlaySound(9)
;**************************************************************************************************
;Load Sprites out of exe
LoadSprites()
;**************************************************************************************************
;Build Font
glcolorkey = RGB(0, 0, 0)
BuildFont(1, "Arial")
SelectFont(1)
;**************************************************************************************************
;Enable 2d
glenable2d()
;**************************************************************************************************
;-Player STructures (Temp)
Structure info
x.d
y.d
animation1.l
animation2.l
animation3.l
currentAnimation.l
sizex.l
sizey.l
dead.l
CanFire.l
BulletTimer.f
BulletEvent.l
EndStructure
Global Dim barricade.info(128) ;holds barriade collision info
Global Player.info
Global bullet.info
Global Dim MobBullet.info(10)
Global MotherShip.info
Global MotherShip\sizex = 48
Global MotherShip\sizey= 21
Global Ships=3
Global Numberofbulletsallowed = 3
player\sizex=26
player\sizey=16
;-Game Constants
#COLOR_SEG_SIZE = 71 ;pixel size of each color segment
#COLOR_SEG_START = 580 ;color segments start at this screen location
#PlayerBULLET_SPEED = 12.0 ;12.0 for normal
#BarricadeSpriteStart=60 ;Size total for barricade=128
#MobSpriteStart=4 ;Size Total for Mobs=55
#BottomLineSpriteStart=189 ;Size Total for Line=134
#BaricadeYPos=440
#BaricadeXPos=150
#BaricadeSpacing=100
#PlayerStartX=160
#PlayerstartY=480
;==================================================================================================
;-Setup Mob Arrays and Vars
;==================================================================================================
PlayerStop = 100
MobStop = PlayerStop-24
MotherShipSpeed.f = 1.8
MotherShipEventTime = 22.0
MobTimeSetting.f = 0.81
MobBeepEventTime.f = MobTimeSetting.f
MobShooteventTime.f = 0.2
BulletAnimationTime.f = 0.08 ;mob bullet animation timer
Global Moby = 300
Global MobYSpace = 34
Global Dim Mobs.info(11, 5)
Global Dim MobShooters.info(11)
Global Dim MobIsFiring(10)
Global Dim MobBullet(10)
Global Dim MobBulletInRoute(10)
Global Dim MobFire(10)
;**************************************************************************************************
;-Procedures
Procedure GetColorSegment(position)
;************************
;This procedure takes the position of a given screen object (y coord)
;And it will give you the correct color accordingly
;Return value is in RGBA format
;Can use fastred, fastgreen, fastblue with glColor4ub()
;Ex: mobRow1Color = GetColorSegment(100)
;glColor4ub(fastred(mobRow1Color), fastgreen(mobRow1Color), fastblue(mobRow1Color), 255)
;then draw sprites - with the correct cellophane color :).
;************************
Protected travelled = #COLOR_SEG_START - position
Protected colorseg = travelled / #COLOR_SEG_SIZE
Protected color
Select colorseg
Case 0:
color = RGBA(255, 0, 0, 255) ;red
tmp$ = "RED"
Case 1:
color = RGBA(215, 215, 0, 255) ;yeller
tmp$ = "YELLER"
Case 2:
color = RGBA(255, 0, 255, 255) ;magenta
tmp$ = "MAGENTA"
Case 3 :
color = RGBA(0, 255, 255, 255) ;cyan or nasty blue
tmp$ = "LGT BLUE"
Case 4 :
color = RGBA(0, 255, 0, 255) ;green
tmp$ = "GREEN"
Case 5 :
color = RGBA(0, 0, 215, 255) ;dark blue
tmp$ = "DRK BLUE"
Case 6 :
color = RGBA(255, 0, 255, 255) ;magenta
tmp$ = "MAGENTA"
EndSelect
;text(100, position, ":)", color)
;;-debug tmp$ + "----" + Str(colorseg)
ProcedureReturn color
EndProcedure
Procedure CheckCollisionBullet(x0, y0, x1, y1)
;x0 is Rect X to check against (Left)
;x1 is Rect Y to check against (Top)
x1 = (x0 + x1) ;Width of Rect (Right)
y1 = (y0 + y1) ;Length of Rect (Bottom)
x2 = bullet\x + 2 ;Bullet X (Left)
y2 = bullet\y ;Bullet Y (Top)
x3 = (x2 + 2) ;Width of bullet (Right Side)
y3 = (y2 + 12) ;Length of Bullet (Bottom)
If (x1<x2 Or x3<x0 Or y1<y2 Or y3<y0) ;See if rectangles overlap
ProcedureReturn #False
Else
ProcedureReturn #True
EndIf
EndProcedure
Procedure MobCheckCollisionBullet(x0, y0, x1, y1, a)
;x0 is Rect X to check against (Left)
;x1 is Rect Y to check against (Top)
x1 = (x0 + x1) ;Width of Rect (Right)
y1 = (y0 + y1) ;Length of Rect (Bottom)
x2 = Mobbullet(a)\x ;Bullet X (Left)
y2 = Mobbullet(a)\y ;Bullet Y (Top)
x3 = (x2 + 2) ;Width of bullet (Right Side)
y3 = (y2 + 12) ;Length of Bullet (Bottom)
If (x1<x2 Or x3<x0 Or y1<y2 Or y3<y0) ;See if rectangles overlap
ProcedureReturn #False
Else
ProcedureReturn #True
EndIf
EndProcedure
Prototype.l P_wglSwapIntervalEXT(nInterval.l)
Procedure.l GL_Set_VSync(lInterval.l) ; enable or disable the VSync
; call it *AFTER* you have checked the vsync control is supported by your driver with GL_VSync_Supported()
Protected wglSwapIntervalEXT_.P_wglSwapIntervalEXT = wglGetProcAddress_("wglSwapIntervalEXT")
ProcedureReturn wglSwapIntervalEXT_(lInterval) ; #True if successful
EndProcedure
Procedure ResetMobs()
;************************************
;This procedure replaces all mobs and barricades
;************************************
FmodSetSoundLooping(9, #True)
FmodPlaySound(9)
FmodSetSoundVol(9, 0.2)
glDeleteSprite(555) ;delete the last dead mob sprite ?why?
Debug Numberofbulletsallowed
For a = 0 To Numberofbulletsallowed ;cheating fucker killed me after he died!
MobBulletInRoute(a) = #False
Next
For a = 1 To 11
With mobs(a, 5) ;Bottom Row
\animation1 = 40
\animation2 = 41
\sizex = 24
\sizey = 16
\y = Moby
\x = 140 + (a*40)
\dead = 0
EndWith
Next a
For a = 1 To 11
With Mobs(a, 4) ;Fourth Row
\animation1 = 40
\animation2 = 41
\sizex = 24
\sizey = 16
\y = Moby-MobYSpace
\x = 140 + (a*40)
\dead = 0
EndWith
Next a
For a = 1 To 11
With Mobs(a, 3) ;Third Row
\animation1 = 38
\animation2 = 39
\sizex = 24
\sizey = 16
\y = Moby-MobYSpace*2
\x = 140 + (a*40)
\dead = 0
EndWith
Next a
For a = 1 To 11
With Mobs(a, 2) ;Second Row
\animation1 = 38
\animation2 = 39
\sizex = 24
\sizey = 16
\y = Moby-MobYSpace*3
\x = 140 + (a*40)
\dead = 0
EndWith
Next a
For a = 1 To 11
With Mobs(a, 1) ;First Row
\animation1 = 36
\animation2 = 37
\sizex = 24
\sizey = 16
\y = Moby-MobYSpace*4
\x = 140 + (a*40)
\dead = 0
EndWith
Next a
a = 0 ;setting up barricade
xPos = #BaricadeXPos ;starting x loc of barricade
yPos = #BaricadeYPos ;starting y loc of barricade
For x = 1 To 4 ;Display barricades (4 of them)
For c = 0 To 7 ;Columns
For r = 0 To 3 ;Rows
;adding collision info to structure
With barricade(a)
\dead = #False ;new barricades aren't dead yet
\x = xPos
\y = yPos + (8*r)
\sizex = 6
\sizey = 8
EndWith
;these are two barricade pieces are invisible
;collison does not need to happen on these.
If (c = 3 And r = 3) Or (c = 4 And r = 3)
barricade(a)\dead = #True
EndIf
a + 1 ;Increase array index counter
Next r
xPos + 6 ;Increase xpos by 6 because we are going over to next column (6px wide)
Next c
xPos + #BaricadeSpacing ;add 100 to our xpos - this is our space between barricades.
Next x ;yay for loops
EndProcedure
Procedure SetupWindow()
;************************************************************************************************
;Experimental procedure to create new window/flip to full screen mode
;Needs work to be intgrated into engine better
;Requires a global thread variable atm
killglwindow()
KillThread(thread)
WindowCreated = #False
SetPriorityClass_(GetCurrentProcess_(), 32) ; Real Time process priority 32=normal
thread = CreateThread(@CreateGlWindow(), 0)
Repeat
; Sleep_(1)
WaitThread(thread, 1) ;this seems to work better - many times it stuck in this loop waiting for windowcreated and never came out
Until WindowCreated = #True
GetWindowGoodies() ;get window handles & the like
LoadSprites() ;need to reload sprites
BuildFont(1, "Arial") ;set up fonts
SelectFont(1)
glEnable2d() ;enable 2d again
GL_Set_VSync(#True) ;turn back on vsync
EndProcedure
;**************************************************************************************************
GL_Set_VSync(#True)
ResetMobs()
;==================================================================================================
player\x = #PlayerStartX
Player\y = #PlayerStartY
;**************************************************************************************************
;-Start our Event Timers
GameEventTimer.d = GetTimer()
StartFPSCounter = GetTimer()
BeepTimer.d = GetTimer()
;**************************************************************************************************
;-Main======================================================================
Main:
Repeat
MainLoopTimer.d =1.0* DeltaTime.d
Time.d = GetTimer()
glClearScreen(0)
text(0, 10, "DeltaTime=" + StrD(deltatime.d))
text(0, 20, "FPS=" + Str(fps))
If Toggle = 0
text(0, 30, "Vsync is ON")
Else
Text(0, 30, "Vsync is Off")
EndIf
Text(0, 50, "Press Down Arrow to toggle Vsync ON/OFF", RGBA(0, 255, 0, 100))
text(0, 65, "Press F1 to toggle fullscreen ON/OFF", RGBA(0, 255, 0, 255))
Text(340, 20, "Score: " + Str(Score), RGBA(0, 255, 0, 100))
Text(30,580,Str(ships), RGBA(0, 255, 255, 255))
;******************************************************
;ships hud
For a = 1 To ships -1
glSprite(399+a, 20+(a*30), 567, 35)
Next
;when mothership is dead
If GetTimer()-MothershipTextEvent<3
Text(Mothership\x, Mothership\y, MotherShipText.s, RGBA(255, 0, 0, 255))
glsprite(3, mothership\x, mothership\y, 60) ;dead sprite
Else
gldeletesprite(3) ;may be better way to do this.
EndIf
r = Keys(#VK_RIGHT) : l = Keys(#VK_LEFT) : sp = Keys(#VK_SPACE) : dwn = keys(#VK_DOWN) : f1 = keys(#VK_F1)
;=================================================================================================
;-Toggle Vsync
If Not dwn
DownToggle = 0
EndIf
If dwn And DownToggle = 0
DownToggle = 1
;resetmobs()
If toggle = 0
Toggle = 1
GL_Set_VSync(#False)
Else
Toggle = 0
GL_Set_VSync(#True)
EndIf
EndIf
If Not f1
f1Toggle = 0
EndIf
If f1 And f1Toggle = 0
f1Toggle = 1
glWindow\fullscreen = ~ glwindow\Fullscreen
SetupWindow()
EndIf
If GameOver = #False
;=================================================================================================
;If MainLoopTimer> = 1.0
;**************************************************************************************************
;-Handles Player
If PlayerDeath=#False
If r And player\x<800-26-PlayerStop
player\x + 2.0*MainLoopTimer
EndIf
If l And player\x>PlayerStop
player\x-2.0*MainLoopTimer
EndIf
glSprite(1, player\x, player\y, 35);place player
Else
;GLDeleteSprite(1)
SetSpriteColorBlend(1, RGBA(255, 0, 0, 255))
If DeathAnimEvent
DeathAnimEvent = #False
ticks + 1 ;number of times this has ran
If ticks > 4 ;only swap animations 4 times
ticks = 0 ;reset animation counter
playerdeath = #False ;let player reset
player\x = #PlayerStartX
Player\y = #PlayerStartY
SetSpriteColorBlend(1, -1) ;turn off color blending for player
EndIf
;starting player death animation is 54
If PlayerAnim = 55 ;this just swaps the animation each time DeathAnimEvent occurs, from 54, 55, 54, 55
PlayerAnim = 54
Else
PlayerAnim = 55
EndIf
EndIf
glSprite(1, player\x, player\y, PlayerAnim);place dead player (current animation)
EndIf
;**************************************************************************************************
;-Handles Bullet
If sp And IsFiring = #False And PlayerDeath = #False
Fire = #True
BulletTimer.f = GetTimer()
EndIf
If Not sp And IsFiring = #True And BulletInRoute = #False
IsFiring = #False
Fire = #False
BulletLife.f = GetTimer()-BulletTimer.f
EndIf
If Fire = #True And IsFiring = #False And BulletInRoute = #False
FmodPlaySound(8)
IsFiring = #True
bullet\x = player\x + 10
bullet\y = player\y-5
EndIf
If IsFiring And Bullet\y>#COLOR_SEG_SIZE
BulletInRoute = #True
For d=1 To #PlayerBULLET_SPEED ;how many pixels are we moving total?
bullet\y-1.0*MainLoopTimer;#BULLET_SPEED*MainLoopTimer ;move one pixel
;===========================================================================
;-Check Collision With bullet and Mobs
;
For b = 1 To 5
For a = 1 To 11
With mobs(a, b)
If \dead = #False
Collide = CheckCollisionBullet(\x, \y, \sizex, \sizey)
;;-debug Collide
If Collide
\dead = #True ;this mob has died, get rid of him
;get correct color for death sprite
;SetSpriteColorBlend(555, GetColorSegment(bullet\y))
glSprite(555, \x, \y, 56) ;drawing death sprite
BulletInRoute = #False ;resetting player bullet
bullet\y = -10;Hide our dead Bullets, they still show to simplify logic
bullet\x = -10;Hide our dead Bullets, they still show to simplify logic
MobBeepEventTime.f-0.0145
Select b ;calculating score
Case 1
score + 30
Case 2
score + 20
Case 3
score + 20
Case 4
score + 10
Case 5
score + 10
EndSelect
FmodPlaySound(11)
gldeletesprite(2);bullet is done. Delete it
MobDeath + 1
If MobDeath>54 ;We Cleared the screen. Reset stuff
MobY + 32;Move mobs down Two Rows
ResetMobs()
MobDeath = 0
MobBeepEventTime.f = MobTimeSetting.f
EndIf
EndIf
EndIf
EndWith
Next a
Next b
;===========================================================================
;-Check Barricades With bullet
spriteCnt = 0 ;reset our spriteCnt var to start at first one
For x = 1 To 4 ;Display barricades (4 of them)
For c = 0 To 7 ;Columns
For r = 0 To 3 ;Rows
With barricade(spriteCnt)
If Not \dead
;If BulletInRoute
Collide = CheckCollisionBullet(\x, \y, \sizex-2, \sizey)
If Collide
\dead = #True
BulletInRoute = #False
bullet\y = 0
bullet\x = 0
gldeletesprite(#BarricadeSpriteStart + spriteCnt)
gldeletesprite(2)
EndIf
EndIf
EndWith
spriteCnt + 1 ;add to sprite counter
imgStart + 1 ;add to image counter
Next r
xPos + 6 ;Increase xpos by 6 because we are going over to next column (6px wide)
Next c
xPos + 100 ;add 100 to our xpos - this is our space between barricades.
imgStart = 2 ;reset our image counter
Next x ;yay for loops
;================================================================================================
;-CheckMothership Collision
;================================================================================================
If MotherShipEvent And MotherShipMoving
;With Mothership
Collide = CheckCollisionBullet(Mothership\x, Mothership\y, Mothership\sizex, Mothership\sizey)
;;-debug Collide
If Collide
glsprite(3, mothership\x, mothership\y, 60)
BulletInRoute = #False
bullet\y = 0
bullet\x = 0
MothershipTextEvent = GetTimer();Start timer for our Mothership Points Display
RandomScore = Random(7) ; Get our 1 out of 3 random score possibility
Select RandomScore
Case 0
score + 100
MotherShipText.s = "100"
Case 1
score + 200
MotherShipText.s = "200"
Case 2
score + 300
MotherShipText.s = "300"
Case 3
score + 50
MotherShipText.s = "50"
Case 4
score + 150
MotherShipText.s = "150"
Case 5
score + 250
MotherShipText.s = "250"
Case 6
score + 50
MotherShipText.s = "50"
Case 7
score + 100
MotherShipText.s = "100"
EndSelect
;gldeletesprite(3);We dont need anymore. Delete Sprite
FmodStopSound(1);Stop the annoying Noise
FmodPlaySound(10)
FmodPlaySound(12)
MotherShipEvent = #False
MotherShipMoving = #False
EndIf
EndIf
;================================================================================================
Next d
;-Draw fighter bullet
SetSpriteColorBlend(2, GetColorSegment(bullet\y))
glSprite(2, bullet\x, bullet\y, 34);place bullet
;GetColorSegment(bullet\y)
Else
glDeleteSprite(2)
If bulletInRoute
glSprite(556, bullet\x - 4, bullet\y, 44) ;show explosion sprite
EndIf
If BeepEvent
glDeleteSprite(556) ;get rid of explosion sprite on next beep
BulletInRoute = #False ;warning this also stops bullet from resetting until next beep
bullet\x = 0 ; i kind of like that imo
bullet\y = 0
EndIf
;Break
EndIf
;**************************************************************************************************
;-Handle Mothership
If MotherShipEvent And MotherShipMoving = #False
FmodPlaySound(1)
FmodSetSoundVol(1, 0.2)
If Random(3) + 1 = 3
MotherShip\x = 800
MotherShipDirection = 0
Else
MotherShip\x = -48
MotherShipDirection = 1
EndIf
MotherShip\y = 80
MotherShipMoving = #True
EndIf
If MotherShipEvent And MotherShipMoving
If MotherShipEvent And MotherShipMoving
If MotherShipDirection = 0 And MotherShip\x>-48;Moving left
MotherShip\x-MotherShipSpeed*MainLoopTimer
GlSprite(3, MotherShip\x, MotherShip\y, 42);Place MotherShip
ElseIf MotherShipDirection = 1 And MotherShip\x<800;Moving right
MotherShip\x + MotherShipSpeed*MainLoopTimer
GlSprite(3, MotherShip\x, MotherShip\y, 42);Place MotherShip
Else
gldeletesprite(3);We dont need anymore. Delete Sprite
FmodStopSound(1);Stop the annoying Noise
MotherShipEvent = #False
MotherShipMoving = #False
EndIf
EndIf
EndIf
;**************************************************************************************************
;-Handle Mobs
If BeepEvent
FireBulletEvent+1
BeepEvent = #False
FmodPlaySound(2 + BeepCount)
glDeleteSprite(555)
BeepCount + 1
If BeepCount>3
BeepCount = 0
EndIf
;=========================================================================
If CheckWallTrigger = #False
For b = 1 To 5 ;-check if mobs need to change direction
For a = 1 To 11
With mobs(a, b)
If \dead = 0
If Not MobDirectionHasChanged
If \x<MobStop
MobDirection = 1
MobDirectionHasChanged = #True
MobDirectionTrigger = #True
CheckWallTrigger = #True
Break;No Reason to continue Loop
EndIf
If \x>800-MobStop-\sizex
MobDirection = 0
MobDirectionHasChanged = #True
MobDirectionTrigger = #True
CheckWallTrigger = #True
Break;No Reason to continue Loop
EndIf
EndIf
EndIf
EndWith
Next a
If MobDirectionHasChanged = #True
Break;Get out of this loop too, Not needed now, we found a mob that hit the wall
EndIf
Next b
EndIf
If MobDirectionTrigger = #True
For b = 1 To 5 ;-Move Mobs
For a = 1 To 11
With mobs(a, b)
\y + 16
EndWith
Next a
Next b
EndIf
;=========================================================================
If MobDirectionHasChanged = #False And MobDirectionTrigger = #False
For b = 1 To 5 ;-Move Mobs
For a = 1 To 11
With mobs(a, b)
If MobDirection = 0
\x-8.0
Else
\x + 8.0
EndIf
EndWith
Next a
Next b
CheckWallTrigger = #False
EndIf
MobDirectionHasChanged = #False
MobDirectionTrigger = #False
;==========================================================================
For b = 1 To 5 ;-swap animations
For a = 1 To 11
With mobs(a, b)
temp = \animation1
\animation1 = \animation2
\animation2 = temp
EndWith
Next a
Next b
EndIf
;**********************************************
For b = 1 To 5 ;-Display Live Mobs
For a = 1 To 11
With mobs(a, b)
If \dead = #False
Rotate = 180
If rotate>360
rotate=0
EndIf
;SetSpriteColorBlend(#MobSpriteStart + Sprite, GetColorSegment(\y + \sizey
;SetSpriteRotation(#MobSpriteStart + sprite, rotate)));checking rebuild of this function on mobs
;SetSpriteAlpha(#MobSpriteStart + Sprite, Random(255))));checking rebuild of this function on mobs
glsprite(#MobSpriteStart + sprite, \x, \y, \animation1)
EndIf
If \dead = #True
gldeletesprite(#MobSpriteStart + sprite)
EndIf
EndWith
sprite + 1
Next a
Next b
Sprite = 0;reset our mob sprite Incrementor
;==========================================================================
;Determine Which Mobs can Shoot
; For a=1 To 11;Clear out Array
;
; Next a
MobShooterCounter = 0
For a = 1 To 11
For b = 5 To 1 Step -1
If Mobs(a, b)\dead = #False
MobShooterCounter + 1
MobShooters(MobShooterCounter)\x = Mobs(a, b)\x
MobShooters(MobShooterCounter)\y = Mobs(a, b)\y
MobShooters(MobShooterCounter)\sizex = Mobs(a, b)\sizex
;MobShooters(0)\CanFire=MobShooterCounter
Break;we found a bottom mob that can shoot, no need to continue loop
EndIf
Next
Next
;;-debug MobShooterCounter
;
;**************************************************************************************************
;-Handles MobBullets
;MobShooter=Random(11)+1
;If FireBulletEvent>2
;Numberofbulletsallowed = 3 -moved to top needed to be global
For a = 1 To NumberOfBulletsAllowed
If MobShootEvent And MobIsFiring(a) = #False And FireBulletEvent>2;
MobFire(a) = #True
MobShootEvent = #False
FireBulletEvent = 0
;********************************************************************************************
;-Handles Random Bullet Generation
mobbullet(a)\currentAnimation = Random(2) ;to start out we grab a random number
Select mobbullet(a)\currentAnimation ;depending on that number set the the bullets
Case 0 ;animation sequence.
mobbullet(a)\currentAnimation = 51 ;up and down bullet
mobbullet(a)\animation1 = 51
mobbullet(a)\animation2 = 52
mobbullet(a)\animation3 = 53
Case 1
mobbullet(a)\currentAnimation = 47 ;zigzag bullet
mobbullet(a)\animation1 = 47
mobbullet(a)\animation2 = 48
mobbullet(a)\animation3 = 49
Case 2 ;zigzag up down bullet (combo bullet)
mobbullet(a)\currentAnimation = 57
mobbullet(a)\animation1 = 57
mobbullet(a)\animation2 = 58
mobbullet(a)\animation3 = 59
EndSelect
EndIf
If MobIsFiring(a) = #True And MobBulletInRoute(a) = #False
MobIsFiring(a) = #False
MobFire(a) = #False
MobShootEvent = #False
EndIf
If MobFire(a) = #True And MobIsFiring(a) = #False And MobBulletInRoute(a) = #False
;-FmodPlaySound(8)
MobIsFiring(a) = #True
;=========================================================================
;-check for closest mob to fire on ship
;=========================================================================
Structure Closest
mob.l
x.l
EndStructure
AimForPlayerCounter + 1
If AimForPlayerCounter = 3
AimForPlayerCounter = 0
ClosestShooter.Closest
ClosestShooter\Mob = 1
ClosestShooter\x = MobShooters(1)\x+12-player\x+13;centers of ship
For z = 1 To MobShooterCounter
;Debug ClosestShooter\x
Test1.l = ClosestShooter\x+12-player\x+13
Test2.l = MobShooters(z)\x+12-player\x+13
If Test1<0
test1 = Abs(Test1)
EndIf
If Test2<0
test2 = Abs(Test2)
EndIf
;Debug test1
;Debug test2
If Test1>Test2
ClosestShooter\x = MobShooters(z)\x
ClosestShooter\Mob = z
EndIf
Next z
MobShooter = ClosestShooter\Mob
Else
MobShooter = Random(MobShooterCounter)
If MobShooter = 0
MobShooter + 1
EndIf
EndIf
;;-debug "mobshooter " + Str(mobshooter) + " MobCounter " + Str(MobShooterCounter)
Mobbullet(a)\x = MobShooters(MobShooter)\x + 10
Mobbullet(a)\y = MobShooters(MobShooter)\y + 16
EndIf
If MobIsFiring(a) And MobBullet(a)\y<600
MobBulletInRoute(a) = #True
For d = 1 To 4
;===========================================================================
;-Check Barricades With bullet
spriteCnt = 0 ;reset our spriteCnt var to start at first one
For x = 1 To 4 ;Display barricades (4 of them)
For c = 0 To 7 ;Columns
For r = 0 To 3 ;Rows
With barricade(spriteCnt)
If Not \dead
Collide = MobCheckCollisionBullet(\x, \y, \sizex, \sizey, a)
If Collide
\dead = #True
MobBulletInRoute(a) = #False
Mobbullet(a)\y = -10;Hide Our DeadBullets, to simplify logic dead bullets still paste
Mobbullet(a)\x = -10;hide our DeadBullets
gldeletesprite(#BarricadeSpriteStart + spriteCnt)
gldeletesprite(600 + a)
EndIf
EndIf
EndWith
spriteCnt + 1 ;add to sprite counter
imgStart + 1 ;add to image counter
Next r
xPos + 6 ;Increase xpos by 6 because we are going over to next column (6px wide)
Next c
xPos + 100 ;add 100 to our xpos - this is our space between barricades.
imgStart = 2 ;reset our image counter
Next x ;yay for loops
;================================================================================================
;-Player Death
Collide = MobCheckCollisionBullet(player\x, player\y, player\sizex, player\sizey, a)
If collide And PlayerDeath = #False ;this stop bullets from double killig you, cheap invaders!
Ships-1
gldeleteSprite(399+ships) ;remove a ship in the hud
PlayerDeath=#True
PlayerDeathTimer.f=GetTimer()
FmodPlaySound(13)
MobBulletInRoute(a) = #False
Mobbullet(a)\y = 0
Mobbullet(a)\x = 0
If ships<1
gameover = #True
EndIf
EndIf
Mobbullet(a)\y + 1.0*MainLoopTimer
Next d
;SetSpriteColorBlend(600+a, GetColorSegment(Mobbullet(a)\y))
;**************************************************************************************************
;-Mob Bullet Animation timer
If GetTimer()-mobbullet(a)\BulletTimer>=BulletAnimationTime
mobbullet(a)\bullettimer = GetTimer()
mobbullet(a)\BulletEvent = #True
EndIf
If mobbullet(a)\BulletEvent
mobbullet(a)\BulletEvent = #False
Select mobbullet(a)\currentAnimation
Case mobbullet(a)\animation3
mobbullet(a)\currentAnimation = mobbullet(a)\animation1
Default
mobbullet(a)\currentAnimation + 1
EndSelect
EndIf
;**************************************************************************************************
glsprite(600 + a, Mobbullet(a)\x, Mobbullet(a)\y, mobbullet(a)\currentAnimation);place bullet
;GetColorSegment(bullet\y)
Else
MobBulletInRoute(a) = #False
Mobbullet(a)\y = 0;reset so collision dont hit
Mobbullet(a)\x = 0;reset so collision dont hit
gldeletesprite(600 + a);bullet is done. Delete it
EndIf
Next a
;EndIf
;**************************************************************************************************
;-Begin Display Barricade(s)
spriteCnt = 0 ;counter for sprite number
imgStart = 2 ;Image number from unpacker file of c1 r1 barricade
xPos = #BaricadeXPos ;starting x loc of barricade
yPos = #BaricadeYPos ;starting y loc of barricade
For x = 1 To 4 ;Display barricades (4 of them)
For c = 0 To 7 ;Columns
For r = 0 To 3 ;Rows
With barricade(spriteCnt)
If Not \dead ;only draw live sprites
;draw the sprite
glSprite(#BarricadeSpriteStart + spriteCnt, xPos, yPos + (8*r), imgStart)
EndIf
EndWith
spriteCnt + 1 ;add to sprite counter
imgStart + 1 ;add to image counter
Next r
xPos + 6 ;Increase xpos by 6 because we are going over to next column (6px wide)
Next c
xPos + #BaricadeSpacing ;add 100 to our xpos - this is our space between barricades. ;add 100 to our xpos - this is our space between barricades.
imgStart = 2 ;reset our image counter
Next x ;yay for loops
;**********************************************
;==================================================================================================
;Sprite = 0;reset our mob sprite Incrementor
;====================================================================================================
;MainLoopTimer-Int(MainLoopTimer); our 1 DeltaTime LoopTime thingy
;text(580, 560, "MainLoopTimer=" + StrF(MainLoopTimer))
For a = 0 To 133
glsprite(#BottomLineSpriteStart + a, a*6, 560, 7);draw bottom line :Player and its bullet, + mobs and barricades and this line=Sprite Position 322, next avail is 323
Next a
Else
text(340, 580, "G A M E O V E R")
EndIf
text(580, 580, "BulletLife=" + StrF(BulletLife))
;-Sync
glSync()
;Sleep_(35)
; For a = 1 To 1000
; gldeletesprite(a)
; Next
;-Timer Resets These can be reconciled into a single Timer Call eventually
;**************************************************************************************************
;Our DeltaTime
Deltatime.d=Abs(gettimer()-time)/0.01666666666;Entire game based on 60hz timer
alltime=(gettimer()-time3)
ScreenFPSCounter+1
;**************************************************************************************************
;Fps Event
If gettimer()-StartFPSCounter>=1
StartFPSCounter=gettimer()
fps=screenfpscounter
ScreenFPSCounter=0
EndIf
;**************************************************************************************************
;MotherShipEvent
If GetTimer()-GameEventTimer>=MotherShipEventTime
MotherShipEvent=#True
GameEventTimer=GetTimer()
EndIf
;**************************************************************************************************
;Beep & animation timer
If GetTimer()-BeepTimer>=MobBeepEventTime
BeepTimer=GetTimer()
BeepEvent=#True
EndIf
;**************************************************************************************************
;Mob Shoot timer
If GetTimer()-MobShootTimer>=MobShooteventTime
MobShootTimer=GetTimer()
MobShootEvent=#True
EndIf
;**************************************************************************************************
If GetTimer()-PlayerDeathTimer.f>=0.30
DeathAnimEvent= #True
PlayerDeathTimer = GetTimer()
EndIf
Until done=#True
;******************************
;-Game Closing
killglwindow()
SoundSystemErrorResult=FMOD_System_Release(SoundSystemObject)
;-debug "FMOD_System_Release"
errcheck(SoundSystemErrorResult)
CloseLibrary(fmodlib)
End


