X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2FGameProc.java;h=e49a40588fd47641eadeea136b65354a9929d5e9;hb=103459785743a8485af69863d65ad1b1a2410ab0;hp=b955d2309d24cbc6d76158e38811f78e8b9846e6;hpb=40312aaac2ec8bd1247ad5979f7bd1d8e47ecae3;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index b955d23..e49a405 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -1,8 +1,13 @@ package ru.deadsoftware.cavecraft.game; +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.Assets; +import ru.deadsoftware.cavecraft.CaveGame; +import ru.deadsoftware.cavecraft.GameState; +import ru.deadsoftware.cavecraft.Items; import ru.deadsoftware.cavecraft.game.mobs.Human; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.objects.Player; @@ -25,13 +30,14 @@ public class GameProc { public boolean isTouchDown = false; public int touchDownX, touchDownY; + public int touchDownButton; public long touchDownTime; public GameProc() { - world = new GameWorld(4096,256); + world = new GameWorld(1024,256); renderer = new GameRenderer(this); physics = new GamePhysics(this); - player = new Player(world.getWidth()/2*16+4, 0); + player = new Player(world.getSpawnPoint()); mobs = new Array(); } @@ -40,14 +46,57 @@ public class GameProc { renderer = new GameRenderer(this); } + private boolean isAutoselectable(int x, int y) { + return (world.getForeMap(x,y)>0 && + Items.BLOCKS.getValueAt(world.getForeMap(x,y)).collision); + } + + private void moveCursor() { + if (player.canJump) { + 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; + } + } + + 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; + } + public void update(float delta) { RUN_TIME += delta; physics.update(delta); + if (ctrlMode==0) moveCursor(); + checkCursorBounds(); if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) { - world.placeToBackground(cursorX,cursorY, - player.inventory[invSlot]); + if (touchDownButton== Input.Buttons.RIGHT) { + world.placeToBackground(cursorX, cursorY, + player.inventory[invSlot]); + } else if (touchDownButton==Input.Buttons.LEFT && + touchDownY< Assets.invBar.getRegionHeight() && + touchDownX>renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 && + touchDownX