Example #1
0
        public void SwitchToSmallMario(bool animate)
        {
            //  ManualMoveY(-17); // put mario back on ground
            state.SwitchToSmallMario(animate);

            marioState = MarioState.SMALL;
        }
    // Start is called before the first frame update
    void Start()
    {
        MarioTransform  = GetComponent <Mariotransform>();
        playerRigidbody = GetComponent <Rigidbody2D>();
        collider        = GetComponent <BoxCollider2D>();
        //spriteRenderer = GetComponent<SpriteRenderer>();
        mainCam = Camera.main;

        MarioTransform.OnTransform += (sr, an, state) =>
        {
            Debug.Log("OnTransform()");
            spriteRenderer = sr;
            animator       = an;
            MarioState     = state;
            if (state == MarioState.Big)
            {
                collider.size   = new Vector2(1, 2);
                collider.offset = new Vector2(0, 0.5f);
                //igMarioBox.enabled = true;
            }
            else
            {
                collider.size   = new Vector2(1, 1);
                collider.offset = new Vector2(0, 0);
                //bigMarioBox.enabled = false;
            }
        };

        layerMask = LayerMask.NameToLayer("Untagged");
    }
Example #3
0
        void Update()
        {
            switch (state)
            {
            case MarioState.RECEIVING:
                if (Input.GetKeyDown(KeyCode.UpArrow))
                {
                    state = MarioState.AT_FLOOR_2_ARMS_DOWN;
                    audioSource.PlayOneShot(movementAudio);
                }
                break;

            case MarioState.AT_FLOOR_2_ARMS_DOWN:
                if (Input.GetKeyDown(KeyCode.UpArrow))
                {
                    state = MarioState.AT_FLOOR_3_ARMS_DOWN;
                    audioSource.PlayOneShot(movementAudio);
                }
                else if (Input.GetKeyDown(KeyCode.DownArrow))
                {
                    state = MarioState.RECEIVING;
                    audioSource.PlayOneShot(movementAudio);
                }
                break;

            case MarioState.AT_FLOOR_3_ARMS_DOWN:
                if (Input.GetKeyDown(KeyCode.DownArrow))
                {
                    state = MarioState.AT_FLOOR_2_ARMS_DOWN;
                    audioSource.PlayOneShot(movementAudio);
                }
                break;
            }
        }
Example #4
0
        public static LevelUtility.SpriteSet SwitchLevel(LevelUtility.SpriteSet spriteSet, int setNum, String currentFilename)
        {
            MarioState temp = spriteSet.players[0].GetState();

            if (setNum == 0)
            {
                firstSet        = new LevelUtility.SpriteSet(0);
                onePositionDict = new Dictionary <string, List <Vector2> >();
                LevelUtility.InitializePositionKey(onePositionDict);
            }
            else
            {
                secondSet       = new LevelUtility.SpriteSet(1);
                twoPositionDict = new Dictionary <string, List <Vector2> >();
                LevelUtility.InitializePositionKey(twoPositionDict);
            }

            if (filenames[setNum] == currentFilename)
            {
                marioStartLocation.Y -= AdjustMarioStart(temp);
                camera = new CameraController(game, new Vector2(marioStartLocation.X - 20, 0), screenHeight, screenWidth);
            }

            spriteSet = LoadLevel(currentFilename, new Vector2(marioStartLocation.X - 20, 0), setNum, spriteSet);
            ResumeLastState(temp, spriteSet);

            filenames[setNum] = currentFilename;
            return(spriteSet);
        }
Example #5
0
 /// <summary>
 /// Run
 /// </summary>
 void Run()
 {
     //DRight = (Input.GetKey(keyForward) ? 1.0f : 0) - (Input.GetKey(keyBack) ? 1.0f : 0);
     if (DRight > 0)
     {
         if (!isFaceRight)
         {
             Reverse();
             isFaceRight = true;
         }
         rb.AddForce(Vector2.right * runSpeed * Time.deltaTime);
     }
     else if (DRight < 0)
     {
         if (isFaceRight)
         {
             Reverse();
             isFaceRight = false;
         }
         rb.AddForce(Vector2.left * runSpeed * Time.deltaTime);
     }
     if (DRight == 0)
     {
         state = MarioState.idle;
     }
     if (DRight != 0 && isGroung)
     {
         state = MarioState.run;
     }
 }
