Пример #1
0
        //picks up and applies any pickups the agent will take in the next move
        public void applySimpleMovement(GameTime gameTime, Agent a, Vector3 velocity)
        {
            BoundingBox agentBoundingBox = a.getBoundingBox();
            Vector3     agentRadius      = size(agentBoundingBox) * 0.5f;
            Vector3     agentPoint       = agentBoundingBox.Min + agentRadius;

            velocity = velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            Vector3       agentVelocity = toESpace(agentRadius, velocity);
            List <PickUp> pickedUp      = new List <PickUp>();

            foreach (ICollidable collidable in getCollidablesToCheck(a, velocity))
            {
                if (collidable is PickUp)
                {
                    PickUp p = (PickUp)collidable;
                    //if (collidesWithPickup(agentRadius, agentPoint, agentVelocity, p)) {
                    if (collidable.getBoundingBox().Intersects(a.getBoundingBox()))
                    {
                        Console.WriteLine("picked up");
                        pickedUp.Add(p);
                    }
                }
            }

            foreach (PickUp p in pickedUp)
            {
                p.pickupGen.removePickUp();
                p.affect(a);
            }

            a.setPosition(a.getPosition() + velocity);
        }
Пример #2
0
        public void applyMovement(float elapsedTime, Agent player, Vector3 velocity)
        {
            BoundingBox playerBoundingBox = player.getBoundingBox();

            //update the persistentVelocity
            Velocities pv = player.agentVelocities;

            if (pv.persistentVelocity.Y == 0)
            {
                pv.persistentVelocity.Y = velocity.Y;
            }
            velocity.Y = 0;
            pv.persistentVelocity.Y += -gravity * elapsedTime;

            //fix it to ensure terminalVelcoity
            if (pv.persistentVelocity.Y <= player.terminalVelocity)
            {
                pv.persistentVelocity.Y = player.terminalVelocity;
            }

            Vector3 retMove = (velocity) * elapsedTime;

            Vector3 offset = center(playerBoundingBox) - player.getPosition();

            Vector3 playerRadius = size(playerBoundingBox) * 0.5f;
            Vector3 basePoint    = toESpace(playerRadius, center(playerBoundingBox));
            Vector3 evelocity    = toESpace(playerRadius, retMove);

            Vector3 pos = collideWithWorld(playerRadius, basePoint, evelocity, 0, player);

            Vector3 eSpacePersistent = toESpace(playerRadius, pv.persistentVelocity);
            Vector3 finalPos         = collideWithWorld(playerRadius, pos, eSpacePersistent, 0, player);
            //Vector3 finalPos = collideWithWorld(playerRadius, pos, Vector3.Zero, 0);

            //check if we're on the floor
            //this happens if we were moving down and the velocity vector was modified
            Vector3 eSpaceActualMove = finalPos - pos;

            if (eSpacePersistent.Y < 0 && eSpaceActualMove.Y - 0.005 > eSpacePersistent.Y)
            {
                pv.persistentVelocity.Y = 0;
                finalPos = pos;
            }
            if (eSpacePersistent.Y > 0 && eSpaceActualMove.Y + 0.005 < eSpacePersistent.Y)
            {
                pv.persistentVelocity.Y = -0.005f;
            }

            player.setPosition(toWorldSpace(playerRadius, finalPos) - offset);
        }
Пример #3
0
        //picks up and applies any pickups the agent will take in the next move
        public void applySimpleMovement(GameTime gameTime, Agent a, Vector3 velocity)
        {
            BoundingBox agentBoundingBox = a.getBoundingBox();
            Vector3 agentRadius = size(agentBoundingBox) * 0.5f;
            Vector3 agentPoint = agentBoundingBox.Min + agentRadius;
            velocity = velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            Vector3 agentVelocity = toESpace(agentRadius, velocity);
            List<PickUp> pickedUp = new List<PickUp>();

            foreach(ICollidable collidable in getCollidablesToCheck(a, velocity))
                if (collidable is PickUp) {
                    PickUp p = (PickUp)collidable;
                    //if (collidesWithPickup(agentRadius, agentPoint, agentVelocity, p)) {
                    if(collidable.getBoundingBox().Intersects(a.getBoundingBox())) {
                        Console.WriteLine("picked up");
                        pickedUp.Add(p);
                    }
                }

            foreach (PickUp p in pickedUp) {
                p.pickupGen.removePickUp();
                p.affect(a);
            }

            a.setPosition(a.getPosition() + velocity);
        }
Пример #4
0
        public void applyMovement(float elapsedTime, Agent player, Vector3 velocity)
        {
            BoundingBox playerBoundingBox = player.getBoundingBox();

            //update the persistentVelocity
            Velocities pv = player.agentVelocities;
            if(pv.persistentVelocity.Y == 0)
                pv.persistentVelocity.Y = velocity.Y;
            velocity.Y = 0;
            pv.persistentVelocity.Y += -gravity * elapsedTime;

            //fix it to ensure terminalVelcoity
            if (pv.persistentVelocity.Y <= player.terminalVelocity)
                pv.persistentVelocity.Y = player.terminalVelocity;

            Vector3 retMove = (velocity) * elapsedTime;

            Vector3 offset = center(playerBoundingBox) - player.getPosition();

            Vector3 playerRadius = size(playerBoundingBox) * 0.5f;
            Vector3 basePoint = toESpace(playerRadius, center(playerBoundingBox));
            Vector3 evelocity = toESpace(playerRadius, retMove);

            Vector3 pos = collideWithWorld(playerRadius, basePoint, evelocity, 0, player);

            Vector3 eSpacePersistent = toESpace(playerRadius, pv.persistentVelocity);
            Vector3 finalPos = collideWithWorld(playerRadius, pos, eSpacePersistent, 0, player);
            //Vector3 finalPos = collideWithWorld(playerRadius, pos, Vector3.Zero, 0);

            //check if we're on the floor
            //this happens if we were moving down and the velocity vector was modified
            Vector3 eSpaceActualMove = finalPos - pos;
            if(eSpacePersistent.Y < 0 && eSpaceActualMove.Y - 0.005 > eSpacePersistent.Y)    {
                pv.persistentVelocity.Y = 0;
                finalPos = pos;
            }
            if (eSpacePersistent.Y > 0 && eSpaceActualMove.Y + 0.005 < eSpacePersistent.Y)
            {
                pv.persistentVelocity.Y = -0.005f;
            }

            player.setPosition(toWorldSpace(playerRadius, finalPos) - offset);
        }