require( "timed_events" )

local game = NewGame()

PlayBackMusic("music/elements.mp3")

AddTimedEvent( 3000, function() CreateOrangeBoomy( -300, -400,  {0, 0} ) end )
AddTimedEvent( 1000, function() CreateOrangeBoomy(  300, -400,  {0, 0} ) end )
AddTimedEvent( 1000, function() CreateOrangeBoomy( -300, -400,  {0, 0} ) end )
AddTimedEvent( 1000, function() CreateOrangeBoomy(  300, -400,  {0, 0} ) end )

AddTimedEvent( 4000, function() CreateOrangeStuff( 0, -400, { {300, 0}, { 0, 500} }, 5 ) end )
AddTimedEvent( 4000, function() CreateOrangeStuff( 0, -400, { {-300, 0}, { 0, 500} }, 5 ) end )
AddTimedEvent( 4000, function() CreateRedStarThingy(  0, -400, {0, 0} ) end )

AddTimedEvent( 8000, function() CreateBonusStuff( -150, RGB(118, 14, 14), bonus_RedWeaponThingy ) end )
AddTimedEvent( 0,    function() CreateBonusStuff(  150, RGB(255, 255, 200), bonus_ShieldThingy ) end )

AddTimedEvent( 2000, function() CreateOrangeBoomy( -300, -400,  {0, 0} ) end )
AddTimedEvent( 2000, function() CreateOrangeBoomy(  300, -400,  {0, 0} ) end )
AddTimedEvent( 2000, function() CreateOrangeRayShooter( -150, -400, {{ 150, 0}, {-300, -200}} ) end )
AddTimedEvent( 0   , function() CreateOrangeRayShooter(  150, -400, {{-150, 0}, { 300, -200}} ) end )
AddTimedEvent( 4000, function() CreatePurpleStuff( -350, -400, { { 200, 0}, { -350, 200} }, 10 ) end )
AddTimedEvent( 0,    function() CreatePurpleStuff(  350, -400, { {-200, 0}, {  350, 200} }, 10 ) end )

AddTimedEvent( 8000, function() CreateBonusStuff( -150, RGB(118, 14, 14), bonus_RedWeaponThingy ) end )
AddTimedEvent( 0,    function() CreateBonusStuff(  150, RGB(118, 14, 14), bonus_RedWeaponThingy ) end )

AddTimedEvent( 4000, function() CreateOrangeStuff( -350, -400, { { 200, 0}, { -350, 200} }, 10 ) end )
AddTimedEvent( 0,    function() CreateOrangeStuff(  350, -400, { {-200, 0}, {  350, 200} }, 10 ) end )
AddTimedEvent( 4000, function() CreateRedStarThingy(  0, -400, {0, 0} ) end )
AddTimedEvent( 3000, function() CreateOrangeStuff( -350, 0, { { 350, -100} }, 5 ) end )
AddTimedEvent( 0,    function() CreateOrangeStuff(  350, 0, { {-350, -100} }, 5 ) end )
AddTimedEvent( 8000, function() CreateOrangeRayShooter( 0, -400, {{ 0, -150}, {-300, -200}} ) end )
AddTimedEvent( 3000, function() CreateOrangeBoomy( -300, -400,  {0, 0} ) end )
AddTimedEvent( 1000, function() CreateOrangeBoomy(  300, -400,  {0, 0} ) end )
AddTimedEvent( 1000, function() CreateOrangeBoomy( -300, -400,  {0, 0} ) end )
AddTimedEvent( 1000, function() CreateOrangeBoomy(  300, -400,  {0, 0} ) end )
AddTimedEvent( 2000, function() CreateOrangeBoomy( -300, -400,  {0, 0} ) end )
AddTimedEvent( 2000, function() CreateOrangeBoomy(  300, -400,  {0, 0} ) end )

AddTimedEvent( 8000, function() CreateBonusStuff( -150, RGB(118, 14, 14), bonus_RedWeaponThingy ) end )
AddTimedEvent( 0,    function() CreateBonusStuff(  150, RGB(118, 14, 14), bonus_RedWeaponThingy ) end )
AddTimedEvent( 0,    function() CreateBonusStuff(    0, RGB(155, 50, 100), bonus_OptionThingy ) end )

AddTimedEvent( 4000, function() CreatePurpleStuff( 0, -400, { {300, 0}, { 0, 500} }, 5 ) end )
AddTimedEvent( 4000, function() CreatePurpleStuff( 0, -400, { {-300, 0}, { 0, 500} }, 5 ) end )
AddTimedEvent( 3000, function() CreateOrangeBoomy( -300, -400,  {0, 0} ) end )
AddTimedEvent( 1000, function() CreateOrangeBoomy(  300, -400,  {0, 0} ) end )
AddTimedEvent( 4000, function() CreateOrangeStuff(  150, -400, { {300, 0}, { 0, 500} }, 5 ) end )
AddTimedEvent(    0, function() CreatePurpleStuff( -150, -400, { {-300, 0}, { 0, 500} }, 5 ) end )

AddTimedEvent( 8000, function() CreateBonusStuff( -150, RGB(14, 118, 60), bonus_GreenWeaponThingy ) end )
AddTimedEvent( 0,    function() CreateBonusStuff(  150, RGB(118, 14, 14), bonus_RedWeaponThingy ) end )
AddTimedEvent( 0,    function() CreateBonusStuff(    0, RGB(155, 50, 100), bonus_OptionThingy ) end )

