Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Rectangle> bounds= new ArrayList<Rectangle>();
- for (int i = 0; i < 250; i++)
- {
- for (int j = 0; j < 250; j++)
- {
- TiledMapTileLayer cur = (TiledMapTileLayer) map.getLayers().get(1);
- Cell cell3 = new Cell();
- if (cur.getCell(i, j) != null)
- {
- cell3 = cur.getCell(i, j);
- System.out.println("Found a chest detector at: " + i + ", " + j
- + ", " + cell3.getTile().getId());
- bounds.add(new Rectangle(i * 64, j * 64, 64, 64));
- }
- }
- }
- // CHECKING FOR TREES
- for (int i = 0; i < bounds.size(); i++)
- {
- if (bounds.get(i).overlaps(player.getBounds()))
- {
- int x = (int) bounds.get(i).x / 64;
- int y = (int) bounds.get(i).y / 64;
- TiledMapTileLayer cur = (TiledMapTileLayer) map.getLayers()
- .get(1);
- Cell cell = cur.getCell(x, y);
- if (cell.getTile().getProperties().containsKey("Green"))
- {
- if (Gdx.input.isKeyPressed(Keys.SPACE))
- {
- System.out.println("You've cut down a tree!");
- }
- }
- if (cell.getTile().getProperties().containsKey("Gray"))
- {
- player.reAdjust();
- }
- }
- }
- String movement = "";
- if (Gdx.input.isKeyPressed(Keys.W))
- {
- if (curEnergy > 0)
- {
- if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT))
- {
- position.y += 2.5f;
- movement = "up";
- curEnergy--;
- currentFrame = animation.getKeyFrame(12 + stateTime);
- }
- }
- else
- {
- allowRegen = true;
- checkIfEnergyIsZero();
- }
- position.y += 2f;
- movement = "up";
- currentFrame = animation.getKeyFrame(12 + stateTime);
- }
- if (Gdx.input.isKeyPressed(Keys.A))
- {
- if (curEnergy > 0)
- {
- if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT))
- {
- position.x -= 2.5f;
- movement = "left";
- curEnergy--;
- currentFrame = animation.getKeyFrame(4 + stateTime);
- }
- }
- else
- {
- allowRegen = true;
- checkIfEnergyIsZero();
- }
- position.x -= 2f;
- movement = "left";
- currentFrame = animation.getKeyFrame(4 + stateTime);
- }
- if (Gdx.input.isKeyPressed(Keys.D))
- {
- if (curEnergy > 0)
- {
- if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT))
- {
- position.x += 2.5f;
- movement = "right";
- curEnergy--;
- currentFrame = animation.getKeyFrame(8 + stateTime);
- }
- }
- else
- {
- allowRegen = true;
- checkIfEnergyIsZero();
- }
- position.x += 2f;
- movement = "right";
- currentFrame = animation.getKeyFrame(8 + stateTime);
- }
- if (Gdx.input.isKeyPressed(Keys.S))
- {
- if (curEnergy > 0)
- {
- if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT))
- {
- position.y -= 2.5f;
- movement = "down";
- curEnergy--;
- currentFrame = animation.getKeyFrame(0 + stateTime);
- }
- }
- else
- {
- allowRegen = true;
- checkIfEnergyIsZero();
- }
- position.y -= 2f;
- movement = "down";
- currentFrame = animation.getKeyFrame(0 + stateTime);
- }
- }
- public void reAdjust()
- {
- if (movement == "up") {
- position.y -= 2f;
- }
- if (movement == "down") {
- position.y += 2f;
- }
- if (movement == "right") {
- position.x -= 2f;
- }
- if (movement == "left") {
- position.x += 2f;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement