#include "menu.au3"
#include "keyinput.au3"
#include "voiceover.au3"
#include "audio.au3"
#include "GUIConstants.au3"
$game=0
$SCORE = 0
$LEVEL=1
$firsttime=1
$interval = 800
$shot = 0
$toshoot=5
$type=0
sOUNDpLAY("INTRO.WAV", 1)
VO("WELCOME")
$music=$device.OpenSound("menu.wav", 1)
$music.repeating=1
$music.play

GUICreate("Juego de reflejos - por el grupo juegos pkb")
GUISetState(@SW_Show)

domenu()
func domenu()
$menu=Create_audio_menu("speech\menu.wav", "speech\item1.wav,speech\item2.wav,speech\item3.wav,speech\item4.wav")
$music.repeating=1
$music.play
select
case $menu = 1
$music.stop

go()
case $menu=2
$music.volume=0.5

score()
$music.volume=1
domenu()
case $menu=3
$music.stop
SoundPlay("speech\help.wav", 1)
SoundPlay("speech\help2.wav", 1)
SoundPlay("enemy.wav", 1)
SoundPlay("speech\help3.wav", 1)
SoundPlay("friend.wav", 1)
SoundPlay("speech\help4.wav", 1)
$music.play
domenu()
case $menu=4
$music.stop
SoundPlay("speech\close.wav", 1)
exit
EndSelect
EndFunc
func score()
$ar=IniReadSection("scores.ini", "scores")
If @error Then
vo("crash")

exit
else
for $i = 1 to $ar[0][0]
vo($ar[$i][0])
vo($ar[$i][1])
next
EndIf
EndFunc
FUNC GO()
SoundPlay("beep.wav", 1)
if $firsttime=1 then
vo("todestroy")
sleep(150)
vo($toshoot)
sleep(150)
vo("rocks")
sleep(1000)
$firsttime=0
EndIf
VO("LEVEL")
vo($level)
vo("score")
sleep(150)
vo($score)
SoundPlay("cb.wav")
      sleep(500)
SoundPlay("cb.wav")
      sleep(500)
SoundPlay("cb.wav")
      sleep(500)
SoundPlay("ce.wav", 1)
$game=1
hotkeyset("{space}", "shoot")
hotkeyset("g", "gtn")
while $game = 1
$type=random(1, 2, 1)
If $type=1 Then
SoundPlay("enemy.wav")
sleep($interval)

else
SoundPlay("friend.wav")
sleep($interval)
EndIf

If $shot=$toshoot Then

hotkeyset("{space}")
levelup()
$game=0
ExitLoop
EndIf


Wend
EndFunc



func shoot()
soundplay("laser.wav", 1)
If $type=1 Then
$score=$score+2
$shot=$shot+1
SoundPlay("hit.wav", 1)
else
gameover()
EndIf
EndFunc
func gameover()
hotkeyset("{space}")
$game=0
SoundPlay("explode.wav", 1)

vo("gameover")
sleep(1500)
vo("score")
vo($score)
SoundPlay("speech\savescore.wav")
$scorep=msgbox(4, "score", "save your score in the score chart?")
If $scorep = 6 Then
SoundPlay("speech\entername.wav")
$name=InputBox("score save: " & $score& "points.", "enter the name you want to appear as on the list.")
iniwrite("scores.ini", "scores", $name, $score)

SoundPlay("speech\playagain.wav")
EndIf
SoundPlay("speech\playagain.wav")
$playagain=msgbox(4, "play again?", "would you like to play again?")

If $playagain = 6 Then
$score=0
$level=1
$interval=800
$toshoot=5
$shot=0
go()
else

domenu()

EndIf
EndFunc
func levelup()
HOTKEYSET("{SPACE}")
$game=0
SoundPlay("levelup.wav", 1)
$score=$score+1000
$level=$level+1
$interval=$interval-100
$shot=0
SoundPlay("speech\levelup.wav",1)
msgbox(0, "Subimos de nivel!", "Dale al espacio cuando estés preparado!")
$toshoot=5
go()
EndFunc
