/// <summary> /// Update method refactored from Map.cs /// </summary> public override void updateActions(KTYD.Model.Map gameMap) { gArray containers = gameMap.getContainers(); List<Entity> trashContainers = gameMap.getTrashContainers(); List<Entity> playersList = gameMap.getPlayersList(); List<Entity> bulletList = gameMap.getBulletList(); if (!this.isDead()) { //Writing a hack here to prevent the enemies from infinitely looking at edge did not work if (1 == 2) { } else { List<Entity> nearbyContainers = containers.getNearbycontainers(this); foreach (Entity u in nearbyContainers) { if (this != u) { if (this.isCollide(u)) { if (u.Type == EntityType.BULLET) { // If bullet is actually hitting entity if (u.isCollide(this)) { trashContainers.Add(u); ((KTYD.Model.Bullet)u).hitTarget(this); ((KTYD.Model.Bullet)u).setDie(); } } else if (u.Type == EntityType.ENEMY) { ((KTYD.AI.Enemy)u).resolveCollision(this); } else { this.restorePrevLocation(); } } else { if (u.Type == EntityType.PLAYER) { ((KTYD.AI.Enemy)this).determineActionForTarget(((KTYD.AI.Enemy)this).findClosestPlayer(playersList),gameMap); } } } }// for each }//offedge } if (!isDead()) { determineAction(trashContainers,playersList,bulletList,gameMap); // Runaway } base.update(); }
/// <summary> /// Monitor and Add enemies to the map /// </summary> /// <param name="gMap">Map</param> public void addEnemiesToMap(KTYD.Model.Map gMap) { int eCount = gMap.EnemiesEntities.Count; List<KTYD.Model.Character> player = gMap.PlayerEntities; int difficultyScore = eCount * GameConfig.DIFF_SCALE_FACTOR; int spawnCount = 0; Vector2 spawnPos; spawnPos.X = 2; spawnPos.Y = 2; int max_runner = 20; // need this just in case while loop is indefinite (if it ever happened) int max_run = 10; // need this just in case while loop is indefinite while (max_run !=0) { eCount++; spawnCount++; if(spawnCount>GameConfig.MAX_ENEMY_SPAWN) { return; } if (eCount > maxEnemies) { break; } if (difficultyScore > myScore) { break; } spawnPos = determineSpawnLocation(gMap.getPlayersList()); int tempRand = r.Next() % 4; Weapon eWeapon; // Spawn random items to be picked up if (tempRand == 1) { eWeapon = Weapon.createPistol(); } else if (tempRand == 2) { eWeapon = Weapon.createShotgun(); //itemTyper = Model.ItemType.HEALTH; } else if (tempRand == 3) { eWeapon = Weapon.createPistol(); } else { eWeapon = Weapon.createShotgun(); } difficultyScore = difficultyScore + GameConfig.DIFF_SCALE_FACTOR; Random r2 = new Random(); Random r3 = new Random(); double rot = (r2.Next()+r3.Next()+r.Next())/ (2 * Math.PI); KTYD.AI.Enemy e = new KTYD.AI.Enemy(spawnPos.X,spawnPos.Y,(float)(rot), GameConfig.IMG_BASE_GRAY, eWeapon, EntityState.SEARCH); gMap.loadEntity(e); --max_runner; }//while return; }