// All KPL programs start with the word "Program" followed by the // name of your program, and end with the words "End Program". Program NewProgram // This is the starting point of the program, and is 'called' // by KPL automatically when the program is run. // // To expand this method, double-click on the box below or click // the plus symbol to the left of the words "Method Main()" Structure BaddyStructure Name As String X As Int Y As Int Speed As Int End Structure Define XCoordinateofUFO As Int Define YCoordinateofUFO As Int Define Baddy As BaddyStructure [9] Define HasCrashed As Bool Method Main() LoadMainSprite() DrawBackground() LoadBaddies () XCoordinateofUFO = 20 YCoordinateofUFO = 200 While HasCrashed = False Delay (4) CheckForAnArrowKey() AnimateBaddies () DetectACrash () End While Explosion () Delay(1700) End Method Method LoadMainSprite() LoadSprite ("UFO", "UFO.gif") MoveSpriteToPoint ("UFO", 20,200) Define Timeline As Int[6] ShowSprite("UFO") Timeline[1] = 100 Timeline[2] = 100 Timeline[3] = 100 Timeline[4] = 100 Timeline[5] = 100 Timeline[6] = 100 SetSpriteAnimationTimeline("UFO", True, Timeline ) End Method Method DrawBackground () LoadSprite ("background", "space.png") SetSpriteCanCollide("background", False) StampSprite ("background") End Method Method CheckForAnArrowKey () If IsKeyDown ("Up") Then YCoordinateofUFO = YCoordinateofUFO - 3 End If If IsKeyDown ("Down") Then YCoordinateofUFO = YCoordinateofUFO + 3 End If If IsKeyDown ("Left") Then XCoordinateofUFO = XCoordinateofUFO - 3 End If If IsKeyDown ("Right") Then XCoordinateofUFO = XCoordinateofUFO + 3 End If MoveSpriteToPoint ("UFO", XCoordinateOfUFO,YCoordinateOfUFO ) End Method Method DetectACrash () DetectWallCrash () DetectBaddyCrash() //TODO:write baddy detect crash End Method Method DetectWallCrash () If (YCoordinateofUFO < 0) Or (XCoordinateofUFO < 0) Or (XCoordinateofUFO > 600) Or (YCoordinateofUFO > 440) Then HasCrashed = True End If End Method Method LoadBaddies () Define Count As Int For Count = 1 To 9 Baddy [Count].Name = "Baddy" + Count LoadSprite (Baddy[Count].Name, "lol.gif") ScaleSprite(Baddy[Count].name, 3) ShowSprite (Baddy[Count].Name) FlipSpriteHorizontally (Baddy[Count].Name) Baddy[count].speed = (Random(1,3)) Next End Method Method AnimateBaddies () Define Count As Int Var Timeline2 As Int[50] For Count = 1 To 9 Baddy[Count].x = (Baddy[count].x + Baddy[Count].speed) MoveSpriteTo(Baddy[Count].Name, 640 - (Baddy[Count].x), (Baddy[Count].y)) If Baddy[Count].x > 750 Then Baddy[count] .x = 0 - Random(0,200) Baddy[count].y = Random(0,480) MoveTo (0,480) //Print (CrashCount) End If Next Timeline2[1] = 1000 Timeline2[2] = 1000 Timeline2[3] = 1000 Timeline2[4] = 1000 Timeline2[5] = 1000 Timeline2[6] = 1000 Timeline2[7] = 1000 Timeline2[8] = 1000 Timeline2[9] = 1000 Timeline2[10] = 1000 Timeline2[11] = 1000 Timeline2[12] = 1000 Timeline2[13] = 1000 Timeline2[14] = 1000 Timeline2[15] = 1000 Timeline2[16] = 1000 Timeline2[17] = 1000 Timeline2[18] = 1000 Timeline2[19] = 1000 Timeline2[20] = 1000 Timeline2[21] = 1000 Timeline2[22] = 1000 Timeline2[23] = 1000 Timeline2[24] = 1000 Timeline2[25] = 1000 Timeline2[26] = 1000 Timeline2[27] = 1000 Timeline2[28] = 1000 Timeline2[29] = 1000 Timeline2[30] = 1000 Timeline2[31] = 1000 Timeline2[32] = 1000 Timeline2[33] = 1000 Timeline2[34] = 1000 Timeline2[35] = 1000 Timeline2[36] = 1000 Timeline2[37] = 1000 Timeline2[38] = 1000 Timeline2[39] = 1000 Timeline2[40] = 1000 Timeline2[41] = 1000 Timeline2[42] = 1000 Timeline2[43] = 1000 Timeline2[44] = 1000 Timeline2[45] = 1000 Timeline2[46] = 1000 Timeline2[47] = 1000 Timeline2[48] = 1000 Timeline2[49] = 1000 Timeline2[50] = 1000 For Count = 1 To 9 SetSpriteAnimationTimeline(Baddy[Count].Name, True, Timeline2 ) Next End Method Method DetectBaddyCrash () Define CrashedWith As String[] CrashedWith = GetSpritesThatIntersectWith("UFO") If ArrayLength(CrashedWith) > 0 Then HasCrashed = True End If End Method Method Explosion () Define Top As Int Define Left As Int Define ArrayExplode As Int[17] Define Count As Int For Count = 1 To 17 ArrayExplode[Count] = 100 Next Top = GetSpriteTop("UFO") Left = GetSpriteLeft("UFO") HideSprite("UFO") LoadSprite ("Explosion","Explosion.gif") MoveSpriteToPoint("Explosion" , Left, Top) SetSpriteAnimationTimeline ("Explosion", True, ArrayExplode) ShowSprite("Explosion") End Method End Program