Esempio n. 1
0
        public GameScreen(IGame game)
            : base(game)
        {
            // Initialize game objects here

            bg1 = new Background(0, 0);
            bg2 = new Background(2160, 0);
            robot = new Robot();
            hb = new Heliboy(340, 360);
            hb2 = new Heliboy(700, 360);

            character = Assets.character;
            character2 = Assets.character2;
            character3 = Assets.character3;

            heliboy = Assets.heliboy;
            heliboy2 = Assets.heliboy2;
            heliboy3 = Assets.heliboy3;
            heliboy4 = Assets.heliboy4;
            heliboy5 = Assets.heliboy5;

            anim = new Animation();
            anim.addFrame(character, 1250);
            anim.addFrame(character2, 50);
            anim.addFrame(character3, 50);
            anim.addFrame(character2, 50);

            hanim = new Animation();
            hanim.addFrame(heliboy, 100);
            hanim.addFrame(heliboy2, 100);
            hanim.addFrame(heliboy3, 100);
            hanim.addFrame(heliboy4, 100);
            hanim.addFrame(heliboy5, 100);
            hanim.addFrame(heliboy4, 100);
            hanim.addFrame(heliboy3, 100);
            hanim.addFrame(heliboy2, 100);

            currentSprite = anim.getImage();

            loadMap();

            // Defining a paint object
            paint1 = new Paint();
            paint1.SetTextSize(30);
            paint1.SetTextAlign(Paint.Align.CENTER);
            paint1.SetAntiAlias(true);
            paint1.SetColor(Color.WHITE);

            paint2 = new Paint();
            paint2.SetTextSize(100);
            paint2.SetTextAlign(Paint.Align.CENTER);
            paint2.SetAntiAlias(true);
            paint2.SetColor(Color.WHITE);

        }
Esempio n. 2
0
        public GameScreen(IGame game)
            : base(game)
        {
            // Initialize game objects here

            bg1   = new Background(0, 0);
            bg2   = new Background(2160, 0);
            robot = new Robot();
            hb    = new Heliboy(340, 360);
            hb2   = new Heliboy(700, 360);

            character  = Assets.character;
            character2 = Assets.character2;
            character3 = Assets.character3;

            heliboy  = Assets.heliboy;
            heliboy2 = Assets.heliboy2;
            heliboy3 = Assets.heliboy3;
            heliboy4 = Assets.heliboy4;
            heliboy5 = Assets.heliboy5;

            anim = new Animation();
            anim.addFrame(character, 1250);
            anim.addFrame(character2, 50);
            anim.addFrame(character3, 50);
            anim.addFrame(character2, 50);

            hanim = new Animation();
            hanim.addFrame(heliboy, 100);
            hanim.addFrame(heliboy2, 100);
            hanim.addFrame(heliboy3, 100);
            hanim.addFrame(heliboy4, 100);
            hanim.addFrame(heliboy5, 100);
            hanim.addFrame(heliboy4, 100);
            hanim.addFrame(heliboy3, 100);
            hanim.addFrame(heliboy2, 100);

            currentSprite = anim.getImage();

            loadMap();

            // Defining a paint object
            paint1             = new Paint();
            paint1.TextSize    = (30);
            paint1.TextAlign   = (Paint.Align.CENTER);
            paint1.IsAntiAlias = (true);
            paint1.Color       = (Color.WHITE);

            paint2             = new Paint();
            paint2.TextSize    = (100);
            paint2.TextAlign   = (Paint.Align.CENTER);
            paint2.IsAntiAlias = (true);
            paint2.Color       = (Color.WHITE);
        }
Esempio n. 3
0
        private void updateRunning(IList <TouchEvent> touchEvents, float deltaTime)
        {
            // This is identical to the update() method from our Unit 2/3 game.

            // 1. All touch input is handled here:
            int len = touchEvents.Size();

            for (int i = 0; i < len; i++)
            {
                TouchEvent @event = touchEvents.Get(i);
                if (@event.type == TouchEvent.TOUCH_DOWN)
                {
                    if (inBounds(@event, 0, 285, 65, 65))
                    {
                        robot.jump();
                        currentSprite = anim.getImage();
                        robot.setDucked(false);
                    }

                    else if (inBounds(@event, 0, 350, 65, 65))
                    {
                        if (robot.isDucked() == false && robot.isJumped() == false &&
                            robot.isReadyToFire())
                        {
                            robot.shoot();
                        }
                    }

                    else if (inBounds(@event, 0, 415, 65, 65) && robot.isJumped() == false)
                    {
                        currentSprite = Assets.characterDown;
                        robot.setDucked(true);
                        robot.setSpeedX(0);
                    }

                    if (@event.x > 400)
                    {
                        // Move right.
                        robot.moveRight();
                        robot.setMovingRight(true);
                    }
                }

                if (@event.
                    type == TouchEvent.TOUCH_UP)
                {
                    if (inBounds(@event, 0, 415, 65, 65))
                    {
                        currentSprite = anim.getImage();
                        robot.setDucked(false);
                    }

                    if (inBounds(@event, 0, 0, 35, 35))
                    {
                        pause();
                    }

                    if (@event.x > 400)
                    {
                        // Move right.
                        robot.stopRight();
                    }
                }
            }

            // 2. Check miscellaneous events like death:

            if (livesLeft == 0)
            {
                state = GameState.GameOver;
            }

            // 3. Call individual update() methods here.
            // This is where all the game updates happen.
            // For example, robot.update();
            robot.update();
            if (robot.isJumped())
            {
                currentSprite = Assets.characterJump;
            }
            else if (robot.isJumped() == false && robot.isDucked() == false)
            {
                currentSprite = anim.getImage();
            }

            ArrayList <Projectile> projectiles = robot.getProjectiles();

            for (int i = 0; i < projectiles.Size(); i++)
            {
                Projectile p = (Projectile)projectiles.Get(i);
                if (p.isVisible() == true)
                {
                    p.update();
                }
                else
                {
                    projectiles.Remove(i);
                }
            }

            updateTiles();
            hb.update();
            hb2.update();
            bg1.update();
            bg2.update();
            animate();

            if (robot.getCenterY() > 500)
            {
                state = GameState.GameOver;
            }
        }