Created
February 21, 2014 06:11
-
-
Save ltagliaferri/9129635 to your computer and use it in GitHub Desktop.
Kitchen Cabinet Educational Game Initial Prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**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); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**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(); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**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