private static void CheckGameStats() { SpriteLabel labelToDraw = null; if (!playerShip.IsVisible) { canInput = false; labelToDraw = gameOverText; } else if (playerShip.IsGrounded && GroundManager.InWinnerPoint(playerShip.Position, playerShip.Ray)) { canInput = false; labelToDraw = winnerText; } if (labelToDraw != null) { if (timeToDrawLabel <= 0) { canInput = false; labelToDraw.Draw(); window.Blit(); isPlaying = false; System.Threading.Thread.Sleep(3500); } else { timeToDrawLabel -= GfxTools.Win.deltaTime; } } }
public static void Play() { isPlaying = true; winnerText = new SpriteLabel(window.width / 2, window.height / 2, WINNER_FILE); gameOverText = new SpriteLabel(window.width / 2, window.height / 2, GAME_OVER_FILE); GfxTools.Init(window); GroundManager.Init(); Background background = new Background(250, 5); playerShip = new Ship(50, window.height - GroundManager.GetGroundHeight() - 24, frictionX * 1.8f, gravity * 2f); AsteroidsManager.Init(12, 0, (int)(GroundManager.GetGroundPosition().Y - playerShip.Height * 2)); while (isPlaying) { if (Win.GetKey(KeyCode.Esc) || !Win.opened) { return; } GfxTools.CleanScreen(); if (canInput) { playerShip.Input(); } playerShip.Update(); background.Draw(); playerShip.Draw(); AsteroidsManager.Draw(); GroundManager.Draw(); window.Blit(); CheckGameStats(); } //mettere if player è morto break, e fuori da isplaying usare Wait o altro metodo per disegnare il risultato }
public void Update() { if (IsAlive) { if (!isGrounded) { velocity.Y += Game.Gravity; //velocity.Y += Game.Gravity * Game.DeltaTime; if (velocity.X > 0) { velocity.X -= Game.FrictionX; //velocity.X -= Game.FrictionX * Game.DeltaTime; if (velocity.X <= 0) { velocity.X = 0; } } else if (velocity.X < 0) { velocity.X += Game.FrictionX; //velocity.X += Game.FrictionX * Game.DeltaTime; if (velocity.X >= 0) { velocity.X = 0; } } } //prova senza delta time float deltaY = velocity.Y; //float deltaY = velocity.Y * Game.DeltaTime; //float deltaX = velocity.X * Game.DeltaTime; float deltaY = velocity.Y * Game.DeltaTime; float deltaX = velocity.X * Game.DeltaTime; position.Y += deltaY; position.X += deltaX; TranslateSprites(deltaX, deltaY); if (position.X - ray < 0 || position.X + ray > Game.Win.width || position.Y - height / 2 < 0) { Die(); return; } if (AsteroidsManager.Collides(position, ray)) { Die(); return; } if (GroundManager.Collides(position, height / 2, ref isGrounded)) { if (!IsGrounded) { Die(); return; } else if (isGrounded && velocity.Y != 0) { if (velocity.GetLength() >= resistance) { Die(); Console.WriteLine("si"); return; } else { velocity.Y = velocity.X = 0f; } } } } else if (isVisible) { if (!explosionDie.Update()) { isVisible = false; } } }