diff --git a/.nb-gradle/private/cache/DodgeGame-d41d8cd98f00b204e9800998ecf8427e b/.nb-gradle/private/cache/DodgeGame-d41d8cd98f00b204e9800998ecf8427e index b891a8f..9c65f6c 100644 Binary files a/.nb-gradle/private/cache/DodgeGame-d41d8cd98f00b204e9800998ecf8427e and b/.nb-gradle/private/cache/DodgeGame-d41d8cd98f00b204e9800998ecf8427e differ diff --git a/.nb-gradle/private/cache/core-fb83b73eb3c879b18d343675f32aca61 b/.nb-gradle/private/cache/core-fb83b73eb3c879b18d343675f32aca61 index 0037c2f..489eb4a 100644 Binary files a/.nb-gradle/private/cache/core-fb83b73eb3c879b18d343675f32aca61 and b/.nb-gradle/private/cache/core-fb83b73eb3c879b18d343675f32aca61 differ diff --git a/.nb-gradle/private/cache/desktop-9bccb601584b92d9c041663102aef73f b/.nb-gradle/private/cache/desktop-9bccb601584b92d9c041663102aef73f index daa1ccc..7b465f3 100644 Binary files a/.nb-gradle/private/cache/desktop-9bccb601584b92d9c041663102aef73f and b/.nb-gradle/private/cache/desktop-9bccb601584b92d9c041663102aef73f differ diff --git a/.nb-gradle/profiles/private/aux-config b/.nb-gradle/profiles/private/aux-config index c0eb7a9..1e60efa 100644 --- a/.nb-gradle/profiles/private/aux-config +++ b/.nb-gradle/profiles/private/aux-config @@ -3,14 +3,16 @@ - - - - - file:/C:/Users/jalen/Programming/Netbeans%20Workspace/Summer%202017/DodgeGame/desktop/src/com/jalenwinslow/game/desktop/DesktopLauncher.java + file:/C:/Users/jalen/Programming/Netbeans%20Workspace/Summer%202017/DodgeGame/core/src/com/jalenwinslow/game/states/GameState.java + file:/C:/Users/jalen/Programming/Netbeans%20Workspace/Summer%202017/DodgeGame/core/src/com/jalenwinslow/game/utils/Players.java + file:/C:/Users/jalen/Programming/Netbeans%20Workspace/Summer%202017/DodgeGame/core/src/com/jalenwinslow/game/gameobjects/Player.java + file:/C:/Users/jalen/Programming/Netbeans%20Workspace/Summer%202017/DodgeGame/core/src/com/jalenwinslow/game/Main.java + file:/C:/Users/jalen/Programming/Netbeans%20Workspace/Summer%202017/DodgeGame/core/src/com/jalenwinslow/game/states/MenuState.java + file:/C:/Users/jalen/Programming/Netbeans%20Workspace/Summer%202017/DodgeGame/core/src/com/jalenwinslow/game/states/GameOverState.java + diff --git a/HELP.txt b/HELP.txt index 68f9846..9504291 100644 --- a/HELP.txt +++ b/HELP.txt @@ -5,11 +5,20 @@ wood walls to help you survive longer. Controls -------- -W, A, S, D = Up, Left, Down, Right -E -> Hold down to destroy wood or build walls. (In menu, you use it to select choices.) -Space -> When you have 7 pieces of wood you can create a wall. +1st Player Controls. + W, A, S, D = Up, Left, Down, Right + E -> Hold down to destroy wood or build walls. (In menu, you use it to select choices.) + Space -> When you have 7 pieces of wood you can create a wall. + Q -> Give wood to other player if standing near them. +2nd Player Controls. + Up, Down, Left, Right Arrow Keys = Up, Down, Left, Right + Right Control(ctrl) = hold down to destroy wood or build walls. (In menu, you use it to select choices.) + Right Shift = When you have 7 pieces of wood you can create a wall + End (button) = Give wood to other player if standing near them. + +Press the num 2 in main menu to add TWO players. -------- -There is an executable in "/built_game". Latest build DodgeGame_1.2.jar. +There is an executable in "/built_game". Latest build DodgeGame_1.3.jar. Created using libgdx. \ No newline at end of file diff --git a/built_game/DodgeGame_1.2.jar b/built_game/DodgeGame_1.3.jar similarity index 83% rename from built_game/DodgeGame_1.2.jar rename to built_game/DodgeGame_1.3.jar index 3f2f27e..8b4906d 100644 Binary files a/built_game/DodgeGame_1.2.jar and b/built_game/DodgeGame_1.3.jar differ diff --git a/built_game/scores.txt b/built_game/scores.txt new file mode 100644 index 0000000..d707c32 --- /dev/null +++ b/built_game/scores.txt @@ -0,0 +1,11 @@ +29 +192 +273 +11 +8 +3 +6 +2 +2 +0 +4 \ No newline at end of file diff --git a/core/assets/b&w_DodgeGame_buttons1.png b/core/assets/b&w_DodgeGame_buttons1.png deleted file mode 100644 index a84add5..0000000 Binary files a/core/assets/b&w_DodgeGame_buttons1.png and /dev/null differ diff --git a/core/assets/b&w_DodgeGame_font1 - Copy.fnt b/core/assets/b&w_DodgeGame_font1 - Copy.fnt new file mode 100644 index 0000000..fab0fac Binary files /dev/null and b/core/assets/b&w_DodgeGame_font1 - Copy.fnt differ diff --git a/core/assets/b&w_DodgeGame_healer.png b/core/assets/b&w_DodgeGame_healer.png new file mode 100644 index 0000000..ae2e11b Binary files /dev/null and b/core/assets/b&w_DodgeGame_healer.png differ diff --git a/core/assets/b&w_DodgeGame_man1.png b/core/assets/b&w_DodgeGame_man1.png index 06b334c..48da790 100644 Binary files a/core/assets/b&w_DodgeGame_man1.png and b/core/assets/b&w_DodgeGame_man1.png differ diff --git a/core/assets/b&w_DodgeGame_woman1.png b/core/assets/b&w_DodgeGame_woman1.png new file mode 100644 index 0000000..a09b8b2 Binary files /dev/null and b/core/assets/b&w_DodgeGame_woman1.png differ diff --git a/core/assets/scores.txt b/core/assets/scores.txt index b20930c..fc215dc 100644 --- a/core/assets/scores.txt +++ b/core/assets/scores.txt @@ -1,11 +1,11 @@ -19 -209 -314 +128 +460 +1372 +20 +22 11 -8 -3 -6 -2 -2 +13 +4 +5 0 -4 \ No newline at end of file +10 \ No newline at end of file diff --git a/core/src/com/jalenwinslow/game/Handler.java b/core/src/com/jalenwinslow/game/Handler.java index de625b0..87a76da 100644 --- a/core/src/com/jalenwinslow/game/Handler.java +++ b/core/src/com/jalenwinslow/game/Handler.java @@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.jalenwinslow.game.gameobjects.GameObjectHandler; import com.jalenwinslow.game.states.*; +import com.jalenwinslow.game.utils.Players; import com.jalenwinslow.game.utils.Score; import java.io.File; import java.io.IOException; @@ -18,6 +19,7 @@ public class Handler { private State menuState, gameState, gameOverState, pauseState, exitState; private GameObjectHandler gameObjectHandler; + private Players players; private BitmapFont font; private String message = ""; @@ -39,6 +41,7 @@ public class Handler { exitState = new ExitState(this); gameObjectHandler = new GameObjectHandler(this); + players = new Players(this); font = new BitmapFont(); font.setColor(Color.RED); @@ -104,6 +107,7 @@ public class Handler { public PauseState getPauseState() {return (PauseState)pauseState;} public ExitState getExitState() {return (ExitState)exitState;} public GameObjectHandler getGameObjectHandler() {return gameObjectHandler;} + public Players getPlayers() {return players;} public FileHandle getScoreFile() {return scoreFile;} public Score getScore() {return score;} diff --git a/core/src/com/jalenwinslow/game/gameobjects/Arrow.java b/core/src/com/jalenwinslow/game/gameobjects/Arrow.java index 8eefbcc..44ec570 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/Arrow.java +++ b/core/src/com/jalenwinslow/game/gameobjects/Arrow.java @@ -15,6 +15,7 @@ public class Arrow extends GameObject { public static final double MIN_SPEED = 2.5; //normal -> maxSpeed: 4 && minSpeed: 2.5 private int dir; + private int damage; private double speed; private double vecX, vecY; //private static Texture boundsTexture = new Texture("DodgeGame_boundsMask.png"); @@ -23,6 +24,7 @@ public class Arrow extends GameObject { public Arrow(Handler handler, double x, double y, TextureRegion image, int dir) { super(handler, x, y, image); this.dir = dir; + this.damage = handler.getGameState().getArrowGen().getArrowDamage(); speed = MIN_SPEED; vecX = 0; vecY = 0; @@ -82,18 +84,21 @@ public class Arrow extends GameObject { } private void checkCollision() { - if (bounds.overlaps(handler.getGameState().getPlayer().getBounds())) { - handler.getGameState().getTimer().stop(); - State.setCurrenState(handler.getGameOverState()); - State.getCurrentState().init(); - handler.getGameObjectHandler().dispose(); - handler.getGameState().dispose(); + + for (int i = 1; i <= handler.getPlayers().getPlayers().size; i++) { + if (bounds.overlaps(handler.getPlayers().getPlayer(i).getBounds())) { + if (!handler.getPlayers().getPlayer(i).isDead()) { + handler.getGameState().getArrowGen().getArrows().removeValue(this, false); + handler.getPlayers().getPlayer(i).setHitPoints(0); + } + handler.getPlayers().getPlayer(i).setDead(true); + } } for (int i = 0; i < handler.getGameObjectHandler().getGameObjects().size; i++) { if (handler.getGameObjectHandler().getGameObjects().get(i).toString().equalsIgnoreCase("TallWall")) { TallWall wall = (TallWall)handler.getGameObjectHandler().getGameObjects().get(i); if (bounds.overlaps(wall.getNoArrowBounds())) { - wall.setHitPoints(wall.getHitPoints() - 6); + wall.setHitPoints(wall.getHitPoints() - damage); handler.getGameState().getArrowGen().getArrows().removeValue(this, false); } } diff --git a/core/src/com/jalenwinslow/game/gameobjects/ArrowGenerator.java b/core/src/com/jalenwinslow/game/gameobjects/ArrowGenerator.java index 552fcc5..42f2ab4 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/ArrowGenerator.java +++ b/core/src/com/jalenwinslow/game/gameobjects/ArrowGenerator.java @@ -19,6 +19,7 @@ public class ArrowGenerator extends GameObject { private double currentDeployTime; private int highestAmountOfArrowsAtOnce; private int amountOfArrowsCreated; + private int arrowDamage; private Random rand; private TextureRegion[][] arrowTextures; @@ -34,6 +35,7 @@ public class ArrowGenerator extends GameObject { currentDeployTime = ARROW_DEPLOY_START_TIME; highestAmountOfArrowsAtOnce = 0; amountOfArrowsCreated = 0; + arrowDamage = 6; rand = new Random(); arrowTextures = image.split(16, 16); @@ -81,6 +83,8 @@ public class ArrowGenerator extends GameObject { currentDeployTime -= 0.1; if (currentDeployTime < ARROW_DEPLOY_END_TIME) currentDeployTime = ARROW_DEPLOY_END_TIME; } + int modifier2 = (handler.getGameState().getTimer().getTime() - 400) / 60; + arrowDamage = 6 + modifier2; } private void addArrow() { @@ -116,5 +120,6 @@ public class ArrowGenerator extends GameObject { public Array getArrows() {return arrows;} public int getAmountOfArrowsCreated() {return amountOfArrowsCreated;} public int getHighestAmountOfArrowsAtOnce() {return highestAmountOfArrowsAtOnce;} + public int getArrowDamage() {return arrowDamage;} } diff --git a/core/src/com/jalenwinslow/game/gameobjects/Button.java b/core/src/com/jalenwinslow/game/gameobjects/Button.java index aaaec15..4bfbffd 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/Button.java +++ b/core/src/com/jalenwinslow/game/gameobjects/Button.java @@ -15,13 +15,13 @@ import com.jalenwinslow.game.states.State; public class Button extends GameObject { //--- Propreties - private TextureRegion[][] images; - private BitmapFont font; - private String message; - private int imageIndex; - private boolean drawHealth; - private HealthBar health; - private int hitPoints; + protected TextureRegion[][] images; + protected BitmapFont font; + protected String message; + protected int imageIndex; + protected boolean drawHealth; + protected HealthBar health; + protected int hitPoints; //--- Constructor public Button(Handler handler, double x, double y, TextureRegion image, String message, int scale) { @@ -43,12 +43,12 @@ public class Button extends GameObject { //--- Methods @Override public void update(float dt) { - //checkIfMouseWithin(); - checkPlayerCollision(); + if (toString().equals("Button")) checkPlayerCollision(); if (hitPoints < 0) {hitPoints = 0;} health.setHealth(hitPoints); if (hitPoints >= 60) { buttonAction(); + hitPoints = 0; } } @@ -72,31 +72,59 @@ public class Button extends GameObject { State.setCurrenState(handler.getGameState()); handler.getGameObjectHandler().dispose(); handler.getGameState().init(); + handler.getPlayers().resetPlayers(); handler.getMenuState().dispose(); } else if (message.equalsIgnoreCase("Stats")) { handler.getMenuState().setSubState(1); + handler.getPlayers().centerPlayers(); } else if (message.equalsIgnoreCase("Exit")) { State.setCurrenState(handler.getExitState()); handler.getGameObjectHandler().dispose(); State.getCurrentState().init(); handler.getMenuState().dispose(); + } else if (message.equalsIgnoreCase("multi-\nplayer")) { + handler.getMenuState().setSubState(2); + handler.getPlayers().centerPlayers(); } else if (message.equalsIgnoreCase("back")) { - handler.getMenuState().setSubState(0); + int subState = handler.getMenuState().getSubState(); + if (subState == 1 || subState == 2) + handler.getMenuState().setSubState(0); + else if (subState == 3) { + handler.getMenuState().setSubState(2); + } + handler.getPlayers().centerPlayers(); + } else if (message.equalsIgnoreCase("Player 1")) { //Player 1 controls + handler.getMenuState().setSubState(3); + handler.getPlayers().centerPlayers(); + } else if (message.equalsIgnoreCase("Player 2")) { //Player 2 controls + handler.getMenuState().setSubState(3); + handler.getPlayers().centerPlayers(); + } else if (message.equalsIgnoreCase("Player 3")) { //Player 3 controls + handler.getMenuState().setSubState(3); + handler.getPlayers().centerPlayers(); + } else if (message.equalsIgnoreCase("Player 4")) { //Player 4 controls + handler.getMenuState().setSubState(3); + handler.getPlayers().centerPlayers(); } } - private void checkPlayerCollision() { - if (bounds.overlaps(handler.getMenuState().getPlayer().getBounds())) { - drawHealth = true; - imageIndex = 1; - if (Gdx.input.isKeyPressed(Keys.E)) { - hitPoints++; - } else {hitPoints--;} - } else { - drawHealth = false; - imageIndex = 0; - hitPoints--; + protected void checkPlayerCollision() { + drawHealth = false; + imageIndex = 0; + int addHitPoints = 0; + for (int i = 0; i < handler.getPlayers().getNumOfPlayers(); i++) { + if (handler.getPlayers().getPlayer(i+1) == null) continue; + if (bounds.overlaps(handler.getPlayers().getPlayer(i+1).getBounds())) { + drawHealth = true; + imageIndex = 1; + if (handler.getPlayers().getPlayer(i+1).getActionPressed()) { + addHitPoints += 1; + } + } } + if (addHitPoints != 0) { + hitPoints += addHitPoints; + } else hitPoints--; } //--- Getters and Setters diff --git a/core/src/com/jalenwinslow/game/gameobjects/ControllerButton.java b/core/src/com/jalenwinslow/game/gameobjects/ControllerButton.java new file mode 100644 index 0000000..426ab8d --- /dev/null +++ b/core/src/com/jalenwinslow/game/gameobjects/ControllerButton.java @@ -0,0 +1,69 @@ +package com.jalenwinslow.game.gameobjects; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.jalenwinslow.game.Handler; + +public class ControllerButton extends Button { + + //--- Propreties + private boolean visible; + private int playerNum; + + private float alpha; + + //--- Constructor + public ControllerButton(Handler handler, double x, double y, TextureRegion image, String message, int scale, int playerNum) { + super(handler, x, y, image, message, scale); + visible = false; + this.playerNum = playerNum; + + this.alpha = 0.5f; + } + + + //--- Methods + @Override + public void update(float dt) { + checkPlayerCollision(); + if (visible && bounds.overlaps(handler.getPlayers().getPlayer(playerNum).getBounds())) + super.update(dt);//fix this area, so only players can change their own controls. + displayButton(); + + } + + @Override + public void render(SpriteBatch batch) { + if (visible) { + batch.setColor(1, 1, 1, alpha); + super.render(batch); + batch.setColor(1, 1, 1, 1); + } + + } + + @Override + public void dispose() { + super.dispose(); + } + + public void displayButton() { + if (handler.getPlayers().getNumOfPlayers() >= playerNum) + visible = handler.getPlayers().getPlayer(playerNum) != null; + if (visible && bounds.overlaps(handler.getPlayers().getPlayer(playerNum).getBounds())) { + alpha = 1; + } else alpha = 0.5f; + } + + + @Override + public String toString() {return "ControllerButton";} + + //--- Getters and Setters + + + + + + +} diff --git a/core/src/com/jalenwinslow/game/gameobjects/GameObject.java b/core/src/com/jalenwinslow/game/gameobjects/GameObject.java index 554e2ae..5919be9 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/GameObject.java +++ b/core/src/com/jalenwinslow/game/gameobjects/GameObject.java @@ -44,5 +44,11 @@ public abstract class GameObject { public int getDepth() {return depth;} public Rectangle getBounds() {return bounds;} + public void setX(double x) {this.x = x;} + public void setY(double y) {this.y = y;} + public void setPosition(double x, double y) {this.x = x; this.y = y;} + public void setDepth(int depth) {this.depth = depth;} + public void setBounds(Rectangle bounds) {this.bounds = bounds;} + } diff --git a/core/src/com/jalenwinslow/game/gameobjects/GameObjectHandler.java b/core/src/com/jalenwinslow/game/gameobjects/GameObjectHandler.java index 4b3a525..aa8e434 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/GameObjectHandler.java +++ b/core/src/com/jalenwinslow/game/gameobjects/GameObjectHandler.java @@ -57,7 +57,7 @@ public class GameObjectHandler { public void sort() { for (int i = 0; i < gameObjects.size - 1; i++) { - if (gameObjects.get(i).depth <= gameObjects.get(i+1).depth) { + if (gameObjects.get(i).depth < gameObjects.get(i+1).depth) { gameObjects.swap(i, i+1); } } diff --git a/core/src/com/jalenwinslow/game/gameobjects/Healer.java b/core/src/com/jalenwinslow/game/gameobjects/Healer.java new file mode 100644 index 0000000..3e16ace --- /dev/null +++ b/core/src/com/jalenwinslow/game/gameobjects/Healer.java @@ -0,0 +1,145 @@ +package com.jalenwinslow.game.gameobjects; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Animation; +import com.badlogic.gdx.graphics.g2d.Animation.PlayMode; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.utils.Array; +import com.jalenwinslow.game.Handler; +import com.jalenwinslow.game.Main; + +public class Healer extends GameObject { + + //--- Propreties + enum HealerStates { + creation, + normal + } + private HealerStates state; + + private Animation anim; + private TextureRegion texture; + + private float elapsedTime; + private float tick; + private int timerCountDown; + + private float alpha; + + private Rectangle boundsHeal; + private Rectangle boundsNoPlayer; + + //private TextureRegion boundsTexture = new TextureRegion(new Texture("DodgeGame_boundsMask.png")); + + //--- Constructor + public Healer(Handler handler, double x, double y, TextureRegion image) { + super(handler, x, y, image); + bounds = new Rectangle(); + boundsNoPlayer = new Rectangle((int)x, (int)y, Main.WIDTH/10, Main.HEIGHT/10); + boundsHeal = new Rectangle();//bounds.x - Main.WIDTH/10, bounds.y-Main.HEIGHT/10, bounds.width+Main.WIDTH/10, bounds.height+Main.HEIGHT/10); + + depth = (int) y + (Main.HEIGHT/20) + (Main.HEIGHT/40); + + elapsedTime = 0; + tick = 0; + timerCountDown = 10; + //createAnimation(); + + alpha = 0.5f; + + state = HealerStates.creation; + } + + + //--- Methods + @Override + public void update(float dt) { + switch (state) { + case creation: + elapsedTime += dt; + if (bounds.area() != boundsNoPlayer.area()) { + boolean check = true; + for (Player player : handler.getPlayers().getPlayers()) { + if (player.getBoundsFeet().overlaps(boundsNoPlayer)) { + check = false; + break; + } + } + if (check) { + alpha = 1; + bounds = new Rectangle(boundsNoPlayer); + boundsHeal = new Rectangle(bounds.x - Main.WIDTH/10, bounds.y-Main.HEIGHT/10, bounds.width+Main.WIDTH/5, bounds.height+Main.HEIGHT/5); + state = HealerStates.normal; + } + } + break; + case normal: + elapsedTime += dt; + if (elapsedTime >= 10) { + for (int i = 0; i < handler.getGameObjectHandler().getGameObjects().size; i++) { + if (handler.getGameObjectHandler().getGameObjects().get(i).equals(this)) { + handler.getGameState().getGrid().setFree(true, (int)(x / handler.getGameState().getGrid().getAreaWidth()), (int)(y / handler.getGameState().getGrid().getAreaHeight())); + handler.getGameObjectHandler().getGameObjects().removeValue(this, false); + } + } + } + handleCollision(); + break; + default: + + break; + } + } + + @Override + public void render(SpriteBatch batch) { + switch (state) { + case creation: + batch.setColor(1, 1, 1, alpha); + batch.draw(image, boundsNoPlayer.x, boundsNoPlayer.y ,boundsNoPlayer.width ,boundsNoPlayer.height + (Main.WIDTH/40)); + batch.setColor(1, 1, 1, 1); + break; + case normal: + batch.draw(image, bounds.x, bounds.y, bounds.width, bounds.height+(Main.HEIGHT/40)); + break; + default: + + break; + } + //batch.draw(boundsTexture, boundsHeal.x, boundsHeal.y, boundsHeal.width, boundsHeal.height); + } + + @Override + public void dispose() { + //boundsTexture.getTexture().dispose(); + } + + @Override + public String toString() {return "Healer";} + + public void createAnimation() { + TextureRegion[][] splitTexture = image.split(16, 20); + Array array = new Array(splitTexture.length * splitTexture[0].length); + for (int i = 0; i < splitTexture[0].length; i++) { + array.add(splitTexture[0][i]); + } + anim = new Animation(0.5f, array, PlayMode.LOOP); + array.clear(); + texture = anim.getKeyFrame(elapsedTime); + } + + public void handleCollision() { + for (Player player : handler.getPlayers().getPlayers()) { + if (!player.isDead()) continue; + if (player.getBoundsFeet().overlaps(boundsHeal)) { + player.setHitPoints(player.getHitPoints()+1); + } + } + } + + //--- Getters and Setters + public Rectangle getBoundsHeal() {return boundsHeal;} + +} diff --git a/core/src/com/jalenwinslow/game/gameobjects/HealerGenerator.java b/core/src/com/jalenwinslow/game/gameobjects/HealerGenerator.java new file mode 100644 index 0000000..de88e89 --- /dev/null +++ b/core/src/com/jalenwinslow/game/gameobjects/HealerGenerator.java @@ -0,0 +1,96 @@ +package com.jalenwinslow.game.gameobjects; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.jalenwinslow.game.Handler; +import java.util.Random; + +public class HealerGenerator extends GameObject { + + public static int BASE_COUNT_DOWN = 30; + + private Random rand; + + //--- Propreties + private float elapsedTime; + private int tick; + private int timerCountDown; + + //--- Constructor + public HealerGenerator(Handler handler, double x, double y, TextureRegion image) { + super(handler, x, y, image); + + rand = new Random(); + + elapsedTime = 0; + tick = 0; + timerCountDown = BASE_COUNT_DOWN + (rand.nextInt(11)-5); + + } + + + //--- Methods + @Override + public void update(float dt) { + elapsedTime += dt; + if (elapsedTime >= 1) { + tick++; + elapsedTime--; + } + + if (tick >= timerCountDown) { + int probability = 80; + if (rand.nextInt(100)+1 <= probability) { + addHealer(); + } + timerCountDown = BASE_COUNT_DOWN + (rand.nextInt(11) - 5); + tick = 0; + } + } + + @Override + public void render(SpriteBatch batch) { + + } + + @Override + public void dispose() { + + } + + public void addHealer() { + int arrayX = rand.nextInt(8)+1; + int arrayY = rand.nextInt(8)+1; + while (true) { + if (handler.getGameState().getGrid().isFree()[arrayY][arrayX] == true) { + break; + } else { + if (arrayX < 8) arrayX++; + else { + if (arrayY < 8) { + arrayY++; + arrayX = 1; + } else { + arrayY = 1; + arrayX = 1; + } + } + } + } + + handler.getGameState().getGrid().setFree(false, arrayX, arrayY); + + int xx = handler.getGameState().getGrid().getAreaWidth() * (arrayX); + int yy = handler.getGameState().getGrid().getAreaHeight() * (arrayY); + + handler.getGameObjectHandler().add(new Healer(handler, xx, yy, image)); + //System.out.println("Created a healer at" + arrayX + ", " + arrayY); + } + + @Override + public String toString() {return "HealerGenerator";} + + //--- Getters and Setters + + +} diff --git a/core/src/com/jalenwinslow/game/gameobjects/HealthBar.java b/core/src/com/jalenwinslow/game/gameobjects/HealthBar.java index 54a5924..82964ab 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/HealthBar.java +++ b/core/src/com/jalenwinslow/game/gameobjects/HealthBar.java @@ -51,6 +51,7 @@ public class HealthBar extends GameObject { public float getHealth() {return health;} public float getTotalHealth() {return totalHealth;} + public void setHealth(float health) {this.health = health;} public void setTotalHealth(float totalHealth) {this.totalHealth = totalHealth;} diff --git a/core/src/com/jalenwinslow/game/gameobjects/Player.java b/core/src/com/jalenwinslow/game/gameobjects/Player.java index c54a18c..a1aa67c 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/Player.java +++ b/core/src/com/jalenwinslow/game/gameobjects/Player.java @@ -12,6 +12,8 @@ import com.badlogic.gdx.utils.Array; import com.jalenwinslow.game.Handler; import com.jalenwinslow.game.Main; import com.jalenwinslow.game.gameobjects.TallWall.TallWallStates; +import com.jalenwinslow.game.states.State; +import com.jalenwinslow.game.utils.Players; public class Player extends GameObject { @@ -24,8 +26,20 @@ public class Player extends GameObject { private int highestNumberOfTallWallsCreated; private int highestNumberOfTallWallsDestroyed; private int numberOfWoodPickedUp; + private int playerid; + private boolean dead; - private Animation animDown, animUp, animRight; + private boolean actionPressed; + private boolean giveWood; + private Controls playerControl; + + private int hitPoints; + private int totalHitPoints; + private HealthBar reviveHealth; + private boolean drawHealth; + private int counterToIncreaseHealth; + + private Animation animDown, animUp, animRight, animLeft; private TextureRegion texture; private float elapsedTime = 0; private Rectangle boundsFeet; @@ -33,9 +47,20 @@ public class Player extends GameObject { //private Texture boundsTexture = new Texture("DodgeGame_boundsMask.png"); //--- Constructor - public Player(Handler handler, double x, double y, TextureRegion image) { + public Player(Handler handler, double x, double y, TextureRegion image, int playerid) { super(handler, x, y, image); + this.playerid = playerid; + this.dead = false; + actionPressed = false; + giveWood = false; + playerControl = new Controls(handler, playerid); + + hitPoints = 0; + totalHitPoints = 450; + reviveHealth = new HealthBar(handler, x, y, new TextureRegion(Players.playerHealthTexture), totalHitPoints); + counterToIncreaseHealth = 0; + dir = 3; vecX = 0; vecY = 0; @@ -62,11 +87,27 @@ public class Player extends GameObject { bounds.setPosition((float)x + 20, (float)y + 8); boundsFeet.setPosition((float)x + 20, (float)y); checks(); + if (dead) { + reviveHealth.setHealth(hitPoints); + reviveHealth.getBounds().setPosition((float)x, (float)y + 64); + if (hitPoints >= totalHitPoints) { + dead = false; + drawHealth = false; + } + } } @Override public void render(SpriteBatch batch) { - batch.draw(texture, (int)x, (int)y, Main.WIDTH/10, Main.HEIGHT/10); + if (!dead) + batch.draw(texture, (int)x, (int)y, Main.WIDTH/10, Main.HEIGHT/10); + else { + batch.setColor(1, 1, 1, 0.5f); + batch.draw(texture, (int)x, (int)y, Main.WIDTH/10, Main.HEIGHT/10); + batch.setColor(1, 1, 1, 1); + if (drawHealth) reviveHealth.render(batch); + } + //batch.draw(boundsTexture, bounds.x, bounds.y, bounds.width, bounds.height); } @@ -76,6 +117,10 @@ public class Player extends GameObject { //boundsTexture.dispose(); } + public boolean returnPausePressed() { + return playerControl.pauseGame; + } + private void createAnimation() { TextureRegion[][] splitTexture = image.split(16, 16); Array array = new Array(splitTexture.length * splitTexture[0].length); @@ -96,33 +141,38 @@ public class Player extends GameObject { } animRight = new Animation(0.1f, array, PlayMode.LOOP); array.clear(); + + for (TextureRegion t : splitTexture[3]) { + array.add(t); + } + animLeft = new Animation(0.1f, array, PlayMode.LOOP); + array.clear(); texture = animDown.getKeyFrame(elapsedTime); } private void handleInput() { - if ( (Gdx.input.isKeyPressed(Keys.W) && Gdx.input.isKeyPressed(Keys.S)) || - (!Gdx.input.isKeyPressed(Keys.W) && !Gdx.input.isKeyPressed(Keys.S)) ) { + playerControl.update(); + if ( (playerControl.up && playerControl.down) || (!playerControl.up && !playerControl.down) ) { vecY = 0; - } else if (Gdx.input.isKeyPressed(Keys.W)) { + } else if (playerControl.up) { vecY = SPEED; dir = 1; - } else if (Gdx.input.isKeyPressed(Keys.S)) { + } else if (playerControl.down) { vecY = -SPEED; dir = 3; } - if ( (Gdx.input.isKeyPressed(Keys.A) && Gdx.input.isKeyPressed(Keys.D)) || - (!Gdx.input.isKeyPressed(Keys.A) && !Gdx.input.isKeyPressed(Keys.D)) ) { + if ( (playerControl.left && playerControl.right) || (!playerControl.left && !playerControl.right) ) { vecX = 0; - } else if (Gdx.input.isKeyPressed(Keys.A)) { + } else if (playerControl.left) { vecX = -SPEED; dir = 2; - } else if (Gdx.input.isKeyPressed(Keys.D)) { + } else if (playerControl.right) { vecX = SPEED; dir = 0; } - if ( (Gdx.input.isKeyJustPressed(Keys.SPACE)) && wood >= 7) { + if (playerControl.placeWall && wood >= 7 && !dead) { int arrayX = ((int)(boundsFeet.x + (boundsFeet.width/2))/64); int arrayY = ((int)(boundsFeet.y + (boundsFeet.height/2))/64); handler.getGameState().getGrid().setFree(false, arrayX, arrayY); @@ -130,6 +180,12 @@ public class Player extends GameObject { wood -= 7; } + actionPressed = playerControl.actionPressed; + giveWood = playerControl.giveWood; + + if (State.getCurrentState() == handler.getGameState() && playerControl.pauseGame) { + handler.getGameState().setPause(true); + } } private void handleCollision() { @@ -138,7 +194,43 @@ public class Player extends GameObject { if (boundsFeet.y + boundsFeet.height + vecY >= Main.HEIGHT-64) vecY = 0; if (boundsFeet.y + vecY <= 0) {vecY = 0;} - handleWallCollision(); + if (!dead) { + handleWallCollision(); + if (handler.getPlayers().getNumOfPlayers() > 1) handlePlayerCollision(); + } else handleDeadPlayerCollision(); + + handleHealerCollision(); + } + + private void handleHealerCollision() { + for (int i = 0; i < handler.getGameObjectHandler().getGameObjects().size; i++) { + if (handler.getGameObjectHandler().getGameObjects().get(i).toString().equalsIgnoreCase("Healer")) { + Healer wall = (Healer)handler.getGameObjectHandler().getGameObjects().get(i); + if (vecX < 0) { + if (wall.getCollision(boundsFeet.x + vecX, boundsFeet.y) || + wall.getCollision(boundsFeet.x + vecX, boundsFeet.y + boundsFeet.height)) { + vecX = 0; + } + } else if (vecX > 0) { + if (wall.getCollision(boundsFeet.x + boundsFeet.width + vecX, boundsFeet.y) || + wall.getCollision(boundsFeet.x + boundsFeet.width + vecX, boundsFeet.y + boundsFeet.height)) { + vecX = 0; + } + } + + if (vecY < 0) { + if (wall.getCollision(boundsFeet.x, boundsFeet.y + vecY) || + wall.getCollision(boundsFeet.x + boundsFeet.width, boundsFeet.y + vecY)) { + vecY = 0; + } + } else if (vecY > 0) { + if (wall.getCollision(boundsFeet.x, boundsFeet.y + boundsFeet.height + vecY) || + wall.getCollision(boundsFeet.x + boundsFeet.width, boundsFeet.y + boundsFeet.height + vecY)) { + vecY = 0; + } + } + } + } } private void handleWallCollision() {// Also breaking walls @@ -146,7 +238,7 @@ public class Player extends GameObject { for (int i = 0; i < handler.getGameObjectHandler().getGameObjects().size; i++) { if (handler.getGameObjectHandler().getGameObjects().get(i).toString().equalsIgnoreCase("ShortWall")) { ShortWall wall = (ShortWall)handler.getGameObjectHandler().getGameObjects().get(i); - if (wall.getShowHealthBounds() != null && boundsFeet.overlaps(wall.getShowHealthBounds()) && Gdx.input.isKeyPressed(Keys.E)) { + if (wall.getShowHealthBounds() != null && boundsFeet.overlaps(wall.getShowHealthBounds()) && actionPressed) { if (wall.getHitPoints() > 0) { wall.setHitPoints(wall.getHitPoints() - 1); } @@ -177,14 +269,22 @@ public class Player extends GameObject { } if (handler.getGameObjectHandler().getGameObjects().get(i).toString().equalsIgnoreCase("TallWall")) { TallWall wall = (TallWall)handler.getGameObjectHandler().getGameObjects().get(i); + //build walls if (wall.getState() == TallWallStates.startCreation) { - if (wall.getShowHealthBounds() != null && boundsFeet.overlaps(wall.getShowHealthBounds()) && Gdx.input.isKeyPressed(Keys.E)) { + if (wall.getShowHealthBounds() != null && boundsFeet.overlaps(wall.getShowHealthBounds()) && actionPressed) { if (wall.getHitPoints() < wall.getTotalHitPoints()) { wall.setHitPoints(wall.getHitPoints() + 1); } } } + //Repair walls + if (wall.getState() == TallWallStates.normal) { + if (wall.getShowHealthBounds() != null && boundsFeet.overlaps(wall.getShowHealthBounds()) && actionPressed) { + wall.setCounterIncreaseHealth(wall.getCounterIncreaseHealth() + 1); + } + } + if (vecX < 0) { if (wall.getCollision(boundsFeet.x + vecX, boundsFeet.y) || wall.getCollision(boundsFeet.x + vecX, boundsFeet.y + boundsFeet.height)) { @@ -212,6 +312,45 @@ public class Player extends GameObject { } } + private void handlePlayerCollision() { + for (Player player : handler.getPlayers().getPlayers()) { + if (player == this) continue; + if (player.getBoundsFeet().overlaps(boundsFeet)) { + if (wood > 0 && giveWood) { + player.setWood(player.getWood() + 1); + wood -= 1; + break; + } + } + } + } + + private void handleDeadPlayerCollision() { + drawHealth = false; + for (Player player : handler.getPlayers().getPlayers()) { + if (player == this) continue; + if (player.getBoundsFeet().overlaps(boundsFeet)) { + drawHealth = true; + if (player.actionPressed) { + counterToIncreaseHealth++; + if (counterToIncreaseHealth >= 4) { + hitPoints++; + counterToIncreaseHealth = 0; + } + } + } + } + for (int i = 0; i < handler.getGameObjectHandler().getGameObjects().size; i++) { + if (handler.getGameObjectHandler().getGameObjects().get(i).toString().equalsIgnoreCase("Healer")) { + Healer healer = (Healer)handler.getGameObjectHandler().getGameObjects().get(i); + if (healer.getBoundsHeal().overlaps(boundsFeet)) { + drawHealth = true; + break; + } + } + } + } + private void handleAnimation() { Animation currentAnimation; if (vecY > 0) dir = 1; @@ -222,7 +361,7 @@ public class Player extends GameObject { switch (dir) { case 0: currentAnimation = animRight; break; case 1: currentAnimation = animUp; break; - case 2: currentAnimation = animRight; break; + case 2: currentAnimation = animLeft; break; case 3: currentAnimation = animDown; break; default: currentAnimation = animDown; break; } @@ -231,8 +370,8 @@ public class Player extends GameObject { texture = currentAnimation.getKeyFrame(elapsedTime); else texture = currentAnimation.getKeyFrame(0); - if (texture.isFlipX()) texture.flip(true, false); - if (dir == 2 && !texture.isFlipX()) texture.flip(true, false); + //if (texture.isFlipX()) texture.flip(true, false); + //if (dir == 2 && !texture.isFlipX()) texture.flip(true, false); } private void checks() { @@ -240,6 +379,25 @@ public class Player extends GameObject { if (wood > 20) wood = 20; } + public void resetPlayer() { + dead = false; + + actionPressed = false; + giveWood = false; + + hitPoints = 0; + totalHitPoints = 450; + counterToIncreaseHealth = 0; + + dir = 3; + vecX = 0; + vecY = 0; + wood = 0; + highestNumberOfTallWallsCreated = 0; + highestNumberOfTallWallsDestroyed = 0; + numberOfWoodPickedUp = 0; + } + @Override public String toString() {return "Player";} @@ -249,10 +407,87 @@ public class Player extends GameObject { public int getHighestNumberOfTallWallsCreated() {return highestNumberOfTallWallsCreated;} public int getHighestNumberOfTallWallsDestroyed() {return highestNumberOfTallWallsDestroyed;} public int getNumberOfWoodPickedUp() {return numberOfWoodPickedUp;} + public boolean getActionPressed() {return actionPressed;} + public int getHitPoints() {return hitPoints;} + public int getTotalHitPoints() {return totalHitPoints;} + public boolean isDead() {return dead;} + public int getPlayerId() {return playerid;} public void setWood(int wood) {this.wood = wood;} public void setHighestNumberOfTallWallsCreated(int tallWalls) {this.highestNumberOfTallWallsCreated = tallWalls;} public void setHighestNumberOfTallWallsDestroyed(int tallWalls) {this.highestNumberOfTallWallsDestroyed = tallWalls;} public void setNumberOfWoodPickedUp(int wood) {this.numberOfWoodPickedUp = wood;} + public void setHitPoints(int hitPoints) {this.hitPoints = hitPoints;} + public void setTotalHitPoints(int hitPoints) {this.totalHitPoints = hitPoints;} + public void setDead(boolean dead) {this.dead = dead;} + public void setPlayerId(int id) {this.playerid = id;} + + //Controls + private class Controls { + + private static final int KEYBOARD = 0, GAMEPAD = 1; + private int controllerType; + + public boolean up, down, left, right; + public boolean actionPressed, placeWall, giveWood; + public boolean pauseGame; + + private int key_up, key_down, key_left, key_right; + private int key_actionPressed, key_placeWall, key_giveWood; + private int key_pauseGame; + + + + public Controls(Handler handler, int playerNum) { + defaultSetup(playerNum); + } + + public void defaultSetup(int playerNum) { + switch (playerNum) { + case 1: controllerType = KEYBOARD; break; + case 2: controllerType = KEYBOARD; break; + case 3: controllerType = GAMEPAD; break; + case 4: controllerType = GAMEPAD; break; + default: controllerType = KEYBOARD; break; + } + switch (playerNum) { + case 1: + key_up = Keys.W; + key_down = Keys.S; + key_left = Keys.A; + key_right = Keys.D; + key_actionPressed = Keys.E; + key_placeWall = Keys.SPACE; + key_giveWood = Keys.Q; + key_pauseGame = Keys.P; + break; + case 2: + key_up = Keys.UP; + key_down = Keys.DOWN; + key_left = Keys.LEFT; + key_right = Keys.RIGHT; + key_actionPressed = Keys.CONTROL_RIGHT; + key_placeWall = Keys.SHIFT_RIGHT; + key_giveWood = Keys.END; + key_pauseGame = Keys.ENTER; + break; + case 3: break; + case 4: break; + default: controllerType = KEYBOARD; break; + } + } + + public void update() { + up = Gdx.input.isKeyPressed(key_up); + down = Gdx.input.isKeyPressed(key_down); + left = Gdx.input.isKeyPressed(key_left); + right = Gdx.input.isKeyPressed(key_right); + actionPressed = Gdx.input.isKeyPressed(key_actionPressed); + placeWall = Gdx.input.isKeyJustPressed(key_placeWall); + giveWood = Gdx.input.isKeyJustPressed(key_giveWood); + pauseGame = Gdx.input.isKeyJustPressed(key_pauseGame); + } + + } } diff --git a/core/src/com/jalenwinslow/game/gameobjects/ShortWall.java b/core/src/com/jalenwinslow/game/gameobjects/ShortWall.java index a1be368..0720acb 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/ShortWall.java +++ b/core/src/com/jalenwinslow/game/gameobjects/ShortWall.java @@ -78,8 +78,17 @@ public class ShortWall extends Wall { switch (state) { case creation: elapsedTime += dt; - if (!noPlayerBounds.overlaps(handler.getGameState().getPlayer().getBoundsFeet())) { - bounds = new Rectangle(noPlayerBounds); + if (bounds.area() != noPlayerBounds.area()) { + boolean check = true; + for (Player player : handler.getPlayers().getPlayers()) { + if (noPlayerBounds.overlaps(player.getBoundsFeet())) { + check = false; + break; + } + } + if (check) { + bounds = new Rectangle(noPlayerBounds); + } } if (elapsedTime >= 0.25 && timer <= 2) { timer += 0.25; @@ -89,7 +98,7 @@ public class ShortWall extends Wall { } if (timer > 2) { alpha = 1; - if (bounds == null) { + if (bounds.area() == 0) { bounds = new Rectangle((int)x, (int)y, Main.WIDTH/10, Main.HEIGHT/10); } deathBounds = new Rectangle((int)x+8, (int)y+8, Main.WIDTH/10-16, Main.HEIGHT/10-16); @@ -105,7 +114,22 @@ public class ShortWall extends Wall { if (hitPoints <= 0) { for (int i = 0; i < handler.getGameObjectHandler().getGameObjects().size; i++) { if (handler.getGameObjectHandler().getGameObjects().get(i).equals(this)) { - handler.getGameState().getPlayer().setWood(handler.getGameState().getPlayer().getWood()+2); + Player[] players = new Player[handler.getPlayers().getPlayers().size]; + int numOfWood = 2; + int numOfPeople = 0; + for (int p = 1; p <= players.length; p++) { + if (showHealthBounds.overlaps(handler.getPlayers().getPlayer(p).getBoundsFeet()) && + !handler.getPlayers().getPlayer(p).isDead()) { + players[p-1] = handler.getPlayers().getPlayer(p); + numOfPeople++; + } + } + if (numOfPeople >= 2) numOfWood = 1; + for (int p = 1; p <= players.length; p++) { + if (players[p-1] != null) { + handler.getPlayers().getPlayer(p).setWood(handler.getPlayers().getPlayer(p).getWood() + numOfWood); + } + } handler.getGameState().getGrid().setFree(true, (int)(x / handler.getGameState().getGrid().getAreaWidth()), (int)(y / handler.getGameState().getGrid().getAreaHeight())); handler.getGameState().getWallGen().setHighestNumberOfShortWallsDestroyed(handler.getGameState().getWallGen().getHighestNumberOfShortWallsDestroyed() + 1); handler.getGameObjectHandler().getGameObjects().removeValue(this, false); @@ -148,14 +172,15 @@ public class ShortWall extends Wall { } private void boundCollisions() { - if (deathBounds.overlaps(handler.getGameState().getPlayer().getBoundsFeet())) { - handler.getGameState().getTimer().stop(); - State.setCurrenState(handler.getGameOverState()); - State.getCurrentState().init(); - handler.getGameObjectHandler().dispose(); - handler.getGameState().dispose(); + drawHealth = false; + for (Player player : handler.getPlayers().getPlayers()) { + if (deathBounds.overlaps(player.getBoundsFeet())) { + player.setDead(true); + } + if (showHealthBounds.overlaps(player.getBoundsFeet())) { + drawHealth = true; + } } - drawHealth = (showHealthBounds.overlaps(handler.getGameState().getPlayer().getBoundsFeet())); } //--- Getters and Setters diff --git a/core/src/com/jalenwinslow/game/gameobjects/TallWall.java b/core/src/com/jalenwinslow/game/gameobjects/TallWall.java index 5740944..c12f9ee 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/TallWall.java +++ b/core/src/com/jalenwinslow/game/gameobjects/TallWall.java @@ -21,6 +21,7 @@ public class TallWall extends Wall { private int imageIndex; private int hitPoints; private int totalHitPoints; + private int counterIncreaseHealth; private boolean drawHealth; private HealthBar health; @@ -40,6 +41,7 @@ public class TallWall extends Wall { imageIndex = 2; hitPoints = 0; totalHitPoints = 600; + counterIncreaseHealth = 0; drawHealth = false; health = new HealthBar(handler, x, y, new TextureRegion(handler.getGameState().getHealthTexture()), totalHitPoints); health.setHealth(hitPoints); @@ -54,7 +56,15 @@ public class TallWall extends Wall { public void update(float dt) { switch (state) { case waitingCreation: - if (!noPlayerBounds.overlaps(handler.getGameState().getPlayer().getBoundsFeet())) { + boolean check = true; + for (Player player : handler.getPlayers().getPlayers()) { + if (noPlayerBounds.overlaps(player.getBoundsFeet())) { + check = false; + break; + } + } + + if (check) { state = TallWallStates.startCreation; bounds = new Rectangle(noPlayerBounds); showHealthBounds = new Rectangle((int)x-8, (int)y-8, bounds.width+16, bounds.height+16); @@ -71,7 +81,7 @@ public class TallWall extends Wall { noArrowBounds.width += 8; noArrowBounds.y += 16; imageIndex = 0; - handler.getGameState().getPlayer().setHighestNumberOfTallWallsCreated(handler.getGameState().getPlayer().getHighestNumberOfTallWallsCreated() + 1); + handler.getPlayers().getPlayer1().setHighestNumberOfTallWallsCreated(handler.getPlayers().getPlayer1().getHighestNumberOfTallWallsCreated() + 1); } break; case normal: @@ -81,11 +91,15 @@ public class TallWall extends Wall { for (int i = 0; i < handler.getGameObjectHandler().getGameObjects().size; i++) { if (handler.getGameObjectHandler().getGameObjects().get(i).equals(this)) { handler.getGameState().getGrid().setFree(true, (int)(x / handler.getGameState().getGrid().getAreaWidth()), (int)(y / handler.getGameState().getGrid().getAreaHeight())); - handler.getGameState().getPlayer().setHighestNumberOfTallWallsDestroyed(handler.getGameState().getPlayer().getHighestNumberOfTallWallsDestroyed()+1); + handler.getPlayers().getPlayer1().setHighestNumberOfTallWallsDestroyed(handler.getPlayers().getPlayer1().getHighestNumberOfTallWallsDestroyed()+1); handler.getGameObjectHandler().getGameObjects().removeValue(this, false); } } } + if (counterIncreaseHealth >= 3) { + if (hitPoints < totalHitPoints) hitPoints++; + counterIncreaseHealth = 0; + } break; default: @@ -111,18 +125,26 @@ public class TallWall extends Wall { public String toString() {return "TallWall";} public void boundCollisions() { - drawHealth = (showHealthBounds.overlaps(handler.getGameState().getPlayer().getBoundsFeet())); + drawHealth = false; + for (Player player : handler.getPlayers().getPlayers()) { + if (showHealthBounds.overlaps(player.getBoundsFeet())) { + drawHealth = true; + break; + } + } } //--- Getters and Setters public int getHitPoints() {return hitPoints;} public int getTotalHitPoints() {return totalHitPoints;} + public int getCounterIncreaseHealth() {return counterIncreaseHealth;} public Rectangle getShowHealthBounds() {return showHealthBounds;} public Rectangle getNoPlayerBounds() {return noPlayerBounds;} public Rectangle getNoArrowBounds() {return noArrowBounds;} public TallWallStates getState() {return state;} public void setHitPoints(int hitPoints) {this.hitPoints = hitPoints;} + public void setCounterIncreaseHealth(int counter) {this.counterIncreaseHealth = counter;} public void setState(TallWallStates state) {this.state = state;} } diff --git a/core/src/com/jalenwinslow/game/gameobjects/Wood.java b/core/src/com/jalenwinslow/game/gameobjects/Wood.java index f226a7f..0bb586a 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/Wood.java +++ b/core/src/com/jalenwinslow/game/gameobjects/Wood.java @@ -62,11 +62,15 @@ public class Wood extends GameObject { public String toString() {return "Wood";} public void boundCollision() { - if (bounds.overlaps(handler.getGameState().getPlayer().getBounds())) { - handler.getGameState().getPlayer().setWood(handler.getGameState().getPlayer().getWood() + 1); - handler.getGameState().getPlayer().setNumberOfWoodPickedUp(handler.getGameState().getPlayer().getNumberOfWoodPickedUp() + 1); - handler.getGameObjectHandler().getGameObjects().removeValue(this, false); + for (Player player : handler.getPlayers().getPlayers()) { + if (bounds.overlaps(player.getBounds()) && !player.isDead()) { + player.setWood(player.getWood() + 1); + player.setNumberOfWoodPickedUp(player.getNumberOfWoodPickedUp() + 1); + handler.getGameObjectHandler().getGameObjects().removeValue(this, false); + break; + } } + } diff --git a/core/src/com/jalenwinslow/game/gameobjects/WoodGUI.java b/core/src/com/jalenwinslow/game/gameobjects/WoodGUI.java index b418af5..0234543 100644 --- a/core/src/com/jalenwinslow/game/gameobjects/WoodGUI.java +++ b/core/src/com/jalenwinslow/game/gameobjects/WoodGUI.java @@ -18,17 +18,20 @@ public class WoodGUI extends GameObject { private TextureRegion[][] texture; private TextureRegion backTexture; - private Texture boundsTexture = new Texture("DodgeGame_boundsMask.png"); + //private Texture boundsTexture = new Texture("DodgeGame_boundsMask.png"); + + private int playerid; //--- Constructor - public WoodGUI(Handler handler, double x, double y, TextureRegion image) { + public WoodGUI(Handler handler, double x, double y, TextureRegion image, int playerid) { super(handler, x, y, image); - bounds = new Rectangle((int)x, (int)y, Main.WIDTH/5, Main.HEIGHT/20); + setGUIPosition(playerid); font = new BitmapFont(Gdx.files.internal("customFont4.fnt")); font.getData().setScale(3, 3); font.setColor(Color.WHITE); backTexture = new TextureRegion(handler.getGameState().getHealthTexture()).split(16, 4)[0][0]; texture = image.split(16, 16); + this.playerid = playerid; } @@ -41,19 +44,29 @@ public class WoodGUI extends GameObject { @Override public void render(SpriteBatch batch) { batch.draw(backTexture, bounds.x-bounds.width, bounds.y, bounds.width, bounds.height); - font.draw(batch, "x " + handler.getGameState().getPlayer().getWood(), bounds.x-64, bounds.y+Main.HEIGHT/20, 0, Align.left, false); + font.draw(batch, "x " + handler.getPlayers().getPlayer(playerid).getWood(), bounds.x-64, bounds.y+Main.HEIGHT/20, 0, Align.left, false); batch.draw(texture[0][0], bounds.x-bounds.width+16, bounds.y-4, Main.WIDTH/16, Main.HEIGHT/16); } @Override public void dispose() { font.dispose(); - boundsTexture.dispose(); + //boundsTexture.dispose(); } @Override public String toString() {return "WoodGUI";} + private void setGUIPosition(int playerid) { + switch (playerid) { + case 1: bounds = new Rectangle((int)(Main.WIDTH/5), (int)(Main.HEIGHT-Main.HEIGHT/20), Main.WIDTH/5, Main.HEIGHT/20); break; + case 2: bounds = new Rectangle((int)(Main.WIDTH), (int)(Main.HEIGHT-Main.HEIGHT/20), Main.WIDTH/5, Main.HEIGHT/20); break; + case 3: bounds = new Rectangle((int)(Main.WIDTH/5), (int)0, Main.WIDTH/5, Main.HEIGHT/20); break; + case 4: bounds = new Rectangle((int)(Main.WIDTH), (int)0, Main.WIDTH/5, Main.HEIGHT/20); break; + default: bounds = new Rectangle(); + } + } + //--- Getters and Setters diff --git a/core/src/com/jalenwinslow/game/states/ExitState.java b/core/src/com/jalenwinslow/game/states/ExitState.java index a6c2add..524812e 100644 --- a/core/src/com/jalenwinslow/game/states/ExitState.java +++ b/core/src/com/jalenwinslow/game/states/ExitState.java @@ -58,6 +58,7 @@ public class ExitState extends State { public void dispose() { font.dispose(); texture.dispose(); + handler.getPlayers().dispose(); } //--- Getters and Setters diff --git a/core/src/com/jalenwinslow/game/states/GameOverState.java b/core/src/com/jalenwinslow/game/states/GameOverState.java index ba1c057..a6f1455 100644 --- a/core/src/com/jalenwinslow/game/states/GameOverState.java +++ b/core/src/com/jalenwinslow/game/states/GameOverState.java @@ -1,6 +1,8 @@ package com.jalenwinslow.game.states; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; @@ -14,6 +16,7 @@ public class GameOverState extends State { //--- Propreties private Texture gameOverTexture; private BitmapFont font; + private float elapsedTime; //--- Constructor public GameOverState(Handler handler) { @@ -32,13 +35,16 @@ public class GameOverState extends State { font = new BitmapFont(Gdx.files.internal("customFont4.fnt")); font.getData().setScale(3, 3); font.setColor(Color.WHITE); + elapsedTime = 0; } @Override public void update(float dt) { - if (Gdx.input.justTouched()) { + elapsedTime += dt; + if (elapsedTime > 1 && Gdx.input.isKeyJustPressed(Keys.ANY_KEY)) { State.setCurrenState(handler.getMenuState()); State.getCurrentState().init(); + handler.getPlayers().resetPlayers(); dispose(); } } @@ -46,7 +52,7 @@ public class GameOverState extends State { @Override public void render(SpriteBatch batch) { batch.draw(gameOverTexture, 0, 0, Main.WIDTH, Main.HEIGHT); - font.draw(batch, "CLICK LEFT TO CONTINUE", 16, Main.HEIGHT-16); + font.draw(batch, "PRESS ANY KEY TO CONTINUE", 16, Main.HEIGHT-16); font.draw(batch, "SURVIVED FOR " + String.valueOf(handler.getGameState().getTimer().getTime()) + " SEC", Main.WIDTH/2, Main.HEIGHT/2 - 64, 0, Align.center, false); } diff --git a/core/src/com/jalenwinslow/game/states/GameState.java b/core/src/com/jalenwinslow/game/states/GameState.java index beea938..7abd071 100644 --- a/core/src/com/jalenwinslow/game/states/GameState.java +++ b/core/src/com/jalenwinslow/game/states/GameState.java @@ -15,23 +15,27 @@ public class GameState extends State{ //--- Propreties Texture background; - Texture playerTexture; Texture woodTexture; Texture arrowTexture; Texture wallTexture; Texture tallWallTexture; Texture healthTexture; + Texture healTexture; - private Player player; + private WoodGUI[] woodGUIs; private WoodGUI woodGui; + private WoodGUI woodGui2; private Grid grid; private ArrowGenerator arrowGen; private WallGenerator wallGen; private WoodGenerator woodGen; + private HealerGenerator healGen; private Wall[] bottomWalls; private Timer timer; private Random rand; + private boolean pause; + //--- Constructor public GameState(Handler handler) { super(handler); @@ -42,25 +46,35 @@ public class GameState extends State{ @Override public void init() { background = new Texture("b&w_DodgeGame_background2.png"); - playerTexture = new Texture("b&w_DodgeGame_man1.png"); woodTexture = new Texture("b&w_DodgeGame_wood1.png"); arrowTexture = new Texture("b&w_DodgeGame_arrow.png"); wallTexture = new Texture("b&w_DodgeGame_wall1.png"); tallWallTexture = new Texture("b&w_DodgeGame_tallWall1.png"); healthTexture = new Texture("b&w_DodgeGame_health1.png"); - player = new Player(handler, Main.WIDTH/2, Main.HEIGHT/2, new TextureRegion(playerTexture)); - woodGui = new WoodGUI(handler, Main.WIDTH, 0, new TextureRegion(woodTexture)); + healTexture = new Texture("b&w_DodgeGame_healer.png"); + //players + //numOfPlayers = handler.getPlayers().getNumOfPlayers(); + //players = new Player[numOfPlayers]; + //player = new Player(handler, Main.WIDTH/2-64, Main.HEIGHT/2, new TextureRegion(playerTexture), 1); + //players[0] = player; + handler.getPlayers().addPlayersToGameObjects(); + woodGUIs = new WoodGUI[handler.getPlayers().getNumOfPlayers()]; + for (int i = 0; i < woodGUIs.length; i++) { + woodGUIs[i] = new WoodGUI(handler, 0, 0, new TextureRegion(woodTexture), i+1); + } + grid = new Grid(handler); arrowGen = new ArrowGenerator(handler, 0, 0, new TextureRegion(arrowTexture)); wallGen = new WallGenerator(handler, 0, 0, new TextureRegion(wallTexture)); woodGen = new WoodGenerator(handler, 0, 0, new TextureRegion(woodTexture)); + healGen = new HealerGenerator(handler, 0, 0, new TextureRegion(healTexture)); bottomWalls = new Wall[Main.WIDTH/64]; for (int i = 0; i < Main.WIDTH/64; i++) { bottomWalls[i] = new ShortWall(handler, 64*i, 0, new TextureRegion(wallTexture)); } timer = new Timer(handler, Main.WIDTH/2, Main.HEIGHT-(Main.HEIGHT/10+32), null); + pause = false; - handler.getGameObjectHandler().add(player); handler.getGameObjectHandler().getGameObjects().addAll(bottomWalls, 0, bottomWalls.length); } @@ -70,12 +84,16 @@ public class GameState extends State{ arrowGen.update(dt); wallGen.update(dt); woodGen.update(dt); + healGen.update(dt); timer.update(dt); - woodGui.update(dt); - if (Gdx.input.isKeyJustPressed(Keys.P)) { + for (WoodGUI wgui : woodGUIs) { + wgui.update(dt); + } + if (pause) { State.setCurrenState(handler.getPauseState()); State.getCurrentState().init(); } + checkForPlayers(); } @Override @@ -85,33 +103,56 @@ public class GameState extends State{ arrowGen.render(batch); wallGen.render(batch); woodGen.render(batch); + healGen.render(batch); timer.render(batch); - woodGui.render(batch); + for (WoodGUI wgui : woodGUIs) wgui.render(batch); } @Override public void dispose() { if (background != null) background.dispose(); - if (playerTexture != null) playerTexture.dispose(); if (arrowTexture != null) arrowTexture.dispose(); if (wallTexture != null) wallTexture.dispose(); if (woodTexture != null) woodTexture.dispose(); if (tallWallTexture != null) tallWallTexture.dispose(); if (healthTexture != null) healthTexture.dispose(); + if (healTexture != null) healTexture.dispose(); if (timer != null) timer.dispose(); if (woodGui != null) woodGui.dispose(); } + public void checkForPlayers() { + boolean check = false; + for (int i = 0; i < handler.getPlayers().getNumOfPlayers(); i++) { + if (handler.getPlayers().getPlayer(i+1).isDead()) { + check = true; + } else { + check = false; + break; + } + } + + if (check) { + handler.getGameState().getTimer().stop(); + State.setCurrenState(handler.getGameOverState()); + State.getCurrentState().init(); + handler.getGameObjectHandler().dispose(); + handler.getGameState().dispose(); + } + } + //--- Getters and Setters public Texture getHealthTexture() {return healthTexture;} public Texture getTallWallTexture() {return tallWallTexture;} - public Player getPlayer() {return player;} public Grid getGrid() {return grid;} public ArrowGenerator getArrowGen() {return arrowGen;} public WallGenerator getWallGen() {return wallGen;} public WoodGenerator getWoodGen() {return woodGen;} + public HealerGenerator getHealGen() {return healGen;} public Wall[] getBottomWalls() {return bottomWalls;} public Timer getTimer() {return timer;} + public boolean getPause() {return pause;} + public void setPause(boolean pause) {this.pause = pause;} } diff --git a/core/src/com/jalenwinslow/game/states/MenuState.java b/core/src/com/jalenwinslow/game/states/MenuState.java index 9b5cea6..3f10e4f 100644 --- a/core/src/com/jalenwinslow/game/states/MenuState.java +++ b/core/src/com/jalenwinslow/game/states/MenuState.java @@ -1,15 +1,20 @@ package com.jalenwinslow.game.states; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.jalenwinslow.game.Handler; import com.jalenwinslow.game.Main; import com.jalenwinslow.game.gameobjects.Button; +import com.jalenwinslow.game.gameobjects.ControllerButton; import com.jalenwinslow.game.gameobjects.Player; import com.jalenwinslow.game.gameobjects.ScoreBoard; import com.jalenwinslow.game.gameobjects.ShortWall; import com.jalenwinslow.game.gameobjects.Wall; +import com.jalenwinslow.game.utils.Players; public class MenuState extends State{ @@ -19,14 +24,13 @@ public class MenuState extends State{ Texture menuBg; //Texture playButtonTexture; Texture buttonTexture; - Texture playerTexture; Texture wallTexture; Texture healthTexture; Texture scoreBoardTexture; private Button[] buttons; + private ControllerButton[] cButtons; private Button backButton; - private Player player; private Wall[] bottomWalls; private ScoreBoard scoreBoard; //private PlayButton playBtn; @@ -45,22 +49,30 @@ public class MenuState extends State{ menuBg = new Texture("b&w_DodgeGame_background2.png"); //playButtonTexture = new Texture("b&w_DodgeGame_playButton.png"); buttonTexture = new Texture("b&w_DodgeGame_buttons1.png"); - playerTexture = new Texture("b&w_DodgeGame_man1.png"); wallTexture = new Texture("b&w_DodgeGame_wall1.png"); healthTexture = new Texture("b&w_DodgeGame_health1.png"); scoreBoardTexture = new Texture("b&w_DodgeGame_scoreBoard.png"); - buttons = new Button[3]; + buttons = new Button[4]; buttons[0] = new Button(handler, Main.WIDTH/4-64, Main.HEIGHT*3/4-96, new TextureRegion(buttonTexture), "PLAY", 6); buttons[1] = new Button(handler, Main.WIDTH*3/4-(64*2), Main.HEIGHT*3/4-96, new TextureRegion(buttonTexture), "STATS", 6); buttons[2] = new Button(handler, Main.WIDTH/4-64, Main.HEIGHT/4+32, new TextureRegion(buttonTexture), "EXIT", 6 ); - player = new Player(handler, Main.WIDTH/2, Main.HEIGHT/2, new TextureRegion(playerTexture)); + buttons[3] = new Button(handler, Main.WIDTH*3/4-(64*2), Main.HEIGHT/4+32, new TextureRegion(buttonTexture), "MULTI-\nPLAYER", 3); + cButtons = new ControllerButton[4]; + cButtons[0] = new ControllerButton(handler, Main.WIDTH/4-64, Main.HEIGHT*3/4-96, new TextureRegion(buttonTexture), "PLAYER 1", 4, 1); + cButtons[1] = new ControllerButton(handler, Main.WIDTH*3/4-(64*2), Main.HEIGHT*3/4-96, new TextureRegion(buttonTexture), "PLAYER\n2", 4, 2); + cButtons[2] = new ControllerButton(handler, Main.WIDTH/4-64, Main.HEIGHT/4+32, new TextureRegion(buttonTexture), "PLAYER\n3", 4 , 3); + cButtons[3] = new ControllerButton(handler, Main.WIDTH*3/4-(64*2), Main.HEIGHT/4+32, new TextureRegion(buttonTexture), "PLAYER\n4", 4, 4); + //player + if (handler.getPlayers().getNumOfPlayers() == 0) { + handler.getPlayers().addPlayer(new Player(handler, Main.WIDTH/2-64, Main.HEIGHT/2, new TextureRegion(Players.player1Texture), 1)); + } else handler.getPlayers().addPlayersToGameObjects(); + backButton = new Button(handler, Main.WIDTH/2-96, Main.HEIGHT/4-64, new TextureRegion(buttonTexture), "BACK", 6); bottomWalls = new Wall[Main.WIDTH/64]; for (int i = 0; i < bottomWalls.length; i++) { bottomWalls[i] = new ShortWall(handler, 64*i, 0, new TextureRegion(wallTexture)); } scoreBoard = new ScoreBoard(handler, Main.WIDTH/8, Main.HEIGHT*3/8, new TextureRegion(scoreBoardTexture)); - handler.getGameObjectHandler().add(player); handler.getGameObjectHandler().getGameObjects().addAll(bottomWalls, 0, bottomWalls.length); //playBtn = new PlayButton(handler, Main.WIDTH/2, Main.HEIGHT/2, new TextureRegion(playButtonTexture)); } @@ -72,10 +84,19 @@ public class MenuState extends State{ for (Button button : buttons) { if (button != null) button.update(dt); } + addPlayers(); break; case 1: backButton.update(dt); break; + case 2: + for (ControllerButton cb : cButtons) { + if (cb != null) cb.update(dt); + } + backButton.update(dt); + break; + case 3: + backButton.update(dt); default: break; @@ -96,6 +117,14 @@ public class MenuState extends State{ scoreBoard.render(batch); backButton.render(batch); break; + case 2: + for (ControllerButton cb : cButtons) { + if (cb != null) cb.render(batch); + } + backButton.render(batch); + break; + case 3: + backButton.render(batch); default: break; @@ -108,7 +137,6 @@ public class MenuState extends State{ public void dispose() { menuBg.dispose(); buttonTexture.dispose(); - playerTexture.dispose(); wallTexture.dispose(); healthTexture.dispose(); scoreBoardTexture.dispose(); @@ -116,13 +144,15 @@ public class MenuState extends State{ for (Button button: buttons) {button.dispose();} backButton.dispose(); //playButtonTexture.dispose(); - //player = null; - //buttons = null; - //bottomWalls = null; + } + + public void addPlayers() { + if (Gdx.input.isKeyJustPressed(Keys.NUM_2)) { + handler.getPlayers().addPlayer(new Player(handler, Main.WIDTH/2, Main.HEIGHT/2, new TextureRegion(Players.player2Texture), 2)); + } } //--- Getters and Setters - public Player getPlayer() {return player;} public Texture getHealthTexture() {return healthTexture;} public int getSubState() {return subState;} diff --git a/core/src/com/jalenwinslow/game/states/PauseState.java b/core/src/com/jalenwinslow/game/states/PauseState.java index 00462a7..3e557ad 100644 --- a/core/src/com/jalenwinslow/game/states/PauseState.java +++ b/core/src/com/jalenwinslow/game/states/PauseState.java @@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.utils.Align; import com.jalenwinslow.game.Handler; import com.jalenwinslow.game.Main; +import com.jalenwinslow.game.gameobjects.Player; public class PauseState extends State { @@ -31,9 +32,12 @@ public class PauseState extends State { @Override public void update(float dt) { - if (Gdx.input.isKeyJustPressed(Keys.P)) { - State.setCurrenState(handler.getGameState()); - dispose(); + for (Player player : handler.getPlayers().getPlayers()) { + if (player.returnPausePressed()) { + State.setCurrenState(handler.getGameState()); + handler.getGameState().setPause(false); + dispose(); + } } } diff --git a/core/src/com/jalenwinslow/game/utils/Players.java b/core/src/com/jalenwinslow/game/utils/Players.java new file mode 100644 index 0000000..0a033d1 --- /dev/null +++ b/core/src/com/jalenwinslow/game/utils/Players.java @@ -0,0 +1,97 @@ +package com.jalenwinslow.game.utils; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.utils.Array; +import com.jalenwinslow.game.Handler; +import com.jalenwinslow.game.Main; +import com.jalenwinslow.game.gameobjects.Player; + +public class Players { + + //--- Propreties + public static Texture playerHealthTexture = new Texture("b&w_DodgeGame_health1.png"); + public static Texture player1Texture = new Texture("b&w_DodgeGame_man1.png"); + public static Texture player2Texture = new Texture("b&w_DodgeGame_woman1.png"); + + private Handler handler; + private Array players; + private int numOfPlayers; + + //--- Constructor + public Players(Handler handler) { + this.handler = handler; + players = new Array(); + numOfPlayers = players.size; + + } + + + //--- Methods + + + public void addPlayer(Player player) { + if (numOfPlayers < 4) { + players.add(player); + handler.getGameObjectHandler().add(player); + numOfPlayers = players.size; + for (int i = 0; i < players.size; i++) { + players.get(i).setPlayerId(i+1); + } + } + } + + public void addPlayersToGameObjects() { + for (Player player : players) { + handler.getGameObjectHandler().add(player); + } + } + + public void removePlayer(Player player) { + if (numOfPlayers > 0) { + players.removeValue(player, false); + handler.getGameObjectHandler().getGameObjects().removeValue(player, false); + numOfPlayers = players.size; + for (int i = 0; i < players.size; i++) { + players.get(i).setPlayerId(i+1); + } + } + } + + public Player getPlayer(int index) { + if (players.get(index-1) != null) + return players.get(index-1); + else return null; + } + + public void centerPlayers() { + if (players.get(0) != null) players.get(0).setPosition(Main.WIDTH/2-Main.WIDTH/10, Main.HEIGHT/2); + if (numOfPlayers == 2 && players.get(1) != null) players.get(1).setPosition(Main.WIDTH/2, Main.HEIGHT/2); + if (numOfPlayers == 3 && players.get(2) != null) players.get(2).setPosition(Main.WIDTH/2-Main.WIDTH/10, Main.HEIGHT/2-Main.HEIGHT/10); + if (numOfPlayers == 4 && players.get(3) != null) players.get(3).setPosition(Main.WIDTH/2, Main.HEIGHT/2-Main.HEIGHT/10); + } + + public void resetPlayers() { + for (Player player : players) { + player.resetPlayer(); + } + centerPlayers(); + } + + public void dispose() { + player1Texture.dispose(); + playerHealthTexture.dispose(); + } + + //--- Getters and Setters + public Array getPlayers() {return players;} + public Player getPlayer1() {return players.get(0);} + public Player getPlayer2() {return players.get(1);} + public Player getPlayer3() {return players.get(2);} + public Player getPlayer4() {return players.get(3);} + public int getNumOfPlayers() {return numOfPlayers;} + + public void setPlayer(Player player, int playerNum) {players.set(playerNum-1, player);} + public void setNumOfPlayers(int num) {this.numOfPlayers = num;} + +} diff --git a/core/src/com/jalenwinslow/game/utils/Score.java b/core/src/com/jalenwinslow/game/utils/Score.java index fdd7f6f..efa1a04 100644 --- a/core/src/com/jalenwinslow/game/utils/Score.java +++ b/core/src/com/jalenwinslow/game/utils/Score.java @@ -38,15 +38,15 @@ public class Score { if (handler.getGameState().getWallGen().getHighestNumberOfShortWallsDestroyed() > highestNumberOfShortWallsDestroyed) highestNumberOfShortWallsDestroyed = handler.getGameState().getWallGen().getHighestNumberOfShortWallsDestroyed(); - if (handler.getGameState().getPlayer().getHighestNumberOfTallWallsCreated() > highestNumberOfTallWallsCreated) - highestNumberOfTallWallsCreated = handler.getGameState().getPlayer().getHighestNumberOfTallWallsCreated(); + if (handler.getPlayers().getPlayer1().getHighestNumberOfTallWallsCreated() > highestNumberOfTallWallsCreated) + highestNumberOfTallWallsCreated = handler.getPlayers().getPlayer1().getHighestNumberOfTallWallsCreated(); if (handler.getGameObjectHandler().getHighestNumberOfTallWallsAtOnce() > highestNumberOfTallWallsAtOnce) highestNumberOfTallWallsAtOnce = handler.getGameObjectHandler().getHighestNumberOfTallWallsAtOnce(); - if (handler.getGameState().getPlayer().getHighestNumberOfTallWallsDestroyed() > highestNumberOfTallWallsDestroyed) - highestNumberOfTallWallsDestroyed = handler.getGameState().getPlayer().getHighestNumberOfTallWallsDestroyed(); + if (handler.getPlayers().getPlayer1().getHighestNumberOfTallWallsDestroyed() > highestNumberOfTallWallsDestroyed) + highestNumberOfTallWallsDestroyed = handler.getPlayers().getPlayer1().getHighestNumberOfTallWallsDestroyed(); - if (handler.getGameState().getPlayer().getNumberOfWoodPickedUp() > highestNumberOfWoodPickedUp) - highestNumberOfWoodPickedUp = handler.getGameState().getPlayer().getNumberOfWoodPickedUp(); + if (handler.getPlayers().getPlayer1().getNumberOfWoodPickedUp() > highestNumberOfWoodPickedUp) + highestNumberOfWoodPickedUp = handler.getPlayers().getPlayer1().getNumberOfWoodPickedUp(); } public void getScoresFromFile() { diff --git a/desktop/build_1.gradle b/desktop/build_1.gradle new file mode 100644 index 0000000..df7038f --- /dev/null +++ b/desktop/build_1.gradle @@ -0,0 +1,55 @@ +apply plugin: "java" + +sourceCompatibility = 1.6 +sourceSets.main.java.srcDirs = [ "src/" ] + +project.ext.mainClassName = "com.jwinslow.game.desktop.DesktopLauncher" +project.ext.assetsDir = new File("../android/assets"); + +task run(dependsOn: classes, type: JavaExec) { + main = project.mainClassName + classpath = sourceSets.main.runtimeClasspath + standardInput = System.in + workingDir = project.assetsDir + ignoreExitValue = true +} + +task debug(dependsOn: classes, type: JavaExec) { + main = project.mainClassName + classpath = sourceSets.main.runtimeClasspath + standardInput = System.in + workingDir = project.assetsDir + ignoreExitValue = true + debug = true +} + +task dist(type: Jar) { + from files(sourceSets.main.output.classesDir) + from files(sourceSets.main.output.resourcesDir) + from {configurations.compile.collect {zipTree(it)}} + from files(project.assetsDir); + + manifest { + attributes 'Main-Class': project.mainClassName + } +} + +dist.dependsOn classes + +eclipse { + project { + name = appName + "-desktop" + linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/android/assets' + } +} + +task afterEclipseImport(description: "Post processing after project generation", group: "IDE") { + doLast { + def classpath = new XmlParser().parse(file(".classpath")) + new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]); + def writer = new FileWriter(file(".classpath")) + def printer = new XmlNodePrinter(new PrintWriter(writer)) + printer.setPreserveWhitespace(true) + printer.print(classpath) + } +}