Example #6
0
        private void DrawOn2DControl(int numQSteps)
        {
            if (!_lockPositions)
            {
                _marioState = MarioState.CreateMarioState();
            }
            MarioState marioStateCenter   = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Center, numQSteps);
            MarioState marioStateForward  = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Forward, numQSteps);
            MarioState marioStateBackward = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Backward, numQSteps);
            MarioState marioStateLeft     = AirMovementCalculator.ApplyInputRepeatedly(_marioState, RelativeDirection.Left, numQSteps);

            ushort marioAngle = _marioState.MarioAngle;

            (float cx, float cz) = (marioStateCenter.X, marioStateCenter.Z);
            (float fx, float fz) = (marioStateForward.X, marioStateForward.Z);
            (float bx, float bz) = (marioStateBackward.X, marioStateBackward.Z);
            (float lx, float lz) = (marioStateLeft.X, marioStateLeft.Z);

            double sideDist     = MoreMath.GetDistanceBetween(cx, cz, lx, lz);
            double forwardDist  = MoreMath.GetDistanceBetween(cx, cz, fx, fz);
            double backwardDist = MoreMath.GetDistanceBetween(cx, cz, bx, bz);

            (float controlCenterX, float controlCenterZ) = MapUtilities.ConvertCoordsForControlTopDownView(cx, cz, UseRelativeCoordinates);
            List <(float pointX, float pointZ)> controlPoints = Enumerable.Range(0, MapConfig.MapCircleNumPoints2D).ToList()
                                                                .ConvertAll(index => (index / (float)MapConfig.MapCircleNumPoints2D) * 65536)
                                                                .ConvertAll(angle => GetEllipsePoint(cx, cz, sideDist, forwardDist, backwardDist, marioAngle, angle))
                                                                .ConvertAll(point => MapUtilities.ConvertCoordsForControlTopDownView((float)point.x, (float)point.z, UseRelativeCoordinates));

            GL.BindTexture(TextureTarget.Texture2D, -1);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            // Draw circle
            GL.Color4(Color.R, Color.G, Color.B, OpacityByte);
            GL.Begin(PrimitiveType.TriangleFan);
            GL.Vertex2(controlCenterX, controlCenterZ);
            foreach ((float x, float z) in controlPoints)
            {
                GL.Vertex2(x, z);
            }
            GL.Vertex2(controlPoints[0].pointX, controlPoints[0].pointZ);
            GL.End();

            // Draw outline
            if (LineWidth != 0)
            {
                GL.Color4(LineColor.R, LineColor.G, LineColor.B, (byte)255);
                GL.LineWidth(LineWidth);
                GL.Begin(PrimitiveType.LineLoop);
                foreach ((float x, float z) in controlPoints)
                {
                    GL.Vertex2(x, z);
                }
                GL.End();
            }

            GL.Color4(1, 1, 1, 1.0f);
        }
        public void SetFireState()
        {
            canGrow       = false;
            marioState    = MarioState.Fire;
            currentSprite = fireStates[marioMovement];

            //Play transition
            stateTransitionTimeRemaining = firePowerupTransitionLength;
        }
 // Use this for initialization
 void Awake()
 {
     instance           = this;
     pointsDisplay.text = GameData.points.ToString();
     spriteRenderer     = GetComponent <SpriteRenderer>();
     animator           = GetComponent <Animator>();
     boxCollider        = GetComponent <BoxCollider2D>();
     marioState         = MarioState.SMALL;
 }
