コード例 #1
0
ファイル: Goomba.cs プロジェクト: MaxPlay/Lemmings
        /// <summary>
        /// Updates the goomba, parsing the user input and updating the animations
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Update(GameTime gameTime)
        {
            Vector2 speed = new Vector2();

            position += speed;

            //parse animations
            if (speed.Length() == 0)
            {
                state = GoombaState.Idle;
            }
            else
            {
                if (Math.Abs(speed.X) > Math.Abs(speed.Y))
                {
                    state = speed.X > 0 ? GoombaState.WalkRight : GoombaState.WalkLeft;
                }
                else
                {
                    state = speed.Y > 0 ? GoombaState.WalkDown : GoombaState.WalkUp;
                }
            }

            //update animations with running in mind
            animations[state].Update(gameTime, 1);
            //Debug.Log("{0} {1}", state, animations[state].CurrentFrame); //Debug the frames
        }
コード例 #2
0
ファイル: Goomba.cs プロジェクト: SidneK/Mario
    private void Update()
    {
        if (isActive)
        {
            State = GoombaState.Moving;

            if (!isDead)
            {
                rb.velocity = direction * speed;
                State       = GoombaState.Moving;
            }
            else
            {
                State = GoombaState.Stomp;
            }
        }
        else
        {
            if (Logic.Instance.Player == null)
            {
                Logic.Instance.Player = GameObject.FindGameObjectWithTag("Player");
            }
            else
            if (transform.position.x - Logic.Instance.Player.transform.position.x <= necessary_distance_for_activation)
            {
                isActive = true;
            }
        }
    }
コード例 #3
0
ファイル: Goomba.cs プロジェクト: MaxPlay/Lemmings
        private void LoadAnimations()
        {
            if (!File.Exists("Content/" + name + ".txt"))
            {
                return;
            }

            string[] lines = File.ReadAllLines("Content/" + name + ".txt"); //Read the textfile for the animations

            //parse every line
            for (int i = 0; i < lines.Length; i++)
            {
                string[] data = lines[i].Split(' ');

                //every line needs at least 2 arguments
                if (data.Length < 2)
                {
                    continue;
                }

                GoombaState state  = (GoombaState)Enum.Parse(typeof(GoombaState), data[0]);
                int         length = int.Parse(data[1]);

                //parse the optional looping for animations
                bool loopable = false;
                if (data.Length > 2)
                {
                    loopable = ("loop" == data[2]);
                }

                //parse the optional speed for animations
                float speed = 1;
                if (data.Length > 3)
                {
                    speed = float.Parse(data[3], System.Globalization.CultureInfo.InvariantCulture);
                }

                //create the animation and fill it with frames
                SpriteAnimation animation = new SpriteAnimation(loopable, speed);
                for (int j = i * frameCount.X; j < i * frameCount.X + length; j++)
                {
                    animation.AddFrame(j);
                }

                animations.Add(state, animation); //add the animation to the hashmap
            }
        }