2 Commits
0.0.2 ... 0.0.5

6 changed files with 621 additions and 206 deletions

View File

@@ -11,6 +11,7 @@ import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import checamon.games.virtuacards.VirtuaCards;
public class AndroidLauncher extends AndroidApplication {
@Override
protected void onCreate (Bundle savedInstanceState) {
@@ -20,7 +21,7 @@ public class AndroidLauncher extends AndroidApplication {
hideVirtualButtons();
}
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new VirtuaCards(), config);
initialize(new VirtuaCards(),config);
Log.e("Error", "Error Test");
}
@TargetApi(19)

View File

@@ -19,6 +19,7 @@ public class Card {
private float sizeY;
private int id;
private boolean faceUp;
private boolean decked;
//private boolean onTable;
//private float orientation;
@@ -60,22 +61,6 @@ public class Card {
this.faceUp = false;
}
/*
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);
@@ -162,4 +147,12 @@ public class Card {
public void setBackSprite(Sprite backSprite) {
this.backSprite = backSprite;
}
public boolean isDecked() {
return decked;
}
public void setDecked(boolean decked) {
this.decked = decked;
}
}

View File

@@ -3,6 +3,7 @@ package checamon.games.virtuacards;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
@@ -61,7 +62,7 @@ public class Deck {
public void drawCards(SpriteBatch batch) {
int i = 0;
while (i <= numberOfCards){
while (i < numberOfCards){
if (drawOrder.get(i) > -1)
cards.get(drawOrder.get(i)).drawCardSprite(batch);
i++;
@@ -74,7 +75,7 @@ public class Deck {
boolean result = false;
int i = 0;
while (i <= numberOfCards && !exit){
while (i < numberOfCards && !exit){
if (drawOrder.get(i) > -1){
if (cards.get(drawOrder.get(i)).isTouched(x, y)) {
result = true;
@@ -92,7 +93,7 @@ public class Deck {
boolean result = false;
int i = 0;
while (i <= numberOfCards && !exit){
while (i < numberOfCards && !exit){
if (drawOrder.get(i) > -1){
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
result = true;
@@ -104,10 +105,54 @@ public class Deck {
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;
}
public Card getTouchedDraggedCard(float x, float y){
Card cardResult = null;
int i = numberOfCards;
int i = numberOfCards - 1;
boolean exit = false;
while (i >= 0 && !exit){
@@ -118,7 +163,9 @@ public class Deck {
i--;
}
}
if (i < numberOfCards)
//TODO Change this to not move to the top until is sure no other cards need to move
if (i < numberOfCards - 1)
setCardDrawOrderOnTop(i);
return cardResult;
}
@@ -126,7 +173,7 @@ public class Deck {
public Card getTouchedCard(float x, float y){
Card cardResult = null;
int i = numberOfCards;
int i = numberOfCards - 1;
boolean exit = false;
while (i >= 0 && !exit){
@@ -137,7 +184,8 @@ public class Deck {
i--;
}
}
if (i < numberOfCards)
//TODO Change this to not move to the top until is sure no other cards need to move
if (i < numberOfCards - 1)
setCardDrawOrderOnTop(i);
return cardResult;
@@ -166,8 +214,8 @@ public class Deck {
int next = 0;
int replace = drawOrder.get(index);;
while (i <= numberOfCards){
if (i < numberOfCards) {
while (i < numberOfCards){
if (i < numberOfCards-1) {
next = drawOrder.get(i + 1);
drawOrder.put(i,next);
i++;
@@ -194,6 +242,8 @@ public class Deck {
}
public void shuffle(float x, float y){
//TODO Change this method, the top may not work when cards already unsorted
ArrayList<Integer> subDeck = new ArrayList<Integer>();
Card c;
int top = numberOfCards-1;
@@ -219,6 +269,77 @@ public class Deck {
}
public void moveDeckTouched(float x, float y){
Card c = getTouchedCard(x,y);
Card card;
float deltaX;
float deltaY;
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
int i = c.getId() - 1;
while (i >= 0){
card = cards.get(drawOrder.get(i));
if (drawOrder.get(i) > -1 && card.isTouched(x, y)) {
card.setPosition(new Point(card.getCardSprite().getX() + deltaX, card.getCardSprite().getY() + deltaY));
}else{
i--;
}
}
}
public void moveDeckTouchedDragged(float x, float y){
Card c = getTouchedCard(x,y);
Card card;
float deltaX;
float deltaY;
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
int i = c.getId() - 1;
while (i >= 0){
card = cards.get(drawOrder.get(i));
if (drawOrder.get(i) > -1 && card.isTouchedDragged(x, y)) {
card.setPosition(new Point(card.getCardSprite().getX() + deltaX, card.getCardSprite().getY() + deltaY));
}else{
i--;
}
}
}
public void autoDeckCard(float x, float y){
Card c = getTouchedCard(x,y);
Card below = getTouchedCard(x,y, numberOfCards - 2);
// Detect if overlapping enough to deck automatically
// by default cards are 150 x 190
if (below != null) {
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);
}else{
c.setDecked(false);
}
}
}
public HashMap<Integer,Integer> getDrawOrder() {
return drawOrder;
}

View File

@@ -1,184 +1,28 @@
package checamon.games.virtuacards;
import com.badlogic.gdx.Game;
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;
/**
* Created by angelcheca on 28/11/15.
*/
public class VirtuaCards extends Game {
SpriteBatch batch;
import java.util.ArrayList;
//TODO Declare loading screen
public class VirtuaCards extends Game implements InputProcessor {
private SpriteBatch batch;
private int dragCounter;
private int cardCounter;
private ArrayList<Point> dragBuffer;
private Deck fullDeck;
@Override
public void create () {
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
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);
//TODO Initialize Loading Screen
this.setScreen(new VirtuaCardsMainMenu(this));
}
@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();
super.render(); // important!
}
/**
* 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++;
public void dispose() {
batch.dispose();
}
}
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++;
}
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 = 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) {
if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 150) && dragCounter > 0) { //flip card
//fullDeck.getCards().get(52).setFaceUp(true);
fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY).toggleFaceUp();
}
/*else// if (cardCounter == 1)
{
fullDeck.shuffle(screenX, Gdx.graphics.getHeight() - screenY);
}*/
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;
}
}

