summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a7ae39b)
raw | patch | inline | side by side (parent: a7ae39b)
author | fred-boy <fred-boy@protonmail.com> | |
Thu, 12 Apr 2018 17:00:14 +0000 (00:00 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Thu, 12 Apr 2018 17:00:14 +0000 (00:00 +0700) |
diff --git a/android/assets/allitems.png b/android/assets/allitems.png
new file mode 100644 (file)
index 0000000..e1e5d77
Binary files /dev/null and b/android/assets/allitems.png differ
index 0000000..e1e5d77
Binary files /dev/null and b/android/assets/allitems.png differ
diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java
index 6a99f1d3a60a34fab05ad670b5caf81418193115..e1fd5c94a1c44923c39ad4fb0ff97462453ad1d4 100644 (file)
public static TextureRegion invBar;
public static TextureRegion invCur;
+ public static Texture creativeTexture;
+ public static TextureRegion creativeInv;
+ public static TextureRegion creativeScroll;
+
public static Texture touchGui;
public static TextureRegion[] touchArrows = new TextureRegion[4];
public static TextureRegion touchLMB, touchRMB;
invBar = new TextureRegion(gui,0,0,182,22);
invCur = new TextureRegion(gui,0,22,24,24);
+ creativeTexture = new Texture(Gdx.files.internal("allitems.png"));
+ creativeInv = new TextureRegion(creativeTexture, 0, 0, 176, 208);
+ creativeInv.flip(false,true);
+ creativeScroll = new TextureRegion(creativeTexture, 2, 209, 12, 15);
+ creativeScroll.flip(false, true);
+
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);
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java
index 0b714ddd43eda90fa210a60108f592d79ece325e..c288afface0331516b5feb2969414f3fecfd1c46 100644 (file)
package ru.deadsoftware.cavecraft.game;
+import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.utils.TimeUtils;
+import ru.deadsoftware.cavecraft.Assets;
import ru.deadsoftware.cavecraft.GameScreen;
+import ru.deadsoftware.cavecraft.Items;
public class GameInputHandler {
if (gameProc.ctrlMode > 1) gameProc.ctrlMode = 0;
}
if (keyCode == Input.Keys.SPACE) {
- if (gameProc.player.canJump) {
- gameProc.player.moveY.add(0, -7);
- } else if (!gameProc.player.flyMode) {
- gameProc.player.flyMode = true;
- gameProc.player.moveY.setZero();
- } else {
- gameProc.player.moveY.y = -GamePhysics.PL_SPEED;
- }
+ if (gameProc.player.canJump) {
+ gameProc.player.moveY.add(0, -7);
+ } else if (!gameProc.player.flyMode) {
+ gameProc.player.flyMode = true;
+ gameProc.player.moveY.setZero();
+ } else {
+ gameProc.player.moveY.y = -GamePhysics.PL_SPEED;
+ }
}
if (keyCode == Input.Keys.CONTROL_LEFT) {
gameProc.player.moveY.y = GamePhysics.PL_SPEED;
}
+ if (keyCode == Input.Keys.E) {
+ gameProc.renderer.showCreative = !gameProc.renderer.showCreative;
+ }
}
public void keyUp(int keyCode) {
gameProc.touchDownY = screenY;
gameProc.touchDownTime = TimeUtils.millis();
gameProc.isTouchDown = true;
+ if (gameProc.renderer.showCreative) {
+ try {
+ int ix = (int)(screenX-(gameProc.renderer.camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2+8))/18;
+ int iy = (int)(screenY-(gameProc.renderer.camera.viewportHeight/2 - Assets.creativeInv.getRegionHeight()/2+18))/18;
+ int item = ix+iy*8;
+ for (int i=8; i>0; i--) {
+ gameProc.player.inventory[i] = gameProc.player.inventory[i-1];
+ }
+ if (item>=0 && item<Items.BLOCKS.size) gameProc.player.inventory[0] = item;
+ } catch (Exception e) {
+ Gdx.app.error("GameInputHandler", e.toString());
+ }
+ }
}
public void touchUp(int screenX, int screenY, int button) {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index 9183c677e3ee90c1c7ba09d52ff5abd2efcd69c3..00508b2b74e153bdeb219000c0bb5c9cc99b6274 100644 (file)
private GameProc gameProc;
+ public boolean showCreative = false;
+
public OrthographicCamera camera, fontCam;
ShapeRenderer shapeRenderer;
SpriteBatch spriteBatch, fontBatch;
Gdx.gl.glClearColor(0f,.6f,.6f,1f);
this.gameProc = gameProc;
camera = new OrthographicCamera();
- camera.setToOrtho(true, 360,
- 360*((float)GameScreen.getHeight()/GameScreen.getWidth()));
+ camera.setToOrtho(true, 480,
+ 480*((float)GameScreen.getHeight()/GameScreen.getWidth()));
shapeRenderer = new ShapeRenderer();
shapeRenderer.setProjectionMatrix(camera.combined);
Assets.playerSkin[0][2].draw(spriteBatch);
}
+ private void drawCreative() {
+ float x = camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2;
+ float y = camera.viewportHeight/2 - Assets.creativeInv.getRegionHeight()/2;
+ spriteBatch.draw(Assets.creativeInv, x, y);
+ spriteBatch.draw(Assets.creativeScroll, x+156, y+18);
+ for (int i=1; i<Items.BLOCKS.size; i++) {
+ spriteBatch.draw(Items.BLOCKS.getValueAt(i).getTexture(),x+8+(i%8)*18,
+ y+18+(i/8)*18);
+ }
+ for (int i=0; i<9; i++) {
+ if (gameProc.player.inventory[i]>0)
+ spriteBatch.draw(Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture(),
+ x+8+i*18, y+184);
+ }
+ }
+
private void drawGUI() {
spriteBatch.draw(Assets.invBar, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2, 0);
for (int i=0; i<9; i++) {
camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2 - 1 + 20*gameProc.invSlot,
-1);
+ if (showCreative) drawCreative();
+
if (CaveGame.TOUCH) {
spriteBatch.draw(Assets.touchArrows[0],26,camera.viewportHeight-52);
spriteBatch.draw(Assets.touchArrows[1],0,camera.viewportHeight-26);