Ejemplo n.º 1
0
        public void checkSideCollision(Rect rleft, Rect rright, Rect leftfoot, Rect rightfoot)
        {
            if (type != 5 && type != 2 && type != 0)
            {
                if (Rect.Intersects(rleft, r))
                {
                    robot.setCenterX(tileX + 102);

                    robot.setSpeedX(0);
                }
                else if (Rect.Intersects(leftfoot, r))
                {
                    robot.setCenterX(tileX + 85);
                    robot.setSpeedX(0);
                }

                if (Rect.Intersects(rright, r))
                {
                    robot.setCenterX(tileX - 62);

                    robot.setSpeedX(0);
                }

                else if (Rect.Intersects(rightfoot, r))
                {
                    robot.setCenterX(tileX - 45);
                    robot.setSpeedX(0);
                }
            }
        }
Ejemplo n.º 2
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;
            }
        }