コード例 #1
0
ファイル: Player.cs プロジェクト: chadng/PokemonSmash
        internal void Update(float dt)
        {
            if (Dead)
            {
                if (anim.state.Animation.Name != "dead")
                {
                    anim.state.SetAnimation("dead", false);
                }
                this.HP = 0;
                body.ApplyForce(new Vec2(-body.GetLinearVelocity().X, 0), new Vec2(.1f, .1f));
                return;
            }

            if (Asleep)
            {
                if (anim.state.Animation.Name != "dead")
                {
                    anim.state.SetAnimation("dead", false);
                }
                body.ApplyForce(new Vec2(-body.GetLinearVelocity().X, 0), new Vec2(.1f, .1f));
                return;
            }

            DisableTime -= dt;
            float MoveSpeed = (float)System.Math.Sqrt(Speed + 50);

            if (Pokemon.Hovers)
            {
                body.ApplyForce(-body.GetWorld().Gravity *Pokemon.Weight);
            }
            if (Pokemon.Hovers && !Disabled)
            {
                Vec2 Desire = new Vec2();
                if (Controls.IsDown(Control.Left))
                {
                    Desire.X -= 1;
                    Direction = -1;
                }

                if (Controls.IsDown(Control.Right))
                {
                    Desire.X += 1;
                    Direction = 1;
                }

                if (Controls.IsDown(Control.Up))
                {
                    Desire.Y += 1;
                }

                if (Controls.IsDown(Control.Down))
                {
                    Desire.Y -= 1;
                }

                var speed = body.GetLinearVelocity();

                if (Desire.X == 0 && Desire.Y == 0)
                {
                    body.ApplyForce(-speed * 0.4f);
                }
                else
                {
                    body.ApplyForce((Desire * MoveSpeed) - speed);
                }
            }

            if (!Pokemon.Hovers)
            {
                float FrictionModifier = (OnGround || Pokemon.CanFly) ? 1 : 0.5f;
                if (Controls.IsDown(Control.Left) && !Disabled)
                {
                    if (anim.state.Animation.Name != "walk")
                    {
                        anim.state.SetAnimation("walk", true);
                    }
                    //body.SetLinearVelocity(new Vec2(vel.X * 1.1f, vel.Y));
                    body.ApplyForce(new Vec2(-(MoveSpeed * FrictionModifier) - (body.GetLinearVelocity().X * 2), 0));
                    Direction = -1;
                }
                else if (Controls.IsDown(Control.Right) && !Disabled)
                {
                    if (anim.state.Animation.Name != "walk")
                    {
                        anim.state.SetAnimation("walk", true);
                    }
                    //body.SetLinearVelocity(new Vec2(vel.X * 0.9f, vel.Y));
                    body.ApplyForce(new Vec2((MoveSpeed * FrictionModifier) - (body.GetLinearVelocity().X * 2), 0));
                    Direction = 1;
                }
                else if (OnGround)
                {
                    if (!Disabled)
                    {
                        if (anim.state.Animation.Name != "idle")
                        {
                            anim.state.SetAnimation("idle", true);
                        }
                    }

                    body.ApplyForce(new Vec2(-body.GetLinearVelocity().X *MoveSpeed * 3, 0), new Vec2(.1f, .1f));
                }

                if (Controls.IsPressed(Control.Jump) && !Disabled && Pokemon.CanJump && (OnGround || Pokemon.CanFly))
                {
                    if (anim.state.Animation.Name != "jump")
                    {
                        anim.state.SetAnimation("jump", false);
                    }
                    Vec2 Vel = body.GetLinearVelocity();
                    if (OnGround)
                    {
                        body.ApplyImpulse(new Vec2(Vel.X, 3 * MoveSpeed));
                    }
                    else
                    {
                        body.ApplyImpulse(new Vec2(Vel.X, MoveSpeed));
                    }
                }
            }


            if (!Disabled)
            {
                if (Controls.IsPressed(Control.Move0))
                {
                    CurrentMove = 0;
                    Move[0].OnUse(this);
                }

                if (Controls.IsPressed(Control.Move1))
                {
                    CurrentMove = 1;
                    Move[1].OnUse(this);
                }

                if (Controls.IsPressed(Control.Move2))
                {
                    CurrentMove = 2;
                    Move[2].OnUse(this);
                }

                if (Controls.IsPressed(Control.Move3))
                {
                    CurrentMove = 3;
                    Move[3].OnUse(this);
                }
            }

            foreach (StatusEffect effect in Effects)
            {
                effect.Update(this, dt);
            }
        }
コード例 #2
0
        internal void Update(float dt)
        {
            if (Dead)
            {
                if (anim.state.Animation.Name != "dead")
                {
                    anim.state.SetAnimation("dead", false);
                }
                this.HP = 0;
                body.ApplyForce(new Vec2(-body.GetLinearVelocity().X, 0), new Vec2(.1f, .1f));
                return;
            }

            DisableTime -= dt;

            if (OnGround)
            {
                if (Controls.IsDown(Control.Left) && !Disabled)
                {
                    if (anim.state.Animation.Name != "walk")
                    {
                        anim.state.SetAnimation("walk", true);
                    }
                    body.ApplyForce(new Vec2(-(Speed / 10) - body.GetLinearVelocity().X, 0), new Vec2(.1f, .1f));
                    Direction = -1;
                }
                else if (Controls.IsDown(Control.Right) && !Disabled)
                {
                    if (anim.state.Animation.Name != "walk")
                    {
                        anim.state.SetAnimation("walk", true);
                    }
                    body.ApplyForce(new Vec2((Speed / 10) - body.GetLinearVelocity().X, 0), new Vec2(.1f, .1f));
                    Direction = 1;
                }
                else
                {
                    if (anim.state.Animation.Name != "idle")
                    {
                        anim.state.SetAnimation("idle", true);
                    }
                    body.ApplyForce(new Vec2(-body.GetLinearVelocity().X *(Speed), 0), new Vec2(.1f, .1f));
                }

                if (Controls.IsPressed(Control.Jump) && !Disabled)
                {
                    if (anim.state.Animation.Name != "jump")
                    {
                        anim.state.SetAnimation("jump", false);
                    }
                    Vec2 Vel = body.GetLinearVelocity();
                    body.ApplyForce(new Vec2(Vel.X, Speed * 5), new Vec2(.1f, .1f));
                }
            }


            if (!Disabled)
            {
                if (Controls.IsPressed(Control.Move0))
                {
                    CurrentMove = 0;
                    Move[0].OnUse(this);
                }

                if (Controls.IsPressed(Control.Move1))
                {
                    CurrentMove = 1;
                    Move[1].OnUse(this);
                }

                if (Controls.IsPressed(Control.Move2))
                {
                    CurrentMove = 2;
                    Move[2].OnUse(this);
                }

                if (Controls.IsPressed(Control.Move3))
                {
                    CurrentMove = 3;
                    Move[3].OnUse(this);
                }
            }
        }