-- Assault Mission --
-- By: DimensionT --

-- MENU --

Select = 1
maxSelect = 3
gamestate = "Menu"
IntroFrame = 1

-- ##### Loading Sprites ##### --

white = Color.new(255,255,255)
black = Color.new(0,0,0)
grau = Color.new(100,100,100)
blue = Color.new(72,61,139)
Auto = Image.load("Pictures/Sprites/Auto1.png")
wand = Image.load ("Pictures/Sprites/wand.jpg")
loch = Image.load ("Pictures/Sprites/loch.jpg")
Strasse = Image.load ("Pictures/Sprites/Strasse.jpg")


-- ##### Posistioning Sprites ##### --

speed = 1
kollision = 0
wand1x = 175
wand2x = 350
wand3x = 525
AutoX = 228
AutoY = 100
AutoHeight = 40
AutoWidth = 25
speed1 = 5
speed2 = 4
SpeedAuto = 2
SaveData = 0
strasse1X = 0
strasse2X = 160
strasse3X = 320
strasse4X = 480
dx = 0
dy = 0
Pause = 0
Select = 0
maxSelect = 3
time = 0
loch1y = math.random(0, 232) 
loch2y = math.random(0, 232) 
loch3y = math.random(0, 232) 



-- ##### Screen ##### --

function movewand()
     speed = speed + 0.001
     
     wand1x = wand1x - speed
     wand2x = wand2x - speed
     wand3x = wand3x - speed
     if kollision == 1 then AutoX = AutoX - speed end
     
     if wand1x < -45 then loch1y = nil wand1x = 480 loch1y = math.random(0, 232) end
     if wand2x < -45 then wand2x = 480 loch2y = math.random(0, 232) end
     if wand3x < -45 then wand3x = 480 loch3y = math.random(0, 232) end
end

function moveBack()
     if strasse1X <= -160 then
          strasse1X = 480
     end
     if strasse2X <= -160 then
          strasse2X = 480
     end
     if strasse3X <= -160 then
          strasse3X = 480
     end
     if strasse4X <= -160 then
          strasse4X = 480
     end

     strasse1X = strasse1X - speed
     strasse2X = strasse2X - speed
     strasse3X = strasse3X - speed
     strasse4X = strasse4X - speed
end


-- ##### Controls ##### --

function moveAuto()

if pad:square() and AutoX > 0 and kollision == 0 then
     AutoX = AutoX - 3
end
if pad:circle() and AutoX < 455 and kollision == 0 then
     AutoX = AutoX + 3
end
if pad:triangle() and AutoY > 0 then
     AutoY = AutoY - 3
end
if pad:cross() and AutoY < 247 then
     AutoY = AutoY + 3
end
if pad:select() then
     Image:save("ms0:/PSP/PHOTO/screen.png")
end
if pad:start() then
     gamestate = "Pause"
end
end     


-- ##### Load Background #####

BG = Image.load("Pictures/BG.png")
Start = Image.load("Pictures/StartGame.png")
Options = Image.load("Pictures/Options.png")
QuitGame = Image.load("Pictures/QuitGame.png")
MenuSelect = Image.load("Pictures/MenuSelection.png")
Paused = Image.load("Pictures/Pause.png")
Optionen = Image.load("Pictures/optionen.png")
Back = Image.load("Pictures/Back.png")
Resume = Image.load("Pictures/Resume.png")
Menu = Image.load("Pictures/Menu.png")
Quit = Image.load("Pictures/Quit.png")
usb = Image.load("Pictures/usb.png")
ton = Image.load("Pictures/ton.png")

-- ##### Load Sounds #####
Move = Sound.load("Sounds/Move.wav",false)
SelectSound = Sound.load("Sounds/Select.wav",false)
Music.playFile("Sounds/Title.xm", true)

-- ##### Main Loop #####
gamestate = "Menu"
oldpad = Controls.read()
while true do
pad = Controls.read()
screen:clear()

if gamestate == "Menu" then    
     screen:blit(0, 0, BG)

     if pad:circle() and oldpad:circle() ~= pad:circle() and Select <= 3 then
          Select = Select + 1
          Move:play()
     end
     if pad:square() and oldpad:square() ~= pad:square() and Select >= 1 then
          Select = Select - 1
          Move:play()
     end
	if Select > maxSelect then
		Select = 1
	elseif Select <= 0 then
		Select = maxSelect
	end

     if Select == 1 then
          screen:blit(276+65,115,MenuSelect)
          screen:blit(280+65,100,Start)
          screen:blit(310+65,100,Options)
          screen:blit(340+65,100,QuitGame)
     end
     if Select == 2 then
          screen:blit(306+65,115,MenuSelect)
          screen:blit(280+65,100,Start)
          screen:blit(310+65,100,Options)
          screen:blit(340+65,100,QuitGame)
     end
     if Select == 3 then
          screen:blit(336+65,115,MenuSelect)
          screen:blit(280+65,100,Start)
          screen:blit(310+65,100,Options)
          screen:blit(340+65,100,QuitGame)
     end
     if Select == 1 and pad:cross() and oldpad:cross() ~= pad:cross() then          
               SelectSound:play()
               Music.stop()


Credits = Image.load("Pictures/Sprites/Credits.png")
               Music.playFile("Sounds/LevelOne.xm", true)
               gamestate = "Game"
     end

     if Select == 2 and pad:cross() and oldpad:cross() ~= pad:cross() then
          gamestate = "options"
     end

     if Select == 3 and pad:cross() and oldpad:cross() ~= pad:cross() then
          System.Quit()
     end
