Deck managemement, snapping cards into partial decks and partial decks into cards, or partial decks into other partial decks. Snapping is great!
This commit is contained in:
@@ -7,6 +7,7 @@ import com.badlogic.gdx.InputProcessor;
|
|||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@@ -18,8 +19,9 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
private ArrayList<Integer> cardsTouched;
|
private ArrayList<Integer> cardsTouched;
|
||||||
private VirtuaCards game;
|
private VirtuaCards game;
|
||||||
private Deck fullDeck;
|
private Deck fullDeck;
|
||||||
|
private int dragTriggered;
|
||||||
|
|
||||||
|
private Rectangle lastTouch;
|
||||||
|
|
||||||
public VirtuaCardsGameScreen (VirtuaCards g) {
|
public VirtuaCardsGameScreen (VirtuaCards g) {
|
||||||
game = g;
|
game = g;
|
||||||
@@ -27,6 +29,8 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
cardsTouched = new ArrayList<Integer>();
|
cardsTouched = new ArrayList<Integer>();
|
||||||
dragCounter = 0;
|
dragCounter = 0;
|
||||||
cardCounter = 0;
|
cardCounter = 0;
|
||||||
|
dragTriggered = 0;
|
||||||
|
lastTouch = new Rectangle(0f, 0f, 0f, 0f);
|
||||||
|
|
||||||
Gdx.input.setCatchBackKey(true);
|
Gdx.input.setCatchBackKey(true);
|
||||||
//Gdx.app.setLogLevel(Application.LOG_ERROR);
|
//Gdx.app.setLogLevel(Application.LOG_ERROR);
|
||||||
@@ -61,24 +65,23 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
||||||
Card c;
|
Card c;
|
||||||
//deck
|
boolean ignore = false;
|
||||||
|
dragTriggered++;
|
||||||
//Gdx.app.error("VirtuaCardsGameScreen", "TouchDragged");
|
Gdx.app.error("VirtuaCardsGameScreen", "TouchDragged");
|
||||||
|
if (dragTriggered < 5){
|
||||||
if (dragCounter == 0) {
|
ignore = true;
|
||||||
|
}else if (dragCounter == 0) {
|
||||||
if (fullDeck.isTouchingCard(screenX, Gdx.graphics.getHeight() - screenY)) {
|
if (fullDeck.isTouchingCard(screenX, Gdx.graphics.getHeight() - screenY)) {
|
||||||
c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
if (cardCounter == 2) { // Move deck of cards
|
if (cardCounter == 2) { // Move deck of cards
|
||||||
if (cardsTouched.get(0).equals(cardsTouched.get(1)) && c.isDecked()) {
|
if (cardsTouched.get(0).equals(cardsTouched.get(1)) && c.isDecked()) {
|
||||||
fullDeck.moveDeckTouched(screenX, Gdx.graphics.getHeight() - screenY);
|
fullDeck.moveDeckTouched(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
||||||
c.setDecked(false);
|
c.setDecked(false);
|
||||||
c.setDeckId(0);
|
c.setDeckId(0);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
||||||
c.setDecked(false);
|
c.setDecked(false);
|
||||||
c.setDeckId(0);
|
c.setDeckId(0);
|
||||||
@@ -114,7 +117,7 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
cardsTouched.clear();
|
cardsTouched.clear();
|
||||||
cardCounter = 0;
|
cardCounter = 0;
|
||||||
}
|
}
|
||||||
return true;
|
return ignore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -141,12 +144,13 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
Card c;
|
Card c;
|
||||||
dragCounter = 0;
|
dragCounter = 0;
|
||||||
dragBuffer.clear();
|
dragBuffer.clear();
|
||||||
//Gdx.app.error("VirtuaCardsGameScreen", "TouchDown");
|
Gdx.app.error("VirtuaCardsGameScreen", "TouchDown");
|
||||||
|
|
||||||
c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
if (c != null){
|
if (c != null){
|
||||||
cardsTouched.add(cardCounter,c.getId());
|
cardsTouched.add(cardCounter,c.getId());
|
||||||
cardCounter++;
|
cardCounter++;
|
||||||
|
lastTouch = c.getCardRectangle();
|
||||||
}else{
|
}else{
|
||||||
cardsTouched.clear();
|
cardsTouched.clear();
|
||||||
cardCounter = 0;
|
cardCounter = 0;
|
||||||
@@ -158,7 +162,7 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
Card c;
|
Card c;
|
||||||
//Gdx.app.error("VirtuaCardsGameScreen", "TouchUp");
|
Gdx.app.error("VirtuaCardsGameScreen", "TouchUp");
|
||||||
if (dragCounter > 0) {
|
if (dragCounter > 0) {
|
||||||
c = fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
c = fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
@@ -197,6 +201,8 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
dragBuffer.clear();
|
dragBuffer.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (dragTriggered > 0)
|
||||||
|
dragTriggered = 0;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -242,4 +248,5 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user