1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-22 05:47:44 +03:00

Fixed building for HTML5

This commit is contained in:
Anuken 2017-12-08 20:59:40 -05:00
parent 404ec68570
commit aa6308fffc
11 changed files with 35 additions and 28 deletions

View File

@ -56,7 +56,8 @@ void main() {
color.a = ALPHA;
for(int i = 0; i < u_hitamount; i ++){
for(int i = 0; i < MAX_HITS; i ++){
if(i >= u_hitamount) break;
vec3 hit = u_hits[i];
float rad = hit.z * HIT_RADIUS;
float fract = 1.0 - hit.z;

View File

@ -3,6 +3,5 @@
<module>
<source path="io/anuke/mindustry" />
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.entities" />
<extend-configuration-property name="gdx.reflect.include" value="java.lang.Class" />
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.ucore.function.DelayRun" />
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.world.Tile" />
</module>

View File

@ -45,7 +45,7 @@ public class Vars{
//whether turrets have infinite ammo (only with debug)
public static boolean infiniteAmmo = false;
//whether to show paths of enemies
public static boolean showPaths = true;
public static boolean showPaths = false;
//if false, player is always hidden
public static boolean showPlayer = true;
//number of save slots-- increasing may lead to layout issues

View File

@ -10,7 +10,6 @@ import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.world.SpawnPoint;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
@ -72,8 +71,11 @@ public class Pathfind{
}
float dst = Vector2.dst(enemy.x, enemy.y, target.worldx(), target.worldy());
float nlinedist = enemy.node >= path.length - 1 ? 9999 :
pointLineDist(path[enemy.node].worldx(), path[enemy.node].worldy(),
path[enemy.node + 1].worldx(), path[enemy.node + 1].worldy(), enemy.x, enemy.y);
if(dst < 8){
if(dst < 8 || nlinedist < 8){
if(enemy.node <= path.length-2)
enemy.node ++;
@ -132,9 +134,7 @@ public class Pathfind{
enemy.path = Vars.control.getSpawnPoints().get(enemy.spawn).pathTiles;
int closest = findClosest(enemy.path, 0, enemy.x, enemy.y);
closest = findClosest(enemy.path, closest + 1, enemy.x, enemy.y);
//closest ++;
int closest = findClosest(enemy.path, enemy.x, enemy.y);
closest = Mathf.clamp(closest, 1, enemy.path.length-1);
Tile end = enemy.path[closest];
@ -142,23 +142,25 @@ public class Pathfind{
//if the enemy can't get to this node, teleport to it
if(enemy.node < enemy.path.length - 2 && Vars.world.raycastWorld(enemy.x, enemy.y, end.worldx(), end.worldy()) != null){
Timers.run(Mathf.random(20f), () -> enemy.set(end.worldx(), end.worldy()));
// Timers.run(Mathf.random(20f), () -> enemy.set(end.worldx(), end.worldy()));
}
}
private static int findClosest(Tile[] tiles, int offset, float x, float y){
int cindex = -1;
private static int findClosest(Tile[] tiles, float x, float y){
int cindex = -2;
float dst = Float.MAX_VALUE;
for(int i = offset; i < tiles.length; i ++){
for(int i = 0; i < tiles.length - 1; i ++){
Tile tile = tiles[i];
if(Vector2.dst(tile.worldx(), tile.worldy(), x, y) < dst){
dst = Vector2.dst(tile.worldx(), tile.worldy(), x, y);
Tile next = tiles[i + 1];
float d = pointLineDist(tile.worldx(), tile.worldy(), next.worldx(), next.worldy(), x, y);
if(d < dst){
dst = d;
cindex = i;
}
}
return cindex;
return cindex + 1;
}
private static int indexOf(Tile tile, Tile[] tiles){
@ -175,6 +177,13 @@ public class Pathfind{
return MathUtils.isEqual(vector.dst(x1, y1) + vector.dst(x2, y2), Vector2.dst(x1, y1, x2, y2), 0.01f);
}
private static float pointLineDist(float x, float y, float x2, float y2, float px, float py){
float l2 = Vector2.dst2(x, y, x2, y2);
float t = Math.max(0, Math.min(1, Vector2.dot(px - x, py - y, x2 - x, y2 - y) / l2));
Vector2 projection = Tmp.v1.set(x, y).add(Tmp.v2.set(x2, y2).sub(x, y).scl(t)); // Projection falls on the segment
return projection.dst(px, py);
}
private static Vector2 projectPoint(float x1, float y1, float x2, float y2, float pointx, float pointy){
float px = x2-x1, py = y2-y1, dAB = px*px + py*py;
float u = ((pointx - x1) * px + (pointy - y1) * py) / dAB;

View File

@ -271,7 +271,7 @@ public class Renderer extends RendererModule{
Draw.reset();
if(Vars.showPaths){
if(Vars.showPaths && Vars.debug){
drawPaths();
}

View File

@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.PixmapIO;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.ObjectMap;
@ -80,7 +79,7 @@ public class EditorControl extends Module{
if(Inputs.keyUp(Keys.E)){
try{
ClassReflection.getMethod(PixmapIO.class, "writePNG", FileHandle.class, Pixmap.class)
ClassReflection.getMethod(ClassReflection.forName("com.badlogic.gdx.graphics.PixmapIO"), "writePNG", FileHandle.class, Pixmap.class)
.invoke(Gdx.files.absolute("/home/anuke/Pictures/maps/out-" + TimeUtils.millis() + ".png"), pixmap);
}catch (Exception e){
throw new RuntimeException(e);

View File

@ -41,8 +41,10 @@ public class Shaders{
public void apply(){
float scale = Settings.getBool("pixelate") ? 1 : Core.cameraScale / Core.camera.zoom;
float scaling = Core.cameraScale / 4f / Core.camera.zoom;
shader.setUniform3fv("u_hits[0]", hits.items, 0, Math.min(hits.size, MAX_HITS));
shader.setUniformi("u_hitamount", Math.min(hits.size, MAX_HITS)/3);
if(hits.size > 0){
shader.setUniform3fv("u_hits[0]", hits.items, 0, Math.min(hits.size, MAX_HITS));
shader.setUniformi("u_hitamount", Math.min(hits.size, MAX_HITS)/3);
}
shader.setUniformf("u_color", color);
shader.setUniformf("u_time", Timers.time());
shader.setUniformf("u_scaling", scaling);

View File

@ -226,7 +226,7 @@ public class Enemy extends DestructibleEntity{
xvelocity = (x - lastx) / Timers.delta();
yvelocity = (y - lasty) / Timers.delta();
float minv = 0.0001f;
float minv = 0.08f;
if(xvelocity < minv && yvelocity < minv && node > 0){
idletime += Timers.delta();

View File

@ -2,9 +2,6 @@ package io.anuke.mindustry.ui;
import static io.anuke.mindustry.Vars.ui;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
@ -44,7 +41,7 @@ public class MenuDialog extends FloatingDialog{
ui.showPrefs();
});
if(Gdx.app.getType() != ApplicationType.WebGL){
if(!Vars.gwt){
content().row();
content().addButton("Save Game", () -> {
save.show();

View File

@ -28,7 +28,7 @@
function preventUseOfDefaultKeys(event) {
if (event.keyCode == 32 || event.keyCode == 27 || event.keyCode == 38 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 40) {
if (event.keyCode == 32 || event.keyCode == 27 || event.keyCode == 38 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 40 || event.keyCode == 17){
event.preventDefault();
}
}

View File

@ -6,7 +6,7 @@ canvas {
}
body {
background-color: black;
background-color: transparent;
margin: 0px;
padding: 0px;
}