summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 472a754)
raw | patch | inline | side by side (parent: 472a754)
author | fred-boy <fred-boy@protonmail.com> | |
Sat, 7 Apr 2018 14:13:43 +0000 (21:13 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Sat, 7 Apr 2018 14:13:43 +0000 (21:13 +0700) |
diff --git a/android/assets/touch_gui.png b/android/assets/touch_gui.png
new file mode 100644 (file)
index 0000000..b194413
Binary files /dev/null and b/android/assets/touch_gui.png differ
index 0000000..b194413
Binary files /dev/null and b/android/assets/touch_gui.png differ
diff --git a/android/src/ru/deadsoftware/cavecraft/AndroidLauncher.java b/android/src/ru/deadsoftware/cavecraft/AndroidLauncher.java
index f97468fcd48f193f0a6c18eafba957c52c811b80..aac1e66e1c51cc7e88c39c81bc7ee8f72a81da6b 100644 (file)
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
- initialize(new CaveGame(), config);
+ initialize(new CaveGame(true), config);
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java
index 45634ebfa449f2ed7fd4ec1357570d6f3e3d9562..96dbbdc328e46d8c69ddcdd70493b25fd7440389 100644 (file)
public static final int BLOCK_TEXTURES = 3;
public static Texture charTexture;
- public static Sprite[] playerSprite = new Sprite[2];
+ public static TextureRegion[] playerSkin = new TextureRegion[2];
public static Sprite shade;
public static TextureRegion invBar;
public static TextureRegion invCur;
+ public static Texture touchGui;
+ public static TextureRegion[] touchArrows = new TextureRegion[4];
+ public static TextureRegion touchLMB, touchRMB;
+ public static TextureRegion touchToggleMode;
+ public static TextureRegion touchSpace;
+
public static void load() {
charTexture = new Texture(Gdx.files.internal("char.png"));
- playerSprite[0] = new Sprite(new TextureRegion(charTexture, 0,0,8,30));
- playerSprite[0].flip(false,true);
- playerSprite[1] = new Sprite(new TextureRegion(charTexture, 8,0,8,30));
- playerSprite[1].flip(false,true);
+ playerSkin[0] = new TextureRegion(charTexture, 0,0,8,30);
+ playerSkin[0].flip(false,true);
+ playerSkin[1] = new TextureRegion(charTexture, 8,0,8,30);
+ playerSkin[1].flip(false,true);
shade = new Sprite(new Texture(Gdx.files.internal("shade.png")));
invBar = new TextureRegion(gui,0,0,182,22);
invCur = new TextureRegion(gui,0,22,24,24);
+ touchGui = new Texture(Gdx.files.internal("touch_gui.png"));
+ for (int i=0; i<4; i++) {
+ touchArrows[i] = new TextureRegion(touchGui, i*26, 0, 26,26);
+ touchArrows[i].flip(false, true);
+ }
+ touchLMB = new TextureRegion(touchGui, 0, 26, 26,26);
+ touchLMB.flip(false, true);
+ touchRMB = new TextureRegion(touchGui, 52, 26, 26,26);
+ touchRMB.flip(false, true);
+ touchToggleMode = new TextureRegion(touchGui, 26, 26, 26, 26);
+ touchToggleMode.flip(false, true);
+ touchSpace = new TextureRegion(touchGui, 0, 52, 104, 26);
+ touchSpace.flip(false, true);
+
terrain = new Texture(Gdx.files.internal("terrain.png"));
for (int i=0; i<BLOCK_TEXTURES; i++) {
blockTextures[i] = new TextureRegion(terrain,
diff --git a/core/src/ru/deadsoftware/cavecraft/CaveGame.java b/core/src/ru/deadsoftware/cavecraft/CaveGame.java
index 447a91e60281b4845e03f8bdf36a80ba245b6e9c..65d332c0054e26aec32968b9fede49913be17990 100644 (file)
public class CaveGame extends Game {
+ public static boolean TOUCH;
+
+ public CaveGame() {
+ this(true);
+ }
+
+ public CaveGame(boolean touch) {
+ TOUCH = touch;
+ }
+
@Override
public void create () {
setScreen(new GameScreen());
}
-}
\ No newline at end of file
+}
diff --git a/core/src/ru/deadsoftware/cavecraft/GameScreen.java b/core/src/ru/deadsoftware/cavecraft/GameScreen.java
index 30382a83cf63183f947658bd251f5fce656fc9a0..3301805e5854acafb14a33263b1e32ec447167b6 100644 (file)
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;
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
screenX *= gameProc.renderer.camera.viewportWidth/getWidth();
screenY *= gameProc.renderer.camera.viewportHeight/getHeight();
- gameInput.touchDown(screenX, screenY, button);
+ if (CaveGame.TOUCH) {
+ if (screenX > 26 && screenX < 52 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 52 &&
+ screenY < gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.keyDown(Input.Keys.W);
+ } else if (screenX > 0 && screenX < 26 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.keyDown(Input.Keys.A);
+ } else if (screenX > 26 && screenX < 52 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.keyDown(Input.Keys.S);
+ } else if (screenX > 52 && screenX < 78 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.keyDown(Input.Keys.D);
+ } else if (screenX > 78 && screenX < 104 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.keyDown(Input.Keys.ALT_LEFT);
+ } else if (screenX > gameProc.renderer.camera.viewportWidth - 52 &&
+ screenX < gameProc.renderer.camera.viewportWidth - 26 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.touchDown(screenX, screenY, Input.Buttons.LEFT);
+ } else if (screenX > gameProc.renderer.camera.viewportWidth - 26 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.touchDown(screenX, screenY, Input.Buttons.RIGHT);
+ } else if (screenX > gameProc.renderer.camera.viewportWidth / 2 - 52 &&
+ screenX < gameProc.renderer.camera.viewportWidth / 2 + 52 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.keyDown(Input.Keys.SPACE);
+ }
+ } else {
+ gameInput.touchDown(screenX, screenY, button);
+ }
return false;
}
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
screenX *= gameProc.renderer.camera.viewportWidth/getWidth();
screenY *= gameProc.renderer.camera.viewportHeight/getHeight();
- gameInput.touchUp(screenX, screenY, button);
+ if (CaveGame.TOUCH) {
+ if (screenX>26 && screenX<52 &&
+ screenY>gameProc.renderer.camera.viewportHeight-52 &&
+ screenY<gameProc.renderer.camera.viewportHeight-26) {
+ gameInput.keyUp(Input.Keys.W);
+ } else if (screenX>0 && screenX<26 &&
+ screenY>gameProc.renderer.camera.viewportHeight-26) {
+ gameInput.keyUp(Input.Keys.A);
+ } else if (screenX>26 && screenX<52 &&
+ screenY>gameProc.renderer.camera.viewportHeight-26) {
+ gameInput.keyUp(Input.Keys.S);
+ } else if (screenX>52 && screenX<78 &&
+ screenY>gameProc.renderer.camera.viewportHeight-26) {
+ gameInput.keyUp(Input.Keys.D);
+ } else if (screenX > 78 && screenX < 104 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.keyUp(Input.Keys.ALT_LEFT);
+ } else if (screenX > gameProc.renderer.camera.viewportWidth - 52 &&
+ screenX < gameProc.renderer.camera.viewportWidth - 26 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.touchUp(screenX, screenY, Input.Buttons.LEFT);
+ } else if (screenX > gameProc.renderer.camera.viewportWidth - 26 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.touchUp(screenX, screenY, Input.Buttons.RIGHT);
+ } else if (screenX > gameProc.renderer.camera.viewportWidth / 2 - 52 &&
+ screenX < gameProc.renderer.camera.viewportWidth / 2 + 52 &&
+ screenY > gameProc.renderer.camera.viewportHeight - 26) {
+ gameInput.keyUp(Input.Keys.SPACE);
+ }
+ } else {
+ gameInput.touchUp(screenX, screenY, button);
+ }
return false;
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java
index 899fbba6f06578dd4ca66ec47162e596cdc3a231..313675d414b6788dfa8b1ca935677f87dd0cbd87 100644 (file)
}
public void keyDown(int keyCode) {
- if (keyCode == Input.Keys.A) {
- gameProc.player.moveX.add(-GamePhysics.PL_SPEED,0);
- gameProc.player.dir = 0;
+ if (gameProc.ctrlMode==0) {
+ if (keyCode == Input.Keys.A) {
+ gameProc.player.moveX.add(-GamePhysics.PL_SPEED, 0);
+ gameProc.player.dir = 0;
+ }
+ if (keyCode == Input.Keys.D) {
+ gameProc.player.moveX.add(GamePhysics.PL_SPEED, 0);
+ gameProc.player.dir = 1;
+ }
+ } else {
+ if (keyCode == Input.Keys.A) {
+ gameProc.cursorX--;
+ }
+ if (keyCode == Input.Keys.D) {
+ gameProc.cursorX++;
+ }
+ if (keyCode == Input.Keys.W) {
+ gameProc.cursorY--;
+ }
+ if (keyCode == Input.Keys.S) {
+ gameProc.cursorY++;
+ }
+ if (gameProc.cursorX < 0)
+ gameProc.cursorX = 0;
+ if (gameProc.cursorX >= gameProc.world.getWidth())
+ gameProc.cursorX = gameProc.world.getWidth()-1;
+ if (gameProc.cursorY < 0)
+ gameProc.cursorY = 0;
+ if (gameProc.cursorY >= gameProc.world.getHeight())
+ gameProc.cursorY = gameProc.world.getHeight()-1;
}
- if (keyCode == Input.Keys.D) {
- gameProc.player.moveX.add(GamePhysics.PL_SPEED,0);
- gameProc.player.dir = 1;
+ if (keyCode == Input.Keys.ALT_LEFT) {
+ gameProc.ctrlMode++;
+ gameProc.cursorX = (int)(gameProc.player.position.x/16);
+ gameProc.cursorY = (int)(gameProc.player.position.y/16);
+ if (gameProc.ctrlMode > 1) gameProc.ctrlMode = 0;
}
- if (keyCode == Input.Keys.SPACE &&
- gameProc.player.canJump) gameProc.player.moveY.add(0,-8);
+ if (keyCode == Input.Keys.SPACE &&
+ gameProc.player.canJump) gameProc.player.moveY.add(0, -8);
}
public void keyUp(int keyCode) {
}
public void mouseMoved(int screenX, int screenY) {
- gameProc.cursorX = (int)((screenX+gameProc.renderer.camera.position.x)/16);
- gameProc.cursorY = (int)((screenY+gameProc.renderer.camera.position.y)/16);
- if (gameProc.cursorX < 0)
- gameProc.cursorX = 0;
- if (gameProc.cursorX >= gameProc.world.getWidth())
- gameProc.cursorX = gameProc.world.getWidth()-1;
- if (gameProc.cursorY < 0)
- gameProc.cursorY = 0;
- if (gameProc.cursorY >= gameProc.world.getHeight())
- gameProc.cursorY = gameProc.world.getHeight()-1;
-
}
public void touchDown(int screenX, int screenY, int button) {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java
index cf70144d75948eeac988b7c517b12a8247d11d0a..6fc7dd956592fd37fe372bf8ef4e177de3ca77db 100644 (file)
public int cursorX, cursorY;
public int invSlot;
+ public int ctrlMode;
public boolean isTouchDown = false;
public int touchDownX, touchDownY;
public long touchDownTime;
public GameProc() {
- world = new GameWorld(512,32);
+ world = new GameWorld(512,256);
renderer = new GameRenderer(this);
physics = new GamePhysics(this);
player = new Player();
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index 3c6d7b38b7aa26b3ee4ec750220c0c1862867b9c..4ab0704af7a016e18dc63956affbe4bd5c4f279b 100644 (file)
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector3;
import ru.deadsoftware.cavecraft.Assets;
+import ru.deadsoftware.cavecraft.CaveGame;
import ru.deadsoftware.cavecraft.Items;
import ru.deadsoftware.cavecraft.GameScreen;
import ru.deadsoftware.cavecraft.game.objects.Player;
spriteBatch.setProjectionMatrix(camera.combined);
}
- private void setColor(int r, int g, int b) {
- shapeRenderer.setColor(r/255f, g/255f, b/255f, 1f);
- }
-
- private void fillRect(float x, float y, float w, float h) {
- shapeRenderer.set(ShapeRenderer.ShapeType.Filled);
- shapeRenderer.rect(x,y,w,h);
- }
-
- private void drawRect(float x, float y, float w, float h) {
- shapeRenderer.set(ShapeRenderer.ShapeType.Line);
- shapeRenderer.rect(x,y,w,h);
- }
-
private void drawWorld() {
int minX = (int) (camera.position.x/16);
int minY = (int) (camera.position.y/16);
}
private void drawPlayer(Player pl) {
- Assets.playerSprite[pl.dir].setPosition(pl.position.x - camera.position.x,
- pl.position.y - camera.position.y);
- Assets.playerSprite[pl.dir].draw(spriteBatch);
+ spriteBatch.draw(Assets.playerSkin[pl.dir],
+ pl.position.x - camera.position.x, pl.position.y - camera.position.y);
}
private void drawGUI() {
spriteBatch.draw(Assets.invBar, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2,
- camera.viewportHeight - Assets.invBar.getRegionHeight());
+ 0);//camera.viewportHeight - Assets.invBar.getRegionHeight());
for (int i=0; i<8; i++) {
if (gameProc.player.inventory[i]>0) {
spriteBatch.draw(Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture(),
camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2+3+i*20,
- camera.viewportHeight-19);
+ 3);
}
}
spriteBatch.draw(Assets.invCur,
camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2 - 1 + 20*gameProc.invSlot,
- camera.viewportHeight - Assets.invBar.getRegionHeight() - 2);
+ -1);
+
+ if (CaveGame.TOUCH) {
+ spriteBatch.draw(Assets.touchArrows[0],26,camera.viewportHeight-52);
+ spriteBatch.draw(Assets.touchArrows[1],0,camera.viewportHeight-26);
+ spriteBatch.draw(Assets.touchArrows[2],26,camera.viewportHeight-26);
+ spriteBatch.draw(Assets.touchArrows[3],52,camera.viewportHeight-26);
+ spriteBatch.draw(Assets.touchSpace, camera.viewportWidth/2-52, camera.viewportHeight-26);
+ spriteBatch.draw(Assets.touchLMB, camera.viewportWidth-52, camera.viewportHeight-26);
+ spriteBatch.draw(Assets.touchRMB, camera.viewportWidth-26, camera.viewportHeight-26);
+ spriteBatch.draw(Assets.touchToggleMode, 78, camera.viewportHeight-26);
+ if (gameProc.ctrlMode==1) {
+ Assets.shade.setPosition(83, camera.viewportHeight-21);
+ Assets.shade.draw(spriteBatch);
+ }
+ }
}
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+
spriteBatch.begin();
drawWorld();
drawPlayer(gameProc.player);
drawGUI();
spriteBatch.end();
- shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
- shapeRenderer.setColor(Color.ORANGE);
- drawRect(gameProc.cursorX*16-camera.position.x,
- gameProc.cursorY*16-camera.position.y,16,16);
- shapeRenderer.end();
+ if (gameProc.ctrlMode==1) {
+ shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
+ shapeRenderer.setColor(Color.ORANGE);
+ shapeRenderer.set(ShapeRenderer.ShapeType.Line);
+ shapeRenderer.rect(gameProc.cursorX * 16 - camera.position.x,
+ gameProc.cursorY * 16 - camera.position.y, 16, 16);
+ shapeRenderer.end();
+ }
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java
index 84f0ae1b7591fe64d52368e6f3bc9019223186c9..9f6e693886a11db7386bebeb2b9a3f7f4ced59dc 100644 (file)
public class WorldGen {
private static int[][] foreMap, backMap;
- private static int[] noise;
+ private static int[] hMap;
- static int[] genNoise(int width, int mid, int min, int max) {
+ static int[] genLandscape(int width, int mid, int min, int max) {
RandomXS128 rand = new RandomXS128(TimeUtils.millis());
int[] res = new int[width];
int t;
static void genWorld(int width, int height) {
foreMap = new int[width][height];
backMap = new int[width][height];
- noise = genNoise(width, height/2, 1, height);
+ hMap = genLandscape(width, height/2, height/4, height/4*3);
for (int x=0; x<width; x++) {
- for (int y=height-noise[x]; y<height; y++) {
- if (y==height-noise[x]) {
+ for (int y = height- hMap[x]; y<height; y++) {
+ if (y==height- hMap[x]) {
foreMap[x][y] = 3;
backMap[x][y] = 3;
- } else if (y<height-noise[x]+4) {
+ } else if (y<height- hMap[x]+4) {
foreMap[x][y] = 2;
backMap[x][y] = 2;
} else {