Graphics 640, 480, 1, 2
SeedRnd MilliSecs()
SetBuffer BackBuffer()
splashscreen = LoadImage("gfx\title.bmp")
DrawImage(splashscreen, 0, 0)
Flip
Delay 5000
AppTitle "Disco MANIA!"
Const DANCE = 0, POINT = 2, FLEE = 3
Type human
Field image
Field frame
Field x, y
Field health
Field antime
Field fattime#
End Type
Type AI
Field image
Field frame
Field mationtime
Field anim
Field x#, y#
Field state
Field strength#
Field health %
Field steps %
Field speed#
Field newangle
Field fattime#
Field vecX#, vecY#
Field human.human
End Type
Type discoball
Field image
Field frame
Field time#
Field x, y
Field lowblue
Field lowred
Field lowgreen
Field highblue
Field highred
Field highgreen
End Type
Type pow
Field image
Field frame
Field x, y
Field time
End Type
Type guywhoisout
Field image
Field x, y
End Type
Include "scancodes.bb"
Global wave = 1
Global start = True
Global dancefloor = LoadImage("gfx/dancefloor.bmp")
Global enemies = 0
Global decider = LoadAnimImage("gfx/beginningselection.bmp", 640, 480, 0, 4)
Global framenumb = 0
Global gameover = LoadImage("gfx/GameOver.bmp")
Global diff = 1
Global AIspeed = 1
Global AIhealth = 50
While Not KeyDown(1)
Cls
DrawImage decider, 0, 0, framenumb
If KeyHit(UP)
framenumb = framenumb - 1
EndIf
If KeyHit(DOWN)
framenumb = framenumb + 1
EndIf
GetScreenie()
If framenumb >= 2
framenumb = 2
EndIf
If framenumb <= 0
framenumb = 0
EndIf
If framenumb = 0
If KeyHit(28)
Game()
EndIf
EndIf
If framenumb = 1
If KeyHit(28)
AIstats()
EndIf
EndIf
If framenumb = 2
If KeyHit(28)
ChangeWave()
EndIf
EndIf
Flip
Wend
End
Function GetScreenie()
If KeyHit(2)
SaveBuffer(FrontBuffer(), "craps.bmp")
EndIf
End Function
Function AIstats()
While Not KeyHit(14)
Cls
Text 0, 0, "Press 'Backspace' to return to menu"
Text 20, 20, "Difficulty is currently set at: " + diff + ""
If KeyHit(UP)
If diff < 4
diff = diff + 1
ChangeAIstats(diff)
EndIf
EndIf
If KeyHit(DOWN)
diff = diff - 1
ChangeAIstats(diff)
EndIf
If diff = 1
Text 20, 35, "1. Easy (you wimp!)"
EndIf
If diff = 2
Text 20, 35, "2. Normal (nothin' to brag about)"
EndIf
If diff = 3
Text 20, 35, "3. Hard (those bosses are tough, ain't they?)"
EndIf
If diff = 4
Text 20, 35, "4. Suicidal (WHOA! life's not THAT bad, is it?!?!)"
EndIf
If diff <= 1
diff = 1
EndIf
Flip
Wend
End Function
Function ChangeWave()
While Not KeyHit(14)
Cls
Text 0, 0, "Press 'Backspace' to return to menu"
Text 20, 20, "Press the up or down keys to chage the current wave: " + wave + ""
If KeyHit(UP)
wave = wave + 1
If wave >= 50
wave = 50
EndIf
EndIf
If wave = 50
Text 20, 35, "Atch! sorry, that right there's the highest wave! "
Text 20, 50, "(unbeaten... report on www.codersworkshop.com if you've beaten the 50th wave!)"
EndIf
If wave = 1
Text 20, 35, "The first wave, eh rookie?"
EndIf
If KeyHit(DOWN)
wave = wave - 1
If wave <= 1
wave = 1
EndIf
EndIf
Flip
Wend
End Function
Function ChangeAIstats(adder)
AIspeed = AIspeed + adder
AIhealth = AIhealth + (adder * 2)
End Function
Function Game()
CreateDiscoBall()
CreateHuman()
While Not KeyDown(1)
PlayMusic("music\NightFever.mid")
.startagain
If start = True
For ouch.guywhoisout = Each guywhoisout
FreeImage ouch\image
Delete ouch
Next
If Not wave = 10 Or wave = 20 Or wave = 30 Or wave = 40 Or wave = 50
For ii = 1 To wave
CreateAI(AIspeed, AIhealth, False)
enemies = enemies + 1
Next
Else
For iii = 1 To wave / 10
CreateAI(AIspeed, AIhealth, True)
enemies = enemies + 1
Next
EndIf
start = False
EndIf
Cls
DrawImage dancefloor, 0, 0
UseHuman()
UseAI()
Collison()
DrawOuches()
DrawDancers()
DrawHumanStats()
DrawPow()
DrawDiscoLights()
DrawDiscoBall()
GetScreenie()
If enemies <= 0
WarnPlayerOfNextWave(wave, 600)
wave = wave + 1
start = True
Goto startagain
EndIf
Flip
Wend
End Function
Function DrawOuches()
For ouch.guywhoisout = Each guywhoisout
DrawImage ouch\image, ouch\x, ouch\y
Next
End Function
Function CreateHuman()
i.human = New human
Print "Createing Player..."
i\image = LoadAnimImage("gfx/mainman.bmp", 400, 400, 0, 4)
MidHandle i\image
MaskImage i\image, 255, 0, 255
ScaleImage i\image,.2,.2
i\frame = 0
i\x = 20
i\antime = 3
i\y = 20
i\health = 100
i\fattime = 600
End Function
Function UseAI()
For bot.AI = Each AI
If bot\x > 620
bot\x = 620
EndIf
If bot\y > 425
bot\y = 425
EndIf
If bot\y < 0
bot\y = 0
EndIf
If bot\x < 0
bot\x = 0
EndIf
bot\fattime = bot\fattime - 1
If bot\fattime <= 0
bot\health = bot\health - 1
bot\fattime = 600
EndIf
AILive()
If bot\health <= 0
CreateOut(bot\x, bot\y)
FreeImage bot\image
Delete bot
enemies = enemies - 1
EndIf
Next
End Function
Function AILive()
For bot.AI = Each AI
Select bot\state
Case DANCE
If bot\steps = 0
bot\newangle = Rand(0, 359)
bot\vecX# = Cos(bot\newangle) * bot\speed
bot\vecY# = Sin(bot\newangle) * bot\speed
bot\steps = Rand(30, 40)
EndIf
bot\steps = bot\steps - 1
bot\x = bot\x + bot\vecX
bot\y = bot\y + bot\vecY
bot\mationtime = bot\mationtime - 1
If bot\mationtime <= 0
bot\frame = bot\frame + 3
If bot\frame >= 4
bot\frame = 0
EndIf
If bot\frame < 0
bot\frame = 0
EndIf
bot\mationtime = 5
EndIf
If bot\human <> Null
If dist(bot, bot\human) < 120
cider = Rand(1, 2)
If cider = 1
bot\state = POINT
Else
EndIf
EndIf
EndIf
Case POINT
If bot\human <> Null
If Not bot\strength = 4
If dist(bot, bot\human) < 120
bot\state = DANCE
EndIf
EndIf
If dist(bot, bot\human) < 50
bot\mationtime = bot\mationtime - 1
If bot\mationtime <= 0
bot\frame = bot\frame + 1
If bot\frame >= 3
bot\frame = 0
EndIf
If bot\frame < 0
bot\frame = 0
EndIf
bot\mationtime = 7
EndIf
EndIf
If Not bot\strength = 4
If dist(bot, bot\human) < 120 And dist(bot, bot\human) > 50
If bot\human\x > bot\x
bot\x = bot\x + 1
EndIf
If bot\human\x < bot\x
bot\x = bot\x - 1
EndIf
If bot\human\y > bot\y
bot\y = bot\y + 1
EndIf
If bot\human\y < bot\y
bot\y = bot\y - 1
EndIf
bot\mationtime = bot\mationtime - 1
If bot\mationtime <= 0
bot\frame = bot\frame + 3
If bot\frame >= 4
bot\frame = 0
EndIf
If bot\frame < 0
bot\frame = 0
EndIf
bot\mationtime = 7
EndIf
EndIf
Else
If dist(bot, bot\human) > 50
If bot\human\x > bot\x
bot\x = bot\x + 1
EndIf
If bot\human\x < bot\x
bot\x = bot\x - 1
EndIf
If bot\human\y > bot\y
bot\y = bot\y + 1
EndIf
If bot\human\y < bot\y
bot\y = bot\y - 1
EndIf
bot\mationtime = bot\mationtime - 1
If bot\mationtime <= 0
bot\frame = bot\frame + 3
If bot\frame >= 4
bot\frame = 0
EndIf
If bot\frame < 0
bot\frame = 0
EndIf
bot\mationtime = 7
EndIf
EndIf
EndIf
EndIf
Case FLEE
If bot\human <> Null
If dist(bot, bot\human) > 120
bot\state = DANCE
EndIf
If dist(bot, bot\human) < 120
If bot\human\x > bot\x
bot\x = bot\x - 1
EndIf
If bot\human\x < bot\x
bot\x = bot\x + 1
EndIf
If bot\human\y > bot\y
bot\y = bot\y - 1
EndIf
If bot\human\y < bot\y
bot\y = bot\y + 1
EndIf
bot\mationtime = bot\mationtime - 1
If bot\mationtime <= 0
bot\frame = bot\frame + 3
If bot\frame >= 4
bot\frame = 0
EndIf
If bot\frame < 0
bot\frame = 0
EndIf
bot\mationtime = 7
EndIf
EndIf
EndIf
End Select
Next
End Function
Function CreateAI(speed, health, bosstrue)
Print "Creating Dance Bot..."
bot.AI = New AI
If bosstrue = False
numb = Rand(1, 3)
If numb = 1
bot\image = LoadAnimImage("gfx/discoman1.bmp", 400, 400, 0, 4)
EndIf
If numb = 2
bot\image = LoadAnimImage("gfx/discoman2.bmp", 400, 400, 0, 4)
EndIf
If numb = 3
bot\image = LoadAnimImage("gfx/discoman3.bmp", 400, 400, 0, 4)
EndIf
Else
bot\image = LoadAnimImage("gfx/bossdancer.bmp", 400, 400, 0, 4)
EndIf
MidHandle bot\image
MaskImage bot\image, 255, 0, 255
ScaleImage bot\image,.2,.2
bot\frame = 0
bot\anim = False
bot\x = Rand(21, 452)
bot\y = Rand(21, 620)
If bosstrue = False
bot\health = health
bot\speed = speed
If bot\speed > 4
bot\speed = 4
EndIf
bot\strength = Rand(1, 3)
Else
bot\health = health * 2
bot\speed = speed * 2
If bot\speed > 4
bot\speed = 4
EndIf
bot\strength = 4
EndIf
bot\newangle = 0
bot\fattime = 600
bot\state = DANCE
bot\mationtime = 7
bot\vecX# = 0
bot\vecY# = 0
bot\steps = Rand(20, 40)
bot\human = GetTheHuman()
End Function
Function GetTheHuman.human()
For i.human = Each human
Return i
Next
End Function
Function CreateDiscoBall()
Print "Creating Disco ball..."
ball.discoball = New discoball
ball\image = LoadAnimImage("gfx/discoball.bmp", 400, 400, 0, 3)
ScaleImage ball\image,.2,.2
ball\frame = 0
ball\x = 270
ball\y = 0
ball\lowblue = 140
ball\lowred = 140
ball\lowgreen = 140
ball\highblue = 250
ball\highred = 250
ball\highgreen = 250
ball\time = 3
End Function
Function DrawDiscoBall()
For ball.discoball = Each discoball
ball\time = ball\time - 1
If ball\time =< 0
ball\frame = ball\frame + 1
ball\time = 3
EndIf
If ball\frame >= 3
ball\frame = 0
EndIf
If ball\frame < 0
ball\frame = 0
EndIf
DrawImage ball\image, ball\x, ball\y, ball\frame
Next
End Function
Function DrawDiscoLights()
For ball.discoball = Each discoball
Color Rand(ball\lowred, ball\highred), Rand(ball\lowgreen, ball\highgreen), Rand(ball\lowblue, ball\highblue)
Rect Rand(0, 640), Rand(0, 480), 10, 10, 1
Rect Rand(0, 640), Rand(0, 480), 10, 10, 1
Rect Rand(0, 640), Rand(0, 480), 10, 10, 1
Next
End Function
Function UseHuman()
For i.human = Each human
If KeyDown(UP)
If i\y > 0
i\y = i\y - 1.5
EndIf
EndIf
If KeyDown(DOWN)
If i\y < 452
i\y = i\y + 1.5
EndIf
EndIf
If KeyDown(RIGHTKEY)
If i\x < 620
i\x = i\x + 1.5
EndIf
EndIf
If KeyDown(LEFTKEY)
If i\x > 0
i\x = i\x - 1.5
EndIf
EndIf
i\fattime = i\fattime - 1
If i\fattime <= 0
i\fattime = 600
i\health = i\health - 1
EndIf
If KeyDown(57)
i\frame = i\frame + 1
If i\frame >= 3
i\frame = 0
EndIf
If i\frame <= 0
i\frame = 0
EndIf
EndIf
If KeyDown(UP) Or KeyDown(DOWN) Or KeyDown(RIGHTKEY) Or KeyDown(LEFTKEY)
i\frame = i\frame + 3
If i\frame >= 4
i\frame = 0
EndIf
If i\frame <= 0
i\frame = 0
EndIf
EndIf
If Not KeyDown(UP) Or KeyDown(DOWN) Or KeyDown(RIGHTKEY) Or KeyDown(LEFTKEY) Or KeyDown(57)
i\frame = 0
EndIf
If i\health <= 0
FreeImage i\image
Delete i
GameOver(600)
EndIf
Next
End Function
Function DrawDancers()
For i.human = Each human
DrawImage i\image, i\x, i\y, i\frame
Next
For bot.AI = Each AI
DrawImage bot\image, bot\x, bot\y, bot\frame
Next
End Function
Function DrawHumanStats()
For i.human = Each human
Rect(i\x - ((i\health / 2) / 2)), i\y + 30, i\health / 2, 5, 1
Next
End Function
Function CreatePow(x, y)
p.pow = New pow
p\image = LoadAnimImage("gfx\pow.bmp", 400, 400, 0, 3)
MaskImage p\image, 255, 0, 255
MidHandle p\image
ScaleImage p\image,.2,.2
p\frame = 0
p\time = 2
p\x = x
p\y = y
End Function
Function DrawPow()
For p.pow = Each pow
p\time = p\time - 1
If p\time <= 0
p\frame = p\frame + 1
p\time = 2
EndIf
If p\frame >= 3
FreeImage p\image
Delete p
EndIf
If p <> Null
DrawImage p\image, p\x, p\y, p\frame
EndIf
Next
End Function
Function Collison()
For i.human = Each human
For bot.AI = Each AI
If i\frame = 2
If bot\frame = 0 Or bot\frame = 1 Or bot\frame = 2 Or bot\frame = 4
If ImagesCollide(i\image, i\x, i\y, 3, bot\image, bot\x, bot\y, 1)
bot\health = bot\health - 5
CreatePow(bot\x, bot\y)
If bot\health < 20
If bot\strength < 5
bot\state = FLEE
Else
EndIf
EndIf
EndIf
EndIf
EndIf
If bot\frame = 2
If i\frame = 0 Or i\frame = 1 Or i\frame = 2 Or i\frame = 4
If ImagesCollide(bot\image, bot\x, bot\y, 3, i\image, i\x, i\y, 1)
i\health = i\health - bot\strength
CreatePow(i\x, i\y)
EndIf
EndIf
EndIf
Next
Next
End Function
Function CreateOut(x#, y#)
ouch.guywhoisout = New guywhoisout
ouch\image = LoadImage("gfx\ouch.bmp")
MaskImage ouch\image, 255, 0, 255
ScaleImage ouch\image,.2,.2
MidHandle ouch\image
ouch\x = x
ouch\y = y
End Function
Function dist#(this.AI, that.human)
If this <> Null
If that <> Null
Return Sqr((that\x - this\x) ^ 2 + (that\y - this\y) ^ 2)
EndIf
EndIf
End Function
Function WarnPlayerOfNextWave(wavenum, time)
Cls
Text 0, 0, " Y O U H A V E L A S T E D T H R O U G H W A V E" + wavenum + ""
Text 220, 200, "READY??? HIT ANY KEY TO DANCE!"
.time
time = time - 1
If time <= 0
Goto theend
Else
Goto time
EndIf
.theend
End Function
Function GameOver(time)
Cls
DrawImage gameover, 0, 0
Flip
time = time - 1
If time <= 0
Goto crap
Else
EndIf
.crap
Delay 6000
End
End Function