Initial commit
This commit is contained in:
11
core/build.gradle
Normal file
11
core/build.gradle
Normal file
@@ -0,0 +1,11 @@
|
||||
apply plugin: "java"
|
||||
|
||||
sourceCompatibility = 1.6
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
|
||||
|
||||
eclipse.project {
|
||||
name = appName + "-core"
|
||||
}
|
||||
114
core/src/checamon/games/virtuacards/Card.java
Normal file
114
core/src/checamon/games/virtuacards/Card.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package checamon.games.virtuacards;
|
||||
|
||||
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.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
|
||||
/**
|
||||
* Created by angelcheca on 17/11/15.
|
||||
*/
|
||||
public class Card {
|
||||
private TextureRegion card;
|
||||
private Point position;
|
||||
private Sprite cardSprite;
|
||||
private float sizeX;
|
||||
private float sizeY;
|
||||
//private boolean faceUp;
|
||||
//private boolean onTable;
|
||||
//private float orientation;
|
||||
|
||||
public Card(Texture deckImage, Point p, float sizeX, float sizeY, float u, float v, float u2, float v2) {
|
||||
|
||||
TextureRegion c = new TextureRegion(deckImage,u,v,u2,v2);
|
||||
this.cardSprite = new Sprite(c);
|
||||
this.card = c;
|
||||
this.sizeX = sizeX;
|
||||
this.sizeY = sizeY;
|
||||
this.position = p;
|
||||
this.cardSprite.setPosition(p.getX(),p.getY());
|
||||
this.cardSprite.setSize(sizeX,sizeY);
|
||||
}
|
||||
|
||||
public Card(Texture deckImage, float u, float v, float u2, float v2) {
|
||||
|
||||
TextureRegion c = new TextureRegion(deckImage,u,v,u2,v2);
|
||||
this.cardSprite = new Sprite(c);
|
||||
this.card = c;
|
||||
this.sizeX = 100f;
|
||||
this.sizeY = 130f;
|
||||
this.position = new Point(100f, 100f);
|
||||
}
|
||||
|
||||
public Card(TextureRegion region) {
|
||||
|
||||
this.card = region;
|
||||
this.cardSprite = new Sprite(region);
|
||||
this.sizeX = 100f;
|
||||
this.sizeY = 130f;
|
||||
this.cardSprite.setSize(sizeX, sizeY);
|
||||
this.position = new Point(100f, 100f);
|
||||
this.cardSprite.setPosition(position.getX(), position.getY());
|
||||
}
|
||||
|
||||
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){
|
||||
//this.cardSprite.setCenter(this.cardSprite.getX() + 1, this.cardSprite.getY() + 1);
|
||||
this.cardSprite.draw(batch);
|
||||
}
|
||||
|
||||
public boolean isTouched(float x, float y){
|
||||
Rectangle r = this.getCardRectangle();
|
||||
float h = r.getHeight();
|
||||
float w = r.getWidth();
|
||||
r.setHeight(r.getHeight() * 20);
|
||||
r.setWidth(r.getWidth() * 20);
|
||||
|
||||
r.setPosition(r.getX() - (r.getWidth() - w)/2, r.getY() - (r.getHeight() - h)/2);
|
||||
return r.contains(x, y);
|
||||
}
|
||||
|
||||
public Rectangle getCardRectangle(){
|
||||
return this.cardSprite.getBoundingRectangle();
|
||||
}
|
||||
|
||||
public void setSize(float sizeX, float sizeY){
|
||||
this.sizeX = sizeX;
|
||||
this.sizeY = sizeY;
|
||||
}
|
||||
|
||||
public TextureRegion getCard() {
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
public Point getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Point position) {
|
||||
|
||||
this.cardSprite.setCenter(position.getX(), position.getY());
|
||||
this.position.setCoordinates(position.getX(),position.getY());
|
||||
}
|
||||
|
||||
public Sprite getCardSprite() {
|
||||
return this.cardSprite;
|
||||
}
|
||||
}
|
||||
123
core/src/checamon/games/virtuacards/Deck.java
Normal file
123
core/src/checamon/games/virtuacards/Deck.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package checamon.games.virtuacards;
|
||||
|
||||
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.TextureRegion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by angelcheca on 17/11/15.
|
||||
*/
|
||||
public class Deck {
|
||||
private ArrayList<Card> cards;
|
||||
private HashMap<Integer,Integer> drawOrder;
|
||||
private int numberOfCards;
|
||||
private Sprite result;
|
||||
|
||||
public Deck(Texture texture) {
|
||||
try {
|
||||
TextureRegion[][] cc = new TextureRegion(texture).split(texture.getWidth()/13,texture.getHeight()/5);
|
||||
|
||||
|
||||
this.cards = new ArrayList();
|
||||
this.drawOrder = new HashMap<Integer,Integer>();
|
||||
int index = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 0; j < 13; j++){
|
||||
this.cards.add(index, new Card(cc[i][j]));
|
||||
this.drawOrder.put(index, -1);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
this.numberOfCards = 54;
|
||||
|
||||
}catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Card> getCards() {
|
||||
return cards;
|
||||
}
|
||||
|
||||
public void drawCard(SpriteBatch batch, int cardIndex, float x, float y, float sizeX, float sizeY){
|
||||
try {
|
||||
batch.draw(cards.get(cardIndex).getCard(),x,y,sizeX, sizeY);
|
||||
cards.get(cardIndex).setPosition(new Point(x,y));
|
||||
}catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isTouchingCard(float x, float y){
|
||||
|
||||
boolean exit = false;
|
||||
boolean result = false;
|
||||
int i = 0;
|
||||
|
||||
while (i < numberOfCards && !exit){
|
||||
if (drawOrder.get(i) > -1){
|
||||
if (cards.get(drawOrder.get(i)).isTouched(x,y)) {
|
||||
result = true;
|
||||
exit = true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else
|
||||
exit = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Card getTouchedCard(float x, float y){
|
||||
|
||||
boolean exit = false;
|
||||
this.result = null;
|
||||
Card cardResult = null;
|
||||
int i = 0;
|
||||
|
||||
while (i < numberOfCards && !exit){
|
||||
if (drawOrder.get(i) > -1){
|
||||
if (cards.get(drawOrder.get(i)).isTouched(x,y)) {
|
||||
|
||||
this.result = cards.get(drawOrder.get(i)).getCardSprite();
|
||||
cardResult = cards.get(drawOrder.get(i));
|
||||
exit = true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else
|
||||
exit = true;
|
||||
}
|
||||
return cardResult;
|
||||
}
|
||||
|
||||
public HashMap<Integer,Integer> getDrawOrder() {
|
||||
return drawOrder;
|
||||
}
|
||||
}
|
||||
7
core/src/checamon/games/virtuacards/Hand.java
Normal file
7
core/src/checamon/games/virtuacards/Hand.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package checamon.games.virtuacards;
|
||||
|
||||
/**
|
||||
* Created by angelcheca on 17/11/15.
|
||||
*/
|
||||
public class Hand {
|
||||
}
|
||||
7
core/src/checamon/games/virtuacards/Player.java
Normal file
7
core/src/checamon/games/virtuacards/Player.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package checamon.games.virtuacards;
|
||||
|
||||
/**
|
||||
* Created by angelcheca on 17/11/15.
|
||||
*/
|
||||
public class Player {
|
||||
}
|
||||
101
core/src/checamon/games/virtuacards/Point.java
Normal file
101
core/src/checamon/games/virtuacards/Point.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package checamon.games.virtuacards;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by angelcheca on 16/11/15.
|
||||
*/
|
||||
public class Point {
|
||||
private float x;
|
||||
private float y;
|
||||
|
||||
public Point (float xNew, float yNew)
|
||||
{
|
||||
x = xNew;
|
||||
y = yNew;
|
||||
}
|
||||
|
||||
public float getX ()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public float getY ()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
public boolean insideSquare(int deltaX, int deltaY)
|
||||
{
|
||||
boolean result = false;
|
||||
if (x <= deltaX && y <= deltaY)
|
||||
result = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean insideRightSquare(float deltaX, float deltaY)
|
||||
{
|
||||
boolean result = false;
|
||||
if (x <= x + deltaX && y <= y + (deltaY/2) && y > y - (deltaY/2))
|
||||
result = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean insideLeftSquare(float deltaX, float deltaY)
|
||||
{
|
||||
boolean result = false;
|
||||
if (x >= x - deltaX && y <= y + (deltaY/2) && y > y - (deltaY/2))
|
||||
result = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean pointListInsideDoubleTouchedDrag(List<Point> points, float deltaX, float deltaY){
|
||||
boolean result = true;
|
||||
Point p0 = null;
|
||||
Point p1 = null;
|
||||
int direction = 0;
|
||||
for (Iterator<Point> it = points.iterator(); it.hasNext();){
|
||||
Point p = it.next();
|
||||
|
||||
if (p1 == null)
|
||||
p1 = p;
|
||||
|
||||
if (p0 != null) {
|
||||
if (p.getX() >= p0.getX()) {
|
||||
if (direction == 0)
|
||||
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
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (direction == 1)
|
||||
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
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
p0 = p;
|
||||
}
|
||||
if (direction < 2) // less than two changes of direction
|
||||
result = false;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setCoordinates(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
246
core/src/checamon/games/virtuacards/VirtuaCards.java
Normal file
246
core/src/checamon/games/virtuacards/VirtuaCards.java
Normal file
@@ -0,0 +1,246 @@
|
||||
package checamon.games.virtuacards;
|
||||
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.InputProcessor;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
|
||||
SpriteBatch batch;
|
||||
Sprite sprite;
|
||||
Texture img, deck1;
|
||||
BitmapFont font;
|
||||
String debugText;
|
||||
|
||||
TextureRegion deck1region;
|
||||
TextureRegion[][] regions;
|
||||
TextureRegion deck2region;
|
||||
Sprite sprite2;
|
||||
|
||||
private float x, y;
|
||||
private int dragCounter;
|
||||
private ArrayList<Point> dragBuffer;
|
||||
private Sprite touchedSprite;
|
||||
|
||||
Deck fullDeck;
|
||||
Texture deck;
|
||||
|
||||
int cardCounter = 0;
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
batch = new SpriteBatch();
|
||||
//img = new Texture("badlogic.jpg");
|
||||
deck1 = new Texture("deck1pic.png");
|
||||
TextureRegion[][] cc = new TextureRegion(deck1).split(deck1.getWidth()/2,deck1.getHeight()/2);
|
||||
deck1region = new TextureRegion(cc[0][0]);
|
||||
deck2region = new TextureRegion(cc[0][1]);
|
||||
|
||||
try {
|
||||
deck = new Texture("full_french_deck.png");
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
font = new BitmapFont();
|
||||
font.setColor(Color.BLUE);
|
||||
//sprite = new Sprite(deck1);
|
||||
sprite = new Sprite(deck1region);
|
||||
|
||||
sprite2 = new Sprite(deck2region);
|
||||
sprite2.setPosition(50f, 50f);
|
||||
sprite2.scale(-0.75f);
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
sprite.setPosition(x, y);
|
||||
sprite.scale(-0.75f);
|
||||
|
||||
debugText = "LOADING ...";
|
||||
if (deck == null)
|
||||
debugText += " DECK IS NULL";
|
||||
dragCounter = 0;
|
||||
dragBuffer = new ArrayList();
|
||||
|
||||
fullDeck = new Deck(deck);
|
||||
touchedSprite = null;
|
||||
|
||||
fullDeck.getDrawOrder().put(0, 13);
|
||||
}
|
||||
|
||||
@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();
|
||||
//sprite.draw(batch);
|
||||
//sprite2.draw(batch);
|
||||
|
||||
fullDeck.drawCards(batch);
|
||||
|
||||
/*
|
||||
if (touchedSprite != null)
|
||||
touchedSprite.draw(batch);
|
||||
*/
|
||||
|
||||
|
||||
//font.draw(batch, debugText, 20, 40);
|
||||
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 (fullDeck.isTouchingCard(screenX, Gdx.graphics.getHeight() - screenY)){
|
||||
fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY).setPosition(new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
||||
/*touchedSprite = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY).getCardSprite();
|
||||
if (touchedSprite != null)
|
||||
touchedSprite.setCenter(screenX, Gdx.graphics.getHeight() - screenY);*/
|
||||
cardCounter++;
|
||||
/*
|
||||
debugText = "Card: X=" + String.valueOf(touchedSprite.getX()) + ", Y=" + String.valueOf(touchedSprite.getY()) +
|
||||
"; Touch X=" + String.valueOf(screenX) + ", Y=" + String.valueOf( Gdx.graphics.getHeight() - screenY) + " DragCounter=" + String.valueOf(dragCounter) +
|
||||
" DragBuffer Length: " + String.valueOf(dragBuffer.size()) + " Touch Card Counter = " + toString().valueOf(cardCounter);
|
||||
*/
|
||||
}
|
||||
else if (dragCounter > 0) {
|
||||
dragCounter = 0;
|
||||
dragBuffer.clear();
|
||||
}
|
||||
|
||||
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) {
|
||||
debugText = "Touch DOWN X=" + String.valueOf(screenX) + ", Y=" + String.valueOf(screenY) + " Image X=" +
|
||||
String.valueOf(sprite.getX()) + " Y=" + String.valueOf(sprite.getY()) + " DragCounter=" + String.valueOf(dragCounter) + " DragBuffer Length: " + String.valueOf(dragBuffer.size());;
|
||||
|
||||
/*Rectangle r = sprite.getBoundingRectangle();
|
||||
|
||||
if (r.contains(screenX,Gdx.graphics.getHeight() - screenY)) // It is touching the deck
|
||||
{
|
||||
batch.begin();
|
||||
sprite.draw(batch);
|
||||
batch.end();
|
||||
}
|
||||
*/
|
||||
|
||||
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)
|
||||
{//double swipe, left/right recognised
|
||||
debugText = "DoubleSwipe UP X=" + String.valueOf(screenX) + ", Y=" + String.valueOf(screenY) + " Image X=" +
|
||||
String.valueOf(sprite.getX()) + " Y=" + String.valueOf(sprite.getY()) + " DragCounter=" + String.valueOf(dragCounter) + " DragBuffer Length: " + String.valueOf(dragBuffer.size());
|
||||
|
||||
//fullDeck.getDrawOrder().put(0, 11);
|
||||
}
|
||||
else
|
||||
{
|
||||
debugText = "Touch UP X=" + String.valueOf(screenX) + ", Y=" + String.valueOf(screenY) + " Image X=" +
|
||||
String.valueOf(sprite.getX()) + " Y=" + String.valueOf(sprite.getY()) + " DragCounter=" + String.valueOf(dragCounter) + " DragBuffer Length: " + String.valueOf(dragBuffer.size());
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user