/// <summary> /// Remove observer /// </summary> public void unregister(KTYD.ObserverModel.Observer obj) { if (this.container.Contains(obj)) { this.container.Remove(obj); } }
public void determineAction(List<Entity> trashContainers, List<Entity> playersList,List<Entity> bulletList,KTYD.Model.Map gameMap) { Entity e = findClosestPlayer(playersList); determineActionForTarget(e,gameMap); myState.update(); search(); }
public Playmode(gameState s, KTYD.Model.Map g, Boolean p, KeyboardState i, bool[] ps, float st, float[] t, Controller.Players gPlayers, Dictionary<PlayerIndex, int> test, View.View gView) : base(s) { c = test; gamePlayers = gPlayers; gameMap = g; pauseGame = p; input = i; pressShoot = ps; storeTime = st; time = t; gameView = gView; }
public void draw(SpriteSheet unitSheet,KTYD.Model.Map gameMap,Rectangle tempStretch,Rectangle tempStretch_Health,Entity e) { tempStretch.Width = 200; tempStretch.Height = 20; tempStretch.X = (int)(this.getLocation().X); tempStretch.Y = (int)(this.getLocation().Y); tempStretch_Health.Height = 18; tempStretch_Health.X = (int)(this.getLocation().X); tempStretch_Health.Y = (int)(this.getLocation().Y); tempStretch_Health.Width = ((e.Health) * tempStretch.Width - 2) / 100; unitSheet.drawAtIndex(GameConfig.IMG_BAR_BASE, GameConfig.IMG_BAR_BASE_ROW, tempStretch); unitSheet.drawAtIndex(GameConfig.IMG_BAR_HEALTH, GameConfig.IMG_BAR_BASE_ROW, tempStretch_Health); }
public AttackState(String m,KTYD.AI.Enemy e,KTYD.Model.Map mm) : base(m,e,mm) { }
public AI_State(String m,KTYD.AI.Enemy e,KTYD.Model.Map mm) { myName = m; myEntity=e; myMap = mm; }
/// <summary> /// Register observer /// </summary> public void register(KTYD.ObserverModel.Observer obj) { this.container.Add(obj); }
/// <summary> /// Load a new player in /// </summary> /// <param name="e"></param> public void loadPlayerIn(KTYD.Model.Character e) { player_list.Add(e); weapons_list.Add(new Weapon[GameConfig.MAX_WEAPON_SLOT]); weapons_list[weapons_list.Count - 1][GameConfig.WEAPON_SLOT_ONE] = Weapon.createPistol(); weapons_list[weapons_list.Count - 1][GameConfig.WEAPON_SLOT_TWO] = Weapon.createPistol(); currentWeapon.Add(GameConfig.WEAPON_SLOT_ONE); currentLifeHas.Add(GameConfig.DEFAULT_LIFE_GIVEN); }
/// <summary> /// Determine action of target /// </summary> /// <param name="e">Target</param> public void determineActionForTarget(Entity e,KTYD.Model.Map myMap) { if (e == null) { myState = new GuardState("GUARD",this,myMap); return; } if (!e.isDead()) { if ((isPlayerWithinCloseRanged(e))) { findPlayer(e); myState = new AttackState("ATTACK", this, myMap); } else if ((isPlayerWithinSight(e))) { findPlayer(e); myState = new SearchState("SEARCH",this,myMap); } else { myState = new GuardState("GUARD",this,myMap); } } else { if (!isDead()) { setState(prevState); } } /* if (e == null) { setState(EntityState.GUARD); return; } if (!e.isDead()) { if ((isPlayerWithinCloseRanged(e))) { findPlayer(e); setState(EntityState.ATTACK); } else if ((isPlayerWithinSight(e))) { findPlayer(e); setState(EntityState.SEARCH); } else { setState(EntityState.GUARD); } } else { if (!isDead()) { setState(prevState); } } */ }
public void updateValues(String s, KTYD.Model.Map g, Boolean p, KeyboardState i, bool[] ps, float st, float[] t, Controller.Players gPlayers, Dictionary<PlayerIndex, int> test) { c = test; gamePlayers = gPlayers; gameMap = g; pauseGame = p; input = i; pressShoot = ps; storeTime = st; time = t; }
/// <summary> /// Load a game map for this view /// </summary> /// <param name="newMap">Map object</param> public void loadMap(KTYD.Model.Map newMap) { gameMap = newMap; //Load barGraphs for (int i = 1; i < gameMap.PlayerEntities.Count() + 1; i++) { BarGraph b1; if (i >= 3) { b1 = new BarGraph(new Vector2(100 * i - 50, 60), 200, 2); } else { b1 = new BarGraph(new Vector2(100 * i - 50, 10), 200, 2); } healthBars.Add(b1); } }
/// <summary> /// Determines what the bullet should do(taken from Map.cs) /// </summary> public override void updateActions(KTYD.Model.Map gameMap) { gArray gameEntities = gameMap.allEntities; List<Entity> trashContainers = gameMap.getTrashContainers(); DiffScaler AIDirector = gameMap.diffScaler(); List<Entity> nearbyEntities=gameEntities.getNearbycontainers(this); foreach (Entity u in nearbyEntities) { if (this != u) { if (this.isCollide(u)) { if (u.Type != EntityType.BULLET) { // if bullet is not already in the trash list if (!trashContainers.Contains(this)) { trashContainers.Add(this); ((KTYD.Model.Bullet)this).hitTarget(u); ((KTYD.Model.Bullet)this).setDie(); //SoundEffect[6].Play(); } if (u.Type == EntityType.ENEMY && ((KTYD.Model.Bullet)this).Owner == EntityType.PLAYER) { // add point AIDirector.addPoint(); } } } } }//for each }
public SearchState(String m,KTYD.AI.Enemy e,KTYD.Model.Map mm) : base(m,e,mm) { }
public void Add(KTYD.Model.Character e) { loadPlayerIn(e); }
/// <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(); }
public void addItemsToMap(KTYD.Model.Map gMap) { KTYD.Model.ItemType itemTyper; int tempRand = r.Next() % 4; // Spawn random items to be picked up if (tempRand == 1) { itemTyper = Model.ItemType.M16_WEAPON; } else if (tempRand == 2) { itemTyper = Model.ItemType.FLAME_WEAPON; //itemTyper = Model.ItemType.HEALTH; } else if (tempRand == 3) { itemTyper = Model.ItemType.SHOTGUN_WEAPON; } else { itemTyper = Model.ItemType.HEALTH; } gMap.loadEntity(new KTYD.Model.Item(50 + r.Next() % (GameConfig.LEVEL_WIDTH - 100), 50 + r.Next() % (GameConfig.LEVEL_HEIGHT - 100), itemTyper)); }
/// <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; }
//This method should not be called public virtual void updateActions(KTYD.Model.Map g) { }
public GuardState(String m,KTYD.AI.Enemy e,KTYD.Model.Map mm) : base(m,e,mm) { }