Skip to content

Instantly share code, notes, and snippets.

@ltagliaferri
Created February 21, 2014 06:11
Show Gist options
  • Save ltagliaferri/9129635 to your computer and use it in GitHub Desktop.
Save ltagliaferri/9129635 to your computer and use it in GitHub Desktop.
Kitchen Cabinet Educational Game Initial Prototype
/**AboutMenu class showing the "About" menu
* Text, picture of host and some of the revolving panel, logo, and logos of social media
* sites that can be used to interact with Kitchen Cabinet through Facebook, Twitter, and Pinterest,
* for example. Logo can also point to an official website.
* Developed using libGDX library
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet.screens;
import aurelienribon.tweenengine.*;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
//import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
//import com.me.kitchencabinet.KitchenCabinet;
import com.me.kitchencabinet.tween.ActorAccessor;
public class AboutMenu implements Screen {
private Stage stage;
private TextureAtlas atlas;
private Skin skin;
private Table table;
private TextButton backButton;
private TweenManager tweenManager;
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
tweenManager.update(delta);
}
public void resize(int width, int height) {
stage.setViewport(width, height, true);
table.invalidateHierarchy();
table.setSize(width, height);
}
public void show() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
atlas = new TextureAtlas("ui/atlas.pack");
skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), atlas);
Texture kc = new Texture(Gdx.files.internal("img/kc.png"));
stage.addActor(new Image(kc));
table = new Table(skin);
table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
table.bottom().right();
backButton = new TextButton("BACK", skin);
backButton.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
}
});
backButton.pad(10);
table.row();
table.add(backButton).bottom().right();;
stage.addActor(table);
tweenManager = new TweenManager();
Tween.registerAccessor(Actor.class, new ActorAccessor());
tweenManager.update(Gdx.graphics.getDeltaTime());
stage.addAction(sequence(moveTo(0, stage.getHeight()), moveTo(0, 0, .5f)));
}
public void hide() {
dispose();
}
public void pause() {
}
public void resume() {
}
public void dispose() {
stage.dispose();
atlas.dispose();
skin.dispose();
}
}
/**ActorAccessor utilised by Actors in Tables and Stages for the tweenManager to animate
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet.tween;
import com.badlogic.gdx.scenes.scene2d.Actor;
import aurelienribon.tweenengine.TweenAccessor;
public class ActorAccessor implements TweenAccessor<Actor>{
/**declare Y, RGB, and ALPHA values to animate along Y-axis @param Y
* and fade-in and out @param ALPHA
*/
public static final int Y = 0, ALPHA = 1;
/**getter*/
public int getValues(Actor target, int tweenType, float[] returnValues) {
switch(tweenType){
case Y:
returnValues[0] = target.getY();return 1;
case ALPHA:
returnValues[0] = target.getColor().a;
return 1;
default:
assert false;
return - 1;
}
}
/**setter*/
public void setValues(Actor target, int tweenType, float[] newValues) {
switch(tweenType){
case Y:
target.setY(newValues[0]);
break;
case ALPHA:
target.setColor(target.getColor().r, target.getColor().g, target.getColor().b, newValues[0]);
break;
default:
assert false;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.me.kitchencabinet"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="17" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
/**Chips class to start preparation of chips. Will sequence across screens, first to cut the potato,
* then to fry the potato, then to reveal completed chips, then for a rating based on a Goldilocks scale,
* and nutritional feedback, eventually the user will continue to the next food item to cook or be returned
* to the city menu.
* Developed using libGDX library
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet.screens;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.me.kitchencabinet.tween.ActorAccessor;
import aurelienribon.tweenengine.*;
public class Chips implements Screen {
private Stage stage;
private TextureAtlas atlas;
private Skin skin;
private Table table;
private TextButton backButton;
private TweenManager tweenManager;
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
tweenManager.update(delta);
}
public void resize(int width, int height) {
stage.setViewport(width, height, true);
table.invalidateHierarchy();
table.setSize(width, height);
}
public void show() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
atlas = new TextureAtlas("ui/atlas.pack");
skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), atlas);
Texture chipBg = new Texture(Gdx.files.internal("img/chips.png"));
stage.addActor(new Image(chipBg));
table = new Table(skin);
table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
table.bottom().right();
backButton = new TextButton("BACK", skin);
backButton.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener()).setScreen(new PotatoMenu());
}
});
backButton.pad(10);
table.add(backButton).bottom().right();;
stage.addActor(table);
tweenManager = new TweenManager();
Tween.registerAccessor(Actor.class, new ActorAccessor());
tweenManager.update(Gdx.graphics.getDeltaTime());
stage.addAction(sequence(moveTo(0, stage.getHeight()), moveTo(0, 0, .5f)));
}
public void hide() {
dispose();
}
public void pause() {
}
public void resume() {
}
public void dispose() {
stage.dispose();
atlas.dispose();
skin.dispose();
}
}
/**Cook class to start game play. User will choose 1-5 of the 5 available sprites on the screen
* to put in "Meal" for cooking. On click of sprite, the user will be informed of the name of the food
* item and have the choice to "Add to Meal" or to "Cancel."
* Developed using libGDX library
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet.screens;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import com.me.kitchencabinet.tween.ActorAccessor;
import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import aurelienribon.tweenengine.*;
public class Cook implements Screen {
private Stage stage;
private TextureAtlas atlas;
private Skin skin;
private Table table;
private TextButton backButton, potatoButton;
private TweenManager tweenManager;
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
//make everything visible
stage.draw();
tweenManager.update(delta);
}
public void resize(int width, int height) {
stage.setViewport(width, height, true);
table.invalidateHierarchy(); //cause table's layout to be recalculated
table.setSize(width, height);
}
public void show() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
atlas = new TextureAtlas("ui/atlas.pack");
skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), atlas);
//background image
Texture levelBG = new Texture(Gdx.files.internal("img/levelBG.png"));
stage.addActor(new Image(levelBG));
//create table
table = new Table(skin);
table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
table.bottom().right();
//create buttons
//back button
backButton = new TextButton("BACK", skin);
backButton.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener()).setScreen(new LevelMenu());
}
});
backButton.pad(10);
//potato button
potatoButton = new TextButton("POTATO", skin);
potatoButton.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener()).setScreen(new PotatoMenu());
}
});
potatoButton.pad(10);
//add buttons to table
table.add(potatoButton);
table.add(backButton).bottom().right();;
stage.addActor(table);
tweenManager = new TweenManager();
Tween.registerAccessor(Actor.class, new ActorAccessor());
tweenManager.update(Gdx.graphics.getDeltaTime());
stage.addAction(sequence(moveTo(0, stage.getHeight()), moveTo(0, 0, .5f)));
}
public void hide() {
dispose();
}
public void pause() {
}
public void resume() {
}
public void dispose() {
stage.dispose();
atlas.dispose();
skin.dispose();
}
}
/**KitchenCabinet class is the class that inherits and implements the Game methods and initiates the
* game with the create() method.
* KitchenCabinet also initiates the @param Strings TITLE and VERSION
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet;
import com.badlogic.gdx.*;
import com.me.kitchencabinet.screens.*;
public class KitchenCabinet extends Game {
public static final String TITLE = "Kitchen Cabinet", VERSION = "1.0";
/**inherits all methods from Game class, create() method is called once, and sets the screen */
public void create() {
/**Screen to start the game with*/
setScreen(new Splash());
}
/**inherits dispose() method to dispose of screen, calls inherited method*/
public void dispose() {
/**Calls dispose() method from Game class*/
super.dispose();
}
/**inherits render() method to render the screen, calls inherited method*/
public void render() {
/**Calls render() method from Game class*/
super.render();
}
/**inherits resize() method to resize screen, calls inherited method*/
public void resize(int width, int height) {
/**Calls resize(width, height) method from Game class*/
super.resize(width, height);
}
/**inherits pause() method to pause the screen, calls inherited method*/
public void pause() {
/**Calls pause() method from Game class*/
super.pause();
}
/**inherits resume() method to resume the game, calls inherited method*/
public void resume() {
/**Calls resume() method from Game class*/
super.resume();
}
}
/**LevelMenu class showing the "Levels" menu to take user to game play once user selects
* a city and presses the "PLAY" button.
* Developed using libGDX library
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet.screens;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
public class LevelMenu implements Screen {
private Stage stage;
private Table table, tableBottom;
private TextureAtlas atlas;
private Skin skin;
private List list; //or "list box" displays textual items and highlights the currently selected item
private ScrollPane scrollPane; //group that scrolls a child widget using scroll bars
private TextButton cook, back;
public void render(float delta) {
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
}
public void resize(int width, int height) {
stage.setViewport(width, height, true);
table.invalidateHierarchy();
table.setSize(width, height);
}
public void show() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
atlas = new TextureAtlas("ui/atlas.pack");
skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), atlas);
Texture levelBg = new Texture(Gdx.files.internal("img/levelMain.png"));
stage.addActor(new Image(levelBg));
table = new Table(skin);
table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
/** instantiate & initialise list comprised of a String array to populate list
* Strings here are city locations in order of appearance on the episodes of Kitchen Cabinet,
* broadcast throughout the UK
*/
list = new List(new String[] {"Sibton", "Whitechapel", "Melton Mowbray", "Rye", "Bristol", "Brighton", "Southwold", "Newcastle", "Cumbria", "Edinburgh", "Birmingham", "Bath"}, skin);
/** instantiate & initialise scollPane, with list widget as child, and using skin
* as described in JSON
*/
scrollPane = new ScrollPane(list, skin);
cook = new TextButton("COOK", skin);
cook.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y){
((Game) Gdx.app.getApplicationListener()).setScreen(new Cook());
}
});
cook.pad(15);
back = new TextButton("BACK", skin);
back.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
}
});
back.pad(10);
/** instantiate & initialise image textBox, with instructions of game play */
Texture textBox = new Texture(Gdx.files.internal("img/text.png"));
table.add().width(table.getWidth() / 5); //make table have 5 columns for spacing
table.add().width(table.getWidth() / 5).row(); //add row, for spacing / style
table.add(scrollPane).left().expandY(); //put scroll pane on left, allow for it to expand as more cities are added
table.add(cook);
table.add(new Image(textBox)).right(); // put textBox image to the right
/** instantiate & initialise tableBottom at the bottom right for back button */
tableBottom = new Table(skin);
tableBottom.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
tableBottom.bottom();
tableBottom.right();
tableBottom.add(back).bottom().right();
stage.addActor(table);
stage.addActor(tableBottom);
/** animation for stage to drop in within a half second */
stage.addAction(sequence(moveTo(0, stage.getHeight()), moveTo(0, 0, .5f)));
}
public void hide() {
dispose();
}
public void pause() {
}
public void resume() {
}
public void dispose() {
stage.dispose();
atlas.dispose();
skin.dispose();
}
}
/**Main class to run Game Application on desktop machines
* Developed using libGDX library
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet;
import com.badlogic.gdx.backends.lwjgl.*;
public class Main {
public static void main(String[] args) {
/**instantiate LwjglApplicationConfiguration to specify configuration settings below
*/
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = KitchenCabinet.TITLE + " v" + KitchenCabinet.VERSION; //set title & version
cfg.vSyncEnabled = true; //synchronise FPS with monitor's refresh rate
cfg.useGL20 = true; //use OpenGL ES 2.0 for high performance graphics
cfg.width = 1280; //set width of Game Application window
cfg.height = 720; //set height of Game Application window
//create OpenGL surface in lightweight window and KitchenCabinet
new LwjglApplication(new KitchenCabinet(), cfg);
}
}
/**Main class to run Game Application on Android
* Developed using libGDX library
* Setup using gdx-setup-ui.jar from the libGDX nightly build
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class MainActivity extends AndroidApplication {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
initialize(new KitchenCabinet(), cfg);
}
}
/**MainMenu class showing the first "Menu" screen of the Game Application
* Developed using libGDX library
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet.screens;
import com.me.kitchencabinet.screens.LevelMenu;
import com.me.kitchencabinet.tween.ActorAccessor;
import aurelienribon.tweenengine.*; //utilising BaseTween, Timeline, Tween, TweenCallback, TweenManager
import com.badlogic.gdx.*; //utilising Game, Gdx, Screen
import com.badlogic.gdx.graphics.*; //utilising GL20, Texture
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.*; //utilising Actor, InputEvent, Stage
import com.badlogic.gdx.scenes.scene2d.ui.*; //utilising Label, Skin, Table, TextButton
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
/**MainMenu class to implement Screen interface
*/
public class MainMenu implements Screen {
private Stage stage; //2d scene graph containing actors, handles viewport and input events
private TextureAtlas atlas; //loads images from texture atlases
private Skin skin; //stores resources for UI widgets to use, described in my created JSON file
private Table table; //a group that sizes and positions children per constraints
private TextButton buttonPlay, buttonAbout, buttonExit; //a button with a child Label to display text
private Label heading; //a text label
private TweenManager tweenManager; //updates all tweens and timelines and once
/**tween -- core class of Tween Engine, interpolation between two values of an object attribute*/
/**render() is called when the screen should render itself.
* @param delta - the time in seconds since the last render.
*/
public void render (float delta) {
/**clear screen prior to rendering new screen*/
Gdx.gl.glClearColor(0, 0, 0, 1); //defines clear screen as black (setter)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); //clears the screen (accessor)
/**act method takes delta time since last frame, causes the act method
*on each actor to be called, so actors make this action based on time */
stage.act(delta);
/**draw method makes the stage visible */
stage.draw();
/**call for tween manager to update tweens and timelines*/
tweenManager.update(delta);
}
/**resize() called when the Application is resized, at any point when at a non-paused state,
* except prior to create() call.
* @param width the new width in pixels
* @param height the new height in pixels
*/
public void resize(int width, int height) {
/**keep stage at same size*/
stage.setViewport(width, height, true);
/**let the layout of the table be recalculated*/
table.invalidateHierarchy(); //invalidates table and its parents
table.setSize(width, height); //set width and height of table when the window is resized by user
}
/**show() called when this screen becomes the current screen for a Game
*/
public void show() {
/**instantiate & initialise stage */
stage = new Stage();
/**allow stage to get input events*/
Gdx.input.setInputProcessor(stage);
/** instantiate & initialise atlas and skin */
atlas = new TextureAtlas("ui/atlas.pack");
skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), atlas);
/**bring in PNG as a texture
* instantiate & initialise background image from file within assets (assets are added to the Android asset folder)*/
Texture bg = new Texture(Gdx.files.internal("img/mainMenuBg.png"));
/**add background image to stage so that it is visible*/
stage.addActor(new Image(bg));
/**instantiate & initialise table with skin */
table = new Table(skin);
/**set the initial table size as the size of the game per KitchenCabinet class*/
table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
/**instantiate & initialise heading */
heading = new Label("MENU", skin); //label takes in String and style from JSON
/**scale font size of the heading*/
heading.setFontScale(2);
/**instantiate & initialise buttons*/
/**create buttonPlay and add ClickListener to go to new screen upon click*/
buttonPlay = new TextButton("PLAY", skin); //text button takes String (word on button) and skin from JSON
buttonPlay.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y){ //change the look of the button when clicked based on JSON
((Game) Gdx.app.getApplicationListener()).setScreen(new LevelMenu());
}
});
buttonPlay.pad(15); //size of the button
/**buttonAbout */
buttonAbout = new TextButton("ABOUT", skin);
buttonAbout.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y){
((Game) Gdx.app.getApplicationListener()).setScreen(new AboutMenu());
}
});
buttonAbout.pad(15);
/** buttonExit */
buttonExit = new TextButton("EXIT", skin); //will read text button style out of the skin
buttonExit.pad(15);
buttonExit.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y) {
Gdx.app.exit();
}
});
buttonExit.pad(15);
/**add all of the elements to the table in order of appearance */
table.add(heading);
table.getCell(heading).spaceBottom(100); //add space below element's cell
table.row(); //adds a new row
table.add(buttonPlay);
table.getCell(buttonPlay).spaceBottom(15);
table.row();
table.add(buttonAbout);
table.getCell(buttonAbout).spaceBottom(15);
table.row();
table.add(buttonExit); //last element, no need to add space
/**add table to stage*/
stage.addActor(table); //each element is considered to be an Actor
/**instantiate & initialise tweenManager */
tweenManager = new TweenManager();
/**set up tween default configuration */
Tween.registerAccessor(Actor.class, new ActorAccessor());
/**create sequence animation that has table elements drop in */
Timeline.createSequence().beginSequence() //create sequential timeline, begin sequence
/**set buttons that need to wait to an alpha transparency of 0
* push = add a new animation to timeline */
.push(Tween.set(buttonPlay, ActorAccessor.ALPHA).target(0))
.push(Tween.set(buttonAbout, ActorAccessor.ALPHA).target(0))
.push(Tween.set(buttonExit, ActorAccessor.ALPHA).target(0))
.push(Tween.from(heading, ActorAccessor.ALPHA, .25f).target(0)) //"from" opposite to "to", quarter second, from 0 to 1
/**change buttons to visible */
.push(Tween.to(buttonPlay, ActorAccessor.ALPHA, .25f).target(1))
.push(Tween.to(buttonAbout, ActorAccessor.ALPHA, .25f).target(1))
.push(Tween.to(buttonExit, ActorAccessor.ALPHA, .25f).target(1))
.end().start(tweenManager); //end timeline
/**table fades in */
Tween.from(table, ActorAccessor.ALPHA, .5f).target(0);
Tween.from(table, ActorAccessor.Y, .5f).target(Gdx.graphics.getHeight() / 8).start(tweenManager);//one-eighth up and down
/**call for tweenManager to update based on delta time */
tweenManager.update(Gdx.graphics.getDeltaTime());
}
/**hide() is called when this screen is no longer the current screen */
public void hide() {
/**dispose of current screen */
dispose();
}
/**pause() is called when the Application is paused, before it is destroyed.
* On Android, a user pressing the Home button or receiving an incoming call.
* On desktop, this will be called only immediately before dispose() is called.
* An Application is paused before it is destroyed, when a user pressed the Home
*/
public void pause() {
}
/**resume() is called when the Application is resumed from a paused state.
* On Android this happens when the activity regains focus
* On the desktop this method will never be called.
*/
public void resume() {
}
/**dispose() is called when the Application is destroyed.
* It is preceded by a call to pause().
*/
public void dispose() {
/**dispose of elements on the screen */
stage.dispose();
atlas.dispose();
skin.dispose();
}
}
{
com.badlogic.gdx.graphics.Color: {
white: { r: 1, g: 1, b: 1, a: 1 },
black: { r: 0, g: 0, b: 0, a: 1 },
red: { r: 1, g: 0, b: 0, a: 1 },
green: { r: 0, g: 1, b: 0, a: 1 },
blue: { r: 0, g: 0, b: 1, a: 1 }
},
com.badlogic.gdx.graphics.g2d.BitmapFont: {
white: { file: font/white.fnt }
},
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
default: { font: white, fontColor: black }
},
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
default: { up: button.up, down: button.down, font: white, fontColor: black, pressedOffsetX: 1, pressedOffsetY: -1 }
},
com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: {
default: { hScrollKnob: button.up, vScrollKnob: button.up }
},
com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle: {
default: { fontColorUnselected: white, selection: blu.select, fontColorSelected: black, font: white }
}
}
/**PotatoMenu class to start game play once user chooses to cook potato,
* menu provides choice of how to prepare the potato.
* Developed using libGDX library
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet.screens;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.me.kitchencabinet.tween.ActorAccessor;
import aurelienribon.tweenengine.*;
public class PotatoMenu implements Screen {
private Stage stage;
private TextureAtlas atlas;
private Skin skin;
private Table table;
private TextButton backButton, chipsButton;
private TweenManager tweenManager;
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
tweenManager.update(delta);
}
public void resize(int width, int height) {
stage.setViewport(width, height, true);
table.invalidateHierarchy();
table.setSize(width, height);
}
public void show() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
atlas = new TextureAtlas("ui/atlas.pack");
skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), atlas);
Texture potato = new Texture(Gdx.files.internal("img/potato.png"));
stage.addActor(new Image(potato));
table = new Table(skin);
table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
table.bottom().right();
backButton = new TextButton("BACK", skin);
backButton.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener()).setScreen(new Cook());
}
});
backButton.pad(10);
chipsButton = new TextButton("CHIPS", skin);
chipsButton.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y) {
((Game) Gdx.app.getApplicationListener()).setScreen(new Chips());
}
});
chipsButton.pad(10);
table.add(chipsButton);
table.add(backButton).bottom().right();;
stage.addActor(table);
tweenManager = new TweenManager();
Tween.registerAccessor(Actor.class, new ActorAccessor());
tweenManager.update(Gdx.graphics.getDeltaTime());
stage.addAction(sequence(moveTo(0, stage.getHeight()), moveTo(0, 0, .5f)));
}
public void hide() {
dispose();
}
public void pause() {
}
public void resume() {
}
public void dispose() {
stage.dispose();
atlas.dispose();
skin.dispose();
}
}
/**Splash class is a fade-in image to introduce the game, can be used in conjunction with loading,
* and will set the tone of the game and the brand.
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet.screens;
import com.me.kitchencabinet.tween.*;
import aurelienribon.tweenengine.*;
import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;
public class Splash implements Screen{
private SpriteBatch batch; //draws 2D rectangles that references a texture (region), class will batch drawing commands and optimize them for processing by the GPU
private Sprite splash;
private TweenManager tweenManager;
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
splash.draw(batch);
batch.end();
tweenManager.update(delta);
}
public void resize(int width, int height) {
}
public void show() {
batch = new SpriteBatch();
tweenManager = new TweenManager();
Tween.registerAccessor(Sprite.class, new SpriteAccessor());
/**overrides size of png file*/
Texture.setEnforcePotImages(false);
Texture splashTexture = new Texture("img/splash.png");
/**bring splashTexture in as a sprite*/
splash = new Sprite(splashTexture);
/**set size of sprite*/
splash.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
/**have sprite fade in at 6 seconds*/
Tween.set(splash, SpriteAccessor.ALPHA).target(0).start(tweenManager);
Tween.to(splash, SpriteAccessor.ALPHA, 6).target(1).setCallback(new TweenCallback() {
public void onEvent(int type, BaseTween<?> source) {
((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
}
}).start(tweenManager);
/**update tweenManager to have the lowest time*/
tweenManager.update(Float.MIN_VALUE);
}
public void hide() {
dispose();
}
public void pause() {
}
public void resume() {
}
public void dispose() {
batch.dispose();
splash.getTexture().dispose();
}
}
/**SpriteAccessor utilised in Splash class for the tweenManager to move between values
* @author LTagliaferri
* @version 1.0
*/
package com.me.kitchencabinet.tween;
import com.badlogic.gdx.graphics.g2d.Sprite;
import aurelienribon.tweenengine.TweenAccessor;
/**SpriteAccessor implements TweenAccessor<Sprite> interface*/
public class SpriteAccessor implements TweenAccessor<Sprite> {
/**ALPHA value is defined by the tweenType*/
public static final int ALPHA = 0; //alpha value of the picture for the Splash class
/**method shows what the values are at the moment (getter)*/
public int getValues(Sprite target, int tweenType, float[] returnValues) {
//fade-in
switch(tweenType){
case ALPHA:
returnValues[0] = target.getColor().a;
return 1; //only one value declared --> return 1
default:
assert false; //if a tweenType is passed in that is not declared, it should not go through
return -1; //to show something is wrong
}
}
/**method sets values to how to change values (accessor)*/
public void setValues(Sprite target, int tweenType, float[] newValues) {
//bring in values to fade to splash image
switch(tweenType){
case ALPHA:
target.setColor(target.getColor().r, target.getColor().g, target.getColor().b, newValues[0]); //pass in rgb at the moment, return newValues
break;
default:
assert false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment