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 override void Update(GameTime gameTime) { for (int i = 0; i < Global.HighScores.Length; i++) { SpriteLabel scoreLabel = SpriteCollection[String.Format("scoreLabel{0}", i)].Cast <SpriteLabel>(); scoreLabel.Text = String.Format("{0} :{1}", Global.HighScores[i].Minutes.ToString("D2"), Global.HighScores[i].Seconds.ToString("D2")); scoreLabel.Origin = new Vector2(scoreLabel.Width / 2, scoreLabel.Height / 2); scoreLabel.IsVisible = Global.HighScores[i] != TimeSpan.Zero; HighScoreControl scoreTypeLabel = SpriteCollection[String.Format("scoreTypeLabel{0}", i)].Cast <HighScoreControl>(); scoreTypeLabel.Control = Global.HighScoresType[i]; if (scoreTypeLabel.Control != ControlTypes.NoControl) { //origin needs to be calculated based on original size of the image so setting scale back to 1 just for origin recalculation scoreTypeLabel.Scale = Vector2.One; scoreTypeLabel.Origin = new Vector2(scoreTypeLabel.Width / 2, scoreTypeLabel.Height / 2); scoreTypeLabel.X = RenderTarget.Width / 2; scoreTypeLabel.Scale = new Vector2(.85f); } SpriteLabel scoreDateLabel = SpriteCollection[String.Format("scoreDateLabel{0}", i)].Cast <SpriteLabel>(); scoreDateLabel.Text = Global.HighScoreDates[i].ToShortDateString(); scoreDateLabel.Origin = new Vector2(scoreDateLabel.Width / 2, scoreDateLabel.Height / 2); scoreDateLabel.IsVisible = Global.HighScores[i] != TimeSpan.Zero; } if (Global.MusicEnabled && MediaPlayer.State != MediaState.Playing) { MediaPlayer.Play(Global.BackgroundSong); } base.Update(gameTime); }
public override void Load(ContentManager content) { Sprite bg = new Sprite("Background", content.Load <Texture2D>("Backgrounds/Game Screen 6"), Vector2.Zero, Color.White); SpriteCollection.Add(bg); Sprite homeButton = new Sprite("homeButton", content.Load <Texture2D>("Screen Images/Home Icon"), new Vector2(0, 1500), Color.White); homeButton.Origin = new Vector2(homeButton.Width / 2, homeButton.Height / 2); homeButton.X = RenderTarget.Width / 2; SpriteCollection.Add(homeButton); Sprite title = new Sprite("title", content.Load <Texture2D>("Screen Images/ScoreTitle"), new Vector2(RenderTarget.Width / 2, 182), Color.White); title.Origin = new Vector2(title.Width / 2, 0); SpriteCollection.Add(title); SpriteLabel timeTitle = new SpriteLabel("timeTitle", content.Load <SpriteFont>("Fonts/dnk48"), "Time:", new Vector2(58, 286), Color.White); SpriteLabel typeTitle = new SpriteLabel("typeTitle", content.Load <SpriteFont>("Fonts/dnk48"), "Type:", new Vector2(449, 286), Color.White); SpriteLabel dateTitle = new SpriteLabel("dateTitle", content.Load <SpriteFont>("Fonts/dnk48"), "Date:", new Vector2(836, 286), Color.White); SpriteCollection.Add(timeTitle); SpriteCollection.Add(typeTitle); SpriteCollection.Add(dateTitle); SpriteLabel highScoreLabel = new SpriteLabel("highScoreLabel", content.Load <SpriteFont>("Fonts/dnk48"), String.Empty, new Vector2(RenderTarget.Width / 2, 350), Color.Black); SpriteCollection.Add(highScoreLabel); int y = 441; int difference = 200; for (int i = 0; i < Global.HighScores.Length; i++) { SpriteLabel scoreLabel = new SpriteLabel(String.Format("scoreLabel{0}", i), content.Load <SpriteFont>("Fonts/dnk48"), String.Empty, new Vector2(timeTitle.X + timeTitle.Width / 2.4f, y), Color.White); SpriteCollection.Add(scoreLabel); HighScoreControl scoreTypeLabel = new HighScoreControl(String.Format("scoreTypeLabel{0}", i), ControlTypes.NoControl, scoreLabel.Position); scoreTypeLabel.X = typeTitle.X + typeTitle.Width / 2.4f; SpriteCollection.Add(scoreTypeLabel); SpriteLabel scoreDateLabel = new SpriteLabel(String.Format("scoreDateLabel{0}", i), content.Load <SpriteFont>("Fonts/dnk48"), String.Empty, scoreLabel.Position, Color.White); scoreDateLabel.X = dateTitle.X + dateTitle.Width / 2.4f; SpriteCollection.Add(scoreDateLabel); y += difference; } #if WINDOWS homeButton.MouseClick += homeButton_MouseClick; #else TouchManager touchManger = TouchManager.Instance; touchManger.GestureOccured += touchManger_GestureOccured; #endif clickSound = content.Load <SoundEffect>("Sounds/Effects/RD click Sound"); }
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 override void Load(Microsoft.Xna.Framework.Content.ContentManager content) { _content = content; loadingDropingObjects(content); loadingBackgrounds(content); loadingSongs(content); FallingItem.FallingSpeed = startingSpeed; startingDifficultyTime = new TimeSpan(0, 0, 3); elapsedArrowTime = TimeSpan.Zero; difficultyTime = startingDifficultyTime; arrowFadeTime = new TimeSpan(0, 0, 0, 5); //SpriteLabel tutorialText = new SpriteLabel("tutorialText", content.Load<SpriteFont>("Fonts/FS14"), "Press the arrows to move!", Vector2.Zero, Color.Black); //tutorialText.Scale = new Vector2(3); //tutorialText.Position = new Vector2(RenderTarget.Width / 2 - tutorialText.Width / 2, RenderTarget.Height - tutorialText.Height * 2); //tutorialText.IsVisible = Global.Tutorial; _columns = new Column[fallingLocation.Length]; for (int i = 0; i < _columns.Length; i++) { _columns[i] = new Column(fallingLocation[i].X.ToInt(true), RenderTarget.Height); } _columns[0].NextColumns.Add(_columns[1]); //_columns[1].NextColumns.Add(_columns[0]); _columns[1].NextColumns.Add(_columns[2]); //_columns[2].NextColumns.Add(_columns[1]); _columns[2].NextColumns.Add(_columns[3]); _columns[3].NextColumns.Add(_columns[2]); backGround = new Sprite("backGround", Global.Backgrounds[Global.CurrentBackgroundIndex], Vector2.Zero, Color.White); leftHelpButton = new Sprite("leftButton", content.Load <Texture2D>("Screen Images/Left Arrow"), Vector2.Zero, Color.White); leftHelpButton.Scale = new Vector2(.8f); leftHelpButton.Position = new Vector2(0, RenderTarget.Height - leftHelpButton.Height * 3f); leftHelpButton.Color = Color.Lerp(Color.White, Color.Transparent, .3f); //leftHelpButton.Effect = SpriteEffects.FlipHorizontally; rightHelpButton = new Sprite("rightButton", content.Load <Texture2D>("Screen Images/Right Arrow"), Vector2.Zero, Color.White); rightHelpButton.Scale = leftHelpButton.Scale; rightHelpButton.Position = new Vector2(RenderTarget.Width - rightHelpButton.Width, leftHelpButton.Y); rightHelpButton.Color = Color.Lerp(Color.White, Color.Transparent, .3f); _fpsLabel = new SpriteLabel("SpeedLabel", content.Load <SpriteFont>("Fonts/dnk24"), String.Empty, Vector2.Zero, Color.Black); _fpsLabel.Text = String.Format("Speed: {0}", FallingItem.FallingSpeed); _fpsLabel.Scale = new Vector2(3); _fpsLabel.Y = RenderTarget.Height - _fpsLabel.Height; _fpsLabel.IsVisible = false; //death Texture2D firstDeathFrame = content.Load <Texture2D>("Characters/Effects/Death/explosion1"); SpriteSheet deathSprite = new SpriteSheet("RedPanda", Vector2.Zero, Color.White, firstDeathFrame); for (int i = 2; i < 6; i++) { Sprite deathFrame = new Sprite("RedPanda", content.Load <Texture2D>(String.Format("Characters/Effects/Death/explosion{0}", i)), Vector2.Zero, Color.White); deathSprite.Add(deathFrame); } foreach (Sprite frame in deathSprite) { frame.Origin = new Vector2(frame.Width / 2, frame.Height / 3 * 2); frame.Scale = new Vector2(0.8f); } deathSprite.AnimateTime = TimeSpan.FromMilliseconds(100); deathSprite.AnimationFinish += deathSprite_AnimationFinish; playerIndex = 1; //ria load Sprite idleRiaFrame = new Sprite("RedPanda", content.Load <Texture2D>("Characters/RedPanda/Ria/0"), Vector2.Zero, Color.White); idleRiaFrame.Origin = new Vector2(380, idleRiaFrame.Height); Texture2D test = content.Load <Texture2D>("Characters/RedPanda/Ria/1"); SpriteSheet movingRiaFrames = new SpriteSheet("RedPanda", Vector2.Zero, Color.White, test); for (int i = 2; i < 7; i++) { Sprite frame = new Sprite("RedPanda", content.Load <Texture2D>(String.Format("Characters/RedPanda/Ria/{0}", i)), Vector2.Zero, Color.White); movingRiaFrames.Add(frame); } movingRiaFrames.Origin = new Vector2(380, test.Height); movingRiaFrames.AnimateTime = TimeSpan.FromMilliseconds(25 / (_level + 1));//speed animation up according to level. Kevin movingRiaFrames.AnimationFinish += movingRiaFrames_AnimationFinish; player = new Character(new ISprite[] { idleRiaFrame, movingRiaFrames, deathSprite }); player.Position = new Vector2(fallingLocation[playerIndex].X - 1, RenderTarget.Height - 50); direction = Direction.None; //SpriteCollection.Add(tutorialText); SpriteCollection.Add(backGround); SpriteCollection.Add(_fpsLabel); SpriteCollection.Add(leftHelpButton); SpriteCollection.Add(rightHelpButton); string leftSwipeFile = String.Empty; string rightSwipeFile = String.Empty; XnaAudio.MediaPlayer.Volume = 1; SpriteCollection.NameCheck = false; SpriteCollection.Add(player); foreach (Column column in _columns) { foreach (FallingItem item in column.Pool) { SpriteCollection.Add(item); } } if (Global.Control == ControlTypes.Swipe) { leftHelpButton.IsVisible = false; rightHelpButton.IsVisible = false; } else { leftHelpButton.IsVisible = true; rightHelpButton.IsVisible = true; } _lastSpwaned = _columns[0]; Column.OffSet = player.BoundingBox.Height + player.BoundingBox.Height / 4; leftSwipeFile = "Sounds/Effects/Air 1 swipe to left"; rightSwipeFile = "Sounds/Effects/Air 2 swipe to right"; #if !WINDOWS TouchManager touch = TouchManager.Instance; touch.GestureOccured += touch_GestureOccured; #endif SpriteLabel helperLabel = new SpriteLabel("helperLabel", content.Load <SpriteFont>("Fonts/dnk48"), String.Empty, new Vector2(RenderTarget.Width / 2, RenderTarget.Height / 2), Color.White); helperLabel.Y += 425; helperLabel.Origin = new Vector2(helperLabel.Width / 2, helperLabel.Height / 2); //helperLabel.Scale = new Vector2(1); SpriteCollection.Add(helperLabel); timeLabel = new SpriteLabel("timeLabel", content.Load <SpriteFont>("Fonts/dnk72"), String.Empty, Vector2.Zero, Color.Black); timeLabel.Position = new Vector2(RenderTarget.Width / 2, 30); //timeLabel.Scale = new Vector2(2); SpriteCollection.Add(timeLabel); controlLabel = new HighScoreControl("controlLabel", ControlTypes.Tap, new Vector2(0, 30)); controlLabel.Scale = new Vector2(0.5f); controlLabel.X = RenderTarget.Width - controlLabel.Width - 30; controlLabel.IsVisible = false; SpriteCollection.Add(controlLabel); deathSound = content.Load <SoundEffect>("Sounds/Effects/DeathSound"); //content.Load<XnaAudio.Song>("Sounds/DeathSound"); leftSwipe = content.Load <SoundEffect>(leftSwipeFile); //content.Load<XnaAudio.Song>(leftSwipeFile); rightSwipe = content.Load <SoundEffect>(rightSwipeFile); // content.Load<XnaAudio.Song>(rightSwipeFile); highScoreSound = content.Load <SoundEffect>("Sounds/Effects/RD High Score"); _level = 0; SpriteCollection.IsReadOnly = true; }
public override void Load(Microsoft.Xna.Framework.Content.ContentManager content) { rand = new Random(); SpriteLabel gameOver = new SpriteLabel("gameOver", content.Load <SpriteFont>("Fonts/dnk72"), "Game Over!", Vector2.Zero, Color.White); gameOver.Origin = new Vector2(gameOver.Width / 2, 0); gameOver.Position = new Vector2(RenderTarget.Width / 2, 240); highScore = new SpriteLabel("HighScoreLabel", content.Load <SpriteFont>("Fonts/dnk121"), "Test", Vector2.Zero, Color.White); //highScore.Position = new Vector2(557, 886); //highScore.Scale = new Vector2(5); Sprite playButton = new Sprite("Play", content.Load <Texture2D>("Screen Images/Replay"), Vector2.Zero, Color.White); //playButton.Scale = new Vector2(.2f); playButton.Position = new Vector2(557, 1124); Sprite house = new Sprite("House", content.Load <Texture2D>("Screen Images/Home Icon"), Vector2.Zero, Color.White); //house.Scale = new Vector2(.5f); house.Position = new Vector2(235, 1124); Sprite highScoreButton = new Sprite("statButton", content.Load <Texture2D>("Screen Images/Rankiings Icon"), Vector2.Zero, Color.White); highScoreButton.Position = new Vector2(235, 1407); Sprite settingsButton = new Sprite("settingsButton", content.Load <Texture2D>("Screen Images/Menu Icon"), Vector2.Zero, Color.White); settingsButton.Position = new Vector2(557, 1407); Sprite timeBox = new Sprite("timeBox", content.Load <Texture2D>("Screen Images/Time"), Vector2.Zero, Color.White); timeBox.Position = new Vector2(257, 589); newHighScore = new SpriteLabel("newHighScore", content.Load <SpriteFont>("Fonts/dnk64"), "New High Score!", Vector2.Zero, Color.White); //newHighScore.Scale = new Vector2(4); newHighScore.Origin = new Vector2(newHighScore.Width / 2, 0); newHighScore.Position = new Vector2(RenderTarget.Width / 2, 397); background = new Sprite("Background", Global.Backgrounds[Global.CurrentBackgroundIndex], Vector2.Zero, Color.White); #if WINDOWS house.MouseClick += house_MouseClick; playButton.MouseClick += playButton_MouseClick; highScoreButton.MouseClick += highScoreButton_MouseClick; settingsButton.MouseClick += settingsButton_MouseClick; #else TouchManager touch = TouchManager.Instance; touch.GestureOccured += touch_GestureOccured; #endif SpriteCollection.Add(background); SpriteCollection.Add(gameOver); SpriteCollection.Add(playButton); SpriteCollection.Add(highScoreButton); SpriteCollection.Add(settingsButton); SpriteCollection.Add(timeBox); SpriteCollection.Add(house); SpriteCollection.Add(highScore); SpriteCollection.Add(newHighScore); clickSound = content.Load <SoundEffect>("Sounds/Effects/RD click Sound"); }