private void UpdateScreens(GameTime gameTime) { switch (gameState) { case GameState.menu: //MENU menu.Update((float)gameTime.ElapsedGameTime.TotalSeconds); break; case GameState.gamePlay: //GAMEPLAY gameManager.Update((float)gameTime.ElapsedGameTime.TotalSeconds); if (gameManager.GameOver() || gameManager.Winner()) { switchScreenTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (switchScreenTimer > 4 || KeyMouseReader.KeyPressed(Keys.Escape) || KeyMouseReader.KeyPressed(Keys.Space)) { switchScreenTimer = 0; gameState = GameState.enterUser; menu.run = Menu.RunTime.FirstLoad; } } else if (KeyMouseReader.KeyPressed(Keys.Escape)) { gameState = GameState.menu; } break; case GameState.highscore: //HIGHSCORES menu.Update((float)gameTime.ElapsedGameTime.TotalSeconds); highScore.Update(); if (KeyMouseReader.KeyPressed(Keys.Escape)) { gameState = GameState.menu; } break; case GameState.enterUser: //ENTER USER newScore.Update(); break; } }
private void AddToString() { if (KeyMouseReader.KeyPressed(Keys.Enter)) { userName += alphabet[alphabetIndex].ToString(); letterSlotIndex++; alphabetIndex = 0; } if (letterSlotIndex == 3) { Game1.WriteScores(Constants.scoreFilePath, userName, Constants.totalScore); Game1.ReadScores(Constants.scoreFilePath); Game1.gameState = Game1.GameState.menu; InitialState(); } }
private void HandleInput() { UpdateFocus(); if (KeyMouseReader.KeyPressed(Keys.Escape)) { EventManager.Dispatch(new PopStateEvent()); } if (!isHovered) { if (KeyMouseReader.LeftClick() || KeyMouseReader.RightClick()) { EventManager.Dispatch(new PopStateEvent()); } } }
public override void Update(GameTime gt) { pos = KeyMouseReader.GetMousePosition() - Offset(); if (KeyMouseReader.LeftPressed()) { enemy.TargetHostile = true; if (enemy.currHealth > 1) { enemy.currHealth -= 0.5f; } } else { enemy.TargetHostile = false; } }
protected override void Update(GameTime gameTime) { KeyMouseReader.Update(); if (KeyMouseReader.KeyClick(Keys.Escape)) { Exit(); } //Calculate delta and multiply it with 2.2. float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; delta *= 2.2f; //Update the simulation world. world.Update(delta); base.Update(gameTime); }
public override void Update(GameTime gameTime) { if (KeyMouseReader.KeyPressed(Keys.Escape)) { NogardGame.GameState = NogardGame.GameStateEnum.GameActive; } foreach (var b in NogardGame.ButtonManager.Buttons) { if (b.ButtonClicked && b.Equals(NogardGame.ButtonManager.ResumeButton)) { NogardGame.GameState = NogardGame.GameStateEnum.GameActive; } if (b.ButtonClicked && b.Equals(NogardGame.ButtonManager.PauseMenuButton)) { NogardGame.MainMenuManager.Init(); } } }
protected override void Update(GameTime gameTime) { KeyMouseReader.Update(); if (EXIT) { Exit(); } if (RELOADGAMEPLAY) { gameManager = new GameManager(screenWidth, screenHeight, tileSize); RELOADGAMEPLAY = false; menu.run = Menu.RunTime.Continued; gameState = GameState.gamePlay; } UpdateScreens(gameTime); base.Update(gameTime); }
private void ChangeLetter(ref int alphabetInt, int alphabetLength) { if (KeyMouseReader.KeyPressed(Keys.W) && alphabetInt < alphabetLength) { alphabetInt++; } else if (KeyMouseReader.KeyPressed(Keys.W) && alphabetInt == alphabetLength) { alphabetInt = 0; } if (KeyMouseReader.KeyPressed(Keys.S) && alphabetInt > 0) { alphabetInt--; } else if (KeyMouseReader.KeyPressed(Keys.S) && alphabetInt == 0) { alphabetInt = alphabetLength; } }
private void ExecuteSelectedButton() { if (KeyMouseReader.KeyPressed(Keys.Enter) || KeyMouseReader.KeyPressed(Keys.Space)) { switch (selected) { case 0: //continue - no changes Game1.gameState = Game1.GameState.gamePlay; break; case 1: //new game Game1.RELOADGAMEPLAY = true; Game1.LoadJsonLevel = true; selected = 0; break; case 2: //highscore Game1.gameState = Game1.GameState.highscore; if (run == RunTime.FirstLoad) { selected = 1; } else { selected = 0; } break; case 3: Game1.EXIT = true; break; } } }
public void Update(GameTime gameTime) { if (KeyMouseReader.RightClick()) { for (int i = 0; i < equipmentSlots.Count(); i++) { if (new Rectangle(equipmentSlots[i].GraphicLocationX, equipmentSlots[i].GraphicLocationY, 64, 64).Contains(KeyMouseReader.mouseState.Position)) { if (equipmentSlots[i].Item == null) { break; } if (tabManager.inventoryTab.inventorySystem.AddItem(equipmentSlots[i].Item)) { tabManager.map.player.team.characters[0].UnequipItem(equipmentSlots[i].Item); equipmentSlots[i].Item = null; equipmentSlots[i].InventoryFull = false; Archive.soundEffectDictionary["equip"].Play(); } } } } }
public void Update(Map map) { if (!map.tabManager.questTab.questSystem.HaveQuest(givingQuest)) { dialogState = (int)DialogState.Giving; } else if (!map.tabManager.questTab.questSystem.TurnInQuest(givingQuest)) { dialogState = (int)DialogState.InProgress; } else if (map.tabManager.questTab.questSystem.TurnInQuest(givingQuest)) { dialogState = (int)DialogState.HandingIn; } if (KeyMouseReader.KeyPressed(Keybinds.binds["talk"]) && !finished) { currentLine++; if (currentLine >= dialogLines[dialogState].Count()) { currentLine = 0; finished = true; if (givingQuest != null) { map.tabManager.questTab.questSystem.AddQuest(givingQuest); if (map.tabManager.questTab.questSystem.TurnInQuest(givingQuest)) { if (map.tabManager.inventoryTab.inventorySystem.AddItem(givingQuest.reward)) { map.tabManager.questTab.questSystem.RemoveQuest(givingQuest); } } } } } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { KeyMouseReader.Update(); // Allows the game to exit if (KeyMouseReader.KeyPressed(Keys.Escape)) { this.Exit(); } if (KeyMouseReader.KeyPressed(Keys.F2)) { BAM.BlocksToggle(); } if (KeyMouseReader.KeyPressed(Keys.F3)) { BAM.LBIToggle(); } BAM.Update(gameTime); // TODO: Add your update logic here base.Update(gameTime); }
private void ManipulateSelected(List <string> list) { if (Game1.navigateTabs == Game1.NavigationTabs.ChooseTool || Game1.navigateTabs == Game1.NavigationTabs.ChooseCategory || Game1.navigateTabs == Game1.NavigationTabs.ChooseObject) { if (selected == -1) { selected = 0; } if (KeyMouseReader.KeyPressed(Keys.W) && selected > 0) { selected--; } if (KeyMouseReader.KeyPressed(Keys.S) && selected < list.Count - 1) { selected++; } } else { selected = -1; } }
protected override void Update(GameTime gameTime) { KeyMouseReader.Update(); if (KeyMouseReader.KeyPressed(Keybinds.binds["toggleFullscreen"])) { graphics.IsFullScreen = !graphics.IsFullScreen; graphics.ApplyChanges(); } switch (currentGameState) { case (GameState.Menus): startMenu.Update(); if (KeyMouseReader.KeyPressed(Keybinds.binds["back"])) { this.Exit(); } break; case (GameState.World): map.Update(gameTime); string previousZoneName = map.zoneName; PortalEntity temporaryPortal = map.ZoneSwitch(); if (temporaryPortal != null) { fileName = temporaryPortal.zoneName; Player tempPlayer = map.player; TabManager tab = map.tabManager; map = FileReader.ReadMap(fileName); map.player = tempPlayer; map.player.position = temporaryPortal.spawnPosition; map.player.map = map; map.tabManager = tab; if (map.zoneName != previousZoneName) { MediaPlayer.Play(Archive.songDictionary[map.zoneName]); } } if (map.EngageCombatBool(ref combat) == true) { currentGameState = GameState.Combat; } if (KeyMouseReader.KeyPressed(Keys.Escape)) { currentGameState = GameState.Menus; MediaPlayer.Stop(); } break; case (GameState.Combat): combat.Update(gameTime); if (!combat.active && !combat.fadingOut) { MediaPlayer.Play(Archive.songDictionary[map.zoneName]); currentGameState = GameState.World; foreach (Quest q in map.tabManager.questTab.questSystem.quests) { foreach (Objective o in q.objectives) { if (o is KillObjective) { KillObjective oKill = (KillObjective)o; oKill.CompareTeam(combat.enemyID); } } } if (combat.winnerTeam == 2) { Initialize(); } else { map.player.team.characters[0].Heal((int)(map.player.team.characters[0].maxHealth * 0.2f)); } } if (KeyMouseReader.KeyPressed(Keybinds.binds["back"])) { this.Exit(); } break; case (GameState.WorldEditor): mapEditor.Update(); if (KeyMouseReader.KeyPressed(Keybinds.binds["back"])) { currentGameState = GameState.Menus; } break; } base.Update(gameTime); }
public void Control(GameTime gt) { if (KeyMouseReader.keyState.IsKeyDown(Keys.E) && GamePlayManager.levelComplete == true && Key.keyPickedUp == true) { GamePlayManager.levelNumber++; GamePlayManager.currentLevel = "level" + GamePlayManager.levelNumber.ToString(); GamePlayManager.map = new MapParser("Content/" + GamePlayManager.currentLevel + ".txt"); GamePlayManager.levelComplete = false; Key.keyPickedUp = false; } if (KeyMouseReader.keyState.IsKeyDown(Keys.D)) { WalkingAnimation(gt); velocity.X = normalVel; } else if (KeyMouseReader.keyState.IsKeyDown(Keys.A))// && pos.X >= startPos.X { WalkingAnimation(gt); velocity.X = -normalVel; } else { velocity.X = 0; } if (KeyMouseReader.mouseState.X >= bX / 2) { playerFacing = Facing.Right; } else if (KeyMouseReader.mouseState.X <= bX / 2) { playerFacing = Facing.Left; } if (KeyMouseReader.keyState.IsKeyDown(Keys.LeftShift)) { if (dashCount > 0) { if (KeyMouseReader.keyState.IsKeyDown(Keys.D)) { velocity.X += dashLength; } if (KeyMouseReader.keyState.IsKeyDown(Keys.A)) { velocity.X -= dashLength; } //save dash snapshot here dashCount = 0; } } if (KeyMouseReader.keyState.IsKeyDown(Keys.Space) && isGrounded) { velocity.Y = -jumpHeight; //jump height isGrounded = false; playerFacing = Facing.Jump; //srRect = new Rectangle(tileSize.X * 3, tileSize.Y * 0, tileSize.X, tileSize.Y); } if (KeyMouseReader.keyState.IsKeyDown(Keys.S) && isGrounded) { velocity.Y = jumpHeight; isGrounded = false; downPlatform = false; playerFacing = Facing.Jump; //srRect = new Rectangle(tileSize.X * 3, tileSize.Y * 0, tileSize.X, tileSize.Y); } if (KeyMouseReader.LeftClick()) { if (shotCount > 0 && canShoot) { bullet = new Bullet(AssetManager.bomb, pos, playerFacing); bulletList.Add(bullet); bullet.isActive = true; shotCount = 0; } } if (KeyMouseReader.keyState.IsKeyDown(Keys.F)) { melee.isActive = true; } else { melee.isActive = false; } if (KeyMouseReader.keyState.IsKeyDown(Keys.Q)) { PunchingAnimation(gt); } if (KeyMouseReader.keyState.IsKeyDown(Keys.R)) { KickingAnimation(gt); } }
protected void TilePicker() { if (selectedTileType == 0) { foreach (Tile t in floorTiles) { Rectangle tileHitbox = new Rectangle((int)t.position.X, (int)t.position.Y, t.texture.Width, t.texture.Height); if (KeyMouseReader.LeftClick() && tileHitbox.Contains(KeyMouseReader.mousePosition)) { selectedTile = t; selectedEntity = null; } } } if (selectedTileType == 1) { foreach (Tile t in wallTiles) { Rectangle tileHitbox = new Rectangle((int)t.position.X, (int)t.position.Y, t.texture.Width, t.texture.Height); if (KeyMouseReader.LeftClick() && tileHitbox.Contains(KeyMouseReader.mousePosition)) { selectedTile = t; selectedEntity = null; } } } if (selectedTileType == 2) { foreach (Entity e in entities) { Rectangle tileHitbox = new Rectangle((int)e.position.X, (int)e.position.Y, e.texture.Width, e.texture.Height); if (KeyMouseReader.LeftClick() && tileHitbox.Contains(KeyMouseReader.mousePosition)) { selectedTile = null; selectedEntity = e; } } } if (selectedTileType == 3) { foreach (Entity i in items) { Rectangle tileHitbox = new Rectangle((int)i.position.X, (int)i.position.Y, i.texture.Width, i.texture.Height); if (KeyMouseReader.LeftClick() && tileHitbox.Contains(KeyMouseReader.mousePosition)) { selectedTile = null; selectedEntity = i; } } } if (selectedTileType == 4) { foreach (PortalEntity p in portals) { Rectangle tileHitbox = new Rectangle((int)p.position.X, (int)p.position.Y, p.texture.Width, p.texture.Height); if (KeyMouseReader.LeftClick() && tileHitbox.Contains(KeyMouseReader.mousePosition)) { selectedTile = null; selectedEntity = p; } } } }
public void Update() { if (KeyMouseReader.LeftClick()) { if (!ItemInHand) { for (int i = 0; i < xNumberOfSlots; i++) { for (int j = 0; j < yNumberOfSlots; j++) { if (new Rectangle(invSlot[i, j].GraphicLocationX, invSlot[i, j].GraphicLocationY, 64, 64).Contains(KeyMouseReader.mouseState.Position)) { if (invSlot[i, j].Item == null) { break; } itemInHand = inPlayerHand.Item; inPlayerHand.Item = invSlot[i, j].Item; invSlot[i, j].Item = itemInHand; ItemInHand = true; if (invSlot[i, j].Item == null) { invSlot[i, j].InventoryFull = false; } else { invSlot[i, j].InventoryFull = true; } break; } } } } else { for (int i = 0; i < xNumberOfSlots; i++) { for (int j = 0; j < yNumberOfSlots; j++) { if (new Rectangle(invSlot[i, j].GraphicLocationX, invSlot[i, j].GraphicLocationY, 64, 64).Contains(KeyMouseReader.mouseState.Position)) { itemInHand = inPlayerHand.Item; inPlayerHand.Item = invSlot[i, j].Item; invSlot[i, j].Item = itemInHand; if (inPlayerHand.Item == null) { ItemInHand = false; } if (invSlot[i, j].Item == null) { invSlot[i, j].InventoryFull = false; } else { invSlot[i, j].InventoryFull = true; } } } } } } if (KeyMouseReader.RightClick()) { for (int i = 0; i < xNumberOfSlots; i++) { for (int j = 0; j < yNumberOfSlots; j++) { if (new Rectangle(invSlot[i, j].GraphicLocationX, invSlot[i, j].GraphicLocationY, 64, 64).Contains(KeyMouseReader.mouseState.Position)) { if (invSlot[i, j].Item == null) { break; } if (tabManager.characterTab.characterSystem.TryEquip(invSlot[i, j].Item)) { invSlot[i, j].Item = null; invSlot[i, j].InventoryFull = false; Archive.soundEffectDictionary["equip"].Play(); } } } } } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { KeyMouseReader.Update(); now = DateTime.Now; // Allows the game to exit if (KeyMouseReader.KeyPressed(Keys.Escape)) { this.Exit(); } if (KeyMouseReader.KeyPressed(Keys.A) && !AIControlled) { controlCar.MoveLeft(); } if (KeyMouseReader.KeyPressed(Keys.D) && !AIControlled) { controlCar.MoveRight(); } if (KeyMouseReader.KeyPressed(Keys.Space)) { AIControlled = !AIControlled; crashes = 0; roundStart = DateTime.Now; } if (AIControlled) { AI.Update(gameTime); } spawnCounter++; if (spawnCounter > spawnAt) { int tries = 0; while (tries < 1) { if (SpawnCar()) { break; } tries++; } /* * int randLane = rand.Next(0, Globals.lanes); * FallingCar newCar = new FallingCar(randLane, (float)(rand.NextDouble() * 7) + 1f); * float TTLPlusCar = newCar.getTTLBeforeCar(); * if (queueList[randLane].Count > 0) * { * if (TTLPlusCar > queueList[randLane].Last.Value.TTL) * { * queueList[randLane].AddLast(newCar); * spawnCounter = 0; * } * } * else * { * queueList[randLane].AddLast(newCar); * spawnCounter = 0; * }*/ } foreach (LinkedList <FallingCar> l in queueList) { foreach (FallingCar f in l) { f.Update(gameTime); } if (l.First != null && l.First.Value.TTL < 0) { l.RemoveFirst(); } } controlCar.Update(gameTime); //testCar2.Update(gameTime); // TODO: Add your update logic here base.Update(gameTime); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { KeyMouseReader.Update(); if (KeyMouseReader.RightClick()) { camera.Update(new Vector2(KeyMouseReader.mouseState.X - camera.CameraPos.X, KeyMouseReader.mouseState.Y - camera.CameraPos.Y)); } grid.Update(new Vector2(KeyMouseReader.mouseState.X, KeyMouseReader.mouseState.Y)); if (navigateTabs == NavigationTabs.ChooseObject) { if (chooseObject == ChooseObject.Player) { grid.tileType = TileGrid.TileType.AddPlayer; } else if (chooseObject == ChooseObject.Wall) { grid.tileType = TileGrid.TileType.AddWall; } else if (chooseObject == ChooseObject.Teleport) { grid.tileType = TileGrid.TileType.AddTeleport; } else if (chooseObject == ChooseObject.EnemySpawner) { grid.tileType = TileGrid.TileType.AddSpawner; } else if (chooseObject == ChooseObject.Pistol) { grid.tileType = TileGrid.TileType.AddPistol; } } hud.Update(camera.CameraPos); if (navigateTabs == NavigationTabs.SetGrid) { SetGrid(); } else if (navigateTabs == NavigationTabs.ChooseTool && chooseTool == ChooseTools.SaveLevel) { grid.SaveToJsonFile(); Console.WriteLine("SAVED"); chooseTool = ChooseTools.AddTiles; hud.selected = 0; } switch (navigateTabs) { case NavigationTabs.ChooseTool: if (KeyMouseReader.KeyPressed(Keys.Escape)) { navigateTabs = NavigationTabs.SetGrid; } if (KeyMouseReader.KeyPressed(Keys.Enter)) { if (hud.selected == 0) { chooseTool = ChooseTools.AddTiles; navigateTabs = NavigationTabs.ChooseCategory; } else if (hud.selected == 1) { chooseTool = ChooseTools.RemoveTiles; } else if (hud.selected == 2) { chooseTool = ChooseTools.SaveLevel; } hud.selected = 0; } break; case NavigationTabs.ChooseCategory: if (KeyMouseReader.KeyPressed(Keys.Escape)) { navigateTabs = NavigationTabs.ChooseTool; } if (KeyMouseReader.KeyPressed(Keys.Enter)) { if (hud.selected == 0) { chooseCategory = ChooseCategory.Characters; } else if (hud.selected == 1) { chooseCategory = ChooseCategory.Environment; } else if (hud.selected == 2) { chooseCategory = ChooseCategory.Weapons; } hud.selected = 0; navigateTabs = NavigationTabs.ChooseObject; } break; case NavigationTabs.ChooseObject: if (KeyMouseReader.KeyPressed(Keys.Escape)) { navigateTabs = NavigationTabs.ChooseCategory; } if (KeyMouseReader.KeyPressed(Keys.Enter)) { if (chooseCategory == ChooseCategory.Characters) { if (hud.selected == 0) { chooseObject = ChooseObject.Player; } else if (hud.selected == 1) { chooseObject = ChooseObject.EnemySpawner; } else if (hud.selected == 2) { chooseObject = ChooseObject.Enemy; } } else if (chooseCategory == ChooseCategory.Environment) { if (hud.selected == 0) { chooseObject = ChooseObject.Wall; } else if (hud.selected == 1) { chooseObject = ChooseObject.Teleport; } } else if (chooseCategory == ChooseCategory.Weapons) { if (hud.selected == 0) { chooseObject = ChooseObject.Pistol; } } } break; } // TODO: Add your update logic here base.Update(gameTime); }
public override void Update(GameTime gameTime) { base.Update(gameTime); Gliding = false; Sinking = false; Moving = false; if (Timer > 0) { Timer -= gameTime.ElapsedGameTime.TotalSeconds; Color = Color.Red; } else { Timer = 0; Color = Color.White; } if (Keyboard.GetState().IsKeyDown(Keys.Right)) { animationState = AnimationEnum.Walking; LastFacing = Facing.Right; Direction.X = 1f; Effects = SpriteEffects.None; } else if (Keyboard.GetState().IsKeyDown(Keys.Left)) { animationState = AnimationEnum.Walking; LastFacing = Facing.Left; Direction.X = -1f; Effects = SpriteEffects.FlipHorizontally; } else { animationState = AnimationEnum.Standing; Direction.X = 0f; Velocity.X = 0f; } if (!Airborn && KeyMouseReader.KeyPressed(Keys.Up)) { Velocity.Y = -12; Airborn = true; } while (Airborn) { animationState = AnimationEnum.Jumping; break; } if (KeyMouseReader.KeyPressed(Keys.Space)) { ChangeFrameShooting = true; } if (Health <= 0) { NogardGame.GameOverManager.Lose(); } if (Velocity.Y >= 60) { Health = 0; } Velocity.Y += GravitySpeed; Velocity += Direction * (Speed / Math.Max(1, Math.Abs(Velocity.X))) * (float)gameTime.ElapsedGameTime.TotalSeconds; Velocity = new Vector2(MathHelper.Clamp(Velocity.X, -3, 3), MathHelper.Clamp(Velocity.Y, -20, 60)); frameTimer -= gameTime.ElapsedGameTime.TotalMilliseconds; PlayerFrames(gameTime); }
public override void Update(GameTime gameTime) { if (KeyMouseReader.mouseState.LeftButton == ButtonState.Pressed) { selectionBox = new Rectangle( Math.Min(KeyMouseReader.mouseState.X, KeyMouseReader.leftMouseDownPosition.X), Math.Min(KeyMouseReader.mouseState.Y, KeyMouseReader.leftMouseDownPosition.Y), Math.Abs(KeyMouseReader.mouseState.X - KeyMouseReader.leftMouseDownPosition.X), Math.Abs(KeyMouseReader.mouseState.Y - KeyMouseReader.leftMouseDownPosition.Y)); } if (KeyMouseReader.LeftClickInPlace()) { if (rPressed) { Point p = Grid.Vector2ToGridPos(KeyMouseReader.mouseState.Position.ToVector2()); gm.SpawnPowerPlant(p.X, p.Y, faction); } else if (aPressed) { //A-move selected units foreach (IAttackable s in selection) { if (s is Unit) { (s as Unit).Controller.AttackMove(KeyMouseReader.mouseState.Position.ToVector2()); } } } else { selection.Clear(); IAttackable s = gm.ClickSelect(KeyMouseReader.mouseState.Position.ToVector2(), faction); if (s != null) { selection.Add(s); } } selectionBox = new Rectangle(); } else if (KeyMouseReader.LeftButtonReleased()) { selection = gm.BoxSelect(selectionBox, faction); selectionBox = new Rectangle(); } if (KeyMouseReader.LeftButtonReleased()) { aPressed = false; rPressed = false; } if (KeyMouseReader.KeyPressed(Keys.S)) //Stop { foreach (IAttackable s in selection) { if (s is Unit) { (s as Unit).Controller.Stop(); } } } if (KeyMouseReader.KeyPressed(Keys.A)) //Attack { aPressed = true; } if (KeyMouseReader.KeyPressed(Keys.H)) //Hold position { foreach (IAttackable s in selection) { if (s is Unit) { (s as Unit).Controller.HoldPosition(); } } } if (KeyMouseReader.KeyPressed(Keys.R)) { //Attack rPressed = true; } //UGLY!!! if (KeyMouseReader.RightClick()) { Attackable a = gm.GetAttackableAtLocation(KeyMouseReader.mouseState.Position.ToVector2(), faction); if (a != null) { foreach (IAttackable s in selection) { if (s is Unit) { (s as Unit).Controller.Attack(a); } } } else { Path p = null; foreach (IAttackable s in selection) { if (s is Unit) { if (p == null) { p = gm.GetPath(s.Position, KeyMouseReader.mouseState.Position.ToVector2()); } (s as Unit).Controller.FollowPath(p); } } } } }
public override void Update(GameTime gameTime) { if (KeyMouseReader.KeyPressed(Keys.P)) { ClickCounter++; switch (ClickCounter % 7) { case 0: SelectedObject = ObjectEnum.Platform; break; case 1: SelectedObject = ObjectEnum.VerticalPlatform; break; case 2: SelectedObject = ObjectEnum.HorizontalPlatform; break; case 3: SelectedObject = ObjectEnum.SpikePlatform; break; case 4: SelectedObject = ObjectEnum.CloudPlatform; break; case 5: SelectedObject = ObjectEnum.IcePlatform; break; case 6: SelectedObject = ObjectEnum.FadingPlatform; break; default: throw new ArgumentOutOfRangeException(); } } if (KeyMouseReader.KeyPressed(Keys.U)) { SelectedObject = ObjectEnum.Player; } if (KeyMouseReader.KeyPressed(Keys.G)) { SelectedObject = ObjectEnum.Goal; } if (Keyboard.GetState().IsKeyDown(Keys.E)) { SelectedObject = ObjectEnum.Enemy; } if (Keyboard.GetState().IsKeyDown(Keys.R)) { SelectedObject = ObjectEnum.WalkingEnemy; } if (Keyboard.GetState().IsKeyDown(Keys.C)) { SelectedObject = ObjectEnum.None; } if (Keyboard.GetState().IsKeyDown(Keys.Q)) { SelectedObject = ObjectEnum.UnlimitedPower; } if (Keyboard.GetState().IsKeyDown(Keys.W)) { SelectedObject = ObjectEnum.SlowWorld; } if (Keyboard.GetState().IsKeyDown(Keys.H)) { SelectedObject = ObjectEnum.HpGain; } if (KeyMouseReader.KeyPressed(Keys.S)) { SaveToFile(); } if (KeyMouseReader.KeyPressed(Keys.L)) { ReadFromFile(); } if (KeyMouseReader.KeyDown(Keys.Right)) { CamPos.X += 1; CamPos.Y += 0; } else if (KeyMouseReader.KeyDown(Keys.Left)) { CamPos.X += -1; CamPos.Y += 0; } if (KeyMouseReader.KeyDown(Keys.Up)) { CamPos.X += 0; CamPos.Y += -1; } else if (KeyMouseReader.KeyDown(Keys.Down)) { CamPos.X += 0; CamPos.Y += 1; } Cam.SetPos(CamPos); MousePosition = KeyMouseReader.MousePosition; var transform = Matrix.Invert(Cam.GetTransform()); Vector2.Transform(ref MousePosition, ref transform, out MousePosition); PlacePosition = MousePosition; if (Objects.Count > 0 && SelectedObject != ObjectEnum.Player) { var closestObj = Objects[0]; foreach (var obj in Objects) { if (Vector2.Distance(obj.GetCenter(), MousePosition) < Vector2.Distance(closestObj.GetCenter(), MousePosition)) { closestObj = obj; } } if (Vector2.Distance(closestObj.GetCenter(), MousePosition) < 25) { PlacePosition = closestObj.GetCenter().X - MousePosition.X < 0 ? new Vector2(closestObj.Dest.Right, closestObj.Dest.Top) : new Vector2(closestObj.Dest.Left - closestObj.Dest.Width, closestObj.Dest.Top); } } if (KeyMouseReader.LeftClick()) { switch (SelectedObject) { case ObjectEnum.Platform: Objects.Add(new Platform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.VerticalPlatform: Objects.Add(new VerticalPlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.HorizontalPlatform: Objects.Add(new HorizontalPlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.SpikePlatform: Objects.Add(new SpikePlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.CloudPlatform: Objects.Add(new CloudPlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.IcePlatform: Objects.Add(new IcePlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.FadingPlatform: Objects.Add(new FadingPlatform(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.Player: Objects.Add(new Player(PlacePosition, TextureManager.NogardAbilitySpritesheet)); break; case ObjectEnum.Enemy: Objects.Add(new BaseEnemy(MousePosition, TextureManager.EnemySpritesheet)); break; case ObjectEnum.WalkingEnemy: Objects.Add(new StandardEnemy(MousePosition, TextureManager.EnemySpritesheet)); break; case ObjectEnum.FlyingEnemy: Objects.Add(new FlyingEnemy(MousePosition, TextureManager.EnemySpritesheet)); break; case ObjectEnum.Goal: Objects.Add(new Goal(PlacePosition, TextureManager.PlatformSpritesheet)); break; case ObjectEnum.None: Objects.RemoveAll(item => Vector2.Distance(item.GetCenter(), MousePosition) < 25); break; case ObjectEnum.UnlimitedPower: Objects.Add(new UnlimitedPowerObject(PlacePosition, TextureManager.UnlimitedPowerTex)); break; case ObjectEnum.SlowWorld: Objects.Add(new SlowWorldPowerObject(PlacePosition, TextureManager.SlowWorldTex)); break; case ObjectEnum.HpGain: Objects.Add(new HealthGain(PlacePosition, TextureManager.HpGainTex)); break; default: throw new ArgumentOutOfRangeException(); } } }
protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); } KeyMouseReader.Update(); foreach (Ship s in p1_ships) { s.Update(gameTime); } foreach (Ship s in p2_ships) { s.Update(gameTime); } foreach (Tile g in p1_grid) { g.Update(gameTime); } foreach (Tile g in p2_grid) { g.Update(gameTime); } if (!running) { if (!ship_placement) { if (KeyMouseReader.LeftClick() && KeyMouseReader.mouse_position.X < 500 && !grab_p1) { ship_to_move = ship_selected(); if (ship_to_move != null) { grab_p1 = true; } } else if (grab_p1) { ship_to_move.ship_pos = new Vector2(KeyMouseReader.mouse_position.X, KeyMouseReader.mouse_position.Y); if (KeyMouseReader.LeftClick()) { if (ship_on_ship()) { ship_to_move.ship_pos.X = (((int)ship_to_move.ship_pos.X / 50) * 50 + ship_to_move.ship_frame_size.Y / 2 + 3); ship_to_move.ship_pos.Y = (((int)ship_to_move.ship_pos.Y / 50) * 50 + ship_to_move.ship_frame_size.Y / 2 + 3); grab_p1 = false; } if (ship_to_move.ship_bounding_box.Right >= 500 || ship_to_move.ship_bounding_box.Top <= 3 || ship_to_move.ship_bounding_box.Left <= 3 || ship_to_move.ship_bounding_box.Bottom >= 500) { grab_p1 = true; } } } if (Keyboard.GetState().IsKeyDown(Keys.Space) && grab_p1 == false) { ship_placement = true; } } if (ship_placement && !play) { if (KeyMouseReader.LeftClick() && KeyMouseReader.mouse_position.X > 700 && !grab_p2) { ship_to_move = ship_selected(); if (ship_to_move != null) { grab_p2 = true; } } else if (grab_p2) { ship_to_move.ship_pos = new Vector2(KeyMouseReader.mouse_position.X, KeyMouseReader.mouse_position.Y); if (KeyMouseReader.LeftClick()) { if (ship_on_ship()) { ship_to_move.ship_pos.X = (((int)ship_to_move.ship_pos.X / 50) * 50 + ship_to_move.ship_frame_size.Y / 2) - 3; ship_to_move.ship_pos.Y = (((int)ship_to_move.ship_pos.Y / 50) * 50 + ship_to_move.ship_frame_size.Y / 2) + 2; grab_p2 = false; } if (ship_to_move.ship_bounding_box.Right >= 1197 || ship_to_move.ship_bounding_box.Top <= 3 || ship_to_move.ship_bounding_box.Left <= 697 || ship_to_move.ship_bounding_box.Bottom >= 500) { grab_p2 = true; } } } if (Keyboard.GetState().IsKeyDown(Keys.Enter) && grab_p2 == false) { play = true; } } if (play == true) { if (KeyMouseReader.LeftClick()) { Tile tile = tile_selected(); if (tile != null && KeyMouseReader.mouse_position.X > 700 && KeyMouseReader.mouse_position.Y < 500 && !player_turn) { if (tile.hit == true || tile.miss == true) { shoot = false; } else { shoot = true; } if (shoot == true) { Ship temp = get_ship(tile.tile_bb); if (temp != null && tile.hit == false && tile.miss == false) { tile.hit = true; hit_p1 += 1; temp.ship_life -= 1; hit_sound.Play(); } else { tile.miss = true; miss_p1 += 1; miss_sound.Play(); } player_turn = true; } } if (tile != null && KeyMouseReader.mouse_position.X < 500 && KeyMouseReader.mouse_position.Y < 500 && player_turn) { if (tile.hit == true || tile.miss == true) { shoot = false; } else { shoot = true; } if (shoot == true) { Ship temp = get_ship(tile.tile_bb); if (temp != null && tile.hit == false && tile.miss == false) { tile.hit = true; hit_p2 += 1; temp.ship_life -= 1; hit_sound.Play(); } else { tile.miss = true; miss_p2 += 1; miss_sound.Play(); } player_turn = !player_turn; } } } } if (hit_p1 == 17 || hit_p2 == 17) { running = true; } base.Update(gameTime); } }
protected override void Update(GameTime gameTime) { KeyMouseReader.Update(); if (!gameOverSound && gameOver) { MediaPlayer.Stop(); MediaPlayer.IsRepeating = false; MediaPlayer.Play(gameOver_sfx); gameOverSound = true; } if (gameOver) { playerinfo = "Press enter to restart"; showPlayerInfo = true; if (Keyboard.GetState().IsKeyDown(Keys.Enter)) { Initialize(); } } if (KeyMouseReader.KeyPressed(Keys.P)) { paused = !paused; } if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); } if (showPlayerInfo) { playerinfoTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } if (playerinfoTime > 9) { showPlayerInfo = false; playerinfoTime = 0; } audioEngine.Update(); if (gameOver || paused) { return; } this.Window.Title = "AsteroidKiller Score: " + playerScore.ToString(); player.Update(); bg1.Update(); bg2.Update(); bg3.Update(); //Difficulty diffLevel = playerTime1 / 15 + playerScore / 10000; maxAsteroids = 10 + diffLevel * 3; rMinSpeed = 1 + diffLevel / 8; rMaxSpeed = 4 + diffLevel / 4; if (SpawnRate > 1) { SpawnRate = 200 - diffLevel * 7; } if (SpawnRate < 1) { SpawnRate = 1; } //Bullet logic foreach (Bullet bullet in bullets) { bullet.Update(); foreach (Asteroid asteroid in asteroids) { asteroid.Collision(bullet.hitbox); if (!piercingBullets) { bullet.Collision(asteroid.hitbox); } } } if (KeyMouseReader.LeftClickPressed() && nextShot >= 60 && !player.dead) { ShootBullet(); nextShot = 0; } if (nextShot < 60) { nextShot += shotRate; } for (int i = bullets.Count - 1; i >= 0; i--) { if (bullets[i].bulletHitAsteroid) { playerScore += 100; } if (bullets[i].removeBullet) { bullets.RemoveAt(i); } } //Asteroid Logic foreach (Asteroid asteroid in asteroids) { asteroid.Update(); player.Collision(asteroid.hitbox); } foreach (Asteroid asteroid in asteroids) { foreach (Asteroid asteroid2 in asteroids) { if (asteroid2 != asteroid && asteroid.scale > 0.7 && asteroid2.scale > 0.7) //Collision with other asteroids { asteroid.Collision(asteroid2.hitbox); asteroid2.Collision(asteroid.hitbox); } } if (asteroid.destroyAsteroid) { asteroid.texture = explosion_texture; } } foreach (Asteroid asteroid in asteroids) { if (asteroid.spawnDaughters) //Logic for spawning "daughter" asteroids { rHitbox = new Rectangle((int)asteroid.pos.X, (int)asteroid.pos.Y, asteroid_texture.Width, asteroid_texture.Height); Vector2 daughterSpeed, daughterSpeed2; daughterSpeed = new Vector2(asteroid.speed.X, rand.Next(-2, 2)); daughterSpeed2 = new Vector2(rand.Next(-2, 2), asteroid.speed.Y); asteroids.Add(new Asteroid(asteroid_texture, asteroid.pos, daughterSpeed, rHitbox, asteroid.scale / 2)); asteroids.Add(new Asteroid(asteroid_texture, asteroid.pos, daughterSpeed2, rHitbox, asteroid.scale / 2)); asteroid.spawnDaughters = false; break; } } nextSpawn += rand.Next(1, 5); if (nextSpawn >= SpawnRate && asteroids.Count < maxAsteroids) { SpawnRandom(); //Randomize position/speed of asteroid rScale = (11 - rand.Next(1, 4)) * 0.12f; //Randomize size of asteroid rHitbox = new Rectangle((int)rPos.X, (int)rPos.Y, asteroid_texture.Width, asteroid_texture.Height); asteroids.Add(new Asteroid(asteroid_texture, rPos, rSpeed, rHitbox, rScale)); nextSpawn = 0; } for (int i = asteroids.Count - 1; i >= 0; i--) //Goes through list in reverse order to avoid rearrangement in list { if (asteroids[i].destroyAsteroid && asteroids[i].animationTime > 10) { if (asteroidSounds < 3) //Prevents sound overlap from more than 3 explosions on the same frame { soundBank.PlayCue("boom6"); ++asteroidSounds; } asteroids.RemoveAt(i); } } asteroidSounds = 0; //Player Logic if (player.dead) { player.texture = player_explode; if (player.animationTime == 1) { soundBank.PlayCue("boom1"); } if (player.animationTime >= 100) //Checks to see whether animation has ended { player.pos = playerStartPos; player.speed = Vector2.Zero; player.texture = player_texture; playerLives -= 1; player.invulnerable = true; player.dead = false; } if (player.animationTime >= 100) { player.animationTime = 0; } } if (playerLives <= 0) { gameOver = true; } if (player.invulnerable) { playerInvulnerableCount += (float)gameTime.ElapsedGameTime.TotalSeconds; } if (playerInvulnerableCount >= playerInvulnerableTime) { player.invulnerable = false; playerInvulnerableCount = 0; } playerTime += (float)gameTime.ElapsedGameTime.TotalSeconds; playerTime1 = (int)playerTime; //Powerup logic powerup.Update(); if (!powerupExists) { powerupCounter += (float)gameTime.ElapsedGameTime.TotalSeconds; } if (powerupCounter >= nextPowerup) { SpawnRandom(); rHitbox = new Rectangle((int)rPos.X, (int)rPos.Y, powerup_texture.Width, powerup_texture.Height); powerup = new Powerup(powerup_texture, rPos, rSpeed * 0.5f, rHitbox, rand.Next(1, 6)); powerupExists = true; nextPowerup = rand.Next(10, 20); powerupCounter = 0; } powerup.Collision(player.hitbox); if (powerup.playerGotPowerup) { switch (powerup.id) { case 1: playerLives += 1; DisplayPlayerInfo(" Life up!"); soundBank.PlayCue("se_bonus"); break; case 2: shotRate = 14; powerupTime = 0; powerupActive = true; DisplayPlayerInfo(" Fire rate doubled!"); soundBank.PlayCue("se_ch02"); break; case 3: foreach (Asteroid asteroid in asteroids) { asteroid.destroyAsteroid = true; } DisplayPlayerInfo(" KABOOM"); soundBank.PlayCue("se_slash"); break; case 4: player.invulnerable = true; playerInvulnerableCount = -7; DisplayPlayerInfo(" Invulnerability!"); soundBank.PlayCue("se_chargeup"); break; case 5: piercingBullets = true; shotRate = 5; powerupTime = 0; powerupActive = true; DisplayPlayerInfo(" Asteroids are made of cheese!"); soundBank.PlayCue("se_charge00"); break; } powerup = new Powerup(powerup_texture, Vector2.Zero, Vector2.Zero, new Rectangle(-10, -10, 0, 0), 0); powerupExists = false; } if (powerupActive) { powerupTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } if (powerupTime >= 10) { shotRate = 7; piercingBullets = false; powerupActive = false; powerupTime = 0; } base.Update(gameTime); }