summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fe86b2f)
raw | patch | inline | side by side (parent: fe86b2f)
author | fred-boy <fred-boy@protonmail.com> | |
Sat, 21 Apr 2018 16:48:22 +0000 (23:48 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Sat, 21 Apr 2018 16:48:22 +0000 (23:48 +0700) |
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
index 3bcbc9b2bcf0b4b163c2a81a9d768c9e9cf2c99b..2fdc29bca17b88dd066b8ef1ebd8840fc0cab6cb 100644 (file)
package ru.deadsoftware.cavecraft.game;
-import com.badlogic.gdx.math.*;
+import com.badlogic.gdx.math.Intersector;
+import com.badlogic.gdx.math.MathUtils;
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavecraft.CaveGame;
import ru.deadsoftware.cavecraft.Items;
import ru.deadsoftware.cavecraft.game.mobs.Mob;
int bl = 0;
switch (dir) {
case 0:
- if ((int)((rect.x+(rect.width/2))/16) - 1>=0)
- bl = gameProc.world.getForeMap(
- (int)((rect.x+(rect.width/2))/16) - 1,
- (int)(rect.y/16)+1);
+ bl = gameProc.world.getForeMap(
+ (int)((rect.x+(rect.width/2))/16) - 1,
+ (int)(rect.y/16)+1);
if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)-1,(int)(rect.y/16))>0) bl=0;
+ if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)-1,(int)(rect.y/16)-1)>0) bl=0;
break;
case 1:
- if ((int)((rect.x+(rect.width/2))/16) + 1<gameProc.world.getWidth())
- bl = gameProc.world.getForeMap(
- (int)((rect.x+(rect.width/2))/16) + 1,
- (int)(rect.y/16)+1);
+ bl = gameProc.world.getForeMap(
+ (int)((rect.x+(rect.width/2))/16) + 1,
+ (int)(rect.y/16)+1);
if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)+1,(int)(rect.y/16))>0) bl=0;
+ if (gameProc.world.getForeMap((int)((rect.x+(rect.width/2))/16)+1,(int)(rect.y/16)-1)>0) bl=0;
break;
default:
bl=0;
int minY = (int) ((rect.y+rect.height/2)/16)-4;
int maxX = (int) ((rect.x+rect.width/2)/16)+4;
int maxY = (int) ((rect.y+rect.height/2)/16)+4;
- if (minX<0) minX=0;
if (minY<0) minY=0;
- 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 (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity);
pl.position.add(pl.moveX);
- if (pl.position.x<0 ||
- pl.position.x+pl.texWidth>=gameProc.world.getWidth()*16)
- pl.position.sub(pl.moveX);
if (checkColl(pl.getRect())) {
if (pl.canJump && !pl.flyMode) pl.position.y-=8;
if (checkColl(pl.getRect())) {
}
mob.moveY.add(gravity);
mob.position.add(mob.moveX);
- if (mob.position.x<32 ||
- mob.position.x+mob.width>gameProc.world.getWidth()*16-32)
- mob.position.sub(mob.moveX);
if (checkColl(mob.getRect())) {
int d = 0;
if (mob.moveX.x<0) d=1; else if (mob.moveX.x>0) d=-1;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java
index 6a2bf046b8c52061885a680e7454d42f1cbd6418..6c532ace6a77c6a6537d7b5b0196f44c3e7d08fc 100644 (file)
import com.badlogic.gdx.Gdx;
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.*;
physics = new GamePhysics(this);
player = new Player(world.getSpawnPoint());
mobs = new Array<Mob>();
- for (int i=0; i<1024/64; i++) {
- mobs.add(new Pig(i*16*64, 0, world));
+ for (int i=0; i<world.getWidth(); i+=64) {
+ mobs.add(new Pig(i*16, 0, world));
}
if (!CaveGame.TOUCH) ctrlMode = 1;
}
}
private void moveCursor() {
- if (ctrlMode==0) {
+ if (ctrlMode==0 && CaveGame.TOUCH) {
if (player.canJump) {
cursorX = (int) (player.position.x + player.texWidth / 2) / 16;
if (player.dir == 0) cursorX--;
(renderer.camera.viewportWidth/GameScreen.getWidth())+renderer.camera.position.x)/16;
cursorY = (int)(Gdx.input.getY()*
(renderer.camera.viewportHeight/GameScreen.getHeight())+renderer.camera.position.y)/16;
+ if ((Gdx.input.getX()*
+ (renderer.camera.viewportWidth/GameScreen.getWidth())+renderer.camera.position.x)<0)
+ cursorX--;
}
}
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;
if (cursorX<(player.position.x+player.texWidth/2)/16)
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index b8b53249be9296363957889c991ae7bf377f5a80..944093826043bbd51204107b89fabddd04e193c9 100644 (file)
package ru.deadsoftware.cavecraft.game;
import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavecraft.Assets;
import ru.deadsoftware.cavecraft.CaveGame;
-import ru.deadsoftware.cavecraft.Items;
import ru.deadsoftware.cavecraft.GameScreen;
+import ru.deadsoftware.cavecraft.Items;
import ru.deadsoftware.cavecraft.game.mobs.Mob;
import ru.deadsoftware.cavecraft.game.objects.Player;
Assets.minecraftFont.draw(fontBatch, str, x, y);
}
- private void drawWorld() {
- int minX = (int) (camera.position.x/16);
- int minY = (int) (camera.position.y/16);
+ private void drawWorldBackground() {
+ int minX = (int) (camera.position.x/16)-1;
+ int minY = (int) (camera.position.y/16)-1;
int maxX = (int) ((camera.position.x+camera.viewportWidth)/16)+1;
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();
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){/* &&
- !Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) {
- spriteBatch.draw(
- Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(),
- x * 16 - camera.position.x,y * 16 - camera.position.y);*/
+ if (gameProc.world.getForeMap(x,y)>0){
} else if (gameProc.world.getBackMap(x,y)>0) {
spriteBatch.draw(
Items.BLOCKS.getValueAt(gameProc.world.getBackMap(x,y)).getTexture(),
}
private void drawWorldForeground(){
- int minX = (int) (camera.position.x/16);
- int minY = (int) (camera.position.y/16);
+ int minX = (int) (camera.position.x/16)-1;
+ int minY = (int) (camera.position.y/16)-1;
int maxX = (int) ((camera.position.x+camera.viewportWidth)/16)+1;
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();
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) { /*&&
- Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) {*/
+ if (gameProc.world.getForeMap(x,y)>0) {
spriteBatch.draw(
Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(),
x * 16 - camera.position.x,y * 16 - camera.position.y);
}
private void drawGamePlay() {
- drawWorld();
+ drawWorldBackground();
Mob.animateMobs();
for (Mob mob : gameProc.mobs) drawMob(mob);
drawPlayer(gameProc.player);
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java
index e6b0b006b36460b590c02199df2fb14144c5a7b5..ab89dd78d2b423c022e448145a266bdc0cb256bf 100644 (file)
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
-import com.badlogic.gdx.utils.ArrayMap;
-import ru.deadsoftware.cavecraft.CaveGame;
-import ru.deadsoftware.cavecraft.GameState;
import ru.deadsoftware.cavecraft.Items;
public class GameWorld {
}
public int getForeMap(int x, int y) {
- int ret = 0;
+ int map = 0;
try {
- ret = foreMap[x][y];
+ if (x<0) {
+ x = x % (getWidth()-1)-1;
+ x = getWidth()- Math.abs(x);
+ } else if (x>0) {
+ x = x % (getWidth()-1)+1;
+ }
+ map = foreMap[x][y];
} catch (ArrayIndexOutOfBoundsException e) {
Gdx.app.error("GameWorld",e.toString());
}
- return ret;
+ return map;
}
public void setForeMap(int x, int y, int value) {
try {
+ if (x<0) {
+ x = x % (getWidth()-1)-1;
+ x = getWidth()- Math.abs(x);
+ } else if (x>0) {
+ x = x % (getWidth()-1)+1;
+ }
foreMap[x][y] = value;
} catch (ArrayIndexOutOfBoundsException e) {
Gdx.app.error("GameWorld", e.toString());
}
public int getBackMap(int x, int y) {
- int ret = 0;
+ int map = 0;
try {
- ret = backMap[x][y];
+ if (x<0) {
+ x = x % (getWidth()-1)-1;
+ x = getWidth()- Math.abs(x);
+ } else if (x>0) {
+ x = x % (getWidth()-1)+1;
+ }
+ map = backMap[x][y];
} catch (ArrayIndexOutOfBoundsException e) {
Gdx.app.error("GameWorld",e.toString());
}
- return ret;
+ return map;
}
public void setBackMap(int x, int y, int value) {
try {
+ if (x<0) {
+ x = x % (getWidth()-1)-1;
+ x = getWidth()- Math.abs(x);
+ } else if (x>0) {
+ x = x % (getWidth()-1)+1;
+ }
backMap[x][y] = value;
} catch (ArrayIndexOutOfBoundsException e) {
Gdx.app.error("GameWorld", e.toString());
public Vector2 getSpawnPoint() {
float x=0, y=0;
- boolean found = false;
- x = getWidth()/2;
- while (!found) {
- for (int i = 0; i < getHeight(); i++) {
- if (getForeMap((int)x, i)>0 &&
- Items.BLOCKS.getValueAt(getForeMap((int)x, i)).collision &&
- getForeMap((int)x, i-1)==0 && getForeMap((int)x, i-1)==0) {
- y = i-2;
- found = true;
- break;
- }
- }
- if (!found) {
- x--;
- if (x<0) x=getWidth()-1;
- if ((int)x == getWidth()/2+1) {
- x--;
- y=0;
- break;
- }
- }
- }
x = x*16 + 4;
y *= 16;
return new Vector2(x,y);
diff --git a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java
index 954bdffd799366b314056582e8043d4949d9de3a..ccbe50a2ad29dd08e95581e749741a36a767f1ef 100644 (file)
package ru.deadsoftware.cavecraft.game;
-import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.RandomXS128;
-import com.badlogic.gdx.utils.ArrayMap;
import com.badlogic.gdx.utils.TimeUtils;
public class WorldGen {
res[0] = mid;
for (int i=1; i<width; i++) {
t = rand.nextInt(3)-1;
+ if (i>width-(max-min)) {
+ if (res[i-1]+t<res[0]) t=Math.abs(t);
+ else if (res[i-1]+t>res[0]) t=-Math.abs(t);
+ }
res[i] = res[i-1] + t;
if (res[i]<min) res[i] = min;
if (res[i]>max) res[i] = max;
rand = new RandomXS128(seed);
foreMap = new int[width][height];
backMap = new int[width][height];
- hMap = genLandscape(width, height/4, height/8, height/2);
+ hMap = genLandscape(width, height/8*3, height/8, height/2);
for (int x=0; x<width; x++) {
dirtH = 4+rand.nextInt(2);
for (int y = height- hMap[x]; y<height; y++) {