Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f92fc6fdf | |||
| 1f01d26d4a | |||
| f5dd9286b7 | |||
| dac6ad76cd | |||
| e8e12d4316 | |||
| c76a2fba08 | |||
| c6298f9829 | |||
| bbe2ae3be5 |
@@ -1,5 +1,5 @@
|
|||||||
android {
|
android {
|
||||||
buildToolsVersion "23.0.1"
|
buildToolsVersion '23.0.2'
|
||||||
compileSdkVersion 21
|
compileSdkVersion 21
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
|
|||||||
@@ -1,20 +1,46 @@
|
|||||||
package checamon.games.virtuacards.android;
|
package checamon.games.virtuacards.android;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.view.View;
|
||||||
|
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplication;
|
import com.badlogic.gdx.backends.android.AndroidApplication;
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
|
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
|
||||||
|
|
||||||
import checamon.games.virtuacards.VirtuaCards;
|
import checamon.games.virtuacards.VirtuaCards;
|
||||||
|
|
||||||
|
|
||||||
public class AndroidLauncher extends AndroidApplication {
|
public class AndroidLauncher extends AndroidApplication {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate (Bundle savedInstanceState) {
|
protected void onCreate (Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
|
||||||
initialize(new VirtuaCards(), config);
|
|
||||||
|
|
||||||
Log.e("Error", "Error Test");
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
|
hideVirtualButtons();
|
||||||
|
}
|
||||||
|
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
||||||
|
initialize(new VirtuaCards(),config);
|
||||||
}
|
}
|
||||||
|
@TargetApi(19)
|
||||||
|
private void hideVirtualButtons() {
|
||||||
|
getWindow().getDecorView().setSystemUiVisibility(
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @Override
|
||||||
|
public void onWindowFocusChanged(boolean hasFocus) {
|
||||||
|
super.onWindowFocusChanged(hasFocus);
|
||||||
|
if (hasFocus) {
|
||||||
|
// In KITKAT (4.4) and next releases, hide the virtual buttons
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
|
hideVirtualButtons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ buildscript {
|
|||||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:1.2.3'
|
classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,15 @@ public class Card {
|
|||||||
private TextureRegion card;
|
private TextureRegion card;
|
||||||
private Point position;
|
private Point position;
|
||||||
private Sprite cardSprite;
|
private Sprite cardSprite;
|
||||||
|
private Sprite backSprite;
|
||||||
private float sizeX;
|
private float sizeX;
|
||||||
private float sizeY;
|
private float sizeY;
|
||||||
//private boolean faceUp;
|
private int id;
|
||||||
|
private boolean faceUp;
|
||||||
|
private boolean decked;
|
||||||
|
private int deckId;
|
||||||
|
private boolean stacked;
|
||||||
|
private int stackid;
|
||||||
//private boolean onTable;
|
//private boolean onTable;
|
||||||
//private float orientation;
|
//private float orientation;
|
||||||
|
|
||||||
@@ -42,35 +48,33 @@ public class Card {
|
|||||||
this.position = new Point(100f, 100f);
|
this.position = new Point(100f, 100f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card(TextureRegion region) {
|
public Card(TextureRegion region, int id, TextureRegion backRegion) {
|
||||||
|
|
||||||
this.card = region;
|
this.card = region;
|
||||||
this.cardSprite = new Sprite(region);
|
this.sizeX = 150f;
|
||||||
this.sizeX = 100f;
|
this.sizeY = 190f;
|
||||||
this.sizeY = 130f;
|
|
||||||
this.cardSprite.setSize(sizeX, sizeY);
|
|
||||||
this.position = new Point(100f, 100f);
|
this.position = new Point(100f, 100f);
|
||||||
|
this.cardSprite = new Sprite(region);
|
||||||
|
this.cardSprite.setSize(sizeX, sizeY);
|
||||||
this.cardSprite.setPosition(position.getX(), position.getY());
|
this.cardSprite.setPosition(position.getX(), position.getY());
|
||||||
|
this.backSprite = new Sprite(backRegion);
|
||||||
|
this.backSprite.setSize(sizeX, sizeY);
|
||||||
|
this.backSprite.setPosition(position.getX(), position.getY());
|
||||||
|
this.id = id;
|
||||||
|
this.faceUp = false;
|
||||||
|
this.decked = true;
|
||||||
|
this.deckId = 1;
|
||||||
|
this.stacked = false;
|
||||||
|
this.stackid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawCardSprite(SpriteBatch batch,Point point, float sizeX, float sizeY){
|
|
||||||
this.cardSprite.setPosition(point.getX(), point.getY());
|
|
||||||
this.cardSprite.setSize(sizeX, sizeY);
|
|
||||||
this.cardSprite.draw(batch);
|
|
||||||
//this.position = point;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawCardSprite(SpriteBatch batch, float sizeX, float sizeY){
|
|
||||||
this.cardSprite.setPosition(this.position.getX(), this.position.getY());
|
|
||||||
this.cardSprite.setSize(sizeX, sizeY);
|
|
||||||
this.cardSprite.draw(batch);
|
|
||||||
//this.sizeX = sizeX;
|
|
||||||
//this.sizeY = sizeY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawCardSprite(SpriteBatch batch){
|
public void drawCardSprite(SpriteBatch batch){
|
||||||
//this.cardSprite.setCenter(this.cardSprite.getX() + 1, this.cardSprite.getY() + 1);
|
//this.cardSprite.setCenter(this.cardSprite.getX() + 1, this.cardSprite.getY() + 1);
|
||||||
this.cardSprite.draw(batch);
|
if (faceUp)
|
||||||
|
this.cardSprite.draw(batch);
|
||||||
|
else
|
||||||
|
this.backSprite.draw(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTouched(float x, float y){
|
public boolean isTouched(float x, float y){
|
||||||
@@ -89,7 +93,12 @@ public class Card {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle getCardRectangle(){
|
public Rectangle getCardRectangle(){
|
||||||
return this.cardSprite.getBoundingRectangle();
|
Rectangle r;
|
||||||
|
if (faceUp)
|
||||||
|
r = this.cardSprite.getBoundingRectangle();
|
||||||
|
else
|
||||||
|
r = this.backSprite.getBoundingRectangle();
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(float sizeX, float sizeY){
|
public void setSize(float sizeX, float sizeY){
|
||||||
@@ -107,18 +116,77 @@ public class Card {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(Point position) {
|
public void setPosition(Point position) {
|
||||||
|
|
||||||
this.cardSprite.setPosition(position.getX(), position.getY());
|
this.cardSprite.setPosition(position.getX(), position.getY());
|
||||||
|
this.backSprite.setPosition(position.getX(), position.getY());
|
||||||
this.position.setCoordinates(position.getX(),position.getY());
|
this.position.setCoordinates(position.getX(),position.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCenter(Point position) {
|
public void setCenter(Point position) {
|
||||||
|
|
||||||
this.cardSprite.setCenter(position.getX(), position.getY());
|
this.cardSprite.setCenter(position.getX(), position.getY());
|
||||||
|
this.backSprite.setCenter(position.getX(), position.getY());
|
||||||
this.position.setCoordinates(position.getX(),position.getY());
|
this.position.setCoordinates(position.getX(),position.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void toggleFaceUp(){
|
||||||
|
faceUp = !faceUp;
|
||||||
|
}
|
||||||
|
|
||||||
public Sprite getCardSprite() {
|
public Sprite getCardSprite() {
|
||||||
return this.cardSprite;
|
return this.cardSprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFaceUp() {
|
||||||
|
return faceUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFaceUp(boolean faceUp) {
|
||||||
|
this.faceUp = faceUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sprite getBackSprite() {
|
||||||
|
return backSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackSprite(Sprite backSprite) {
|
||||||
|
this.backSprite = backSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDecked() {
|
||||||
|
return decked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDecked(boolean decked) {
|
||||||
|
this.decked = decked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeckId() {
|
||||||
|
return deckId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeckId(int deckId) {
|
||||||
|
this.deckId = deckId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStackid(int stackid) {
|
||||||
|
this.stackid = stackid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStacked(boolean stacked) {
|
||||||
|
|
||||||
|
this.stacked = stacked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStackid() {
|
||||||
|
|
||||||
|
return stackid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStacked() {
|
||||||
|
|
||||||
|
return stacked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package checamon.games.virtuacards;
|
package checamon.games.virtuacards;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
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.
|
||||||
*/
|
*/
|
||||||
@@ -17,7 +17,8 @@ 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 Sprite result;
|
private int deckCounter;
|
||||||
|
private int stackCounter;
|
||||||
|
|
||||||
public Deck(Texture texture) {
|
public Deck(Texture texture) {
|
||||||
try {
|
try {
|
||||||
@@ -29,13 +30,15 @@ public class Deck {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
for (int j = 0; j < 13; j++){
|
for (int j = 0; j < 13; j++){
|
||||||
this.cards.add(index, new Card(cc[i][j]));
|
this.cards.add(index, new Card(cc[i][j], index, cc[4][2]));
|
||||||
this.drawOrder.put(index, -1);
|
this.drawOrder.put(index, -1);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.numberOfCards = 54;
|
this.numberOfCards = 54;
|
||||||
|
this.deckCounter = 1;
|
||||||
|
this.stackCounter = 0;
|
||||||
|
|
||||||
}catch (Exception e)
|
}catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -58,20 +61,14 @@ public class Deck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawCards(SpriteBatch batch)
|
public void drawCards(SpriteBatch batch) {
|
||||||
{
|
|
||||||
boolean exit = false;
|
|
||||||
Sprite aux;
|
|
||||||
int i = 0;
|
|
||||||
while (i < numberOfCards && !exit){
|
|
||||||
if (drawOrder.get(i) > -1){
|
|
||||||
cards.get(drawOrder.get(i)).drawCardSprite(batch);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
exit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (i < numberOfCards){
|
||||||
|
if (drawOrder.get(i) > -1)
|
||||||
|
cards.get(drawOrder.get(i)).drawCardSprite(batch);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTouchingCard(float x, float y){
|
public boolean isTouchingCard(float x, float y){
|
||||||
@@ -82,14 +79,12 @@ public class Deck {
|
|||||||
|
|
||||||
while (i < numberOfCards && !exit){
|
while (i < numberOfCards && !exit){
|
||||||
if (drawOrder.get(i) > -1){
|
if (drawOrder.get(i) > -1){
|
||||||
if (cards.get(drawOrder.get(i)).isTouched(x,y)) {
|
if (cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
||||||
result = true;
|
result = true;
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else
|
i++;
|
||||||
exit = true;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -106,61 +101,399 @@ public class Deck {
|
|||||||
result = true;
|
result = true;
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else
|
i++;
|
||||||
exit = true;
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCardTouchedTopOfDeck(float x, float y){
|
||||||
|
boolean exit = false;
|
||||||
|
boolean result = false;
|
||||||
|
int touchCounter = 0;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (i < numberOfCards && !exit){
|
||||||
|
if (drawOrder.get(i) > -1){
|
||||||
|
if (cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
||||||
|
if (touchCounter == 0)
|
||||||
|
touchCounter++;
|
||||||
|
else if (touchCounter == 1) {
|
||||||
|
exit = true;
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCardTouchedDraggedTopOfDeck(float x, float y){
|
||||||
|
boolean exit = false;
|
||||||
|
boolean result = false;
|
||||||
|
int touchCounter = 0;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (i < numberOfCards && !exit){
|
||||||
|
if (drawOrder.get(i) > -1){
|
||||||
|
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
|
||||||
|
if (touchCounter == 0)
|
||||||
|
touchCounter++;
|
||||||
|
else if (touchCounter == 1) {
|
||||||
|
exit = true;
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card getTouchedDraggedCard(float x, float y){
|
public Card getTouchedDraggedCard(float x, float y){
|
||||||
|
|
||||||
boolean exit = false;
|
|
||||||
this.result = null;
|
|
||||||
Card cardResult = null;
|
Card cardResult = null;
|
||||||
int i = 0;
|
int i = numberOfCards - 1;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
while (i < numberOfCards && !exit){
|
while (i >= 0 && !exit){
|
||||||
if (drawOrder.get(i) > -1){
|
|
||||||
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
|
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
|
||||||
|
|
||||||
this.result = cards.get(drawOrder.get(i)).getCardSprite();
|
|
||||||
cardResult = cards.get(drawOrder.get(i));
|
cardResult = cards.get(drawOrder.get(i));
|
||||||
exit = true;
|
exit = true;
|
||||||
|
}else {
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
exit = true;
|
//TODO Change this to not move to the top until is sure no other cards need to move
|
||||||
}
|
if (i >= 0 && i < numberOfCards - 1)
|
||||||
|
setCardDrawOrderOnTop(i);
|
||||||
return cardResult;
|
return cardResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card getTouchedCard(float x, float y){
|
public Card getTouchedCard(float x, float y){
|
||||||
|
|
||||||
boolean exit = false;
|
|
||||||
this.result = null;
|
|
||||||
Card cardResult = null;
|
Card cardResult = null;
|
||||||
int i = 0;
|
int i = numberOfCards - 1;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
while (i < numberOfCards && !exit){
|
while (i >= 0 && !exit){
|
||||||
if (drawOrder.get(i) > -1){
|
if (drawOrder.get(i) > -1 && cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
||||||
if (cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
|
||||||
|
|
||||||
this.result = cards.get(drawOrder.get(i)).getCardSprite();
|
|
||||||
cardResult = cards.get(drawOrder.get(i));
|
cardResult = cards.get(drawOrder.get(i));
|
||||||
exit = true;
|
exit = true;
|
||||||
|
}else{
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
i++;
|
}
|
||||||
}
|
//TODO Change this to not move to the top until is sure no other cards need to move
|
||||||
else
|
if (i >= 0 && i < numberOfCards - 1)
|
||||||
|
setCardDrawOrderOnTop(i);
|
||||||
|
|
||||||
|
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;
|
exit = true;
|
||||||
|
}else{
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (Integer)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCardIndex(Card c){
|
||||||
|
int i = numberOfCards - 1;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
|
while (i >= 0 && !exit){
|
||||||
|
if (drawOrder.get(i) == c.getId()) {
|
||||||
|
exit = true;
|
||||||
|
}else{
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (Integer)i;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Card getTouchedCard(float x, float y, int top){
|
||||||
|
|
||||||
|
Card cardResult = null;
|
||||||
|
int i = top;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
|
while (i >= 0 && !exit){
|
||||||
|
if (drawOrder.get(i) > -1 && cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
||||||
|
cardResult = cards.get(drawOrder.get(i));
|
||||||
|
exit = true;
|
||||||
|
}else{
|
||||||
|
i--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cardResult;
|
return cardResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shuffle(float x, float y){
|
||||||
|
|
||||||
|
ArrayList<Integer> subDeck = new ArrayList<Integer>();
|
||||||
|
Card c;
|
||||||
|
int i = numberOfCards-1;
|
||||||
|
int index = 0;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
|
while (i >= 0 && !exit){
|
||||||
|
c = this.getTouchedCard(x, y, i);
|
||||||
|
if (c == null)
|
||||||
|
exit = true;
|
||||||
|
else{
|
||||||
|
subDeck.add(index,c.getId());
|
||||||
|
index++;
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!subDeck.isEmpty()){
|
||||||
|
setRandomCardDraw(subDeck);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveDeckTouched(float x, float y){
|
||||||
|
Card card;
|
||||||
|
int deckId = -1;
|
||||||
|
int cardDeck = -1;
|
||||||
|
int lastIndex = -1;
|
||||||
|
|
||||||
|
//Move all cards in the deck
|
||||||
|
int i = getTouchedCardIndex(x,y);
|
||||||
|
lastIndex = i;
|
||||||
|
|
||||||
|
while (i >= 0){
|
||||||
|
card = cards.get(drawOrder.get(i));
|
||||||
|
cardDeck = card.getDeckId();
|
||||||
|
if (cardDeck == deckId) {
|
||||||
|
card.setCenter(new Point(x, y));
|
||||||
|
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){
|
||||||
|
Card card;
|
||||||
|
int deckId = -1;
|
||||||
|
int cardDeck = -1;
|
||||||
|
int lastIndex = -1;
|
||||||
|
|
||||||
|
//Move all cards in the deck
|
||||||
|
int i = getTouchedCardIndex(x,y);
|
||||||
|
lastIndex = i;
|
||||||
|
|
||||||
|
while (i >= 0){
|
||||||
|
card = cards.get(drawOrder.get(i));
|
||||||
|
cardDeck = card.getDeckId();
|
||||||
|
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{
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!exit)
|
||||||
|
cardResult = null;
|
||||||
|
|
||||||
|
return cardResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
// by default cards are 150 x 190
|
||||||
|
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();
|
||||||
|
c.setPosition(new Point(r.getX(), r.getY()));
|
||||||
|
c.setDecked(true);
|
||||||
|
if (below.getDeckId() == 0) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void autoStackCard(float x, float y){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFaceUpDeck(Card c, boolean originalDecked, float x, float y){
|
||||||
|
int deckId = c.getDeckId();
|
||||||
|
int i = numberOfCards - 1;
|
||||||
|
int cardDeck;
|
||||||
|
boolean exit = false;
|
||||||
|
Card card;
|
||||||
|
|
||||||
|
if (!originalDecked){
|
||||||
|
c.toggleFaceUp();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
while (i >= 0 && !exit){
|
||||||
|
card = cards.get(drawOrder.get(i));
|
||||||
|
cardDeck = card.getDeckId();
|
||||||
|
if (cardDeck == deckId) {
|
||||||
|
card.toggleFaceUp();
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public HashMap<Integer,Integer> getDrawOrder() {
|
public HashMap<Integer,Integer> getDrawOrder() {
|
||||||
return drawOrder;
|
return drawOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumberOfCards() {
|
||||||
|
return numberOfCards;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeckCounter() {
|
||||||
|
return deckCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeckCounter(int deckCounter) {
|
||||||
|
this.deckCounter = deckCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCardDrawOrderOnTop(int index){
|
||||||
|
|
||||||
|
int i = index;
|
||||||
|
int next = 0;
|
||||||
|
int replace = drawOrder.get(index);;
|
||||||
|
|
||||||
|
while (i < numberOfCards){
|
||||||
|
if (i < numberOfCards-1) {
|
||||||
|
next = drawOrder.get(i + 1);
|
||||||
|
drawOrder.put(i,next);
|
||||||
|
i++;
|
||||||
|
}else{
|
||||||
|
drawOrder.put(i,replace);
|
||||||
|
i++;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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){
|
||||||
|
ArrayList<Integer> originalOrder = (ArrayList<Integer>) subDeck.clone();
|
||||||
|
|
||||||
|
Collections.shuffle(subDeck);
|
||||||
|
Integer replace;
|
||||||
|
for (int i = 0; i < originalOrder.size(); i++){
|
||||||
|
replace = drawOrder.get(originalOrder.get(i));
|
||||||
|
drawOrder.put(originalOrder.get(i),drawOrder.get(subDeck.get(i)));
|
||||||
|
drawOrder.put(subDeck.get(i),replace);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,19 +35,19 @@ public class Point {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean insideRightSquare(float deltaX, float deltaY)
|
public boolean insideRightSquare(float deltaX, float deltaY, float originalY)
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if (x <= x + deltaX && y <= y + (deltaY/2) && y > y - (deltaY/2))
|
if (x <= x + deltaX && y <= originalY + (deltaY/2) && y > originalY - (deltaY/2))
|
||||||
result = true;
|
result = true;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean insideLeftSquare(float deltaX, float deltaY)
|
public boolean insideLeftSquare(float deltaX, float deltaY, float originalY)
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if (x >= x - deltaX && y <= y + (deltaY/2) && y > y - (deltaY/2))
|
if (x >= x - deltaX && y <= originalY + (deltaY/2) && y > originalY - (deltaY/2))
|
||||||
result = true;
|
result = true;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -69,7 +69,7 @@ public class Point {
|
|||||||
if (direction == 0)
|
if (direction == 0)
|
||||||
direction++; // Always 1 when going to the right
|
direction++; // Always 1 when going to the right
|
||||||
|
|
||||||
if (!p.insideRightSquare(deltaX,deltaY) || direction > 1) //Already changed direction to the left and now has come back to the right or outside the range
|
if (!p.insideRightSquare(deltaX,deltaY, points.get(0).getY()) || direction > 1) //Already changed direction to the left and now has come back to the right or outside the range
|
||||||
{
|
{
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
@@ -79,7 +79,7 @@ public class Point {
|
|||||||
if (direction == 1)
|
if (direction == 1)
|
||||||
direction++; // Always 2 when going to the left
|
direction++; // Always 2 when going to the left
|
||||||
|
|
||||||
if (!p.insideLeftSquare(deltaX, deltaY) || direction == 0 || direction > 2) //Already changed direction several times or has started going left or outside range
|
if (!p.insideLeftSquare(deltaX, deltaY, points.get(0).getY()) || direction == 0 || direction > 2) //Already changed direction several times or has started going left or outside range
|
||||||
{
|
{
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,175 +1,28 @@
|
|||||||
package checamon.games.virtuacards;
|
package checamon.games.virtuacards;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Game;
|
||||||
import com.badlogic.gdx.ApplicationAdapter;
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.badlogic.gdx.InputProcessor;
|
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
/**
|
||||||
|
* Created by angelcheca on 28/11/15.
|
||||||
|
*/
|
||||||
|
public class VirtuaCards extends Game {
|
||||||
|
SpriteBatch batch;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
//TODO Declare loading screen
|
||||||
|
|
||||||
|
public void create() {
|
||||||
|
batch = new SpriteBatch();
|
||||||
|
|
||||||
public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
|
//TODO Initialize Loading Screen
|
||||||
private SpriteBatch batch;
|
|
||||||
|
|
||||||
private int dragCounter;
|
this.setScreen(new VirtuaCardsMainMenu(this));
|
||||||
private int cardCounter;
|
}
|
||||||
private ArrayList<Point> dragBuffer;
|
|
||||||
|
|
||||||
private Deck fullDeck;
|
public void render() {
|
||||||
|
super.render(); // important!
|
||||||
@Override
|
}
|
||||||
public void create () {
|
|
||||||
batch = new SpriteBatch();
|
|
||||||
dragBuffer = new ArrayList<Point>();
|
|
||||||
dragCounter = 0;
|
|
||||||
cardCounter = 0;
|
|
||||||
|
|
||||||
fullDeck = new Deck(new Texture("full_french_deck.png"));
|
|
||||||
|
|
||||||
//init drawn cards
|
|
||||||
fullDeck.getDrawOrder().put(0,11);
|
|
||||||
fullDeck.getDrawOrder().put(1,2);
|
|
||||||
fullDeck.getCards().get(2).setPosition(new Point (200f,300f));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render() {
|
|
||||||
Gdx.gl.glClearColor(0.2f, 0.6f, 0.2f, 0);
|
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
||||||
Gdx.input.setInputProcessor(this);
|
|
||||||
batch.begin();
|
|
||||||
|
|
||||||
fullDeck.drawCards(batch);
|
|
||||||
|
|
||||||
batch.end();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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));
|
|
||||||
dragCounter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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));
|
|
||||||
dragCounter++;
|
|
||||||
cardCounter++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dragCounter = 0;
|
|
||||||
dragBuffer.clear();
|
|
||||||
cardCounter = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a key was pressed
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean keyDown(int keycode) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a key was released
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean keyUp(int keycode) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a key was typed
|
|
||||||
*
|
|
||||||
* @param character The character
|
|
||||||
* @return whether the input was processed
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean keyTyped(char character) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @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 = 0;
|
|
||||||
|
|
||||||
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) {
|
|
||||||
|
|
||||||
//if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 50) && dragCounter > 0)
|
|
||||||
|
|
||||||
dragCounter = 0;
|
|
||||||
dragBuffer.clear();
|
|
||||||
cardCounter = 0;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
* @return whether the input was processed.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean scrolled(int amount) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
batch.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
254
core/src/checamon/games/virtuacards/VirtuaCardsGameScreen.java
Normal file
254
core/src/checamon/games/virtuacards/VirtuaCardsGameScreen.java
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
package checamon.games.virtuacards;
|
||||||
|
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
|
import com.badlogic.gdx.InputProcessor;
|
||||||
|
import com.badlogic.gdx.Screen;
|
||||||
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class VirtuaCardsGameScreen implements Screen, InputProcessor {
|
||||||
|
|
||||||
|
private int dragCounter;
|
||||||
|
private int cardCounter;
|
||||||
|
private ArrayList<Point> dragBuffer;
|
||||||
|
private ArrayList<Integer> cardsTouched;
|
||||||
|
private VirtuaCards game;
|
||||||
|
private Deck fullDeck;
|
||||||
|
private int dragTriggered;
|
||||||
|
|
||||||
|
private Rectangle lastTouch;
|
||||||
|
|
||||||
|
public VirtuaCardsGameScreen (VirtuaCards g) {
|
||||||
|
game = g;
|
||||||
|
dragBuffer = new ArrayList<Point>();
|
||||||
|
cardsTouched = new ArrayList<Integer>();
|
||||||
|
dragCounter = 0;
|
||||||
|
cardCounter = 0;
|
||||||
|
dragTriggered = 0;
|
||||||
|
lastTouch = new Rectangle(0f, 0f, 0f, 0f);
|
||||||
|
|
||||||
|
Gdx.input.setCatchBackKey(true);
|
||||||
|
//Gdx.app.setLogLevel(Application.LOG_ERROR);
|
||||||
|
|
||||||
|
fullDeck = new Deck(new Texture("full_french_deck.png"));
|
||||||
|
|
||||||
|
//init drawn cards
|
||||||
|
for (int i = 0; i < fullDeck.getNumberOfCards(); i++)
|
||||||
|
fullDeck.getDrawOrder().put(i,i);
|
||||||
|
|
||||||
|
//fullDeck.getCards().get(52).setPosition(new Point(300f,100f));
|
||||||
|
|
||||||
|
//fullDeck.shuffle(110f, 110f);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(float delta) {
|
||||||
|
Gdx.gl.glClearColor(0.2f, 0.6f, 0.2f, 0);
|
||||||
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
Gdx.input.setInputProcessor(this);
|
||||||
|
|
||||||
|
game.batch.begin();
|
||||||
|
|
||||||
|
fullDeck.drawCards(game.batch);
|
||||||
|
|
||||||
|
game.batch.end();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
||||||
|
Card c;
|
||||||
|
boolean ignore = false;
|
||||||
|
dragTriggered++;
|
||||||
|
Gdx.app.error("VirtuaCardsGameScreen", "TouchDragged");
|
||||||
|
if (dragTriggered < 5){
|
||||||
|
ignore = true;
|
||||||
|
}else if (dragCounter == 0) {
|
||||||
|
if (fullDeck.isTouchingCard(screenX, Gdx.graphics.getHeight() - screenY)) {
|
||||||
|
c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
|
if (cardCounter == 2) { // Move deck of cards
|
||||||
|
if (cardsTouched.get(0).equals(cardsTouched.get(1)) && c.isDecked()) {
|
||||||
|
fullDeck.moveDeckTouched(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));
|
||||||
|
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));
|
||||||
|
dragCounter++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dragCounter = 0;
|
||||||
|
dragBuffer.clear();
|
||||||
|
cardsTouched.clear();
|
||||||
|
cardCounter = 0;
|
||||||
|
}
|
||||||
|
return ignore;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyDown(int keycode) {
|
||||||
|
if(keycode == Input.Keys.BACK) {
|
||||||
|
game.setScreen(new VirtuaCardsMainMenu(game));
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyUp(int keycode) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(char character) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||||
|
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++;
|
||||||
|
lastTouch = c.getCardRectangle();
|
||||||
|
}else{
|
||||||
|
cardsTouched.clear();
|
||||||
|
cardCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
|
Card c;
|
||||||
|
boolean decked = false;
|
||||||
|
Gdx.app.error("VirtuaCardsGameScreen", "TouchUp");
|
||||||
|
if (dragCounter > 0) {
|
||||||
|
c = fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
|
if (c != null) {
|
||||||
|
decked = c.isDecked();
|
||||||
|
fullDeck.autoDeckCard(screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
|
|
||||||
|
if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 150)) { //flip card
|
||||||
|
fullDeck.toggleFaceUpDeck(c, decked, screenX, Gdx.graphics.getHeight() - screenY);
|
||||||
|
//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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cardCounter == 3){
|
||||||
|
cardCounter = 0;
|
||||||
|
cardsTouched.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dragCounter > 0){
|
||||||
|
dragCounter = 0;
|
||||||
|
dragBuffer.clear();
|
||||||
|
|
||||||
|
}
|
||||||
|
if (dragTriggered > 0)
|
||||||
|
dragTriggered = 0;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseMoved(int screenX, int screenY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean scrolled(int amount) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resize(int width, int height) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hide() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
187
core/src/checamon/games/virtuacards/VirtuaCardsMainMenu.java
Normal file
187
core/src/checamon/games/virtuacards/VirtuaCardsMainMenu.java
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
package checamon.games.virtuacards;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.InputProcessor;
|
||||||
|
import com.badlogic.gdx.Screen;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by angelcheca on 28/11/15.
|
||||||
|
*/
|
||||||
|
public class VirtuaCardsMainMenu implements Screen, InputProcessor {
|
||||||
|
final VirtuaCards game;
|
||||||
|
private Skin skin;
|
||||||
|
|
||||||
|
private TextButton playButton;
|
||||||
|
private TextButton settingsButton;
|
||||||
|
private TextButton exitButton;
|
||||||
|
|
||||||
|
|
||||||
|
public VirtuaCardsMainMenu (final VirtuaCards g){
|
||||||
|
game = g;
|
||||||
|
skin = new Skin();
|
||||||
|
|
||||||
|
Gdx.input.setInputProcessor(this);
|
||||||
|
|
||||||
|
Pixmap pixmap = new Pixmap(400, 100, Pixmap.Format.RGBA8888);
|
||||||
|
pixmap.setColor(Color.GREEN);
|
||||||
|
pixmap.fill();
|
||||||
|
|
||||||
|
BitmapFont bfont= new BitmapFont();
|
||||||
|
bfont.getData().setScale(2f,2f);
|
||||||
|
skin.add("default", bfont);
|
||||||
|
|
||||||
|
skin.add("white", new Texture(pixmap));
|
||||||
|
|
||||||
|
TextButtonStyle buttonStyle;
|
||||||
|
|
||||||
|
buttonStyle = new TextButtonStyle();
|
||||||
|
buttonStyle.up = skin.newDrawable("white", Color.GRAY);
|
||||||
|
buttonStyle.down = skin.newDrawable("white", Color.BLUE);
|
||||||
|
buttonStyle.over = skin.newDrawable("white",Color.LIGHT_GRAY);
|
||||||
|
buttonStyle.font = skin.getFont("default");
|
||||||
|
|
||||||
|
skin.add("buttonStyle",buttonStyle);
|
||||||
|
|
||||||
|
float x = Gdx.graphics.getWidth()/2 - 200;
|
||||||
|
float y = Gdx.graphics.getHeight()/2 - 200;
|
||||||
|
|
||||||
|
playButton = new TextButton("PLAY",buttonStyle);
|
||||||
|
playButton.setPosition(x, y);
|
||||||
|
settingsButton = new TextButton("SETTINGS",buttonStyle);
|
||||||
|
settingsButton.setPosition(x,y - 105f);
|
||||||
|
exitButton = new TextButton("EXIT",buttonStyle);
|
||||||
|
exitButton.setPosition(x,y - 210f);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when this screen becomes the current screen for a {@link Game}.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void show() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the screen should render itself.
|
||||||
|
*
|
||||||
|
* @param delta The time in seconds since the last render.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void render(float delta) {
|
||||||
|
Gdx.gl.glClearColor(0, 0f, 0.2f, 0);
|
||||||
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
game.batch.begin();
|
||||||
|
//TODO Draw loading screen the first time
|
||||||
|
try {
|
||||||
|
playButton.draw(game.batch, 2f);
|
||||||
|
settingsButton.draw(game.batch, 2f);
|
||||||
|
exitButton.draw(game.batch, 2f);
|
||||||
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
Gdx.app.error("Virtua Cards", "VirtuaCardsMainMenu - render", e);
|
||||||
|
}
|
||||||
|
game.batch.end();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resize(int width, int height) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hide() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyDown(int keycode) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyUp(int keycode) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(char character) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||||
|
|
||||||
|
boolean buttonClicked = false;
|
||||||
|
Rectangle r = new Rectangle(playButton.getX(), playButton.getY(), playButton.getWidth(), playButton.getHeight());
|
||||||
|
buttonClicked = r.contains(screenX,Gdx.graphics.getHeight() - screenY);
|
||||||
|
|
||||||
|
if (buttonClicked) // play button clicked
|
||||||
|
{
|
||||||
|
game.setScreen(new VirtuaCardsGameScreen(game));
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
else { // exit button clicked
|
||||||
|
r.set(exitButton.getX(), exitButton.getY(), exitButton.getWidth(), exitButton.getHeight());
|
||||||
|
buttonClicked = r.contains(screenX,Gdx.graphics.getHeight() - screenY);
|
||||||
|
if (buttonClicked){
|
||||||
|
Gdx.app.exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseMoved(int screenX, int screenY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean scrolled(int amount) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
#Sat Sep 21 13:08:26 CEST 2013
|
#Thu Dec 10 21:15:17 GMT 2015
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=http\://services.gradle.org/distributions/gradle-2.4-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
|
||||||
|
|||||||
Reference in New Issue
Block a user