public void dealDamage(float damage, Agent source) { health -= (int)damage; takingDamage = true; damageSource = source; timeSinceDamageDealt = 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); }
public AgentHitScan(Vector3 cp, Ray rae, Agent a) : base(cp, rae, null) { this.agent = a; }
public Agent findAgentIntersection(BoundingBox bb, Agent ignore) { foreach (Agent a in core.allAgents()) { if (a.spawnTime > 0) continue; if (ignore == a) continue; if (a.getBoundingBox().Intersects(bb)) return a; } return null; }
//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); }
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); }