示例#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
        public void spawnPlayer(Agent p)
        {
            //find the spawn point furthest from other agents
            float   maxDist  = -float.MaxValue;
            Vector3 minPoint = Vector3.Zero;

            foreach (Vector3 pos in mapEngine.playerPoss)
            {
                float dist = 0;
                foreach (Agent a in allAgents())
                {
                    dist += Vector3.Distance(a.getPosition(), pos);
                }
                if (dist > maxDist)
                {
                    maxDist  = dist;
                    minPoint = pos;
                }
            }

            p.setPosition(minPoint);
        }
示例#4
0
        public void spawnPlayer(Agent p)
        {
            //find the spawn point furthest from other agents
            float maxDist = -float.MaxValue;
            Vector3 minPoint = Vector3.Zero;
            foreach (Vector3 pos in mapEngine.playerPoss) {
                float dist = 0;
                foreach (Agent a in allAgents())
                    dist += Vector3.Distance(a.getPosition(), pos);
                if (dist > maxDist) {
                    maxDist = dist;
                    minPoint = pos;
                }
            }

            p.setPosition(minPoint);
        }
示例#5
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);
        }
示例#6
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);
        }