end




   


if gamestate == "Game" then
screen:clear(blue)

moveAuto()

movewand()



screen:blit(wand1x, 0, wand)
screen:blit(wand2x,0, wand)
screen:blit(wand3x, 0, wand)
screen:blit(wand1x, loch1y, loch)
screen:blit(wand2x,loch2y, loch)
screen:blit(wand3x, loch3y, loch)
screen:blit(AutoX, AutoY, Auto)






if kollision == 1 then
if AutoX < -10 then
   speed = 1
   kollision = 0
   AutoX = 228
   AutoY = 100
   gamestate = "Menu"
   Music.stop()
   Music.playFile("Sounds/Title.xm", true)
end
end



if AutoX + 25 > wand1x and AutoX + 25 < wand1x + 10 then
   if AutoY > loch1y and AutoY < loch1y + 30 then kollision = 0
   else
   kollision = 1
   end
   
end


if AutoX + 25 > wand2x and AutoX + 25 < wand2x + 10 then
   if AutoY > loch2y and AutoY < loch2y + 30 then kollision = 0
   else
   kollision = 1
   end
   
end


if AutoX + 25 > wand3x and AutoX + 25 < wand3x + 10 then
   if AutoY > loch3y and AutoY < loch3y + 30 then kollision = 0
   else
   kollision = 1
   end
   
end



end


if gamestate == "options" then    
   screen:blit(0, 0, Optionen)


     if pad:circle() and oldpad:circle() ~= pad:circle() and Select <= 3 then
          Select = Select + 1
          Move:play()
     end
     if pad:square() and oldpad:square() ~= pad:square() and Select >= 1 then
          Select = Select - 1
          Move:play()
     end
	if Select > maxSelect then
		Select = 1
	elseif Select <= 0 then
		Select = maxSelect
	end

     if Select == 1 then
          screen:blit(276+65,115,MenuSelect)
          screen:blit(280+65,100,usb)
          screen:blit(310+65,100,ton)
          screen:blit(340+65,100,Back)
     end
     if Select == 2 then
          screen:blit(306+65,115,MenuSelect)
          screen:blit(280+65,100,usb)
          screen:blit(310+65,100,ton)
          screen:blit(340+65,100,Back)
     end
     if Select == 3 then
          screen:blit(336+65,115,MenuSelect)
          screen:blit(280+65,100,usb)
          screen:blit(310+65,100,ton)
          screen:blit(340+65,100,Back)
     end

     if Select == 1 and pad:cross() and oldpad:cross() ~= pad:cross() then
                System.usbDiskModeActivate()
     end

     if Select == 1 and pad:circle() and oldpad:circle() ~= pad:circle() then
                System.usbDiskModeDeactivate()
     end

     if Select == 2 and pad:cross() and oldpad:cross() ~= pad:cross() then
                Music.volume(128)
     end


     if Select == 2 and pad:circle() and oldpad:circle() ~= pad:circle() then
                Music.volume(0)
     end

     if Select == 3 and pad:cross() and oldpad:cross() ~= pad:cross() then
          gamestate = "Menu"
     end
end



if gamestate == "Pause" then
screen:clear()    
     screen:blit(0, 0, Paused, true)


     if pad:circle() and oldpad:circle() ~= pad:circle() and Select <= 3 then
          Select = Select + 1
          Move:play()
     end
     if pad:square() and oldpad:square() ~= pad:square() and Select >= 1 then
          Select = Select - 1
          Move:play()
     end
	if Select > maxSelect then
		Select = 1
	elseif Select <= 0 then
		Select = maxSelect
	end

     if Select == 1 then
          screen:blit(276+65,115,MenuSelect)
          screen:blit(280+65,100,Resume)
          screen:blit(310+65,100,Menu)
          screen:blit(340+65,100,Quit)
     end
     if Select == 2 then
          screen:blit(306+65,115,MenuSelect)
          screen:blit(280+65,100,Resume)
          screen:blit(310+65,100,Menu)
          screen:blit(340+65,100,Quit)
     end
     if Select == 3 then
          screen:blit(336+65,115,MenuSelect)
          screen:blit(280+65,100,Resume)
          screen:blit(310+65,100,Menu)
          screen:blit(340+65,100,Quit)
     end
     if Select == 1 and pad:cross() and oldpad:cross() ~= pad:cross() then
          SelectSound:play()
          gamestate = "Game"
     end
     if Select == 2 and pad:cross() and oldpad:cross() ~= pad:cross() then
          SelectSound:play()
          Music.playFile("Sounds/Title.xm", true)
          gamestate = "Menu"
     end
     if Select == 3 and pad:cross() and oldpad:cross() ~= pad:cross() then
          System.Quit()
     end



elseif gamestate == "Credits" then
     screen:blit(0, 0, Black)
     screen:blit(113, 10, DemoComplete)
     screen:blit(90, 72, Credits)
     screen:blit(129, 250, PressX)
          if pad:cross() and oldpad:cross() ~= pad:cross() then
          wolkencroll = 0
          Polizei1Y = -40
          Polizei2Y = -40
          Polizei3Y = -40
          Polizei4Y = -40
          AutoX = 150
          AutoY = 100
               SelectSound:play()
               Music.playFile("Sounds/Title.xm", true)
               gamestate = "Menu"
          end
end

screen.waitVblankStart()
screen.flip()
oldpad = pad
end