コード例 #1
0
    public CAndy()
    {
        setFrames(Resources.LoadAll <Sprite> ("Sprites/nina"));
        setName("Nina");
        setSortingLayerName("Player");

        setScale(0.5f);

        setRegistration(CSprite.REG_TOP_LEFT);

        setWidth(WIDTH);
        setHeight(HEIGHT);

        // TODO: PASAR A LA CAMARA CUANDO SE IMPLEMENTE.
        CAudioManager.Inst.setAudioListener(this);
        CAudioManager.Inst.setPrimaryParent(this.getGameObject());

        // Agregate al audio manager como audio source.
        // Este objeto emite sonido.
        CAudioManager.Inst.addAudioSource(this).gameObject.transform.SetParent(this.getGameObject().transform);

        setState(STATE_STAND);

        if (this.debug)
        {
            mRect = new CSprite();
            mRect.setImage(Resources.Load <Sprite> ("Sprites/ui/pixel"));
            mRect.setSortingLayerName("Player");
            mRect.setSortingOrder(20);
            mRect.setAlpha(0.5f);
            mRect.setName("player_debug_rect");

            mRect2 = new CSprite();
            mRect2.setImage(Resources.Load <Sprite> ("Sprites/ui/pixel"));
            mRect2.setSortingLayerName("Player");
            mRect2.setSortingOrder(20);
            mRect2.setColor(Color.red);
            mRect2.setAlpha(0.5f);
            mRect2.setName("player_debug_rect2");
        }

        this.powers = new List <Power>();
        this.powers.Add(new Earth());
        this.powers.Add(new Air(this));
        this.powers.Add(new Water(this));
        this.powers.Add(new Fire(this));

        this.selectedPower = 0;

        this.powers[this.selectedPower].setActive();

        textoPoderes = new CText(this.powers[this.selectedPower].getName());
        textoPoderes.setWidth(this.getWidth());
        textoPoderes.setWrapping(false);
        textoPoderes.setFontSize(40f);
        textoPoderes.setXY(this.getX(), this.getY() - textoPoderes.getHeight());
        textoPoderes.setAlignment(TMPro.TextAlignmentOptions.Center);

        this.setBounds(0, 0, CTileMap.Instance.getMapWidth() * CTileMap.Instance.getTileWidth(), CTileMap.Instance.getMapHeight() * CTileMap.Instance.getTileHeight());
        this.setBoundAction(CGameObject.BOUNCE);
    }
