public EpicRPG() { instance = this; this.Window.Title = "EPIC RPG"; this.Window.AllowUserResizing = true; OutputManager.getInstance().initializeGraphics(this); Content.RootDirectory = "Content"; this.gameState = State.GameState.INITIALIZING; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here currentState = State.GameState.Initializing; //Initialize Managers//// InterfaceManager.initializeInterfaceManager(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); MapManager.initializeMapManager(); InputManager.initializeInputManager(); base.Initialize(); currentState = State.GameState.Menu; }
/// <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) { InterfaceManager.getInstance().update(); InputManager.getInstance().Update(); //PERFORM UPDATE ACTIONS ACCORDING TO THE CURRENT STATE//// switch (state) { case State.GameState.Initializing: break; case State.GameState.Menu: break; case State.GameState.Load_Game: break; case State.GameState.Save_Game: break; case State.GameState.Character_Creation: currentPlayer = new Player(new Vector2(400, 300)); camera = new Camera(currentPlayer.getPos(), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); currentState = State.GameState.In_Play; break; case State.GameState.Paused: break; case State.GameState.Options: break; case State.GameState.In_Play: MapManager.getInstance().currentMap.update(); //currentPlayer.move(State.Direction.South); camera.update(); break; } base.Update(gameTime); }
public void Update() { PreviousKeyboardState = CurrentKeyboardState; CurrentKeyboardState = Keyboard.GetState(); currentState = Fagblo.getInstance().currentState; switch (currentState) { case State.GameState.Menu: if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { //EXIT MENU } break; case State.GameState.Load_Game: if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { //EXIT MENU } break; case State.GameState.Save_Game: if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { //EXIT MENU } break; case State.GameState.Character_Creation: if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { //EXIT MENU } break; case State.GameState.Paused: if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { //EXIT MENU } break; case State.GameState.Options: if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { //EXIT MENU } break; case State.GameState.In_Play: if (Keyboard.GetState().IsKeyDown(Keys.W) && Keyboard.GetState().IsKeyDown(Keys.A)) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Moving; Fagblo.getInstance().currentPlayer.move(State.Direction.NorthWest); } else if (Keyboard.GetState().IsKeyDown(Keys.W) && Keyboard.GetState().IsKeyDown(Keys.D)) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Moving; Fagblo.getInstance().currentPlayer.move(State.Direction.NorthEast); } else if (Keyboard.GetState().IsKeyDown(Keys.S) && Keyboard.GetState().IsKeyDown(Keys.A)) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Moving; Fagblo.getInstance().currentPlayer.move(State.Direction.SouthWest); } else if (Keyboard.GetState().IsKeyDown(Keys.S) && Keyboard.GetState().IsKeyDown(Keys.D)) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Moving; Fagblo.getInstance().currentPlayer.move(State.Direction.SouthEast); } else if (Keyboard.GetState().IsKeyDown(Keys.W)) { //MOVE PLAYER UP Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Moving; Fagblo.getInstance().currentPlayer.move(State.Direction.North); } else if (Keyboard.GetState().IsKeyDown(Keys.S)) { //MOVE PLAYER DOWN Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Moving; Fagblo.getInstance().currentPlayer.move(State.Direction.South); } else if (Keyboard.GetState().IsKeyDown(Keys.D)) { //MOVE PLAYER RIGHT Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Moving; Fagblo.getInstance().currentPlayer.move(State.Direction.East); } else if (Keyboard.GetState().IsKeyDown(Keys.A)) { //MOVE PLAYER LEFT Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Moving; Fagblo.getInstance().currentPlayer.move(State.Direction.West); } if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { //OPEN MENU } if (Keyboard.GetState().IsKeyDown(Keys.N)) { //OPEN CHARACTER MENU } if (Keyboard.GetState().IsKeyDown(Keys.I)) { //OPEN INVENTORY } if (Keyboard.GetState().IsKeyDown(Keys.M)) { //OPEN MAP MENU } if (Keyboard.GetState().IsKeyDown(Keys.P)) { //PAUSE GAME } if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { //OPEN OPTIONS } if (Keyboard.GetState().IsKeyDown(Keys.F8)) { //OPEN SAVE MENU } if (Keyboard.GetState().IsKeyDown(Keys.F9)) { //OPEN LOAD MENU } //MOVING TO IDLE STATE CHANGES if (PreviousKeyboardState.IsKeyDown(Keys.W) == true && CurrentKeyboardState.IsKeyUp(Keys.W) == true) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Idle; } if (PreviousKeyboardState.IsKeyDown(Keys.S) == true && CurrentKeyboardState.IsKeyUp(Keys.S) == true) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Idle; } if (PreviousKeyboardState.IsKeyDown(Keys.D) == true && CurrentKeyboardState.IsKeyUp(Keys.D) == true) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Idle; } if (PreviousKeyboardState.IsKeyDown(Keys.A) == true && CurrentKeyboardState.IsKeyUp(Keys.A) == true) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Idle; } //NE if (PreviousKeyboardState.IsKeyDown(Keys.W) && PreviousKeyboardState.IsKeyDown(Keys.D) == true && CurrentKeyboardState.IsKeyUp(Keys.W) && CurrentKeyboardState.IsKeyUp(Keys.D) == true) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Idle; } //NW if (PreviousKeyboardState.IsKeyDown(Keys.W) && PreviousKeyboardState.IsKeyDown(Keys.A) == true && CurrentKeyboardState.IsKeyUp(Keys.W) && CurrentKeyboardState.IsKeyUp(Keys.A) == true) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Idle; } //SE if (PreviousKeyboardState.IsKeyDown(Keys.S) && PreviousKeyboardState.IsKeyDown(Keys.D) == true && CurrentKeyboardState.IsKeyUp(Keys.S) && CurrentKeyboardState.IsKeyUp(Keys.D) == true) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Idle; } //SW if (PreviousKeyboardState.IsKeyDown(Keys.S) && PreviousKeyboardState.IsKeyDown(Keys.A) == true && CurrentKeyboardState.IsKeyUp(Keys.S) && CurrentKeyboardState.IsKeyUp(Keys.A) == true) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Idle; } //determine if we're clicking the playfield if (InterfaceManager.getInstance().cursor.isLeftPressed() && InterfaceManager.getInstance().cursor.getPos().Y < InterfaceManager.getInstance().getUtilityBarBoundary()) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Attacking; //now to determine the direction //the basic algorithm will be to split up the playfield into 8 fields, one for all eight directions //once the field is split, we then find which one the cursor is in //i hate math Vector2 mousePos = InterfaceManager.getInstance().cursor.getPos(); Vector2 playerPos = MapManager.getInstance().currentMap.positionOnScreen(Fagblo.getInstance().currentPlayer.getPos()); double angle; //easy cases first if (mousePos.X == playerPos.X && mousePos.Y < playerPos.Y) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.North; } else if (mousePos.X == playerPos.X && mousePos.Y >= playerPos.Y) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.South; } else if (mousePos.X >= playerPos.X && mousePos.Y == playerPos.Y) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.East; } else if (mousePos.X < playerPos.X && mousePos.Y == playerPos.Y) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.West; } else { //quadrant based, man this sucks if (playerPos.X < mousePos.X && playerPos.Y > mousePos.Y) { angle = (180 / Math.PI) * Math.Atan((playerPos.Y - mousePos.Y) / (mousePos.X - playerPos.X)); } else if (playerPos.X > mousePos.X && playerPos.Y > mousePos.Y) { angle = 90 + (90 - (180 / Math.PI) * Math.Atan((playerPos.Y - mousePos.Y) / (playerPos.X - mousePos.X))); } else if (playerPos.X > mousePos.X && playerPos.Y < mousePos.Y) { angle = 180 + (180 / Math.PI) * Math.Atan((mousePos.Y - playerPos.Y) / (playerPos.X - mousePos.X)); } else if (playerPos.X < mousePos.X && playerPos.Y < mousePos.Y) { angle = 270 + (90 - (180 / Math.PI) * Math.Atan((mousePos.Y - playerPos.Y) / (mousePos.X - playerPos.X))); } else { angle = 0; } //NOW, find which field the cursor is in if (angle > 330 || angle <= 30) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.East; } else if (angle > 30 && angle <= 60) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.NorthEast; } else if (angle > 60 && angle <= 120) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.North; } else if (angle > 120 && angle <= 150) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.NorthWest; } else if (angle > 150 && angle <= 210) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.West; } else if (angle > 210 && angle <= 240) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.SouthWest; } else if (angle > 240 && angle <= 300) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.South; } else if (angle > 300 && angle <= 330) { Fagblo.getInstance().currentPlayer.playerDirection = State.Direction.SouthEast; } else { //if we got here, uh oh } } } //now check to see if we released if (InterfaceManager.getInstance().cursor.wasLeftJustReleased() && Fagblo.getInstance().currentPlayer.currentState == State.PlayerState.Attacking) { Fagblo.getInstance().currentPlayer.currentState = State.PlayerState.Idle; } break; } }
public void update() { this.mouseOverEnergy = false; this.mouseOverHealth = false; currentState = Fagblo.getInstance().currentState; cursor.update(); //UPDATE INTERFACE FOR THE CURRENT STATE//// switch (currentState) { case State.GameState.Menu: newGameButton.update(cursor); exitGameButton.update(cursor); //interactions//// if (newGameButton.wasJustPressed()) { Fagblo.getInstance().currentState = State.GameState.Character_Creation; newGameButton.committedAction(); } if (exitGameButton.wasJustPressed()) { Fagblo.getInstance().Exit(); exitGameButton.committedAction(); } break; case State.GameState.Load_Game: break; case State.GameState.Save_Game: break; case State.GameState.Character_Creation: backButton.update(cursor); //interactions//// if (backButton.wasJustPressed()) { Fagblo.getInstance().currentState = State.GameState.Menu; backButton.committedAction(); } break; case State.GameState.Paused: resumeButton.update(cursor); exitFromPausedButton.update(cursor); //interactions//// if (resumeButton.wasJustPressed()) { Fagblo.getInstance().currentState = State.GameState.In_Play; resumeButton.committedAction(); } if (exitFromPausedButton.wasJustPressed()) { Fagblo.getInstance().Exit(); exitFromPausedButton.committedAction(); } break; case State.GameState.Options: break; case State.GameState.In_Play: healthRatio = (float)Fagblo.getInstance().currentPlayer.health / Fagblo.getInstance().currentPlayer.maxHealth; energyRatio = (float)Fagblo.getInstance().currentPlayer.energy / Fagblo.getInstance().currentPlayer.maxEnergy; //if mouse cursor is hovering over health bar, tell the player their current/max health if (cursor.getPos().X >= screenWidth * 0.10 && cursor.getPos().X <= screenWidth * 0.10 + TextureBank.InterfaceTextures.healthBar.Width && cursor.getPos().Y >= screenHeight - 135 && cursor.getPos().Y <= screenHeight - 135 + TextureBank.InterfaceTextures.healthBar.Height) { this.mouseOverHealth = true; } //if mouse cursor is hovering over energy bar, tell the player their current/max energy if (cursor.getPos().X >= screenWidth * 0.55 && cursor.getPos().X <= screenWidth * 0.55 + TextureBank.InterfaceTextures.energyBar.Width && cursor.getPos().Y >= screenHeight - 135 && cursor.getPos().Y <= screenHeight - 135 + TextureBank.InterfaceTextures.energyBar.Height) { this.mouseOverEnergy = true; } utilityBarMenuButton.update(cursor); //interactions//// if (utilityBarMenuButton.wasJustPressed()) { Fagblo.getInstance().currentState = State.GameState.Paused; utilityBarMenuButton.committedAction(); } break; } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. OutputManager.getInstance().initializeSpriteBatch(GraphicsDevice); OutputManager.getInstance().setFonts(Content.Load<SpriteFont>(@"Arial")); EntityManager.getInstance().initializeEntityManager(); FileManager.getInstance().loadGameConfiguration(); MenuManager.getInstance().initializeMenuManager(); // TODO: use this.Content to load your game content here //done, ready to play this.gameState = State.GameState.MENU; }