示例#1
0
        public override void Update(GameTime gametime)
        {
            base.Update(gametime);
            anima.Update(gametime);
            renderer.animNum = anima.currentFrameNumber;
            o_platformControler contact = null;

            switch (TYPEOFBLOCK)
            {
            case BLOCK_TYPE.DOOR:
                if (flag == "0")
                {
                    renderer.animNum = 1;
                    if (IntersectBox <o_plcharacter>(new Vector2(0, 0)) != null)
                    {
                        Game1.game.IncrementLevel();
                    }
                }
                else
                {
                    renderer.animNum = 0;
                }
                break;

            case BLOCK_TYPE.PORTAL:
                anima.SetAnimation("portal", true);
                contact = IntersectBox <o_platformControler>(new Vector2(0, 0));
                if (contact != null)
                {
                    if (doorDelay <= 0)
                    {
                        o_block f = Game1.FindCharacter <o_block>(flag);
                        contact.position = f.position;
                        f.velocity       = Vector2.Zero;
                        Game1.PlaySound(11);
                        f.doorDelay = 1.2f;
                        doorDelay   = 1.2f;
                    }
                }
                else
                {
                    if (doorDelay > 0)
                    {
                        doorDelay -= Game1.deltaTime;
                    }
                }
                if (doorDelay <= 0)
                {
                    renderer.colour = new Color(1, 1, 1, 1f);
                }
                else
                {
                    renderer.colour = new Color(1, 1, 1, 0.5f);
                }
                break;

            case BLOCK_TYPE.SWITCH_DOOR:

                if (flag == "0")
                {
                    Game1.game.ChangeTile(position, 0);
                    Game1.RemoveObject(this);
                }
                break;

            case BLOCK_TYPE.BOMBER:

                if (bomb_timer <= 0)
                {
                    if (bomb_ItemToFocusOn == null)
                    {
                        o_item it = Game1.AddObject <o_item>(position + new Vector2(0, 20), "bomb", Game1.textures["bomb"].Item2, Game1.textures["bomb"].Item1);
                        if (it != null)
                        {
                            it.itType          = o_item.ITEM_TY.Bomb;
                            it.iscatchable     = false;
                            it.velocityLimiter = 0.97f;
                            it.Throw(direction);
                            it.bombTimer          = 2.5f;
                            it.collisionOffset    = new Vector2(6, 0);
                            it.collisionBox.Width = 12;
                            bomb_ItemToFocusOn    = it;
                            it.parent             = this;
                            bomb_timer            = max_bomb_timer;
                        }
                    }
                }
                else
                if (bomb_ItemToFocusOn == null)
                {
                    bomb_timer -= Game1.deltaTime;
                }
                break;
            }
        }
示例#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);
        }
        public override void Update(GameTime gametime)
        {
            if (CheckPoint(new Vector2(0, 0)))
            {
                if (catchDel < 0)
                {
                    Game1.RemoveObject(this);
                }
            }

            o_block block = null;

            block = IntersectBox <o_block>(new Vector2(0, 0));

            if (block != null)
            {
                switch (block.TYPEOFBLOCK)
                {
                case o_block.BLOCK_TYPE.SWITCH:

                    block.ButtonChange();
                    Game1.RemoveObject(this);
                    break;

                case o_block.BLOCK_TYPE.SPIKES:

                    if (itType != ITEM_TY.Bomb)
                    {
                        position = spawnpoint;
                        velocity = Vector2.Zero;
                    }
                    else
                    {
                        bombTimer = 0;
                    }
                    break;
                }
            }

            if (itType == ITEM_TY.Bomb)
            {
                switch (fs)
                {
                case FUSE_STATE.THROWN:
                    if (parent == null)
                    {
                        bombTimer -= (float)gametime.ElapsedGameTime.TotalSeconds;
                        if (bombTimer <= 0)
                        {
                            isKenematic       = false;
                            collisionBox.Size = (new Vector2(20, 20) * 2f).ToPoint();
                            position          = new Vector2(collisionBox.Location.X + 10, collisionBox.Location.Y - 10);
                            ForceCollisionBoxUpdate();
                            bombTimer = 0.5f;
                            fs        = FUSE_STATE.BLOWING_UP;
                        }
                    }
                    else
                    {
                        o_plcharacter play = IntersectBox <o_plcharacter>(new Vector2(0, 0));
                        if (play != null)
                        {
                            if (parent != null)
                            {
                                parent.bomb_ItemToFocusOn = null;
                            }
                            TPPlayer(ref play);
                            return;
                        }
                    }
                    break;

                case FUSE_STATE.BLOWING_UP:

                    bombTimer -= (float)gametime.ElapsedGameTime.TotalSeconds;
                    if (bombTimer >= 0)
                    {
                        Destroy();
                    }
                    else
                    {
                        Game1.PlaySound(7, position);
                        if (parent != null)
                        {
                            parent.bomb_ItemToFocusOn = null;
                        }
                        else
                        {
                            o_item it = Game1.AddObject <o_item>(spawnpoint, "bomb", Game1.textures["bomb"].Item2, Game1.textures["bomb"].Item1);
                            if (it != null)
                            {
                                it.itType     = o_item.ITEM_TY.Bomb;
                                it.spawnpoint = spawnpoint;
                            }
                        }

                        Game1.RemoveObject(this);
                    }
                    break;
                }
            }

            //timer -= (float)gametime.ElapsedGameTime.TotalSeconds;
            if (catchDel > 0)
            {
                catchDel -= (float)gametime.ElapsedGameTime.TotalSeconds;
            }

            o_plcharacter pl = CheckPointEnt <o_plcharacter>(new Vector2(10, 10));

            if (pl != null)
            {
                if (catchDel <= 0 && iscatchable)
                {
                    pl.heldItem  = itType;
                    pl.itemSpawn = spawnpoint;
                    Game1.RemoveObject(this);
                }
            }

            /*
             * if (timer < 0)
             *  Game1.RemoveObject(this);
             *
             * o_movableSolid item = IntersectBox<o_movableSolid>(new Vector2(0, 0));
             * if (item != null)
             * {
             *  item.velocity.X += velocity.X / 10;
             *  velocity = Vector2.Zero;
             * }
             */


            base.Update(gametime);
        }