AddTimedEvent( 4000, function() CreateOrangeStuff( 0, -400, { {300, 0}, { 0, 500} }, 15 ) end )
AddTimedEvent( 4000, function() CreateOrangeStuff( 0, -400, { {-300, 0}, { 0, 500} }, 15 ) end )
AddTimedEvent( 4000, function() CreateRedStarThingy(  -300, -400, {-50, -50} ) end )
AddTimedEvent( 4000, function() CreateRedStarThingy(   300, -400, { 50, -50} ) end )
AddTimedEvent( 4000, function() CreateRedStarThingy(  -300,  400, {-50,  50} ) end )
AddTimedEvent( 4000, function() CreateRedStarThingy(   300,  400, { 50,  50} ) end )

AddTimedEvent( 8000, function() CreateBonusStuff( -150, RGB(14, 118, 60), bonus_GreenWeaponThingy ) end )
AddTimedEvent( 0,    function() CreateBonusStuff(  150, RGB(118, 14, 14), bonus_ShieldThingy ) end )

AddTimedEvent( 4000, function() CreatePurpleStuff(  300, -400, { {-300, -100 }, {300, 100} }, 10 ) end )
AddTimedEvent( 0   , function() CreatePurpleStuff( -300, -400, { {300, -100 }, {-300, 100} }, 10 ) end )
AddTimedEvent( 8000, function() CreateRedStarThingy( -400, 100, { 150, 0} ) end )
AddTimedEvent( 4000, function() CreateRedStarThingy(  400, 100, {-150, 0} ) end )
AddTimedEvent( 4000, function() CreateRedStarThingy(  0,  -400, {0, -150} ) end )
AddTimedEvent( 8000, function() CreateOrangeStuff( 0, -400, { {300, 0}, { 0, 500} }, 15 ) end )
AddTimedEvent( 4000, function() CreateOrangeStuff( 0, -400, { {-300, 0}, { 0, 500} }, 15 ) end )
AddTimedEvent( 8000, function() CreatePurpleStuff(  300, -400, { {-300, -100 }, {300, 100} }, 10 ) end )
AddTimedEvent( 0   , function() CreatePurpleStuff( -300, -400, { {300, -100 }, {-300, 100} }, 10 ) end )
AddTimedEvent( 8000, function() CreateRedStarThingy( -400, 100, { 150, 0} ) end )
AddTimedEvent( 4000, function() CreateOrangeBoomy( -300, -400,  {-150, -150} ) end )
AddTimedEvent( 1000, function() CreateOrangeBoomy(  300, -400,  { 150, -150} ) end )
AddTimedEvent( 1000, function() CreateOrangeBoomy( -300,  400,  {-150,  150} ) end )
AddTimedEvent( 1000, function() CreateOrangeBoomy(  300,  400,  { 150,  150} ) end )
AddTimedEvent( 4000, function() CreateOrangeStuff( -300, -150, { { 200, -300 }, { -300, -300} }, 10 ) end )
AddTimedEvent( 0   , function() CreateOrangeStuff(  300, -150, { {-200, -300 }, {  300, -300} }, 10 ) end )

AddTimedEvent( 16000, function() CreateBonusStuff( -150, RGB(155, 50, 100), bonus_OptionThingy ) end )
AddTimedEvent( 0    , function() CreateBonusStuff(  150, RGB(118, 14, 14),  bonus_RedWeaponThingy ) end )
AddTimedEvent( 0    , function() CreateBonusStuff(    0, RGB(40, 62, 158),  bonus_BombThingy ) end )

AddTimedEvent( 8000, function() CreateBossPear() end )

BossDefeated = function()
	Loader.completeLevel( "level3", "REDCROSS" )
end

local spr1 = CreateSprite("fog", 0, 0)
GroupObjects( spr1, CreateSprite("fog", 600, 512) )
local spr2 = CreateSprite("fog", 0, 0)
GroupObjects( spr2, CreateSprite("fog", 600, 512) )
SetObjSpriteColor( spr1, {73/255, 120/255, 174/255, -0.4} )
SetObjSpriteColor( spr2, {73/255, 120/255, 174/255, -0.4} )
SetObjPos( spr1, 0, 0, -0.9 )
SetObjPos( spr2, 0, 0, -0.9 )


background =
{
	{ CreateSprite( "back_desu", 0, 0 ), 0, 0, 2, 887 },
	{ CreateSprite( "back_desu" ,0, 0), 0, -887, 2, 887 },
	{ CreateSprite( "back_desu2", 0, 0 ), 0, 0, 1.5 , 887},
	{ CreateSprite( "back_desu2", 0, 0 ), 0, -887, 1.5 , 887},
	{ spr1, 0, 0, 1, 1024 },
	{ spr2, 0, -1024, 1, 1024 },
}

function ProcessBackground()
	for k, v in pairs(background) do
			v[3] = v[3] + v[4]
			SetObjPos(v[1], v[2], v[3] )
			if v[3] >= v[5] then
				v[3] = v[3] - 2*v[5]
			end
	end
end

return game