Example #9
0
        public static int AdjustMarioStart(MarioState state)
        {
            int adjust = 0;

            if (state == MarioState.LARGE || state == MarioState.FIRE)
            {
                adjust = 32;
            }
            return(adjust);
        }
 public void restart_course()
 {
     death_counter       = -1;
     damage_time_counter = -1;
     mario_object.setDead(false);
     mario_state = MarioState.SMALL;
     lives--;
     SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
     mario_object.Start();
 }
Example #11
0
        // The constructor takes the sprite sheet to use and the initial location
        public Mario(Texture2D spriteSheet, Vector2 marioLoc, MarioState startingState)
        {
            this.spriteSheet = spriteSheet;
            this.marioLoc    = marioLoc;
            this.state       = startingState;

            // Initialize
            fps          = 10.0;            // Will cycle through 10 walk frames per second
            timePerFrame = 1.0 / fps;       // Time per frame = amount of time in a single walk image
        }
Example #12
0
 /// <summary>
 /// 跳跃
 /// </summary>
 public void Jump()
 {
     if (isGroung && mobileJump)
     {
         mobileJump = false;
         rb.AddForce(Vector2.up * height);
         AudioManager.audioManager.PlayerVoice("Jump");
         state = MarioState.jump;
     }
 }
Example #13
0
        public void SwitchToFireMario(bool animate)
        {
            if (marioState.Equals(MarioState.LARGE))
            {
                SoundManager.PlaySound(Game1.marioPowerUpSound);
            }
            state.SwitchToFireMario(animate);


            marioState = MarioState.FIRE;
        }
Example #14
0
    //Increases the cureent MarioState
    public void IncreaseMarioState()
    {
        if (currentMarioState != MarioState.FIRE)
        {
            sfxManager.PlaySound(9);
            StartCoroutine(playerMovement.TempFreezeMovement(1f));
            currentMarioState += 1;
            anim.SetInteger("playerState", (int)currentMarioState);
        }

        UpdateMarioCollider();
    }
Example #15
0
 public void SwitchToBigMario(bool animate)
 {
     if (marioState.Equals(MarioState.SMALL))
     {
         if (animate)
         {
             SoundManager.PlaySound(Game1.marioPowerUpSound);
             //state.SwitchToBigMario();
         }
         state.SwitchToBigMario(animate);
     }
     marioState = MarioState.LARGE;
 }
Example #16
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Sets up the mario location
            marioLoc = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);

            // Initialize
            fps          = 10.0;
            timePerFrame = 1.0 / fps;

            state = MarioState.FaceRight;

            base.Initialize();
        }
Example #17
0
    /// <summary>
    /// 碰到敌人
    /// </summary>
    public void CollisionEnemy()
    {
        SmallJump();
        if (!isBig)
        {
            state = MarioState.deth;
            AudioManager.audioManager.PlayerVoice("Deth");
        }

        if (isBig)
        {
            ChangeSmall();
        }
    }
Example #18
0
        public void GetKilled()
        {
            isDying = true;
            state.BeKilled();
            Game1.mainBGMInstance.Pause();
            SoundManager.PauseTime = 3;
            SoundManager.PlaySound(Game1.marioDieSound);
            SoundManager.SoundLock1 = true;
            marioState = MarioState.DEAD;

            SetVerticalVelocity(-5);
            deathCoords     = location;
            enemyMultiplier = 1;
        }
Example #19
0
 public void ResetState()
 {
     if (state == MarioState.AT_FLOOR_1)
     {
         state = MarioState.RECEIVING;
     }
     else if (state == MarioState.AT_FLOOR_2_ARMS_UP)
     {
         state = MarioState.AT_FLOOR_2_ARMS_DOWN;
     }
     else if (state == MarioState.AT_FLOOR_3_ARMS_UP)
     {
         state = MarioState.AT_FLOOR_3_ARMS_DOWN;
     }
 }
