public class Assets {
- public static final int BLOCK_TEXTURES = 3;
+ public static final int BLOCK_TEXTURES = 9;
public static BitmapFont minecraftFont;
public static void load() {
BLOCKS.put("none", null);
BLOCKS.put("stone", new Block(0,0,16,16,Assets.blockTextures[0]));
- BLOCKS.put("dirt", new Block(0,0,16,16,Assets.blockTextures[1]));
- BLOCKS.put("grass", new Block(0,0,16,16,Assets.blockTextures[2]));
+ BLOCKS.put("grass", new Block(0,0,16,16,Assets.blockTextures[1]));
+ BLOCKS.put("dirt", new Block(0,0,16,16,Assets.blockTextures[2]));
+ BLOCKS.put("cobblestone", new Block(0,0,16,16,Assets.blockTextures[3]));
+ BLOCKS.put("planks", new Block(0,0,16,16,Assets.blockTextures[4]));
+ BLOCKS.put("sapling", new Block(0,0,16,16,Assets.blockTextures[5],false,true));
+ BLOCKS.put("bedrock", new Block(0,0,16,16,Assets.blockTextures[6]));
+ BLOCKS.put("water", new Block(0,0,16,16,Assets.blockTextures[7],false,true));
+ BLOCKS.put("lava", new Block(0,0,16,16,Assets.blockTextures[8],false,true));
}
}
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
+import ru.deadsoftware.cavecraft.Items;
import ru.deadsoftware.cavecraft.game.mobs.Mob;
import ru.deadsoftware.cavecraft.game.objects.Player;
}
private boolean checkJump(Rectangle rect, int dir) {
- int bl;
+ int bl = 0;
switch (dir) {
case 0:
- bl = gameProc.world.getForeMap(
+ 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);
break;
case 1:
- bl = gameProc.world.getForeMap(
+ 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);
break;
default:
bl=0;
}
- return (bl!=0);
+ return (bl>0 && Items.BLOCKS.getValueAt(bl).collision);
}
private boolean checkColl(Rectangle rect) {
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));
- for (int b: bl) if (b>0) {
+ for (int b: bl) if (b>0 && Items.BLOCKS.getValueAt(b).collision) {
return true;
}
return false;
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) {
+ 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);
}
}
+ private void drawWorldForeground(){
+ int minX = (int) (camera.position.x/16);
+ int minY = (int) (camera.position.y/16);
+ 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);
+ }
+ }
+ }
+ }
+
private void drawMob(Mob mob) {
mob.draw(spriteBatch,
mob.position.x-camera.position.x, mob.position.y-camera.position.y);
private void drawGUI() {
spriteBatch.draw(Assets.invBar, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2, 0);
- for (int i=0; i<8; i++) {
+ for (int i=0; i<9; 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,
drawWorld();
for (Mob mob : gameProc.mobs) drawMob(mob);
drawPlayer(gameProc.player);
+ drawWorldForeground();
drawGUI();
spriteBatch.end();
drawString("Y: "+(int)(gameProc.player.position.y/16), 0, 60);
drawString("Block: "+
Items.BLOCKS.keys().toArray().get(gameProc.world.getForeMap(
- (int)(gameProc.player.position.x/16),
+ (int)((gameProc.player.position.x+gameProc.player.texWidth/2)/16),
(int)(gameProc.player.position.y/16+2))),
0, 80);
fontBatch.end();
dirtH = 4+rand.nextInt(2);
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-hMap[x]+dirtH) {
foreMap[x][y] = 2;
backMap[x][y] = 2;
- } else {
+ } else if (y<height-hMap[x]+dirtH) {
+ foreMap[x][y] = 3;
+ backMap[x][y] = 3;
+ } else if (y<height-1){
foreMap[x][y] = 1;
backMap[x][y] = 1;
+ } else {
+ foreMap[x][y] = 7;
+ backMap[x][y] = 7;
}
}
}
private Rectangle rect;
private TextureRegion texture;
+ public boolean collision, foreground;
+
public Block(int x, int y, int w, int h, TextureRegion texture) {
+ this(x,y,w,h,texture, true, false);
+ }
+
+ public Block(int x, int y, int w, int h, TextureRegion texture, boolean collision, boolean foreground) {
rect = new Rectangle(x,y,w,h);
this.texture = texture;
+ this.collision = collision;
+ this.foreground = foreground;
}
public TextureRegion getTexture() {
inventory[0] = 1;
inventory[1] = 2;
inventory[2] = 3;
+ inventory[3] = 4;
+ inventory[4] = 5;
+ inventory[5] = 6;
+ inventory[6] = 7;
+ inventory[7] = 8;
+ inventory[8] = 9;
}
public Rectangle getRect() {