private void UpdateMovement(Entity entity, List <GameObject> objects, WallMap wallMap) { if ((entity.velocity.X != 0) && CheckCollisions(entity, wallMap, objects, true) == true) { entity.velocity.X = 0; } entity.position.X += entity.velocity.X; if ((entity.velocity.Y != 0) && CheckCollisions(entity, wallMap, objects, false) == true) { entity.velocity.Y = 0; } entity.position.Y += entity.velocity.Y; //check if should apply gravity if (entity.applyGravity == true) { entity.ApplyGravity(wallMap); } entity.velocity.X = entity.TendToZero(entity.velocity.X, entity.friction); // friction on Y if not using gravity if (entity.applyGravity == false) { entity.velocity.Y = entity.TendToZero(entity.velocity.Y, entity.friction); } }
public Enviroment(LevelView level, int enemyRadius = 4, int trapRadius = 1, WallMap wallMap = null, int wallRadius = 4) { if (wallMap == null) { wallMap = new WallMap(level, wallRadius); } WallMap = wallMap; TrapMap = new TrapMap(level, trapRadius); EnemyMap = new EnemyMap(level, enemyRadius); Exit = level.Field.GetCellsOfType(CellType.Exit).First(); Start = level.Field.GetCellsOfType(CellType.PlayerStart).First(); }
// Use this for initialization void Start() { // init wallMap = GameObject.Find("Stage").GetComponent <WallMap>(); smokeMap = GameObject.Find("Smoke").GetComponent <SmokeBehavier>(); padding = 10; minObserveDistance = 3.0f; accumulatedDeltaTime = 0; updateFPS = 30; Precision = WallMap.Precision; PrototypePerson = GameObject.Find("Prototype Person"); CrowdingArea = new Vector2[Random.Range(3, 8)]; Crowds = new List <Person>(); // find crowding area for (int i = 0; i < CrowdingArea.Length; i++) { int ca_x = 0, ca_y = 0; while (wallMap.IsWall[ca_x, ca_y] || ca_x <= 0) { ca_x = Random.Range(padding, Precision - padding); ca_y = Random.Range(padding, Precision - padding); } CrowdingArea[i] = new Vector2(ca_x, ca_x); // spread people around crowding area int crowndNum = 4 + Random.Range(-2, 6); for (int n = 0; n < crowndNum; n++) { float randx = 0, randy = 0; while (wallMap.IsWall[(int)(randx + 0.5), (int)(randy + 0.5)] || randx <= 0) { randx = Mathf.Clamp(ca_x + Random.value * 10, 0, Precision - 1); randy = Mathf.Clamp(ca_y + Random.value * 10, 0, Precision - 1); } Vector3 pos = wallMap.PixelToWorldCoord(randx, randy) + Vector3.up; Crowds.Add(new Person(Instantiate(PrototypePerson, pos, Quaternion.identity))); } } }
public virtual bool CheckCollisions(Entity entity, WallMap wallMap, List <GameObject> objects, bool xAxis) { Rectangle futureBoundingBox = entity.BoundingBox; if (xAxis == true && entity.velocity.X != 0) { futureBoundingBox.X += (int)Math.Ceiling(entity.maxSpeed) * Math.Sign(entity.velocity.X); // pixel perfect x axis collisions Rectangle wallCollisionX = wallMap.CheckCollision(futureBoundingBox); if (wallCollisionX != Rectangle.Empty) //if there is a collision xspd away from player... { var hSpd_ = Math.Sign(entity.velocity.X); Rectangle pixelBoundingBox = entity.BoundingBox; var pixelCollision = wallMap.CheckCollision(pixelBoundingBox); while (pixelCollision == Rectangle.Empty) { pixelBoundingBox.X += hSpd_; pixelCollision = wallMap.CheckCollision(pixelBoundingBox); if (pixelCollision == Rectangle.Empty) { entity.position.X += hSpd_; } } hSpd_ = 0; return(true); } } else if (xAxis == false && entity.velocity.Y != 0) { futureBoundingBox.Y += (int)Math.Ceiling(entity.velocity.Y); // pixel perfect y axis collisions Rectangle wallCollisionY = wallMap.CheckCollision(futureBoundingBox); if (wallCollisionY != Rectangle.Empty) { var vSpd_ = Math.Sign(entity.velocity.Y); Rectangle pixelBoundingBox = entity.BoundingBox; pixelBoundingBox.Y += vSpd_; var pixelCollision = wallMap.CheckCollision(pixelBoundingBox); while (pixelCollision == Rectangle.Empty) { pixelBoundingBox.Y += vSpd_; pixelCollision = wallMap.CheckCollision(pixelBoundingBox); if (pixelCollision == Rectangle.Empty) { entity.position.Y += vSpd_; } } vSpd_ = 0; return(true); } } for (int i = 0; i < objects.Count; i++) { if (objects[i] != entity && objects[i].active == true && objects[i].CheckCollision(futureBoundingBox) == true) { if ((objects[i].objectType == "Enemy") || (objects[i].objectType == "Player")) { if (entity.objectType == "Player" && !entity.invincible) { if (entity.BoundingBox.X > objects[i].BoundingBox.X) { entity.knockbackDir.X = 1; } else { entity.knockbackDir.X = -1; } entity.isHurt = true; } if (entity.objectType == "Enemy" && objects[i].objectType != "Enemy" && !objects[i].invincible) { if (entity.BoundingBox.X > objects[i].BoundingBox.X) { objects[i].knockbackDir.X = -1; } else { objects[i].knockbackDir.X = 1; } objects[i].isHurt = true; } } if (objects[i].objectType == "Damage") { entity.isHurt = true; } return(false); } } return(false); }
public FastKillAi(LevelView level) { Exit = level.Field.GetCellsOfType(CellType.Exit).First(); WallMap = new WallMap(level, 2); }