Example #20
0
        public Mario(Vector2 initLocation, SoundManager sm)
        {
            location            = initLocation;
            state               = new RightIdleSmallMarioState(this);
            marioSprite         = new RightIdleSmallMario();
            marioState          = MarioState.SMALL;
            powerupManager      = new MarioPowerupChangeManager();
            largeToFireManager  = new MarioLargeToFireAnimationManager();
            endLevelManager     = new MarioEndOfLevelAnimationManager();
            takingDamageManager = new MarioTakingDamageAnimationManager();
            velo     = 0;
            this.sm  = sm;
            numLives = 3;

            marioMovMnger = new MarioMovingManager(this);
        }
Example #21
0
        public static LevelUtility.SpriteSet LoadLevel(String filename, Vector2 cameraStart, int setNum, LevelUtility.SpriteSet spriteSet)
        {
            if (setNum == 0)
            {
                positionDict = onePositionDict;
            }
            else
            {
                positionDict = twoPositionDict;
            }

            CSVReader     csvReader = new CSVReader();
            List <string> csvLines  = csvReader.getLines(filename);

            CSVParser levelParser = new CSVParser();

            camera = new CameraController(game, cameraStart, screenHeight, screenWidth);

            spriteSet = SwitchSpriteSet(setNum);

            levelParser.parse(positionDict, csvLines, screenHeight, screenWidth);

            int levelHeight = csvLines.Count();
            int levelWidth  = csvLines[0].Count();

            int worldHeight = screenHeight;
            int worldWidth  = levelWidth;

            if (spriteSet.players.Count > 0)
            {
                lastState = spriteSet.players[0].GetState();
                lives     = spriteSet.players[0].GetLives();
            }

            spriteSet.players = new List <IPlayer>();

            SpriteGenerator spriteGenerator = new SpriteGenerator();

            foreach (KeyValuePair <string, List <Vector2> > pair in positionDict)
            {
                spriteGenerator.generateSprites(pair.Key, pair.Value, spriteSet.players, spriteSet.blocks, spriteSet.pipes, spriteSet.goombas, spriteSet.koopas, spriteSet.coins, spriteSet.items, spriteSet.objects);
            }

            ResumeLastState(lastState, spriteSet);

            return(spriteSet);
        }
Example #22
0
 public static void ResumeLastState(MarioState lastState, LevelUtility.SpriteSet spriteSet)
 {
     if (lastState == MarioState.SMALL)
     {
         spriteSet.players[0].SwitchToSmallMario(false);
         spriteSet.players[0].ManualMoveY(-16);
     }
     else if (lastState == MarioState.LARGE)
     {
         spriteSet.players[0].SwitchToBigMario(false);
         //players[0].ManualMoveY(32);
     }
     else if (lastState == MarioState.FIRE)
     {
         spriteSet.players[0].SwitchToFireMario(false);
     }
 }
Example #23
0
    private void ShowSprite(MarioState state)
    {
        HideAllSprite();
        switch (state)
        {
        case MarioState.Idle:
            spriteIdle.enabled = true;
            break;

        case MarioState.Run:
            spriteRun.enabled = true;
            break;

        case MarioState.Jump:
            spriteJump.enabled = true;
            break;
        }
    }
 public void Reset()
 {
     canGrow          = true;
     starPower        = false;
     isJumping        = false;
     flagpoleSequence = false;
     flagpoleColPos   = new Vector2();
     flagpoleSlide    = new Vector2();
     finishSequence   = false;
     flagpoleCount    = 0;
     marioState       = MarioState.Small;
     marioMovement    = MarioMovement.IdleRight;
     currentSprite    = smallStates[marioMovement];
     SwitchCurrentSprite(marioMovement);
     stateTransitionTimeRemaining = ZERO;
     warpTimeRemaining            = ZERO;
     blinkTimeRemaining           = ZERO;
 }
