X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2FGameProc.java;h=4fe96c6595274d6e97db4086e3d21ec665034b53;hb=6ab2a53526f16de139d39a59c3d800e5f3013c68;hp=47b3100aa9164e3f5d4cd22060d46deebc0331b1;hpb=c6925c7674b71e9b6fe537aaca3aa7330e04e13f;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index 47b3100..4fe96c6 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -2,46 +2,60 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; -import com.badlogic.gdx.math.RandomXS128; -import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.TimeUtils; import ru.deadsoftware.cavecraft.*; -import ru.deadsoftware.cavecraft.game.mobs.Human; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.objects.Player; -public class GameProc { +import java.io.Serializable; +import java.util.ArrayList; + +public class GameProc implements Serializable{ public static double RUN_TIME = 0; public Player player; - public Array mobs; + public ArrayList mobs; - public GameWorld world; - public GameRenderer renderer; - public GamePhysics physics; + public transient GameWorld world; + public transient GameRenderer renderer; + public transient GamePhysics physics; public int cursorX, cursorY; public int invSlot; public int ctrlMode; - public boolean isTouchDown = false; - public int touchDownX, touchDownY; + public boolean isTouchDown, isKeyDown; + public int touchDownX, touchDownY, keyDownCode; public int touchDownButton; public long touchDownTime; public GameProc() { - world = new GameWorld(1024,256); - renderer = new GameRenderer(this); - physics = new GamePhysics(this); + world = new GameWorld(); + world.generate(8,256); player = new Player(world.getSpawnPoint()); - mobs = new Array(); + mobs = new ArrayList(); + physics = new GamePhysics(this); if (!CaveGame.TOUCH) ctrlMode = 1; + if (CaveGame.TOUCH) { + renderer = new GameRenderer(this,320, + 320*((float)GameScreen.getHeight()/GameScreen.getWidth())); + } else { + renderer = new GameRenderer(this,480, + 480*((float)GameScreen.getHeight()/GameScreen.getWidth())); + } + GameSaver.save(this); } public void resetRenderer() { - renderer = new GameRenderer(this); + if (CaveGame.TOUCH) { + renderer = new GameRenderer(this,320, + 320*((float)GameScreen.getHeight()/GameScreen.getWidth())); + } else { + renderer = new GameRenderer(this,480, + 480*((float)GameScreen.getHeight()/GameScreen.getWidth())); + } } private boolean isAutoselectable(int x, int y) { @@ -50,43 +64,41 @@ public class GameProc { } private void moveCursor() { - if (ctrlMode==0) { - if (player.canJump) { - cursorX = (int) (player.position.x + player.texWidth / 2) / 16; - if (player.dir == 0) cursorX--; + if (ctrlMode == 0 && CaveGame.TOUCH) { + cursorX = (int) (player.position.x + player.texWidth / 2) / 16; + if (player.dir == 0) cursorX--; else cursorX++; - cursorY = (int) (player.position.y + player.texWidth) / 16; - if (!isAutoselectable(cursorX, cursorY)) { - cursorY++; - } - if (!isAutoselectable(cursorX, cursorY)) { - cursorY++; - } - if (!isAutoselectable(cursorX, cursorY)) { - if (player.dir == 0) cursorX++; - else cursorX--; - } - } else { - cursorX = (int) (player.position.x + player.texWidth / 2) / 16; - cursorY = (int) (player.position.y + player.height+8)/16; + cursorY = (int) (player.position.y + player.texWidth) / 16; + if (!isAutoselectable(cursorX, cursorY)) { + cursorY++; + } + if (!isAutoselectable(cursorX, cursorY)) { + cursorY++; + } + if (!isAutoselectable(cursorX, cursorY)) { + if (player.dir == 0) cursorX++; + else cursorX--; } } else if (!CaveGame.TOUCH){ cursorX = (int)(Gdx.input.getX()* (renderer.camera.viewportWidth/GameScreen.getWidth())+renderer.camera.position.x)/16; cursorY = (int)(Gdx.input.getY()* (renderer.camera.viewportHeight/GameScreen.getHeight())+renderer.camera.position.y)/16; + if ((Gdx.input.getX()* + (renderer.camera.viewportWidth/GameScreen.getWidth())+renderer.camera.position.x)<0) + cursorX--; } } private void checkCursorBounds() { - if (cursorX < 0) cursorX = 0; - if (cursorX >= world.getWidth()) cursorX = world.getWidth()-1; if (cursorY < 0) cursorY = 0; if (cursorY >= world.getHeight()) cursorY = world.getHeight()-1; - if (cursorX<(player.position.x+player.texWidth/2)/16) - player.dir=0; - if (cursorX>(player.position.x+player.texWidth/2)/16) - player.dir=1; + if (ctrlMode==1) { + if (cursorX*16+8player.position.x+player.texWidth/2) + player.dir=1; + } } public void update(float delta) { @@ -104,7 +116,7 @@ public class GameProc { touchDownY< Assets.invBar.getRegionHeight() && touchDownX>renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 && touchDownX