From: fred-boy Date: Sat, 21 Apr 2018 19:47:38 +0000 (+0700) Subject: Add menu screen and game logo X-Git-Tag: alpha0.2.1~6 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=4140ddda97930af75b0d50b821ed9eb6337273e2;p=cavedroid.git Add menu screen and game logo --- diff --git a/android/assets/gamelogo.png b/android/assets/gamelogo.png new file mode 100644 index 0000000..7984a53 Binary files /dev/null and b/android/assets/gamelogo.png differ diff --git a/android/assets/gamelogo_s.png b/android/assets/gamelogo_s.png new file mode 100644 index 0000000..e91b200 Binary files /dev/null and b/android/assets/gamelogo_s.png differ diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java index acdebdf..427ebc6 100644 --- a/core/src/ru/deadsoftware/cavecraft/Assets.java +++ b/core/src/ru/deadsoftware/cavecraft/Assets.java @@ -12,6 +12,8 @@ public class Assets { public static BitmapFont minecraftFont; + public static Sprite gameLogo; + public static Texture charTexture; public static Sprite[][] playerSprite = new Sprite[2][4]; @@ -82,6 +84,8 @@ public class Assets { public static void load() { minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true); + gameLogo = new Sprite(new Texture(Gdx.files.internal("gamelogo.png"))); + gameLogo.flip(false, true); loadPlayer(); loadPig(); diff --git a/core/src/ru/deadsoftware/cavecraft/CaveGame.java b/core/src/ru/deadsoftware/cavecraft/CaveGame.java index 99e4f68..6ef0427 100644 --- a/core/src/ru/deadsoftware/cavecraft/CaveGame.java +++ b/core/src/ru/deadsoftware/cavecraft/CaveGame.java @@ -16,7 +16,7 @@ public class CaveGame extends Game { public CaveGame(boolean touch) { TOUCH = touch; - STATE = GameState.GAME_PLAY; + STATE = GameState.MENU_MAIN; } @Override diff --git a/core/src/ru/deadsoftware/cavecraft/GameScreen.java b/core/src/ru/deadsoftware/cavecraft/GameScreen.java index 2a2c262..6daa039 100644 --- a/core/src/ru/deadsoftware/cavecraft/GameScreen.java +++ b/core/src/ru/deadsoftware/cavecraft/GameScreen.java @@ -1,23 +1,23 @@ package ru.deadsoftware.cavecraft; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.Input; -import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.Screen; -import ru.deadsoftware.cavecraft.game.GameInputHandler; import ru.deadsoftware.cavecraft.game.GameProc; +import ru.deadsoftware.cavecraft.menu.MenuRenderer; public class GameScreen implements Screen { public static int FPS; private GameProc gameProc; + private Renderer renderer; public GameScreen() { Assets.load(); Items.load(); gameProc = new GameProc(); - Gdx.input.setInputProcessor(new InputHandler(gameProc)); + renderer = new MenuRenderer(); + Gdx.input.setInputProcessor(new InputHandlerMenu()); } public static int getWidth() { @@ -28,6 +28,13 @@ public class GameScreen implements Screen { return Gdx.graphics.getHeight(); } + private void game(float delta) { + gameProc.update(delta); + } + + private void menu() { + } + @Override public void show() { @@ -35,19 +42,35 @@ public class GameScreen implements Screen { @Override public void render(float delta) { - if (CaveGame.STATE == GameState.RESTART) { - gameProc = new GameProc(); - Gdx.input.setInputProcessor(new InputHandler(gameProc)); - CaveGame.STATE = GameState.GAME_PLAY; - } FPS = (int)(1/delta); - gameProc.update(delta); - gameProc.renderer.render(); + switch (CaveGame.STATE) { + case GAME_PLAY: case GAME_CREATIVE_INV: + game(delta); + break; + + case MENU_MAIN: + menu(); + break; + + case RESTART: + gameProc = new GameProc(); + Gdx.input.setInputProcessor(new InputHandlerGame(gameProc)); + CaveGame.STATE = GameState.GAME_PLAY; + break; + } + renderer.render(); } @Override public void resize(int width, int height) { - gameProc.resetRenderer(); + switch (CaveGame.STATE) { + case MENU_MAIN: + renderer = new MenuRenderer(); + break; + case GAME_PLAY: case GAME_CREATIVE_INV: + gameProc.resetRenderer(); + break; + } } @Override diff --git a/core/src/ru/deadsoftware/cavecraft/GameState.java b/core/src/ru/deadsoftware/cavecraft/GameState.java index dd6b021..d8be71a 100644 --- a/core/src/ru/deadsoftware/cavecraft/GameState.java +++ b/core/src/ru/deadsoftware/cavecraft/GameState.java @@ -2,6 +2,7 @@ package ru.deadsoftware.cavecraft; public enum GameState { RESTART, + MENU_MAIN, GAME_PLAY, GAME_CREATIVE_INV } diff --git a/core/src/ru/deadsoftware/cavecraft/InputHandler.java b/core/src/ru/deadsoftware/cavecraft/InputHandlerGame.java similarity index 95% rename from core/src/ru/deadsoftware/cavecraft/InputHandler.java rename to core/src/ru/deadsoftware/cavecraft/InputHandlerGame.java index da3e9e4..e22caec 100644 --- a/core/src/ru/deadsoftware/cavecraft/InputHandler.java +++ b/core/src/ru/deadsoftware/cavecraft/InputHandlerGame.java @@ -2,22 +2,22 @@ package ru.deadsoftware.cavecraft; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputProcessor; -import ru.deadsoftware.cavecraft.game.GameInputHandler; +import ru.deadsoftware.cavecraft.game.GameInput; import ru.deadsoftware.cavecraft.game.GameProc; import static ru.deadsoftware.cavecraft.GameScreen.getHeight; import static ru.deadsoftware.cavecraft.GameScreen.getWidth; -public class InputHandler implements InputProcessor { +public class InputHandlerGame implements InputProcessor { private GameProc gameProc; - private GameInputHandler gameInput; + private GameInput gameInput; private float tWidth, tHeight; - public InputHandler(GameProc gameProc) { + public InputHandlerGame(GameProc gameProc) { this.gameProc = gameProc; - this.gameInput = new GameInputHandler(gameProc); + this.gameInput = new GameInput(gameProc); tWidth = gameProc.renderer.camera.viewportWidth; tHeight = gameProc.renderer.camera.viewportHeight; } diff --git a/core/src/ru/deadsoftware/cavecraft/InputHandlerMenu.java b/core/src/ru/deadsoftware/cavecraft/InputHandlerMenu.java new file mode 100644 index 0000000..fe3cb4d --- /dev/null +++ b/core/src/ru/deadsoftware/cavecraft/InputHandlerMenu.java @@ -0,0 +1,47 @@ +package ru.deadsoftware.cavecraft; + +import com.badlogic.gdx.InputProcessor; + +public class InputHandlerMenu implements InputProcessor{ + + @Override + public boolean keyDown(int keycode) { + return false; + } + + @Override + public boolean keyUp(int keycode) { + return false; + } + + @Override + public boolean keyTyped(char character) { + return false; + } + + @Override + public boolean touchDown(int screenX, int screenY, int pointer, int button) { + return false; + } + + @Override + public boolean touchUp(int screenX, int screenY, int pointer, int button) { + return false; + } + + @Override + public boolean touchDragged(int screenX, int screenY, int pointer) { + return false; + } + + @Override + public boolean mouseMoved(int screenX, int screenY) { + return false; + } + + @Override + public boolean scrolled(int amount) { + return false; + } + +} diff --git a/core/src/ru/deadsoftware/cavecraft/Renderer.java b/core/src/ru/deadsoftware/cavecraft/Renderer.java new file mode 100644 index 0000000..635af85 --- /dev/null +++ b/core/src/ru/deadsoftware/cavecraft/Renderer.java @@ -0,0 +1,33 @@ +package ru.deadsoftware.cavecraft; + +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +public abstract class Renderer { + + public OrthographicCamera camera; + public ShapeRenderer shapeRenderer; + public SpriteBatch spriteBatch; + + public Renderer() { + } + + public Renderer(float width, float height) { + camera = new OrthographicCamera(); + shapeRenderer = new ShapeRenderer(); + spriteBatch = new SpriteBatch(); + camera.setToOrtho(true, width, height); + shapeRenderer.setProjectionMatrix(camera.combined); + spriteBatch.setProjectionMatrix(camera.combined); + } + + public float getWidth() { + return camera.viewportWidth; + } + + public float getHeight() {return camera.viewportHeight;} + + public abstract void render(); + +} diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java similarity index 98% rename from core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java rename to core/src/ru/deadsoftware/cavecraft/game/GameInput.java index dc19afd..3e72368 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java @@ -5,11 +5,11 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.utils.TimeUtils; import ru.deadsoftware.cavecraft.*; -public class GameInputHandler { +public class GameInput { private GameProc gameProc; - public GameInputHandler(GameProc gameProc) { + public GameInput(GameProc gameProc) { this.gameProc = gameProc; } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 009d9b7..e64ed13 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -6,20 +6,16 @@ import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector2; -import ru.deadsoftware.cavecraft.Assets; -import ru.deadsoftware.cavecraft.CaveGame; -import ru.deadsoftware.cavecraft.GameScreen; -import ru.deadsoftware.cavecraft.Items; +import ru.deadsoftware.cavecraft.*; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.objects.Player; -public class GameRenderer { +public class GameRenderer extends Renderer{ private GameProc gameProc; - public OrthographicCamera camera, fontCam; - ShapeRenderer shapeRenderer; - SpriteBatch spriteBatch, fontBatch; + public OrthographicCamera fontCam; + SpriteBatch fontBatch; public GameRenderer(GameProc gameProc) { Gdx.gl.glClearColor(0f,.6f,.6f,1f); @@ -199,6 +195,7 @@ public class GameRenderer { drawGUI(); } + @Override public void render() { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); diff --git a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java new file mode 100644 index 0000000..0f8011d --- /dev/null +++ b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java @@ -0,0 +1,23 @@ +package ru.deadsoftware.cavecraft.menu; + +import ru.deadsoftware.cavecraft.Assets; +import ru.deadsoftware.cavecraft.GameScreen; +import ru.deadsoftware.cavecraft.Items; +import ru.deadsoftware.cavecraft.Renderer; + +public class MenuRenderer extends Renderer { + + public MenuRenderer() { + super(480,480*((float) GameScreen.getHeight()/GameScreen.getWidth())); + } + + @Override + public void render() { + spriteBatch.begin(); + for (int x=0; x<=getWidth(); x++) + for (int y=0; y<=getHeight(); y++) + spriteBatch.draw(Items.BLOCKS.get("dirt").getTexture(),x*16,y*16); + spriteBatch.draw(Assets.gameLogo, getWidth()/2-Assets.gameLogo.getWidth()/2, 0); + spriteBatch.end(); + } +}