DEADSOFTWARE

Add menu screen and game logo
authorfred-boy <fred-boy@protonmail.com>
Sat, 21 Apr 2018 19:47:38 +0000 (02:47 +0700)
committerfred-boy <fred-boy@protonmail.com>
Sat, 21 Apr 2018 20:04:28 +0000 (03:04 +0700)
12 files changed:
android/assets/gamelogo.png [new file with mode: 0644]
android/assets/gamelogo_s.png [new file with mode: 0644]
core/src/ru/deadsoftware/cavecraft/Assets.java
core/src/ru/deadsoftware/cavecraft/CaveGame.java
core/src/ru/deadsoftware/cavecraft/GameScreen.java
core/src/ru/deadsoftware/cavecraft/GameState.java
core/src/ru/deadsoftware/cavecraft/InputHandlerGame.java [moved from core/src/ru/deadsoftware/cavecraft/InputHandler.java with 95% similarity]
core/src/ru/deadsoftware/cavecraft/InputHandlerMenu.java [new file with mode: 0644]
core/src/ru/deadsoftware/cavecraft/Renderer.java [new file with mode: 0644]
core/src/ru/deadsoftware/cavecraft/game/GameInput.java [moved from core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java with 98% similarity]
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java [new file with mode: 0644]

diff --git a/android/assets/gamelogo.png b/android/assets/gamelogo.png
new file mode 100644 (file)
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 (file)
index 0000000..e91b200
Binary files /dev/null and b/android/assets/gamelogo_s.png differ
index acdebdffafdba033f4d3f887fcf8f8ec62a9a097..427ebc66bf2efc23ea32812d36e0bb0e6a4396b2 100644 (file)
@@ -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();
index 99e4f689c11bccede1c6702cb9d6e789a0080e5f..6ef042799292bf0973a0ebcc530633817c88de43 100644 (file)
@@ -16,7 +16,7 @@ public class CaveGame extends Game {
 
        public CaveGame(boolean touch) {
                TOUCH = touch;
-               STATE = GameState.GAME_PLAY;
+               STATE = GameState.MENU_MAIN;
        }
 
        @Override
index 2a2c262a6f4fe3cb0a36feb45f33f996080cc091..6daa039bdb5043143300029941094c1b18a10ff5 100644 (file)
@@ -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
index dd6b021ee1894055516d61e78db7a7190e5e3fde..d8be71ab9655859791276a47bf2cf1665efd5547 100644 (file)
@@ -2,6 +2,7 @@ package ru.deadsoftware.cavecraft;
 
 public enum GameState {
     RESTART,
+    MENU_MAIN,
     GAME_PLAY,
     GAME_CREATIVE_INV
 }
similarity index 95%
rename from core/src/ru/deadsoftware/cavecraft/InputHandler.java
rename to core/src/ru/deadsoftware/cavecraft/InputHandlerGame.java
index da3e9e43d9be2deaf71a0454ae92f0a92d288519..e22caec183bf6c522cc31db12a2a97739b1e889d 100644 (file)
@@ -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 (file)
index 0000000..fe3cb4d
--- /dev/null
@@ -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 (file)
index 0000000..635af85
--- /dev/null
@@ -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();
+
+}
similarity index 98%
rename from core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java
rename to core/src/ru/deadsoftware/cavecraft/game/GameInput.java
index dc19afdb0f42a6bd207fe3fc04956f274e85fb54..3e72368c319ef927efe0492d639a38d86b5d35ba 100644 (file)
@@ -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;
     }
 
index 009d9b75765768e7a793daec3228a0230f7a4d09..e64ed135335265ce1d48948e10af7c1c0e7cac11 100644 (file)
@@ -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 (file)
index 0000000..0f8011d
--- /dev/null
@@ -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();
+    }
+}