diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/Properties.java b/core/src/cz/nic/tablexia/game/games/shooting_range/Properties.java index 3c89e985d85b9a7899e30a2c193bd58608469ba3..97dcb85b1a38365faff32bf8807d5a13e6918eec 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/Properties.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/Properties.java @@ -6,18 +6,19 @@ package cz.nic.tablexia.game.games.shooting_range; public class Properties { public static final String BASE_DIR = "strelnice/"; - public static final int FLOWERS_WAVE1_ZINDEX = 35; - public static final int FLOWERS_WAVE2_ZINDEX = 25; - public static final int FLOWERS_WAVE3_ZINDEX = 15; + // GAME SPEED AND TIME + public static final float ADD_TIME = 5f; + public static final float SUB_TIME = -5f; - public static final float WATCH_CENTER_X_OFFSET = 7; - public static final float WATCH_CENTER_Y_OFFSET = -65; - - public static final int GAME_TIME = 60; - public static final int WARNING_TIME = 5; - public static final float WAVE_VERTICAL_OFFSET = 0.2f; // procento výšky obrazovky + public static final float GAME_SPEED_FAST = 2.0f; + public static final float GAME_SPEED_NORMAL = 1f; + public static final float GAME_SPEED_SLOW = 0.5f; + public static final float GAME_SPEED_TIMEOUT = 5f; + public static final int GAME_TIME = 60; + public static final int WARNING_TIME = 5; + // RESULTS public static final int[] CUPS_EASY = {25, 45, 75}; public static final int[] CUPS_MEDIUM = {20, 40, 70}; public static final int[] CUPS_HARD = {20, 35, 60}; diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/ShootingRangeGame.java b/core/src/cz/nic/tablexia/game/games/shooting_range/ShootingRangeGame.java index f04db5a0a5f89e87e3115869825f457ab25bc5da..c004765d799b6e0c621c0f2ad178fee7516b92a6 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/ShootingRangeGame.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/ShootingRangeGame.java @@ -11,14 +11,14 @@ import cz.nic.tablexia.TablexiaSettings; import cz.nic.tablexia.game.AbstractTablexiaGame; import cz.nic.tablexia.game.common.media.GfxLibrary; import cz.nic.tablexia.game.common.media.SfxLibrary; -import cz.nic.tablexia.game.difficulty.GameDifficulty; import cz.nic.tablexia.game.games.shooting_range.actors.Carousel; import cz.nic.tablexia.game.games.shooting_range.actors.Row; import cz.nic.tablexia.game.games.shooting_range.actors.Scene; import cz.nic.tablexia.game.games.shooting_range.actors.Target; import cz.nic.tablexia.game.games.shooting_range.actors.Watch; +import cz.nic.tablexia.game.games.shooting_range.media.BoxType; import cz.nic.tablexia.game.games.shooting_range.media.SoundType; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; import cz.nic.tablexia.game.games.shooting_range.model.GameState; import cz.nic.tablexia.game.games.shooting_range.model.Wave; import cz.nic.tablexia.game.games.shooting_range.tools.HitEvaluator; @@ -31,7 +31,7 @@ import cz.nic.tablexia.game.games.shooting_range.tools.TargetPositionController; */ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> { - private GfxLibrary gfxLibrary = new GfxLibrary(this, Textures.values()); + private GfxLibrary gfxLibrary = new GfxLibrary(this, TextureType.values()); private SfxLibrary sfxLibrary = new SfxLibrary(this, SoundType.values()); private Scene scene; @@ -41,30 +41,57 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> { private TargetPositionController targetPositionController; private HitEvaluator hitEvaluator; + /** + * Most important listener deciding every hit on target + */ private InputListener clickListener = new InputListener() { + /** + * Decide on touchDown for fast response + */ @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { Target target = (Target) event.getTarget(); - if (!target.isShot()) { + if (!target.isShot()) { // skip if target already hit and let miss listener to catch if (target.getTextureType().equals(getData().getCurrentTarget())) { sfxLibrary.getSound(SoundType.HIT_1).play(); target.setShot(true); target.addAction(Actions.scaleTo(1, 0, 0.1f)); - getData().addScore(2); - } else if (target.getTextureType().equals(Textures.BOX_BAD)) { + getData().addHit(); + } else if (target.getTextureType().equals(TextureType.BOX_BAD)) { target.setShot(true); - sfxLibrary.getSound(SoundType.BOX_FAST).play(); + getData().addBoxBad(); + target.addAction(Actions.scaleTo(1, 0, 0.1f)); + + // TODO box BAD random (FAST, SMOKE) - } else if (target.getTextureType().equals(Textures.BOX_GOOD)) { + } else if (target.getTextureType().equals(TextureType.BOX_GOOD)) { target.setShot(true); - sfxLibrary.getSound(SoundType.BOX_SLOW).play(); - // TODO box GOOD random (SLOW, GOOD_HIT) + getData().addBoxGood(); + target.addAction(Actions.scaleTo(1, 0, 0.1f)); + switch (BoxType.GOOD_BOXES[getRandom().nextInt(BoxType.GOOD_BOXES.length)]) { + case SLOW_DOWN: + // setGameSpeed(TargetPositionUpdateHandler.GAME_SPEED_SLOW);TODO + //showEffect(target, TextureType.BOX_SPEED_DOWN); TODO + sfxLibrary.getSound(SoundType.BOX_SLOW).play(); + break; + case TIME_SUB: + getData().addTime(Properties.SUB_TIME); + sfxLibrary.getSound(SoundType.BELL).play(); + //showEffect(target, TextureType.BOX_TIME_PLUS_5); TODO + break; + case HIT: + // showEffect(target, TextureType.BOX_HIT); TODO + sfxLibrary.getSound(SoundType.HITS[getRandom().nextInt(SoundType.HITS.length)]).play(); + break; + default: + throw new IllegalStateException("Unknown state"); + } } else { sfxLibrary.getSound(SoundType.WRONG).play(); - getData().addScore(-1); + getData().addWrongTarget(); } } - return true; + return super.touchDown(event, x, y, pointer, button); } }; @@ -72,7 +99,7 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { sfxLibrary.getSound(SoundType.MISS).play(); - // TODO MISS + getData().addMiss(); return super.touchDown(event, x, y, pointer, button); } }; @@ -95,13 +122,15 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> { super.gameLoaded(gameState); initScene(); - hitEvaluator = new PixelPerfectHitEvaluator(gfxLibrary, Textures.getTargetPack(getGameDifficulty())); // need to be done here - getGameDifficulty returns null anywhere before - // TODO add boxes + // Create new hit evaluator + hitEvaluator = new PixelPerfectHitEvaluator(gfxLibrary, TextureType.getTargetPack(getGameDifficulty())); // need to be done here - getGameDifficulty returns null anywhere before + // TODO add boxes - hit evaluator is initialized with flowers, but not boxes and could case glitch when evaluating box hit addDisposable(hitEvaluator); + targetGenerator = new TargetGenerator(getGameDifficulty(), getRandom(), gfxLibrary, clickListener, hitEvaluator); targetPositionController = new TargetPositionController(scene, targetGenerator, getRandom(), getStage().getWidth()); - for (Row row : scene.getRows()) { + for (Row row : scene.getRows()) { // init each row with starting flowers row.setWave(Wave.getWave(getGameDifficulty(), row.getRowIndex())); row.addTargets(targetGenerator.generateTargetRow(row)); } @@ -118,31 +147,40 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> { }))); } + /** + * Based on game difficulty create randome hit limit for current target + * Current it 1-4 hit for all difficulties + * + * @return hitLimit + */ private int getNewHitLimit() { - if (getGameDifficulty() == GameDifficulty.EASY) { - // currentHitLimit = 3; - return getRandom().nextInt(4) + 1; - } else if (getGameDifficulty() == GameDifficulty.MEDIUM) { - // currentHitLimit = 2; - return getRandom().nextInt(4) + 1; - } else if (getGameDifficulty() == GameDifficulty.HARD) { - return getRandom().nextInt(4) + 1; - } else { - throw new IllegalStateException("Undefined"); - } + return getRandom().nextInt(4) + 1; } + /** + * Generate new target and hit limit a show it in carousel + */ private void newTarget() { + getData().setCurrentHitLimit(getNewHitLimit()); getData().setCurrentTarget(getRandomFlower()); carousel.showNextFlower(getData().getCurrentTarget()); - getData().setCurrentHitLimit(getNewHitLimit()); } - private Textures getRandomFlower() { - Textures flowerType = targetGenerator.getRandomFlowerType(getGameDifficulty()); + /** + * Get random flower from target bag. Currently ignoring if target type is on the screen + * + * @return + */ + private TextureType getRandomFlower() { + TextureType flowerType = targetGenerator.getRandomFlowerType(getGameDifficulty()); return flowerType; } + /** + * Called in each tick of rendering engine. Updates position of targets and passed game time + * + * @param delta + */ @Override protected void screenRender(float delta) { super.screenRender(delta); @@ -155,6 +193,9 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> { watch.setTime((int) getData().getTime()); } + /** + * Create scene with watch, carousel and background + */ private void initScene() { getStage().addActor(scene = new Scene(gfxLibrary)); scene.setBounds(0, getStage().getCamera().position.y - getStage().getHeight() / 2, getStage().getWidth(), getStage().getHeight()); // scaling viewport camera y-position adjustment @@ -165,6 +206,12 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> { screenResized((int) getStage().getWidth(), (int) getStage().getHeight()); } + /** + * Recompute carousel and watch position on screen resize + * + * @param width + * @param height + */ @Override protected void screenResized(int width, int height) { super.screenResized(width, height); diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Carousel.java b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Carousel.java index 0af3f3758c91a9d2c2b32858ada3b3d669c6f1e3..77f47c93b34d163af21a024e26835bcde78c520f 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Carousel.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Carousel.java @@ -7,7 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.ui.Image; import cz.nic.tablexia.game.common.media.GfxLibrary; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; /** * Created by lhoracek on 6/23/15. @@ -18,7 +18,7 @@ public class Carousel extends Group { private GfxLibrary gfxLibrary; public Carousel(GfxLibrary gfxLibrary) { - addActor(carouselBase = new Image(gfxLibrary.getTextureRegion(Textures.CAROUSEL))); + addActor(carouselBase = new Image(gfxLibrary.getTextureRegion(TextureType.CAROUSEL))); setSize(carouselBase.getWidth(), carouselBase.getHeight()); setTouchable(Touchable.disabled); setSize(carouselBase.getWidth(), carouselBase.getHeight()); @@ -26,7 +26,7 @@ public class Carousel extends Group { this.gfxLibrary = gfxLibrary; } - public void showNextFlower(final Textures textureType) { // TODO change type to Flower + public void showNextFlower(final TextureType textureType) { // TODO change type to Flower final Image oldFlower = this.flower; this.flower = new Image(gfxLibrary.getTextureRegion(textureType)); addActor(flower); diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Flower.java b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Flower.java index 9e7c395f1861f30f705b35d137ebf623a6b44b5b..2db8b56cb5f0de0fd30282f599c26e8022d00c54 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Flower.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Flower.java @@ -3,14 +3,14 @@ package cz.nic.tablexia.game.games.shooting_range.actors; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; import cz.nic.tablexia.game.games.shooting_range.tools.HitEvaluator; /** * Created by lhoracek on 6/26/15. */ public class Flower extends Target { - public Flower(TextureRegion texture, Float startTime, Row row, Textures textureType, ClickListener listener, HitEvaluator hitEvaluator) { + public Flower(TextureRegion texture, Float startTime, Row row, TextureType textureType, ClickListener listener, HitEvaluator hitEvaluator) { super(texture, startTime, row, textureType, listener, hitEvaluator); } } diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Row.java b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Row.java index f612275fde8adf66d549bd69268ff238c388cca9..3030507e2318c181f7c0ddc1b15bf42b3888ff21 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Row.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Row.java @@ -9,7 +9,7 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import cz.nic.tablexia.game.common.media.GfxLibrary; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; import cz.nic.tablexia.game.games.shooting_range.model.Wave; /** @@ -22,7 +22,7 @@ public class Row extends Group { private Wave wave; private int rowIndex; - public Row(GfxLibrary gfxLibrary, int index, Textures texture) { + public Row(GfxLibrary gfxLibrary, int index, TextureType texture) { addActor(targetGroup = new Group()); addActor(waveImage = new Image(gfxLibrary.getTextureRegion(texture))); rowIndex = index; diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Scene.java b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Scene.java index b41f50c4064ba71da79b737dc52e33918671d330..051ee862ffed7c35ce6f4fe45503d57a48b6c040 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Scene.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Scene.java @@ -5,7 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.Touchable; import com.badlogic.gdx.scenes.scene2d.ui.Image; import cz.nic.tablexia.game.common.media.GfxLibrary; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; /** * Created by lhoracek on 6/23/15. @@ -18,14 +18,14 @@ public class Scene extends Group { public Scene(GfxLibrary gfxLibrary) { - addActor(background = new Image(gfxLibrary.getTextureRegion(Textures.BACKGROUND))); + addActor(background = new Image(gfxLibrary.getTextureRegion(TextureType.BACKGROUND))); - addActor(row1 = new Row(gfxLibrary, 0, Textures.WAVE_1)); - addActor(row2 = new Row(gfxLibrary, 1, Textures.WAVE_2)); - addActor(row3 = new Row(gfxLibrary, 2, Textures.WAVE_3)); + addActor(row1 = new Row(gfxLibrary, 0, TextureType.WAVE_1)); + addActor(row2 = new Row(gfxLibrary, 1, TextureType.WAVE_2)); + addActor(row3 = new Row(gfxLibrary, 2, TextureType.WAVE_3)); rows = new Row[]{row1, row2, row3}; - addActor(frame = new Image(gfxLibrary.getTextureRegion(Textures.FRAME))); + addActor(frame = new Image(gfxLibrary.getTextureRegion(TextureType.FRAME))); frame.setTouchable(Touchable.disabled); } diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Target.java b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Target.java index c8dec72a47db30e46c8d5af61f47ae186e592479..43f538aa4ccbfc979f7e43239d66ccc83d51a773 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Target.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Target.java @@ -6,15 +6,15 @@ import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.ui.Image; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; import cz.nic.tablexia.game.games.shooting_range.tools.HitEvaluator; /** * Created by lhoracek on 6/22/15. */ public class Target extends Image { - private final float startTime; - private Textures textureType; + private final float startTime; + private TextureType textureType; private boolean shot = false; private Sprite effect; private Row row; @@ -32,7 +32,7 @@ public class Target extends Image { }; } - public Target(TextureRegion texture, Float startTime, Row row, Textures textureType, InputListener listener, HitEvaluator hitEvaluator) { + public Target(TextureRegion texture, Float startTime, Row row, TextureType textureType, InputListener listener, HitEvaluator hitEvaluator) { super(texture); this.startTime = startTime; this.textureType = textureType; @@ -45,11 +45,11 @@ public class Target extends Image { return startTime; } - public void setTextureType(Textures textureType) { + public void setTextureType(TextureType textureType) { this.textureType = textureType; } - public Textures getTextureType() { + public TextureType getTextureType() { return textureType; } diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Watch.java b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Watch.java index 8e99499c626d2087296be2aa88eeaace02bec997..ad08cb4c5b4a53a6fb90ddf76a8787074594a216 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Watch.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/actors/Watch.java @@ -7,7 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.ui.Image; import cz.nic.tablexia.game.common.media.GfxLibrary; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; /** * Created by lhoracek on 6/23/15. @@ -16,8 +16,8 @@ public class Watch extends Group { private Image watch, watchHand; public Watch(GfxLibrary gfxLibrary) { - addActor(watch = new Image(gfxLibrary.getTextureRegion(Textures.WATCH))); - addActor(watchHand = new Image(gfxLibrary.getTextureRegion(Textures.WATCH_HAND))); + addActor(watch = new Image(gfxLibrary.getTextureRegion(TextureType.WATCH))); + addActor(watchHand = new Image(gfxLibrary.getTextureRegion(TextureType.WATCH_HAND))); watchHand.setPosition(254, 166); watchHand.setOrigin(watchHand.getWidth() / 2, 15); setTouchable(Touchable.disabled); diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/media/BoxType.java b/core/src/cz/nic/tablexia/game/games/shooting_range/media/BoxType.java new file mode 100644 index 0000000000000000000000000000000000000000..1e46ad40224465957a6c794499fb0d1c5a47562a --- /dev/null +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/media/BoxType.java @@ -0,0 +1,28 @@ +package cz.nic.tablexia.game.games.shooting_range.media; + +/** + * @author lhoracek + */ +public enum BoxType { + + TIME_ADD(TextureType.BOX_BAD), // + TIME_SUB(TextureType.BOX_GOOD), // + SLOW_DOWN(TextureType.BOX_GOOD), // + SPEED_UP(TextureType.BOX_BAD), // + HIT(TextureType.BOX_GOOD), // + CLOUD(TextureType.BOX_BAD); + + public static final BoxType[] GOOD_BOXES = new BoxType[]{HIT, TIME_SUB, SLOW_DOWN}; + public static final BoxType[] BAD_BOXES = new BoxType[]{TIME_ADD, SPEED_UP, CLOUD}; + + private final TextureType textureType; + + private BoxType(TextureType textureType) { + this.textureType = textureType; + } + + public TextureType getTextures() { + return textureType; + } + +} diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/media/Textures.java b/core/src/cz/nic/tablexia/game/games/shooting_range/media/TextureType.java similarity index 61% rename from core/src/cz/nic/tablexia/game/games/shooting_range/media/Textures.java rename to core/src/cz/nic/tablexia/game/games/shooting_range/media/TextureType.java index 9357b8d71b38ef0f7a6b44ca314f8e7acba62abd..14afe1f55a6e2124a5219a8b55a16ca5df775e34 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/media/Textures.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/media/TextureType.java @@ -9,7 +9,7 @@ import cz.nic.tablexia.game.difficulty.GameDifficulty; /** * Created by lhoracek on 6/22/15. */ -public enum Textures implements AssetDescription { +public enum TextureType implements AssetDescription { WATCH("watch"), // WATCH_HAND("watch_hand"), // @@ -66,15 +66,15 @@ public enum Textures implements AssetDescription { ; // - public static final Textures[] BOXES = {BOX_BAD, BOX_GOOD}; - public static final Textures[] EFFECTS = {BOX_SMOKE_1, BOX_SMOKE_2, BOX_SMOKE_3, BOX_SMOKE_4, BOX_SMOKE_5, BOX_TIME_MINUS_5, BOX_TIME_MINUS_7, BOX_TIME_PLUS_5, BOX_TIME_PLUS_7, BOX_SPEED_UP, BOX_SPEED_DOWN}; - public static final Textures[] FLOWERS_LEVEL_EASY = {FLOWER_1, FLOWER_6, FLOWER_9, FLOWER_13, FLOWER_17, FLOWER_21}; - public static final Textures[] FLOWERS_LEVEL_MEDIUM = {FLOWER_2, FLOWER_4, FLOWER_5, FLOWER_7, FLOWER_11, FLOWER_12, FLOWER_14, FLOWER_15, FLOWER_17, FLOWER_19, FLOWER_21, FLOWER_22}; - public static final Textures[] FLOWERS_LEVEL_HARD = {FLOWER_1, FLOWER_2, FLOWER_3, FLOWER_4, FLOWER_5, FLOWER_6, FLOWER_7, FLOWER_8, FLOWER_9, FLOWER_10, FLOWER_11, FLOWER_12, FLOWER_13, FLOWER_14, FLOWER_15, FLOWER_16, FLOWER_17, FLOWER_18, FLOWER_19, FLOWER_20, FLOWER_21, FLOWER_22, FLOWER_23, FLOWER_24}; + public static final TextureType[] BOXES = {BOX_BAD, BOX_GOOD}; + public static final TextureType[] EFFECTS = {BOX_SMOKE_1, BOX_SMOKE_2, BOX_SMOKE_3, BOX_SMOKE_4, BOX_SMOKE_5, BOX_TIME_MINUS_5, BOX_TIME_MINUS_7, BOX_TIME_PLUS_5, BOX_TIME_PLUS_7, BOX_SPEED_UP, BOX_SPEED_DOWN}; + public static final TextureType[] FLOWERS_LEVEL_EASY = {FLOWER_1, FLOWER_6, FLOWER_9, FLOWER_13, FLOWER_17, FLOWER_21}; + public static final TextureType[] FLOWERS_LEVEL_MEDIUM = {FLOWER_2, FLOWER_4, FLOWER_5, FLOWER_7, FLOWER_11, FLOWER_12, FLOWER_14, FLOWER_15, FLOWER_17, FLOWER_19, FLOWER_21, FLOWER_22}; + public static final TextureType[] FLOWERS_LEVEL_HARD = {FLOWER_1, FLOWER_2, FLOWER_3, FLOWER_4, FLOWER_5, FLOWER_6, FLOWER_7, FLOWER_8, FLOWER_9, FLOWER_10, FLOWER_11, FLOWER_12, FLOWER_13, FLOWER_14, FLOWER_15, FLOWER_16, FLOWER_17, FLOWER_18, FLOWER_19, FLOWER_20, FLOWER_21, FLOWER_22, FLOWER_23, FLOWER_24}; private final String resource; - private Textures(String resource) { + private TextureType(String resource) { this.resource = resource; } @@ -82,14 +82,14 @@ public enum Textures implements AssetDescription { return resource; } - public static List<Textures> getTargetPack(GameDifficulty gameDifficulty) { + public static List<TextureType> getTargetPack(GameDifficulty gameDifficulty) { switch (gameDifficulty) { case EASY: - return Arrays.asList(Textures.FLOWERS_LEVEL_EASY); + return Arrays.asList(TextureType.FLOWERS_LEVEL_EASY); case MEDIUM: - return Arrays.asList(Textures.FLOWERS_LEVEL_MEDIUM); + return Arrays.asList(TextureType.FLOWERS_LEVEL_MEDIUM); case HARD: - return Arrays.asList(Textures.FLOWERS_LEVEL_HARD); + return Arrays.asList(TextureType.FLOWERS_LEVEL_HARD); default: throw new IllegalStateException("Unknown difficulty"); } diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/model/GameState.java b/core/src/cz/nic/tablexia/game/games/shooting_range/model/GameState.java index 42b8ac316f2b3a594114f42b0a83ab68b41795ac..3ce852c0ce18e8f10fe5cb0d9b8d662a79df42b9 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/model/GameState.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/model/GameState.java @@ -1,6 +1,6 @@ package cz.nic.tablexia.game.games.shooting_range.model; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; /** * Created by lhoracek on 6/22/15. @@ -9,9 +9,14 @@ public class GameState { private boolean running = false; - private int score = 0; - private float time = 0f; - private Textures currentTarget; + private int score = 0; + private int hits = 0; + private int misses = 0; + private int wrongTargets = 0; + private int boxesBadHit = 0; + private int boxesGoodHit = 0; + private float time = 0f; + private TextureType currentTarget; private int currentHitLimit = 0; public int getCurrentHitLimit() { @@ -30,6 +35,51 @@ public class GameState { score += diff; } + public void addMiss() { + misses++; + addScore(-1); + } + + public void addWrongTarget() { + wrongTargets++; + addScore(-1); + } + + public void addBoxGood() { + boxesGoodHit++; + } + + public void addBoxBad() { + boxesBadHit++; + } + + + public int getHits() { + return hits; + } + + public void addHit() { + this.hits++; + addScore(2); + } + + public int getMisses() { + return misses; + + } + + public int getWrongTargets() { + return wrongTargets; + } + + public int getBoxesBadHit() { + return boxesBadHit; + } + + public int getBoxesGoodHit() { + return boxesGoodHit; + } + public float getTime() { return time; } @@ -50,11 +100,11 @@ public class GameState { this.running = running; } - public Textures getCurrentTarget() { + public TextureType getCurrentTarget() { return currentTarget; } - public void setCurrentTarget(Textures currentTarget) { + public void setCurrentTarget(TextureType currentTarget) { this.currentTarget = currentTarget; } } diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/model/HitType.java b/core/src/cz/nic/tablexia/game/games/shooting_range/model/HitType.java deleted file mode 100644 index 6310c44585057048bf3b8fe4dcc31fb8b94aa9e1..0000000000000000000000000000000000000000 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/model/HitType.java +++ /dev/null @@ -1,12 +0,0 @@ -package cz.nic.tablexia.game.games.shooting_range.model; - -/** - * Created by lhoracek on 7/14/15. - */ -public enum HitType { - CORRECT, - WHRONG, - MISS, - BOX_GOOD, - BOX_BAD -} diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/model/Wave.java b/core/src/cz/nic/tablexia/game/games/shooting_range/model/Wave.java index 23e2a157cbcc0e3938fb1680e01834e1bc625117..f7f2656fb195f76094e1340a2d80a5a0c02e7eea 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/model/Wave.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/model/Wave.java @@ -1,7 +1,6 @@ package cz.nic.tablexia.game.games.shooting_range.model; import cz.nic.tablexia.game.difficulty.GameDifficulty; -import cz.nic.tablexia.game.games.shooting_range.Properties; import cz.nic.tablexia.game.games.shooting_range.actors.Target; /** @@ -106,10 +105,6 @@ public enum Wave { return runningTime; } - public int getVerticalOrder() { - return verticalOrder; - } - public float getY(float elapsedTime, float maxHeight) { return positionProvider.getY(elapsedTime, maxHeight); } @@ -118,20 +113,6 @@ public enum Wave { return ((Direction.LEFT == direction ? -1 : 1) * (maxWidth * (elapsedTime / getRunningTime()))) + (Direction.LEFT == direction ? maxWidth : 0); } - public int getzIndex() { - switch (verticalOrder) { - // TODO - case 0: - return Properties.FLOWERS_WAVE1_ZINDEX; - case 1: - return Properties.FLOWERS_WAVE2_ZINDEX; - case 2: - return Properties.FLOWERS_WAVE3_ZINDEX; - default: - throw new IllegalArgumentException("Unknown z-index"); - } - } - public int getFlowersOnScreen() { return flowerOnScreen; } diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/tools/PixelPerfectHitEvaluator.java b/core/src/cz/nic/tablexia/game/games/shooting_range/tools/PixelPerfectHitEvaluator.java index b6b4e8307fe8ad4d08ea8070ec4af7e010f8c90a..fbf029939747233a16038cc36d6dce6c627c3482 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/tools/PixelPerfectHitEvaluator.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/tools/PixelPerfectHitEvaluator.java @@ -12,7 +12,7 @@ import java.util.Map; import cz.nic.tablexia.game.common.media.GfxLibrary; import cz.nic.tablexia.game.games.shooting_range.actors.Target; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; /** * Created by lhoracek on 7/14/15. @@ -27,12 +27,12 @@ public class PixelPerfectHitEvaluator implements HitEvaluator { } } - public PixelPerfectHitEvaluator(GfxLibrary gfxLibrary, List<Textures> targetTypes) { + public PixelPerfectHitEvaluator(GfxLibrary gfxLibrary, List<TextureType> targetTypes) { init(gfxLibrary, targetTypes); } - private void init(GfxLibrary gfxLibrary, List<Textures> targetTypes) { - for (Textures targetType : targetTypes) { + private void init(GfxLibrary gfxLibrary, List<TextureType> targetTypes) { + for (TextureType targetType : targetTypes) { getPixmap(gfxLibrary.getTextureRegion(targetType).getTexture()); } } diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/tools/TargetGenerator.java b/core/src/cz/nic/tablexia/game/games/shooting_range/tools/TargetGenerator.java index 5f42652a9b83c0d56d1cefced4aa5a8dbd2f2cf3..d22930898a63b9196e93f8ece8cdf75ca7843705 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/tools/TargetGenerator.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/tools/TargetGenerator.java @@ -13,7 +13,7 @@ import cz.nic.tablexia.game.common.media.GfxLibrary; import cz.nic.tablexia.game.difficulty.GameDifficulty; import cz.nic.tablexia.game.games.shooting_range.actors.Row; import cz.nic.tablexia.game.games.shooting_range.actors.Target; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; /** * Created by lhoracek on 6/22/15. @@ -44,8 +44,8 @@ public class TargetGenerator { this.hitEvaluator = hitEvaluator; } - public Textures getRandomFlowerType(GameDifficulty gameDifficulty) { - List<Textures> textureTypeBag = getTextureTypeBag(); + public TextureType getRandomFlowerType(GameDifficulty gameDifficulty) { + List<TextureType> textureTypeBag = getTextureTypeBag(); return textureTypeBag.get(random.nextInt(textureTypeBag.size())); } @@ -55,18 +55,18 @@ public class TargetGenerator { return lastTargetsForRow.get(row); } - public Target addNewTargetToRow(Row row, Textures requiredTextureType) { + public Target addNewTargetToRow(Row row, TextureType requiredTextureType) { Target prevLastTarget = getLastTargetInRow(row); float targetPeriod = row.getWave().getRunningTime() / row.getWave().getFlowersOnScreen(); return addNewTargetToRow(row, requiredTextureType, prevLastTarget.getStartTime() + targetPeriod); } - public Target addNewTargetToRow(Row row, Textures requiredTextureType, float startTime) { + public Target addNewTargetToRow(Row row, TextureType requiredTextureType, float startTime) { return addNewTargetToRow(row, requiredTextureType, startTime, true); } - public Target addNewTargetToRow(Row row, Textures requiredTextureType, float startTime, boolean asLast) { - List<Textures> textureTypeBag = new ArrayList<Textures>(requiredTextureType == null ? getTextureTypeBag() : Arrays.asList((new Textures[]{requiredTextureType}))); + public Target addNewTargetToRow(Row row, TextureType requiredTextureType, float startTime, boolean asLast) { + List<TextureType> textureTypeBag = new ArrayList<TextureType>(requiredTextureType == null ? getTextureTypeBag() : Arrays.asList((new TextureType[]{requiredTextureType}))); Target target = getRandomTarget(textureTypeBag, startTime, row); if (asLast) { lastTargetsForRow.put(row, target); @@ -79,7 +79,7 @@ public class TargetGenerator { */ public List<Target> generateTargetRow(Row row) { List<Target> flowers = new ArrayList<Target>(); - List<Textures> textureTypeBag = new ArrayList<Textures>(getTextureTypeBag()); + List<TextureType> textureTypeBag = new ArrayList<TextureType>(getTextureTypeBag()); int flowerNumber = row.getWave().getFlowersOnScreen(); float targetPeriod = row.getWave().getRunningTime() / row.getWave().getFlowersOnScreen(); @@ -95,22 +95,22 @@ public class TargetGenerator { return flowers; } - private Textures getRandomBoxType() { + private TextureType getRandomBoxType() { float boxTypeIndex = random.nextFloat(); if ((gameDifficulty == GameDifficulty.EASY) && (boxTypeIndex > EASY_GOOD_PROBABILITY)) { - return Textures.BOX_BAD; + return TextureType.BOX_BAD; } else if ((gameDifficulty == GameDifficulty.MEDIUM) && (boxTypeIndex > HARD_GOOD_PROBABILITY)) { - return Textures.BOX_BAD; + return TextureType.BOX_BAD; } else if ((gameDifficulty == GameDifficulty.HARD) && (boxTypeIndex > HARD_GOOD_PROBABILITY)) { - return Textures.BOX_BAD; + return TextureType.BOX_BAD; } - return Textures.BOX_GOOD; + return TextureType.BOX_GOOD; } - private Target getRandomTarget(List<Textures> textureTypeBag, float startTime, Row row) { + private Target getRandomTarget(List<TextureType> textureTypeBag, float startTime, Row row) { float boxIndex = random.nextFloat(); - Textures textureType = getRandomBoxType(); + TextureType textureType = getRandomBoxType(); if (boxIndex > getBoxProbability()) { int random = (int) (Math.random() * textureTypeBag.size()); textureType = textureTypeBag.get(random); @@ -131,7 +131,7 @@ public class TargetGenerator { } } - private List<Textures> getTextureTypeBag() { - return Textures.getTargetPack(gameDifficulty); + private List<TextureType> getTextureTypeBag() { + return TextureType.getTargetPack(gameDifficulty); } } \ No newline at end of file diff --git a/core/src/cz/nic/tablexia/game/games/shooting_range/tools/TargetPositionController.java b/core/src/cz/nic/tablexia/game/games/shooting_range/tools/TargetPositionController.java index 91245a4a3c459d7d93c615b680c1e45e4378ed42..698b6a1b4c7f3c5cec3a0a17f0d239ed84f8279e 100644 --- a/core/src/cz/nic/tablexia/game/games/shooting_range/tools/TargetPositionController.java +++ b/core/src/cz/nic/tablexia/game/games/shooting_range/tools/TargetPositionController.java @@ -6,10 +6,11 @@ import java.util.List; import java.util.Random; import java.util.Set; +import cz.nic.tablexia.game.games.shooting_range.Properties; import cz.nic.tablexia.game.games.shooting_range.actors.Row; import cz.nic.tablexia.game.games.shooting_range.actors.Scene; import cz.nic.tablexia.game.games.shooting_range.actors.Target; -import cz.nic.tablexia.game.games.shooting_range.media.Textures; +import cz.nic.tablexia.game.games.shooting_range.media.TextureType; import cz.nic.tablexia.game.games.shooting_range.model.Direction; /** @@ -17,18 +18,13 @@ import cz.nic.tablexia.game.games.shooting_range.model.Direction; */ public class TargetPositionController { - public static final float GAME_SPEED_FAST = 2.0f; - public static final float GAME_SPEED_NORMAL = 1f; - public static final float GAME_SPEED_SLOW = 0.5f; - public static final float GAME_SPEED_TIMEOUT = 5f; - private float elapsedTime = 0; private float gameSpeed = 1; private final TargetGenerator targetGenerator; private final Random random; private final float width; private final Scene scene; - private Textures targetType; + private TextureType targetType; public TargetPositionController(Scene scene, TargetGenerator targetGenerator, Random random, float width) { @@ -44,10 +40,10 @@ public class TargetPositionController { } public void resetGameSpeed() { - gameSpeed = GAME_SPEED_NORMAL; + gameSpeed = Properties.GAME_SPEED_NORMAL; } - public void setTargetType(Textures targetType) { + public void setTargetType(TextureType targetType) { this.targetType = targetType; } @@ -57,7 +53,7 @@ public class TargetPositionController { */ public void onUpdate(float pSecondsElapsed) { elapsedTime += (pSecondsElapsed * gameSpeed); - Set<Textures> availableTypes = new HashSet<Textures>(); + Set<TextureType> availableTypes = new HashSet<TextureType>(); List<Target> invisibles = new ArrayList<Target>(); for (Row row : scene.getRows()) { @@ -68,7 +64,7 @@ public class TargetPositionController { // is last target in row if (targetGenerator.getLastTargetInRow(row).equals(target)) { // last invisible target is on scene - add new one - row.addTarget(targetGenerator.addNewTargetToRow(row, Textures.FLOWER_1)); + row.addTarget(targetGenerator.addNewTargetToRow(row, TextureType.FLOWER_1)); //Log.info(getClass(), "Adding " + target); } target.setX(x);