Commit 12c660db authored by a.guest's avatar a.guest

First Commit

parent 4817397b
package com.mygdx.game; package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
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;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import screens.MainMenuScreen;
public class MyGdxGame extends ApplicationAdapter { public class MyGdxGame extends Game {
SpriteBatch batch; public SpriteBatch batch;
Texture img; public BitmapFont font;
@Override @Override
public void create () { public void create () {
batch = new SpriteBatch(); batch = new SpriteBatch();
img = new Texture("badlogic.jpg"); font = new BitmapFont();
this.setScreen(new MainMenuScreen(this));
} }
@Override @Override
public void render () { public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1); super.render();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
} }
@Override @Override
public void dispose () { public void dispose () {
batch.dispose(); batch.dispose();
img.dispose(); font.dispose();
} }
} }
package screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.Input.Keys;
import com.mygdx.game.*;
public class GameOverScreen extends ScreenTemplate{
public GameOverScreen(final MyGdxGame game)
{
super(game);
}
public void process_input(float delta)
{
super.process_input(delta);
if (Gdx.input.isKeyPressed(Keys.F1)&&enough_time_passed()) {
game_handle.setScreen(new MainMenuScreen(game_handle));
dispose();
}
}
public void update(float delta)
{
}
public void render_me(float delta)
{
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
game_handle.batch.setProjectionMatrix(camera.combined);
game_handle.batch.begin();
game_handle.font.draw(game_handle.batch, "Game Over! ", 100, 150);
game_handle.font.draw(game_handle.batch, "Press F1 to play again", 100, 100);
game_handle.batch.end();
}
}
package screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.Input.Keys;
import com.mygdx.game.*;
public class MainGameScreen extends ScreenTemplate{
public MainGameScreen(final MyGdxGame game)
{
super(game);
}
public void process_input(float delta)
{
super.process_input(delta);
if (Gdx.input.isKeyPressed(Keys.F1)&&enough_time_passed()) {
game_handle.setScreen(new GameOverScreen(game_handle));
dispose();
}
}
public void update(float delta)
{
}
public void render_me(float delta)
{
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
game_handle.batch.setProjectionMatrix(camera.combined);
game_handle.batch.begin();
game_handle.font.draw(game_handle.batch, "oooh super sexy game play!! ", 100, 150);
game_handle.font.draw(game_handle.batch, "Press F1 to end game", 100, 100);
game_handle.batch.end();
}
}
package screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.Input.Keys;
import com.mygdx.game.*;
public class MainMenuScreen extends ScreenTemplate{
public MainMenuScreen(final MyGdxGame game)
{
super(game);
}
public void process_input(float delta)
{
super.process_input(delta);
if (Gdx.input.isTouched()) {
game_handle.setScreen(new MainGameScreen(game_handle));
dispose();
}
if (Gdx.input.isKeyPressed(Keys.F1)&&enough_time_passed()) {
game_handle.setScreen(new MainGameScreen(game_handle));
dispose();
}
}
public void update(float delta)
{
}
public void render_me(float delta)
{
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
game_handle.batch.setProjectionMatrix(camera.combined);
game_handle.batch.begin();
game_handle.font.draw(game_handle.batch, "Welcome to My Sexy Game!!! ", 100, 150);
game_handle.font.draw(game_handle.batch, "Tap anywhere to begin!, Esc for options", 100, 100);
game_handle.batch.end();
}
}
package screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.Input.Keys;
import com.mygdx.game.*;
public class OptionsScreen extends ScreenTemplate{
public ScreenTemplate previousScreen;
boolean ESC_PRESSED=false;
public OptionsScreen(final MyGdxGame game, ScreenTemplate prev_screen)
{
super(game);
previousScreen = prev_screen;
}
public void process_input(float delta)
{
// do not call super.process_input(delta) here
// its there to call switch to options screen
// and we are already there!
if (Gdx.input.isTouched()) {
game_handle.setScreen(new MainGameScreen(game_handle));
dispose();
}
if (Gdx.input.isKeyPressed(Keys.F1)&&enough_time_passed()) {
game_handle.setScreen(new MainGameScreen(game_handle));
dispose();
}
if (Gdx.input.isKeyPressed(Keys.ESCAPE)&&enough_time_passed()) {
previousScreen.set_start_time();
game_handle.setScreen(previousScreen);
dispose();
}
}
public void update(float delta)
{
}
public void render_me(float delta)
{
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
game_handle.batch.setProjectionMatrix(camera.combined);
game_handle.batch.begin();
game_handle.font.draw(game_handle.batch, "Options Screen", 100, 150);
game_handle.font.draw(game_handle.batch, "Press escape to return", 100, 100);
game_handle.batch.end();
}
}
package screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.Input.Keys;
import com.mygdx.game.*;
import com.badlogic.gdx.utils.TimeUtils;
public class ScreenTemplate implements Screen{
public MyGdxGame game_handle;
public OrthographicCamera camera;
public long StartTime;
public final long ENOUGH_TIME = 250; // 250ms
public ScreenTemplate()
{
game_handle = null;
}
public ScreenTemplate(final MyGdxGame game)
{
game_handle = game;
camera = new OrthographicCamera();
camera.setToOrtho(false,800,600);
set_start_time();
}
@Override
public void show() {
// TODO Auto-generated method stub
}
public long elapsed_time()
{
long NowTime = TimeUtils.nanosToMillis(TimeUtils.nanoTime());
return(NowTime-StartTime);
}
public boolean enough_time_passed()
{
if (elapsed_time()>ENOUGH_TIME)
return true;
else
return false;
}
public void set_start_time()
{
StartTime = TimeUtils.nanosToMillis(TimeUtils.nanoTime());
}
public void process_input(float delta)
{
if (Gdx.input.isKeyPressed(Keys.ESCAPE)&&enough_time_passed()) {
game_handle.setScreen(new OptionsScreen(game_handle,this));
}
}
public void update(float delta)
{
}
public void render_me(float delta)
{
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
game_handle.batch.setProjectionMatrix(camera.combined);
game_handle.batch.begin();
game_handle.font.draw(game_handle.batch, "Game Over! ", 100, 150);
game_handle.font.draw(game_handle.batch, "Press F1 to play again", 100, 100);
game_handle.batch.end();
}
@Override
public void render(float delta) {
process_input(delta);
update(delta);
render_me(delta);
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment