symphony flow - cross-platform game development
TRANSCRIPT
Symphony is a culture-driven technology house.
Zarko Oroz
Cross-Platform Game DevelopmentBunny Hopper
Bunny Hopper
2D Arcade gameRetro style
8bit textures and music
Developed in free time
libGDX
Cross-platform game and visualization development framework
Open sourceWritten in the Java
programming language with some C and C++ components for performance
V1.0 released in 2014 current is 1.9
libGDX
libGDX
libGDX
Before we beginFree Textures:http://opengameart.org/
Free Sounds:http://www.littlerobotsoundfactory.com/
Assets
Textures
Sounds
Let’s Start (libGDX Android)
Download & Rungdx-setup.jar file
GUI project generator
ProjectsAndroid
Core1 2 3
Fill info, select platforms and extensions
libGDXGUI project generator
libGDXAndroidCore
Application Adaptercreate()render()
BunnyHopperBackground2 TexturesBackground velocityTrack BackgroundY
Move background to top
...Texture[] backgrounds;float backgroundVelocity = 10f;int backgroundSize = 2;float[] backgroundY = new float[backgroundSize];...
public void create() {...backgrounds = new Texture[backgroundSize];backgrounds[0] = new Texture("grass_4.jpg");backgrounds[1] = new Texture("grass_4.jpg");backgroundY[0] = 0;backgroundY[1] = Gdx.graphics.getHeight();...
public void render() {…for (int i = 0; i < backgroundSize; i++) { if (backgroundY[i] < -Gdx.graphics.getHeight()) { backgroundY[i] = backgroundY[i == 0 ? 1 : 0] + Gdx.graphics.getHeight(); Gdx.app.log("Move", "true"); } else { backgroundY[i] = backgroundY[i] - backgroundVelocity; } batch.draw(backgrounds[0], 0, backgroundY[0], Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.draw(backgrounds[1], 0, backgroundY[1], Gdx.graphics.getWidth(), Gdx.graphics.getHeight());}...
BunnyHopper Background Video
...Texture[] run;Texture[] jump;TextureRegion[] runFrames;TextureRegion[] jumpFrames;Animation runAnimation;Animation jumpAnimation;
TextureRegion currentFrame;float slateTime;float bunnyY = 0;float startBunnyY = 0;float velocity = 0;float gravity = 1f;...
public void create() {...startBunnyY = Gdx.graphics.getHeight() / 10;bunnyY = startBunnyY;runFrames = new TextureRegion[2];jumpFrames = new TextureRegion[8];
run = new Texture[2];run[0] = new Texture(Gdx.files.internal("run1.png"));run[1] = new Texture(Gdx.files.internal("run2.png"));runFrames[0] = new TextureRegion(run[0]);runFrames[1] = new TextureRegion(run[1]);
runAnimation = new Animation(0.125f, runFrames);slateTime = 0f;...
Running animationJumping animationDefault state
BunnyHopperMain Character
public void render() {…slateTime += Gdx.graphics.getDeltaTime();if (bunnyY > startBunnyY || velocity < 0) { velocity = velocity + gravity; bunnyY -= velocity; }if ((/*Gdx.input.justTouched() ||*/ Gdx.input.getAccelerometerZ() > 15) && bunnyY <= startBunnyY) { // Jump velocity = -25;}if (bunnyY > startBunnyY) { currentFrame = jumpAnimation.getKeyFrame(slateTime, true);} else { currentFrame = runAnimation.getKeyFrame(slateTime, true);}//draw bunnybatch.draw(currentFrame, Gdx.graphics.getWidth() / 2 - BUNNY_SIZE / 2, bunnyY, BUNNY_SIZE, BUNNY_SIZE);...
Running animationJumping animationDefault state
BunnyHopperMain Character
BunnyHopper Main Character Video
Texture[] obstacles;int numberOfObstacles = 4;int minGap = 600;int maxGap = 1200;int obstacleHeight = 135;int lastObstacleY = 0;int scoringObstacle = 0;…public void create() {…obstacles = new Texture[numberOfObstacles];setObstacles();
obstacles[0] = new Texture("wall.png");obstacles[1] = new Texture("fence.png");obstacles[2] = new Texture("stone.png");obstacles[3] = new Texture("ground.png");lastObstacleY = Gdx.graphics.getHeight() + obstacleHeight;…public void render() {...for (int i = 0; i < numberOfObstacles; i++) { obstaclesRectangles[i].y = obstaclesRectangles[i].y - backgroundVelocity; batch.draw(obstacles[i], 0, obstaclesRectangles[i].y, obstaclesRectangles[i].width, obstaclesRectangles[i].height);
if (obstaclesRectangles[i].y > lastObstacleY) lastObstacleY = (int) obstaclesRectangles[i].y;
if (obstaclesRectangles[i].y < -Gdx.graphics.getHeight()) { Gdx.app.log("Move Obstacle", "true"); obstaclesRectangles[i].y = Gdx.graphics.getHeight() + obstacleHeight + getGap(); }
4 obstaclesRandom gapMove to top when
exits screenTrack scoring
obstacle
BunnyHopperObstacles
BunnyHopper Obstacles Video
Jump over obstacleDetect collision
shapesTrack bunnyY and
animationScore saved in
Preferences
ShapeRenderer shapeRenderer;Rectangle bunnyRect;Rectangle[] obstaclesRectangles;int score = 0;int scoringObstacle = 0;boolean newRecord;…public void create() {…shapeRenderer = new ShapeRenderer();bunnyRect = new Rectangle();obstaclesRectangles = new Rectangle[numberOfObstacles];…public void render() {…bunnyRect.set(Gdx.graphics.getWidth() / 2 - BUNNY_SIZE / 2, bunnyY, BUNNY_SIZE, BUNNY_SIZE);for (int i = 0; i < numberOfObstacles; i++) { obstaclesRectangles[i].y = obstaclesRectangles[i].y - backgroundVelocity;if (bunnyY <= startBunnyY && Intersector.overlaps(bunnyRect, obstaclesRectangles[i])) { Gdx.app.log("DEAD", "true"); // update high score if (score > getHighScore()) { newRecord = true; setHighScore(score); }}if (obstaclesRectangles[scoringObstacle].y < Gdx.graphics.getHeight() && obstaclesRectangles[scoringObstacle].y - obstaclesRectangles[scoringObstacle].getHeight() < startBunnyY - BUNNY_SIZE) { score++; Gdx.app.log("Score", String.valueOf(score)); if (scoringObstacle < numberOfObstacles - 1) { scoringObstacle++; } else { scoringObstacle = 0; }}
BunnyHopperCollision and Scoring
BunnyHopper Collision and scoring video
Background musicSounds
Start soundJump soundDead soundHighScore sound
Music themeSound;Sound jumpSound, deadSound, startSound, newRecordSound;…public void create() {…jumpSound = Gdx.audio.newSound(Gdx.files.internal("jumpland.wav"));deadSound = Gdx.audio.newSound(Gdx.files.internal("dead.ogg"));startSound = Gdx.audio.newSound(Gdx.files.internal("start.wav"));newRecordSound = Gdx.audio.newSound(Gdx.files.internal("new_record.mp3"));themeSound = Gdx.audio.newMusic(Gdx.files.internal("theme_song_2.ogg"));themeSound.setLooping(true);themeSound.setVolume(0.4f);themeSound.play();…public void render() {…if ((/*Gdx.input.justTouched() ||*/ Gdx.input.getAccelerometerZ() > 15) && bunnyY <= startBunnyY) { jumpSound.play();…
BunnyHopperSounds and Music
ReadyBest scoreInstructions
RunningRender
GameOverScoreTap to restart
BunnyHopperGame States
BunnyHopper Final game video