Added full block descriptions, improved shield shaders

This commit is contained in:
Anuken 2017-11-20 19:02:35 -05:00
parent aedf46257a
commit 806b762333
7 changed files with 131 additions and 78 deletions

View File

@ -8,6 +8,7 @@ uniform sampler2D u_texture;
uniform vec4 u_color;
uniform vec2 u_texsize;
uniform float u_time;
uniform float u_scaling;
uniform vec2 u_offset;
varying vec4 v_color;
@ -19,7 +20,7 @@ void main() {
vec2 coords = (T * u_texsize) + u_offset;
T += vec2(sin(coords.y / 3.0 + u_time / 20.0) / 250.0, sin(coords.x / 3.0 + u_time / 20.0) / 250.0);
T += vec2(sin(coords.y / 3.0 + u_time / 20.0) / 250.0, sin(coords.x / 3.0 + u_time / 20.0) / 250.0) * u_scaling;
float si = 1.0 + sin(u_time / 20.0 /*+ (coords.x + coords.y) / 30.0*/) / 8.0;

View File

@ -45,17 +45,17 @@ public class Renderer extends RendererModule{
public Renderer() {
Core.cameraScale = baseCameraScale;
Graphics.addSurface("pixel", Core.cameraScale);
}
@Override
public void init(){
pixelate = Settings.getBool("pixelate");
Graphics.addSurface("shadow", Settings.getBool("pixelate") ? Core.cameraScale : 1);
Graphics.addSurface("shield", Settings.getBool("pixelate") ? Core.cameraScale : 1);
}
public void setPixelate(boolean pixelate){
this.pixelate = pixelate;
}
@ -82,9 +82,9 @@ public class Renderer extends RendererModule{
clearScreen();
}else{
boolean smoothcam = Settings.getBool("smoothcam");
if(World.core.block() == ProductionBlocks.core){
if(!smoothcam){
setCamera(player.x, player.y);
}else{
@ -93,7 +93,7 @@ public class Renderer extends RendererModule{
}else{
smoothCamera(World.core.worldx(), World.core.worldy(), 0.4f);
}
if(Settings.getBool("pixelate"))
limitCamera(4f, player.x, player.y);
@ -111,28 +111,26 @@ public class Renderer extends RendererModule{
}
float lastx = camera.position.x, lasty = camera.position.y;
if(Vars.snapCamera && smoothcam && Settings.getBool("pixelate")){
camera.position.set((int) camera.position.x, (int) camera.position.y, 0);
}
if(Gdx.graphics.getHeight() / Core.cameraScale % 2 == 1){
camera.position.add(0, -0.5f, 0);
}
if(Gdx.graphics.getWidth() / Core.cameraScale % 2 == 1){
camera.position.add(-0.5f, 0, 0);
}
long time = TimeUtils.nanoTime();
drawDefault();
if(Timers.get("profiled", profileTime)) Profiler.draw = TimeUtils.timeSinceNanos(time);
if(Timers.get("profiled", profileTime))
Profiler.draw = TimeUtils.timeSinceNanos(time);
if(Vars.debug && Vars.debugGL && Timers.get("profile", 60)){
UCore.log("shaders: " + GLProfiler.shaderSwitches,
"calls: " + GLProfiler.drawCalls,
"bindings: " + GLProfiler.textureBindings,
"vertices: " + GLProfiler.vertexCount.average);
UCore.log("shaders: " + GLProfiler.shaderSwitches, "calls: " + GLProfiler.drawCalls, "bindings: " + GLProfiler.textureBindings, "vertices: " + GLProfiler.vertexCount.average);
}
camera.position.set(lastx - deltax, lasty - deltay, 0);
@ -147,19 +145,21 @@ public class Renderer extends RendererModule{
public void draw(){
Graphics.surface("shield");
Graphics.surface();
long time = TimeUtils.nanoTime();
renderTiles();
if(Timers.get("profilebd", profileTime)) Profiler.blockDraw = TimeUtils.timeSinceNanos(time);
if(Timers.get("profilebd", profileTime))
Profiler.blockDraw = TimeUtils.timeSinceNanos(time);
time = TimeUtils.nanoTime();
Entities.draw();
if(Timers.get("profileed", profileTime)) Profiler.entityDraw = TimeUtils.timeSinceNanos(time);
if(Timers.get("profileed", profileTime))
Profiler.entityDraw = TimeUtils.timeSinceNanos(time);
drawShield();
renderPixelOverlay();
if(Settings.getBool("indicators")){
drawEnemyMarkers();
}
@ -173,20 +173,18 @@ public class Renderer extends RendererModule{
AndroidInput.mousey = Gdx.graphics.getHeight() / 2;
camera.position.set(player.x, player.y, 0);
}
void drawEnemyMarkers(){
Draw.color(Color.RED);
Draw.alpha(0.6f);
for(Entity entity : Entities.all()){
if(entity instanceof Enemy){
Enemy enemy = (Enemy)entity;
if(Tmp.r1.setSize(camera.viewportWidth, camera.viewportHeight)
.setCenter(camera.position.x, camera.position.y)
.overlaps(enemy.hitbox.getRect(enemy.x, enemy.y))){
Enemy enemy = (Enemy) entity;
if(Tmp.r1.setSize(camera.viewportWidth, camera.viewportHeight).setCenter(camera.position.x, camera.position.y).overlaps(enemy.hitbox.getRect(enemy.x, enemy.y))){
continue;
}
float angle = Angles.angle(camera.position.x, camera.position.y, enemy.x, enemy.y);
Angles.translation(angle, Unit.dp.inPixels(20f));
Draw.rect("enemyarrow", camera.position.x + Angles.x(), camera.position.y + Angles.y(), angle);
@ -194,20 +192,20 @@ public class Renderer extends RendererModule{
}
Draw.color();
}
void drawShield(){
Texture texture = Graphics.getSurface("shield").texture();
Shaders.shield.color.set(Color.SKY);
Tmp.tr2.setRegion(texture);
Shaders.shield.region = Tmp.tr2;
Graphics.end();
Graphics.shader(Shaders.shield);
Graphics.setScreen();
Core.batch.draw(texture, 0, Gdx.graphics.getHeight(), Gdx.graphics.getWidth(), -Gdx.graphics.getHeight());
Graphics.shader();
Graphics.end();
Graphics.beginCam();
@ -219,9 +217,9 @@ public class Renderer extends RendererModule{
//render the entire map
if(floorCache == null || floorCache.length != chunksx || floorCache[0].length != chunksy){
floorCache = new Cache[chunksx][chunksy];
for(int x = 0; x < chunksx; x ++){
for(int y = 0; y < chunksy; y ++){
for(int x = 0; x < chunksx; x++){
for(int y = 0; y < chunksy; y++){
renderCache(x, y);
}
}
@ -257,9 +255,9 @@ public class Renderer extends RendererModule{
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2) + 2;
boolean noshadows = Settings.getBool("noshadows");
boolean drawTiles = true;
//0 = shadows
//1 = normal blocks
//2 = over blocks
@ -267,7 +265,7 @@ public class Renderer extends RendererModule{
if(l == 0){
Graphics.surface("shadow");
}
for(int x = -rangex; x <= rangex; x++){
for(int y = -rangey; y <= rangey; y++){
int worldx = Mathf.scl(camera.position.x, tilesize) + x;
@ -294,6 +292,23 @@ public class Renderer extends RendererModule{
Draw.color();
}
}
if(Vars.debug && Vars.debugChunks){
Draw.color(Color.YELLOW);
Draw.thick(1f);
for(int x = -crangex; x <= crangex; x++){
for(int y = -crangey; y <= crangey; y++){
int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x;
int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y;
if(!Mathf.inBounds(worldx, worldy, floorCache))
continue;
Draw.linerect(worldx * chunksize * tilesize, worldy * chunksize * tilesize,
chunksize * tilesize, chunksize * tilesize);
}
}
Draw.reset();
}
}
void renderCache(int cx, int cy){
@ -303,11 +318,11 @@ public class Renderer extends RendererModule{
for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){
Tile tile = World.tile(tilex, tiley);
tile.floor().drawCache(tile);
}
}
floorCache[cx][cy] = Caches.end();
}
public void clearTiles(){
@ -316,15 +331,16 @@ public class Renderer extends RendererModule{
void renderPixelOverlay(){
//draw tutorial placement point
if(Vars.control.tutorial.showBlock()){
int x = World.core.x + Vars.control.tutorial.getPlacePoint().x;
int y = World.core.y + Vars.control.tutorial.getPlacePoint().y;
int rot = Vars.control.tutorial.getPlaceRotation();
Draw.thick(1f);
Draw.color(Color.YELLOW);
Draw.square(x * tilesize, y * tilesize, tilesize/2f + Mathf.sin(Timers.time(), 4f, 1f));
Draw.square(x * tilesize, y * tilesize, tilesize / 2f + Mathf.sin(Timers.time(), 4f, 1f));
Draw.color(Color.ORANGE);
Draw.thick(2f);
if(rot != -1){
@ -332,8 +348,10 @@ public class Renderer extends RendererModule{
}
Draw.reset();
}
if(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && (!ui.hasMouse() || android) && AndroidInput.mode == PlaceMode.cursor){
//draw placement box
if(player.recipe != null && Vars.control.hasItems(player.recipe.requirements)
&& (!ui.hasMouse() || android) && AndroidInput.mode == PlaceMode.cursor){
float x = 0;
float y = 0;
@ -348,22 +366,19 @@ public class Renderer extends RendererModule{
tilex = Input.tilex();
tiley = Input.tiley();
}
x = tilex*tilesize;
y = tiley*tilesize;
boolean valid = World.validPlace(tilex, tiley, player.recipe.result) && (android ||
Input.cursorNear());
x = tilex * tilesize;
y = tiley * tilesize;
boolean valid = World.validPlace(tilex, tiley, player.recipe.result) && (android || Input.cursorNear());
Vector2 offset = player.recipe.result.getPlaceOffset();
float si = MathUtils.sin(Timers.time() / 6f) + 1;
Draw.color(valid ? Color.PURPLE : Color.SCARLET);
Draw.thickness(2f);
Draw.linecrect(x + offset.x, y + offset.y,
tilesize * player.recipe.result.width + si,
tilesize * player.recipe.result.height + si);
Draw.linecrect(x + offset.x, y + offset.y, tilesize * player.recipe.result.width + si, tilesize * player.recipe.result.height + si);
player.recipe.result.drawPlace(tilex, tiley, valid);
@ -390,25 +405,27 @@ public class Renderer extends RendererModule{
//block breaking
if(Inputs.buttonDown(Buttons.RIGHT) && World.validBreak(Input.tilex(), Input.tiley())){
Tile tile = World.tile(Input.tilex(), Input.tiley());
if(tile.isLinked()) tile = tile.getLinked();
if(tile.isLinked())
tile = tile.getLinked();
Vector2 offset = tile.block().getPlaceOffset();
Draw.color(Color.YELLOW, Color.SCARLET, player.breaktime / tile.getBreakTime());
Draw.linecrect(tile.worldx() + offset.x, tile.worldy() + offset.y, tile.block().width * Vars.tilesize, tile.block().height * Vars.tilesize);
Draw.reset();
}else if(android && player.breaktime > 0){ //android block breaking
Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(0));
if(World.validBreak(Mathf.scl2(vec.x, tilesize), Mathf.scl2(vec.y, tilesize))){
Tile tile = World.tile(Mathf.scl2(vec.x, tilesize), Mathf.scl2(vec.y, tilesize));
float fract = player.breaktime / tile.getBreakTime();
Draw.color(Color.YELLOW, Color.SCARLET, fract);
Draw.circle(tile.worldx(), tile.worldy(), 4 + (1f - fract) * 26);
Draw.reset();
}
}
//draw selected block health
if(player.recipe == null && !ui.hasMouse()){
Tile tile = World.tile(Input.tilex(), Input.tiley());
@ -416,33 +433,33 @@ public class Renderer extends RendererModule{
Tile target = tile;
if(tile.isLinked())
target = tile.getLinked();
Vector2 offset = target.block().getPlaceOffset();
if(target.entity != null)
drawHealth(target.entity.x + offset.x, target.entity.y - 3f - target.block().height/2f * Vars.tilesize + offset.y,
target.entity.health, target.entity.maxhealth);
drawHealth(target.entity.x + offset.x, target.entity.y - 3f - target.block().height / 2f * Vars.tilesize + offset.y, target.entity.health, target.entity.maxhealth);
target.block().drawPixelOverlay(target);
}
}
boolean smoothcam = Settings.getBool("smoothcam");
boolean smoothcam = Settings.getBool("smoothcam");
//draw entity health bars
for(Entity entity : Entities.all()){
if(entity instanceof DestructibleEntity && !(entity instanceof TileEntity)){
DestructibleEntity dest = ((DestructibleEntity) entity);
if(dest instanceof Player && Vars.snapCamera && smoothcam && Settings.getBool("pixelate")){
drawHealth((int)dest.x, (int)dest.y - 7f, dest.health, dest.maxhealth);
drawHealth((int) dest.x, (int) dest.y - 7f, dest.health, dest.maxhealth);
}else{
drawHealth(dest.x, dest.y - 7f, dest.health, dest.maxhealth);
}
}
}
}
void drawHealth(float x, float y, float health, float maxhealth){
drawBar(Color.RED, x, y, health / maxhealth);
}

View File

@ -3,6 +3,7 @@ package io.anuke.mindustry;
import com.badlogic.gdx.graphics.Color;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Shader;
import io.anuke.ucore.util.Tmp;
@ -35,10 +36,14 @@ public class Shaders{
@Override
public void apply(){
float scale = Settings.getBool("pixelate") ? 1 : Core.cameraScale / Core.camera.zoom;
float scaling = Core.cameraScale / 4f / Core.camera.zoom;
shader.setUniformf("u_color", color);
shader.setUniformf("u_time", Timers.time());
shader.setUniformf("u_scaling", scaling);
shader.setUniformf("u_offset", Tmp.v1.set(Core.camera.position.x, Core.camera.position.y));
shader.setUniformf("u_texsize", Tmp.v1.set(region.getTexture().getWidth(), region.getTexture().getHeight()));
shader.setUniformf("u_texsize", Tmp.v1.set(region.getTexture().getWidth() / scale,
region.getTexture().getHeight() / scale));
}
}

View File

@ -665,7 +665,33 @@ public class UI extends SceneModule{
header.addImage(region).size(8*5).padTop(4).units(Unit.dp);
Label nameLabel = new Label(recipe.result.formalName);
nameLabel.setWrap(true);
header.add(nameLabel).padLeft(4).width(160f).units(Unit.dp);
header.add(nameLabel).padLeft(4).width(135f).units(Unit.dp);
//extra info
if(recipe.result.fullDescription != null){
header.addButton("?", ()->{
Label desclabel = new Label(recipe.result.fullDescription);
desclabel.setWrap(true);
boolean wasPaused = GameState.is(State.paused);
GameState.set(State.paused);
FloatingDialog d = new FloatingDialog("Block Info");
Table top = new Table();
top.left();
top.add(new Image(region)).size(8*5).units(Unit.dp);
top.add("[orange]"+recipe.result.formalName).padLeft(6f).units(Unit.dp);
d.content().add(top).fill().left();
d.content().row();
d.content().add(desclabel).width(600).units(Unit.dp);
d.buttons().addButton("OK", ()->{
if(!wasPaused) GameState.set(State.playing);
d.hide();
}).size(110, 50).pad(10f).units(Unit.dp);
d.show();
}).fillX().top().right().size(36f, 40f).units(Unit.dp);
}
desctable.add().pad(2).units(Unit.dp);

View File

@ -31,6 +31,8 @@ public class Vars{
public static boolean debug = false;
//whether to debug openGL info
public static boolean debugGL = false;
//whether to draw chunk borders
public static boolean debugChunks = false;
//whether turrets have infinite ammo (only with debug)
public static boolean infiniteAmmo = true;
//whether to show paths of enemies

View File

@ -13,6 +13,8 @@ public class DefenseBlocks{
stonewall = new Wall("stonewall"){{
health = 50;
formalName = "stone wall";
fullDescription =
"A cheap defensive block. Useful for protecting the core and turrets in the first few waves.";
}},
ironwall = new Wall("ironwall"){{

Binary file not shown.