Everything is in these method:
public boolean keyUp(int keycode) {
// Reset game world
if (keycode == Keys.R) {
init();
}
// Toggle camera follow
else if (keycode == Keys.ENTER) {
cameraHelper.setTarget(cameraHelper.hasTarget() ? null
: levelGenerator.head);
} else if (keycode == Keys.ESCAPE || keycode == Keys.BACK) {
new MainMenuScreen(game);
}
return false;
}
collision with a rock
private void onCollisionBunnyHeadWithStecca(Rectangle r) {
if (varcoCollision == false) {
if(steccaCollision==false){
if (levelGenerator.head.jumpState != State.DYING)
if (Settings.soundEnabled)
Assets.playSound(Assets.urto);
levelGenerator.head.jumpState = State.DYING;
steccaCollision = true;
game.setScreen(new MainMenuScreen(game));
}
} else if (varcoCollision == true) {
levelGenerator.head.position.y = r.y
- levelGenerator.head.dimension.y;
levelGenerator.head.velocity.y = 0;
}
}
this is the MainMenuScreen:
package com.me.jumper.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GLCommon;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.me.jumper.Jump;
import com.me.jumper.game.Assets;
import com.me.jumper.util.OverlapTester;
import com.me.jumper.util.Settings;
public class MainMenuScreen extends InputAdapter implements Screen {
Jump game;
OrthographicCamera guiCam;
SpriteBatch batcher;
Rectangle playBounds, highScoreBounds, soundBounds;
Vector3 touchPoint;
boolean touchUp, touchDn;
AtlasRegion play, highScore, sound;
public MainMenuScreen(Jump game) {
this.game = game;
guiCam = new OrthographicCamera(320, 480);
guiCam.position.set(320 / 2, 480 / 2, 0);
batcher = new SpriteBatch();
playBounds = new Rectangle(160 - 75, 240 + 15, 150, 45);
highScoreBounds = new Rectangle(160 - 75, 240 - 15 - 75 / 2, 150, 45);
soundBounds = new Rectangle(160 - 75, 240 - 30 - 75 / 2 - 30 - 75 / 2
+ 15, 150, 45);
touchPoint = new Vector3();
play = Assets.playUp;
highScore = Assets.highScoreUp;
if (Settings.soundEnabled)
sound = Assets.soundOnUp;
else
sound = Assets.soundOffUp;
}
public void update(float deltaTime) {
}
public void draw(float deltaTime) {
GLCommon gl = Gdx.gl;
gl.glClearColor(1, 0, 0, 1);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
guiCam.update();
batcher.setProjectionMatrix(guiCam.combined);
batcher.disableBlending();
batcher.begin();
batcher.draw(Assets.menuBackground, 0, 0, 320, 480);
batcher.end();
batcher.enableBlending();
batcher.begin();
batcher.draw(play, 160 - 75, 240, 150, 75);
batcher.draw(highScore, 160 - 75, 240 - 30 - 75 / 2, 150, 75);
batcher.draw(sound, 160 - 75, 240 - 30 - 75 / 2 - 30 - 75 / 2, 150, 75);
batcher.end();
}
@Override
public void render(float delta) {
update(delta);
draw(delta);
}
@Override
public void resize(int width, int height) {
}
@Override
public void show() {
Gdx.input.setInputProcessor(this);
play = Assets.playUp;
highScore = Assets.highScoreUp;
if (Settings.soundEnabled)
sound = Assets.soundOnUp;
else
sound = Assets.soundOffUp;
}
@Override
public void hide() {
Settings.save();
}
@Override
public void pause() {
Settings.save();
}
@Override
public void resume() {
Settings.load();
}
@Override
public void dispose() {
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
guiCam.unproject(touchPoint.set(screenX, screenY, 0));
if (OverlapTester.pointInRectangle(playBounds, touchPoint.x,
touchPoint.y)) {
play = Assets.playDn;
}
if (OverlapTester.pointInRectangle(highScoreBounds, touchPoint.x,
touchPoint.y)) {
highScore = Assets.highScoreDn;
}
if (OverlapTester.pointInRectangle(soundBounds, touchPoint.x,
touchPoint.y)) {
if (Settings.soundEnabled)
sound = Assets.soundOnDn;
else
sound = Assets.soundOffDn;
}
return super.touchDown(screenX, screenY, pointer, button);
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if (OverlapTester.pointInRectangle(playBounds, touchPoint.x,
touchPoint.y)) {
play = Assets.playUp;
game.setScreen(new GameScreen(game));
}
if (OverlapTester.pointInRectangle(highScoreBounds, touchPoint.x,
touchPoint.y)) {
highScore = Assets.highScoreUp;
if (game.actionResolver.getSignedInGPGS())
game.actionResolver.getLeaderboardGPGS();
else
game.actionResolver.loginGPGS();
}
if (OverlapTester.pointInRectangle(soundBounds, touchPoint.x,
touchPoint.y)) {
if (Settings.soundEnabled)
sound = Assets.soundOffUp;
else
sound = Assets.soundOnUp;
Settings.soundEnabled = !Settings.soundEnabled;
if (Settings.soundEnabled)
Assets.song01.play();
else
Assets.song01.pause();
Settings.save();
}
return super.touchUp(screenX, screenY, pointer, button);
}
}