private void pushObject(GameInit gameInit, ZoneTile pushingTile, ZoneTile destination) { if (pushingTile.isFull()) { if (destination.isFree() && destination.isPushable()) { if (pushingTile.getTileObject().isPushable()) { ManipulatableObject tileObject = pushingTile.getTileObject(); int direction = gameInit.getPlayer().getFacingDirection(); if (direction == 0) { tileObject.activate(gameInit.getContentHandler(), gameInit.getZoneFactory().getCurrentZone(), "PUSH_UP"); gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_UP"]); } else if (direction == 1) { tileObject.activate(gameInit.getContentHandler(), gameInit.getZoneFactory().getCurrentZone(), "PUSH_DOWN"); gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_DOWN"]); } else if (direction == 2) { tileObject.activate(gameInit.getContentHandler(), gameInit.getZoneFactory().getCurrentZone(), "PUSH_RIGHT"); gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_RIGHT"]); } else if (direction == 3) { tileObject.activate(gameInit.getContentHandler(), gameInit.getZoneFactory().getCurrentZone(), "PUSH_LEFT"); gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_LEFT"]); } //manipulatedObjects.Add(tileObject); animatingObject = tileObject; environmentAnimation = true; pushing = false; } } } }
private void animateObjects(GameInit gameInit) { List<ManipulatableObject> objectList = gameInit.getZoneFactory().getCurrentZone().getObjectList(); for (int i = 0; i < objectList.Count; i++) { ManipulatableObject currentObject = objectList[i]; if (currentObject.isStationary()) { if (currentObject.isAnimationFinished()) { currentObject.activate(gameInit.getContentHandler(), gameInit.getZoneFactory().getCurrentZone(), "STATIONARY"); } else { currentObject.advanceAnimation(); } } } }
private void movePlayer(GameInit gameInit) { int verticalCounter = 0; int horizontalCounter = 0; movementHandler.resetFlags(); if (moveUpFlag) { verticalCounter--; } if (moveDownFlag) { verticalCounter++; } if (moveRightFlag) { horizontalCounter++; } if (moveLeftFlag) { horizontalCounter--; } if (horizontalCounter > 0) { movementHandler.movePlayer(2, gameInit.getPlayer(), gameInit.getZoneFactory()); } else if (horizontalCounter < 0) { movementHandler.movePlayer(3, gameInit.getPlayer(), gameInit.getZoneFactory()); } if (verticalCounter > 0) { movementHandler.movePlayer(1, gameInit.getPlayer(), gameInit.getZoneFactory()); } else if (verticalCounter < 0) { movementHandler.movePlayer(0, gameInit.getPlayer(), gameInit.getZoneFactory()); } }
private void jump(GameInit gameInit, ZoneTile jumpingTile, ZoneTile destination) { int direction = gameInit.getPlayer().getFacingDirection(); if (jumpingTile.isJumpable()) { if (destination.getType() == 0) { if (destination.isFree()) { walking = false; jumping = true; pushingCounter = 0; if (direction == 0) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["JUMP_UP"]); } else if (direction == 1) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["JUMP_DOWN"]); } else if (direction == 2) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["JUMP_RIGHT"]); } else if (direction == 3) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["JUMP_LEFT"]); } gameInit.getPlayer().jump(direction); gameInit.getPlayer().setGlobalLocation(gameInit.getPlayer().getGlobalLocation() + gameInit.getPlayer().getJumpOffset()[gameInit.getPlayer().getAnimationIndex()]); movementHandler.updateDrawLocations(gameInit.getPlayer(), gameInit.getZoneFactory().getCurrentZone()); } } else if (destination.getType() == 1) { if (destination.isFull()) { walking = false; jumping = true; pushingCounter = 0; if (direction == 0) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["JUMP_UP"]); } else if (direction == 1) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["JUMP_DOWN"]); } else if (direction == 2) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["JUMP_RIGHT"]); } else if (direction == 3) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["JUMP_LEFT"]); } gameInit.getPlayer().jump(direction); gameInit.getPlayer().setGlobalLocation(gameInit.getPlayer().getGlobalLocation() + gameInit.getPlayer().getJumpOffset()[gameInit.getPlayer().getAnimationIndex()]); movementHandler.updateDrawLocations(gameInit.getPlayer(), gameInit.getZoneFactory().getCurrentZone()); } } else { walking = false; pushingCounter = 0; setStationaryAnimation(gameInit); } } else { pushing = true; walking = false; if (direction == 0) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["PUSH_UP"]); } else if (direction == 1) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["PUSH_DOWN"]); } else if (direction == 2) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["PUSH_RIGHT"]); } else if (direction == 3) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["PUSH_LEFT"]); } } }
private void drain(GameInit gameInit) { int xStart = (int)drainCenter.X - drainRadius; int yStart = (int)drainCenter.Y - drainRadius; int xTileStart; int yTileStart; int xLength; int yLength; int xTiles; int yTiles; if (xStart >= 0) { xTileStart = xStart / 30; xLength = 2 * drainRadius; xTiles = (xLength + 29 + xStart % 30) / 30; } else { xTileStart = 0; xLength = 2 * drainRadius + xStart; xTiles = (xLength + 29) / 30; } if (yStart >= 0) { yTileStart = yStart / 30; yLength = 2 * drainRadius; yTiles = (yLength + 29 + yStart % 30) / 30; } else { yTileStart = 0; yLength = 2 * drainRadius + yStart; yTiles = (yLength + 29) / 30; } Console.WriteLine("X: " + xTiles); Console.WriteLine("Y: " + yTiles); for (int i = 0; i < xTiles; i++) { for (int j = 0; j < yTiles; j++) { if (xTileStart + i > 0 && xTileStart + i < gameInit.getZoneFactory().getCurrentZone().getTileWidth()) { if (yTileStart + j > 0 && yTileStart + i < gameInit.getZoneFactory().getCurrentZone().getTileHeight()) { if (gameInit.getZoneFactory().getCurrentZone().getZoneTileMap().getTile(yTileStart + j, xTileStart + i, gameInit.getPlayer().getCurrentZoneLevel()).isObject()) { ManipulatableObject currentObject = gameInit.getZoneFactory().getCurrentZone().getZoneTileMap().getTile(yTileStart + j, xTileStart + i, gameInit.getPlayer().getCurrentZoneLevel()).getTileObject(); if (currentObject.getDrainAmount() != 0 && currentObject.getEnergy() != 0 && currentObject.isStationary()) { currentObject.activate(gameInit.getContentHandler(), gameInit.getZoneFactory().getCurrentZone(), "DRAIN"); gameInit.getPlayer().drainEnergy(currentObject.getDrainAmount(), currentObject.getEnergyType()); manipulatedObjects.Add(currentObject); } } } } } } Console.WriteLine(manipulatedObjects.Count); }
private void cleanManipulatedObjects(GameInit gameInit) { for (int i = 0; i < manipulatedObjects.Count; i++) { ManipulatableObject currentObject = manipulatedObjects[i]; if (currentObject.isAnimationFinished()) { manipulatedObjects.Remove(currentObject); currentObject.activate(gameInit.getContentHandler(), gameInit.getZoneFactory().getCurrentZone(), "STATIONARY"); } else { currentObject.advanceAnimation(); } } }
private void checkForNPCs(GameInit gameInit) { int direction = gameInit.getPlayer().getFacingDirection(); if (direction == 0) { int yLocation = (int)gameInit.getPlayer().getGlobalLocation().Y; int xLocation = (int)gameInit.getPlayer().getGlobalLocation().X; if (yLocation >= 0) { for (int i = 0; i < gameInit.getZoneFactory().getCurrentZone().getNPCs().Count; i++) { NPC currentNPC = gameInit.getZoneFactory().getCurrentZone().getNPCs()[i]; if (currentNPC.getCurrentLevel() == gameInit.getPlayer().getCurrentZoneLevel()) { int npcLocation = (int)currentNPC.getCurrentLocation().Y + (int)currentNPC.getSize().Y - 1; if (npcLocation < yLocation && npcLocation >= yLocation - 5) { if (currentNPC.getCurrentLocation().X >= xLocation && currentNPC.getCurrentLocation().X < xLocation + 30) { if (talkToNPC) { } else { currentAction = TALK; talkToNPC = true; interactingNPC = currentNPC; } } else if (currentNPC.getCurrentLocation().X + currentNPC.getSize().X - 1 >= xLocation && currentNPC.getCurrentLocation().X + currentNPC.getSize().X - 1 < xLocation + 30) { if (talkToNPC) { } else { currentAction = TALK; talkToNPC = true; interactingNPC = currentNPC; } } } } } } if (!talkToNPC) { currentAction = NONE; } } else if (direction == 1) { int yLocation = (int)gameInit.getPlayer().getGlobalLocation().Y; int xLocation = (int)gameInit.getPlayer().getGlobalLocation().X; if (yLocation < gameInit.getZoneFactory().getCurrentZone().getHeight()) { for (int i = 0; i < gameInit.getZoneFactory().getCurrentZone().getNPCs().Count; i++) { NPC currentNPC = gameInit.getZoneFactory().getCurrentZone().getNPCs()[i]; if (currentNPC.getCurrentLevel() == gameInit.getPlayer().getCurrentZoneLevel()) { int npcLocation = (int)currentNPC.getCurrentLocation().Y; if (npcLocation > yLocation + 29 && npcLocation <= yLocation + 29 + 5) { if (currentNPC.getCurrentLocation().X >= xLocation && currentNPC.getCurrentLocation().X < xLocation + 30) { if (talkToNPC) { } else { currentAction = TALK; talkToNPC = true; interactingNPC = currentNPC; } } else if (currentNPC.getCurrentLocation().X + currentNPC.getSize().X - 1 >= xLocation && currentNPC.getCurrentLocation().X + currentNPC.getSize().X - 1 < xLocation + 30) { if (talkToNPC) { } else { currentAction = TALK; talkToNPC = true; interactingNPC = currentNPC; } } } } } } if (!talkToNPC) { currentAction = NONE; } } else if (direction == 2) { int yLocation = (int)gameInit.getPlayer().getGlobalLocation().Y; int xLocation = (int)gameInit.getPlayer().getGlobalLocation().X; if (xLocation < gameInit.getZoneFactory().getCurrentZone().getWidth()) { for (int i = 0; i < gameInit.getZoneFactory().getCurrentZone().getNPCs().Count; i++) { NPC currentNPC = gameInit.getZoneFactory().getCurrentZone().getNPCs()[i]; if (currentNPC.getCurrentLevel() == gameInit.getPlayer().getCurrentZoneLevel()) { int npcLocation = (int)currentNPC.getCurrentLocation().X; if (npcLocation > xLocation + 29 && npcLocation <= xLocation + 29 + 5) { if (currentNPC.getCurrentLocation().Y >= yLocation && currentNPC.getCurrentLocation().Y < yLocation + 30) { if (talkToNPC) { } else { currentAction = TALK; talkToNPC = true; interactingNPC = currentNPC; } } else if (currentNPC.getCurrentLocation().Y + currentNPC.getSize().Y - 1 >= yLocation && currentNPC.getCurrentLocation().Y + currentNPC.getSize().Y < yLocation + 30) { if (talkToNPC) { } else { currentAction = TALK; talkToNPC = true; interactingNPC = currentNPC; } } } } } } if (!talkToNPC) { currentAction = NONE; } } else if (direction == 3) { int yLocation = (int)gameInit.getPlayer().getGlobalLocation().Y; int xLocation = (int)gameInit.getPlayer().getGlobalLocation().X; if (xLocation >= 0) { for (int i = 0; i < gameInit.getZoneFactory().getCurrentZone().getNPCs().Count; i++) { NPC currentNPC = gameInit.getZoneFactory().getCurrentZone().getNPCs()[i]; if (currentNPC.getCurrentLevel() == gameInit.getPlayer().getCurrentZoneLevel()) { int npcLocation = (int)currentNPC.getCurrentLocation().X + (int)currentNPC.getSize().X - 1; if (npcLocation < xLocation && npcLocation >= xLocation - 5) { if (currentNPC.getCurrentLocation().Y >= yLocation && currentNPC.getCurrentLocation().Y < yLocation + 30) { if (talkToNPC) { } else { currentAction = TALK; talkToNPC = true; interactingNPC = currentNPC; } } else if (currentNPC.getCurrentLocation().Y + currentNPC.getSize().Y - 1 >= yLocation && currentNPC.getCurrentLocation().Y + currentNPC.getSize().Y < yLocation + 30) { if (talkToNPC) { } else { currentAction = TALK; talkToNPC = true; interactingNPC = currentNPC; } } } } } } if (!talkToNPC) { currentAction = NONE; } } }