View File

@@ -0,0 +1,245 @@
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 java.util.ArrayList;
public class VirtuaCardsGameScreen implements Screen, InputProcessor {
private int dragCounter;
private int cardCounter;
private ArrayList<Point> dragBuffer;
private VirtuaCards game;
private Deck fullDeck;
public VirtuaCardsGameScreen (VirtuaCards g) {
game = g;
dragBuffer = new ArrayList<Point>();
dragCounter = 0;
cardCounter = 0;
Gdx.input.setInputProcessor(this);
Gdx.input.setCatchBackKey(true);
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);
game.batch.begin();
fullDeck.drawCards(game.batch);
game.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++;
}
else {
dragCounter = 0;
dragBuffer.clear();
}
cardCounter = 0;
return true;
}
/**
* Called when a key was pressed
*
*/
@Override
public boolean keyDown(int keycode) {
if(keycode == Input.Keys.BACK) {
game.setScreen(new VirtuaCardsMainMenu(game));
dispose();
}
return true;
}
/**
* 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 = 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;
if (dragCounter > 0) {
c = fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY);
if (c != null) {
fullDeck.autoDeckCard(screenX, Gdx.graphics.getHeight() - screenY);
if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 150)) { //flip card
//fullDeck.getCards().get(52).setFaceUp(true);
c.toggleFaceUp();
}
}
}
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;
}
/**
* Called when this screen becomes the current screen for a {@link Game}.
*/
@Override
public void show() {
}
/**
* @param width
* @param height
* @see ApplicationListener#resize(int, int)
*/
@Override
public void resize(int width, int height) {
}
/**
* @see ApplicationListener#pause()
*/
@Override
public void pause() {
}
/**
* @see ApplicationListener#resume()
*/
@Override
public void resume() {
}
/**
* Called when this screen is no longer the current screen for a {@link Game}.
*/
@Override
public void hide() {
}
/**
* Called when this screen should release all resources.
*/
@Override
public void dispose() {
}
}

View File

@@ -0,0 +1,211 @@
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.Stage;
import com.badlogic.gdx.scenes.scene2d.Touchable;
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;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
/**
* Created by angelcheca on 28/11/15.
*/
public class VirtuaCardsMainMenu implements Screen, InputProcessor {
final VirtuaCards game;
private boolean exitScreen;
private Skin skin;
private TextButton playButton;
private TextButton settingsButton;
private TextButton exitButton;
public VirtuaCardsMainMenu (final VirtuaCards g){
game = g;
exitScreen = false;
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();
if (exitScreen)
dispose();
}
/**
* @param width
* @param height
* @see ApplicationListener#resize(int, int)
*/
@Override
public void resize(int width, int height) {
}
/**
* @see ApplicationListener#pause()
*/
@Override
public void pause() {
}
/**
* @see ApplicationListener#resume()
*/
@Override
public void resume() {
}
/**
* Called when this screen is no longer the current screen for a {@link Game}.
*/
@Override
public void hide() {
}
/**
* Called when this screen should release all resources.
*/
@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));
exitScreen = true;
}
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;
}
}