Ok after the cannon rotates a few times it starts to become very laggy
Graphics 900,700,32,2 Include "Timers.bb" Global Castle = LoadImage("Castle.jpg") Global Cannon = LoadImage("Cannon.jpg") Global CannonBall = LoadImage("CannonBall.jpg") Global Arrow = LoadImage("Arrow.jpg") Global Knight = LoadImage("Knight.jpg") Global Rammer = LoadImage("Rammer.jpg") Global GameMenu = LoadImage("Menu1.jpg") Global NextLevelMenu = LoadImage("LevelMenu.jpg") Global ROT = True MaskImage Castle,255,0,0 MaskImage Cannon,255,0,0 MaskImage CannonBall,255,0,0 MaskImage Arrow,255,0,0 MaskImage Knight,255,0,0 MaskImage Rammer,255,0,0 Type Attacker Field vx#,img,hp,typeA,x,y End Type Type Projectile Field dmg,typeP,img,xv#,yv#,dist,x#,y# End Type Global CANNONS = 10 Global ARROWS = 25 Global Lives = 10 Global Angle = 0 Global Attackers = 0 Global Level = 1 Global MaxA = 0 Global KILLS = 0 Global GAME_MODE = 2 Global NotLoaded = False Global TIMER = MilliSecs() Global time = 500 While Not KeyHit(1) Cls If NotLoaded = False CANNONS = 10 ARROWS = 25 Lives = 10 Angle = 0 Attackers = 0 Level = 1 MaxA = 0 KILLS = 0 GAME_MODE = 2 NotLoaded = True EndIf Select GAME_MODE Case 1 DrawScenery() AimControl() FireControl() UpdateAttackers() UpdateLevel() UpdateProjectiles() Case 2 UpdateMenu() ; Case 3 ; UpdateShopMenu() End Select FlushKeys Flip Wend Function StartNewGame() GAME_MODE = 1 End Function Function DrawScenery() DrawImage Castle,0,500 DrawImage Cannon,400,500 For A.projectile = Each projectile DrawImage A\img,A\x,A\y Next For B.attacker = Each attacker DrawImage B\img,B\x,B\y Next End Function Function UpdateMenu() DrawImage GameMenu,0,0 If MouseHit(1) And (MouseX() > 0 And MouseX() < 900) If MouseY() > 0 And MouseY() < 700 Cls StartNewGame() EndIf EndIf End Function Function AimControl() If KeyDown(200) Angle = Angle + 5 ROT = True EndIf If KeyDown(208) And Angle > 4 Angle = Angle - 5 ROT = True EndIf If Angle > 360 Angle = Angle - 360 EndIf If Angle < 0 Angle = Angle + 360 EndIf If MilliSecs() > time + timer And Rot = True Then timer = MilliSecs() ; reset the timer to the current value of millisecs() RotateImage Cannon,Angle End If ROT = False End Function Function UpdateProjectiles() For PX.projectile = Each projectile PX\dist = PX\dist + 1 PX\y# = PX\y# + PX\yv# * 8 PX\x# = PX\x# + PX\xv# * 8 If PX\dist > 900 FreeImage PX\img Delete PX Goto SkipA EndIf For A.attacker = Each attacker If ProjectileCollide(PX,A) A\hp = A\hp - PX\dmg Delay(200) PX\dist = 901 EndIf Next .SkipA Next End Function Function UpdateAttackers() If Attackers < 3 A.attacker = New attacker A\typeA = Rand(0,1) Attackers = Attackers + 1 Select A\typeA Case 0 A\img = CopyImage(Knight) A\hp = 2 A\vx = -3 Case 1 A\img = CopyImage(Rammer) A\hp = 5 A\vx = -2 End Select A\x = 825 A\y = 625 EndIf For B.Attacker = Each Attacker B\x = B\x + B\vx If B\hp < 1 FreeImage B\img Delete B KILLS = KILLS + 1 Attackers = Attackers - 1 EndIf Next End Function Function UpdateLevel() MaxA = ((Level + 2)^2) If Lives < 0 GameOverScreen() GAME_MODE = 2 Cannons = 10 Arrows = 25 Lives = 10 Angle = 0 Attackers = 0 Level = 1 For P.projectile = Each Projectile FreeImage P\img Delete P Next For A.attacker = Each Attacker FreeImage A\img Delete A Next EndIf If Kills >= MaxA ShowLevelScreen(Level+1) Level = Level + 1 Kills = 0 Cannons = Cannons + Level Arrows = Arrows + (3/2) * Level Delay(3000) Game_Mode = 1 EndIf End Function Function GameOverScreen() Cls HSData = OpenFile("HighScores.dat") A$ = Input("Name: ") WriteInt(HSData,Kills) WriteString(HSData,A$) CloseFile HSData Kills = 0 End Function Function FireControl() If KeyHit(30) If Arrows < 1 Goto Ending EndIf Arrows = Arrows - 1 A.Projectile = New Projectile A\dmg = 1 A\img = CopyImage(Arrow) RotateImage A\img,Angle A\typeP = 1 A\xv# = GetXV#(Angle) A\yv# = GetYV#(Angle) A\x# = 200 A\y# = 400 .Ending EndIf If KeyHit(48) If Cannons < 1 Goto Ending2 EndIf A.Projectile = New Projectile A\dmg = 3 A\img = CopyImage(CannonBall) RotateImage A\img,Angle A\typeP = 2 A\xv# = GetXV#(Angle) A\yv# = GetYV#(Angle) A\x# = 200 A\y# = 400 Cannons = Cannons - 1 .Ending2 EndIf End Function Function ProjectileCollide(PR.Projectile,AT.attacker) If ImagesOverlap(PR\img,PR\X,PR\Y,AT\img,AT\X,AT\Y) Return True EndIf End Function Function ShowLevelScreen(levelX) DrawImage NextLevelMenu,0,0 Text "Level " + Level,450,350 End Function Function GetXV#(ang#) Return Cos#(ang#) End Function Function GETYV#(ang#) Return Sin#(ang#) End Function