Simple menu to play and exit, no settings menu yet.
This commit is contained in:
@@ -11,6 +11,7 @@ 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) {
|
||||||
@@ -20,18 +21,18 @@ public class AndroidLauncher extends AndroidApplication {
|
|||||||
hideVirtualButtons();
|
hideVirtualButtons();
|
||||||
}
|
}
|
||||||
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
||||||
initialize(new VirtuaCards(), config);
|
initialize(new VirtuaCards(),config);
|
||||||
Log.e("Error", "Error Test");
|
Log.e("Error", "Error Test");
|
||||||
}
|
}
|
||||||
@TargetApi(19)
|
@TargetApi(19)
|
||||||
private void hideVirtualButtons() {
|
private void hideVirtualButtons() {
|
||||||
getWindow().getDecorView().setSystemUiVisibility(
|
getWindow().getDecorView().setSystemUiVisibility(
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @Override
|
/* @Override
|
||||||
|
|||||||
@@ -1,184 +1,28 @@
|
|||||||
package checamon.games.virtuacards;
|
package checamon.games.virtuacards;
|
||||||
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Game;
|
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;
|
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 {
|
public void create() {
|
||||||
private SpriteBatch batch;
|
batch = new SpriteBatch();
|
||||||
private int dragCounter;
|
|
||||||
private int cardCounter;
|
|
||||||
private ArrayList<Point> dragBuffer;
|
|
||||||
|
|
||||||
private Deck fullDeck;
|
//TODO Initialize Loading Screen
|
||||||
|
|
||||||
|
this.setScreen(new VirtuaCardsMainMenu(this));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
public void render() {
|
||||||
public void create () {
|
super.render(); // important!
|
||||||
batch = new SpriteBatch();
|
}
|
||||||
dragBuffer = new ArrayList<Point>();
|
|
||||||
dragCounter = 0;
|
|
||||||
cardCounter = 0;
|
|
||||||
|
|
||||||
fullDeck = new Deck(new Texture("full_french_deck.png"));
|
public void dispose() {
|
||||||
|
batch.dispose();
|
||||||
//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() {
|
|
||||||
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++;
|
|
||||||
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
241
core/src/checamon/games/virtuacards/VirtuaCardsGameScreen.java
Normal file
241
core/src/checamon/games/virtuacards/VirtuaCardsGameScreen.java
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
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) {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
211
core/src/checamon/games/virtuacards/VirtuaCardsMainMenu.java
Normal file
211
core/src/checamon/games/virtuacards/VirtuaCardsMainMenu.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user