public bool checkActions(GameInit gameInit, KeyHandler keyHandler, ContentHandler content) { if (keyHandler.isActionReady()) { if (checkMainAction(gameInit, keyHandler)) { return true; } } if (keyHandler.isBackReady()) { return true; } if (keyHandler.isM1Ready()) { return true; } if (keyHandler.isM2Ready()) { return true; } return false; }
public void createRegion(GameInit gameInit, ContentHandler content, int regionNumber, int zoneNumber) { gameInit.getFreeRoamState().setCurrentRegion(regionNumber); gameInit.getRegionFactory().getZoneFactories()[regionNumber].createZones(); gameInit.getFreeRoamState().setCurrentZones(gameInit.getRegionFactory().getZoneFactories()[regionNumber].getRegionZones()); gameInit.getFreeRoamState().setCurrentZone(zoneNumber); content.getRegionContent()[regionNumber].loadContent(); }
// should find some file and load from it public void loadGame(GameInit gameInit, ContentHandler content, TransitionHandler transitionHandler) { transitionHandler.createRegion(gameInit, content, 0, 0); gameInit.getParty().addPartyMember(gameInit.getCharacterFactory().createCharacter(0, 0)); gameInit.getParty().getPartyMembers()[0].setXPosition(50); gameInit.getParty().getPartyMembers()[0].setYPosition(50); gameInit.getParty().getPartyMembers()[0].setHeight(2); gameInit.getParty().getPartyMembers()[0].setFacingDirection(0); gameInit.getFreeRoamState().getCurrentZone().addCharacter(gameInit.getParty().getPartyMembers()[0], 50, 50); gameInit.getMessageBlockFactory().createRegionCharacterBlocks(0); gameInit.getGameState().setFreeRoamState(); }
public void updateLogic(GameInit gameInit, KeyHandler keyHandler, ContentHandler content) { if (gameInit.getGameState().getState() == gameInit.getGameState().START_STATE) { updateStartLogic(gameInit, keyHandler, content); } else if (gameInit.getGameState().getState() == gameInit.getGameState().FREE_ROAM_STATE) { updateFreeRoamLogic(gameInit, keyHandler, content); } else if (gameInit.getGameState().getState() == gameInit.getGameState().BATTLE_STATE) { updateBattleLogic(gameInit, keyHandler, content); } else if (gameInit.getGameState().getState() == gameInit.getGameState().PAUSE_STATE) { } }
public void draw(SpriteBatch spriteBatch, GameInit gameInit, ContentHandler contentHandler, Color color) { if (gameInit.getGameState().getState() == gameInit.getGameState().START_STATE) { drawStartState(spriteBatch, gameInit, contentHandler, color); } else if (gameInit.getGameState().getState() == gameInit.getGameState().FREE_ROAM_STATE) { drawFreeRoamState(spriteBatch, gameInit, contentHandler, color); } else if (gameInit.getGameState().getState() == gameInit.getGameState().BATTLE_STATE) { drawBattleState(spriteBatch, gameInit, contentHandler, color); } else if (gameInit.getGameState().getState() == gameInit.getGameState().PAUSE_STATE) { drawPauseState(spriteBatch, gameInit, contentHandler, color); } }
private void updateFreeRoamLogic(GameInit gameInit, KeyHandler keyHandler, ContentHandler content) { updateFreeRoamPlayerLogic(gameInit, keyHandler, content); }
private void drawBattleState(SpriteBatch spriteBatch, GameInit gameInit, ContentHandler contentHandler, Color color) { }
private void drawFreeRoamState(SpriteBatch spriteBatch, GameInit gameInit, ContentHandler contentHandler, Color color) { Zone currentZone = gameInit.getFreeRoamState().getCurrentZone(); List<Vector2> orderedTileList = currentZone.getTileLocations(); List<int> orderedImageList = currentZone.getImageIdentifiers(); List<Tile> orderedTiles = currentZone.getOrderedTiles(); for (int i = orderedTileList.Count - 1; i >= 0; i--) { Tile currentTile = orderedTiles[i]; int heightDiff = gameInit.getParty().getPartyMembers()[0].getHeight() - currentTile.getWalkingHeight(); int xDiff = gameInit.getParty().getPartyMembers()[0].getX() - (int)orderedTileList[i].X; int yDiff = gameInit.getParty().getPartyMembers()[0].getY() - (int)orderedTileList[i].Y; Vector2 playerOffset = gameInit.getParty().getPartyMembers()[0].getTileDrawOffset(); Vector2 drawLoc = -playerOffset + NORMALPLAYERDRAWLOCATION + TILEOFFSET + new Vector2((TILESIZE.X / 2) * (xDiff + yDiff), (TILESIZE.Y / 2) * (-xDiff + yDiff) + TILETHICKNESS * heightDiff); if (currentTile.isSloped()) { int direction = currentTile.getSlopedOrientation(); if (direction == 0) { if (checkIfDisplay(drawLoc, TILESIZE.X, TILESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getTopLeftSlope()[orderedImageList[i]], drawLoc, color); } } else if (direction == 1) { if (checkIfDisplay(drawLoc, TILESIZE.X, TILESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getTopRightSlope()[orderedImageList[i]], drawLoc, color); } } else if (direction == 2) { if (checkIfDisplay(drawLoc, TILESIZE.X, TILESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getBottomRightSlope()[orderedImageList[i]], drawLoc, color); } } else if (direction == 3) { if (checkIfDisplay(drawLoc, TILESIZE.X, TILESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getBottomLeftSlope()[orderedImageList[i]], drawLoc, color); } } else if (direction == 4) { if (checkIfDisplay(drawLoc, TILESIZE.X, TILESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getTopSlope()[orderedImageList[i]], drawLoc, color); } } else if (direction == 5) { if (checkIfDisplay(drawLoc, TILESIZE.X, TILESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getBottomSlope()[orderedImageList[i]], drawLoc, color); } } else if (direction == 6) { if (checkIfDisplay(drawLoc, TILESIZE.X, TILESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getRightSlope()[orderedImageList[i]], drawLoc, color); } } else if (direction == 7) { if (checkIfDisplay(drawLoc, TILESIZE.X, TILESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getLeftSlope()[orderedImageList[i]], drawLoc, color); } } } else { if (checkIfDisplay(drawLoc, TILESIZE.X, TILESIZE.Y + TILETHICKNESS * (Math.Abs(heightDiff) - 1))) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getTileImages()[orderedImageList[i]], drawLoc, color); } } // change this to look at next tiles if (orderedTileList[i].X == currentZone.getTileWidth() - 1) { for (int j = 0; j < currentTile.getWalkingHeight(); j++) { Vector2 leftEdgeLoc = drawLoc + new Vector2(0, TILESIZE.Y / 2 + TILETHICKNESS * (j + 1)); if (checkIfDisplay(leftEdgeLoc, EDGESIZE.X, EDGESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getLeftWallImages()[orderedImageList[i]], leftEdgeLoc, color); } } } else { int leftHeightDiff = currentTile.getWalkingHeight() - currentZone.getTileMap()[(int)orderedTileList[i].X + 1, (int)orderedTileList[i].Y].getWalkingHeight(); if (leftHeightDiff > 1) { for (int j = 0; j < leftHeightDiff - 1; j++) { Vector2 leftEdgeLoc = drawLoc + new Vector2(0, TILESIZE.Y / 2 + TILETHICKNESS * (j + 1)); if (checkIfDisplay(leftEdgeLoc, EDGESIZE.X, EDGESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getLeftWallImages()[orderedImageList[i]], leftEdgeLoc, color); } } } } if (orderedTileList[i].Y == 0) { for (int j = 0; j < currentTile.getWalkingHeight(); j++) { Vector2 rightEdgeLoc = drawLoc + new Vector2(0, TILESIZE.Y / 2 + TILETHICKNESS * (j + 1)) + new Vector2(TILESIZE.X / 2, 0); if (checkIfDisplay(rightEdgeLoc, EDGESIZE.X, EDGESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getRightWallImages()[orderedImageList[i]], rightEdgeLoc, color); } } } else { int rightHeightDiff = currentTile.getWalkingHeight() - currentZone.getTileMap()[(int)orderedTileList[i].X, (int)orderedTileList[i].Y - 1].getWalkingHeight(); if (rightHeightDiff > 1) { for (int j = 0; j < rightHeightDiff - 1; j++) { Vector2 rightEdgeLoc = drawLoc + new Vector2(0, TILESIZE.Y / 2 + TILETHICKNESS * (j + 1)) + new Vector2(TILESIZE.X / 2, 0); if (checkIfDisplay(rightEdgeLoc, EDGESIZE.X, EDGESIZE.Y)) { spriteBatch.Draw(contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getRightWallImages()[orderedImageList[i]], rightEdgeLoc, color); } } } } if (gameInit.getFreeRoamState().getCurrentZone().getTrafficMap().getObjectBooleanMap()[(int)orderedTileList[i].X, (int)orderedTileList[i].Y]) { ManipulatableObject obj = gameInit.getFreeRoamState().getCurrentZone().getTrafficMap().getObjectMap()[(int)orderedTileList[i].X, (int)orderedTileList[i].Y]; Texture2D texture = contentHandler.getRegionContent()[gameInit.getFreeRoamState().getCurrentRegion()].getObjectContent()[obj.getObjectAnimation().getID()]; int rectX = obj.getObjectAnimation().getColumn() * (int)obj.getObjectAnimation().getSectionSize().X; int rectY = obj.getObjectAnimation().getRow() * (int)obj.getObjectAnimation().getSectionSize().Y; int xSize = (int)obj.getObjectAnimation().getSpriteSize().X; int ySize = (int)obj.getObjectAnimation().getSpriteSize().Y; Rectangle rect = new Rectangle(rectX, rectY, xSize, ySize); spriteBatch.Draw(texture, drawLoc + obj.getDrawOffset(), rect, color); } // do the same for characters if (gameInit.getFreeRoamState().getCurrentZone().getTrafficMap().getCharacterBooleanMap()[(int)orderedTileList[i].X, (int)orderedTileList[i].Y]) { Character character = gameInit.getFreeRoamState().getCurrentZone().getTrafficMap().getCharacterMap()[(int)orderedTileList[i].X, (int)orderedTileList[i].Y]; if (character.getX() == orderedTileList[i].X && character.getY() == orderedTileList[i].Y) { Texture2D texture = contentHandler.getCharacterContent().getSpriteSheets()[character.getType()]; int rectX = character.getCharacterAnimations().getCurrentAnimationColumn() * (int)character.getCharacterAnimations().getAnimations().getSectionSize().X; int rectY = character.getCharacterAnimations().getCurrentAnimationRow() * (int)character.getCharacterAnimations().getAnimations().getSectionSize().Y; int xSize = (int)character.getCharacterAnimations().getAnimations().getSpriteSize().X; int ySize = (int)character.getCharacterAnimations().getAnimations().getSpriteSize().Y; if (checkIfDisplay(drawLoc + character.getTileDrawOffset() - TILEOFFSET, (float)xSize, (float)ySize)) { Rectangle rect = new Rectangle(rectX, rectY, xSize, ySize); spriteBatch.Draw(texture, drawLoc + character.getTileDrawOffset() - TILEOFFSET, rect, color); } } } if (gameInit.getFreeRoamState().showChatWindow()) { SpriteFont chatBoxFont = contentHandler.getChatContentHandler().getChatBoxFont(); string message = gameInit.getFreeRoamState().getMessage(); int size = (int)chatBoxFont.MeasureString(message).X; int index; if (size > 200) { index = size / 20 - 4 + 16; } else { index = size / 10 - 4; } if (index < 0) { index = 0; } else if (index >= contentHandler.getChatContentHandler().getChatBoxes().Count) { index = contentHandler.getChatContentHandler().getChatBoxes().Count - 1; } Vector2 chatDrawLoc; int direction = gameInit.getParty().getPartyMembers()[0].getFacingDirection(); if (direction == 0 || direction == 3) { if (size > 200) { chatDrawLoc = BIGBOTDRAW - new Vector2((size - 200) / 2, 0); } else { chatDrawLoc = SMALLBOTDRAW - new Vector2(size / 2, 0); } } else { if (size > 200) { chatDrawLoc = BIGTOPDRAW - new Vector2((size - 200)/ 2, 0); } else { chatDrawLoc = SMALLTOPDRAW - new Vector2(size / 2 , 0); } } spriteBatch.Draw(contentHandler.getChatContentHandler().getChatBox(index), chatDrawLoc, Color.White); int distance = 0; int line = 0; for (int j = 0; j < gameInit.getFreeRoamState().getParsedMessage().Count; j++) { string currentString = gameInit.getFreeRoamState().getParsedMessage()[j]; if (distance + (int)chatBoxFont.MeasureString(currentString).X > 50 + (index % 16) * 10) { distance = 0; line++; } spriteBatch.DrawString(chatBoxFont, currentString, chatDrawLoc + CHATWINDOWOFFSET + new Vector2(distance, 20 * line), Color.White); distance += (int)chatBoxFont.MeasureString(currentString).X; } List<string> options = gameInit.getFreeRoamState().getOptions(); if (options.Count != 0) { if (direction == 0 || direction == 3) { chatDrawLoc = BOTOPTION; } else { chatDrawLoc = TOPOPTION; } spriteBatch.Draw(contentHandler.getChatContentHandler().getOptionBox(options.Count), chatDrawLoc, Color.White); line = 0; for (int j = 0; j < options.Count; j++) { spriteBatch.DrawString(chatBoxFont, options[j], drawLoc + CHATWINDOWOFFSET + new Vector2(0, line * 20), Color.White); line++; } } else { } } } }
/// <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 npcAnimationContent = new ContentManager(Content.ServiceProvider, Content.RootDirectory); menuContent = new ContentManager(Content.ServiceProvider, Content.RootDirectory); zoneContent = new ContentManager(Content.ServiceProvider, Content.RootDirectory); battleContent = new ContentManager(Content.ServiceProvider, Content.RootDirectory); game = new GameInit(); debugger = new Debugger(); contentHandler = new ContentHandler(npcAnimationContent, menuContent, zoneContent, battleContent); paintHandler = new PaintHandler(); keyHandler = new KeyHandler(); logicHandler = new LogicHandler(); logicHandler.loadGame(game, contentHandler); base.Initialize(); }
private void updateStartLogic(GameInit gameInit, KeyHandler keyHandler, ContentHandler content) { }
public bool checkMove(GameInit gameInit, KeyHandler keyHandler, ContentHandler content) { int direction = getGreatestDirection(keyHandler); if (direction == 0) { gameInit.getParty().getPartyMembers()[0].setFacingDirection(0); if (keyHandler.getUpTime() < TURN_THRESHOLD) { return false; } else { if (checkHeight(gameInit, -1, 0) && checkAvailability(gameInit, -1, 0)) { return true; } else { return false; } } } else if (direction == 1) { gameInit.getParty().getPartyMembers()[0].setFacingDirection(1); if (keyHandler.getDownTime() < TURN_THRESHOLD) { return false; } else { if (checkHeight(gameInit, 1, 0) && checkAvailability(gameInit, 1, 0)) { return true; } else { return false; } } } else if (direction == 2) { gameInit.getParty().getPartyMembers()[0].setFacingDirection(2); if (keyHandler.getRightTime() < TURN_THRESHOLD) { return false; } else { if (checkHeight(gameInit, 0, -1) && checkAvailability(gameInit, 0, -1)) { return true; } else { return false; } } } else if (direction == 3) { gameInit.getParty().getPartyMembers()[0].setFacingDirection(3); if (keyHandler.getLeftTime() < TURN_THRESHOLD) { return false; } else { if (checkHeight(gameInit, 0, 1) && checkAvailability(gameInit, 0, 1)) { return true; } else { return false; } } } else { return false; } }
private void updateFreeRoamPlayerLogic(GameInit gameInit, KeyHandler keyHandler, ContentHandler content) { //Console.WriteLine("PLAYER X: " + gameInit.getParty().getPartyMembers()[0].getX()); //Console.WriteLine("PLAYER Y: " + gameInit.getParty().getPartyMembers()[0].getY()); //Console.WriteLine("HEIGHT: " + gameInit.getParty().getPartyMembers()[0].getHeight()); if (movementHandler.isMoving()) { movementHandler.updateMove(gameInit); } else if (transitionHandler.isTransitioning()) { transitionHandler.continueTransition(gameInit); drawColor = transitionHandler.getFadeColor(); } else if (actionHandler.isActivating()) { actionHandler.continueActivation(gameInit); if (actionHandler.isTransitionReady()) { transitionHandler.startTransition(gameInit, (Door)actionHandler.getTransitioningObject()); } } else if (actionHandler.showBigChat()) { } else if (actionHandler.showChatWindow()) { actionHandler.continueChatWindow(gameInit, keyHandler); } else { if (!actionHandler.checkActions(gameInit, keyHandler, content)) { if (!checkMove(gameInit, keyHandler, content)) { int x = gameInit.getParty().getPartyMembers()[0].getX(); int y = gameInit.getParty().getPartyMembers()[0].getY(); int direction = gameInit.getParty().getPartyMembers()[0].getFacingDirection(); if (gameInit.getFreeRoamState().getCurrentZone().getTileMap()[x, y].isTransition() && gameInit.getFreeRoamState().getCurrentZone().getTileMap()[x, y].getTransitionDirection() == direction) { gameInit.getParty().getPartyMembers()[0].setFacingDirection(gameInit.getFreeRoamState().getCurrentZone().getTileMap()[x, y].getTransitionDirection()); transitionHandler.startTransition(gameInit, gameInit.getFreeRoamState().getCurrentZone().getTileMap()[x, y]); } else { if (direction == 0) { gameInit.getParty().getPartyMembers()[0].getCharacterAnimations().setNewAnimation(0); if (gameInit.getFreeRoamState().getCurrentZone().getTileMap()[x, y].isSloped()) { gameInit.getParty().getPartyMembers()[0].setTileDrawOffset(new Vector2(0, 4)); } else { gameInit.getParty().getPartyMembers()[0].setTileDrawOffset(new Vector2(0, 0)); } } else if (direction == 1) { gameInit.getParty().getPartyMembers()[0].getCharacterAnimations().setNewAnimation(1); if (gameInit.getFreeRoamState().getCurrentZone().getTileMap()[x, y].isSloped()) { gameInit.getParty().getPartyMembers()[0].setTileDrawOffset(new Vector2(0, 4)); } else { gameInit.getParty().getPartyMembers()[0].setTileDrawOffset(new Vector2(0, 0)); } } else if (direction == 2) { gameInit.getParty().getPartyMembers()[0].getCharacterAnimations().setNewAnimation(2); if (gameInit.getFreeRoamState().getCurrentZone().getTileMap()[x, y].isSloped()) { gameInit.getParty().getPartyMembers()[0].setTileDrawOffset(new Vector2(0, 4)); } else { gameInit.getParty().getPartyMembers()[0].setTileDrawOffset(new Vector2(0, 0)); } } else if (direction == 3) { gameInit.getParty().getPartyMembers()[0].getCharacterAnimations().setNewAnimation(3); if (gameInit.getFreeRoamState().getCurrentZone().getTileMap()[x, y].isSloped()) { gameInit.getParty().getPartyMembers()[0].setTileDrawOffset(new Vector2(0, 4)); } else { gameInit.getParty().getPartyMembers()[0].setTileDrawOffset(new Vector2(0, 0)); } } } } else { movementHandler.movePlayer(gameInit); } } else { } } }
public void updateObjects(GameInit gameInit, ContentHandler content) { }
private void updateBattleLogic(GameInit gameInit, KeyHandler keyHandler, ContentHandler content) { }
private bool checkMove(GameInit gameInit, KeyHandler keyHandler, ContentHandler content) { return movementHandler.checkMove(gameInit, keyHandler, content); }
private bool checkMenu(GameInit gameInit, KeyHandler keyHandler, ContentHandler content) { return true; }
//pass in some save data as well public void loadGame(GameInit gameInit, ContentHandler content) { saveGameHandler.loadGame(gameInit, content, transitionHandler); }