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:
@@ -3,7 +3,6 @@ package checamon.games.virtuacards.android;
|
|||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplication;
|
import com.badlogic.gdx.backends.android.AndroidApplication;
|
||||||
@@ -22,7 +21,6 @@ public class AndroidLauncher extends AndroidApplication {
|
|||||||
}
|
}
|
||||||
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
||||||
initialize(new VirtuaCards(),config);
|
initialize(new VirtuaCards(),config);
|
||||||
Log.e("Error", "Error Test");
|
|
||||||
}
|
}
|
||||||
@TargetApi(19)
|
@TargetApi(19)
|
||||||
private void hideVirtualButtons() {
|
private void hideVirtualButtons() {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public class Card {
|
|||||||
private int id;
|
private int id;
|
||||||
private boolean faceUp;
|
private boolean faceUp;
|
||||||
private boolean decked;
|
private boolean decked;
|
||||||
|
private int deckId;
|
||||||
//private boolean onTable;
|
//private boolean onTable;
|
||||||
//private float orientation;
|
//private float orientation;
|
||||||
|
|
||||||
@@ -59,6 +60,8 @@ public class Card {
|
|||||||
this.backSprite.setPosition(position.getX(), position.getY());
|
this.backSprite.setPosition(position.getX(), position.getY());
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.faceUp = false;
|
this.faceUp = false;
|
||||||
|
this.decked = true;
|
||||||
|
this.deckId = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -155,4 +158,12 @@ public class Card {
|
|||||||
public void setDecked(boolean decked) {
|
public void setDecked(boolean decked) {
|
||||||
this.decked = decked;
|
this.decked = decked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDeckId() {
|
||||||
|
return deckId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeckId(int deckId) {
|
||||||
|
this.deckId = deckId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by angelcheca on 17/11/15.
|
* Created by angelcheca on 17/11/15.
|
||||||
*/
|
*/
|
||||||
@@ -18,7 +17,7 @@ public class Deck {
|
|||||||
private ArrayList<Card> cards;
|
private ArrayList<Card> cards;
|
||||||
private HashMap<Integer,Integer> drawOrder;
|
private HashMap<Integer,Integer> drawOrder;
|
||||||
private int numberOfCards;
|
private int numberOfCards;
|
||||||
//private ArrayList<Deck> subdecks;
|
private int deckCounter;
|
||||||
|
|
||||||
public Deck(Texture texture) {
|
public Deck(Texture texture) {
|
||||||
try {
|
try {
|
||||||
@@ -37,6 +36,7 @@ public class Deck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.numberOfCards = 54;
|
this.numberOfCards = 54;
|
||||||
|
this.deckCounter = 1;
|
||||||
|
|
||||||
}catch (Exception e)
|
}catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -165,7 +165,7 @@ public class Deck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO Change this to not move to the top until is sure no other cards need to move
|
//TODO Change this to not move to the top until is sure no other cards need to move
|
||||||
if (i < numberOfCards - 1)
|
if (i >= 0 && i < numberOfCards - 1)
|
||||||
setCardDrawOrderOnTop(i);
|
setCardDrawOrderOnTop(i);
|
||||||
return cardResult;
|
return cardResult;
|
||||||
}
|
}
|
||||||
@@ -185,12 +185,25 @@ public class Deck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO Change this to not move to the top until is sure no other cards need to move
|
//TODO Change this to not move to the top until is sure no other cards need to move
|
||||||
if (i < numberOfCards - 1)
|
if (i >= 0 && i < numberOfCards - 1)
|
||||||
setCardDrawOrderOnTop(i);
|
setCardDrawOrderOnTop(i);
|
||||||
|
|
||||||
return cardResult;
|
return cardResult;
|
||||||
}
|
}
|
||||||
|
public Integer getTouchedCardIndex(float x, float y){
|
||||||
|
|
||||||
|
int i = numberOfCards - 1;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
|
while (i >= 0 && !exit){
|
||||||
|
if (drawOrder.get(i) > -1 && cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
||||||
|
exit = true;
|
||||||
|
}else{
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (Integer)i;
|
||||||
|
}
|
||||||
public Card getTouchedCard(float x, float y, int top){
|
public Card getTouchedCard(float x, float y, int top){
|
||||||
|
|
||||||
Card cardResult = null;
|
Card cardResult = null;
|
||||||
@@ -226,6 +239,25 @@ public class Deck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//TODO Make sure it orders the cards up to the top
|
||||||
|
private void setCardDrawOrderOnTopSubDeck(int index, int last){
|
||||||
|
|
||||||
|
int i = index;
|
||||||
|
int next = 0;
|
||||||
|
int replace = drawOrder.get(index);
|
||||||
|
|
||||||
|
while (i < last){
|
||||||
|
if (i < last - 1) {
|
||||||
|
next = drawOrder.get(i + 1);
|
||||||
|
drawOrder.put(i,next);
|
||||||
|
i++;
|
||||||
|
}else{
|
||||||
|
drawOrder.put(i,replace);
|
||||||
|
i++;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setRandomCardDraw(ArrayList<Integer> subDeck){
|
private void setRandomCardDraw(ArrayList<Integer> subDeck){
|
||||||
ArrayList<Integer> originalOrder = (ArrayList<Integer>) subDeck.clone();
|
ArrayList<Integer> originalOrder = (ArrayList<Integer>) subDeck.clone();
|
||||||
@@ -235,8 +267,7 @@ public class Deck {
|
|||||||
for (int i = 0; i < originalOrder.size(); i++){
|
for (int i = 0; i < originalOrder.size(); i++){
|
||||||
replace = drawOrder.get(originalOrder.get(i));
|
replace = drawOrder.get(originalOrder.get(i));
|
||||||
drawOrder.put(originalOrder.get(i),drawOrder.get(subDeck.get(i)));
|
drawOrder.put(originalOrder.get(i),drawOrder.get(subDeck.get(i)));
|
||||||
if (i < originalOrder.size() - 1)
|
drawOrder.put(subDeck.get(i),replace);
|
||||||
drawOrder.put(subDeck.get(i),replace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -246,18 +277,16 @@ public class Deck {
|
|||||||
|
|
||||||
ArrayList<Integer> subDeck = new ArrayList<Integer>();
|
ArrayList<Integer> subDeck = new ArrayList<Integer>();
|
||||||
Card c;
|
Card c;
|
||||||
int top = numberOfCards-1;
|
|
||||||
int i = numberOfCards-1;
|
int i = numberOfCards-1;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
boolean exit = false;
|
boolean exit = false;
|
||||||
|
|
||||||
while (i >= 0 && !exit){
|
while (i >= 0 && !exit){
|
||||||
c = this.getTouchedCard(x,y,top);
|
c = this.getTouchedCard(x, y, i);
|
||||||
if (c == null)
|
if (c == null)
|
||||||
exit = true;
|
exit = true;
|
||||||
else{
|
else{
|
||||||
subDeck.add(index,c.getId());
|
subDeck.add(index,c.getId());
|
||||||
top = c.getId() - 1;
|
|
||||||
index++;
|
index++;
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
@@ -270,73 +299,141 @@ public class Deck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void moveDeckTouched(float x, float y){
|
public void moveDeckTouched(float x, float y){
|
||||||
Card c = getTouchedCard(x,y);
|
|
||||||
Card card;
|
Card card;
|
||||||
float deltaX;
|
int deckId = -1;
|
||||||
float deltaY;
|
int cardDeck = -1;
|
||||||
|
int lastIndex = -1;
|
||||||
Rectangle r = c.getCardRectangle();
|
|
||||||
c.setCenter(new Point(x,y));
|
|
||||||
Rectangle r2 = c.getCardRectangle();
|
|
||||||
|
|
||||||
deltaX = r2.getX() - r.getX();
|
|
||||||
deltaY = r2.getY() - r.getY();
|
|
||||||
|
|
||||||
//Move all cards in the deck
|
//Move all cards in the deck
|
||||||
int i = c.getId() - 1;
|
int i = getTouchedCardIndex(x,y);
|
||||||
|
lastIndex = i;
|
||||||
|
|
||||||
while (i >= 0){
|
while (i >= 0){
|
||||||
card = cards.get(drawOrder.get(i));
|
card = cards.get(drawOrder.get(i));
|
||||||
if (drawOrder.get(i) > -1 && card.isTouched(x, y)) {
|
cardDeck = card.getDeckId();
|
||||||
card.setPosition(new Point(card.getCardSprite().getX() + deltaX, card.getCardSprite().getY() + deltaY));
|
if (cardDeck == deckId) {
|
||||||
}else{
|
card.setCenter(new Point(x, y));
|
||||||
i--;
|
setCardDrawOrderOnTopSubDeck(i, lastIndex);
|
||||||
|
lastIndex--;
|
||||||
}
|
}
|
||||||
|
else if (deckId == -1){
|
||||||
|
if (drawOrder.get(i) > -1 && card.isTouched(x, y)) {
|
||||||
|
deckId = card.getDeckId();
|
||||||
|
card.setCenter(new Point(x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveDeckTouchedDragged(float x, float y){
|
public void moveDeckTouchedDragged(float x, float y){
|
||||||
Card c = getTouchedCard(x,y);
|
|
||||||
Card card;
|
Card card;
|
||||||
float deltaX;
|
int deckId = -1;
|
||||||
float deltaY;
|
int cardDeck = -1;
|
||||||
|
int lastIndex = -1;
|
||||||
Rectangle r = c.getCardRectangle();
|
|
||||||
c.setCenter(new Point(x,y));
|
|
||||||
Rectangle r2 = c.getCardRectangle();
|
|
||||||
|
|
||||||
deltaX = r2.getX() - r.getX();
|
|
||||||
deltaY = r2.getY() - r.getY();
|
|
||||||
|
|
||||||
//Move all cards in the deck
|
//Move all cards in the deck
|
||||||
int i = c.getId() - 1;
|
int i = getTouchedCardIndex(x,y);
|
||||||
|
lastIndex = i;
|
||||||
|
|
||||||
while (i >= 0){
|
while (i >= 0){
|
||||||
card = cards.get(drawOrder.get(i));
|
card = cards.get(drawOrder.get(i));
|
||||||
if (drawOrder.get(i) > -1 && card.isTouchedDragged(x, y)) {
|
cardDeck = card.getDeckId();
|
||||||
card.setPosition(new Point(card.getCardSprite().getX() + deltaX, card.getCardSprite().getY() + deltaY));
|
if (cardDeck == deckId) {
|
||||||
|
card.setCenter(new Point(x, y));
|
||||||
|
setCardDrawOrderOnTopSubDeck(i, lastIndex);
|
||||||
|
lastIndex--;
|
||||||
|
}
|
||||||
|
else if (deckId == -1){
|
||||||
|
if (drawOrder.get(i) > -1 && card.isTouchedDragged(x, y)) {
|
||||||
|
deckId = card.getDeckId();
|
||||||
|
card.setCenter(new Point(x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeckPosition(int belowDeckId, int aboveDeckId, float x, float y){
|
||||||
|
Card card;
|
||||||
|
int cardDeck = -1;
|
||||||
|
|
||||||
|
//Move all cards in the deck
|
||||||
|
int i = numberOfCards - 1;
|
||||||
|
|
||||||
|
while (i >= 0){
|
||||||
|
card = cards.get(drawOrder.get(i));
|
||||||
|
cardDeck = card.getDeckId();
|
||||||
|
if (cardDeck == aboveDeckId) {
|
||||||
|
card.setPosition(new Point(x, y));
|
||||||
|
card.setDeckId(belowDeckId);
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public Card getTouchedCardDifferentDeck(float x, float y, int deckiId){
|
||||||
|
Card cardResult = null;
|
||||||
|
int i = numberOfCards - 1;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
|
while (i >= 0 && !exit){
|
||||||
|
cardResult = cards.get(drawOrder.get(i));
|
||||||
|
if (drawOrder.get(i) > -1 && cardResult.isTouched(x, y) && cardResult.getDeckId() != deckiId) {
|
||||||
|
exit = true;
|
||||||
}else{
|
}else{
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!exit)
|
||||||
|
cardResult = null;
|
||||||
|
|
||||||
|
return cardResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void autoDeckCard(float x, float y){
|
|
||||||
Card c = getTouchedCard(x,y);
|
|
||||||
Card below = getTouchedCard(x,y, numberOfCards - 2);
|
public void autoDeckCard(float x, float y) {
|
||||||
|
Card c = getTouchedCard(x, y);
|
||||||
|
Card below;
|
||||||
|
if (!c.isDecked()) {
|
||||||
|
below = getTouchedCard(x, y, numberOfCards - 2);
|
||||||
|
} else {
|
||||||
|
below = getTouchedCardDifferentDeck(x, y, c.getDeckId());
|
||||||
|
}
|
||||||
|
|
||||||
// Detect if overlapping enough to deck automatically
|
// Detect if overlapping enough to deck automatically
|
||||||
// by default cards are 150 x 190
|
// by default cards are 150 x 190
|
||||||
if (below != null) {
|
if (below != null && !c.isDecked()) {
|
||||||
if (((c.getCardSprite().getX() <= below.getCardSprite().getX() + 35) && (c.getCardSprite().getX() >= below.getCardSprite().getX() - 35)) &&
|
if (((c.getCardSprite().getX() <= below.getCardSprite().getX() + 35) && (c.getCardSprite().getX() >= below.getCardSprite().getX() - 35)) &&
|
||||||
((c.getCardSprite().getY() <= below.getCardSprite().getY() + 35) && (c.getCardSprite().getY() >= below.getCardSprite().getY() - 35))) {
|
((c.getCardSprite().getY() <= below.getCardSprite().getY() + 35) && (c.getCardSprite().getY() >= below.getCardSprite().getY() - 35))) {
|
||||||
Rectangle r = below.getCardRectangle();
|
Rectangle r = below.getCardRectangle();
|
||||||
c.setPosition(new Point(r.getX(), r.getY()));
|
c.setPosition(new Point(r.getX(), r.getY()));
|
||||||
c.setDecked(true);
|
c.setDecked(true);
|
||||||
}else{
|
if (below.getDeckId() == 0) {
|
||||||
c.setDecked(false);
|
deckCounter++;
|
||||||
|
below.setDecked(true);
|
||||||
|
below.setDeckId(deckCounter);
|
||||||
|
c.setDeckId(deckCounter);
|
||||||
|
} else {
|
||||||
|
c.setDeckId(below.getDeckId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if (below != null && c.isDecked()) {
|
||||||
|
if (((c.getCardSprite().getX() <= below.getCardSprite().getX() + 35) && (c.getCardSprite().getX() >= below.getCardSprite().getX() - 35)) &&
|
||||||
|
((c.getCardSprite().getY() <= below.getCardSprite().getY() + 35) && (c.getCardSprite().getY() >= below.getCardSprite().getY() - 35))) {
|
||||||
|
Rectangle r = below.getCardRectangle();
|
||||||
|
if (below.getDeckId() == 0) {
|
||||||
|
below.setDecked(true);
|
||||||
|
below.setDeckId(c.getDeckId());
|
||||||
|
setDeckPosition(c.getDeckId(), c.getDeckId(), r.getX(), r.getY());
|
||||||
|
} else {
|
||||||
|
setDeckPosition(below.getDeckId(), c.getDeckId(), r.getX(), r.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//TODO resetDeckIds(); complex to compute... not worth it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,4 +444,12 @@ public class Deck {
|
|||||||
public int getNumberOfCards() {
|
public int getNumberOfCards() {
|
||||||
return numberOfCards;
|
return numberOfCards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDeckCounter() {
|
||||||
|
return deckCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeckCounter(int deckCounter) {
|
||||||
|
this.deckCounter = deckCounter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
private int dragCounter;
|
private int dragCounter;
|
||||||
private int cardCounter;
|
private int cardCounter;
|
||||||
private ArrayList<Point> dragBuffer;
|
private ArrayList<Point> dragBuffer;
|
||||||
|
private ArrayList<Integer> cardsTouched;
|
||||||
private VirtuaCards game;
|
private VirtuaCards game;
|
||||||
|
|
||||||
private Deck fullDeck;
|
private Deck fullDeck;
|
||||||
|
|
||||||
|
|
||||||
@@ -24,11 +24,12 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
public VirtuaCardsGameScreen (VirtuaCards g) {
|
public VirtuaCardsGameScreen (VirtuaCards g) {
|
||||||
game = g;
|
game = g;
|
||||||
dragBuffer = new ArrayList<Point>();
|
dragBuffer = new ArrayList<Point>();
|
||||||
|
cardsTouched = new ArrayList<Integer>();
|
||||||
dragCounter = 0;
|
dragCounter = 0;
|
||||||
cardCounter = 0;
|
cardCounter = 0;
|
||||||
|
|
||||||
Gdx.input.setInputProcessor(this);
|
|
||||||
Gdx.input.setCatchBackKey(true);
|
Gdx.input.setCatchBackKey(true);
|
||||||
|
//Gdx.app.setLogLevel(Application.LOG_ERROR);
|
||||||
|
|
||||||
fullDeck = new Deck(new Texture("full_french_deck.png"));
|
fullDeck = new Deck(new Texture("full_french_deck.png"));
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
|
|
||||||
//fullDeck.getCards().get(52).setPosition(new Point(300f,100f));
|
//fullDeck.getCards().get(52).setPosition(new Point(300f,100f));
|
||||||
|
|
||||||
fullDeck.shuffle(110f, 110f);
|
//fullDeck.shuffle(110f, 110f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +47,7 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
public void render(float delta) {
|
public void render(float delta) {
|
||||||
Gdx.gl.glClearColor(0.2f, 0.6f, 0.2f, 0);
|
Gdx.gl.glClearColor(0.2f, 0.6f, 0.2f, 0);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
Gdx.input.setInputProcessor(this);
|
||||||
|
|
||||||
game.batch.begin();
|
game.batch.begin();
|
||||||
|
|
||||||
@@ -55,189 +57,187 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a finger or the mouse was dragged.
|
|
||||||
*
|
|
||||||
* @param screenX
|
|
||||||
* @param screenY
|
|
||||||
* @param pointer the pointer for the event. @return whether the input was processed
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
|
||||||
//deck
|
|
||||||
if (dragCounter == 0) {
|
|
||||||
if (fullDeck.isTouchingCard(screenX, Gdx.graphics.getHeight() - screenY)) {
|
|
||||||
fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY).setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
|
||||||
|
|
||||||
dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
@Override
|
||||||
dragCounter++;
|
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
||||||
}
|
Card c;
|
||||||
}
|
//deck
|
||||||
else if (fullDeck.isTouchingDraggedCard(screenX, Gdx.graphics.getHeight() - screenY)) {
|
|
||||||
fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY).setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
|
||||||
|
|
||||||
dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
//Gdx.app.error("VirtuaCardsGameScreen", "TouchDragged");
|
||||||
dragCounter++;
|
|
||||||
|
|
||||||
}
|
if (dragCounter == 0) {
|
||||||
else {
|
if (fullDeck.isTouchingCard(screenX, Gdx.graphics.getHeight() - screenY)) {
|
||||||
dragCounter = 0;
|
c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
dragBuffer.clear();
|
if (cardCounter == 2) { // Move deck of cards
|
||||||
}
|
if (cardsTouched.get(0).equals(cardsTouched.get(1)) && c.isDecked()) {
|
||||||
cardCounter = 0;
|
fullDeck.moveDeckTouched(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
return true;
|
}
|
||||||
}
|
else {
|
||||||
|
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
||||||
|
c.setDecked(false);
|
||||||
|
c.setDeckId(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
||||||
|
c.setDecked(false);
|
||||||
|
c.setDeckId(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
||||||
|
dragCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fullDeck.isTouchingDraggedCard(screenX, Gdx.graphics.getHeight() - screenY)) {
|
||||||
|
c = fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
|
if (cardCounter == 2) { // Move deck of cards
|
||||||
|
if (cardsTouched.get(0).equals(cardsTouched.get(1)) && c.isDecked()) {
|
||||||
|
fullDeck.moveDeckTouchedDragged(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
|
} else {
|
||||||
|
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
||||||
|
c.setDecked(false);
|
||||||
|
c.setDeckId(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
||||||
|
c.setDecked(false);
|
||||||
|
c.setDeckId(0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
||||||
* Called when a key was pressed
|
dragCounter++;
|
||||||
*
|
}
|
||||||
*/
|
else {
|
||||||
@Override
|
dragCounter = 0;
|
||||||
public boolean keyDown(int keycode) {
|
dragBuffer.clear();
|
||||||
|
cardsTouched.clear();
|
||||||
|
cardCounter = 0;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyDown(int keycode) {
|
||||||
if(keycode == Input.Keys.BACK) {
|
if(keycode == Input.Keys.BACK) {
|
||||||
game.setScreen(new VirtuaCardsMainMenu(game));
|
game.setScreen(new VirtuaCardsMainMenu(game));
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Called when a key was released
|
public boolean keyUp(int keycode) {
|
||||||
*
|
return false;
|
||||||
*/
|
}
|
||||||
@Override
|
|
||||||
public boolean keyUp(int keycode) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Called when a key was typed
|
public boolean keyTyped(char character) {
|
||||||
*
|
return false;
|
||||||
* @param character The character
|
}
|
||||||
* @return whether the input was processed
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean keyTyped(char character) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
*
|
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||||
* @param screenX The x coordinate, origin is in the upper left corner
|
|
||||||
* @param screenY The y coordinate, origin is in the upper left corner
|
|
||||||
* @param pointer the pointer for the event.
|
|
||||||
* @param button the button
|
|
||||||
* @return whether the input was processed
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
|
||||||
|
|
||||||
dragCounter = 0;
|
|
||||||
dragBuffer.clear();
|
|
||||||
cardCounter = 1;
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param screenX
|
|
||||||
* @param screenY
|
|
||||||
* @param pointer the pointer for the event.
|
|
||||||
* @param button the button @return whether the input was processed
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
|
||||||
Card c;
|
Card c;
|
||||||
|
dragCounter = 0;
|
||||||
|
dragBuffer.clear();
|
||||||
|
//Gdx.app.error("VirtuaCardsGameScreen", "TouchDown");
|
||||||
|
|
||||||
|
c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
|
if (c != null){
|
||||||
|
cardsTouched.add(cardCounter,c.getId());
|
||||||
|
cardCounter++;
|
||||||
|
}else{
|
||||||
|
cardsTouched.clear();
|
||||||
|
cardCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
|
Card c;
|
||||||
|
//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) {
|
||||||
fullDeck.autoDeckCard(screenX, Gdx.graphics.getHeight() - screenY);
|
fullDeck.autoDeckCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
|
|
||||||
if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 150)) { //flip card
|
if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 150)) { //flip card
|
||||||
//fullDeck.getCards().get(52).setFaceUp(true);
|
//fullDeck.getCards().get(52).setFaceUp(true);
|
||||||
c.toggleFaceUp();
|
c.toggleFaceUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cardCounter > 0){
|
||||||
|
cardCounter = 0;
|
||||||
|
cardsTouched.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
|
if (c != null){
|
||||||
|
if (cardCounter == 3){ // three touches on the same card shuffles the sub deck
|
||||||
|
if (cardsTouched.get(0) == cardsTouched.get(1) && cardsTouched.get(1) == cardsTouched.get(2)){
|
||||||
|
fullDeck.shuffle(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
|
}
|
||||||
|
cardCounter = 0;
|
||||||
|
cardsTouched.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dragCounter = 0;
|
if (cardCounter == 3){
|
||||||
dragBuffer.clear();
|
cardCounter = 0;
|
||||||
cardCounter = 0;
|
cardsTouched.clear();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
if (dragCounter > 0){
|
||||||
}
|
dragCounter = 0;
|
||||||
|
dragBuffer.clear();
|
||||||
|
|
||||||
/**
|
}
|
||||||
* Called when the mouse was moved without any buttons being pressed. Will not be called on iOS.
|
|
||||||
*
|
|
||||||
* @param screenX
|
|
||||||
* @param screenY
|
|
||||||
* @return whether the input was processed
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean mouseMoved(int screenX, int screenY) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return true;
|
||||||
* Called when the mouse wheel was scrolled. Will not be called on iOS.
|
}
|
||||||
*
|
|
||||||
* @param amount the scroll amount, -1 or 1 depending on the direction the wheel was scrolled.
|
@Override
|
||||||
* @return whether the input was processed.
|
public boolean mouseMoved(int screenX, int screenY) {
|
||||||
*/
|
return false;
|
||||||
@Override
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean scrolled(int amount) {
|
public boolean scrolled(int amount) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when this screen becomes the current screen for a {@link Game}.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param width
|
|
||||||
* @param height
|
|
||||||
* @see ApplicationListener#resize(int, int)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(int width, int height) {
|
public void resize(int width, int height) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ApplicationListener#pause()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void pause() {
|
public void pause() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ApplicationListener#resume()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void resume() {
|
public void resume() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when this screen is no longer the current screen for a {@link Game}.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void hide() {
|
public void hide() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when this screen should release all resources.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
|
||||||
|
|||||||
@@ -9,19 +9,15 @@ import com.badlogic.gdx.graphics.Pixmap;
|
|||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by angelcheca on 28/11/15.
|
* Created by angelcheca on 28/11/15.
|
||||||
*/
|
*/
|
||||||
public class VirtuaCardsMainMenu implements Screen, InputProcessor {
|
public class VirtuaCardsMainMenu implements Screen, InputProcessor {
|
||||||
final VirtuaCards game;
|
final VirtuaCards game;
|
||||||
private boolean exitScreen;
|
|
||||||
private Skin skin;
|
private Skin skin;
|
||||||
|
|
||||||
private TextButton playButton;
|
private TextButton playButton;
|
||||||
@@ -31,12 +27,10 @@ public class VirtuaCardsMainMenu implements Screen, InputProcessor {
|
|||||||
|
|
||||||
public VirtuaCardsMainMenu (final VirtuaCards g){
|
public VirtuaCardsMainMenu (final VirtuaCards g){
|
||||||
game = g;
|
game = g;
|
||||||
exitScreen = false;
|
|
||||||
skin = new Skin();
|
skin = new Skin();
|
||||||
|
|
||||||
Gdx.input.setInputProcessor(this);
|
Gdx.input.setInputProcessor(this);
|
||||||
|
|
||||||
|
|
||||||
Pixmap pixmap = new Pixmap(400, 100, Pixmap.Format.RGBA8888);
|
Pixmap pixmap = new Pixmap(400, 100, Pixmap.Format.RGBA8888);
|
||||||
pixmap.setColor(Color.GREEN);
|
pixmap.setColor(Color.GREEN);
|
||||||
pixmap.fill();
|
pixmap.fill();
|
||||||
@@ -99,47 +93,29 @@ public class VirtuaCardsMainMenu implements Screen, InputProcessor {
|
|||||||
}
|
}
|
||||||
game.batch.end();
|
game.batch.end();
|
||||||
|
|
||||||
if (exitScreen)
|
|
||||||
dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param width
|
|
||||||
* @param height
|
|
||||||
* @see ApplicationListener#resize(int, int)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(int width, int height) {
|
public void resize(int width, int height) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ApplicationListener#pause()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void pause() {
|
public void pause() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ApplicationListener#resume()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void resume() {
|
public void resume() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when this screen is no longer the current screen for a {@link Game}.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void hide() {
|
public void hide() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when this screen should release all resources.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
}
|
}
|
||||||
@@ -172,7 +148,7 @@ public class VirtuaCardsMainMenu implements Screen, InputProcessor {
|
|||||||
if (buttonClicked) // play button clicked
|
if (buttonClicked) // play button clicked
|
||||||
{
|
{
|
||||||
game.setScreen(new VirtuaCardsGameScreen(game));
|
game.setScreen(new VirtuaCardsGameScreen(game));
|
||||||
exitScreen = true;
|
dispose();
|
||||||
}
|
}
|
||||||
else { // exit button clicked
|
else { // exit button clicked
|
||||||
r.set(exitButton.getX(), exitButton.getY(), exitButton.getWidth(), exitButton.getHeight());
|
r.set(exitButton.getX(), exitButton.getY(), exitButton.getWidth(), exitButton.getHeight());
|
||||||
|
|||||||
Reference in New Issue
Block a user