Skip to content
Snippets Groups Projects
Commit 81aeeca8 authored by Luboš Horáček's avatar Luboš Horáček
Browse files

#31 Pixel perfect hit decision

parent bbf393ae
Branches
Tags
No related merge requests found
......@@ -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);
}
};
......
......@@ -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;
......
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;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment