diff --git a/android/assets/target.png b/android/assets/target.png new file mode 100644 index 0000000000000000000000000000000000000000..cc2ea6c4aa944df052a7820b1e29f252b1f52d33 Binary files /dev/null and b/android/assets/target.png differ diff --git a/core/src/com/tdt4240/paint2win/controller/managers/Collider.java b/core/src/com/tdt4240/paint2win/controller/managers/Collider.java index 0a3f3c3524e4127490ccff0235a655cc314b70c3..0de362a600641fd74e54bf73dfb82c654e39d1bc 100644 --- a/core/src/com/tdt4240/paint2win/controller/managers/Collider.java +++ b/core/src/com/tdt4240/paint2win/controller/managers/Collider.java @@ -3,11 +3,13 @@ package com.tdt4240.paint2win.controller.managers; import com.tdt4240.paint2win.container.BulletsContainer; import com.tdt4240.paint2win.container.ObstacleContainer; import com.tdt4240.paint2win.container.PlayersContainer; +import com.tdt4240.paint2win.model.Target; public class Collider { private final PlayersContainer playersContainer; private final BulletsContainer bulletsContainer; private final ObstacleContainer obstacleContainer; + private final Target target; /** * Manager to check if bullet and players collide (player get shoot), @@ -16,10 +18,11 @@ public class Collider { * @param bulletsContainer Container with bullets in the map * @param obstacleContainer Container with obstacles in the map */ - public Collider(PlayersContainer playersContainer, BulletsContainer bulletsContainer, ObstacleContainer obstacleContainer) { + public Collider(PlayersContainer playersContainer, BulletsContainer bulletsContainer, ObstacleContainer obstacleContainer, Target target) { this.playersContainer = playersContainer; this.bulletsContainer = bulletsContainer; this.obstacleContainer = obstacleContainer; + this.target = target; } /** @@ -27,12 +30,8 @@ public class Collider { * checks if bullet hits obstacle (removes bullet) */ public void checkCollisions() { - bulletsContainer.stream().forEach(bullet -> playersContainer.stream() - .filter(player -> player.getShooter().isPresent()) - .filter(player -> player.getShooter() - .get().collidesWith(bullet)) - .findFirst() - .ifPresent(player -> {player.noticeHit(bullet.getPlayer()); bullet.noticeHit();})); + bulletsContainer.stream().filter(bullet -> bullet.collidesWith(target)) + .findFirst().ifPresent(bullet -> {target.noticeHit(); bullet.noticeHit();}); bulletsContainer.stream().forEach(bullet -> obstacleContainer.stream() .filter(obstacle -> obstacle.collidesWith(bullet)) .findFirst() diff --git a/core/src/com/tdt4240/paint2win/controller/states/FinishedGame.java b/core/src/com/tdt4240/paint2win/controller/states/FinishedGame.java index b8d6e02e9f1a8e4db9b69e219605d5699c90a567..b05988d5c57489ac1d0b93cb7d209ee53c7f32d1 100644 --- a/core/src/com/tdt4240/paint2win/controller/states/FinishedGame.java +++ b/core/src/com/tdt4240/paint2win/controller/states/FinishedGame.java @@ -1,14 +1,18 @@ package com.tdt4240.paint2win.controller.states; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; import com.tdt4240.paint2win.Paint2Win; +import com.tdt4240.paint2win.model.TimerWatch; import static com.tdt4240.paint2win.Paint2Win.MENU_HEIGHT; import static com.tdt4240.paint2win.Paint2Win.MENU_WIDTH; @@ -19,14 +23,24 @@ public class FinishedGame extends State { private final Texture backgroundImage; private final Texture mainMenuButton; - private final Texture header; private final int mainMenuButtonXPosition; private final int mainMenuButtonYPosition; + private BitmapFont textRenderer; + private long timeUsed; + private static final float getPositionOffset(BitmapFont bitmapFont, String value) { + GlyphLayout glyphLayout = new GlyphLayout(); + glyphLayout.setText(bitmapFont, value); + return (MENU_WIDTH - glyphLayout.width)/2 ; + } - public FinishedGame(GameStateManager gsm, boolean Won) { + public FinishedGame(GameStateManager gsm, boolean Won, long timeUsed) { super(gsm); + this.textRenderer = new BitmapFont(); + this.timeUsed = timeUsed; + textRenderer.getData().setScale(4); + textRenderer.setColor(Color.WHITE); cam = new OrthographicCamera(); cam.setToOrtho(false, MENU_WIDTH, MENU_HEIGHT); backgroundImage = new Texture("WinOrLose.png"); @@ -35,11 +49,9 @@ public class FinishedGame extends State { mainMenuButtonYPosition = MENU_HEIGHT/4; Paint2Win.AUDIO_MANAGER.stopMusic(); if(Won){ - header = new Texture("YouWin.png"); Paint2Win.AUDIO_MANAGER.playSound("winSound.mp3"); } else{ - header = new Texture("YouLose.png"); Paint2Win.AUDIO_MANAGER.playSound("failSound.mp3"); } } @@ -84,7 +96,8 @@ public class FinishedGame extends State { sb.setProjectionMatrix(cam.combined); sb.begin(); sb.draw(backgroundImage, 0,0, MENU_WIDTH, MENU_HEIGHT); - sb.draw(header, MENU_WIDTH/2 - header.getWidth()/2,MENU_HEIGHT/2); + textRenderer.setColor(Color.OLIVE); + textRenderer.draw(sb, "Your time: "+TimerWatch.fancyString(this.timeUsed), getPositionOffset(textRenderer,"Your time: "+TimerWatch.fancyString(this.timeUsed)), MENU_HEIGHT/1.75f); sb.draw(mainMenuButton, mainMenuButtonXPosition, mainMenuButtonYPosition); sb.end(); } @@ -97,6 +110,5 @@ public class FinishedGame extends State { System.out.println("Disposed finishedGame"); backgroundImage.dispose(); mainMenuButton.dispose(); - header.dispose(); } } diff --git a/core/src/com/tdt4240/paint2win/controller/states/PlayState.java b/core/src/com/tdt4240/paint2win/controller/states/PlayState.java index 2117b8fe63d77679ca7cac5a24a6aed48de42463..a9389eb4d238883fe524a0ecc9be21278cb6f8fa 100644 --- a/core/src/com/tdt4240/paint2win/controller/states/PlayState.java +++ b/core/src/com/tdt4240/paint2win/controller/states/PlayState.java @@ -1,22 +1,23 @@ package com.tdt4240.paint2win.controller.states; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.utils.viewport.FillViewport; import com.badlogic.gdx.utils.viewport.Viewport; import com.tdt4240.paint2win.Paint2Win; import com.tdt4240.paint2win.container.BulletsContainer; -import com.tdt4240.paint2win.container.ObstacleContainer; import com.tdt4240.paint2win.container.PlayersContainer; import com.tdt4240.paint2win.controller.controls.DualJoysticks; import com.tdt4240.paint2win.controller.managers.Collider; import com.tdt4240.paint2win.controller.managers.Respawner; import com.tdt4240.paint2win.model.Bullet; import com.tdt4240.paint2win.model.GameMap; +import com.tdt4240.paint2win.model.Target; +import com.tdt4240.paint2win.model.TimerWatch; import com.tdt4240.paint2win.model.maps.AbstractMap; import com.tdt4240.paint2win.model.Obstacle; import com.tdt4240.paint2win.model.Player; @@ -38,7 +39,6 @@ public class PlayState extends State { private GameMap gameMap; private PlayersContainer playersContainer; private BulletsContainer bulletsContainer; - private ObstacleContainer obstacleContainer; private Respawner respawner; private Collider collider; private ContainerRenderer<Player> playersRenderer; @@ -51,6 +51,8 @@ public class PlayState extends State { private AbstractMap map; private Scoreboard scoreboard; private BitmapFont textrenderer; + private Target target; + private TimerWatch timerWatch; /** * Constructor, includes all logic that only has to get rendered once @@ -60,39 +62,36 @@ public class PlayState extends State { super(gsm); viewport = new FillViewport(MAP_WIDTH, MAP_HEIGHT); gameMap = new GameMap(MAP_WIDTH, MAP_HEIGHT); - obstacleContainer = new ObstacleContainer(); - chooseMap(mapType); - mainplayer = new Player(Color.CYAN,obstacleContainer); - Player player2 = new Player(Color.RED,obstacleContainer); + bulletsContainer = new BulletsContainer(); playersContainer = new PlayersContainer(); + chooseMap(mapType); + mainplayer = new Player(Color.CYAN,map.getObstacleContainer()); playersContainer.add(mainplayer); - playersContainer.add(player2); - bulletsContainer = new BulletsContainer(); - respawner = new Respawner(playersContainer, obstacleContainer); - collider = new Collider(playersContainer, bulletsContainer, obstacleContainer); + respawner = new Respawner(playersContainer, map.getObstacleContainer()); + stage = new Stage(viewport); + scoreboard = new Scoreboard(1,mainplayer.getColor()); + timerWatch = new TimerWatch(mainplayer.getColor()); + target = new Target(map.getObstacleContainer(), scoreboard); + collider = new Collider(playersContainer, bulletsContainer, map.getObstacleContainer(), target); playersRenderer = new ContainerRenderer<Player>(playersContainer, PlayerRenderer::new); bulletsRenderer = new ContainerRenderer<Bullet>(bulletsContainer, VisibleRenderer::new); - obstacleRenderer = new ContainerRenderer<Obstacle>(obstacleContainer, VisibleRenderer::new); + obstacleRenderer = new ContainerRenderer<Obstacle>(map.getObstacleContainer(), VisibleRenderer::new); playerCamera = new PlayerCamera(); - stage = new Stage(viewport); joysticks = new DualJoysticks(stage); this.joysticks.addObserver(mainplayer); - //this.joysticks.addObserver(player2); - scoreboard = new Scoreboard(0.f,stage.getHeight()); - mainplayer.addObserver(scoreboard); - player2.addObserver(scoreboard); this.textrenderer = new BitmapFont(); textrenderer.setColor(Color.WHITE); textrenderer.getData().setScale(8); Paint2Win.AUDIO_MANAGER.playMusic("run_free.mp3"); + timerWatch.start(); } private void chooseMap(AbstractMap.valid_maps chosenMap) { if (chosenMap == AbstractMap.valid_maps.DESERT) { - map = new desert_map(obstacleContainer); + map = new desert_map(); } else if (chosenMap == AbstractMap.valid_maps.URBAN) { - map = new urban_map(obstacleContainer); + map = new urban_map(); } } @@ -109,8 +108,8 @@ public class PlayState extends State { playersContainer.streamShooters().forEach(gameMap::ensurePlacementWithinBounds); playersContainer.obtainAndStreamBullets().forEach(bulletsContainer::add); bulletsContainer.update(delta); - obstacleContainer.update(delta); - obstacleContainer.stream().forEach(gameMap::ensurePlacementWithinBounds); + map.getObstacleContainer().update(delta); + map.getObstacleContainer().stream().forEach(gameMap::ensurePlacementWithinBounds); } /** @@ -122,7 +121,6 @@ public class PlayState extends State { public void render(SpriteBatch sb) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - viewport.apply(); sb.begin(); sb.setProjectionMatrix(playerCamera.updatedCamera(mainplayer.getPos().x, mainplayer.getPos().y).combined); @@ -131,10 +129,14 @@ public class PlayState extends State { playersRenderer.render(sb); bulletsRenderer.render(sb); obstacleRenderer.render(sb); + target.draw(sb); sb.end(); joysticks.render(); - //scoreboard.setPosition(0,stage.getHeight()-10); - scoreboard.render(stage.getBatch(), textrenderer); + scoreboard.render(new Vector2 (0.f,stage.getHeight()/1.1f),stage.getBatch(), textrenderer); + timerWatch.render(new Vector2(stage.getWidth()/1.5f,stage.getHeight()/1.1f), stage.getBatch(), textrenderer); + if(scoreboard.isGoalReached()){ + gsm.set(new FinishedGame(gsm,true, timerWatch.getElapsedTime())); + } } @Override diff --git a/core/src/com/tdt4240/paint2win/model/Scoreboard.java b/core/src/com/tdt4240/paint2win/model/Scoreboard.java index ec5128ff29065653413173fd64e292aca120bf70..fc1318a0853d3787152bab7066fccf45f894b0b0 100644 --- a/core/src/com/tdt4240/paint2win/model/Scoreboard.java +++ b/core/src/com/tdt4240/paint2win/model/Scoreboard.java @@ -3,234 +3,48 @@ package com.tdt4240.paint2win.model; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.tdt4240.paint2win.utility.IDeathObserver; -import com.tdt4240.paint2win.view.PlayerCamera; +import com.badlogic.gdx.math.Vector2; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -/** Scoreboard counts the mount of times the ID player gets hit - * @author JLK +/** Scoreboard counts the mount of times the Target gets hit + * @author HMM */ -public class Scoreboard implements IDeathObserver { - private float posX; - private float posY; - - private int numScoreObjects; - private Map<UUID, Color> ColorTable; - private Map<UUID,Integer> ScoreTable; - private Map<UUID,String> NameTable; - - - private int goal; - private boolean isGoalReached; - - public Scoreboard(float x, float y){ - this.ScoreTable = new HashMap<UUID,Integer>(); - this.ColorTable = new HashMap<UUID,Color>(); - this.NameTable = new HashMap<UUID,String>(); - this.isGoalReached =false; - numScoreObjects=0; - posX=0; - posY=0; - setPosition(x,y); - } +public class Scoreboard { + private int score; + private int maxScore; + private Color color; - public Scoreboard(){ - this.ScoreTable = new HashMap<UUID,Integer>(); - this.ColorTable = new HashMap<UUID,Color>(); - this.NameTable = new HashMap<UUID,String>(); - this.isGoalReached =false; - numScoreObjects=0; - posX=0; - posY=0; + public Scoreboard(int maxScore, Color color) { + this.score = 0; + this.maxScore = maxScore; + this.color = color; } - /** Render and update function need to ber run every frame - * - * @param sb spritebatch - * @param textrenderer bitmapfont + /** + * Render and update function need to ber run every frame + * @param sb spritebatch + * @param textRenderer bitmapfont */ - public void render(Batch sb, BitmapFont textrenderer){ + public void render(Vector2 position, Batch sb, BitmapFont textRenderer) { sb.begin(); - int i = 0; - for (Map.Entry mapElement : ScoreTable.entrySet()) { - UUID ID = (UUID)mapElement.getKey(); - int score = (int)mapElement.getValue(); - - //System.out.println((String)(ID+ ":"+ score)); - textrenderer.setColor(getColor(ID)); - textrenderer.draw(sb,(String)(this.getName(ID)+ ": "+score) ,posX ,posY-i); - textrenderer.setColor(Color.WHITE); - textrenderer.getLineHeight(); - i+=textrenderer.getLineHeight(); - if (score >= goal){ - isGoalReached=true; - } - } + textRenderer.setColor(color); + textRenderer.draw(sb, "Targets hit: " + score + "/" + maxScore, position.x, position.y); sb.end(); } /** - * Sets the position for the scoreboard to be drawn at - * @param x x-postion - * @param y y-position - */ - public void setPosition(float x, float y) { - posX = x; - posY = y; - } - - /** is the goal reched of this scoreboard - * - * @return - */ - public boolean isGoalReached(){return isGoalReached;} - - /** Set the goal of the scoreboard - * - * @param goal integer of score - */ - public void setGoal(int goal){this.goal=goal;} - - /** Gets the name of the winning player, - * - * @return returns "None" if no winner has reached the goal - */ - public String getWinner(){ - String winner="None"; - if (isGoalReached){ - for (Map.Entry mapElement : ScoreTable.entrySet()) { - UUID ID = (UUID)mapElement.getKey(); - int score = (int)mapElement.getValue(); - if (score >= goal){ - winner = getName(ID); - } - } - } - return winner; - } - - /** Adds 1 to the score of the player with ID - * - * @param ID id of player - */ - private void addScore(UUID ID){ - this.ScoreTable.put(ID,this.ScoreTable.get(ID)+1); - } - - private void addScoreToOthers(UUID ID){ - for (Map.Entry mapElement : ScoreTable.entrySet()) { - UUID id = (UUID)mapElement.getKey(); - int score = (int)mapElement.getValue(); - if(ID!=id){ - addScore(id); - } - } - } - - /** adds an id object to tracked - * - * @param ID id of player - */ - public void addScoreObject(UUID ID){ - if (!this.ScoreTable.containsKey(ID)){ - this.ScoreTable.put(ID,0); - numScoreObjects++; - } - } - - /** Adds a color to be associated with their ID - * - * @param ID - * @param color - */ - public void addColor(UUID ID, Color color){ - if (this.ScoreTable.containsKey(ID)){ - this.ColorTable.put(ID,color); - } - } - public Color getColor(UUID ID){ - return this.ColorTable.get(ID); - } - - /**Adds a name to be associated with their ID - * - * @param ID - * @param name - */ - public void addName(UUID ID, String name){ - if (this.ScoreTable.containsKey(ID)){ - this.NameTable.put(ID,name); - } - } - public void addName(UUID ID){ - if (this.ScoreTable.containsKey(ID)){ - this.NameTable.put(ID,(String)("Player "+numScoreObjects)); - } - } - public String getName(UUID ID){ - return this.NameTable.get(ID); - } - - - - /** removes the id object from scoreboard + * Is the goal reached of this scoreboard * - * @param ID id of player + * @return true if goal is reached */ - public void RemoveScoreObject(UUID ID){ - this.ScoreTable.remove(ID); - this.ColorTable.remove(ID); - this.NameTable.remove(ID); - numScoreObjects--; + public boolean isGoalReached() { + return score == maxScore; } /** - * Updates the scoreboard based on different events - * @param ID - * @param dead + * Adds one to the score */ - @Override - public void UpdateEvent(UUID ID, boolean dead, Color color) { - if (dead){ - if (this.ScoreTable.containsKey(ID)){ - addScoreToOthers(ID); - } - else if (!this.ScoreTable.containsKey(ID)){ - addScoreObject(ID); - addColor(ID, color); - addName(ID); - addScoreToOthers(ID); - } - } - else { - if (!this.ScoreTable.containsKey(ID)){ - addScoreObject(ID); - addColor(ID, color); - addName(ID); - } - else if (this.ScoreTable.containsKey(ID)){ - addColor(ID, color); - addName(ID); - } - } + public void increaseScore() { + this.score++; } - @Override - public void UpdateEvent(UUID IDtogivepointsto, Color color) { - if (this.ScoreTable.containsKey(IDtogivepointsto)){ - addScore(IDtogivepointsto); - } - else if (!this.ScoreTable.containsKey(IDtogivepointsto)){ - addScoreObject(IDtogivepointsto); - addColor(IDtogivepointsto, color); - addName(IDtogivepointsto); - addScore(IDtogivepointsto); - } - } - - -} +} \ No newline at end of file diff --git a/core/src/com/tdt4240/paint2win/model/Shooter.java b/core/src/com/tdt4240/paint2win/model/Shooter.java index 3944c63771eccffeb850f86a8b087e1d7d807d4b..6fcb1077a800273e9ad4e6806e7f48ba43c3e0c0 100644 --- a/core/src/com/tdt4240/paint2win/model/Shooter.java +++ b/core/src/com/tdt4240/paint2win/model/Shooter.java @@ -52,9 +52,6 @@ public class Shooter implements IVisible, IIdentifiable { this.player = player; position = new Vector2(0, 0); lastShot = Instant.EPOCH; - - - } /** diff --git a/core/src/com/tdt4240/paint2win/model/Target.java b/core/src/com/tdt4240/paint2win/model/Target.java new file mode 100644 index 0000000000000000000000000000000000000000..66da14a6a3cd478223dcc00e895361c27c96405f --- /dev/null +++ b/core/src/com/tdt4240/paint2win/model/Target.java @@ -0,0 +1,84 @@ +package com.tdt4240.paint2win.model; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Intersector; +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Vector2; +import com.tdt4240.paint2win.Paint2Win; +import com.tdt4240.paint2win.container.ObstacleContainer; + +import java.util.Optional; +import java.util.Random; + +public class Target implements IVisible { + + private static final Random random = new Random(); + public static final int TARGETWIDTH = 155; + public static final int TARGETHEIGHT = 155; + public static final Vector2 MIDDLE = new Vector2(TARGETWIDTH/2, TARGETHEIGHT/2); + private static final Texture texture = new Texture("target.png"); + private Sprite sprite; + private Vector2 position; + private ObstacleContainer obstacleContainer; + private Scoreboard scoreboard; + + + public Target(ObstacleContainer obstacleContainer, Scoreboard scoreboard){ + this.sprite = new Sprite(texture, TARGETWIDTH, TARGETHEIGHT); + this.sprite.setOrigin(MIDDLE.x, MIDDLE.y); + this.obstacleContainer = obstacleContainer; + this.position = randomRespawnPoint(this.obstacleContainer); + this.sprite.setPosition(this.position.x,this.position.y); + this.scoreboard = scoreboard; + } + + @Override + public Sprite getSprite() { + return this.sprite; + } + + @Override + public Vector2 getPos() { + return this.position; + } + + @Override + public Vector2 getOriginalMeasures() { + return new Vector2(TARGETWIDTH, TARGETHEIGHT); + } + + public void setPos(Vector2 position){ + this.position=position; + this.sprite.setPosition(position.x,position.y); + } + + /** + * The target gets hit and is placed random + */ + public void noticeHit() { + this.setPos(randomRespawnPoint(obstacleContainer)); + this.scoreboard.increaseScore(); + Paint2Win.AUDIO_MANAGER.playSound("hit_by_paintball.mp3"); + } + + private Vector2 randomRespawnPoint(ObstacleContainer obstacleContainer) { + Rectangle tempRectangel = this.sprite.getBoundingRectangle(); + while(true) { + Vector2 randomPos = new Vector2(random.nextInt((int)Math.floor(Paint2Win.MAP_WIDTH-TARGETWIDTH)), + random.nextInt((int) Math.floor(Paint2Win.MAP_HEIGHT-TARGETHEIGHT))); + tempRectangel.setPosition(randomPos); + Optional<Obstacle> collidingObstacle = obstacleContainer.stream() + .filter(obstacle -> Intersector.overlaps(tempRectangel,obstacle.getSprite().getBoundingRectangle())) + .findAny(); + if (!collidingObstacle.isPresent()) { + return randomPos; + } + } + } + + public void draw(SpriteBatch sb) { + sb.draw(this.sprite.getTexture(),position.x,position.y); + } +} diff --git a/core/src/com/tdt4240/paint2win/model/TimerWatch.java b/core/src/com/tdt4240/paint2win/model/TimerWatch.java new file mode 100644 index 0000000000000000000000000000000000000000..ba7782d3a9f67bda7a77682f5365263f2cf482c5 --- /dev/null +++ b/core/src/com/tdt4240/paint2win/model/TimerWatch.java @@ -0,0 +1,57 @@ +package com.tdt4240.paint2win.model; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.math.Vector2; + +public class TimerWatch { + + private long startTime; + private long stopTime; + private boolean running; + private Color color; + + public static final String fancyString(long elapsedTime) { + int millisec = (int) elapsedTime %1000; + int seconds = (int) (elapsedTime / 1000) % 60 ; + int minutes = (int) ((elapsedTime / (1000*60)) % 60); + return minutes+":"+seconds+":"+millisec; + } + + public TimerWatch (Color color){ + this.startTime = 0; + this.stopTime = 0; + this.running = false; + this.color = color; + } + + public void start() { + this.startTime = System.currentTimeMillis(); + this.running = true; + } + + + public void stop() { + this.stopTime = System.currentTimeMillis(); + this.running = false; + } + + //elaspsed time in milliseconds + public long getElapsedTime() { + long elapsed; + if (running) { + elapsed = (System.currentTimeMillis() - startTime); + } else { + elapsed = (stopTime - startTime); + } + return elapsed; + } + + public void render(Vector2 position, Batch sb, BitmapFont textRenderer) { + sb.begin(); + textRenderer.setColor(color); + textRenderer.draw(sb, "Time: " +fancyString(this.getElapsedTime()), position.x, position.y); + sb.end(); + } +} \ No newline at end of file diff --git a/core/src/com/tdt4240/paint2win/model/maps/AbstractMap.java b/core/src/com/tdt4240/paint2win/model/maps/AbstractMap.java index 106480226766cc215922dbde90dcf86edde1fa1b..91fc7606cecb022205f40b08c034545da9b4d800 100644 --- a/core/src/com/tdt4240/paint2win/model/maps/AbstractMap.java +++ b/core/src/com/tdt4240/paint2win/model/maps/AbstractMap.java @@ -1,6 +1,7 @@ package com.tdt4240.paint2win.model.maps; import com.badlogic.gdx.graphics.Texture; +import com.tdt4240.paint2win.container.ObstacleContainer; import com.tdt4240.paint2win.model.IIdentifiable; import java.util.UUID; @@ -9,6 +10,7 @@ public abstract class AbstractMap implements IIdentifiable { private Texture backGround; private UUID uuid; + protected ObstacleContainer obstacleContainer; public enum valid_maps {DESERT, URBAN } @@ -19,6 +21,7 @@ public abstract class AbstractMap implements IIdentifiable { public AbstractMap(Texture backGround) { this.backGround = backGround; this.uuid = UUID.randomUUID(); + this.obstacleContainer = new ObstacleContainer(); } /** @@ -40,4 +43,8 @@ public abstract class AbstractMap implements IIdentifiable { public UUID getId() { return uuid; } + + public ObstacleContainer getObstacleContainer(){ + return this.obstacleContainer; + } } diff --git a/core/src/com/tdt4240/paint2win/model/maps/desert_map.java b/core/src/com/tdt4240/paint2win/model/maps/desert_map.java index 06577829c71d9cb2f621d99432c61e0378de6758..4f86665debfd39cd7aa83f8c3db5d65e4cf81a63 100644 --- a/core/src/com/tdt4240/paint2win/model/maps/desert_map.java +++ b/core/src/com/tdt4240/paint2win/model/maps/desert_map.java @@ -9,9 +9,8 @@ public class desert_map extends AbstractMap { /** * Creates a map designed to look like a desert environment - * @param obstacleContainer */ - public desert_map(ObstacleContainer obstacleContainer) { + public desert_map() { super(new Texture("sand_bg.png")); Texture texture_container = new Texture("dark_container.png"); Texture texture_medic_car = new Texture("medic_car.png"); diff --git a/core/src/com/tdt4240/paint2win/model/maps/urban_map.java b/core/src/com/tdt4240/paint2win/model/maps/urban_map.java index ab090f11eaa664e8f07f8fd735028c09ec659d71..ebbe62ea4aa381099bde5b72c234e9bedc8c5340 100644 --- a/core/src/com/tdt4240/paint2win/model/maps/urban_map.java +++ b/core/src/com/tdt4240/paint2win/model/maps/urban_map.java @@ -11,7 +11,7 @@ public class urban_map extends AbstractMap { * Creates a map designed to look like an urban environment * @param obstacleContainer */ - public urban_map(ObstacleContainer obstacleContainer) { + public urban_map() { super(new Texture("background.png")); Texture texture = new Texture("Crate.png"); Texture texture_2 = new Texture("Iron_crate.png"); diff --git a/core/src/com/tdt4240/paint2win/view/ContainerRenderer.java b/core/src/com/tdt4240/paint2win/view/ContainerRenderer.java index e17d6964a24f466f939e33d43ffa16285a93b0ce..8b516478a84dd8a4583f43f56b7bdb559acfc826 100644 --- a/core/src/com/tdt4240/paint2win/view/ContainerRenderer.java +++ b/core/src/com/tdt4240/paint2win/view/ContainerRenderer.java @@ -1,7 +1,6 @@ package com.tdt4240.paint2win.view; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.tdt4240.paint2win.container.IContainer; import java.util.Map;