summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a6ec412)
raw | patch | inline | side by side (parent: a6ec412)
author | fred-boy <fred-boy@protonmail.com> | |
Fri, 6 Apr 2018 11:07:28 +0000 (18:07 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Fri, 6 Apr 2018 11:07:28 +0000 (18:07 +0700) |
diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java
--- /dev/null
@@ -0,0 +1,21 @@
+package ru.deadsoftware.cavecraft;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+
+public class Assets {
+
+ public static Texture charTexture;
+ public static Sprite[] playerSprite = new Sprite[2];
+
+ 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);
+ }
+
+}
diff --git a/core/src/ru/deadsoftware/cavecraft/GameScreen.java b/core/src/ru/deadsoftware/cavecraft/GameScreen.java
index 451f2a2e241520d25e193263083e783b00fb6a86..9ad88f6eb4517c61f7c437ce202a6e5c49158d9c 100644 (file)
private GameInputHandler gameInput;
public GameScreen() {
+ Assets.load();
gameProc = new GameProc();
gameInput = new GameInputHandler(gameProc);
-
Gdx.input.setInputProcessor(new InputHandler());
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java
index c3aa564c9b25c0ad45c104eaa6e0effe537db918..26b4b6acdc9bfba26fd494d123ef7929c0ffcab2 100644 (file)
gameProc.player.moveX.add(GamePhysics.PL_SPEED,0);
gameProc.player.dir = 1;
}
- if (keyCode == Input.Keys.UP) gameProc.player.moveY.add(0,-12);
+ if (keyCode == Input.Keys.UP &&
+ gameProc.player.canJump) gameProc.player.moveY.add(0,-8);
}
public void keyUp(int keyCode) {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
index 1ed455b75ce04cd450e7c6c5b407dfe31b205b8b..631e9d128c4c8b8a55ceab3cd033f8f55a5e16ac 100644 (file)
package ru.deadsoftware.cavecraft.game;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavecraft.game.objects.Player;
public GamePhysics(GameProc gameProc) {
this.gameProc = gameProc;
- gravity = new Vector2(0,2);
+ gravity = new Vector2(0,1);
}
private boolean checkColl(Rectangle rect) {
int[] bl = new int [6];
- bl[0] = gameProc.world.getForeMap(((int)rect.x/16), ((int)rect.y/16));
- bl[1] = gameProc.world.getForeMap(((int)(rect.x+rect.width-1)/16), ((int)rect.y/16));
- bl[2] = gameProc.world.getForeMap(((int)rect.x/16), ((int)(rect.y+rect.height/2)/16));
- bl[3] = gameProc.world.getForeMap(((int)(rect.x+rect.width-1)/16), ((int)(rect.y+rect.height/2)/16));
- bl[4] = gameProc.world.getForeMap(((int)rect.x/16), ((int)(rect.y+rect.height-1)/16));
- bl[5] = gameProc.world.getForeMap(((int)(rect.x+rect.width-1)/16), ((int)(rect.y+(rect.height-1))/16));
+ bl[0] = gameProc.world.getForeMap(((int)(rect.x+2)/16), ((int)rect.y/16));
+ bl[1] = gameProc.world.getForeMap(((int)(rect.x+rect.width-2)/16), ((int)rect.y/16));
+ bl[2] = gameProc.world.getForeMap(((int)(rect.x+2)/16), ((int)(rect.y+rect.height/2)/16));
+ bl[3] = gameProc.world.getForeMap(((int)(rect.x+rect.width-2)/16), ((int)(rect.y+rect.height/2)/16));
+ bl[4] = gameProc.world.getForeMap(((int)(rect.x+2)/16), ((int)(rect.y+rect.height-1)/16));
+ bl[5] = gameProc.world.getForeMap(((int)(rect.x+rect.width-2)/16), ((int)(rect.y+(rect.height-1))/16));
for (int b: bl) if (b>0) {
return true;
}
private void movePlayer(Player pl) {
pl.position.add(pl.moveX);
+ if (pl.position.x<0 ||
+ pl.position.x+pl.width>gameProc.world.getWidth()*16)
+ pl.position.sub(pl.moveX);
if (checkColl(pl.getRect())) {
int d = 0;
if (pl.moveX.x<0) d=1; else if (pl.moveX.x>0) d=-1;
+ pl.position.x = MathUtils.round(pl.position.x);
while (checkColl(pl.getRect())) pl.position.x+=d;
- //pl.moveX.setZero();
}
pl.position.add(pl.moveY);
if (checkColl(pl.getRect())) {
- int d = 0;
+ pl.canJump = true;
+ float d = 0;
if (pl.moveY.y<0) d=1; else if (pl.moveY.y>0) d=-1;
+ pl.position.y = MathUtils.round(pl.position.y);
while (checkColl(pl.getRect())) pl.position.y+=d;
pl.moveY.setZero();
+ } else {
+ pl.canJump = false;
}
pl.moveY.add(gravity);
switch (pl.dir) {
gameProc.renderer.camTargetPos.x = pl.position.x-100;
break;
}
+ if (gameProc.renderer.camTargetPos.x < 0) gameProc.renderer.camTargetPos.x = 0;
+ if (gameProc.renderer.camTargetPos.x + gameProc.renderer.camera.viewportWidth >
+ gameProc.world.getWidth()*16)
+ gameProc.renderer.camTargetPos.x = gameProc.world.getWidth()*16-gameProc.renderer.camera.viewportWidth;
}
public void update(float delta) {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index 563f095203bd418c6822cb9039b907a70c48318d..b93de89b8d756f9e42470882954f262fa0a03e2d 100644 (file)
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
+import ru.deadsoftware.cavecraft.Assets;
import ru.deadsoftware.cavecraft.GameScreen;
import ru.deadsoftware.cavecraft.game.objects.Player;
public Vector3 camTargetPos;
public OrthographicCamera camera;
ShapeRenderer shapeRenderer;
+ SpriteBatch spriteBatch;
public GameRenderer(GameProc gameProc) {
Gdx.gl.glClearColor(0f,.6f,.6f,1f);
this.gameProc = gameProc;
camera = new OrthographicCamera();
- camera.setToOrtho(true, 320,
- 320*((float)GameScreen.getHeight()/GameScreen.getWidth()));
+ camera.setToOrtho(true, 360,
+ 360*((float)GameScreen.getHeight()/GameScreen.getWidth()));
camera.position.x=0;
camera.position.y=0;
camTargetPos = camera.position.cpy();
shapeRenderer = new ShapeRenderer();
shapeRenderer.setProjectionMatrix(camera.combined);
shapeRenderer.setAutoShapeType(true);
+ spriteBatch = new SpriteBatch();
+ spriteBatch.setProjectionMatrix(camera.combined);
}
private void setColor(int r, int g, int b) {
int maxY = (int) ((camera.position.y+camera.viewportHeight)/16)+1;
if (minX<0) minX=0;
if (minY<0) minY=0;
- if (maxX>=gameProc.world.getWidth()) maxX = gameProc.world.getWidth()-1;
- if (maxY>=gameProc.world.getHeight()) maxY = gameProc.world.getHeight()-1;
+ if (maxX>gameProc.world.getWidth()) maxX = gameProc.world.getWidth();
+ if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight();
for (int y=minY; y<maxY; y++) {
for (int x=minX; x<maxX; x++) {
if (gameProc.world.getForeMap(x,y)>0) {
}
private void drawPlayer(Player pl) {
- setColor(0,128,0);
- fillRect(pl.position.x - camera.position.x,
- pl.position.y - camera.position.y, pl.width, pl.height);
+ spriteBatch.begin();
+ Assets.playerSprite[pl.dir].setPosition(pl.position.x - camera.position.x,
+ pl.position.y - camera.position.y);
+ Assets.playerSprite[pl.dir].draw(spriteBatch);
+ spriteBatch.end();
}
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
shapeRenderer.begin();
drawWorld();
- drawPlayer(gameProc.player);
shapeRenderer.end();
+ drawPlayer(gameProc.player);
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java
index c63e0595449265aba12da75e3cf947424ddbd167..0c5581a7ee2711999f526e52bbc77cafa4385a2e 100644 (file)
public Vector2 position;
public Vector2 moveX, moveY;
public int width, height, dir;
+ public boolean canJump;
public Player() {
position = new Vector2(0, 0);
diff --git a/desktop/src/ru/deadsoftware/cavecraft/desktop/DesktopLauncher.java b/desktop/src/ru/deadsoftware/cavecraft/desktop/DesktopLauncher.java
index 8afb2b9f50ee6f8cae9650d105146b1b324ed53a..2f0d7b020ac0c6da2679d44251655adb0c13a5c6 100644 (file)
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
+ config.foregroundFPS = 60;
+ config.title = "CaveCraft";
+ config.width = 960;
+ config.height = 720;
new LwjglApplication(new CaveGame(), config);
}
}