Implemented elevation in-game with sprites

This commit is contained in:
Anuken 2018-06-11 21:08:15 -04:00
parent b609b5909b
commit e36a666542
16 changed files with 552 additions and 419 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

View File

@ -48,7 +48,7 @@ float snoise(vec2 v){
void main() {
vec2 c = v_texCoord.xy;
vec4 color = texture2D(u_texture, c);
vec4 color = texture2D(u_texture, c) * v_color;
vec2 v = vec2(1.0/screensize.x, 1.0/screensize.y);
ivec2 icoords = ivec2(int(c.x / v.x + camerapos.x), int(c.y / v.y + camerapos.y));

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 KiB

After

Width:  |  Height:  |  Size: 111 KiB

View File

@ -191,14 +191,14 @@ public class Build {
for (int dx = 0; dx < type.size; dx++) {
for (int dy = 0; dy < type.size; dy++) {
Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
if (other == null || (other.block() != Blocks.air && !other.block().alwaysReplace) || !other.floor().placeableOn) {
if (other == null || (other.block() != Blocks.air && !other.block().alwaysReplace) || other.cliffs != 0 || !other.floor().placeableOn) {
return false;
}
}
}
return true;
} else {
return (tile.getTeam() == Team.none || tile.getTeam() == team) && tile.floor().placeableOn
return (tile.getTeam() == Team.none || tile.getTeam() == team) && tile.floor().placeableOn && tile.cliffs == 0
&& ((type.canReplace(tile.block()) && !(type == tile.block() && rotation == tile.getRotation() && type.rotate)) || tile.block().alwaysReplace || tile.block() == Blocks.air)
&& tile.block().isMultiblock() == type.isMultiblock() && type.canPlaceOn(tile);
}

View File

@ -311,16 +311,35 @@ public class Tile implements PosTrait, TargetTrait {
cost = 1;
cliffs = 0;
boolean occluded = false;
//check for occlusion
for(int i = 0; i < 8; i ++){
GridPoint2 point = Geometry.d8[i];
Tile tile = world.tile(x + point.x, y + point.y);
if(tile != null){
if(tile.solid()){
occluded = true;
}
if(tile.elevation < elevation){
cliffs |= (0x1 << i);
}
if(tile != null && tile.solid()){
occluded = true;
break;
}
}
//check for bitmasking cliffs
for(int i = 0; i < 4; i ++){
GridPoint2 pc = Geometry.d4[i];
GridPoint2 pe = Geometry.d8edge[i];
Tile tc = world.tile(x + pc.x, y + pc.y);
Tile te = world.tile(x + pe.x, y + pe.y);
Tile tex = world.tile(x, y + pe.y);
Tile tey = world.tile(x + pe.x, y);
//check for cardinal direction elevation changes and bitmask that
if(tc != null && tc.elevation < elevation){
cliffs |= (1 << (i*2));
}
//check for corner bitmasking
if(te != null && tex != null && tey != null && te.elevation < elevation && tex.elevation < elevation && tey.elevation < elevation){
cliffs |= (1 << (i*2 + 1));
}
}
if(occluded){

View File

@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.IntIntMap;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.fx.BlockFx;
import io.anuke.mindustry.type.Liquid;
@ -16,11 +17,19 @@ import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class Floor extends Block{
protected static IntIntMap bitmask = Mathf.mapInt(2, 1, 8, 2, 10, 3, 11, 4, 16, 5, 18, 6, 22, 7, 24, 8,
26, 9, 27, 10, 30, 11, 31, 12, 64, 13, 66, 14, 72, 15, 74, 16, 75, 17, 80, 18,
82, 19, 86, 20, 88, 21, 90, 22, 91, 23, 94, 24, 95, 25, 104, 26, 106, 27, 107, 28,
120, 29, 122, 30, 123, 31, 126, 32, 127, 33, 208, 34, 210, 35, 214, 36, 216, 37,
218, 38, 219, 39, 222, 40, 223, 41, 248, 42, 250, 43, 251, 44, 254, 45, 255, 46, 0, 47);
protected TextureRegion edgeRegion;
protected TextureRegion[] edgeRegions;
protected TextureRegion[] cliffRegions;
protected Vector2[] offsets;
protected Predicate<Block> blends = block -> block != this;
protected boolean blend = true;
@ -80,6 +89,20 @@ public class Floor extends Block{
edgeRegions[i] = result;
offsets[i] = new Vector2(-4 + rx, -4 + ry);
}
if(Draw.hasRegion(name + "-cliff")){
cliffRegions = new TextureRegion[8];
TextureRegion base = Draw.region(name + "-cliff");
for(int i = 0; i < 8; i ++){
int dx = Geometry.d8[i].x, dy = Geometry.d8[i].y;
TextureRegion region = new TextureRegion();
region.setTexture(base.getTexture());
region.setRegion(base.getRegionX() + tilesize + tilesize*dx, base.getRegionY() + tilesize - tilesize*dy, tilesize, tilesize);
cliffRegions[i] = region;
}
}
}
}
@ -105,11 +128,32 @@ public class Floor extends Block{
Draw.rect(variants > 0 ? (name() + MathUtils.random(1, variants)) : name(), tile.worldx(), tile.worldy());
if(Draw.hasRegion(name + "-cliff-side") && tile.cliffs != 0){
for(int i = 0; i < 4; i ++){
if((tile.cliffs & (1 << i*2)) != 0) {
Draw.colorl(i > 1 ? 0.6f : 1f);
boolean above = (tile.cliffs & (1 << ((i+1)%4)*2)) != 0, below = (tile.cliffs & (1 << (Mathf.mod(i-1, 4))*2)) != 0;
if(above && below){
Draw.rect(name + "-cliff-edge-2", tile.worldx(), tile.worldy(), i * 90);
}else if(above){
Draw.rect(name + "-cliff-edge", tile.worldx(), tile.worldy(), i * 90);
}else if(below){
Draw.rect(name + "-cliff-edge-1", tile.worldx(), tile.worldy(), i * 90);
}else{
Draw.rect(name + "-cliff-side", tile.worldx(), tile.worldy(), i * 90);
}
}
}
}
Draw.reset();
drawEdges(tile, false);
}
private void drawEdges(Tile tile, boolean sameLayer){
if(!blend) return;
if(!blend || tile.cliffs > 0) return;
for(int i = 0; i < 8; i ++){
int dx = Geometry.d8[i].x, dy = Geometry.d8[i].y;