private void CreateMissile() { var missileSprite = new MissileSprite(_missileTexture, _exhaustTexture); missileSprite.Position = new Vector2(_playerSprite.Position.X + 33, _playerSprite.Position.Y - 25); _missileList.Add(missileSprite); AddGameObject(missileSprite); }
/// <summary> /// Load the game over screen /// </summary> public override void Load() { GridStyle = GridStyles.Ticks; BackgroundColor = Color.Black; FontName = "QuartzMS"; // Add the score text ScoreText = AddText(new Text { Alignment = HorizontalAlignments.Left, VerticalAlign = VerticalAlignments.Top, Scale = .4f, Position = new Vector2(-100f, 100f), Color = Color.White }); // Add the start key text RestartText = AddText(new Text { Value = "Press SPACE to Play", Position = new Vector2(0f, -100f), Alignment = HorizontalAlignments.Center, VerticalAlign = VerticalAlignments.Bottom, AnimationType = TextAnimations.Typewriter, AnimationSeconds = 0.2, Scale = 0.5f, Color = Color.Lime }); if (Game.Platform == GamePlatforms.XBox) { RestartText.Value = "Press START to Play"; } else if (Game.Platform == GamePlatforms.WindowsPhone) { RestartText.Value = "TAP to Play"; } missile = AddSprite<MissileSprite>(); missile.SetCostume("ufo"); missile.Costume.YCenter = VerticalAlignments.Center; missile.Scale = 2; missile.Show(); missile.X = 0; missile.Y = 50; barrier = AddSprite<BarrierSprite>(); barrier.Scale = 2.5f; barrier.Y = -70; ufo = AddSprite<UfoSprite>(); ufo.Position = Vector2.Zero; ufo.Costume.YCenter = VerticalAlignments.Top; ufo.Scale = 1; ufo.Show(); }
using Color = Microsoft.Xna.Framework.Color; #endregion namespace ScratchyXna { public class PlayScreen : Scene { public enum PlayScreenModes { Init, ShowingPlayerNumber, Playing, Finished }
public override void HandleInput(GameTime gameTime) { InputManager.GetCommands(cmd => { if (cmd is DevInputCommand.DevQuit) { NotifyEvent(new BaseGameStateEvent.GameQuit()); } if (cmd is DevInputCommand.DevShoot) { _missile = new MissileSprite(LoadTexture(MissileTexture), LoadTexture(ExhaustTexture)); _missile.Position = new Vector2(_player.Position.X, _player.Position.Y - 25); AddGameObject(_missile); } }); }
public void StartProgram() { SnapsEngine.SetBackgroundColor(SnapsColor.Black); SnapsEngine.StartGameEngine(fullScreen: false, framesPerSecond: 60); List <MovingSprite> sprites = new List <MovingSprite>(); List <AlienSprite> aliens = new List <AlienSprite>(); for (int i = 0; i < 100; i++) { ImageSprite starImage = new ImageSprite(imageURL: "ms-appx:///Images/star.png"); SnapsEngine.AddSpriteToGame(starImage); starImage.ScaleSpriteWidth(SnapsEngine.GameViewportWidth / 75); FallingSprite star = new FallingSprite(sprite: starImage, xSpeed: 0, ySpeed: 15, viewportWidth: SnapsEngine.GameViewportWidth, viewportHeight: SnapsEngine.GameViewportHeight); sprites.Add(star); } ImageSprite rocketImage = new ImageSprite(imageURL: "ms-appx:///Images/SpaceRocket.png"); SnapsEngine.AddSpriteToGame(rocketImage); rocketImage.ScaleSpriteWidth(SnapsEngine.GameViewportWidth / 15); rocketImage.CenterX = SnapsEngine.GameViewportWidth / 2.0; rocketImage.CenterY = SnapsEngine.GameViewportHeight / 2.0; RocketSprite rocket = new RocketSprite(sprite: rocketImage, xSpeed: 10, ySpeed: 10); sprites.Add(rocket); ImageSprite chasingAlienImage = new ImageSprite(imageURL: "ms-appx:///Images/purpleAlien.png"); SnapsEngine.AddSpriteToGame(chasingAlienImage); chasingAlienImage.Top = 10; chasingAlienImage.ScaleSpriteWidth(SnapsEngine.GameViewportWidth / 20); chasingAlienImage.CenterX = SnapsEngine.GameViewportWidth / 2.0; chasingAlienImage.Top = 0; ChasingAlien chaser = new ChasingAlien(sprite: chasingAlienImage, target: rocket, xAcceleration: .3, yAcceleration: .3, friction: 0.99); sprites.Add(chaser); aliens.Add(chaser); int noOfAliens = 10; double alienWidth = SnapsEngine.GameViewportWidth / (noOfAliens * 2); double alienSpacing = (SnapsEngine.GameViewportWidth - alienWidth) / noOfAliens; double alienX = 0; double alienY = 100; for (int i = 0; i < noOfAliens; i = i + 1) { ImageSprite alienImage = new ImageSprite(imageURL: "ms-appx:///Images/greenAlien.png"); SnapsEngine.AddSpriteToGame(alienImage); alienImage.ScaleSpriteWidth(alienWidth); alienImage.CenterX = alienX; alienImage.Top = alienY; double xMin = alienX; double xMax = alienX + alienSpacing; LineAlien alien = new LineAlien(sprite: alienImage, xSpeed: 2, ySpeed: 0, target: rocket, xMax: xMax, xMin: xMin); sprites.Add(alien); aliens.Add(alien); alienX = alienX + alienSpacing; } ImageSprite missileImage = new ImageSprite(imageURL: "ms-appx:///Images/Missile.png"); missileImage.ScaleSpriteWidth(SnapsEngine.GameViewportWidth / 200); SnapsEngine.AddSpriteToGame(missileImage); MissileSprite missile = new MissileSprite(sprite: missileImage, rocket: rocket, xSpeed: 0, ySpeed: -15, aliens: aliens); sprites.Add(missile); rocket.Missiles.Add(missile); while (true) { foreach (MovingSprite sprite in sprites) { sprite.Update(); } SnapsEngine.DrawGamePage(); } }
void setupGame() { SnapsEngine.SetBackgroundColor(SnapsColor.Black); SnapsEngine.StartGameEngine(fullScreen: false, framesPerSecond: 60); for (int i = 0; i < 100; i++) { ImageSprite starImage = new ImageSprite(imageURL: "ms-appx:///Images/star.png"); SnapsEngine.AddSpriteToGame(starImage); starImage.ScaleSpriteWidth(SnapsEngine.GameViewportWidth / 75); FallingSprite star = new FallingSprite(sprite: starImage, xSpeed: 0, ySpeed: 15, viewportWidth: SnapsEngine.GameViewportWidth, viewportHeight: SnapsEngine.GameViewportHeight); sprites.Add(star); } ImageSprite rocketImage = new ImageSprite(imageURL: "ms-appx:///Images/SpaceRocket.png"); SnapsEngine.AddSpriteToGame(rocketImage); rocketImage.ScaleSpriteWidth(SnapsEngine.GameViewportWidth / 15); rocketImage.CenterX = SnapsEngine.GameViewportWidth / 2.0; rocketImage.CenterY = SnapsEngine.GameViewportHeight / 2.0; rocket = new RocketSprite(sprite: rocketImage, game: this, xSpeed: 10, ySpeed: 10); sprites.Add(rocket); ImageSprite chasingAlienImage = new ImageSprite(imageURL: "ms-appx:///Images/purpleAlien.png"); SnapsEngine.AddSpriteToGame(chasingAlienImage); chasingAlienImage.Top = 10; chasingAlienImage.ScaleSpriteWidth(SnapsEngine.GameViewportWidth / 20); chasingAlienImage.CenterX = SnapsEngine.GameViewportWidth / 2.0; chasingAlienImage.Top = 0; chaser = new ChasingAlien(sprite: chasingAlienImage, game: this, target: rocket, xAcceleration: .3, yAcceleration: .3, friction: 0.99); sprites.Add(chaser); aliens.Add(chaser); int noOfAliens = 10; double alienWidth = SnapsEngine.GameViewportWidth / (noOfAliens * 2); double alienSpacing = (SnapsEngine.GameViewportWidth - alienWidth) / noOfAliens; double alienX = 0; double alienY = 100; for (int i = 0; i < noOfAliens; i = i + 1) { ImageSprite alienImage = new ImageSprite(imageURL: "ms-appx:///Images/greenAlien.png"); SnapsEngine.AddSpriteToGame(alienImage); alienImage.ScaleSpriteWidth(alienWidth); alienImage.CenterX = alienX; alienImage.Top = alienY; double xMin = alienX; double xMax = alienX + alienSpacing; LineAlien alien = new LineAlien(sprite: alienImage, game: this, xSpeed: 2, ySpeed: 0, target: rocket, xMax: xMax, xMin: xMin); sprites.Add(alien); aliens.Add(alien); alienX = alienX + alienSpacing; } ImageSprite missileImage = new ImageSprite(imageURL: "ms-appx:///Images/Missile.png"); missileImage.ScaleSpriteWidth(SnapsEngine.GameViewportWidth / 200); SnapsEngine.AddSpriteToGame(missileImage); MissileSprite missile = new MissileSprite(sprite: missileImage, rocket: rocket, xSpeed: 0, ySpeed: -15, aliens: aliens); sprites.Add(missile); rocket.Missiles.Add(missile); gameOverScreen = new ImageSprite(imageURL: "ms-appx:///Images/SpaceRocketsInSpaceGameOverScreen.png"); gameOverScreen.Hide(); SnapsEngine.AddSpriteToGame(gameOverScreen); gameOverScreen.Width = SnapsEngine.GameViewportWidth; gameOverScreen.Height = SnapsEngine.GameViewportHeight; messageBack = new TextBlockSprite(text: "", fontSize: 60, fontFamily: "Impact", color: SnapsColor.Black); SnapsEngine.AddSpriteToGame(messageBack); message = new TextBlockSprite(text: "", fontSize: 60, fontFamily: "Impact", color: SnapsColor.Red); SnapsEngine.AddSpriteToGame(message); titleScreen = new ImageSprite(imageURL: "ms-appx:///Images/SpaceRocketsInSpaceTitleScreen.png"); titleScreen.Hide(); SnapsEngine.AddSpriteToGame(titleScreen); titleScreen.Width = SnapsEngine.GameViewportWidth; titleScreen.Height = SnapsEngine.GameViewportHeight; }