コード例 #2
0
    override public void update()
    {
        int tileWidth  = CGame.inst().getMap().getTileWidth();
        int tileHeight = CGame.inst().getMap().getTileHeight();

        //Debug.Log ("test left : " + CKeyboard.pressed (CKeyboard.LEFT) + CKeyboard.pressed (CKeyboard.UP) + CKeyboard.pressed (CKeyboard.SPACE));
        //Debug.Log ("test right: " + CKeyboard.pressed (CKeyboard.RIGHT) + CKeyboard.pressed (CKeyboard.UP) + CKeyboard.pressed (CKeyboard.SPACE));

        // Guardar la posicion anterior del objeto.
        setOldYPosition();

        base.update();

        if (CKeyboard.firstPress(KeyCode.E))
        {
            this.selectNextPower();
        }
        else if (CKeyboard.firstPress(KeyCode.Q))
        {
            this.selectPreviousPower();
        }

        if (getState() == STATE_STAND)
        {
            // En stand no deberia pasar nunca que quede metido en una pared.
            // Si estamos en una pared, corregirnos.
            if (isWallLeft(getX(), getY()))
            {
                // Reposicionar el personaje contra la pared.
                setX(((mLeftX + 1) * tileWidth) - this.getLeftOffsetBoundingBox());
            }
            if (isWallRight(getX(), getY()))
            {
                // Reposicionar el personaje contra la pared.
                setX((((mRightX) * tileWidth) - getWidth()) + this.getRightOffsetBoundingBox());
            }


            // Si en el pixel de abajo del jugador no hay piso, caemos.
            if (!isFloor(getX(), getY() + 1))
            {
                setState(STATE_FALLING);
                return;
            }

            if (CKeyboard.firstPress(CKeyboard.SPACE))
            {
                setState(STATE_PRE_JUMPING);
                return;
            }

            if (CKeyboard.pressed(CKeyboard.KEY_A) && !isWallLeft(getX() - 1, getY()))
            {
                setState(STATE_WALKING);
                return;
            }

            if (CKeyboard.pressed(CKeyboard.KEY_D) && !isWallRight(getX() + 1, getY()))
            {
                setState(STATE_WALKING);
                return;
            }
        }
        else if (getState() == STATE_WALKING)
        {
            if (isWallLeft(getX(), getY()))
            {
                // Reposicionar el personaje contra la pared.
                setX(((mLeftX + 1) * tileWidth) - this.getLeftOffsetBoundingBox());
            }
            if (isWallRight(getX(), getY()))
            {
                // Reposicionar el personaje contra la pared.
                setX((((mRightX) * tileWidth) - getWidth()) + this.getRightOffsetBoundingBox());
            }

            if (CKeyboard.firstPress(CKeyboard.SPACE))
            {
                setState(STATE_PRE_JUMPING);
                return;
            }

            // Si en el pixel de abajo del jugador no hay piso, caemos.
            if (!isFloor(getX(), getY() + 1))
            {
                setState(STATE_FALLING);
                return;
            }

            if (!(CKeyboard.pressed(CKeyboard.KEY_A) || CKeyboard.pressed(CKeyboard.KEY_D)))
            {
                setState(STATE_STAND);
                return;
            }
            else
            {
                if (CKeyboard.pressed(CKeyboard.KEY_A))
                {
                    // Chequear pared a la izquierda.
                    // Si hay pared a la izquierda vamos a stand.
                    if (isWallLeft(getX(), getY()))
                    {
                        // Reposicionar el personaje contra la pared.
                        //setX((((int) getX ()/tileWidth)+1)*tileWidth);
                        setX(((mLeftX + 1) * tileWidth) - this.getLeftOffsetBoundingBox());

                        // Carlos version.
                        //setX (getX()+tileWidth/(getWidth()-1));

                        setState(STATE_STAND);
                        return;
                    }
                    else
                    {
                        // No hay pared, se puede mover.
                        setVelX(-400);
                        setFlip(true);
                    }
                }
                else
                {
                    // Chequear pared a la derecha.
                    // Si hay pared a la derecha vamos a stand.
                    if (isWallRight(getX(), getY()))
                    {
                        // Reposicionar el personaje contra la pared.
                        setX((((mRightX) * tileWidth) - getWidth()) + this.getRightOffsetBoundingBox());

                        setState(STATE_STAND);
                        return;
                    }
                    else
                    {
                        // No hay pared, se puede mover.
                        setVelX(400);
                        setFlip(false);
                    }
                }
            }
        }
        else if (getState() == STATE_PRE_JUMPING)
        {
            controlMoveHorizontal();

            if (!isFloor(getX(), getY() + 1) && getAccelY() == 0)
            {
                setAccelY(CGameConstants.GRAVITY);
            }

            if (this.isEnded())
            {
                this.setState(STATE_JUMPING);
            }
        }
        else if (getState() == STATE_JUMPING)
        {
            controlMoveHorizontal();

            if (this.getVelY() > 0)
            {
                setState(STATE_FALLING);
                return;
            }

            if (isFloor(getX(), getY() + 1))
            {
                setY(mDownY * tileHeight - getHeight());
                setState(STATE_STAND);
                return;
            }

            if (isRoof(getX(), getY() - 1))
            {
                setY(((mUpY + 1) * tileHeight) - this.getTopOffsetBoundingBox());
                setVelY(0);
                setState(STATE_HIT_ROOF);
                return;
            }
        }
        else if (getState() == STATE_FALLING)
        {
            controlMoveHorizontal();

            if (isFloor(getX(), getY() + 1))
            {
                setY(mDownY * tileHeight - getHeight());
                setState(STATE_STAND);
                return;
            }
        }
        else if (getState() == STATE_HIT_ROOF)
        {
            if (getTimeState() > 0.02f * 5.0f)
            {
                setState(STATE_FALLING);
                return;
            }
        }
        else if (getState() == STATE_DASHING)
        {
            setVelY(0);
            // Si estamos en una pared, corregirnos.
            if (isWallLeft(getX(), mOldY))
            {
                // Reposicionar el personaje contra la pared.
                setX(((mLeftX + 1) * CTileMap.Instance.getTileWidth()) - this.getLeftOffsetBoundingBox());
            }
            if (isWallRight(getX(), mOldY))
            {
                // Reposicionar el personaje contra la pared.
                setX((((mRightX) * CTileMap.Instance.getTileWidth()) - getWidth()) + this.getRightOffsetBoundingBox());
            }

            if (isFloor(getX(), getY() + 1))
            {
                setY(mDownY * CTileMap.Instance.getTileHeight() - getHeight());
            }

            if (isRoof(getX(), getY() - 1))
            {
                setY(((mUpY + 1) * CTileMap.Instance.getTileHeight()) - this.getTopOffsetBoundingBox());
            }

            if (this.getTimeState() >= 0.6f / 3 * 2)
            {
                this.initAnimation(47, 49, 12, false);
            }

            if (this.getTimeState() >= 0.6f)
            {
                this.setState(STATE_STAND);
            }
        }


        // Chequear el paso entre pantallas.
        controlRooms();

        textoPoderes.setXY(this.getX(), this.getY() - textoPoderes.getHeight());
        textoPoderes.setText(this.powers[this.selectedPower].getName());
        textoPoderes.update();

        for (int i = 0; i < this.powers.Count; i++)
        {
            this.powers[i].update();
        }
    }