Example #1
0
        public void Update(GameTime gameTime, TileMap map, ContentManager Content2)
        {
            Content = Content2;
            m_vibrate -= gameTime.ElapsedGameTime.TotalSeconds;
            if (m_vibrate < 0)
                GamePad.SetVibration(m_index, 0, 0);
            m_rect.X = m_pos.X;
            m_rect.Y = m_pos.Y;
            int ladder_x = 0, ladder_y = 0;

            bool onLadder = map.OnLadder(this, out ladder_x, out ladder_y);

            this.m_dir.X = GamePad.GetState(m_index).ThumbSticks.Left.X;
            if (Keyboard.GetState().IsKeyDown(m_controls[0]))
            {
                m_dir.X = -1;
            }
            else if (Keyboard.GetState().IsKeyDown(m_controls[1]))
            {
                m_dir.X = 1;
            }
            if (onLadder)
            {
                this.m_dir.Y = -GamePad.GetState(m_index).ThumbSticks.Left.Y;
                if (Keyboard.GetState().IsKeyDown(m_controls[2]))
                {
                    m_dir.Y = -1;
                }
                else if (Keyboard.GetState().IsKeyDown(m_controls[3]))
                {
                    m_dir.Y = 1;
                }
                if (Math.Abs(m_dir.Y) > Math.Abs(m_dir.X))
                    m_pos.X = (float)ladder_x;
            }
            else
                m_dir.Y = 0;
            if (m_dir.LengthSquared() > 0)
                m_dir.Normalize();

            // stuck wall hack
            bool unstuck = false;
            if (!onLadder)
            {
                float grav = m_gravity.Y * (float)(gameTime.ElapsedGameTime.TotalSeconds);
                m_vec = m_gravity * (float)(gameTime.ElapsedGameTime.TotalSeconds);
                m_vec = map.Collide(this);
                if (m_vec.Y == grav)
                    unstuck = true;
            }
            if(!unstuck && m_atype != Animation.AnimationType.SHOOTING)
                m_vec.X = m_dir.X * (float)(m_xspeed * gameTime.ElapsedGameTime.TotalSeconds);
            m_vec.Y = m_dir.Y * (float)(m_yspeed * gameTime.ElapsedGameTime.TotalSeconds);
            if (!onLadder)
            {
                m_vec += m_gravity * (float)(gameTime.ElapsedGameTime.TotalSeconds);
            }
            else
            {
                if (Math.Abs(m_vec.Y) < 0.20f) m_atype = Animation.AnimationType.IDLING;
                else m_atype = Animation.AnimationType.CLIMBING;
            }
            m_vec = map.Collide(this);

            m_pos.X += m_vec.X;
            m_pos.Y += m_vec.Y;

            if (onLadder && Math.Abs(m_dir.Y) > Math.Abs(m_dir.X))
            {
                m_rect.X = m_pos.X;
                m_rect.Y = m_pos.Y;
                int dummyx, dummyy;
                if (!map.OnLadder(this, out dummyx, out dummyy))
                {
                    m_pos.Y = ladder_y - m_rect.Height;
                }
            }

            if (m_vec.X > 0)
            {
                m_bulletDir.X = 2.0f;
                flipped = false;
            }
            else if (m_vec.X < 0)
            {
                m_bulletDir.X = -2.0f;
                flipped = true;
            }

            if (m_atype != Animation.AnimationType.SHOOTING && m_atype != Animation.AnimationType.DYING)
            {
                if (Math.Abs(m_vec.X) > 0.20f && Math.Abs(m_vec.Y) < 0.20f)
                {
                    m_atype = Animation.AnimationType.RUNNING;
                }
                if (Math.Abs(m_vec.Y) > 0.20f && Math.Abs(m_vec.X) < 0.20f && onLadder == true)
                {
                    m_atype = Animation.AnimationType.CLIMBING;
                }
                if (Math.Abs(m_vec.X) < 0.20f && !onLadder)
                {
                    m_atype = Animation.AnimationType.IDLING;
                }
            }

            // go back to idle animation after SHOOTING animation is done
            if (m_atype == Animation.AnimationType.SHOOTING && m_sprite.IsCurrentAnimationDone() == true)
            {
                m_atype = Animation.AnimationType.IDLING;
            }

            // go back to idle animation after SPAWNING animation is done
            if (m_atype == Animation.AnimationType.SPAWNING && m_sprite.IsCurrentAnimationDone() == true)
            {
                m_atype = Animation.AnimationType.IDLING;
            }

            if (dyingAnimationIsDone)
            {
                dyingAnimationIsDone = false;
                Respawn();
            }

            // if dying animation completed, respawn
            if (m_atype == Animation.AnimationType.DYING && m_sprite.IsCurrentAnimationDone() == true)
            {
                dyingAnimationIsDone = true;
            }

            m_sprite.Update(gameTime, m_pos + new Vector2(8, 0), Content2);
            //m_sprite.PlayAnimation(Animation.AnimationType.RUNNING); // start in "idling animation" state

            // bullets!
            m_bulletWait -= gameTime.ElapsedGameTime.TotalSeconds;
            if (m_bulletWait < 0) m_bulletWait = 0;
            if((GamePad.GetState(m_index).Buttons.A == ButtonState.Pressed || (Keyboard.GetState().IsKeyDown(m_controls[4])))
                && m_bullets.Count() < 1 && m_bulletWait <= 0)
            {
                m_atype = Animation.AnimationType.SHOOTING;
                m_bulletWait = 0.5f;
                 m_bullets.AddLast(new Bullet(m_content,
                    new floatRectangle(m_pos.X + 8, m_pos.Y + 24, 8, 8),
                    m_bulletDir * 320.0f,
                    m_index, m_team));
            }
            LinkedList<Bullet> garbage = new LinkedList<Bullet>();
            foreach (Bullet b in m_bullets)
            {
                if (!b.IsValid())
                    garbage.AddLast(b);
                else
                    b.Update(gameTime, map);
            }
            foreach (Bullet b in garbage)
            {
                m_bullets.Remove(b);
            }

            switch (m_atype)
            {
                case Animation.AnimationType.DYING: m_sprite.PlayAnimation(Animation.AnimationType.DYING); break;
                case Animation.AnimationType.RUNNING: m_sprite.PlayAnimation(Animation.AnimationType.RUNNING); break;
                case Animation.AnimationType.CLIMBING: m_sprite.PlayAnimation(Animation.AnimationType.CLIMBING); break;
                case Animation.AnimationType.IDLING: m_sprite.PlayAnimation(Animation.AnimationType.IDLING); break;
                case Animation.AnimationType.PANTING: m_sprite.PlayAnimation(Animation.AnimationType.PANTING); break;
                case Animation.AnimationType.SHOOTING: m_sprite.PlayAnimation(Animation.AnimationType.SHOOTING); break;
                case Animation.AnimationType.SPAWNING: m_sprite.PlayAnimation(Animation.AnimationType.SPAWNING); break;
                default: break;
            }
        }
