public void loadInitialRoom() { XNACS1Base.World.SetWorldCoordinate (new Vector2(initialRoom.X * 100f, initialRoom.Y * (9f/16f)*100f), 100f); hero = new Hero(new Vector2(rooms[(int)initialRoom.X, (int)initialRoom.Y].roomOrig().X + 50f, rooms[(int)initialRoom.X, (int)initialRoom.Y].roomOrig().Y + (9f / 16f) * 50f)); rooms[(int)initialRoom.X, (int)initialRoom.Y].loadRoom(); currentRoom = initialRoom; }
public Vector2 updateRoom(Hero hero) { walls.UpdateWallCollisionWithHero(hero); for (int i = 0; i < myEnemies.Length; i++) { myEnemies[i].UpdateEnemy(hero, walls); walls.UpdateWallCollisionWithEnemy(myEnemies[i]); } //note to self: work on trigger if (XNACS1Base.GamePad.ButtonXClicked()) wand.Shoot(hero); for (int i = 0; i < numEnemies; i++) { dropPos = wand.Update(myEnemies[i]); if(dropPos.X > -1) reduceActiveEnemies(); } if (key != null) if (hero.Collided(key)) { openAllDoors(); key.RemoveFromAutoDrawSet(); key = null; } Vector2 newRoom = new Vector2(-1f, -1f); for (int i = 0; i < numDoors; i++) { newRoom = myDoors[i].UpdateDoor(hero); if (newRoom.X > 0f) return newRoom; } return newRoom; }
public Vector2 UpdateDoor(Hero hero) { Vector2 bad = new Vector2(-1f, -1f); if (CurrentState == DoorsState.Open) { if (Collided(hero)) { hero.Center = heroNextPos; hero.HeroInitialPos = hero.Center; return nextRoom; } } return bad; //if (Collided(hero) && CurrentState == DoorsState.Open) { // CurrentState = DoorsState.Open; // Color = Color.White; //} //else { // CurrentState = DoorsState.Closed; // Color = Color.Brown; //} }
private void UpdateEnemyChaseState(Hero hero, float distToHero) { bool caught = false; caught = Collided(hero); if (caught) { hero.Caught(); hero.Center = hero.HeroInitialPos; } TargetPosition = hero.Center; if (caught) hero.Color = Color.Red; else { Center += .05f * (hero.Center - Center); } }
public Vector2 updateRoom(Hero hero) { walls.UpdateWallCollisionWithHero(hero); XNACS1Base.EchoToTopStatus("num of enemy" + activeEnemies ); for (int i = 0; i < myEnemies.Length; i++) { myEnemies[i].UpdateEnemy(hero, walls); walls.UpdateWallCollisionWithEnemy(myEnemies[i]); } //note to self: work on trigger if (XNACS1Base.GamePad.ButtonXClicked()) wand.Shoot(hero); dropPos = wand.Update(myEnemies); if(dropPos.X > -1) reduceActiveEnemies(); allDone = true; for (int i = 0; i < myEnemies.Length; i++) { if (!myEnemies[i].isBunny()) allDone = false; } if (key != null) { if (hero.Collided(key)) { openAllDoors(); key.RemoveFromAutoDrawSet(); } if(myDoors[0].isOpen() && key != null) key.RemoveFromAutoDrawSet(); } Vector2 newRoom = new Vector2(-1f, -1f); for (int i = 0; i < numDoors; i++) { newRoom = myDoors[i].UpdateDoor(hero); if (newRoom.X > 0f) return newRoom; } return newRoom; }
public void UpdateWallCollisionWithHero(Hero hero) { for (int i = 0; i < RoomWalls.Length; i++) hero.UpdateCollisionWithWall(RoomWalls[i]); }
public Vector2 updateRoom(Hero hero, int levelNum) { heroCaught = false; walls.UpdateWallCollisionWithHero(hero); for (int i = 0; i < myEnemies.Length; i++) { bool temp = myEnemies[i].UpdateEnemy(hero, walls); if (temp) heroCaught = temp; walls.UpdateWallCollisionWithEnemy(myEnemies[i]); } walls.updateStatus(hero, levelNum); if ((XNACS1Base.GamePad.Triggers.Right > 0 && !triggerPressed) || XNACS1Base.GamePad.ButtonXClicked()) { wand.Shoot(hero); triggerPressed = true; } if (XNACS1Base.GamePad.Triggers.Right == 0) { triggerPressed = false; } dropPos = wand.Update(myEnemies, walls); if (dropPos.X > -1) reduceActiveEnemies(); //allDone = true; //for (int i = 0; i < myEnemies.Length; i++) { // if (!myEnemies[i].isBunny()) // allDone = false; //} if (hasStairs == 1 && badGuy != null) { walls.updateWizardStats(badGuy); hasWon = badGuy.Update(hero, wand); if (hasWon) { stairs.AddToAutoDrawSet(); stairs.available = true; openAllDoors(); } if (badGuy.heroHit) { heroCaught = true; } } if (key != null) { if (hero.Collided(key)) { openAllDoors(); XNACS1Base.PlayACue("door_open"); key.RemoveFromAutoDrawSet(); } if (myDoors[0].isOpen() && key != null) { key.RemoveFromAutoDrawSet(); key = null; } } Vector2 newRoom = new Vector2(-1f, -1f); for (int i = 0; i < numDoors; i++) { newRoom = myDoors[i].UpdateDoor(hero); if (newRoom.X > 0f) return newRoom; } return newRoom; }
public bool updateLevel(XNACS1Lib.XNACS1Lib.GamePadSupport.AllButtonsOnGamePad pad, XNACS1Lib.XNACS1Lib.GamePadSupport.ThumbSticksOnGamePad thumbs, Hero hero) { Vector2 newRoom = new Vector2(-1, -1); if (rooms[(int)currentRoom.X, (int)currentRoom.Y].heroCaught || paused) { if (ticker > 0) { paused = true; ticker--; } else { paused = false; rooms[(int)currentRoom.X, (int)currentRoom.Y].heroCaught = false; ticker = 80; } } else if (loads == loadState.notLoading) { hero.UpdateHero(thumbs.Left); newRoom = rooms[(int)currentRoom.X, (int)currentRoom.Y].updateRoom(hero, levelNum); if (newRoom.X > -1) { loads = loadState.loading; if (newRoom.X > currentRoom.X) currentDirection = loadDirection.right; else if (newRoom.X < currentRoom.X) currentDirection = loadDirection.left; else if (newRoom.Y > currentRoom.Y) currentDirection = loadDirection.top; else currentDirection = loadDirection.bottom; lastVisitedRoom = currentRoom; currentRoom = newRoom; loadRoom(hero); expectedOrigin = new Vector2(currentRoom.X * 100f, currentRoom.Y * ((9f / 16f) * 100f)); } } if (loads == loadState.loading) { hero.Visible = false; moveRoom(); } if(loads == loadState.finished){ hero.Visible = true; unLoadRoom(); loads = loadState.notLoading; currentDirection = loadDirection.noDirection; currentOrigin = expectedOrigin; } if(rooms[(int)currentRoom.X, (int)currentRoom.Y].stairsInRoom()){ if (hero.Collided(rooms[(int)currentRoom.X, (int)currentRoom.Y].stairs) && rooms[(int)currentRoom.X, (int)currentRoom.Y].stairs.available) return true; } return false; }
public void UpdateWallCollisionWithHero(Hero hero) { hero.UpdateCollisionWithObject(this); }
public void loadInitialRoom(int difficulty) { XNACS1Base.World.SetWorldCoordinate (new Vector2(initialRoom.X * 100f, initialRoom.Y * (9f/16f)*100f), 100f); //XNACS1Base.World.SetBackgroundTexture("bg1"); hero = new Hero(new Vector2(rooms[(int)initialRoom.X, (int)initialRoom.Y].roomOrig().X + 50f, rooms[(int)initialRoom.X, (int)initialRoom.Y].roomOrig().Y + (9f / 16f) * 50f), difficulty); rooms[(int)initialRoom.X, (int)initialRoom.Y].loadRoom(); currentRoom = initialRoom; lastVisitedRoom = currentRoom; currentOrigin = new Vector2(currentRoom.X * 100f, currentRoom.Y * (9f / 16f) * 100f); loads = loadState.notLoading; currentDirection = loadDirection.noDirection; }
public void unloadLevel() { for (int i = 0; i < cellNum; i++) { for (int j = 0; j < cellNum; j++ ) { if (rooms[i, j] != null) { rooms[i, j].deleteRoom(); } } } hero.RemoveFromAutoDrawSet(); hero = null; }
public void updateStatus(Hero hero, int levelNum) { left.Label = "Princess Lives Left: " + hero.lives; left.LabelColor = Color.White; ctr.Label = "Level: " + levelNum; ctr.LabelColor = Color.White; }
public bool Update(Hero hero, Wand w) { heroHit = false; health.Update(new Vector2(this.Center.X, this.Center.Y+1), healthRemaining, initialLives); if (current == wizardStatus.isAlive) { if (shieldCoolDown < 0 && !shielded) { shielded = true; shieldCoolDown = 100; } else shieldCoolDown--; if (shieldCoolDown < 0 && shielded) { shielded = false; shieldCoolDown = 100; } if (shielded) { Texture = "wizardShield"; } else { Texture = "wizardRight"; if (coolDown < 0) { coolDown = 40; shoot(hero.Center); } else coolDown--; } for (int i = 0; i < list.Count; i++) { shot temp = list[i]; if (list[i].shotLife == 0) { list[i].bullet.RemoveFromAutoDrawSet(); list[i].emitter.RemoveFromAutoDrawSet(); list.Remove(list[i]); } else { temp.shotLife--; if (hero.Collided(temp.bullet) && !temp.hit) { hero.Caught(); hero.Center = hero.HeroInitialPos; temp.hit = true; heroHit = true; } list[i] = temp; list[i].emitter.Center = list[i].bullet.Center; } } for (int i = 0; i < w.list.Count; i++) if (w.list[i].bullet.Collided(this)) { if (!shielded) healthRemaining--; else { Random r = new Random(); if (r.Next(0, 100) < 10) healthRemaining--; } } if (healthRemaining <= 0) { current = wizardStatus.isDead; Texture = "Newteddybear"; XNACS1Base.PlayACue("Bear-Sound"); return true; } if (this.Center.X - hero.Center.X > 0) Texture = shielded ? "wizardShieldLeft" : "wizardLeft"; else Texture = shielded ? "wizardShield" : "wizardRight"; } if (current == wizardStatus.isDead) { for (int i = 0; i < list.Count; i++) { list[i].bullet.RemoveFromAutoDrawSet(); list[i].emitter.RemoveFromAutoDrawSet(); list.Remove(list[i]); } } return false; }
public void loadInitialRoom(int difficulty, Hero hero) { XNACS1Base.World.SetWorldCoordinate (new Vector2(initialRoom.X * 100f, initialRoom.Y * (9f/16f)*100f), 100f); hero.Center = new Vector2(rooms[(int)initialRoom.X, (int)initialRoom.Y].roomOrig().X + 50f, rooms[(int)initialRoom.X, (int)initialRoom.Y].roomOrig().Y + (9f / 16f) * 50f); rooms[(int)initialRoom.X, (int)initialRoom.Y].loadRoom(hero, levelNum); roomMap[(int)initialRoom.X, (int)initialRoom.Y] = roomState.visited; // betania added currentRoom = initialRoom; lastVisitedRoom = currentRoom; currentOrigin = new Vector2(currentRoom.X * 100f, currentRoom.Y * (9f / 16f) * 100f); loads = loadState.notLoading; currentDirection = loadDirection.noDirection; hero.TopOfAutoDrawSet(); }
public bool UpdateEnemy(Hero hero, WallSet wall) { if (CurrentState != EnemyState.Bunny) { DetectHero(hero); Vector2 toTarget = TargetPosition - Center; float distToTarget = toTarget.Length(); toTarget.Normalize(); if (CurrentState == EnemyState.Chaser) { ChaserCount--; if (UpdateEnemyChaseState(hero, distToTarget)) { return true; } } else if (CurrentState == EnemyState.Patrol) UpdateEnemyPatrolState(wall); if (ChaserCount == 0 && distToTarget > kDistToBeginChase) { CurrentState = EnemyState.Patrol; ChaserCount = 500; } } if (lives > initialLives) initialLives = lives; health.Update(this.Center, lives, initialLives); return false; }
public void loadRoom(Hero hero) { rooms[(int)currentRoom.X, (int)currentRoom.Y].loadRoom(hero, levelNum); roomMap[(int)currentRoom.X, (int)currentRoom.Y] = roomState.visited; }
protected bool UpdateEnemyChaseState(Hero hero, float distToHero) { bool caught = false; caught = Collided(hero); if (caught) { hero.Caught(); hero.Center = hero.HeroInitialPos; } TargetPosition = hero.Center; if (caught) { Center = EnemyInitialPos; CurrentState = EnemyState.Patrol; return true; } else { Center += .05f * (hero.Center - Center) * difficulty; } return false; }
public void loadRoom(Hero hero, int levelNum) { walls.loadWalls(); roomObjects.AddAllToAutoDraw(); if (hasStairs == 1 && !stairs.available) stairs.RemoveFromAutoDrawSet(); if (numEnemies == 0 && !isAlive) openAllDoors(); walls.updateStatus(hero, levelNum); }
public void UpdateEnemy(Hero hero, WallSet wall) { if (CurrentState != EnemyState.Bunny) { DetectHero(hero); Vector2 toTarget = TargetPosition - Center; float distToTarget = toTarget.Length(); toTarget.Normalize(); if (CurrentState == EnemyState.Chaser) { ChaserCount--; UpdateEnemyChaseState(hero, distToTarget); } else if (CurrentState == EnemyState.Patrol) UpdateEnemyPatrolState(wall); if (ChaserCount == 0 && distToTarget > kDistToBeginChase) { CurrentState = EnemyState.Patrol; ChaserCount = 500; } } }
public Vector2 UpdateDoor(Hero hero) { Vector2 bad = new Vector2(-1f, -1f); if (CurrentState == DoorsState.Open) { if (Collided(hero)) { hero.Center = heroNextPos; hero.HeroInitialPos = hero.Center; return nextRoom; } } return bad; }
private void DetectHero(Hero hero) { Vector2 toHero = hero.Center - Center; if (toHero.Length() < kDistToBeginChase) { CurrentState = EnemyState.Chaser; TargetPosition = hero.Center; } }
protected override void UpdateWorld() { #region game is going on if (gameStarted && !gameOver && !win) { int roomX = (int)theLevel.currentRoom.X; int roomY = (int)theLevel.currentRoom.Y; #region removing while testing new pause screen //if (pauseScreen == null) { //we are creating the pause screen every update! // float x = theLevel.currentOrigin.X + 50f; // float y = theLevel.currentOrigin.Y + (9f/16f)*50f; // pauseScreen = new XNACS1Rectangle(new Vector2(x, y), 100f, (9f / 16f)*100f); // pauseScreen.Color = Color.Black; // map = new Map(new Vector2(x, y));// betania added this // map.Visible = false; // map.RemoveFromAutoDrawSet();// betania added this //} #endregion if (GamePad.ButtonStartClicked() && !exiting) paused = paused ? false : true; //toggle the pause button if (theLevel.paused) World.Paused = true; if (!theLevel.paused && lostLifeScreen != null) { lostLifeScreen.RemoveFromAutoDrawSet(); lostLifeScreen = null; } if (!theLevel.paused && !paused) World.Paused = false; if (!paused && !theLevel.paused ) { //if (theLevel.paused) // World.Paused = true; if (GamePad.ButtonBackClicked() || exiting) { exiting = true; World.Paused = true; float x = theLevel.rooms[roomX, roomY].roomOrigin.X + 50f; float y = theLevel.rooms[roomX, roomY].roomOrigin.Y + 27f; if (areYouSure == null) { areYouSure = new XNACS1Rectangle(new Vector2(x, y), 50, 27f); areYouSure.Color = Color.Black; areYouSure.Label = "Are you sure you want to quit? All progress will be lost.\n" + "Press A to exit or B or cancel and return to the game"; areYouSure.LabelColor = Color.White; areYouSure.AddToAutoDrawSet(); } if (GamePad.ButtonAClicked()) { Exit(); } else if (GamePad.ButtonBClicked()) { areYouSure.RemoveFromAutoDrawSet(); areYouSure = null; World.Paused = false; exiting = false; } } else { if (!loading) { newLevel = false; newLevel = theLevel.updateLevel(GamePad.Buttons, GamePad.ThumbSticks, hero); if (newLevel) { loading = true; currentLevel++; } } if (loading) { if (currentLevel <= totalLevels) { float x = theLevel.rooms[roomX, roomY].roomOrigin.X + 50f; float y = theLevel.rooms[roomX, roomY].roomOrigin.Y + 28.2f; if (levelScreen == null) { levelScreen = new XNACS1Rectangle(new Vector2(x, y), 100f, 56f); levelScreen.Color = Color.Black; levelScreen.Label = "Level " + currentLevel; levelScreen.LabelColor = Color.White; levelScreen.AddToAutoDrawSet(); } World.Paused = true; if (tick > 0) { tick--; } else { tick = 120; levelScreen.RemoveFromAutoDrawSet(); levelScreen = null; theLevel.unloadLevel(); // delete all rooms //map.removeRoom(); switch (currentLevel) { case 1: path = @"level1.txt"; break; case 2: path = @"level2.txt"; break; case 3: path = @"level3.txt"; break; case 4: path = @"level4.txt"; break; default: win = true; break; } s = new StreamReader(path); XmlDocument xml = new XmlDocument(); theLevel = new Level(ref s, xml); theLevel.loadInitialRoom(difficulty, hero); World.Paused = false; loading = false; } } else { win = true; } } if (pauseScreen.IsInAutoDrawSet()) { pauseScreen.RemoveFromAutoDrawSet(); pauseScreen = null; if (map.IsInAutoDrawSet()) { map.RemoveFromAutoDrawSet(); map.removeRoom(); map.Visible = false; // map = null; } } } } else if (paused && !theLevel.paused) { pauseScreen.AddToAutoDrawSet(); if (!map.Visible) { map.AddToAutoDrawSet();// betania added this map.drawRoom(map.LowerLeft);// betania added this map.displayMap(theLevel);// betania added map.Visible = true; } } else { if (lostLifeScreen == null) { lostLifeScreen = new XNACS1Rectangle( new Vector2(theLevel.currentOrigin.X + 50f, theLevel.currentOrigin.Y + ((9f / 16f) * 100) / 2), 100f, 56f); lostLifeScreen.Label = "Princess Lives Left " + hero.NumTimesCaught; lostLifeScreen.Color = Color.Black; lostLifeScreen.LabelColor = Color.White; lostLifeScreen.AddToAutoDrawSet(); } theLevel.updateLevel(GamePad.Buttons, GamePad.ThumbSticks, hero); } gameOver = hero.lives < 0; //String message = "Number of Lives: " + hero.lives + " Level Number: " + currentLevel; //SetTopEchoColor(Color.White); //EchoToTopStatus(message); theLevel.rooms[(int)theLevel.currentRoom.X, (int)theLevel.currentRoom.Y].wand.UpdateWand(currentLevel); //if (w == null) // w = new Wizard(Vector2.One); //w.Update(hero, theLevel.rooms[(int)theLevel.currentRoom.X, (int)theLevel.currentRoom.Y].wand); } #endregion #region game is won or lost else if (gameOver || win) { World.SetWorldCoordinate(new Vector2(0, 0), 100f); if (gameOver) { #region duplicate check //if (gameOverText == null) //{ // cover = new XNACS1Rectangle( // new Vector2(50f, ((9f / 16f) * 100f) / 2f), 100, (9f / 16f) * 100f); // cover.Color = Color.Black; //} #endregion if (gameOverText == null) { gameOverText = new XNACS1Rectangle(new Vector2(50, 40), 40, 10); gameOverText.Label = "GAME OVER \n A TO RESTART \n B TO EXIT"; gameOverText.Color = Color.Black; gameOverText.LabelColor = Color.White; } } else { if (winScreen == null) { winScreen = new XNACS1Rectangle( new Vector2(50f, ((9f / 16f) * 100f) / 2f), 100, (9f / 16f) * 100f); winScreen.Color = Color.Black; winScreen.Label = "You've escaped the evil wizard's castle!\n You're free at last!"; winScreen.LabelColor = Color.White; } } //unload everything if(theLevel != null) theLevel.unloadLevel(); theLevel = null; if(hero != null) hero.RemoveFromAutoDrawSet(); hero = null; if (GamePad.ButtonAClicked()) { gameOverText.RemoveFromAutoDrawSet(); gameOverText = null; cover.RemoveFromAutoDrawSet(); cover = null; setupGame(); } if (GamePad.ButtonBClicked()) { Exit(); } } #endregion #region game hasn't been started yet else if (!gameStarted) { if (GamePad.ButtonAClicked()) { if (selected.Center == easy.Center) difficulty = 1; else if (selected.Center == medium.Center) difficulty = 2; else difficulty = 3; hero = new Hero(new Vector2(0f, 0f), difficulty); theLevel.loadInitialRoom(difficulty, hero); //EchoToTopStatus(difficulty.ToString()); gameStarted = true; selected.RemoveFromAutoDrawSet(); } if (tick > 0) tick--; else { if (GamePad.ThumbSticks.Left.Y > 0) { if (selected.Center != easy.Center) if (selected.Center != medium.Center) selected.Center = medium.Center; else selected.Center = easy.Center; tick = 8; } else if (GamePad.ThumbSticks.Left.Y < 0) { if (selected.Center != hard.Center) if (selected.Center != medium.Center) selected.Center = medium.Center; else selected.Center = hard.Center; tick = 8; } } } #endregion }