} //btnStart_Click /*funkcija koja vrti glavni dio programa*/ void gameLoop_Update(TimeSpan elapsed) { if (torpedoCooldown > 0) { torpedoCooldown--; } if (pauseCooldown > 0) { pauseCooldown--; } /*detekcija korisnikova unosa*/ if (status == GameState.pokrenuto) { PlayerShip.Velocity = new Vector(0, 0); if (keyHandler.IsKeyPressed(Key.Left) || keyHandler.IsKeyPressed(Key.A)) { if (PlayerShip.kut == 0) { PlayerShip.kut = 355; } else { PlayerShip.kut -= 5; } } if (keyHandler.IsKeyPressed(Key.Right) || keyHandler.IsKeyPressed(Key.D)) { if (PlayerShip.kut == 355) { PlayerShip.kut = 0; } else { PlayerShip.kut += 5; } } if ((keyHandler.IsKeyPressed(Key.Up) || keyHandler.IsKeyPressed(Key.W)) && PlayerShip.brzina < maxBrzina) { PlayerShip.brzina += 5; } if ((keyHandler.IsKeyPressed(Key.Down) || keyHandler.IsKeyPressed(Key.S)) && PlayerShip.brzina > minBrzina) { if (PlayerShip.brzina > minBrzina) { PlayerShip.brzina -= 5; } } if ((keyHandler.IsKeyPressed(Key.Space) || keyHandler.IsKeyPressed(Key.NumPad0)) && amunicija > 0 && torpedoCooldown == 0) { torpedoCooldown = 10; Torpedo pucanj = PlayerShip.Fire(); pucanj.MinX = pucanj.MinY = 0; pucanj.MaxX = gameRoot.Width; pucanj.MaxY = gameRoot.Height; Torpedi.Add(pucanj); gameRoot.Children.Add(pucanj.SpriteCanvas); Torpedo_Zvuk(0.5); RotateTransform rotate = new RotateTransform(); rotate.Angle = PlayerShip.kut; rotate.CenterX = pucanj.CentarX; rotate.CenterY = pucanj.CentarY; pucanj.SpriteCanvas.RenderTransform = rotate; amunicija--; } if ((keyHandler.IsKeyPressed(Key.Delete) || keyHandler.IsKeyPressed(Key.Y)) && pauseCooldown == 0) { status = GameState.pauza; gameRoot.Visibility = Visibility.Collapsed; cnvInfo.Visibility = Visibility.Visible; pauseCooldown = 10; Style stil = gameRoot.Resources["btnStyle3"] as Style; btnStart.Style = stil; //Canvas.Left="269" Canvas.Top="446" LayoutRoot.Children.Add(btnStart); } if ((keyHandler.IsKeyPressed(Key.NumPad2) || keyHandler.IsKeyPressed(Key.Ctrl)) && brojStitova > 0 && stanjeStita == 0) { brojStitova--; stanjeStita = 100; Point pozicija = new Point(); pozicija = PlayerShip.Position; int brzina = PlayerShip.brzina; int kut = PlayerShip.kut; gameRoot.Children.Remove(PlayerShip.SpriteCanvas); PlayerShip = new Ship(30, 20, pozicija, brzina, kut, 1); PlayerShip.MaxX = gameRoot.Width - 30; PlayerShip.MaxY = gameRoot.Height - 30; PlayerShip.MinX = 10; PlayerShip.MinY = 10; gameRoot.Children.Add(PlayerShip.SpriteCanvas); } if ((keyHandler.IsKeyPressed(Key.X) || keyHandler.IsKeyPressed(Key.Enter)) && amunicija >= 10 && torpedoCooldown == 0 && killZonePresent == 0) { torpedoCooldown = 10; amunicija -= 10; killzone = new KillZone(300, 300, PlayerShip.Position, 0, 0); killZonePresent = 200; gameRoot.Children.Add(killzone.SpriteCanvas); Torpedo_Zvuk(1); foreach (Meteorite meteor in Meteoriti) { if (Sprite.Collides(killzone, meteor)) { eksplozija explosion = meteor.unisten(); Eksplozije.Add(explosion); gameRoot.Children.Add(explosion.SpriteCanvas); MeteoritiRemove.Add(meteor); unisteniMeteoriti++; Eksplozija_Zvuk(0.3); } } foreach (Sonda sonda in Sonde) { if (Sprite.Collides(killzone, sonda)) { eksplozija explosion = sonda.unistena(); Eksplozije.Add(explosion); gameRoot.Children.Add(explosion.SpriteCanvas); SondeRemove.Add(sonda); Eksplozija_Zvuk(0.3); } } foreach (Grumen grumen in Grumenje) { if (Sprite.Collides(killzone, grumen)) { eksplozija explosion = grumen.unisten(); Eksplozije.Add(explosion); gameRoot.Children.Add(explosion.SpriteCanvas); GrumenjeRemove.Add(grumen); Eksplozija_Zvuk(0.3); } } } if (zdravlje < 100) { zdravlje += 0.0001 * PlayerShip.brzina; } else { zdravlje = 100; } if (stanjeStita > 0) { stanjeStita -= 0.1; } else { stanjeStita = 0; } if (stanjeStita == 0) { Point pozicija = new Point(); pozicija = PlayerShip.Position; gameRoot.Children.Remove(PlayerShip.SpriteCanvas); int brzina = PlayerShip.brzina; int kut = PlayerShip.kut; PlayerShip = new Ship(30, 20, pozicija, brzina, kut, 0); PlayerShip.MaxX = gameRoot.Width - 30; PlayerShip.MaxY = gameRoot.Height - 30; PlayerShip.MinX = 10; PlayerShip.MinY = 10; gameRoot.Children.Add(PlayerShip.SpriteCanvas); } RotateTransform rotacija = new RotateTransform(); rotacija.Angle = PlayerShip.kut; rotacija.CenterX = 16.5; rotacija.CenterY = 25; PlayerShip.SpriteCanvas.RenderTransform = rotacija; PlayerShip.Velocity = Vector.CreateVectorFromAngle(PlayerShip.kut, PlayerShip.brzina); PlayerShip.Update(elapsed); Meteorite_Loop(elapsed); Torpedo_Loop(elapsed); ExplosionLoop(elapsed); InformacijeLoop(elapsed); GrumenjeLoop(elapsed); Sonde_Loop(elapsed); if (killZonePresent > 0) { KillZoneLoop(elapsed); } /*ažuriranje podataka na korisničkom sučelju*/ MP.MeteoriScore = brojMeteora; TA.TorpediAmunicija = amunicija; UM.MeteoriUnisteni = unisteniMeteoriti; zdravljeBroda.Health = zdravlje; KZ.Update(killZonePresent, amunicija); GS.Bodovi = pokupljeniGrumeni; SS.BrojStitova = brojStitova; SS.StanjeStita = stanjeStita; } else { if ((keyHandler.IsKeyPressed(Key.Delete) || keyHandler.IsKeyPressed(Key.Y)) && pauseCooldown == 0) { odpauziraj(); } } } //gameLoop_Update