示例#1
0
 public void OnBounce()
 {
     Game1.PlaySound(9, position);
     anima.SetAnimation("spring_idle", false);
     anima.SetAnimation("spring_bounce", false);
 }
示例#2
0
        public override void Update(GameTime gametime)
        {
            anima.Update(gametime);
            ushort plTile = Game1.game.GetTile(collisionBox.Center.ToVector2());

            oyxgenMetre = MathHelper.Clamp(oyxgenMetre, 0, 0.99f);

            if (!Keyboard.GetState().IsKeyDown(Keys.S))
            {
                if (fallkeyPressed)
                {
                    fallkeyPressed = false;
                }
            }

            switch (STATE)
            {
            case CHARA_STATE.MOVING:
                //isdebug = false;
                if (isgrounded)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.A) || Keyboard.GetState().IsKeyDown(Keys.D))
                    {
                        anima.SetAnimation("walk", true);
                    }
                    else
                    {
                        anima.SetAnimation("idle", false);
                    }
                }
                else
                {
                    anima.SetAnimation("jump", false);
                }

                oyxgenMetre += 0.01f;
                fallVel      = gravity;

                if (isgrounded)
                {
                    speed = speedOrigin;
                }

                if (Game1.IsSameLayer(plTile, "liquid"))
                {
                    speed = speedOrigin;
                    Game1.PlaySound(1);
                    STATE = CHARA_STATE.SWIMMING;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.D))
                {
                    renderer.spriteRotation = SpriteEffects.None;
                    velocity.X = speed;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.A))
                {
                    renderer.spriteRotation = SpriteEffects.FlipHorizontally;
                    velocity.X = -speed;
                }

                if (isdebug)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.S))
                    {
                        velocity.Y = speed;
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.W))
                    {
                        velocity.Y = -speed;
                    }
                }
                else
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.Space))
                    {
                        if (isgrounded == true)
                        {
                            anima.SetAnimation("walk", false);
                            position.Y -= 3;
                            if (Keyboard.GetState().IsKeyDown(Keys.A) || Keyboard.GetState().IsKeyDown(Keys.D))
                            {
                                Game1.PlaySound(6);
                                velocity.Y = -2.60f;
                            }
                            else
                            {
                                Game1.PlaySound(6);
                                speed      = speedOrigin / 1.4f;
                                velocity.Y = -3.31f;
                            }
                        }
                    }
                }
                break;

            case CHARA_STATE.SWIMMING:
                //isdebug = true;
                oyxgenMetre -= 0.0005f;
                velocity.Y  *= velocityLimiter;
                fallVel      = 0.04f;

                anima.SetAnimation("jump", false);
                if (Keyboard.GetState().IsKeyDown(Keys.W))
                {
                    if (Game1.IsSameLayer(plTile, "air"))
                    {
                        velocity.Y = -speed * 1.35f;
                    }
                    else
                    {
                        velocity.Y = -speed;
                    }
                }

                if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
                {
                    speed        = speedOrigin * 0.93f;
                    oyxgenMetre -= 0.0007f;
                }
                else
                {
                    speed = speedOrigin / 2.5f;
                }

                if (Game1.IsSameLayer(plTile, "air"))
                {
                    Game1.PlaySound(10, collisionBox.Location.ToVector2());
                    STATE = CHARA_STATE.MOVING;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.D))
                {
                    renderer.spriteRotation = SpriteEffects.None;
                    velocity.X = speed;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.A))
                {
                    renderer.spriteRotation = SpriteEffects.FlipHorizontally;
                    velocity.X = -speed;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.S))
                {
                    velocity.Y = speed;
                }

                if (oyxgenMetre <= 0.00)
                {
                    Game1.game.ResetLevel();
                }

                break;
            }

            o_block detectedSpike = IntersectBox <o_block>(new Vector2(0, 0), x => x.TYPEOFBLOCK == o_block.BLOCK_TYPE.SPIKES);

            if (detectedSpike != null)
            {
                position.Y = spawnpoint.Y - 1;
                position.X = spawnpoint.X;
                Game1.PlaySound(3);
                velocity = Vector2.Zero;
                Game1.game.ResetLevel();
            }
            if (throwDel > 0)
            {
                throwDel -= Game1.deltaTime;
            }

            o_item item = CheckPointEnt <o_item>(centre);

            if (item != null)
            {
                if (item.catchDel > 0)
                {
                    if (heldItem == o_item.ITEM_TY.None)
                    {
                        itemSpawn = item.spawnpoint;
                        heldItem  = item.itType;
                        Game1.RemoveObject(item);
                    }
                }
            }

            if (Game1.mousestate.LeftButton == ButtonState.Pressed)
            {
                if (heldItem != o_item.ITEM_TY.None)
                {
                    o_item it = null;
                    switch (heldItem)
                    {
                    case o_item.ITEM_TY.Bomb:
                        it = Game1.AddObject <o_item>(centre + new Vector2(-10, -15), "bomb", Game1.textures["bomb"].Item2, Game1.textures["bomb"].Item1);
                        break;

                    case o_item.ITEM_TY.Throwing:
                        it = Game1.AddObject <o_item>(centre + new Vector2(-10, -15), "Thing", Game1.textures["ball"].Item2, Game1.textures["ball"].Item1);
                        break;
                    }
                    it.catchDel = 0.2f;
                    if (it != null)
                    {
                        it.spawnpoint      = itemSpawn;
                        it.itType          = heldItem;
                        it.velocityLimiter = 0.97f;
                        it.Throw(new Vector2(throwDir.X * throwMultiplier, throwDir.Y * throwMultiplier));
                        heldItem = o_item.ITEM_TY.None;
                    }
                }
            }
            renderer.animNum = anima.currentFrameNumber;
            base.Update(gametime);
        }