private void setupPaddle()
 {
     paddle = new ImageSprite(imageURL: "ms-appx:///Images/paddle.png");
     SnapsEngine.AddSpriteToGame(paddle);
     paddleWidth = SnapsEngine.GameViewportWidth / 10.0;
     paddle.ScaleSpriteWidth(paddleWidth);
 }
Beispiel #2
0
    public void StartProgram()
    {
        SnapsEngine.StartGameEngine(fullScreen: false, framesPerSecond: 60);

        ImageSprite scaledCity = new ImageSprite(imageURL: "ms-appx:///Images/city.jpg");

        SnapsEngine.AddSpriteToGame(scaledCity);

        float maxWidth     = 500;
        float minWidth     = 100;
        float currentWidth = 100;
        float widthUpdate  = 1;

        while (true)
        {
            currentWidth = currentWidth + widthUpdate;
            if (currentWidth > maxWidth)
            {
                widthUpdate = -1;
            }
            if (currentWidth < minWidth)
            {
                widthUpdate = 1;
            }
            scaledCity.ScaleSpriteWidth(currentWidth);
            SnapsEngine.DrawGamePage();
        }
    }
Beispiel #3
0
    public void StartProgram()
    {
        SnapsEngine.SetBackgroundColor(SnapsColor.Black);

        SnapsEngine.StartGameEngine(fullScreen: false, framesPerSecond: 60);

        List <MovingSprite> sprites = new List <MovingSprite>();

        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,
                                                   ySpeed: 15);
            sprites.Add(star);
        }

        while (true)
        {
            foreach (MovingSprite sprite in sprites)
            {
                sprite.Update();
            }
            SnapsEngine.DrawGamePage();
        }
    }
    private void setupBall()
    {
        ball = new ImageSprite(imageURL: "ms-appx:///Images/ball.png");
        SnapsEngine.AddSpriteToGame(ball);

        ballWidth = SnapsEngine.GameViewportWidth / 20.0;
        ball.ScaleSpriteWidth(ballWidth);
    }
    public void StartProgram()
    {
        SnapsEngine.SetBackgroundColor(SnapsColor.Black);

        SnapsEngine.StartGameEngine(fullScreen: false, framesPerSecond: 60);

        List <MovingSprite> sprites = new List <MovingSprite>();

        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,
                                                   ySpeed: 15);
            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);

        while (true)
        {
            foreach (MovingSprite sprite in sprites)
            {
                sprite.Update();
            }
            SnapsEngine.DrawGamePage();
        }
    }