Example #25
0
 public void UpdateState()
 {
     if (state == MarioState.RECEIVING)
     {
         state = MarioState.AT_FLOOR_1;
         audioSource.PlayOneShot(passBoxAudio);
     }
     else if (state == MarioState.AT_FLOOR_2_ARMS_DOWN)
     {
         state = MarioState.AT_FLOOR_2_ARMS_UP;
         audioSource.PlayOneShot(passBoxAudio);
     }
     else if (state == MarioState.AT_FLOOR_3_ARMS_DOWN)
     {
         state = MarioState.AT_FLOOR_3_ARMS_UP;
         audioSource.PlayOneShot(passBoxAudio);
     }
 }
Example #26
0
        public IItem ReleaseItem(MarioState state)
        {
            if (HasItem())
            {
                if (item.GetType() == typeof(PowerUpPlaceholder))
                {
                    Rectangle loc = item.GetRectangle();
                    switch (state)
                    {
                    case MarioState.SMALL:
                        return(new RedMushroom(new Vector2(loc.X, loc.Y)));

                    case MarioState.LARGE:
                        return(new FireFlower(new Vector2(loc.X, loc.Y)));

                    case MarioState.FIRE:
                        return(new Star(new Vector2(loc.X, loc.Y)));

                    default:
                        return(null);
                    }
                }
                else if (item.GetType() == typeof(BlockCoin))
                {
                    Display.UpdateNumCoins();
                    return(item);
                }
                else if (item.GetType() == typeof(MultiCoin))
                {
                    Display.UpdateNumCoins();
                    timer += (float)lastUpdate.ElapsedGameTime.Seconds;
                    hitCount++;
                    return(new MultiCoin(new Vector2(location.X, location.Y - 16)));
                }
                else
                {
                    return(item);
                }
            }
            else
            {
                return(null);
            }
        }
        public void Shrink()
        {
            canGrow = true;

            if (marioState == MarioState.Small)
            {
                mario.Die();
            }
            else
            {
                //If facing left, set movement to be transition left.
                marioMovement = (MarioFacingLeft()) ? MarioMovement.ShrinkLeft : MarioMovement.ShrinkRight;
                marioState    = MarioState.Small;
                SoundEffectFactory.Instance.PlayPipeSound();
                UpdateSprite();
                blinkTimeRemaining           = blinkLength;
                stateTransitionTimeRemaining = (marioState == MarioState.Big) ? firePowerupTransitionLength : currentSprite.ClipLength;
            }
        }
Example #28
0
    //Decreases the cureent MarioState
    public void DecreaseMarioState()
    {
        if (currentMarioState != MarioState.SMALL)
        {
            sfxManager.PlaySound(13);
            StartCoroutine(playerMovement.TempFreezeMovement(1f));
            currentMarioState -= 1;
            anim.SetInteger("playerState", (int)currentMarioState);
        }
        else
        {
            //Lives Manager . Lose Life
            Debug.Log("LOSE");
            anim.SetTrigger("playerDie");
            bgmManager.PlaySound(4);
            livesManager.LoseLife();
        }

        UpdateMarioCollider();
    }
        public void SetState(MarioState marioState)
        {
            switch (marioState)
            {
            case MarioState.small:
                playerState = SmallMS;
                break;

            case MarioState.big:
                playerState = BigMS;
                break;

            case MarioState.raccoon:
                playerState = RaccoonMS;
                break;

            case MarioState.fire:
                playerState = FireMS;
                break;
            }
        }
        public void Grow()
        {
            if (canGrow)
            {
                marioState = MarioState.Big;
                //If facing left, set movement to be transition left.
                marioMovement = (MarioFacingLeft()) ? MarioMovement.GrowLeft : MarioMovement.GrowRight;
                ISprite oldSprite = currentSprite;
                UpdateSprite();

                //Move us up since small sprite is smaller than big sprite
                if (oldSprite != null && currentSprite != null)
                {
                    mario.ForceMove(0, -Math.Abs(currentSprite.Height - oldSprite.Height));
                }

                //Play growing transition
                stateTransitionTimeRemaining = currentSprite.ClipLength;
            }
            canGrow = false;
        }