private void movePlayerUp(int distance, GameInit gameInit) { if (upDistance < MAX_MOVE) { if (upDistance + distance >= MAX_MOVE) { gameInit.getPlayer().moveUp(MAX_MOVE - upDistance); } else { gameInit.getPlayer().moveUp(distance); upDistance += distance; } } }
private void movePlayerDown(int distance, GameInit gameInit) { if (downDistance < MAX_MOVE) { if (downDistance + distance >= MAX_MOVE) { gameInit.getPlayer().moveDown(MAX_MOVE - downDistance); } else { gameInit.getPlayer().moveDown(distance); downDistance += distance; } } }
private void movePlayerRight(int distance, GameInit gameInit) { if (rightDistance < MAX_MOVE) { if (rightDistance + distance >= MAX_MOVE) { gameInit.getPlayer().moveRight(MAX_MOVE - rightDistance); } else { gameInit.getPlayer().moveRight(distance); rightDistance += distance; } } }
private void movePlayerLeft(int distance, GameInit gameInit) { if (leftDistance < MAX_MOVE) { if (leftDistance + distance >= MAX_MOVE) { gameInit.getPlayer().moveLeft(MAX_MOVE - leftDistance); } else { gameInit.getPlayer().moveLeft(distance); leftDistance += distance; } } }
public void executeAction(GameInit gameInit) { if (currentAction == ACTIVATE) { } else if (currentAction == ENTER) { } else if (currentAction == INSPECT) { } else if (currentAction == OPEN) { } else if (currentAction == TALK) { int direction = gameInit.getPlayer().getFacingDirection(); if (direction == 0) { interactingNPC.turn(1); interactingNPC.setNewAnimation(gameInit.getContentHandler().getNPCContentHandler().getNPCImages()[interactingNPC.getName()]["STATIONARY_DOWN"]); } else if (direction == 1) { interactingNPC.turn(0); interactingNPC.setNewAnimation(gameInit.getContentHandler().getNPCContentHandler().getNPCImages()[interactingNPC.getName()]["STATIONARY_UP"]); } else if (direction == 2) { interactingNPC.turn(3); interactingNPC.setNewAnimation(gameInit.getContentHandler().getNPCContentHandler().getNPCImages()[interactingNPC.getName()]["STATIONARY_LEFT"]); } else if (direction == 3) { interactingNPC.turn(2); interactingNPC.setNewAnimation(gameInit.getContentHandler().getNPCContentHandler().getNPCImages()[interactingNPC.getName()]["STATIONARY_RIGHT"]); } gameInit.getGameState().setChatState(); gameInit.getChatKeyHandler().fadeIn(interactingNPC); } }
private void lateralMove(int direction, GameInit gameInit) { if (direction == 0) { Vector2 start = gameInit.getPlayer().getLocation() + new Vector2(0, -2); int level = gameInit.getPlayer().getLevel(); if (start.Y >= 0) { int hits = 0; for (int i = 0; i < gameInit.getPlayer().getWalkingSize().X; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X + i) / 30, (int)start.Y / 30, level); if (!tile.checkAvailability(((int)start.X + i) % 30, (int)start.Y % 30, level)) { hits++; } } if (hits == 0) { start += new Vector2(0, -2); if (start.Y < 0) { movePlayerUp(2, gameInit); } else { for (int i = 0; i < gameInit.getPlayer().getWalkingSize().X; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X + i) / 30, (int)start.Y / 30, level); if (!tile.checkAvailability(((int)start.X + i) % 30, (int)start.Y % 30, level)) { hits++; movePlayerUp(2, gameInit); } } if (hits == 0) { movePlayerUp(4, gameInit); } } } } } else if (direction == 1) { Vector2 start = gameInit.getPlayer().getLocation() + new Vector2(0, 2 + gameInit.getPlayer().getWalkingSize().Y - 1); int level = gameInit.getPlayer().getLevel(); if (start.Y < gameInit.getCurrentZone().getPixelHeight()) { int hits = 0; for (int i = 0; i < gameInit.getPlayer().getWalkingSize().X; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X + i) / 30, (int)start.Y / 30, level); if (!tile.checkAvailability(((int)start.X + i) % 30, (int)start.Y % 30, level)) { hits++; } } if (hits == 0) { start += new Vector2(0, 2); if (start.Y >= gameInit.getCurrentZone().getPixelHeight()) { movePlayerDown(2, gameInit); } else { for (int i = 0; i < gameInit.getPlayer().getWalkingSize().X; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X + i) / 30, (int)start.Y / 30, level); if (!tile.checkAvailability(((int)start.X + i) % 30, (int)start.Y % 30, level)) { hits++; movePlayerDown(2, gameInit); } } if (hits == 0) { movePlayerDown(4, gameInit); } } } } } else if (direction == 2) { Vector2 start = gameInit.getPlayer().getLocation() + new Vector2(2 + gameInit.getPlayer().getWalkingSize().X - 1, 0); int level = gameInit.getPlayer().getLevel(); if (start.X < gameInit.getCurrentZone().getPixelWidth()) { int hits = 0; for (int i = 0; i < gameInit.getPlayer().getWalkingSize().Y; i++) { Tile tile = gameInit.getCurrentZone().getTile((int)start.X / 30, ((int)start.Y + i) / 30, level); if (!tile.checkAvailability(((int)start.X) % 30, ((int)start.Y + i) % 30, level)) { hits++; } } if (hits == 0) { start += new Vector2(2, 0); if (start.X >= gameInit.getCurrentZone().getPixelWidth()) { movePlayerRight(2, gameInit); } else { for (int i = 0; i < gameInit.getPlayer().getWalkingSize().Y; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X) / 30, ((int)start.Y + i) / 30, level); if (!tile.checkAvailability(((int)start.X) % 30, ((int)start.Y + i) % 30, level)) { hits++; movePlayerRight(2, gameInit); } } if (hits == 0) { movePlayerRight(4, gameInit); } } } } } else if (direction == 3) { Vector2 start = gameInit.getPlayer().getLocation() + new Vector2(-2, 0); int level = gameInit.getPlayer().getLevel(); if (start.X >= 0) { int hits = 0; for (int i = 0; i < gameInit.getPlayer().getWalkingSize().Y; i++) { Tile tile = gameInit.getCurrentZone().getTile((int)start.X / 30, ((int)start.Y + i) / 30, level); if (!tile.checkAvailability(((int)start.X) % 30, ((int)start.Y + i) % 30, level)) { hits++; } } if (hits == 0) { start += new Vector2(-2, 0); if (start.X < 0) { movePlayerLeft(2, gameInit); } else { for (int i = 0; i < gameInit.getPlayer().getWalkingSize().Y; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X) / 30, ((int)start.Y + i) / 30, level); if (!tile.checkAvailability(((int)start.X) % 30, ((int)start.Y + i) % 30, level)) { hits++; movePlayerLeft(2, gameInit); } } if (hits == 0) { movePlayerLeft(4, gameInit); } } } } } }
public void updateLogic(GameInit gameInit, KeyHandler keyHandler, ContentHandler content) { actionPerformed = false; moveUp = false; moveDown = false; moveRight = false; moveLeft = false; upDistance = 0; downDistance = 0; rightDistance = 0; leftDistance = 0; duration = 0; if (gameInit.getPlayer().getAnimationState().isAnimationCancellable()) { if (keyHandler.isActionReady()) { } if (!actionPerformed) { int direction = getFacingDirection(keyHandler); if (direction != -1 && duration > MOVE_THRESHOLD) { currentState = WALK; if (direction == 0) { if (!moveDown) { checkMove(0, gameInit); } if (moveRight) { if (!moveLeft) { lateralMove(2, gameInit); } } if (moveLeft) { if (!moveRight) { lateralMove(3, gameInit); } } if (upDistance == 0) { blockedCounter++; } else { blockedCounter = 0; } } else if (direction == 1) { if (!moveUp) { checkMove(1, gameInit); } if (moveRight) { if (!moveLeft) { lateralMove(2, gameInit); } } if (moveLeft) { if (!moveRight) { lateralMove(3, gameInit); } } if (downDistance == 0) { blockedCounter++; } else { blockedCounter = 0; } } else if (direction == 2) { if (!moveLeft) { checkMove(2, gameInit); } if (moveUp) { if (!moveDown) { lateralMove(0, gameInit); } } if (moveDown) { if (!moveUp) { lateralMove(1, gameInit); } } if (rightDistance == 0) { blockedCounter++; } else { blockedCounter = 0; } } else if (direction == 3) { if (!moveRight) { checkMove(3, gameInit); } if (moveUp) { if (!moveDown) { lateralMove(0, gameInit); } } if (moveDown) { if (!moveUp) { lateralMove(1, gameInit); } } if (leftDistance == 0) { blockedCounter++; } else { blockedCounter = 0; } } if (blockedCounter > BLOCKED_THRESHOLD) { } } else { currentState = STAND; gameInit.getPlayer().setFacingDirection(direction); } // do animation stuff } previousState = currentState; } }
// check for npcs somewhere before move private void checkMove(int direction, GameInit gameInit) { if (direction == 0) { Vector2 start = gameInit.getPlayer().getLocation() + new Vector2(0, -2); int level = gameInit.getPlayer().getLevel(); if (start.Y >= 0) { int leftBump = 0; int rightBump = 0; int centerBump = 0; int hits = 0; for (int i = 0; i < gameInit.getPlayer().getWalkingSize().X; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X + i) / 30, (int)start.Y / 30, level); if (!tile.checkAvailability(((int)start.X + i) % 30, (int)start.Y % 30, level)) { hits++; if (i < BUMP_RIGHT) { rightBump++; } else if (i >= BUMP_LEFT) { leftBump++; } else { centerBump++; } } } if (hits != 0) { if (centerBump == 0) { if (leftBump > 0) { movePlayerLeft(2, gameInit); } else if (rightBump > 0) { movePlayerRight(2, gameInit); } } } else { start += new Vector2(0, -2); if (start.Y < 0) { movePlayerUp(2, gameInit); } else { for (int i = 0; i < gameInit.getPlayer().getWalkingSize().X; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X + i) / 30, (int)start.Y / 30, level); if (!tile.checkAvailability(((int)start.X + i) % 30, (int)start.Y % 30, level)) { hits++; movePlayerUp(2, gameInit); } } if (hits == 0) { movePlayerUp(4, gameInit); } } } } } else if (direction == 1) { Vector2 start = gameInit.getPlayer().getLocation() + new Vector2(0, 2 - 1 + gameInit.getPlayer().getWalkingSize().Y); int level = gameInit.getPlayer().getLevel(); if (start.Y < gameInit.getCurrentZone().getPixelHeight()) { int leftBump = 0; int rightBump = 0; int centerBump = 0; int hits = 0; for (int i = 0; i < gameInit.getPlayer().getWalkingSize().X; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X + i) / 30, (int)start.Y / 30, level); if (!tile.checkAvailability(((int)start.X + i) % 30, (int)start.Y % 30, level)) { hits++; if (i < BUMP_RIGHT) { rightBump++; } else if (i >= BUMP_LEFT) { leftBump++; } else { centerBump++; } } } if (hits != 0) { if (centerBump == 0) { if (leftBump > 0) { movePlayerLeft(2, gameInit); } else if (rightBump > 0) { movePlayerRight(2, gameInit); } } } else { start += new Vector2(0, 2); if (start.Y >= gameInit.getCurrentZone().getPixelHeight()) { movePlayerDown(2, gameInit); } else { for (int i = 0; i < gameInit.getPlayer().getWalkingSize().X; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X + i) / 30, (int)start.Y / 30, level); if (!tile.checkAvailability(((int)start.X + i) % 30, (int)start.Y % 30, level)) { hits++; movePlayerDown(2, gameInit); } } if (hits == 0) { movePlayerDown(4, gameInit); } } } } } else if (direction == 2) { Vector2 start = gameInit.getPlayer().getLocation() + new Vector2(2 - 1 + gameInit.getPlayer().getWalkingSize().X, 0); int level = gameInit.getPlayer().getLevel(); if (start.X < gameInit.getCurrentZone().getPixelWidth()) { int rightBump = 0; int leftBump = 0; int centerBump = 0; int hits = 0; for (int i = 0; i < gameInit.getPlayer().getWalkingSize().Y; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X) / 30, ((int)start.Y + i) / 30, level); if (!tile.checkAvailability(((int)start.X) % 30, ((int)start.Y + i) % 30, level)) { hits++; if (i < BUMP_RIGHT) { rightBump++; } else if (i >= BUMP_LEFT) { leftBump++; } else { centerBump++; } } } if (hits != 0) { if (centerBump == 0) { if (leftBump > 0) { movePlayerDown(2, gameInit); } else if (rightBump > 0) { movePlayerUp(2, gameInit); } } } else { start += new Vector2(2, 0); if (start.X >= gameInit.getCurrentZone().getPixelWidth()) { movePlayerRight(2, gameInit); } else { for (int i = 0; i < gameInit.getPlayer().getWalkingSize().Y; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X) / 30, ((int)start.Y + i) / 30, level); if (!tile.checkAvailability(((int)start.X) % 30, ((int)start.Y + i) % 30, level)) { hits++; movePlayerRight(2, gameInit); } } if (hits == 0) { movePlayerRight(4, gameInit); } } } } } else if (direction == 3) { Vector2 start = gameInit.getPlayer().getLocation() + new Vector2(-2, 0); int level = gameInit.getPlayer().getLevel(); if (start.X >= 0) { int rightBump = 0; int leftBump = 0; int centerBump = 0; int hits = 0; for (int i = 0; i < gameInit.getPlayer().getWalkingSize().Y; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X) / 30, ((int)start.Y + i) / 30, level); if (!tile.checkAvailability(((int)start.X) % 30, ((int)start.Y + i) % 30, level)) { hits++; if (i < BUMP_RIGHT) { rightBump++; } else if (i >= BUMP_LEFT) { leftBump++; } else { centerBump++; } } } if (hits != 0) { if (centerBump == 0) { if (leftBump > 0) { movePlayerDown(2, gameInit); } else if (rightBump > 0) { movePlayerUp(2, gameInit); } } } else { start += new Vector2(-2, 0); if (start.X < 0) { movePlayerLeft(2, gameInit); } else { for (int i = 0; i < gameInit.getPlayer().getWalkingSize().Y; i++) { Tile tile = gameInit.getCurrentZone().getTile(((int)start.X) / 30, ((int)start.Y + i) / 30, level); if (!tile.checkAvailability(((int)start.X) % 30, ((int)start.Y + i) % 30, level)) { hits++; movePlayerLeft(2, gameInit); } } if (hits == 0) { movePlayerLeft(4, gameInit); } } } } } }
private void checkIfPushContinue(GameInit gameInit, KeyboardState keyboardState) { int direction = gameInit.getPlayer().getFacingDirection(); if (direction == 0) { if (keyboardState.IsKeyDown(DOWN_MOVE)) { pushing = false; pushingCounter = 0; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_UP"]); } if (keyboardState.IsKeyDown(RIGHT_MOVE)) { pushing = false; pushingCounter = 0; walking = true; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["WALK_UP"]); moveRightFlag = true; } if (keyboardState.IsKeyDown(LEFT_MOVE)) { pushing = false; pushingCounter = 0; walking = true; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["WALK_UP"]); moveLeftFlag = true; } if (!keyboardState.IsKeyDown(DOWN_MOVE) && !keyboardState.IsKeyDown(RIGHT_MOVE) && !keyboardState.IsKeyDown(LEFT_MOVE)) { if (gameInit.getPlayer().isAnimationFinished()) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["PUSH_UP"]); } else { gameInit.getPlayer().advanceCurrentAnimation(); } } } else if (direction == 1) { if (keyboardState.IsKeyDown(UP_MOVE)) { pushing = false; pushingCounter = 0; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_DOWN"]); } if (keyboardState.IsKeyDown(RIGHT_MOVE)) { pushing = false; pushingCounter = 0; walking = true; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["WALK_DOWN"]); moveRightFlag = true; } if (keyboardState.IsKeyDown(LEFT_MOVE)) { pushing = false; pushingCounter = 0; walking = true; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["WALK_DOWN"]); moveLeftFlag = true; } if (!keyboardState.IsKeyDown(UP_MOVE) && !keyboardState.IsKeyDown(RIGHT_MOVE) && !keyboardState.IsKeyDown(LEFT_MOVE)) { if (gameInit.getPlayer().isAnimationFinished()) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["PUSH_DOWN"]); } else { gameInit.getPlayer().advanceCurrentAnimation(); } } } else if (direction == 2) { if (keyboardState.IsKeyDown(DOWN_MOVE)) { pushing = false; pushingCounter = 0; walking = true; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["WALK_RIGHT"]); moveDownFlag = true; } if (keyboardState.IsKeyDown(UP_MOVE)) { pushing = false; pushingCounter = 0; walking = true; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["WALK_RIGHT"]); moveUpFlag = true; } if (keyboardState.IsKeyDown(LEFT_MOVE)) { pushing = false; pushingCounter = 0; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_RIGHT"]); } if (!keyboardState.IsKeyDown(DOWN_MOVE) && !keyboardState.IsKeyDown(UP_MOVE) && !keyboardState.IsKeyDown(LEFT_MOVE)) { if (gameInit.getPlayer().isAnimationFinished()) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["PUSH_RIGHT"]); } else { gameInit.getPlayer().advanceCurrentAnimation(); } } } else if (direction == 3) { if (keyboardState.IsKeyDown(DOWN_MOVE)) { pushing = false; pushingCounter = 0; walking = true; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["WALK_LEFT"]); moveDownFlag = true; } if (keyboardState.IsKeyDown(RIGHT_MOVE)) { pushing = false; pushingCounter = 0; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_LEFT"]); } if (keyboardState.IsKeyDown(UP_MOVE)) { pushing = false; pushingCounter = 0; walking = true; gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["WALK_LEFT"]); moveUpFlag = true; } if (!keyboardState.IsKeyDown(DOWN_MOVE) && !keyboardState.IsKeyDown(RIGHT_MOVE) && !keyboardState.IsKeyDown(UP_MOVE)) { if (gameInit.getPlayer().isAnimationFinished()) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["PUSH_LEFT"]); } else { gameInit.getPlayer().advanceCurrentAnimation(); } } } }
private void setStationaryAnimation(GameInit gameInit) { int direction = gameInit.getPlayer().getFacingDirection(); if (direction == 0) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_UP"]); } else if (direction == 1) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_DOWN"]); } else if (direction == 2) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_RIGHT"]); } else if (direction == 3) { gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["STATIONARY_LEFT"]); } }
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 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); }
public void lookForAction(GameInit gameInit) { // anything that can be interacted with will be at least 1 tile in size and have a size that is a multiple of tile size talkToNPC = false; int xTile = (int)gameInit.getPlayer().getGlobalLocation().X / 30; int yTile = (int)gameInit.getPlayer().getGlobalLocation().Y / 30; int xOff = (int)gameInit.getPlayer().getGlobalLocation().X % 30; int yOff = (int)gameInit.getPlayer().getGlobalLocation().Y % 30; int direction = gameInit.getPlayer().getFacingDirection(); if (direction == 0) { if (yOff == 0) { checkForNPCs(gameInit); } else { checkForNPCs(gameInit); } } else if (direction == 1) { if (yOff == 0) { checkForNPCs(gameInit); } else { checkForNPCs(gameInit); } } else if (direction == 2) { if (xOff == 0) { checkForNPCs(gameInit); } else { checkForNPCs(gameInit); } } else if (direction == 3) { if (xOff == 0) { checkForNPCs(gameInit); } else { checkForNPCs(gameInit); } } }
private void beginDrain(GameInit gameInit) { drainTiles.Clear(); int direction = gameInit.getPlayer().getFacingDirection(); if (direction == 0) { drainCenter = gameInit.getPlayer().getGlobalLocation() + new Vector2(15, -15); gameInit.getPlayer().setNewAbilityAnimation(gameInit.getContentHandler().getAbilityContentHandler().getAbilityAnimations()["CIRCLEGROWUP"], gameInit.getContentHandler().getAbilityContentHandler().getAbilityAnimationOffsets()["CIRCLEGROWUP"]); gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["DRAIN_UP"]); } else if (direction == 1) { drainCenter = gameInit.getPlayer().getGlobalLocation() + new Vector2(15, 45); gameInit.getPlayer().setNewAbilityAnimation(gameInit.getContentHandler().getAbilityContentHandler().getAbilityAnimations()["CIRCLEGROWDOWN"], gameInit.getContentHandler().getAbilityContentHandler().getAbilityAnimationOffsets()["CIRCLEGROWDOWN"]); gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["DRAIN_DOWN"]); } else if (direction == 2) { drainCenter = gameInit.getPlayer().getGlobalLocation() + new Vector2(45, 15); gameInit.getPlayer().setNewAbilityAnimation(gameInit.getContentHandler().getAbilityContentHandler().getAbilityAnimations()["CIRCLEGROWRIGHT"], gameInit.getContentHandler().getAbilityContentHandler().getAbilityAnimationOffsets()["CIRCLEGROWRIGHT"]); gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["DRAIN_RIGHT"]); } else if (direction == 3) { drainCenter = gameInit.getPlayer().getGlobalLocation() + new Vector2(-15, 15); gameInit.getPlayer().setNewAbilityAnimation(gameInit.getContentHandler().getAbilityContentHandler().getAbilityAnimations()["CIRCLEGROWLEFT"], gameInit.getContentHandler().getAbilityContentHandler().getAbilityAnimationOffsets()["CIRCLEGROWLEFT"]); gameInit.getPlayer().setNewAnimation(gameInit.getContentHandler().getPlayerContentHandler().getPlayerAnimations()["DRAIN_LEFT"]); } drainCounter++; drainRadius = 10; //fillDrainTiles(gameInit); }
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; } } }