Beispiel #6
0
    public void StartProgram()
    {
        SnapsEngine.StartGameEngine(fullScreen: false, framesPerSecond: 60);

        ImageSprite scaledBall = new ImageSprite(imageURL: "ms-appx:///Images/ball.png");

        SnapsEngine.AddSpriteToGame(scaledBall);

        double ballWidth = SnapsEngine.GameViewportWidth / 20.0;

        scaledBall.ScaleSpriteWidth(ballWidth);

        while (true)
        {
            SnapsEngine.DrawGamePage();
        }
    }
    public void StartProgram()
    {
        SnapsEngine.SetBackgroundColor(SnapsColor.Black);

        SnapsEngine.StartGameEngine(fullScreen: false, framesPerSecond: 60);

        ImageSprite starImage = new ImageSprite(imageURL: "ms-appx:///Images/star.png");

        SnapsEngine.AddSpriteToGame(starImage);
        starImage.ScaleSpriteWidth(SnapsEngine.GameViewportWidth / 50);
        FallingSprite star = new FallingSprite(sprite: starImage, ySpeed: 1);

        while (true)
        {
            star.Update();
            SnapsEngine.DrawGamePage();
        }
    }
    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();
        }
    }
    public void StartProgram()
    {
        SnapsEngine.StartGameEngine(fullScreen: false, framesPerSecond: 60);

        ImageSprite ball = new ImageSprite(imageURL: "ms-appx:///Images/ball.png");
        SnapsEngine.AddSpriteToGame(ball);

        double ballWidth = SnapsEngine.GameViewportWidth / 20.0;
        ball.ScaleSpriteWidth(ballWidth);

        double XBallSpeed = 10;
        double YBallSpeed = 10;

        ImageSprite paddle = new ImageSprite(imageURL: "ms-appx:///Images/paddle.png");
        SnapsEngine.AddSpriteToGame(paddle);
        double paddleWidth = SnapsEngine.GameViewportWidth / 10.0;
        paddle.ScaleSpriteWidth(paddleWidth);
        paddle.Bottom = SnapsEngine.GameViewportHeight - 10;
        paddle.CenterX = SnapsEngine.GameViewportWidth / 2;
        double XPaddleSpeed = 15;

        while (true)
        {
            // update the ball position according to the speed
            ball.X = ball.X + XBallSpeed;
            ball.Y = ball.Y + YBallSpeed;

            if (ball.Left < 0)
            {
                // ball is going off the left hand edge
                if (XBallSpeed < 0)
                {
                    // ball is moving to the left 
                    // because the speed is negative
                    // make it "bounce" back into the viewport
                    // make the speed positive
                    XBallSpeed = -XBallSpeed;
                }
            }

            if (ball.Right > SnapsEngine.GameViewportWidth)
            {
                // ball is going off the right hand edge
                if (XBallSpeed > 0)
                {
                    // ball is moving to the right
                    // because the speed is positive
                    // make it "bounce" back into the viewport
                    // make the speed negative
                    XBallSpeed = -XBallSpeed;
                }
            }

            if (ball.Bottom > SnapsEngine.GameViewportHeight)
            {
                // ball is going off the bottom edge
                if (YBallSpeed > 0)
                {
                    // ball is moving down the screen
                    // because the speed is positive
                    // make it bounce back into the viewport
                    // make the speed negative
                    YBallSpeed = -YBallSpeed;
                }
            }

            if (ball.Top < 0)
            {
                // ball is going off the top edge
                if (YBallSpeed < 0)
                {
                    // ball is up down the screen
                    // because the speed is negative
                    // make it bounce back into the viewport
                    // make the speed positive
                    YBallSpeed = -YBallSpeed;
                }
            }

            // Now update the gamepad

            if (SnapsEngine.GetRightGamepad())
            {
                paddle.X = paddle.X + XPaddleSpeed;
            }

            if (SnapsEngine.GetLeftGamepad())
            {
                paddle.X = paddle.X - XPaddleSpeed;
            }

            if (paddle.Left < 0)
            {
                // Trying to move off the left edge - pull the pad back
                paddle.Left = 0;
            }

            if (paddle.Right > SnapsEngine.GameViewportWidth)
            {
                // Trying to move off the right edge - pull the pad back
                paddle.Right = SnapsEngine.GameViewportWidth;
            }

            // Handle collisions with the ball

            if (paddle.IntersectsWith(ball))
            {
                if (YBallSpeed > 0)
                {
                    // ball is going down, make it bounce off the bat
                    // and go up
                    YBallSpeed = -YBallSpeed;
                }
            }
            SnapsEngine.DrawGamePage();
        }
    }
Beispiel #10
0
    public void StartProgram()
    {
        SnapsEngine.StartGameEngine(fullScreen: false, framesPerSecond: 60);

        ISnapsSprite ball = new ImageSprite(imageURL: "ms-appx:///Images/ball.png");

        SnapsEngine.AddSpriteToGame(ball);

        double ballWidth = SnapsEngine.GameViewportWidth / 20.0;

        ball.ScaleSpriteWidth(ballWidth);

        double XBallSpeed = 10;
        double YBallSpeed = 10;

        while (true)
        {
            // update the ball position according to the speed
            ball.X = ball.X + XBallSpeed;
            ball.Y = ball.Y + YBallSpeed;

            if (ball.Left < 0)
            {
                // ball is going off the left hand edge
                if (XBallSpeed < 0)
                {
                    // ball is moving to the left
                    // because the speed is negative
                    // make it "bounce" back into the viewport
                    // make the speed positive
                    XBallSpeed = -XBallSpeed;
                }
            }

            if (ball.Right > SnapsEngine.GameViewportWidth)
            {
                // ball is going off the right hand edge
                if (XBallSpeed > 0)
                {
                    // ball is moving to the right
                    // because the speed is positive
                    // make it "bounce" back into the viewport
                    // make the speed negative
                    XBallSpeed = -XBallSpeed;
                }
            }

            if (ball.Bottom > SnapsEngine.GameViewportHeight)
            {
                // ball is going off the bottom edge
                if (YBallSpeed > 0)
                {
                    // ball is moving down the screen
                    // because the speed is positive
                    // make it bounce back into the viewport
                    // make the speed negative
                    YBallSpeed = -YBallSpeed;
                }
            }

            if (ball.Top < 0)
            {
                // ball is going off the top edge
                if (YBallSpeed < 0)
                {
                    // ball is up down the screen
                    // because the speed is negative
                    // make it bounce back into the viewport
                    // make the speed positive
                    YBallSpeed = -YBallSpeed;
                }
            }
            // draw the game page
            SnapsEngine.DrawGamePage();
        }
    }
Beispiel #11
0
        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;
        }