Ejemplo n.º 1
0
        public List <Collectible> GetPlayerCollectibleCollisions(Vector2 playerPosition)
        {
            List <Collectible> collectibleCollisions = new List <Collectible>();

            Hitbox playerHitbox = GetPlayerHitbox(playerPosition);

            foreach (Tuple <Collectible, Hitbox> collectibleWithHitbox in collectiblesWithHitboxes)
            {
                if (playerHitbox.CollidesWith(collectibleWithHitbox.Item2))
                {
                    collectibleCollisions.Add(collectibleWithHitbox.Item1);
                }
            }

            return(collectibleCollisions);
        }
Ejemplo n.º 2
0
        public override void Update()
        {
            base.Update();

            Vector2 changePosition = Vector2.Zero;

            changePosition.Y -= velocity;
            velocity         += gravity;
            if (dashReady > 0)
            {
                dashReady--;
            }

            changePosition.X += Input.Keyboard.IsDown(Keys.Right) ? 3f : 0;
            changePosition.X += Input.Keyboard.IsDown(Keys.Left) ? -3f : 0;
            //changePosition.Y += Input.Keyboard.IsDown(Keys.Up) ? -1 : 0;
            //changePosition.Y += Input.Keyboard.IsDown(Keys.Down) ? 1 : 0;

            if (Input.Keyboard.IsPressed(Keys.Space) && jumps > 0)
            {
                jumps--;
                velocity          = 10;
                changePosition.Y -= 15;
            }

            if (Input.Keyboard.IsPressed(Keys.LeftShift) && dashReady == 0)
            {
                if (changePosition.X != 0)
                {
                    changePosition.X *= 70;
                    dashReady         = 180;
                }
            }

            bool collided = false;

            Transform.Position += changePosition;

            foreach (Entity e in this.Scene)
            {
                if (e == this)
                {
                    continue;
                }
                Hitbox h;
                if ((h = e.Get <Hitbox>()) != null)
                {
                    if (playerHitbox.CollidesWith(h))
                    {
                        if (h.GlobalRotation == 0)
                        {
                            if (e is Tile)
                            {
                                if (playerHitbox.GlobalBottom > h.GlobalTop)
                                {
                                    Transform.Position.Y = h.GlobalTop - playerHitbox.Height;
                                    jumps    = 2;
                                    velocity = 0;
                                }

                                if (playerHitbox.GlobalRight > h.GlobalLeft && playerHitbox.GlobalBottom > h.GlobalTop)
                                {
                                    Transform.Position.X = h.GlobalLeft;
                                }
                                if (playerHitbox.GlobalLeft < h.GlobalRight && playerHitbox.GlobalBottom > h.GlobalTop)
                                {
                                    Transform.Position.X = h.GlobalRight;
                                }
                            }
                        }
                        else
                        {
                            changePosition = Vector2.Zero;
                        }

                        if (e is Coin)
                        {
                            Coin c = e as Coin;
                            c.HandlePlayerCollision();
                        }
                    }
                }
            }

            if (!collided)
            {
                if (changePosition.X < 0)
                {
                    alien.Flipped = true;
                }
                else if (changePosition.X > 0)
                {
                    alien.Flipped = false;
                }
            }

            if (changePosition.X != 0)
            {
                alien.Play("walk");
            }
            //else if (velocity == 0 && Input.Keyboard.IsDown(Keys.Down))
            //    alien.Play("duck");
        }