From 81aeeca89333c2452a7f50bba5ea987adeb77eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Hor=C3=A1=C4=8Dek?= <horaceklubos@gmail.com> Date: Tue, 14 Jul 2015 13:03:35 +0200 Subject: [PATCH] #31 Pixel perfect hit decision --- .../game/games/shooting_range/ShootingRangeGame.java | 10 +++++----- .../game/games/shooting_range/actors/Target.java | 4 ++-- .../games/shooting_range/tools/TargetGenerator.java | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) 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 c5bcec3b5..0e3103a62 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 @@ -5,9 +5,9 @@ import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.ui.Image; -import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import java.util.HashMap; import java.util.List; @@ -45,10 +45,9 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> { private Map<Texture, Pixmap> pixmapCache = new HashMap<Texture, Pixmap>(); - private ClickListener clickListener = new ClickListener() { + private InputListener clickListener = new InputListener() { @Override - public void clicked(InputEvent event, float x, float y) { - super.clicked(event, x, y); + public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (event.getTarget() instanceof Target) { // Pixel perfect hit decision Target target = (Target) event.getTarget(); @@ -68,7 +67,7 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> { } Pixmap pix = pixmapCache.get(texture); - int pixel = pix.getPixel(textureRegion.getRegionX() + (int) x, textureRegion.getRegionY() + (int) y); + int pixel = pix.getPixel(textureRegion.getRegionX() + (int) x, textureRegion.getRegionY() + textureRegion.getRegionHeight() - (int) y); if (new Color(pixel).a != 0) { if (textureType.equals(getData().getCurrentTarget())) { @@ -90,6 +89,7 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> { } } + return super.touchDown(event, x, y, pointer, button); } }; 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 0ac752d21..87d3fab01 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 @@ -2,8 +2,8 @@ package cz.nic.tablexia.game.games.shooting_range.actors; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.ui.Image; -import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import cz.nic.tablexia.game.games.shooting_range.media.Textures; @@ -29,7 +29,7 @@ public class Target extends Image { }; } - public Target(TextureRegion texture, Float startTime, Row row, Textures textureType, ClickListener listener) { + public Target(TextureRegion texture, Float startTime, Row row, Textures textureType, InputListener listener) { super(texture); this.startTime = startTime; this.textureType = textureType; 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 7fd50d7ae..f661dc1e7 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 @@ -1,5 +1,6 @@ package cz.nic.tablexia.game.games.shooting_range.tools; +import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import java.util.ArrayList; @@ -32,9 +33,9 @@ public class TargetGenerator { private final GameDifficulty gameDifficulty; private final Random random; private final GfxLibrary gfxLibrary; - private final ClickListener clickListener; + private final InputListener clickListener; - public TargetGenerator(GameDifficulty gameDifficulty, Random random, GfxLibrary gfxLibrary, ClickListener clickListener) { + public TargetGenerator(GameDifficulty gameDifficulty, Random random, GfxLibrary gfxLibrary, InputListener clickListener) { super(); this.random = random; this.gameDifficulty = gameDifficulty; -- GitLab