Example #2
0
 public void Respawn()
 {
     m_atype = Animation.AnimationType.IDLING;
     m_pos = m_origin[new Random().Next(4)];
     m_health = 1;
     //            soundEffect = Content.Load<SoundEffect>("damage_01");
     //            soundEffect.Play();
     //            soundEffect = Content.Load<SoundEffect>("power_up_01");
     //            soundEffect.Play();
 }
Example #3
0
 public Sprite()
 {
     SpriteTexture = new AnimatedTexture(Vector2.Zero, Rotation, Scale, Depth);
     dyingAnimationIsDone = false;
     currentAnimation = Animation.AnimationType.NONE;
 }
Example #4
0
 /// <summary>
 /// パーティクル
 /// </summary>
 /// <param name="name">アセット名</param>
 /// <param name="position">座標</param>
 /// <param name="size">大きさ</param>
 /// <param name="frame">アニメーションのフレーム数</param>
 /// <param name="time">1枚当たりのアニメーション時間</param>
 /// <param name="animationType">アニメーション方向</param>
 public Particle(string name, Vector2 position, Point size, int frame, float time, Animation.AnimationType animationType = Animation.AnimationType.Horizontal)
     : base(name, position, size)
 {
     animation = new Animation(size, frame, time, false, animationType);
     ParticleManager.Instance.Add(this);
 }
Example #5
0
        public void PlayAnimation(Animation.AnimationType animationToPlay)
        {
            // if character is dying, can't change to new animation; don't restart animation if currently playing
            if (currentAnimation != Animation.AnimationType.DYING && currentAnimation != animationToPlay)
            {
                // reset all animations to frame 0 prior to starting new animation
                foreach (Animation anim in AnimationsList)
                {
                    anim.ResetAnimation();
                }

                // trigger animation to play, by specifying enum AnimationType
                currentAnimation = animationToPlay;
                AnimationsList[(int)currentAnimation].PlayAnimation();

                switch (currentAnimation)
                {
                    case Animation.AnimationType.DYING: break;
                    case Animation.AnimationType.RUNNING: soundEffect = Content.Load<SoundEffect>("kaboom2"); break;
                    case Animation.AnimationType.CLIMBING: soundEffect = Content.Load<SoundEffect>("kaboom2"); break;
                    case Animation.AnimationType.IDLING: soundEffect = Content.Load<SoundEffect>("kaboom2"); break;
                    case Animation.AnimationType.PANTING: soundEffect = Content.Load<SoundEffect>("kaboom2"); break;
                    case Animation.AnimationType.SHOOTING: soundEffect = Content.Load<SoundEffect>("gun_shoot_02"); break;
                    case Animation.AnimationType.SPAWNING: break;
                    default: break;
                }
                soundEffect.Play();
            }
        }