summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9764e48)
raw | patch | inline | side by side (parent: 9764e48)
author | fred-boy <fred-boy@protonmail.com> | |
Sat, 24 Nov 2018 20:48:07 +0000 (03:48 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Sat, 24 Nov 2018 20:48:07 +0000 (03:48 +0700) |
Draw background fade with shape renderer (fps boost?)
diff --git a/android/build.gradle b/android/build.gradle
index e917a5fd80b1271395d8917bd4ad6f9f09a91bfd..4beaa6e2dd6650aaf0bac53c0fc489a0c29399fa 100644 (file)
--- a/android/build.gradle
+++ b/android/build.gradle
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
- file("libs/armeabi/").mkdirs();
- file("libs/armeabi-v7a/").mkdirs();
- file("libs/arm64-v8a/").mkdirs();
- file("libs/x86_64/").mkdirs();
- file("libs/x86/").mkdirs();
+ file("libs/armeabi/").mkdirs()
+ file("libs/armeabi-v7a/").mkdirs()
+ file("libs/arm64-v8a/").mkdirs()
+ file("libs/x86_64/").mkdirs()
+ file("libs/x86/").mkdirs()
configurations.natives.files.each { jar ->
def outputDir = null
project {
name = appName + "-android"
natures 'com.android.ide.eclipse.adt.AndroidNature'
- buildCommands.clear();
+ buildCommands.clear()
buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
// sets up the Android Idea project, using the old Ant based build.
idea {
module {
- sourceDirs += file("src");
+ sourceDirs += file("src")
scopes = [COMPILE: [plus: [project.configurations.compile]]]
iml {
withXml {
def node = it.asNode()
- def builder = NodeBuilder.newInstance();
- builder.current = node;
+ def builder = NodeBuilder.newInstance()
+ builder.current = node
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
index 94f6f36d9dd6aa37e0b4ffc4a4f2caf7d3d338e2..88791dc67a59d337235c8a79d55c9080cb117c04 100644 (file)
private boolean checkJump(Rectangle rect, int dir) {
int bl;
- switch (dir) {
- case 0:
- bl = gp.world.getForeMap((int) ((rect.x - 8) / 16), (int) ((rect.y + rect.height - 8) / 16));
- if (checkColl(new Rectangle(rect.x - 8, rect.y - 18, rect.width, rect.height))) bl = 0;
- break;
- case 1:
- bl = gp.world.getForeMap((int) ((rect.x + rect.width + 8) / 16), (int) ((rect.y + rect.height - 8) / 16));
- if (checkColl(new Rectangle(rect.x + rect.width + 8, rect.y - 18, rect.width, rect.height))) bl = 0;
- break;
- default:
- bl = 0;
- }
+ int blX = (int) (rect.x + rect.width * dir - 8 + 16 * dir);
+ int blY = (int) (rect.y + rect.height - 8);
+
+ bl = gp.world.getForeMap(blX / 16, blY / 16);
+ if (checkColl(new Rectangle(blX, rect.y - 18, rect.width, rect.height))) bl = 0;
+
return (bl > 0 && GameItems.getBlock(bl).toJump() &&
- (rect.y + rect.height) - GameItems.getBlock(bl).getRect((int) ((rect.x - 8) / 16), (int) ((rect.y + rect.height - 8) / 16)).y > 8);
+ (rect.y + rect.height) - GameItems.getBlock(bl).getRect(blX / 16, blY / 16).y > 8);
}
private boolean checkColl(Rectangle rect) {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index 72686d11e6484a83a5091f09776f499965236267..3d65ddc68faf2db0ed563a673991698b3ace6b8e 100644 (file)
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import ru.deadsoftware.cavecraft.CaveGame;
import ru.deadsoftware.cavecraft.GameScreen;
import ru.deadsoftware.cavecraft.game.mobs.Mob;
drawX(x), drawY(y));
if (gp.world.getForeMap(x, y) == 0 && x == gp.curX && y == gp.curY)
drawWreck(gp.world.getBackMap(gp.curX, gp.curY));
- Assets.shade.setPosition(drawX(x), drawY(y));
- Assets.shade.draw(spriter);
}
}
if (gp.world.getForeMap(x, y) > 0 && GameItems.getBlock(gp.world.getForeMap(x, y)).isBackground() == drawBG) {
drawBlock(x, y, bg);
}
}
+ if (bg) {
+ spriter.end();
+ Gdx.gl.glEnable(GL20.GL_BLEND);
+ Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
+ shaper.begin(ShapeRenderer.ShapeType.Filled);
+ shaper.setColor(0f, 0f, 0f, .5f);
+ for (int y = minY; y < maxY; y++) {
+ for (int x = minX; x < maxX; x++) {
+ if ((gp.world.getForeMap(x, y) == 0 || GameItems.getBlock(gp.world.getForeMap(x, y)).isTransparent())
+ && gp.world.getBackMap(x, y) > 0) shaper.rect(drawX(x), drawY(y), 16, 16);
+ }
+ }
+ shaper.end();
+ Gdx.gl.glDisable(GL20.GL_BLEND);
+ spriter.begin();
+ }
}
private void drawMob(Mob mob) {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java
index c4e13a640a737ec58b8bf1a1a9bb6c425a42c2c5..00d91bf3b4ec9f50860cdcbb1969c44c8dbc5f64 100644 (file)
out.write(intToBytes(VERSION));
out.write(intToBytes(width));
out.write(intToBytes(height));
- for (int y = 0; y < map[0].length; y++) {
+ for (int y = 0; y < height; y++) {
bl = map[0][y];
rl = 0;
- for (int x = 0; x < map.length; x++) {
+ for (int x = 0; x < width; x++) {
if (map[x][y] != bl) {
out.write(intToBytes(rl));
out.write(intToBytes(bl));
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java
index 25d3660fc1cf29d9a01b25560e9a2b16baaa4a46..e6c5633ba78c016b76a521be8244bd929f172787 100644 (file)
return x;
}
- public int getForeMap(int x, int y) {
+ private int getMap(int x, int y, int layer) {
int map = 0;
try {
x = transformX(x);
- map = foreMap[x][y];
+ map = (layer == 0) ? foreMap[x][y] : backMap[x][y];
} catch (ArrayIndexOutOfBoundsException e) {
- //Gdx.app.error("GameWorld",e.toString());
}
return map;
}
- public void setForeMap(int x, int y, int value) {
+ private void setMap(int x, int y, int layer, int value) {
try {
x = transformX(x);
- foreMap[x][y] = value;
+ if (layer == 0) foreMap[x][y] = value;
+ else backMap[x][y] = value;
} catch (ArrayIndexOutOfBoundsException e) {
- //Gdx.app.error("GameWorld", e.toString());
}
}
+ public int getForeMap(int x, int y) {
+ return getMap(x, y, 0);
+ }
+
+ public void setForeMap(int x, int y, int value) {
+ setMap(x, y, 0, value);
+ }
+
public int getBackMap(int x, int y) {
- int map = 0;
- try {
- x = transformX(x);
- map = backMap[x][y];
- } catch (ArrayIndexOutOfBoundsException e) {
- //Gdx.app.error("GameWorld",e.toString());
- }
- return map;
+ return getMap(x, y, 1);
}
public void setBackMap(int x, int y, int value) {
- try {
- x = transformX(x);
- backMap[x][y] = value;
- } catch (ArrayIndexOutOfBoundsException e) {
- //Gdx.app.error("GameWorld", e.toString());
- }
+ setMap(x, y, 1, value);
}
private void placeSlab(int x, int y, int value) {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java
index 16e3a5277edd67202148588639cc5bd36b645e11..5810eb55a047e86b8977341e32256c3ecd491b3c 100644 (file)
}
public void setDir(int dir) {
- if (dir != getDir()) changeDir();
+ if (dir != getDir()) switchDir();
}
@Override
@Override
public void changeDir() {
- switchDir();
}
@Override
diff --git a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java
index 7a660e768a3e995d7a136b8eb22024b3b054c61d..bdaf2b1a1f842eda665444000e363528c77a2b54 100644 (file)
spriter.draw(Assets.menuBtn[button.getType()], button.getX(), button.getY());
setFontColor(255, 255, 255);
drawString(button.getLabel(),
- (button.getX() + button.getWidth() / 2) - Assets.getStringWidth(button.getLabel()) / 2,
- (button.getY() + button.getHeight() / 2) - Assets.getStringHeight(button.getLabel()) / 2);
+ (button.getX() + button.getWidth() / 2) - (float) Assets.getStringWidth(button.getLabel()) / 2,
+ (button.getY() + button.getHeight() / 2) - (float) Assets.getStringHeight(button.getLabel()) / 2);
}
private void drawButtons(Array<Button> buttons) {
diff --git a/core/src/ru/deadsoftware/cavecraft/misc/InputHandlerGame.java b/core/src/ru/deadsoftware/cavecraft/misc/InputHandlerGame.java
index 0d0cb5639e934f7f8533815036b2730999ba1d41..6a912ac355f4d5145e144d68d84b6d785cfc8ebf 100644 (file)
private GameProc gp;
private GameInput gameInput;
- private float tWidth, tHeight;
-
public InputHandlerGame(GameProc gp) {
this.gp = gp;
this.gameInput = new GameInput(gp);
- tWidth = gp.renderer.getWidth();
- tHeight = gp.renderer.getHeight();
}
@Override
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
- int tx = (int) (screenX * tWidth / getWidth());
- int ty = (int) (screenY * tHeight / getHeight());
screenX *= gp.renderer.getWidth() / getWidth();
screenY *= gp.renderer.getHeight() / getHeight();
if (CaveGame.TOUCH) {
- if (tx > 26 && tx < 52 && ty > tHeight - 52 && ty < tHeight - 26) {
+ if (screenX > 26 && screenX < 52 && screenY > gp.renderer.getHeight() - 52 &&
+ screenY < gp.renderer.getHeight() - 26) {
if (gp.ctrlMode == 1) gameInput.keyDown(Input.Keys.W);
else gameInput.keyDown(Input.Keys.SPACE);
- } else if (tx > 0 && tx < 26 && ty > tHeight - 26) {
+ } else if (screenX > 0 && screenX < 26 && screenY > gp.renderer.getHeight() - 26) {
gameInput.keyDown(Input.Keys.A);
- } else if (tx > 26 && tx < 52 && ty > tHeight - 26) {
+ } else if (screenX > 26 && screenX < 52 && screenY > gp.renderer.getHeight() - 26) {
if (gp.ctrlMode == 1) gameInput.keyDown(Input.Keys.S);
else gameInput.keyDown(Input.Keys.CONTROL_LEFT);
- } else if (tx > 52 && tx < 78 && ty > tHeight - 26) {
+ } else if (screenX > 52 && screenX < 78 && screenY > gp.renderer.getHeight() - 26) {
gameInput.keyDown(Input.Keys.D);
- } else if (tx > 78 && tx < 104 && ty > tHeight - 26) {
+ } else if (screenX > 78 && screenX < 104 && screenY > gp.renderer.getHeight() - 26) {
gameInput.keyDown(Input.Keys.ALT_LEFT);
- } else if (tx > tWidth - 52 && tx < tWidth - 26 && ty > tHeight - 26) {
+ } else if (screenX > gp.renderer.getWidth() - 52 && screenX < gp.renderer.getWidth() - 26 &&
+ screenY > gp.renderer.getHeight() - 26) {
gameInput.touchDown(screenX, screenY, Input.Buttons.LEFT);
- } else if (tx > tWidth - 26 && screenY > ty - 26) {
+ } else if (screenX > gp.renderer.getWidth() - 26 && screenY > screenY - 26) {
gameInput.touchDown(screenX, screenY, Input.Buttons.RIGHT);
} else {
gameInput.touchDown(screenX, screenY, -1);
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
- int tx = (int) (screenX * tWidth / getWidth());
- int ty = (int) (screenY * tHeight / getHeight());
screenX *= gp.renderer.getWidth() / getWidth();
screenY *= gp.renderer.getHeight() / getHeight();
if (CaveGame.TOUCH) {
- if (tx > 26 && tx < 52 && ty > tHeight - 52 && ty < tHeight - 26) {
+ if (screenX > 26 && screenX < 52 && screenY > gp.renderer.getHeight() - 52 &&
+ screenY < gp.renderer.getHeight() - 26) {
if (gp.ctrlMode == 1) gameInput.keyUp(Input.Keys.W);
else gameInput.keyUp(Input.Keys.SPACE);
- } else if (tx > 0 && tx < 26 && ty > tHeight - 26) {
+ } else if (screenX > 0 && screenX < 26 && screenY > gp.renderer.getHeight() - 26) {
gameInput.keyUp(Input.Keys.A);
- } else if (tx > 26 && tx < 52 && ty > tHeight - 26) {
+ } else if (screenX > 26 && screenX < 52 && screenY > gp.renderer.getHeight() - 26) {
if (gp.ctrlMode == 1) gameInput.keyUp(Input.Keys.S);
else gameInput.keyUp(Input.Keys.CONTROL_LEFT);
- } else if (tx > 52 && tx < 78 && ty > tHeight - 26) {
+ } else if (screenX > 52 && screenX < 78 && screenY > gp.renderer.getHeight() - 26) {
gameInput.keyUp(Input.Keys.D);
- } else if (tx > 78 && tx < 104 && ty > tHeight - 26) {
+ } else if (screenX > 78 && screenX < 104 && screenY > gp.renderer.getHeight() - 26) {
gameInput.keyUp(Input.Keys.ALT_LEFT);
- } else if (tx > tWidth - 52 && tx < tWidth - 26 && ty > tHeight - 26) {
+ } else if (screenX > gp.renderer.getWidth() - 52 && screenX < gp.renderer.getWidth() - 26 &&
+ screenY > gp.renderer.getHeight() - 26) {
gameInput.touchUp(screenX, screenY, Input.Buttons.LEFT);
- } else if (tx > tWidth - 26 && screenY > ty - 26) {
+ } else if (screenX > gp.renderer.getWidth() - 26 && screenY > screenY - 26) {
gameInput.touchUp(screenX, screenY, Input.Buttons.RIGHT);
} else {
gameInput.touchUp(screenX, screenY, -1);
diff --git a/core/src/ru/deadsoftware/cavecraft/misc/Renderer.java b/core/src/ru/deadsoftware/cavecraft/misc/Renderer.java
index 0d63d5a21b32945fe2191dc0ef6576941f4e6ba9..b2acb6d67c988014a6965652173cfdb939b7ea7d 100644 (file)
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.graphics.g2d.SpriteCache;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import ru.deadsoftware.cavecraft.GameScreen;
protected ShapeRenderer shaper;
protected SpriteBatch spriter;
+ protected SpriteCache spriteCache;
public Renderer() {
this(GameScreen.getWidth(), GameScreen.getHeight());
shaper.setProjectionMatrix(camera.combined);
spriter = new SpriteBatch();
spriter.setProjectionMatrix(camera.combined);
+ spriteCache = new SpriteCache();
+ spriteCache.setProjectionMatrix(camera.combined);
}
public float getWidth() {