Merge pull request #1991 from kevlahnota/newmaster2

update Adventure Matchscreen
This commit is contained in:
Anthony Calosa
2022-12-01 15:16:52 +08:00
committed by GitHub
11 changed files with 611 additions and 512 deletions

View File

@@ -350,6 +350,9 @@ public class Forge implements ApplicationListener {
try { try {
FileHandle transitionFile = Config.instance().getFile("ui/transition.png"); FileHandle transitionFile = Config.instance().getFile("ui/transition.png");
FileHandle titleBGFile = Forge.isLandscapeMode() ? Config.instance().getFile("ui/title_bg.png") : Config.instance().getFile("ui/title_bg_portrait.png"); FileHandle titleBGFile = Forge.isLandscapeMode() ? Config.instance().getFile("ui/title_bg.png") : Config.instance().getFile("ui/title_bg_portrait.png");
FileHandle vsIcon = Config.instance().getFile("ui/vs.png");
if (vsIcon.exists())
Forge.getAssets().fallback_skins().put(2, new Texture(vsIcon));
if (transitionFile.exists()) if (transitionFile.exists())
Forge.getAssets().fallback_skins().put(1, new Texture(transitionFile)); Forge.getAssets().fallback_skins().put(1, new Texture(transitionFile));
if (titleBGFile.exists()) if (titleBGFile.exists())

View File

@@ -5,6 +5,7 @@ import java.util.Deque;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.*; import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.ShaderProgram;
@@ -46,6 +47,7 @@ public class Graphics {
private final ShaderProgram shaderRipple = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragRipple); private final ShaderProgram shaderRipple = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragRipple);
private final ShaderProgram shaderPixelateWarp = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragPixelateShaderWarp); private final ShaderProgram shaderPixelateWarp = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragPixelateShaderWarp);
private final ShaderProgram shaderChromaticAbberation = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragChromaticAbberation); private final ShaderProgram shaderChromaticAbberation = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragChromaticAbberation);
private final ShaderProgram shaderHueShift = new ShaderProgram(Shaders.vertPixelateShader, Shaders.fragHueShift);
private Texture dummyTexture = null; private Texture dummyTexture = null;
@@ -92,7 +94,7 @@ public class Graphics {
shaderGrayscale.dispose(); shaderGrayscale.dispose();
shaderUnderwater.dispose(); shaderUnderwater.dispose();
shaderWarp.dispose(); shaderWarp.dispose();
if(dummyTexture != null) dummyTexture.dispose(); if (dummyTexture != null) dummyTexture.dispose();
} }
public SpriteBatch getBatch() { public SpriteBatch getBatch() {
@@ -102,6 +104,7 @@ public class Graphics {
public boolean startClip() { public boolean startClip() {
return startClip(0, 0, bounds.width, bounds.height); return startClip(0, 0, bounds.width, bounds.height);
} }
public boolean startClip(float x, float y, float w, float h) { public boolean startClip(float x, float y, float w, float h) {
batch.flush(); //must flush batch to prevent other things not rendering batch.flush(); //must flush batch to prevent other things not rendering
@@ -115,22 +118,40 @@ public class Graphics {
float maxY = minY; float maxY = minY;
tmp.set(clip.x + clip.width, clip.y, 0); tmp.set(clip.x + clip.width, clip.y, 0);
tmp.mul(batch.getTransformMatrix()); tmp.mul(batch.getTransformMatrix());
if (tmp.x < minX) { minX = tmp.x; } if (tmp.x < minX) {
else if (tmp.x > maxX) { maxX = tmp.x; } minX = tmp.x;
if (tmp.y < minY) { minY = tmp.y; } } else if (tmp.x > maxX) {
else if (tmp.y > maxY) { maxY = tmp.y; } maxX = tmp.x;
}
if (tmp.y < minY) {
minY = tmp.y;
} else if (tmp.y > maxY) {
maxY = tmp.y;
}
tmp.set(clip.x + clip.width, clip.y + clip.height, 0); tmp.set(clip.x + clip.width, clip.y + clip.height, 0);
tmp.mul(batch.getTransformMatrix()); tmp.mul(batch.getTransformMatrix());
if (tmp.x < minX) { minX = tmp.x; } if (tmp.x < minX) {
else if (tmp.x > maxX) { maxX = tmp.x; } minX = tmp.x;
if (tmp.y < minY) { minY = tmp.y; } } else if (tmp.x > maxX) {
else if (tmp.y > maxY) { maxY = tmp.y; } maxX = tmp.x;
}
if (tmp.y < minY) {
minY = tmp.y;
} else if (tmp.y > maxY) {
maxY = tmp.y;
}
tmp.set(clip.x, clip.y + clip.height, 0); tmp.set(clip.x, clip.y + clip.height, 0);
tmp.mul(batch.getTransformMatrix()); tmp.mul(batch.getTransformMatrix());
if (tmp.x < minX) { minX = tmp.x; } if (tmp.x < minX) {
else if (tmp.x > maxX) { maxX = tmp.x; } minX = tmp.x;
if (tmp.y < minY) { minY = tmp.y; } } else if (tmp.x > maxX) {
else if (tmp.y > maxY) { maxY = tmp.y; } maxX = tmp.x;
}
if (tmp.y < minY) {
minY = tmp.y;
} else if (tmp.y > maxY) {
maxY = tmp.y;
}
clip.set(minX, minY, maxX - minX, maxY - minY); clip.set(minX, minY, maxX - minX, maxY - minY);
} }
@@ -140,12 +161,12 @@ public class Graphics {
} }
return true; return true;
} }
public void endClip() { public void endClip() {
if (failedClipCount == 0) { if (failedClipCount == 0) {
batch.flush(); //must flush batch to ensure stuffed rendered during clip respects that clip batch.flush(); //must flush batch to ensure stuffed rendered during clip respects that clip
ScissorStack.popScissors(); ScissorStack.popScissors();
} } else {
else {
failedClipCount--; failedClipCount--;
} }
} }
@@ -159,8 +180,7 @@ public class Graphics {
bounds = new Rectangle(parentBounds.x + displayObj.getLeft(), parentBounds.y + displayObj.getTop(), displayObj.getWidth(), displayObj.getHeight()); bounds = new Rectangle(parentBounds.x + displayObj.getLeft(), parentBounds.y + displayObj.getTop(), displayObj.getWidth(), displayObj.getHeight());
if (!Dtransforms.isEmpty()) { //transform screen position if needed by applying transform matrix to rectangle if (!Dtransforms.isEmpty()) { //transform screen position if needed by applying transform matrix to rectangle
updateScreenPosForRotation(displayObj); updateScreenPosForRotation(displayObj);
} } else {
else {
displayObj.screenPos.set(bounds); displayObj.screenPos.set(bounds);
} }
@@ -172,8 +192,7 @@ public class Graphics {
if (displayObj.getRotate90()) { //use top-right corner of bounds as pivot point if (displayObj.getRotate90()) { //use top-right corner of bounds as pivot point
startRotateTransform(displayObj.getWidth(), 0, -90); startRotateTransform(displayObj.getWidth(), 0, -90);
updateScreenPosForRotation(displayObj); updateScreenPosForRotation(displayObj);
} } else if (displayObj.getRotate180()) { //use center of bounds as pivot point
else if (displayObj.getRotate180()) { //use center of bounds as pivot point
startRotateTransform(displayObj.getWidth() / 2, displayObj.getHeight() / 2, 180); startRotateTransform(displayObj.getWidth() / 2, displayObj.getHeight() / 2, 180);
//screen position won't change for this object from a 180 degree rotation //screen position won't change for this object from a 180 degree rotation
} }
@@ -181,7 +200,7 @@ public class Graphics {
displayObj.draw(this); displayObj.draw(this);
if (displayObj.getRotate90() || displayObj.getRotate180()) { if (displayObj.getRotate90() || displayObj.getRotate180()) {
endTransform(); endTransform();
} }
visibleBounds = backup; visibleBounds = backup;
@@ -201,24 +220,42 @@ public class Graphics {
tmp.set(bounds.x + bounds.width, regionHeight - bounds.y, 0); tmp.set(bounds.x + bounds.width, regionHeight - bounds.y, 0);
tmp.mul(batch.getTransformMatrix()); tmp.mul(batch.getTransformMatrix());
tmp.y = regionHeight - tmp.y; tmp.y = regionHeight - tmp.y;
if (tmp.x < minX) { minX = tmp.x; } if (tmp.x < minX) {
else if (tmp.x > maxX) { maxX = tmp.x; } minX = tmp.x;
if (tmp.y < minY) { minY = tmp.y; } } else if (tmp.x > maxX) {
else if (tmp.y > maxY) { maxY = tmp.y; } maxX = tmp.x;
}
if (tmp.y < minY) {
minY = tmp.y;
} else if (tmp.y > maxY) {
maxY = tmp.y;
}
tmp.set(bounds.x + bounds.width, regionHeight - bounds.y - bounds.height, 0); tmp.set(bounds.x + bounds.width, regionHeight - bounds.y - bounds.height, 0);
tmp.mul(batch.getTransformMatrix()); tmp.mul(batch.getTransformMatrix());
tmp.y = regionHeight - tmp.y; tmp.y = regionHeight - tmp.y;
if (tmp.x < minX) { minX = tmp.x; } if (tmp.x < minX) {
else if (tmp.x > maxX) { maxX = tmp.x; } minX = tmp.x;
if (tmp.y < minY) { minY = tmp.y; } } else if (tmp.x > maxX) {
else if (tmp.y > maxY) { maxY = tmp.y; } maxX = tmp.x;
}
if (tmp.y < minY) {
minY = tmp.y;
} else if (tmp.y > maxY) {
maxY = tmp.y;
}
tmp.set(bounds.x, regionHeight - bounds.y - bounds.height, 0); tmp.set(bounds.x, regionHeight - bounds.y - bounds.height, 0);
tmp.mul(batch.getTransformMatrix()); tmp.mul(batch.getTransformMatrix());
tmp.y = regionHeight - tmp.y; tmp.y = regionHeight - tmp.y;
if (tmp.x < minX) { minX = tmp.x; } if (tmp.x < minX) {
else if (tmp.x > maxX) { maxX = tmp.x; } minX = tmp.x;
if (tmp.y < minY) { minY = tmp.y; } } else if (tmp.x > maxX) {
else if (tmp.y > maxY) { maxY = tmp.y; } maxX = tmp.x;
}
if (tmp.y < minY) {
minY = tmp.y;
} else if (tmp.y > maxY) {
maxY = tmp.y;
}
displayObj.screenPos.set(minX, minY, maxX - minX, maxY - minY); displayObj.screenPos.set(minX, minY, maxX - minX, maxY - minY);
} }
@@ -226,6 +263,7 @@ public class Graphics {
public void drawLine(float thickness, FSkinColor skinColor, float x1, float y1, float x2, float y2) { public void drawLine(float thickness, FSkinColor skinColor, float x1, float y1, float x2, float y2) {
drawLine(thickness, skinColor.getColor(), x1, y1, x2, y2); drawLine(thickness, skinColor.getColor(), x1, y1, x2, y2);
} }
public void drawLine(float thickness, Color color, float x1, float y1, float x2, float y2) { public void drawLine(float thickness, Color color, float x1, float y1, float x2, float y2) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
@@ -264,16 +302,17 @@ public class Graphics {
public void drawLineArrow(float arrowThickness, FSkinColor skinColor, float x1, float y1, float x2, float y2) { public void drawLineArrow(float arrowThickness, FSkinColor skinColor, float x1, float y1, float x2, float y2) {
fillCircle(skinColor.getColor(), x2, y2, arrowThickness); fillCircle(skinColor.getColor(), x2, y2, arrowThickness);
drawLineArrow(arrowThickness, skinColor.getColor(), x1, y1, x2, y2); drawLineArrow(arrowThickness, skinColor.getColor(), x1, y1, x2, y2);
fillCircle(Color.WHITE, x2, y2, arrowThickness/2); fillCircle(Color.WHITE, x2, y2, arrowThickness / 2);
drawLine(arrowThickness/3, Color.WHITE, x1, y1, x2, y2); drawLine(arrowThickness / 3, Color.WHITE, x1, y1, x2, y2);
} }
public void drawLineArrow(float thickness, Color color, float x1, float y1, float x2, float y2) { public void drawLineArrow(float thickness, Color color, float x1, float y1, float x2, float y2) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
float angle = new Vector2(x1 - x2, y1 - y2).angleRad(); float angle = new Vector2(x1 - x2, y1 - y2).angleRad();
float arrowHeadRotation = (float)(Math.PI * 0.8f); float arrowHeadRotation = (float) (Math.PI * 0.8f);
Vector2 arrowCorner3 = new Vector2(x2 + (thickness/3) * (float)Math.cos(angle + arrowHeadRotation), y2 + (thickness/3) * (float)Math.sin(angle + arrowHeadRotation)); Vector2 arrowCorner3 = new Vector2(x2 + (thickness / 3) * (float) Math.cos(angle + arrowHeadRotation), y2 + (thickness / 3) * (float) Math.sin(angle + arrowHeadRotation));
Vector2 arrowCorner4 = new Vector2(x2 + (thickness/3) * (float)Math.cos(angle - arrowHeadRotation), y2 + (thickness/3) * (float)Math.sin(angle - arrowHeadRotation)); Vector2 arrowCorner4 = new Vector2(x2 + (thickness / 3) * (float) Math.cos(angle - arrowHeadRotation), y2 + (thickness / 3) * (float) Math.sin(angle - arrowHeadRotation));
if (thickness > 1) { if (thickness > 1) {
Gdx.gl.glLineWidth(thickness); Gdx.gl.glLineWidth(thickness);
@@ -306,9 +345,11 @@ public class Graphics {
batch.begin(); batch.begin();
} }
public void drawArrow(float borderThickness, float arrowThickness, float arrowSize, FSkinColor skinColor, float x1, float y1, float x2, float y2) { public void drawArrow(float borderThickness, float arrowThickness, float arrowSize, FSkinColor skinColor, float x1, float y1, float x2, float y2) {
drawArrow(borderThickness, arrowThickness, arrowSize, skinColor.getColor(), x1, y1, x2, y2); drawArrow(borderThickness, arrowThickness, arrowSize, skinColor.getColor(), x1, y1, x2, y2);
} }
public void drawArrow(float borderThickness, float arrowThickness, float arrowSize, Color color, float x1, float y1, float x2, float y2) { public void drawArrow(float borderThickness, float arrowThickness, float arrowSize, Color color, float x1, float y1, float x2, float y2) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
@@ -319,31 +360,31 @@ public class Graphics {
Gdx.gl.glEnable(GL_LINE_SMOOTH); Gdx.gl.glEnable(GL_LINE_SMOOTH);
float angle = new Vector2(x2 - x1, y2 - y1).angleRad(); float angle = new Vector2(x2 - x1, y2 - y1).angleRad();
float perpRotation = (float)(Math.PI * 0.5f); float perpRotation = (float) (Math.PI * 0.5f);
float arrowHeadRotation = (float)(Math.PI * 0.8f); float arrowHeadRotation = (float) (Math.PI * 0.8f);
float arrowTipAngle = (float)(Math.PI - arrowHeadRotation); float arrowTipAngle = (float) (Math.PI - arrowHeadRotation);
float halfThickness = arrowThickness / 2; float halfThickness = arrowThickness / 2;
int index = 0; int index = 0;
float[] vertices = new float[14]; float[] vertices = new float[14];
Vector2 arrowCorner1 = new Vector2(x2 + arrowSize * (float)Math.cos(angle + arrowHeadRotation), y2 + arrowSize * (float)Math.sin(angle + arrowHeadRotation)); Vector2 arrowCorner1 = new Vector2(x2 + arrowSize * (float) Math.cos(angle + arrowHeadRotation), y2 + arrowSize * (float) Math.sin(angle + arrowHeadRotation));
Vector2 arrowCorner2 = new Vector2(x2 + arrowSize * (float)Math.cos(angle - arrowHeadRotation), y2 + arrowSize * (float)Math.sin(angle - arrowHeadRotation)); Vector2 arrowCorner2 = new Vector2(x2 + arrowSize * (float) Math.cos(angle - arrowHeadRotation), y2 + arrowSize * (float) Math.sin(angle - arrowHeadRotation));
float arrowCornerLen = (arrowCorner1.dst(arrowCorner2) - arrowThickness) / 2; float arrowCornerLen = (arrowCorner1.dst(arrowCorner2) - arrowThickness) / 2;
float arrowHeadLen = arrowSize * (float)Math.cos(arrowTipAngle); float arrowHeadLen = arrowSize * (float) Math.cos(arrowTipAngle);
index = addVertex(arrowCorner1.x, arrowCorner1.y, vertices, index); index = addVertex(arrowCorner1.x, arrowCorner1.y, vertices, index);
index = addVertex(x2, y2, vertices, index); index = addVertex(x2, y2, vertices, index);
index = addVertex(arrowCorner2.x, arrowCorner2.y, vertices, index); index = addVertex(arrowCorner2.x, arrowCorner2.y, vertices, index);
index = addVertex(arrowCorner2.x + arrowCornerLen * (float)Math.cos(angle + perpRotation), arrowCorner2.y + arrowCornerLen * (float)Math.sin(angle + perpRotation), vertices, index); index = addVertex(arrowCorner2.x + arrowCornerLen * (float) Math.cos(angle + perpRotation), arrowCorner2.y + arrowCornerLen * (float) Math.sin(angle + perpRotation), vertices, index);
index = addVertex(x1 + halfThickness * (float)Math.cos(angle - perpRotation), y1 + halfThickness * (float)Math.sin(angle - perpRotation), vertices, index); index = addVertex(x1 + halfThickness * (float) Math.cos(angle - perpRotation), y1 + halfThickness * (float) Math.sin(angle - perpRotation), vertices, index);
index = addVertex(x1 + halfThickness * (float)Math.cos(angle + perpRotation), y1 + halfThickness * (float)Math.sin(angle + perpRotation), vertices, index); index = addVertex(x1 + halfThickness * (float) Math.cos(angle + perpRotation), y1 + halfThickness * (float) Math.sin(angle + perpRotation), vertices, index);
index = addVertex(arrowCorner1.x + arrowCornerLen * (float)Math.cos(angle - perpRotation), arrowCorner1.y + arrowCornerLen * (float)Math.sin(angle - perpRotation), vertices, index); index = addVertex(arrowCorner1.x + arrowCornerLen * (float) Math.cos(angle - perpRotation), arrowCorner1.y + arrowCornerLen * (float) Math.sin(angle - perpRotation), vertices, index);
//draw arrow tail //draw arrow tail
startShape(ShapeType.Filled); startShape(ShapeType.Filled);
shapeRenderer.setColor(color); shapeRenderer.setColor(color);
shapeRenderer.rectLine(adjustX(x1), adjustY(y1, 0), shapeRenderer.rectLine(adjustX(x1), adjustY(y1, 0),
adjustX(x2 - arrowHeadLen * (float)Math.cos(angle)), //shorten tail to make room for arrow head adjustX(x2 - arrowHeadLen * (float) Math.cos(angle)), //shorten tail to make room for arrow head
adjustY(y2 - arrowHeadLen * (float)Math.sin(angle), 0), arrowThickness); adjustY(y2 - arrowHeadLen * (float) Math.sin(angle), 0), arrowThickness);
//draw arrow head //draw arrow head
shapeRenderer.triangle(vertices[0], vertices[1], vertices[2], vertices[3], vertices[4], vertices[5]); shapeRenderer.triangle(vertices[0], vertices[1], vertices[2], vertices[3], vertices[4], vertices[5]);
@@ -381,6 +422,7 @@ public class Graphics {
public void drawRoundRect(float thickness, FSkinColor skinColor, float x, float y, float w, float h, float cornerRadius) { public void drawRoundRect(float thickness, FSkinColor skinColor, float x, float y, float w, float h, float cornerRadius) {
drawRoundRect(thickness, skinColor.getColor(), x, y, w, h, cornerRadius); drawRoundRect(thickness, skinColor.getColor(), x, y, w, h, cornerRadius);
} }
public void drawRoundRect(float thickness, Color color, float x, float y, float w, float h, float cornerRadius) { public void drawRoundRect(float thickness, Color color, float x, float y, float w, float h, float cornerRadius) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
@@ -408,8 +450,8 @@ public class Graphics {
shapeRenderer.arc(adjustX(x) + w - cornerRadius, adjustY(y + cornerRadius, 0), cornerRadius, 0f, 90f); shapeRenderer.arc(adjustX(x) + w - cornerRadius, adjustY(y + cornerRadius, 0), cornerRadius, 0f, 90f);
shapeRenderer.arc(adjustX(x) + w - cornerRadius, adjustY(y + h - cornerRadius, 0), cornerRadius, 270, 90f); shapeRenderer.arc(adjustX(x) + w - cornerRadius, adjustY(y + h - cornerRadius, 0), cornerRadius, 270, 90f);
shapeRenderer.arc(adjustX(x) + cornerRadius, adjustY(y + h - cornerRadius, 0), cornerRadius, 180, 90f); shapeRenderer.arc(adjustX(x) + cornerRadius, adjustY(y + h - cornerRadius, 0), cornerRadius, 180, 90f);
shapeRenderer.rect(adjustX(x), adjustY(y+cornerRadius, h-cornerRadius*2), w, h-cornerRadius*2); shapeRenderer.rect(adjustX(x), adjustY(y + cornerRadius, h - cornerRadius * 2), w, h - cornerRadius * 2);
shapeRenderer.rect(adjustX(x+cornerRadius), adjustY(y, h), w-cornerRadius*2, h); shapeRenderer.rect(adjustX(x + cornerRadius), adjustY(y, h), w - cornerRadius * 2, h);
endShape(); endShape();
@@ -429,6 +471,7 @@ public class Graphics {
public void fillRoundRect(FSkinColor skinColor, float x, float y, float w, float h, float cornerRadius) { public void fillRoundRect(FSkinColor skinColor, float x, float y, float w, float h, float cornerRadius) {
fillRoundRect(skinColor.getColor(), x, y, w, h, cornerRadius); fillRoundRect(skinColor.getColor(), x, y, w, h, cornerRadius);
} }
public void fillRoundRect(Color color, float x, float y, float w, float h, float cornerRadius) { public void fillRoundRect(Color color, float x, float y, float w, float h, float cornerRadius) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
if (alphaComposite < 1) { if (alphaComposite < 1) {
@@ -443,8 +486,8 @@ public class Graphics {
shapeRenderer.arc(adjustX(x) + w - cornerRadius, adjustY(y + cornerRadius, 0), cornerRadius, 0f, 90f); shapeRenderer.arc(adjustX(x) + w - cornerRadius, adjustY(y + cornerRadius, 0), cornerRadius, 0f, 90f);
shapeRenderer.arc(adjustX(x) + w - cornerRadius, adjustY(y + h - cornerRadius, 0), cornerRadius, 270, 90f); shapeRenderer.arc(adjustX(x) + w - cornerRadius, adjustY(y + h - cornerRadius, 0), cornerRadius, 270, 90f);
shapeRenderer.arc(adjustX(x) + cornerRadius, adjustY(y + h - cornerRadius, 0), cornerRadius, 180, 90f); shapeRenderer.arc(adjustX(x) + cornerRadius, adjustY(y + h - cornerRadius, 0), cornerRadius, 180, 90f);
shapeRenderer.rect(adjustX(x), adjustY(y+cornerRadius, h-cornerRadius*2), w, h-cornerRadius*2); shapeRenderer.rect(adjustX(x), adjustY(y + cornerRadius, h - cornerRadius * 2), w, h - cornerRadius * 2);
shapeRenderer.rect(adjustX(x+cornerRadius), adjustY(y, h), w-cornerRadius*2, h); shapeRenderer.rect(adjustX(x + cornerRadius), adjustY(y, h), w - cornerRadius * 2, h);
endShape(); endShape();
if (color.a < 1) { if (color.a < 1) {
Gdx.gl.glDisable(GL_BLEND); Gdx.gl.glDisable(GL_BLEND);
@@ -455,6 +498,7 @@ public class Graphics {
public void drawRect(float thickness, FSkinColor skinColor, float x, float y, float w, float h) { public void drawRect(float thickness, FSkinColor skinColor, float x, float y, float w, float h) {
drawRect(thickness, skinColor.getColor(), x, y, w, h); drawRect(thickness, skinColor.getColor(), x, y, w, h);
} }
public void drawRect(float thickness, Color color, float x, float y, float w, float h) { public void drawRect(float thickness, Color color, float x, float y, float w, float h) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
@@ -480,16 +524,18 @@ public class Graphics {
batch.begin(); batch.begin();
} }
public void drawRectLines(float thickness, Color color, float x, float y, float w, float h) { public void drawRectLines(float thickness, Color color, float x, float y, float w, float h) {
drawLine(thickness, color, x, y, x+w, y); drawLine(thickness, color, x, y, x + w, y);
drawLine(thickness, color, x+thickness/2f, y+thickness/2f, x+thickness/2f, y+h-thickness/2f); drawLine(thickness, color, x + thickness / 2f, y + thickness / 2f, x + thickness / 2f, y + h - thickness / 2f);
drawLine(thickness, color, x, y+h, x+w, y+h); drawLine(thickness, color, x, y + h, x + w, y + h);
drawLine(thickness, color, x+w-thickness/2f, y+thickness/2f, x+w-thickness/2f, y+h-thickness/2f); drawLine(thickness, color, x + w - thickness / 2f, y + thickness / 2f, x + w - thickness / 2f, y + h - thickness / 2f);
} }
public void fillRect(FSkinColor skinColor, float x, float y, float w, float h) { public void fillRect(FSkinColor skinColor, float x, float y, float w, float h) {
fillRect(skinColor.getColor(), x, y, w, h); fillRect(skinColor.getColor(), x, y, w, h);
} }
public void fillRect(Color color, float x, float y, float w, float h) { public void fillRect(Color color, float x, float y, float w, float h) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
@@ -515,6 +561,7 @@ public class Graphics {
public void drawCircle(float thickness, FSkinColor skinColor, float x, float y, float radius) { public void drawCircle(float thickness, FSkinColor skinColor, float x, float y, float radius) {
drawCircle(thickness, skinColor.getColor(), x, y, radius); drawCircle(thickness, skinColor.getColor(), x, y, radius);
} }
public void drawCircle(float thickness, Color color, float x, float y, float radius) { public void drawCircle(float thickness, Color color, float x, float y, float radius) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
@@ -544,6 +591,7 @@ public class Graphics {
public void fillCircle(FSkinColor skinColor, float x, float y, float radius) { public void fillCircle(FSkinColor skinColor, float x, float y, float radius) {
fillCircle(skinColor.getColor(), x, y, radius); fillCircle(skinColor.getColor(), x, y, radius);
} }
public void fillCircle(Color color, float x, float y, float radius) { public void fillCircle(Color color, float x, float y, float radius) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
@@ -569,6 +617,7 @@ public class Graphics {
public void fillTriangle(FSkinColor skinColor, float x1, float y1, float x2, float y2, float x3, float y3) { public void fillTriangle(FSkinColor skinColor, float x1, float y1, float x2, float y2, float x3, float y3) {
fillTriangle(skinColor.getColor(), x1, y1, x2, y2, x3, y3); fillTriangle(skinColor.getColor(), x1, y1, x2, y2, x3, y3);
} }
public void fillTriangle(Color color, float x1, float y1, float x2, float y2, float x3, float y3) { public void fillTriangle(Color color, float x1, float y1, float x2, float y2, float x3, float y3) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
@@ -594,12 +643,15 @@ public class Graphics {
public void fillGradientRect(FSkinColor skinColor1, FSkinColor skinColor2, boolean vertical, float x, float y, float w, float h) { public void fillGradientRect(FSkinColor skinColor1, FSkinColor skinColor2, boolean vertical, float x, float y, float w, float h) {
fillGradientRect(skinColor1.getColor(), skinColor2.getColor(), vertical, x, y, w, h); fillGradientRect(skinColor1.getColor(), skinColor2.getColor(), vertical, x, y, w, h);
} }
public void fillGradientRect(FSkinColor skinColor1, Color color2, boolean vertical, float x, float y, float w, float h) { public void fillGradientRect(FSkinColor skinColor1, Color color2, boolean vertical, float x, float y, float w, float h) {
fillGradientRect(skinColor1.getColor(), color2, vertical, x, y, w, h); fillGradientRect(skinColor1.getColor(), color2, vertical, x, y, w, h);
} }
public void fillGradientRect(Color color1, FSkinColor skinColor2, boolean vertical, float x, float y, float w, float h) { public void fillGradientRect(Color color1, FSkinColor skinColor2, boolean vertical, float x, float y, float w, float h) {
fillGradientRect(color1, skinColor2.getColor(), vertical, x, y, w, h); fillGradientRect(color1, skinColor2.getColor(), vertical, x, y, w, h);
} }
public void fillGradientRect(Color color1, Color color2, boolean vertical, float x, float y, float w, float h) { public void fillGradientRect(Color color1, Color color2, boolean vertical, float x, float y, float w, float h) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
@@ -654,17 +706,21 @@ public class Graphics {
alphaComposite = alphaComposite0; alphaComposite = alphaComposite0;
batch.setColor(new Color(1, 1, 1, alphaComposite)); batch.setColor(new Color(1, 1, 1, alphaComposite));
} }
public void resetAlphaComposite() { public void resetAlphaComposite() {
alphaComposite = 1; alphaComposite = 1;
batch.setColor(Color.WHITE); batch.setColor(Color.WHITE);
} }
public float getfloatAlphaComposite() { return alphaComposite; }
public float getfloatAlphaComposite() {
return alphaComposite;
}
public void drawBorderImage(FImage image, Color borderColor, Color tintColor, float x, float y, float w, float h, boolean tint) { public void drawBorderImage(FImage image, Color borderColor, Color tintColor, float x, float y, float w, float h, boolean tint) {
float oldalpha = alphaComposite; float oldalpha = alphaComposite;
if(tint && !tintColor.equals(borderColor)){ if (tint && !tintColor.equals(borderColor)) {
drawRoundRect(2f, borderLining(borderColor.toString()), x, y, w, h, (h-w)/12); drawRoundRect(2f, borderLining(borderColor.toString()), x, y, w, h, (h - w) / 12);
fillRoundRect(tintColor, x, y, w, h, (h-w)/12); fillRoundRect(tintColor, x, y, w, h, (h - w) / 12);
} else { } else {
if (image != null) { if (image != null) {
image.draw(this, x, y, w, h); image.draw(this, x, y, w, h);
@@ -673,17 +729,20 @@ public class Graphics {
} }
setAlphaComposite(oldalpha); setAlphaComposite(oldalpha);
} }
public void drawborderImage(Color borderColor, float x, float y, float w, float h) { public void drawborderImage(Color borderColor, float x, float y, float w, float h) {
float oldalpha = alphaComposite; float oldalpha = alphaComposite;
fillRoundRect(borderColor, x, y, w, h, (h-w)/12); fillRoundRect(borderColor, x, y, w, h, (h - w) / 12);
setAlphaComposite(oldalpha); setAlphaComposite(oldalpha);
} }
public void drawImage(FImage image, Color borderColor, float x, float y, float w, float h) { public void drawImage(FImage image, Color borderColor, float x, float y, float w, float h) {
if (image == null) if (image == null)
return; return;
image.draw(this, x, y, w, h); image.draw(this, x, y, w, h);
fillRoundRect(borderColor, x+1, y+1, w-1.5f, h-1.5f, (h-w)/10);//used by zoom let some edges show... fillRoundRect(borderColor, x + 1, y + 1, w - 1.5f, h - 1.5f, (h - w) / 10);//used by zoom let some edges show...
} }
public void drawAvatarImage(FImage image, float x, float y, float w, float h, boolean drawGrayscale) { public void drawAvatarImage(FImage image, float x, float y, float w, float h, boolean drawGrayscale) {
if (image == null) if (image == null)
return; return;
@@ -704,6 +763,7 @@ public class Graphics {
batch.begin(); batch.begin();
} }
} }
public void drawCardImage(FImage image, TextureRegion damage_overlay, float x, float y, float w, float h, boolean drawGrayscale, boolean damaged) { public void drawCardImage(FImage image, TextureRegion damage_overlay, float x, float y, float w, float h, boolean drawGrayscale, boolean damaged) {
if (image == null) if (image == null)
return; return;
@@ -726,6 +786,7 @@ public class Graphics {
batch.begin(); batch.begin();
} }
} }
public void drawCardImage(Texture image, TextureRegion damage_overlay, float x, float y, float w, float h, boolean drawGrayscale, boolean damaged) { public void drawCardImage(Texture image, TextureRegion damage_overlay, float x, float y, float w, float h, boolean drawGrayscale, boolean damaged) {
if (!drawGrayscale) { if (!drawGrayscale) {
batch.draw(image, adjustX(x), adjustY(y, h), w, h); batch.draw(image, adjustX(x), adjustY(y, h), w, h);
@@ -746,6 +807,7 @@ public class Graphics {
batch.begin(); batch.begin();
} }
} }
public void drawCardImage(TextureRegion image, TextureRegion damage_overlay, float x, float y, float w, float h, boolean drawGrayscale, boolean damaged) { public void drawCardImage(TextureRegion image, TextureRegion damage_overlay, float x, float y, float w, float h, boolean drawGrayscale, boolean damaged) {
if (image != null) { if (image != null) {
if (!drawGrayscale) { if (!drawGrayscale) {
@@ -768,6 +830,7 @@ public class Graphics {
} }
} }
} }
public void drawGrayTransitionImage(FImage image, float x, float y, float w, float h, float percentage) { public void drawGrayTransitionImage(FImage image, float x, float y, float w, float h, float percentage) {
if (image == null) if (image == null)
return; return;
@@ -784,6 +847,7 @@ public class Graphics {
batch.setShader(null); batch.setShader(null);
batch.begin(); batch.begin();
} }
public void drawGrayTransitionImage(Texture image, float x, float y, float w, float h, boolean withDarkOverlay, float percentage) { public void drawGrayTransitionImage(Texture image, float x, float y, float w, float h, boolean withDarkOverlay, float percentage) {
batch.end(); batch.end();
shaderGrayscale.bind(); shaderGrayscale.bind();
@@ -798,6 +862,7 @@ public class Graphics {
batch.setShader(null); batch.setShader(null);
batch.begin(); batch.begin();
} }
public void drawGrayTransitionImage(TextureRegion image, float x, float y, float w, float h, boolean withDarkOverlay, float percentage) { public void drawGrayTransitionImage(TextureRegion image, float x, float y, float w, float h, boolean withDarkOverlay, float percentage) {
batch.end(); batch.end();
shaderGrayscale.bind(); shaderGrayscale.bind();
@@ -812,6 +877,47 @@ public class Graphics {
batch.setShader(null); batch.setShader(null);
batch.begin(); batch.begin();
} }
public void drawHueShift(Texture image, float x, float y, float w, float h, Float time) {
if (image == null)
return;
if (time != null) {
batch.end();
shaderHueShift.bind();
shaderHueShift.setUniformf("u_time", time);
batch.setShader(shaderHueShift);
batch.begin();
//draw
batch.draw(image, x, y, w, h);
//reset
batch.end();
batch.setShader(null);
batch.begin();
} else {
drawImage(image, x, y, w, h);
}
}
public void drawHueShift(TextureRegion image, float x, float y, float w, float h, Float time) {
if (image == null)
return;
if (time != null) {
batch.end();
shaderHueShift.bind();
shaderHueShift.setUniformf("u_time", time);
batch.setShader(shaderHueShift);
batch.begin();
//draw
batch.draw(image, x, y, w, h);
//reset
batch.end();
batch.setShader(null);
batch.begin();
} else {
drawImage(image, x, y, w, h);
}
}
public void drawChromatic(TextureRegion image, float x, float y, float w, float h, Float time) { public void drawChromatic(TextureRegion image, float x, float y, float w, float h, Float time) {
if (image == null) if (image == null)
return; return;
@@ -831,6 +937,7 @@ public class Graphics {
drawImage(image, x, y, w, h); drawImage(image, x, y, w, h);
} }
} }
public void drawRipple(FImage image, float x, float y, float w, float h, Float amount, boolean flipY) { public void drawRipple(FImage image, float x, float y, float w, float h, Float amount, boolean flipY) {
if (image == null) if (image == null)
return; return;
@@ -852,13 +959,14 @@ public class Graphics {
drawImage(image, x, y, w, h); drawImage(image, x, y, w, h);
} }
} }
public void drawPixelated(FImage image, float x, float y, float w, float h, Float amount, boolean flipY) { public void drawPixelated(FImage image, float x, float y, float w, float h, Float amount, boolean flipY) {
if (image == null) if (image == null)
return; return;
if (amount != null) { if (amount != null) {
batch.end(); batch.end();
shaderPixelate.bind(); shaderPixelate.bind();
shaderPixelate.setUniformf("u_resolution", Forge.isLandscapeMode() ? w : h , Forge.isLandscapeMode() ? h : w); shaderPixelate.setUniformf("u_resolution", Forge.isLandscapeMode() ? w : h, Forge.isLandscapeMode() ? h : w);
shaderPixelate.setUniformf("u_cellSize", amount); shaderPixelate.setUniformf("u_cellSize", amount);
shaderPixelate.setUniformf("u_yflip", flipY ? 1f : 0f); shaderPixelate.setUniformf("u_yflip", flipY ? 1f : 0f);
shaderPixelate.setUniformf("u_bias", 0.7f); shaderPixelate.setUniformf("u_bias", 0.7f);
@@ -874,13 +982,14 @@ public class Graphics {
drawImage(image, x, y, w, h); drawImage(image, x, y, w, h);
} }
} }
public void drawPixelated(TextureRegion image, float x, float y, float w, float h, Float amount, boolean flipY) { public void drawPixelated(TextureRegion image, float x, float y, float w, float h, Float amount, boolean flipY) {
if (image == null) if (image == null)
return; return;
if (amount != null) { if (amount != null) {
batch.end(); batch.end();
shaderPixelate.bind(); shaderPixelate.bind();
shaderPixelate.setUniformf("u_resolution", Forge.isLandscapeMode() ? w : h , Forge.isLandscapeMode() ? h : w); shaderPixelate.setUniformf("u_resolution", Forge.isLandscapeMode() ? w : h, Forge.isLandscapeMode() ? h : w);
shaderPixelate.setUniformf("u_cellSize", amount); shaderPixelate.setUniformf("u_cellSize", amount);
shaderPixelate.setUniformf("u_yflip", flipY ? 1 : 0); shaderPixelate.setUniformf("u_yflip", flipY ? 1 : 0);
shaderPixelate.setUniformf("u_bias", 0.6f); shaderPixelate.setUniformf("u_bias", 0.6f);
@@ -896,6 +1005,7 @@ public class Graphics {
drawImage(image, x, y, w, h); drawImage(image, x, y, w, h);
} }
} }
public void drawPixelatedWarp(TextureRegion image, float x, float y, float w, float h, float amount) { public void drawPixelatedWarp(TextureRegion image, float x, float y, float w, float h, float amount) {
if (image == null) if (image == null)
return; return;
@@ -904,7 +1014,7 @@ public class Graphics {
shaderPixelateWarp.bind(); shaderPixelateWarp.bind();
shaderPixelateWarp.setUniformf("u_resolution", image.getRegionWidth(), image.getRegionHeight()); shaderPixelateWarp.setUniformf("u_resolution", image.getRegionWidth(), image.getRegionHeight());
shaderPixelateWarp.setUniformf("u_cellSize", amount); shaderPixelateWarp.setUniformf("u_cellSize", amount);
shaderPixelateWarp.setUniformf("u_amount", 0.2f*amount); shaderPixelateWarp.setUniformf("u_amount", 0.2f * amount);
shaderPixelateWarp.setUniformf("u_speed", 0.5f); shaderPixelateWarp.setUniformf("u_speed", 0.5f);
shaderPixelateWarp.setUniformf("u_time", 0.8f); shaderPixelateWarp.setUniformf("u_time", 0.8f);
batch.setShader(shaderPixelateWarp); batch.setShader(shaderPixelateWarp);
@@ -919,6 +1029,7 @@ public class Graphics {
drawImage(image, x, y, w, h); drawImage(image, x, y, w, h);
} }
} }
public void drawWarpImage(Texture image, float x, float y, float w, float h, float time) { public void drawWarpImage(Texture image, float x, float y, float w, float h, float time) {
batch.end(); batch.end();
shaderWarp.bind(); shaderWarp.bind();
@@ -934,6 +1045,7 @@ public class Graphics {
batch.setShader(null); batch.setShader(null);
batch.begin(); batch.begin();
} }
public void drawWarpImage(TextureRegion image, float x, float y, float w, float h, float time) { public void drawWarpImage(TextureRegion image, float x, float y, float w, float h, float time) {
batch.end(); batch.end();
shaderWarp.bind(); shaderWarp.bind();
@@ -949,6 +1061,7 @@ public class Graphics {
batch.setShader(null); batch.setShader(null);
batch.begin(); batch.begin();
} }
public void drawWarpImage(FImage image, float x, float y, float w, float h, float time) { public void drawWarpImage(FImage image, float x, float y, float w, float h, float time) {
if (image == null) if (image == null)
return; return;
@@ -966,13 +1079,14 @@ public class Graphics {
batch.setShader(null); batch.setShader(null);
batch.begin(); batch.begin();
} }
public void drawUnderWaterImage(FImage image, float x, float y, float w, float h, float time) { public void drawUnderWaterImage(FImage image, float x, float y, float w, float h, float time) {
if (image == null) if (image == null)
return; return;
batch.end(); batch.end();
shaderUnderwater.bind(); shaderUnderwater.bind();
shaderUnderwater.setUniformf("u_amount", 10f*time); shaderUnderwater.setUniformf("u_amount", 10f * time);
shaderUnderwater.setUniformf("u_speed", 0.5f*time); shaderUnderwater.setUniformf("u_speed", 0.5f * time);
shaderUnderwater.setUniformf("u_time", time); shaderUnderwater.setUniformf("u_time", time);
shaderUnderwater.setUniformf("u_bias", 0.7f); shaderUnderwater.setUniformf("u_bias", 0.7f);
batch.setShader(shaderUnderwater); batch.setShader(shaderUnderwater);
@@ -984,6 +1098,7 @@ public class Graphics {
batch.setShader(null); batch.setShader(null);
batch.begin(); batch.begin();
} }
public void drawNightDay(FImage image, float x, float y, float w, float h, Float time) { public void drawNightDay(FImage image, float x, float y, float w, float h, Float time) {
if (image == null) if (image == null)
return; return;
@@ -1003,6 +1118,7 @@ public class Graphics {
drawImage(image, x, y, w, h); drawImage(image, x, y, w, h);
} }
} }
public void drawUnderWaterImage(TextureRegion image, float x, float y, float w, float h, float time) { public void drawUnderWaterImage(TextureRegion image, float x, float y, float w, float h, float time) {
batch.end(); batch.end();
shaderUnderwater.bind(); shaderUnderwater.bind();
@@ -1018,32 +1134,37 @@ public class Graphics {
batch.setShader(null); batch.setShader(null);
batch.begin(); batch.begin();
} }
public void drawImage(FImage image, float x, float y, float w, float h) { public void drawImage(FImage image, float x, float y, float w, float h) {
drawImage(image, x, y, w, h, false); drawImage(image, x, y, w, h, false);
} }
public void drawImage(FImage image, float x, float y, float w, float h, boolean withDarkOverlay) { public void drawImage(FImage image, float x, float y, float w, float h, boolean withDarkOverlay) {
if (image == null) if (image == null)
return; return;
image.draw(this, x, y, w, h); image.draw(this, x, y, w, h);
if(withDarkOverlay){ if (withDarkOverlay) {
float oldalpha = alphaComposite; float oldalpha = alphaComposite;
setAlphaComposite(0.4f); setAlphaComposite(0.4f);
fillRect(Color.BLACK, x, y, w, h); fillRect(Color.BLACK, x, y, w, h);
setAlphaComposite(oldalpha); setAlphaComposite(oldalpha);
} }
} }
public void drawImage(Texture image, float x, float y, float w, float h) { public void drawImage(Texture image, float x, float y, float w, float h) {
if (image != null) if (image != null)
batch.draw(image, adjustX(x), adjustY(y, h), w, h); batch.draw(image, adjustX(x), adjustY(y, h), w, h);
} }
public void drawImage(TextureRegion image, float x, float y, float w, float h) { public void drawImage(TextureRegion image, float x, float y, float w, float h) {
if (image != null) if (image != null)
batch.draw(image, adjustX(x), adjustY(y, h), w, h); batch.draw(image, adjustX(x), adjustY(y, h), w, h);
} }
public void drawImage(TextureRegion image, TextureRegion glowImageReference, float x, float y, float w, float h, Color glowColor, boolean selected) { public void drawImage(TextureRegion image, TextureRegion glowImageReference, float x, float y, float w, float h, Color glowColor, boolean selected) {
if (image == null || glowImageReference == null) if (image == null || glowImageReference == null)
return; return;
//1st image is the image on top of the shader, 2nd image is for the outline reference for the shader glow... //1st image is the image on top of the shader, 2nd image is for the outline reference for the shader glow...
// if the 1st image don't have transparency in the middle (only on the sides, top and bottom, use the 1st image as outline reference... // if the 1st image don't have transparency in the middle (only on the sides, top and bottom, use the 1st image as outline reference...
if (!selected) { if (!selected) {
batch.draw(image, adjustX(x), adjustY(y, h), w, h); batch.draw(image, adjustX(x), adjustY(y, h), w, h);
@@ -1065,12 +1186,13 @@ public class Graphics {
batch.draw(image, adjustX(x), adjustY(y, h), w, h); batch.draw(image, adjustX(x), adjustY(y, h), w, h);
} }
} }
public void drawDeckBox(FImage cardArt, float scale, TextureRegion image, TextureRegion glowImageReference, float x, float y, float w, float h, Color glowColor, boolean selected) { public void drawDeckBox(FImage cardArt, float scale, TextureRegion image, TextureRegion glowImageReference, float x, float y, float w, float h, Color glowColor, boolean selected) {
if (image == null || glowImageReference == null) if (image == null || glowImageReference == null)
return; return;
float yBox = y-(h*0.25f); float yBox = y - (h * 0.25f);
if (!selected) { if (!selected) {
cardArt.draw(this,x+((w-w*scale)/2), y+((h-h*scale)/3f), w*scale, h*scale/1.85f); cardArt.draw(this, x + ((w - w * scale) / 2), y + ((h - h * scale) / 3f), w * scale, h * scale / 1.85f);
batch.draw(image, adjustX(x), adjustY(yBox, h), w, h); batch.draw(image, adjustX(x), adjustY(yBox, h), w, h);
} else { } else {
batch.end(); batch.end();
@@ -1087,7 +1209,7 @@ public class Graphics {
batch.setShader(null); batch.setShader(null);
batch.begin(); batch.begin();
//cardart //cardart
cardArt.draw(this,x+((w-w*scale)/2), y+((h-h*scale)/3f), w*scale, h*scale/1.85f); cardArt.draw(this, x + ((w - w * scale) / 2), y + ((h - h * scale) / 3f), w * scale, h * scale / 1.85f);
//deckbox //deckbox
batch.draw(image, adjustX(x), adjustY(yBox, h), w, h); batch.draw(image, adjustX(x), adjustY(yBox, h), w, h);
} }
@@ -1097,8 +1219,8 @@ public class Graphics {
if (image == null) if (image == null)
return; return;
if (startClip(x, y, w, h)) { //only render if clip successful, otherwise it will escape bounds if (startClip(x, y, w, h)) { //only render if clip successful, otherwise it will escape bounds
int tilesW = (int)(w / image.getWidth()) + 1; int tilesW = (int) (w / image.getWidth()) + 1;
int tilesH = (int)(h / image.getHeight()) + 1; int tilesH = (int) (h / image.getHeight()) + 1;
batch.draw(image, adjustX(x), adjustY(y, h), batch.draw(image, adjustX(x), adjustY(y, h),
image.getWidth() * tilesW, image.getWidth() * tilesW,
image.getHeight() * tilesH, image.getHeight() * tilesH,
@@ -1136,7 +1258,7 @@ public class Graphics {
shapeRenderer.setTransformMatrix(batch.getTransformMatrix().idt()); shapeRenderer.setTransformMatrix(batch.getTransformMatrix().idt());
Dtransforms.removeFirst(); Dtransforms.removeFirst();
transformCount--; transformCount--;
if(transformCount != Dtransforms.size()) { if (transformCount != Dtransforms.size()) {
System.err.println(String.format("Stack count: %d, transformCount: %d", Dtransforms.size(), transformCount)); System.err.println(String.format("Stack count: %d, transformCount: %d", Dtransforms.size(), transformCount));
transformCount = 0; transformCount = 0;
Dtransforms.clear(); Dtransforms.clear();
@@ -1149,16 +1271,26 @@ public class Graphics {
public void drawRotatedImage(Texture image, float x, float y, float w, float h, float originX, float originY, float rotation) { public void drawRotatedImage(Texture image, float x, float y, float w, float h, float originX, float originY, float rotation) {
drawRotatedImage(image, x, y, w, h, originX, originY, 0, 0, image.getWidth(), image.getHeight(), rotation); drawRotatedImage(image, x, y, w, h, originX, originY, 0, 0, image.getWidth(), image.getHeight(), rotation);
} }
public void drawRotatedImage(TextureRegion image, float x, float y, float w, float h, float originX, float originY, float rotation) { public void drawRotatedImage(TextureRegion image, float x, float y, float w, float h, float originX, float originY, float rotation) {
drawRotatedImage(image.getTexture(), x, y, w, h, originX, originY, image.getRegionX(), image.getRegionY(), image.getRegionWidth(), image.getRegionHeight(), rotation); drawRotatedImage(image.getTexture(), x, y, w, h, originX, originY, image.getRegionX(), image.getRegionY(), image.getRegionWidth(), image.getRegionHeight(), rotation);
} }
public void drawRotatedImage(Texture image, float x, float y, float w, float h, float originX, float originY, int srcX, int srcY, int srcWidth, int srcHeight, float rotation) { public void drawRotatedImage(Texture image, float x, float y, float w, float h, float originX, float originY, int srcX, int srcY, int srcWidth, int srcHeight, float rotation) {
batch.draw(image, adjustX(x), adjustY(y, h), originX - x, h - (originY - y), w, h, 1, 1, rotation, srcX, srcY, srcWidth, srcHeight, false, false); batch.draw(image, adjustX(x), adjustY(y, h), originX - x, h - (originY - y), w, h, 1, 1, rotation, srcX, srcY, srcWidth, srcHeight, false, false);
} }
public void drawText(String text, BitmapFont bitmapFont, float x, float y, Color color, float alpha) {
if (text == null || bitmapFont == null || text.isEmpty())
return;
bitmapFont.setColor(color.r, color.g, color.b, alpha);
bitmapFont.draw(batch, text, x, y);
}
public void drawText(String text, FSkinFont font, FSkinColor skinColor, float x, float y, float w, float h, boolean wrap, int horzAlignment, boolean centerVertically) { public void drawText(String text, FSkinFont font, FSkinColor skinColor, float x, float y, float w, float h, boolean wrap, int horzAlignment, boolean centerVertically) {
drawText(text, font, skinColor.getColor(), x, y, w, h, wrap, horzAlignment, centerVertically); drawText(text, font, skinColor.getColor(), x, y, w, h, wrap, horzAlignment, centerVertically);
} }
public void drawText(String text, FSkinFont font, Color color, float x, float y, float w, float h, boolean wrap, int horzAlignment, boolean centerVertically) { public void drawText(String text, FSkinFont font, Color color, float x, float y, float w, float h, boolean wrap, int horzAlignment, boolean centerVertically) {
try { try {
if (text == null) if (text == null)
@@ -1173,8 +1305,7 @@ public class Graphics {
TextBounds textBounds; TextBounds textBounds;
if (wrap) { if (wrap) {
textBounds = font.getWrappedBounds(text, w); textBounds = font.getWrappedBounds(text, w);
} } else {
else {
textBounds = font.getMultiLineBounds(text); textBounds = font.getMultiLineBounds(text);
} }
@@ -1185,12 +1316,10 @@ public class Graphics {
font = font.shrink(); font = font.shrink();
if (wrap) { if (wrap) {
textBounds = font.getWrappedBounds(text, w); textBounds = font.getWrappedBounds(text, w);
} } else {
else {
textBounds = font.getMultiLineBounds(text); textBounds = font.getMultiLineBounds(text);
} }
} } else {
else {
needClip = true; needClip = true;
break; break;
} }
@@ -1224,6 +1353,7 @@ public class Graphics {
public void drawOutlinedText(String text, FSkinFont skinFont, Color textColor, Color outlineColor, float x, float y, float w, float h, boolean wrap, int horzAlignment, boolean centerVertically) { public void drawOutlinedText(String text, FSkinFont skinFont, Color textColor, Color outlineColor, float x, float y, float w, float h, boolean wrap, int horzAlignment, boolean centerVertically) {
drawOutlinedText(text, skinFont, textColor, outlineColor, x, y, w, h, wrap, horzAlignment, centerVertically, false); drawOutlinedText(text, skinFont, textColor, outlineColor, x, y, w, h, wrap, horzAlignment, centerVertically, false);
} }
public void drawOutlinedText(String text, FSkinFont skinFont, Color textColor, Color outlineColor, float x, float y, float w, float h, boolean wrap, int horzAlignment, boolean centerVertically, boolean shadow) { public void drawOutlinedText(String text, FSkinFont skinFont, Color textColor, Color outlineColor, float x, float y, float w, float h, boolean wrap, int horzAlignment, boolean centerVertically, boolean shadow) {
if (shadow) { if (shadow) {
float oldAlpha = alphaComposite; float oldAlpha = alphaComposite;
@@ -1250,20 +1380,21 @@ public class Graphics {
public float adjustY(float y, float height) { public float adjustY(float y, float height) {
return regionHeight - y - bounds.y - height; //flip y-axis return regionHeight - y - bounds.y - height; //flip y-axis
} }
public Color borderLining(String c){
public Color borderLining(String c) {
if (c == null || c == "") if (c == null || c == "")
return Color.valueOf("#fffffd"); return Color.valueOf("#fffffd");
int c_r = Integer.parseInt(c.substring(0,2),16); int c_r = Integer.parseInt(c.substring(0, 2), 16);
int c_g = Integer.parseInt(c.substring(2,4),16); int c_g = Integer.parseInt(c.substring(2, 4), 16);
int c_b = Integer.parseInt(c.substring(4,6),16); int c_b = Integer.parseInt(c.substring(4, 6), 16);
int brightness = ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000; int brightness = ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000;
return brightness > 155 ? Color.valueOf("#171717") : Color.valueOf("#fffffd"); return brightness > 155 ? Color.valueOf("#171717") : Color.valueOf("#fffffd");
} }
public Texture getDummyTexture(){ public Texture getDummyTexture() {
if (dummyTexture == null){ if (dummyTexture == null) {
Pixmap P = new Pixmap(1, 1, Pixmap.Format.RGBA8888); Pixmap P = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
P.setColor(1f,1f,1f,1f); P.setColor(1f, 1f, 1f, 1f);
P.drawPixel(0, 0); P.drawPixel(0, 0);
dummyTexture = new Texture(P); dummyTexture = new Texture(P);
P.dispose(); P.dispose();

View File

@@ -25,9 +25,9 @@ public class Shaders {
+ " gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" + " gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
+ "}\n"; + "}\n";
/* /*
* Test Pixelate shader * Test Pixelate shader
* *
**/ **/
public static final String vertPixelateShader = "attribute vec4 a_position;\n" + public static final String vertPixelateShader = "attribute vec4 a_position;\n" +
"attribute vec4 a_color;\n" + "attribute vec4 a_color;\n" +
"attribute vec2 a_texCoord0;\n" + "attribute vec2 a_texCoord0;\n" +
@@ -42,7 +42,31 @@ public class Shaders {
" v_texCoords = a_texCoord0;\n" + " v_texCoords = a_texCoord0;\n" +
" gl_Position = u_projTrans * a_position;\n" + " gl_Position = u_projTrans * a_position;\n" +
"}"; "}";
public static final String fragRipple="#ifdef GL_ES\n" + public static final String fragHueShift = "#ifdef GL_ES\n" +
"#define LOWP lowp\n" +
"precision mediump float;\n" +
"#else\n" +
"#define LOWP \n" +
"#endif\n" +
"varying vec2 v_texCoords;\n" +
"uniform sampler2D u_texture;\n" +
"uniform float u_time;\n" +
"\n" +
"vec3 hs(vec3 c, float s) {\n" +
" vec3 m=vec3(cos(s),s=sin(s)*.5774,-s);\n" +
" return c*mat3(m+=(1.-m.x)/3.,m.zxy,m.yzx);\n" +
"}\n" +
"\n" +
"void main() {\n" +
"\tvec2 uv = v_texCoords;\n" +
" vec4 orig = texture2D(u_texture, uv);\n" +
" vec3 col = texture2D(u_texture, uv).rgb;\n" +
" vec4 col2 = vec4(hs(col, u_time), 1.);\n" +
" //multiply the original texture alpha to render only opaque shifted colors \n" +
" col2.a *= orig.a;\n" +
" gl_FragColor = col2;\n" +
"}";
public static final String fragRipple = "#ifdef GL_ES\n" +
"#define LOWP lowp\n" + "#define LOWP lowp\n" +
"precision mediump float;\n" + "precision mediump float;\n" +
"#else\n" + "#else\n" +
@@ -74,7 +98,7 @@ public class Shaders {
"\t\tcolor = texture2D(u_texture, coord);\n" + "\t\tcolor = texture2D(u_texture, coord);\n" +
"\tgl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), vec4(color.rgba * dist), u_bias);\n" + "\tgl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), vec4(color.rgba * dist), u_bias);\n" +
"}"; "}";
public static final String fragChromaticAbberation="#ifdef GL_ES\n" + public static final String fragChromaticAbberation = "#ifdef GL_ES\n" +
"#define LOWP lowp\n" + "#define LOWP lowp\n" +
"precision mediump float;\n" + "precision mediump float;\n" +
"#else\n" + "#else\n" +
@@ -1135,6 +1159,7 @@ public class Shaders {
* {@link com.github.tommyettinger.colorful.rgb.ColorTools#rgb(float, float, float, float)}. * {@link com.github.tommyettinger.colorful.rgb.ColorTools#rgb(float, float, float, float)}.
* <br> * <br>
* Meant for use with {@link #vertexShader}. * Meant for use with {@link #vertexShader}.
*
* @see #fragmentShaderConfigurableContrast a per-sprite-configurable version of this * @see #fragmentShaderConfigurableContrast a per-sprite-configurable version of this
*/ */
public static String fragmentShaderFlatLightness = public static String fragmentShaderFlatLightness =
@@ -1176,6 +1201,7 @@ public class Shaders {
* the specific way this uses them. * the specific way this uses them.
* <br> * <br>
* Meant for use with {@link #vertexShader}. * Meant for use with {@link #vertexShader}.
*
* @see #fragmentShaderFlatLightness if you only need one contrast setting and still want to set color tints * @see #fragmentShaderFlatLightness if you only need one contrast setting and still want to set color tints
*/ */
public static String fragmentShaderConfigurableContrast = public static String fragmentShaderConfigurableContrast =

View File

@@ -1,10 +1,7 @@
package forge.adventure.scene; package forge.adventure.scene;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.scenes.scene2d.ui.*;
@@ -15,7 +12,6 @@ import forge.Forge;
import forge.adventure.character.EnemySprite; import forge.adventure.character.EnemySprite;
import forge.adventure.data.ArenaData; import forge.adventure.data.ArenaData;
import forge.adventure.data.WorldData; import forge.adventure.data.WorldData;
import forge.adventure.player.AdventurePlayer;
import forge.adventure.stage.GameHUD; import forge.adventure.stage.GameHUD;
import forge.adventure.stage.IAfterMatch; import forge.adventure.stage.IAfterMatch;
import forge.adventure.stage.WorldStage; import forge.adventure.stage.WorldStage;
@@ -29,16 +25,14 @@ import java.util.Random;
* Displays the rewards of a fight or a treasure * Displays the rewards of a fight or a treasure
*/ */
public class ArenaScene extends UIScene implements IAfterMatch { public class ArenaScene extends UIScene implements IAfterMatch {
private FileHandle vsIcon = Config.instance().getFile("ui/vs.png");
private TextureRegion vsTextureRegion = vsIcon.exists() ? new TextureRegion(new Texture(vsIcon)) : null;
private static ArenaScene object; private static ArenaScene object;
private final float gridSize; private final float gridSize;
private ArenaData arenaData; private ArenaData arenaData;
private final TextraButton startButton; private final TextraButton startButton;
public static ArenaScene instance() { public static ArenaScene instance() {
if(object==null) if (object == null)
object=new ArenaScene(); object = new ArenaScene();
return object; return object;
} }
@@ -46,7 +40,7 @@ public class ArenaScene extends UIScene implements IAfterMatch {
private final TextraLabel goldLabel; private final TextraLabel goldLabel;
private final Group arenaPlane; private final Group arenaPlane;
private final Random rand=new Random(); private final Random rand = new Random();
final Sprite fighterSpot; final Sprite fighterSpot;
final Sprite lostOverlay; final Sprite lostOverlay;
@@ -58,49 +52,45 @@ public class ArenaScene extends UIScene implements IAfterMatch {
final Sprite edgeM; final Sprite edgeM;
final Sprite edgeWin; final Sprite edgeWin;
final Sprite edgeWinM; final Sprite edgeWinM;
boolean arenaStarted=false; boolean arenaStarted = false;
private ArenaScene() { private ArenaScene() {
super(Forge.isLandscapeMode() ? "ui/arena.json" : "ui/arena_portrait.json"); super(Forge.isLandscapeMode() ? "ui/arena.json" : "ui/arena_portrait.json");
TextureAtlas atlas = Config.instance().getAtlas(Paths.ARENA_ATLAS);
fighterSpot = atlas.createSprite("Spot");
lostOverlay = atlas.createSprite("Lost");
up = atlas.createSprite("Up");
upWin = atlas.createSprite("UpWin");
side = atlas.createSprite("Side");
sideWin = atlas.createSprite("SideWin");
edge = atlas.createSprite("Edge");
edgeM = atlas.createSprite("Edge");
edgeM.setFlip(true, false);
edgeWin = atlas.createSprite("EdgeWin");
edgeWinM = atlas.createSprite("EdgeWin");
edgeWinM.setFlip(true, false);
gridSize = fighterSpot.getRegionWidth();
goldLabel = ui.findActor("gold");
TextureAtlas atlas=Config.instance().getAtlas(Paths.ARENA_ATLAS);
fighterSpot=atlas.createSprite("Spot");
lostOverlay=atlas.createSprite("Lost");
up=atlas.createSprite("Up");
upWin=atlas.createSprite("UpWin");
side=atlas.createSprite("Side");
sideWin=atlas.createSprite("SideWin");
edge=atlas.createSprite("Edge");
edgeM=atlas.createSprite("Edge");
edgeM.setFlip(true,false);
edgeWin=atlas.createSprite("EdgeWin");
edgeWinM=atlas.createSprite("EdgeWin");
edgeWinM.setFlip(true,false);
gridSize=fighterSpot.getRegionWidth();
goldLabel=ui.findActor("gold");
ui.onButtonPress("done", () -> { ui.onButtonPress("done", () -> {
if(!arenaStarted) if (!arenaStarted)
ArenaScene.this.done(); ArenaScene.this.done();
else else
showAreYouSure(); showAreYouSure();
}); });
ui.onButtonPress("start", () -> startButton()); ui.onButtonPress("start", () -> startButton());
doneButton = ui.findActor("done"); doneButton = ui.findActor("done");
ScrollPane pane= ui.findActor("arena"); ScrollPane pane = ui.findActor("arena");
arenaPlane=new Table(); arenaPlane = new Table();
pane.setActor(arenaPlane); pane.setActor(arenaPlane);
startButton=ui.findActor("start"); startButton = ui.findActor("start");
} }
private void showAreYouSure() { private void showAreYouSure() {
Dialog areYouSureDialog = prepareDialog(Forge.getLocalizer().getMessage("lblConcedeTitle"), ButtonYes | ButtonNo, () -> loose());
Dialog areYouSureDialog= prepareDialog(Forge.getLocalizer().getMessage("lblConcedeTitle"),ButtonYes|ButtonNo,()->loose());
areYouSureDialog.text(Forge.getLocalizer().getMessage("lblConcedeCurrentGame")); areYouSureDialog.text(Forge.getLocalizer().getMessage("lblConcedeCurrentGame"));
showDialog(areYouSureDialog); showDialog(areYouSureDialog);
} }
@@ -109,26 +99,24 @@ public class ArenaScene extends UIScene implements IAfterMatch {
doneButton.setText(Forge.getLocalizer().getMessage("lblLeave")); doneButton.setText(Forge.getLocalizer().getMessage("lblLeave"));
doneButton.layout(); doneButton.layout();
startButton.setDisabled(true); startButton.setDisabled(true);
arenaStarted=false; arenaStarted = false;
} }
private void startButton() { private void startButton() {
if(roundsWon ==0) if (roundsWon == 0) {
{ Dialog startDialog = prepareDialog(Forge.getLocalizer().getMessage("lblStart"), ButtonYes | ButtonNo, () -> startArena());
Dialog startDialog = prepareDialog(Forge.getLocalizer().getMessage("lblStart"), ButtonYes|ButtonNo,()->startArena());
startDialog.text("Do you want to go into the Arena?"); startDialog.text("Do you want to go into the Arena?");
showDialog(startDialog); showDialog(startDialog);
} } else {
else
{
startRound(); startRound();
} }
} }
int roundsWon =0; int roundsWon = 0;
private void startArena() { private void startArena() {
goldLabel.setVisible(false); goldLabel.setVisible(false);
arenaStarted=true; arenaStarted = true;
startButton.setText(Forge.getLocalizer().getMessage("lblContinue")); startButton.setText(Forge.getLocalizer().getMessage("lblContinue"));
startButton.layout(); startButton.layout();
doneButton.setText(Forge.getLocalizer().getMessage("lblConcede")); doneButton.setText(Forge.getLocalizer().getMessage("lblConcede"));
@@ -137,48 +125,41 @@ public class ArenaScene extends UIScene implements IAfterMatch {
Current.player().takeGold(arenaData.entryFee); Current.player().takeGold(arenaData.entryFee);
startRound(); startRound();
} }
@Override @Override
public void setWinner(boolean winner) { public void setWinner(boolean winner) {
Array<Actor> winners=new Array<>(); Array<Actor> winners = new Array<>();
Array<EnemySprite> winnersEnemies=new Array<>(); Array<EnemySprite> winnersEnemies = new Array<>();
for(int i=0;i<fighters.size-2;i+=2) for (int i = 0; i < fighters.size - 2; i += 2) {
{ boolean leftWon = rand.nextBoolean();
boolean leftWon=rand.nextBoolean(); if (leftWon) {
if(leftWon) winners.add(fighters.get(i));
{ winnersEnemies.add(enemies.get(i));
winners.add(fighters.get(i)); moveFighter(fighters.get(i), true);
winnersEnemies.add(enemies.get(i)); markLostFighter(fighters.get(i + 1));
moveFighter(fighters.get(i),true); } else {
markLostFighter(fighters.get(i+1)); markLostFighter(fighters.get(i));
} moveFighter(fighters.get(i + 1), false);
else winners.add(fighters.get(i + 1));
{ winnersEnemies.add(enemies.get(i + 1));
markLostFighter(fighters.get(i)); }
moveFighter(fighters.get(i+1),false);
winners.add(fighters.get(i+1));
winnersEnemies.add(enemies.get(i+1));
}
}
if(winner)
{
markLostFighter(fighters.get(fighters.size-2));
moveFighter(fighters.get(fighters.size-1),false);
winners.add(fighters.get(fighters.size-1));
roundsWon++;
} }
else if (winner) {
{ markLostFighter(fighters.get(fighters.size - 2));
markLostFighter(fighters.get(fighters.size-1)); moveFighter(fighters.get(fighters.size - 1), false);
moveFighter(fighters.get(fighters.size-2),true); winners.add(fighters.get(fighters.size - 1));
winners.add(fighters.get(fighters.size-2)); roundsWon++;
} else {
markLostFighter(fighters.get(fighters.size - 1));
moveFighter(fighters.get(fighters.size - 2), true);
winners.add(fighters.get(fighters.size - 2));
loose(); loose();
} }
fighters=winners; fighters = winners;
enemies=winnersEnemies; enemies = winnersEnemies;
if(roundsWon >=arenaData.rounds ) if (roundsWon >= arenaData.rounds) {
{ arenaStarted = false;
arenaStarted=false;
startButton.setDisabled(true); startButton.setDisabled(true);
doneButton.setText(Forge.getLocalizer().getMessage("lblDone")); doneButton.setText(Forge.getLocalizer().getMessage("lblDone"));
doneButton.layout(); doneButton.layout();
@@ -186,49 +167,44 @@ public class ArenaScene extends UIScene implements IAfterMatch {
} }
private void moveFighter(Actor actor, boolean leftPlayer) { private void moveFighter(Actor actor, boolean leftPlayer) {
Image spotImg = new Image(upWin);
Image spotImg=new Image(upWin); double stepsToTheSide = Math.pow(2, roundsWon);
double stepsToTheSide=Math.pow(2, roundsWon); float widthDiff = actor.getWidth() - spotImg.getWidth();
float widthDiff=actor.getWidth()-spotImg.getWidth(); spotImg.setPosition(actor.getX() + widthDiff / 2, actor.getY() + gridSize + widthDiff / 2);
spotImg.setPosition(actor.getX()+widthDiff/2,actor.getY()+gridSize+widthDiff/2);
arenaPlane.addActor(spotImg); arenaPlane.addActor(spotImg);
for(int i=0;i<stepsToTheSide;i++) for (int i = 0; i < stepsToTheSide; i++) {
{
Image leftImg; Image leftImg;
if(i==0) if (i == 0)
leftImg=new Image(leftPlayer?edgeWin:edgeWinM); leftImg = new Image(leftPlayer ? edgeWin : edgeWinM);
else else
leftImg=new Image(sideWin); leftImg = new Image(sideWin);
leftImg.setPosition(actor.getX()+(i*(leftPlayer?1:-1))*gridSize+widthDiff/2,actor.getY()+gridSize*2+widthDiff/2); leftImg.setPosition(actor.getX() + (i * (leftPlayer ? 1 : -1)) * gridSize + widthDiff / 2, actor.getY() + gridSize * 2 + widthDiff / 2);
arenaPlane.addActor(leftImg); arenaPlane.addActor(leftImg);
} }
actor.moveBy((float) (gridSize*stepsToTheSide*(leftPlayer?1:-1)),gridSize*2f); actor.moveBy((float) (gridSize * stepsToTheSide * (leftPlayer ? 1 : -1)), gridSize * 2f);
} }
private void markLostFighter(Actor fighter) { private void markLostFighter(Actor fighter) {
Image lost = new Image(lostOverlay);
Image lost=new Image(lostOverlay); float widthDiff = fighter.getWidth() - lost.getWidth();
float widthDiff=fighter.getWidth()-lost.getWidth(); lost.setPosition(fighter.getX() + widthDiff / 2, fighter.getY() + widthDiff / 2);
lost.setPosition(fighter.getX()+widthDiff/2,fighter.getY()+widthDiff/2);
arenaPlane.addActor(lost); arenaPlane.addActor(lost);
} }
private void startRound() { private void startRound() {
DuelScene duelScene = DuelScene.instance(); DuelScene duelScene = DuelScene.instance();
EnemySprite enemy = enemies.get(enemies.size-1); EnemySprite enemy = enemies.get(enemies.size - 1);
FThreads.invokeInEdtNowOrLater(() -> { FThreads.invokeInEdtNowOrLater(() -> {
Forge.setTransitionScreen(new TransitionScreen(() -> { Forge.setTransitionScreen(new TransitionScreen(() -> {
duelScene.initDuels(WorldStage.getInstance().getPlayerSprite(), enemy); duelScene.initDuels(WorldStage.getInstance().getPlayerSprite(), enemy);
Forge.switchScene(duelScene); Forge.switchScene(duelScene);
}, Forge.takeScreenshot(), true, false, false, false, "", vsTextureRegion, AdventurePlayer.current().avatar(), enemy.getAtlasPath())); }, Forge.takeScreenshot(), true, false, false, false, "", Current.player().avatar(), enemy.getAtlasPath(), Current.player().getName(), enemy.nameOverride.isEmpty() ? enemy.getData().name : enemy.nameOverride));
}); });
} }
public boolean start() { public boolean start() {
return true; return true;
} }
@@ -236,14 +212,11 @@ public class ArenaScene extends UIScene implements IAfterMatch {
public boolean done() { public boolean done() {
GameHUD.getInstance().getTouchpad().setVisible(false); GameHUD.getInstance().getTouchpad().setVisible(false);
Forge.switchToLast(); Forge.switchToLast();
if(roundsWon !=0) if (roundsWon != 0) {
{ Array<Reward> data = new Array<>();
Array<Reward> data=new Array<>(); for (int i = 0; i < roundsWon; i++) {
for(int i = 0; i< roundsWon; i++) for (int j = 0; j < arenaData.rewards[i].length; j++) {
{ data.addAll(arenaData.rewards[i][j].generate(false, null));
for(int j=0;j<arenaData.rewards[i].length;j++)
{
data.addAll(arenaData.rewards[i][j].generate(false, null ));
} }
} }
RewardScene.instance().loadRewards(data, RewardScene.Type.Loot, null); RewardScene.instance().loadRewards(data, RewardScene.Type.Loot, null);
@@ -251,96 +224,84 @@ public class ArenaScene extends UIScene implements IAfterMatch {
} }
return true; return true;
} }
@Override @Override
public void act(float delta) { public void act(float delta) {
stage.act(delta); stage.act(delta);
} }
Array<EnemySprite> enemies = new Array<>(); Array<EnemySprite> enemies = new Array<>();
Array<Actor> fighters = new Array<>(); Array<Actor> fighters = new Array<>();
Actor player; Actor player;
public void loadArenaData(ArenaData data,long seed) { public void loadArenaData(ArenaData data, long seed) {
startButton.setText(Forge.getLocalizer().getMessage("lblStart")); startButton.setText(Forge.getLocalizer().getMessage("lblStart"));
startButton.layout(); startButton.layout();
doneButton.setText(Forge.getLocalizer().getMessage("lblDone")); doneButton.setText(Forge.getLocalizer().getMessage("lblDone"));
doneButton.layout(); doneButton.layout();
arenaData=data; arenaData = data;
//rand.setSeed(seed); allow to reshuffle arena enemies for now //rand.setSeed(seed); allow to reshuffle arena enemies for now
enemies.clear(); enemies.clear();
fighters.clear(); fighters.clear();
arenaPlane.clear(); arenaPlane.clear();
roundsWon =0; roundsWon = 0;
int numberOfEnemies= (int) (Math.pow(2f, data.rounds)-1); int numberOfEnemies = (int) (Math.pow(2f, data.rounds) - 1);
for(int i=0;i<numberOfEnemies;i++) for (int i = 0; i < numberOfEnemies; i++) {
{ EnemySprite enemy = new EnemySprite(WorldData.getEnemy(data.enemyPool[rand.nextInt(data.enemyPool.length)]));
EnemySprite enemy=new EnemySprite(WorldData.getEnemy(data.enemyPool[rand.nextInt(data.enemyPool.length)]));
enemies.add(enemy); enemies.add(enemy);
fighters.add(new Image(enemy.getAvatar())); fighters.add(new Image(enemy.getAvatar()));
} }
fighters.add(new Image(Current.player().avatar())); fighters.add(new Image(Current.player().avatar()));
player=fighters.get(fighters.size-1); player = fighters.get(fighters.size - 1);
goldLabel.setText(data.entryFee +" [+Gold]"); goldLabel.setText(data.entryFee + " [+Gold]");
goldLabel.layout(); goldLabel.layout();
goldLabel.setVisible(true); goldLabel.setVisible(true);
startButton.setDisabled(data.entryFee>Current.player().getGold()); startButton.setDisabled(data.entryFee > Current.player().getGold());
int currentSpots=numberOfEnemies+1; int currentSpots = numberOfEnemies + 1;
int gridWidth=currentSpots*2; int gridWidth = currentSpots * 2;
int gridHeight=data.rounds+1; int gridHeight = data.rounds + 1;
arenaPlane.setSize(gridWidth*gridSize,gridHeight*gridSize*2); arenaPlane.setSize(gridWidth * gridSize, gridHeight * gridSize * 2);
int fighterIndex=0; int fighterIndex = 0;
for(int x=0;x<gridWidth;x++) for (int x = 0; x < gridWidth; x++) {
{ for (int y = 0; y < gridHeight; y++) {
for(int y=0;y<gridHeight;y++) if (x % Math.pow(2, y + 1) == Math.pow(2, y)) {
{ if (y == 0) {
if(x % Math.pow(2,y+1) == Math.pow(2,y)) if (fighterIndex < fighters.size) {
{ float widthDiff = gridSize - fighters.get(fighterIndex).getWidth();
if(y==0) fighters.get(fighterIndex).setPosition(x * gridSize + widthDiff / 2, y * gridSize * 2 + widthDiff / 2);
{
if(fighterIndex<fighters.size)
{
float widthDiff=gridSize-fighters.get(fighterIndex).getWidth();
fighters.get(fighterIndex).setPosition(x*gridSize+widthDiff/2,y*gridSize*2+widthDiff/2);
arenaPlane.addActor(fighters.get(fighterIndex)); arenaPlane.addActor(fighters.get(fighterIndex));
fighterIndex++; fighterIndex++;
} }
} }
Image spotImg=new Image(fighterSpot); Image spotImg = new Image(fighterSpot);
spotImg.setPosition(x*gridSize,y*gridSize*2); spotImg.setPosition(x * gridSize, y * gridSize * 2);
arenaPlane.addActor(spotImg); arenaPlane.addActor(spotImg);
if(y!=gridHeight-1) if (y != gridHeight - 1) {
{ Image upImg = new Image(up);
Image upImg=new Image(up); upImg.setPosition(x * gridSize, y * gridSize * 2 + gridSize);
upImg.setPosition(x*gridSize,y*gridSize*2+gridSize);
arenaPlane.addActor(upImg); arenaPlane.addActor(upImg);
} }
if(y!=0) if (y != 0) {
{ for (int i = 0; i < Math.pow(2, (y - 1)); i++) {
for(int i=0;i<Math.pow(2,(y-1));i++)
{
Image leftImg; Image leftImg;
Image rightImg; Image rightImg;
if(i==Math.pow(2,(y-1))-1) if (i == Math.pow(2, (y - 1)) - 1) {
{ leftImg = new Image(edge);
leftImg=new Image(edge); rightImg = new Image(edgeM);
rightImg=new Image(edgeM); } else {
leftImg = new Image(side);
rightImg = new Image(side);
} }
else leftImg.setPosition((x - (i + 1)) * gridSize, y * gridSize * 2);
{ rightImg.setPosition((x + (i + 1)) * gridSize, y * gridSize * 2);
leftImg=new Image(side);
rightImg=new Image(side);
}
leftImg.setPosition((x-(i+1))*gridSize,y*gridSize*2);
rightImg.setPosition((x+(i+1))*gridSize,y*gridSize*2);
arenaPlane.addActor(leftImg); arenaPlane.addActor(leftImg);
arenaPlane.addActor(rightImg); arenaPlane.addActor(rightImg);
} }
@@ -349,5 +310,4 @@ public class ArenaScene extends UIScene implements IAfterMatch {
} }
} }
} }
} }

View File

@@ -51,10 +51,11 @@ public class DuelScene extends ForgeScene {
private static DuelScene object; private static DuelScene object;
public static DuelScene instance() { public static DuelScene instance() {
if(object==null) if (object == null)
object=new DuelScene(); object = new DuelScene();
return object; return object;
} }
//GameLobby lobby; //GameLobby lobby;
HostedMatch hostedMatch; HostedMatch hostedMatch;
EnemySprite enemy; EnemySprite enemy;
@@ -85,7 +86,7 @@ public class DuelScene extends ForgeScene {
String enemyName = (enemy.nameOverride.isEmpty() ? enemy.getData().name : enemy.nameOverride); String enemyName = (enemy.nameOverride.isEmpty() ? enemy.getData().name : enemy.nameOverride);
boolean showMessages = enemy.getData().copyPlayerDeck && Current.player().isUsingCustomDeck(); boolean showMessages = enemy.getData().copyPlayerDeck && Current.player().isUsingCustomDeck();
Current.player().clearBlessing(); Current.player().clearBlessing();
if ((chaosBattle||showMessages) && !winner) { if ((chaosBattle || showMessages) && !winner) {
callbackExit = true; callbackExit = true;
List<String> insult = Lists.newArrayList("I'm sorry...", "... ....", "Learn from your defeat.", List<String> insult = Lists.newArrayList("I'm sorry...", "... ....", "Learn from your defeat.",
"I haven't begun to use my full power.", "No matter how much you try, you still won't beat me.", "I haven't begun to use my full power.", "No matter how much you try, you still won't beat me.",
@@ -244,7 +245,7 @@ public class DuelScene extends ForgeScene {
this.AIExtras = aiCards; this.AIExtras = aiCards;
deck = deckProxy.getDeck(); deck = deckProxy.getDeck();
} else { } else {
deck = currentEnemy.copyPlayerDeck ? this.playerDeck : currentEnemy.generateDeck(Current.player().isFantasyMode(), Current.player().isUsingCustomDeck()||Current.player().getDifficulty().name.equalsIgnoreCase("Hard")); deck = currentEnemy.copyPlayerDeck ? this.playerDeck : currentEnemy.generateDeck(Current.player().isFantasyMode(), Current.player().isUsingCustomDeck() || Current.player().getDifficulty().name.equalsIgnoreCase("Hard"));
} }
RegisteredPlayer aiPlayer = RegisteredPlayer.forVariants(playerCount, appliedVariants, deck, null, false, null, null); RegisteredPlayer aiPlayer = RegisteredPlayer.forVariants(playerCount, appliedVariants, deck, null, false, null, null);
@@ -300,7 +301,7 @@ public class DuelScene extends ForgeScene {
hostedMatch.startMatch(rules, appliedVariants, players, guiMap); hostedMatch.startMatch(rules, appliedVariants, players, guiMap);
MatchController.instance.setGameView(hostedMatch.getGameView()); MatchController.instance.setGameView(hostedMatch.getGameView());
boolean showMessages = enemy.getData().copyPlayerDeck && Current.player().isUsingCustomDeck(); boolean showMessages = enemy.getData().copyPlayerDeck && Current.player().isUsingCustomDeck();
if (chaosBattle||showMessages) { if (chaosBattle || showMessages) {
List<String> list = Lists.newArrayList("It all depends on your skill!", "It's showtime!", "Let's party!", List<String> list = Lists.newArrayList("It all depends on your skill!", "It's showtime!", "Let's party!",
"You've proved yourself!", "Are you ready? Go!", "Prepare to strike, now!", "Let's go!", "What's next?", "You've proved yourself!", "Are you ready? Go!", "Prepare to strike, now!", "Let's go!", "What's next?",
"Yeah, I've been waitin' for this!", "The stage of battle is set!", "And the battle begins!", "Let's get started!", "Yeah, I've been waitin' for this!", "The stage of battle is set!", "And the battle begins!", "Let's get started!",

View File

@@ -3,7 +3,6 @@ package forge.adventure.scene;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import forge.Forge; import forge.Forge;
import forge.adventure.character.PlayerSprite;
import forge.adventure.data.BiomeData; import forge.adventure.data.BiomeData;
import forge.adventure.stage.MapStage; import forge.adventure.stage.MapStage;
import forge.adventure.stage.WorldStage; import forge.adventure.stage.WorldStage;
@@ -27,8 +26,8 @@ public class GameScene extends HudScene {
private static GameScene object; private static GameScene object;
public static GameScene instance() { public static GameScene instance() {
if(object==null) if (object == null)
object=new GameScene(); object = new GameScene();
return object; return object;
} }
@@ -58,18 +57,18 @@ public class GameScene extends HudScene {
super.enter(); super.enter();
WorldStage.getInstance().handlePointsOfInterestCollision(); WorldStage.getInstance().handlePointsOfInterestCollision();
} }
public String getAdventurePlayerLocation(boolean forHeader) { public String getAdventurePlayerLocation(boolean forHeader) {
String location = ""; String location = "";
if(MapStage.getInstance().isInMap()) { if (MapStage.getInstance().isInMap()) {
location = forHeader? TileMapScene.instance().rootPoint.getData().name : TileMapScene.instance().rootPoint.getData().type; location = forHeader ? TileMapScene.instance().rootPoint.getData().name : TileMapScene.instance().rootPoint.getData().type;
} else { } else {
World world= Current.world(); World world = Current.world();
PlayerSprite player = WorldStage.getInstance().getPlayerSprite(); int currentBiome = World.highestBiome(world.getBiome((int) Current.player().getWorldPosX() / world.getTileSize(), (int) Current.player().getWorldPosY() / world.getTileSize()));
int currentBiome = World.highestBiome(world.getBiome((int) player.getX() / world.getTileSize(), (int) player.getY() / world.getTileSize())); List<BiomeData> biomeData = world.getData().GetBiomes();
List<BiomeData> biomeData = Current.world().getData().GetBiomes();
try { try {
BiomeData data = biomeData.get(currentBiome); BiomeData data = biomeData.get(currentBiome);
location = forHeader? TextUtil.capitalize(data.name)+" Map" : data.name; location = forHeader ? TextUtil.capitalize(data.name) + " Map" : data.name;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
location = forHeader ? "Waste Map" : "waste"; location = forHeader ? "Waste Map" : "waste";

View File

@@ -56,7 +56,7 @@ public class MapStage extends GameStage {
final Array<MapActor> actors = new Array<>(); final Array<MapActor> actors = new Array<>();
TiledMap map; TiledMap map;
Array<Rectangle> collisionRect=new Array<>(); Array<Rectangle> collisionRect = new Array<>();
private boolean isInMap = false; private boolean isInMap = false;
MapLayer spriteLayer; MapLayer spriteLayer;
private PointOfInterestChanges changes; private PointOfInterestChanges changes;
@@ -76,9 +76,9 @@ public class MapStage extends GameStage {
//These maps are defined as embedded properties within the Tiled maps. //These maps are defined as embedded properties within the Tiled maps.
private EffectData effect; //"Dungeon Effect": Character Effect applied to all adversaries within the map. private EffectData effect; //"Dungeon Effect": Character Effect applied to all adversaries within the map.
private boolean preventEscape = false; //Prevents player from escaping the dungeon by any means that aren't an exit. private boolean preventEscape = false; //Prevents player from escaping the dungeon by any means that aren't an exit.
private final Array< TextraButton> dialogButtonMap=new Array<>(); private final Array<TextraButton> dialogButtonMap = new Array<>();
public InputEvent eventTouchDown, eventTouchUp; public InputEvent eventTouchDown, eventTouchUp;
TextraButton selectedKey; TextraButton selectedKey;
private boolean respawnEnemies; private boolean respawnEnemies;
@@ -118,8 +118,7 @@ public class MapStage extends GameStage {
return changes; return changes;
} }
private MapStage() private MapStage() {
{
dialog = Controls.newDialog(""); dialog = Controls.newDialog("");
eventTouchDown = new InputEvent(); eventTouchDown = new InputEvent();
eventTouchDown.setPointer(-1); eventTouchDown.setPointer(-1);
@@ -128,6 +127,7 @@ public class MapStage extends GameStage {
eventTouchUp.setPointer(-1); eventTouchUp.setPointer(-1);
eventTouchUp.setType(InputEvent.Type.touchUp); eventTouchUp.setType(InputEvent.Type.touchUp);
} }
public static MapStage getInstance() { public static MapStage getInstance() {
return instance == null ? instance = new MapStage() : instance; return instance == null ? instance = new MapStage() : instance;
} }
@@ -246,9 +246,10 @@ public class MapStage extends GameStage {
setDialogStage(GameHUD.getInstance()); setDialogStage(GameHUD.getInstance());
showDialog(); showDialog();
} }
Array<EntryActor> otherEntries=new Array<>();
Array<EntryActor> spawnClassified=new Array<>(); Array<EntryActor> otherEntries = new Array<>();
Array<EntryActor> sourceMapMatch=new Array<>(); Array<EntryActor> spawnClassified = new Array<>();
Array<EntryActor> sourceMapMatch = new Array<>();
public void loadMap(TiledMap map, String sourceMap) { public void loadMap(TiledMap map, String sourceMap) {
isLoadingMatch = false; isLoadingMatch = false;
@@ -263,9 +264,9 @@ public class MapStage extends GameStage {
actors.clear(); actors.clear();
collisionRect.clear(); collisionRect.clear();
if(collisionGroup!=null) if (collisionGroup != null)
collisionGroup.remove(); collisionGroup.remove();
collisionGroup=null; collisionGroup = null;
float width = Float.parseFloat(map.getProperties().get("width").toString()); float width = Float.parseFloat(map.getProperties().get("width").toString());
float height = Float.parseFloat(map.getProperties().get("height").toString()); float height = Float.parseFloat(map.getProperties().get("height").toString());
@@ -281,13 +282,10 @@ public class MapStage extends GameStage {
effect = JSONStringLoader.parse(EffectData.class, map.getProperties().get("dungeonEffect").toString(), ""); effect = JSONStringLoader.parse(EffectData.class, map.getProperties().get("dungeonEffect").toString(), "");
effectDialog(effect); effectDialog(effect);
} }
if(MP.get("respawnEnemies")!=null&&MP.get("respawnEnemies") instanceof Boolean&&(Boolean)MP.get("respawnEnemies")) if (MP.get("respawnEnemies") != null && MP.get("respawnEnemies") instanceof Boolean && (Boolean) MP.get("respawnEnemies")) {
{ respawnEnemies = true;
respawnEnemies=true; } else {
} respawnEnemies = false;
else
{
respawnEnemies=false;
} }
if (MP.get("preventEscape") != null) preventEscape = (boolean) MP.get("preventEscape"); if (MP.get("preventEscape") != null) preventEscape = (boolean) MP.get("preventEscape");
@@ -310,34 +308,31 @@ public class MapStage extends GameStage {
loadObjects(layer, sourceMap); loadObjects(layer, sourceMap);
} }
} }
if(!spawnClassified.isEmpty()) if (!spawnClassified.isEmpty())
spawnClassified.first().spawn(); spawnClassified.first().spawn();
else if(!sourceMapMatch.isEmpty()) else if (!sourceMapMatch.isEmpty())
sourceMapMatch.first().spawn(); sourceMapMatch.first().spawn();
else if(!otherEntries.isEmpty()) else if (!otherEntries.isEmpty())
otherEntries.first().spawn(); otherEntries.first().spawn();
//reduce geometry in collision rectangles //reduce geometry in collision rectangles
int oldSize; int oldSize;
do { do {
oldSize=collisionRect.size; oldSize = collisionRect.size;
for(int i=0;i<collisionRect.size;i++) for (int i = 0; i < collisionRect.size; i++) {
{ Rectangle r1 = collisionRect.get(i);
Rectangle r1= collisionRect.get(i); for (int j = i + 1; j < collisionRect.size; j++) {
for(int j=i+1;j<collisionRect.size;j++) Rectangle r2 = collisionRect.get(j);
{ if ((Math.abs(r1.x - (r2.x + r2.width)) < 1 && Math.abs(r1.y - r2.y) < 1 && Math.abs(r1.height - r2.height) < 1)//left edge is the same as right edge
Rectangle r2= collisionRect.get(j);
if( (Math.abs(r1.x-(r2.x+r2.width))<1&&Math.abs(r1.y-r2.y)<1&&Math.abs(r1.height-r2.height)<1)//left edge is the same as right edge
||(Math.abs((r1.x+r1.width)-r2.x)<1&&Math.abs(r1.y-r2.y)<1&&Math.abs(r1.height-r2.height)<1)//right edge is the same as left edge || (Math.abs((r1.x + r1.width) - r2.x) < 1 && Math.abs(r1.y - r2.y) < 1 && Math.abs(r1.height - r2.height) < 1)//right edge is the same as left edge
||(Math.abs(r1.x - r2.x )<1&& Math.abs((r1.y+r1.height)-r2.y)<1&&Math.abs(r1.width-r2.width)<1)//top edge is the same as bottom edge || (Math.abs(r1.x - r2.x) < 1 && Math.abs((r1.y + r1.height) - r2.y) < 1 && Math.abs(r1.width - r2.width) < 1)//top edge is the same as bottom edge
||(Math.abs(r1.x - r2.x )<1&& Math.abs(r1.y-(r2.y+r2.height))<1&&Math.abs(r1.width-r2.width)<1)//bottom edge is the same as left edge || (Math.abs(r1.x - r2.x) < 1 && Math.abs(r1.y - (r2.y + r2.height)) < 1 && Math.abs(r1.width - r2.width) < 1)//bottom edge is the same as left edge
||containsOrEquals(r1,r2)||containsOrEquals(r2,r1) || containsOrEquals(r1, r2) || containsOrEquals(r2, r1)
) ) {
{
r1.merge(r2); r1.merge(r2);
collisionRect.removeIndex(j); collisionRect.removeIndex(j);
i--; i--;
@@ -345,19 +340,20 @@ public class MapStage extends GameStage {
} }
} }
} }
}while (oldSize!=collisionRect.size); } while (oldSize != collisionRect.size);
if (spriteLayer == null) System.err.print("Warning: No spriteLayer present in map.\n"); if (spriteLayer == null) System.err.print("Warning: No spriteLayer present in map.\n");
getPlayerSprite().stop(); getPlayerSprite().stop();
} }
static public boolean containsOrEquals(Rectangle r1,Rectangle r2) { static public boolean containsOrEquals(Rectangle r1, Rectangle r2) {
float xmi = r2.x; float xmi = r2.x;
float xma = xmi + r2.width; float xma = xmi + r2.width;
float ymi = r2.y; float ymi = r2.y;
float yma = ymi + r2.height; float yma = ymi + r2.height;
return xmi >= r1.x && xmi <= r1.x + r1.width && xma >= r1.x && xma <= r1.x + r1.width && ymi >= r1.y && ymi <= r1.y + r1.height && yma >= r1.y && yma <= r1.y + r1.height; return xmi >= r1.x && xmi <= r1.x + r1.width && xma >= r1.x && xma <= r1.x + r1.width && ymi >= r1.y && ymi <= r1.y + r1.height && yma >= r1.y && yma <= r1.y + r1.height;
} }
private void loadCollision(TiledMapTileLayer layer) { private void loadCollision(TiledMapTileLayer layer) {
for (int x = 0; x < layer.getWidth(); x++) { for (int x = 0; x < layer.getWidth(); x++) {
for (int y = 0; y < layer.getHeight(); y++) { for (int y = 0; y < layer.getHeight(); y++) {
@@ -390,7 +386,7 @@ public class MapStage extends GameStage {
for (MapObject obj : layer.getObjects()) { for (MapObject obj : layer.getObjects()) {
MapProperties prop = obj.getProperties(); MapProperties prop = obj.getProperties();
String type = prop.get("type", String.class); String type = prop.get("type", String.class);
if (type!=null) { if (type != null) {
int id = prop.get("id", int.class); int id = prop.get("id", int.class);
if (changes.isObjectDeleted(id)) if (changes.isObjectDeleted(id))
continue; continue;
@@ -403,20 +399,16 @@ public class MapStage extends GameStage {
float w = Float.parseFloat(prop.get("width").toString()); float w = Float.parseFloat(prop.get("width").toString());
float h = Float.parseFloat(prop.get("height").toString()); float h = Float.parseFloat(prop.get("height").toString());
String targetMap=prop.get("teleport").toString(); String targetMap = prop.get("teleport").toString();
boolean spawnPlayerThere=(targetMap==null||targetMap.isEmpty()&&sourceMap.isEmpty())||//if target is null and "from world" boolean spawnPlayerThere = (targetMap == null || targetMap.isEmpty() && sourceMap.isEmpty()) ||//if target is null and "from world"
!sourceMap.isEmpty()&&targetMap.equals(sourceMap); !sourceMap.isEmpty() && targetMap.equals(sourceMap);
EntryActor entry=new EntryActor(this, id, prop.get("teleport").toString(), x, y, w, h, prop.get("direction").toString()); EntryActor entry = new EntryActor(this, id, prop.get("teleport").toString(), x, y, w, h, prop.get("direction").toString());
if((prop.containsKey("spawn")&& prop.get("spawn").toString().equals("true"))&&spawnPlayerThere) if ((prop.containsKey("spawn") && prop.get("spawn").toString().equals("true")) && spawnPlayerThere) {
{
spawnClassified.add(entry); spawnClassified.add(entry);
}else if(spawnPlayerThere) } else if (spawnPlayerThere) {
{
sourceMapMatch.add(entry); sourceMapMatch.add(entry);
} } else {
else
{
otherEntries.add(entry); otherEntries.add(entry);
} }
addMapActor(obj, entry); addMapActor(obj, entry);
@@ -484,11 +476,10 @@ public class MapStage extends GameStage {
addMapActor(obj, new OnCollide(() -> Forge.switchScene(SpellSmithScene.instance()))); addMapActor(obj, new OnCollide(() -> Forge.switchScene(SpellSmithScene.instance())));
break; break;
case "arena": case "arena":
addMapActor(obj, new OnCollide(() -> { addMapActor(obj, new OnCollide(() -> {
ArenaData arenaData = JSONStringLoader.parse(ArenaData.class, prop.get("arena").toString(), ""); ArenaData arenaData = JSONStringLoader.parse(ArenaData.class, prop.get("arena").toString(), "");
ArenaScene.instance().loadArenaData(arenaData,WorldSave.getCurrentSave().getWorld().getRandom().nextLong()); ArenaScene.instance().loadArenaData(arenaData, WorldSave.getCurrentSave().getWorld().getRandom().nextLong());
Forge.switchScene(ArenaScene.instance()); Forge.switchScene(ArenaScene.instance());
})); }));
break; break;
case "exit": case "exit":
@@ -498,10 +489,10 @@ public class MapStage extends GameStage {
if (obj instanceof TiledMapTileMapObject) { if (obj instanceof TiledMapTileMapObject) {
TiledMapTileMapObject tiledObj = (TiledMapTileMapObject) obj; TiledMapTileMapObject tiledObj = (TiledMapTileMapObject) obj;
DialogActor dialog; DialogActor dialog;
if(prop.containsKey("sprite")) if (prop.containsKey("sprite"))
dialog= new DialogActor(this, id, prop.get("dialog").toString(), prop.get("sprite").toString()); dialog = new DialogActor(this, id, prop.get("dialog").toString(), prop.get("sprite").toString());
else else
dialog= new DialogActor(this, id, prop.get("dialog").toString(), tiledObj.getTextureRegion()); dialog = new DialogActor(this, id, prop.get("dialog").toString(), tiledObj.getTextureRegion());
addMapActor(obj, dialog); addMapActor(obj, dialog);
} }
break; break;
@@ -611,12 +602,12 @@ public class MapStage extends GameStage {
protected void getReward() { protected void getReward() {
isLoadingMatch = false; isLoadingMatch = false;
RewardScene.instance().loadRewards(currentMob.getRewards(), RewardScene.Type.Loot, null); RewardScene.instance().loadRewards(currentMob.getRewards(), RewardScene.Type.Loot, null);
Forge.switchScene(RewardScene.instance()); Forge.switchScene(RewardScene.instance());
if (currentMob.defeatDialog == null) { if (currentMob.defeatDialog == null) {
currentMob.remove(); currentMob.remove();
actors.removeValue(currentMob, true); actors.removeValue(currentMob, true);
if(!respawnEnemies||currentMob.getData().boss) if (!respawnEnemies || currentMob.getData().boss)
changes.deleteObject(currentMob.getId()); changes.deleteObject(currentMob.getId());
} else { } else {
currentMob.defeatDialog.activate(); currentMob.defeatDialog.activate();
@@ -638,8 +629,8 @@ public class MapStage extends GameStage {
@Override @Override
protected void onActing(float delta) { protected void onActing(float delta) {
float sprintingMod=currentModifications.containsKey(PlayerModification.Sprint)?2:1; float sprintingMod = currentModifications.containsKey(PlayerModification.Sprint) ? 2 : 1;
player.setMoveModifier(2*sprintingMod); player.setMoveModifier(2 * sprintingMod);
oldPosition4.set(oldPosition3); oldPosition4.set(oldPosition3);
oldPosition3.set(oldPosition2); oldPosition3.set(oldPosition2);
oldPosition2.set(oldPosition); oldPosition2.set(oldPosition);
@@ -659,10 +650,10 @@ public class MapStage extends GameStage {
} else if (actor instanceof RewardSprite) { } else if (actor instanceof RewardSprite) {
Gdx.input.vibrate(50); Gdx.input.vibrate(50);
if (Controllers.getCurrent() != null && Controllers.getCurrent().canVibrate()) if (Controllers.getCurrent() != null && Controllers.getCurrent().canVibrate())
Controllers.getCurrent().startVibration(100,1); Controllers.getCurrent().startVibration(100, 1);
startPause(0.1f, () -> { //Switch to item pickup scene. startPause(0.1f, () -> { //Switch to item pickup scene.
RewardSprite RS = (RewardSprite) actor; RewardSprite RS = (RewardSprite) actor;
RewardScene.instance().loadRewards(RS.getRewards(), RewardScene.Type.Loot, null); RewardScene.instance().loadRewards(RS.getRewards(), RewardScene.Type.Loot, null);
RS.remove(); RS.remove();
actors.removeValue(RS, true); actors.removeValue(RS, true);
changes.deleteObject(RS.getId()); changes.deleteObject(RS.getId());
@@ -683,11 +674,11 @@ public class MapStage extends GameStage {
Gdx.input.vibrate(50); Gdx.input.vibrate(50);
int duration = mob.getData().boss ? 400 : 200; int duration = mob.getData().boss ? 400 : 200;
if (Controllers.getCurrent() != null && Controllers.getCurrent().canVibrate()) if (Controllers.getCurrent() != null && Controllers.getCurrent().canVibrate())
Controllers.getCurrent().startVibration(duration,1); Controllers.getCurrent().startVibration(duration, 1);
startPause(0.8f, () -> { startPause(0.8f, () -> {
Forge.setCursor(null, Forge.magnifyToggle ? "1" : "2"); Forge.setCursor(null, Forge.magnifyToggle ? "1" : "2");
SoundSystem.instance.play(SoundEffectType.ManaBurn, false); SoundSystem.instance.play(SoundEffectType.ManaBurn, false);
DuelScene duelScene = DuelScene.instance(); DuelScene duelScene = DuelScene.instance();
FThreads.invokeInEdtNowOrLater(() -> { FThreads.invokeInEdtNowOrLater(() -> {
if (!isLoadingMatch) { if (!isLoadingMatch) {
isLoadingMatch = true; isLoadingMatch = true;
@@ -696,7 +687,7 @@ public class MapStage extends GameStage {
if (isInMap && effect != null) if (isInMap && effect != null)
duelScene.setDungeonEffect(effect); duelScene.setDungeonEffect(effect);
Forge.switchScene(duelScene); Forge.switchScene(duelScene);
}, Forge.takeScreenshot(), true, false)); }, Forge.takeScreenshot(), true, false, false, false, "", Current.player().avatar(), mob.getAtlasPath(), Current.player().getName(), mob.nameOverride.isEmpty() ? mob.getData().name : mob.nameOverride));
} }
}); });
}); });
@@ -709,6 +700,7 @@ public class MapStage extends GameStage {
public boolean isInMap() { public boolean isInMap() {
return isInMap; return isInMap;
} }
public boolean isDialogOnlyInput() { public boolean isDialogOnlyInput() {
return dialogOnlyInput; return dialogOnlyInput;
} }
@@ -717,12 +709,12 @@ public class MapStage extends GameStage {
dialogButtonMap.clear(); dialogButtonMap.clear();
for (int i = 0; i < dialog.getButtonTable().getCells().size; i++) { for (int i = 0; i < dialog.getButtonTable().getCells().size; i++) {
dialogButtonMap.add( (TextraButton) dialog.getButtonTable().getCells().get(i).getActor()); dialogButtonMap.add((TextraButton) dialog.getButtonTable().getCells().get(i).getActor());
} }
dialog.show(dialogStage, Actions.show()); dialog.show(dialogStage, Actions.show());
dialog.setPosition((dialogStage.getWidth() - dialog.getWidth()) / 2, (dialogStage.getHeight() - dialog.getHeight()) / 2); dialog.setPosition((dialogStage.getWidth() - dialog.getWidth()) / 2, (dialogStage.getHeight() - dialog.getHeight()) / 2);
dialogOnlyInput = true; dialogOnlyInput = true;
if (Forge.hasGamepad()&&!dialogButtonMap.isEmpty()) if (Forge.hasGamepad() && !dialogButtonMap.isEmpty())
dialogStage.setKeyboardFocus(dialogButtonMap.first()); dialogStage.setKeyboardFocus(dialogButtonMap.first());
} }
@@ -792,40 +784,36 @@ public class MapStage extends GameStage {
} }
}, 0.10f); }, 0.10f);
} }
private void selectNextDialogButton() { private void selectNextDialogButton() {
if (dialogButtonMap.size < 2) if (dialogButtonMap.size < 2)
return; return;
if(!(dialogStage.getKeyboardFocus() instanceof Button)) if (!(dialogStage.getKeyboardFocus() instanceof Button)) {
{
dialogStage.setKeyboardFocus(dialogButtonMap.first()); dialogStage.setKeyboardFocus(dialogButtonMap.first());
return; return;
} }
for(int i=0;i<dialogButtonMap.size;i++) for (int i = 0; i < dialogButtonMap.size; i++) {
{ if (dialogStage.getKeyboardFocus() == dialogButtonMap.get(i)) {
if(dialogStage.getKeyboardFocus()==dialogButtonMap.get(i)) i += 1;
{ i %= dialogButtonMap.size;
i+=1;
i%=dialogButtonMap.size;
dialogStage.setKeyboardFocus(dialogButtonMap.get(i)); dialogStage.setKeyboardFocus(dialogButtonMap.get(i));
return; return;
} }
} }
} }
private void selectPreviousDialogButton() { private void selectPreviousDialogButton() {
if (dialogButtonMap.size < 2) if (dialogButtonMap.size < 2)
return; return;
if(!(dialogStage.getKeyboardFocus() instanceof Button)) if (!(dialogStage.getKeyboardFocus() instanceof Button)) {
{
dialogStage.setKeyboardFocus(dialogButtonMap.first()); dialogStage.setKeyboardFocus(dialogButtonMap.first());
return; return;
} }
for(int i=0;i<dialogButtonMap.size;i++) for (int i = 0; i < dialogButtonMap.size; i++) {
{ if (dialogStage.getKeyboardFocus() == dialogButtonMap.get(i)) {
if(dialogStage.getKeyboardFocus()==dialogButtonMap.get(i)) i -= 1;
{ if (i < 0)
i-=1; i = dialogButtonMap.size - 1;
if(i<0)
i=dialogButtonMap.size-1;
dialogStage.setKeyboardFocus(dialogButtonMap.get(i)); dialogStage.setKeyboardFocus(dialogButtonMap.get(i));
return; return;
} }

View File

@@ -40,8 +40,7 @@ import java.util.Random;
* Stage for the over world. Will handle monster spawns * Stage for the over world. Will handle monster spawns
*/ */
public class WorldStage extends GameStage implements SaveFileContent { public class WorldStage extends GameStage implements SaveFileContent {
private static WorldStage instance = null;
private static WorldStage instance=null;
protected EnemySprite currentMob; protected EnemySprite currentMob;
protected Random rand = MyRandom.getRandom(); protected Random rand = MyRandom.getRandom();
WorldBackground background; WorldBackground background;
@@ -49,8 +48,8 @@ public class WorldStage extends GameStage implements SaveFileContent {
private static final float spawnInterval = 4;//todo config private static final float spawnInterval = 4;//todo config
private PointOfInterestMapSprite collidingPoint; private PointOfInterestMapSprite collidingPoint;
protected ArrayList<Pair<Float, EnemySprite>> enemies = new ArrayList<>(); protected ArrayList<Pair<Float, EnemySprite>> enemies = new ArrayList<>();
private final static Float dieTimer=20f;//todo config private final static Float dieTimer = 20f;//todo config
private Float globalTimer=0f; private Float globalTimer = 0f;
public WorldStage() { public WorldStage() {
super(); super();
@@ -63,57 +62,50 @@ public class WorldStage extends GameStage implements SaveFileContent {
return instance == null ? instance = new WorldStage() : instance; return instance == null ? instance = new WorldStage() : instance;
} }
final Rectangle tempBoundingRect = new Rectangle();
final Vector2 enemyMoveVector = new Vector2();
final Rectangle tempBoundingRect=new Rectangle();
final Vector2 enemyMoveVector =new Vector2();
@Override @Override
protected void onActing(float delta) { protected void onActing(float delta) {
if (player.isMoving()) { if (player.isMoving()) {
handleMonsterSpawn(delta); handleMonsterSpawn(delta);
handlePointsOfInterestCollision(); handlePointsOfInterestCollision();
globalTimer+=delta; globalTimer += delta;
Iterator<Pair<Float, EnemySprite>> it = enemies.iterator(); Iterator<Pair<Float, EnemySprite>> it = enemies.iterator();
while (it.hasNext()) { while (it.hasNext()) {
Pair<Float, EnemySprite> pair= it.next(); Pair<Float, EnemySprite> pair = it.next();
if(globalTimer>=pair.getKey()+dieTimer) if (globalTimer >= pair.getKey() + dieTimer) {
{
foregroundSprites.removeActor(pair.getValue()); foregroundSprites.removeActor(pair.getValue());
it.remove(); it.remove();
continue; continue;
} }
EnemySprite mob=pair.getValue(); EnemySprite mob = pair.getValue();
if(!currentModifications.containsKey(PlayerModification.Hide)) if (!currentModifications.containsKey(PlayerModification.Hide)) {
{
enemyMoveVector.set(player.getX(), player.getY()).sub(mob.pos()); enemyMoveVector.set(player.getX(), player.getY()).sub(mob.pos());
enemyMoveVector.setLength(mob.speed()*delta); enemyMoveVector.setLength(mob.speed() * delta);
tempBoundingRect.set(mob.getX()+ enemyMoveVector.x,mob.getY()+ enemyMoveVector.y,mob.getWidth(),mob.getHeight()*mob.getCollisionHeight()); tempBoundingRect.set(mob.getX() + enemyMoveVector.x, mob.getY() + enemyMoveVector.y, mob.getWidth(), mob.getHeight() * mob.getCollisionHeight());
if(!mob.getData().flying && WorldSave.getCurrentSave().getWorld().collidingTile(tempBoundingRect))//if direct path is not possible if (!mob.getData().flying && WorldSave.getCurrentSave().getWorld().collidingTile(tempBoundingRect))//if direct path is not possible
{ {
tempBoundingRect.set(mob.getX()+ enemyMoveVector.x,mob.getY(),mob.getWidth(),mob.getHeight()); tempBoundingRect.set(mob.getX() + enemyMoveVector.x, mob.getY(), mob.getWidth(), mob.getHeight());
if(WorldSave.getCurrentSave().getWorld().collidingTile(tempBoundingRect))//if only x path is not possible if (WorldSave.getCurrentSave().getWorld().collidingTile(tempBoundingRect))//if only x path is not possible
{ {
tempBoundingRect.set(mob.getX(),mob.getY()+ enemyMoveVector.y,mob.getWidth(),mob.getHeight()); tempBoundingRect.set(mob.getX(), mob.getY() + enemyMoveVector.y, mob.getWidth(), mob.getHeight());
if(!WorldSave.getCurrentSave().getWorld().collidingTile(tempBoundingRect))//if y path is possible if (!WorldSave.getCurrentSave().getWorld().collidingTile(tempBoundingRect))//if y path is possible
{ {
mob.moveBy(0, enemyMoveVector.y); mob.moveBy(0, enemyMoveVector.y);
} }
} } else {
else
{
mob.moveBy(enemyMoveVector.x, 0); mob.moveBy(enemyMoveVector.x, 0);
} }
} } else {
else
{
mob.moveBy(enemyMoveVector.x, enemyMoveVector.y); mob.moveBy(enemyMoveVector.x, enemyMoveVector.y);
} }
} }
if (player.collideWith(mob)) { if (player.collideWith(mob)) {
player.setAnimation(CharacterSprite.AnimationTypes.Attack); player.setAnimation(CharacterSprite.AnimationTypes.Attack);
mob.setAnimation(CharacterSprite.AnimationTypes.Attack); mob.setAnimation(CharacterSprite.AnimationTypes.Attack);
@@ -121,16 +113,16 @@ public class WorldStage extends GameStage implements SaveFileContent {
Gdx.input.vibrate(50); Gdx.input.vibrate(50);
int duration = mob.getData().boss ? 400 : 200; int duration = mob.getData().boss ? 400 : 200;
if (Controllers.getCurrent() != null && Controllers.getCurrent().canVibrate()) if (Controllers.getCurrent() != null && Controllers.getCurrent().canVibrate())
Controllers.getCurrent().startVibration(duration,1); Controllers.getCurrent().startVibration(duration, 1);
startPause(0.8f, () -> { startPause(0.8f, () -> {
Forge.setCursor(null, Forge.magnifyToggle ? "1" : "2"); Forge.setCursor(null, Forge.magnifyToggle ? "1" : "2");
SoundSystem.instance.play(SoundEffectType.ManaBurn, false); SoundSystem.instance.play(SoundEffectType.ManaBurn, false);
DuelScene duelScene = DuelScene.instance(); DuelScene duelScene = DuelScene.instance();
FThreads.invokeInEdtNowOrLater(() -> { FThreads.invokeInEdtNowOrLater(() -> {
Forge.setTransitionScreen(new TransitionScreen(() -> { Forge.setTransitionScreen(new TransitionScreen(() -> {
duelScene.initDuels(player, mob); duelScene.initDuels(player, mob);
Forge.switchScene(duelScene); Forge.switchScene(duelScene);
}, Forge.takeScreenshot(), true, false)); }, Forge.takeScreenshot(), true, false, false, false, "", Current.player().avatar(), mob.getAtlasPath(), Current.player().getName(), mob.nameOverride.isEmpty() ? mob.getData().name : mob.nameOverride));
currentMob = mob; currentMob = mob;
WorldSave.getCurrentSave().autoSave(); WorldSave.getCurrentSave().autoSave();
}); });
@@ -138,29 +130,27 @@ public class WorldStage extends GameStage implements SaveFileContent {
break; break;
} }
} }
} else { } else {
for (Pair<Float, EnemySprite> pair : enemies) { for (Pair<Float, EnemySprite> pair : enemies) {
pair.getValue().setAnimation(CharacterSprite.AnimationTypes.Idle); pair.getValue().setAnimation(CharacterSprite.AnimationTypes.Idle);
} }
} }
} }
private void removeEnemy(EnemySprite currentMob) {
private void removeEnemy(EnemySprite currentMob) {
currentMob.removeAfterEffects(); currentMob.removeAfterEffects();
Iterator<Pair<Float, EnemySprite>> it = enemies.iterator(); Iterator<Pair<Float, EnemySprite>> it = enemies.iterator();
while (it.hasNext()) { while (it.hasNext()) {
Pair<Float, EnemySprite> pair = it.next(); Pair<Float, EnemySprite> pair = it.next();
if (pair.getValue()==currentMob) { if (pair.getValue() == currentMob) {
it.remove(); it.remove();
return; return;
} }
} }
} }
@Override @Override
public void setWinner(boolean playerIsWinner) { public void setWinner(boolean playerIsWinner) {
if (playerIsWinner) { if (playerIsWinner) {
Current.player().win(); Current.player().win();
player.setAnimation(CharacterSprite.AnimationTypes.Attack); player.setAnimation(CharacterSprite.AnimationTypes.Attack);
@@ -179,12 +169,10 @@ public class WorldStage extends GameStage implements SaveFileContent {
WorldStage.this.removeEnemy(currentMob); WorldStage.this.removeEnemy(currentMob);
currentMob = null; currentMob = null;
}); });
} }
} }
public void handlePointsOfInterestCollision() {
public void handlePointsOfInterestCollision() {
for (Actor actor : foregroundSprites.getChildren()) { for (Actor actor : foregroundSprites.getChildren()) {
if (actor.getClass() == PointOfInterestMapSprite.class) { if (actor.getClass() == PointOfInterestMapSprite.class) {
PointOfInterestMapSprite point = (PointOfInterestMapSprite) actor; PointOfInterestMapSprite point = (PointOfInterestMapSprite) actor;
@@ -200,18 +188,17 @@ public class WorldStage extends GameStage implements SaveFileContent {
} }
} }
} }
} }
} }
@Override @Override
public boolean isColliding(Rectangle boundingRect) public boolean isColliding(Rectangle boundingRect) {
{ if (currentModifications.containsKey(PlayerModification.Fly))
if(currentModifications.containsKey(PlayerModification.Fly))
return false; return false;
return WorldSave.getCurrentSave().getWorld().collidingTile(boundingRect); return WorldSave.getCurrentSave().getWorld().collidingTile(boundingRect);
} }
public boolean spawn(String enemy)
{ public boolean spawn(String enemy) {
return spawn(WorldData.getEnemy(enemy)); return spawn(WorldData.getEnemy(enemy));
} }
@@ -219,23 +206,23 @@ public class WorldStage extends GameStage implements SaveFileContent {
World world = WorldSave.getCurrentSave().getWorld(); World world = WorldSave.getCurrentSave().getWorld();
int currentBiome = World.highestBiome(world.getBiome((int) player.getX() / world.getTileSize(), (int) player.getY() / world.getTileSize())); int currentBiome = World.highestBiome(world.getBiome((int) player.getX() / world.getTileSize(), (int) player.getY() / world.getTileSize()));
List<BiomeData> biomeData = WorldSave.getCurrentSave().getWorld().getData().GetBiomes(); List<BiomeData> biomeData = WorldSave.getCurrentSave().getWorld().getData().GetBiomes();
float sprintingMod=currentModifications.containsKey(PlayerModification.Sprint)?2:1; float sprintingMod = currentModifications.containsKey(PlayerModification.Sprint) ? 2 : 1;
if (biomeData.size() <= currentBiome) {// "if isOnRoad if (biomeData.size() <= currentBiome) {// "if isOnRoad
player.setMoveModifier(1.5f*sprintingMod); player.setMoveModifier(1.5f * sprintingMod);
return; return;
} }
player.setMoveModifier(1.0f*sprintingMod); player.setMoveModifier(1.0f * sprintingMod);
BiomeData data = biomeData.get(currentBiome); BiomeData data = biomeData.get(currentBiome);
if (data == null) return; if (data == null) return;
spawnDelay -= delta; spawnDelay -= delta;
if(spawnDelay>=0) return; if (spawnDelay >= 0) return;
spawnDelay=spawnInterval + ( rand.nextFloat() * 4.0f ); spawnDelay = spawnInterval + (rand.nextFloat() * 4.0f);
ArrayList<EnemyData> list = data.getEnemyList(); ArrayList<EnemyData> list = data.getEnemyList();
if (list == null) if (list == null)
return; return;
EnemyData enemyData = data.getEnemy( 1.0f ); EnemyData enemyData = data.getEnemy(1.0f);
spawn(enemyData); spawn(enemyData);
} }
@@ -245,23 +232,20 @@ public class WorldStage extends GameStage implements SaveFileContent {
EnemySprite sprite = new EnemySprite(enemyData); EnemySprite sprite = new EnemySprite(enemyData);
float unit = Scene.getIntendedHeight() / 6f; float unit = Scene.getIntendedHeight() / 6f;
Vector2 spawnPos = new Vector2(1, 1); Vector2 spawnPos = new Vector2(1, 1);
for(int j=0;j<10;j++) for (int j = 0; j < 10; j++) {
{
spawnPos.setLength(unit + (unit * 3) * rand.nextFloat()); spawnPos.setLength(unit + (unit * 3) * rand.nextFloat());
spawnPos.setAngleDeg(360 * rand.nextFloat()); spawnPos.setAngleDeg(360 * rand.nextFloat());
for(int i=0;i<10;i++) for (int i = 0; i < 10; i++) {
{ boolean enemyXIsBigger = sprite.getX() > player.getX();
boolean enemyXIsBigger=sprite.getX()>player.getX(); boolean enemyYIsBigger = sprite.getY() > player.getY();
boolean enemyYIsBigger=sprite.getY()>player.getY(); sprite.setX(player.getX() + spawnPos.x + (i * sprite.getWidth() * (enemyXIsBigger ? 1 : -1)));//maybe find a better way to get spawn points
sprite.setX(player.getX() + spawnPos.x+(i*sprite.getWidth()*(enemyXIsBigger?1:-1)));//maybe find a better way to get spawn points sprite.setY(player.getY() + spawnPos.y + (i * sprite.getHeight() * (enemyYIsBigger ? 1 : -1)));
sprite.setY(player.getY() + spawnPos.y+(i*sprite.getHeight()*(enemyYIsBigger?1:-1))); if (sprite.getData().flying || !WorldSave.getCurrentSave().getWorld().collidingTile(sprite.boundingRect())) {
if(sprite.getData().flying || !WorldSave.getCurrentSave().getWorld().collidingTile(sprite.boundingRect())) enemies.add(Pair.of(globalTimer, sprite));
{
enemies.add(Pair.of(globalTimer,sprite));
foregroundSprites.addActor(sprite); foregroundSprites.addActor(sprite);
return true; return true;
} }
int g=0; int g = 0;
} }
} }
return false; return false;
@@ -273,13 +257,13 @@ public class WorldStage extends GameStage implements SaveFileContent {
//spriteGroup.setCullingArea(new Rectangle(player.getX()-getViewport().getWorldHeight()/2,player.getY()-getViewport().getWorldHeight()/2,getViewport().getWorldHeight(),getViewport().getWorldHeight())); //spriteGroup.setCullingArea(new Rectangle(player.getX()-getViewport().getWorldHeight()/2,player.getY()-getViewport().getWorldHeight()/2,getViewport().getWorldHeight(),getViewport().getWorldHeight()));
super.draw(); super.draw();
if (WorldSave.getCurrentSave().getPlayer().hasAnnounceFantasy()) { if (WorldSave.getCurrentSave().getPlayer().hasAnnounceFantasy()) {
MapStage.getInstance().showDeckAwardDialog("{BLINK=WHITE;RED}Chaos Mode!{ENDBLINK}\n"+ WorldSave.getCurrentSave().getPlayer().getName()+ "'s Deck: "+ MapStage.getInstance().showDeckAwardDialog("{BLINK=WHITE;RED}Chaos Mode!{ENDBLINK}\n" + WorldSave.getCurrentSave().getPlayer().getName() + "'s Deck: " +
WorldSave.getCurrentSave().getPlayer().getSelectedDeck().getName()+ WorldSave.getCurrentSave().getPlayer().getSelectedDeck().getName() +
"\nEnemy will use Preconstructed or Random Generated Decks. Genetic AI Decks will be available to some enemies on Hard difficulty.", WorldSave.getCurrentSave().getPlayer().getSelectedDeck()); "\nEnemy will use Preconstructed or Random Generated Decks. Genetic AI Decks will be available to some enemies on Hard difficulty.", WorldSave.getCurrentSave().getPlayer().getSelectedDeck());
WorldSave.getCurrentSave().getPlayer().clearAnnounceFantasy(); WorldSave.getCurrentSave().getPlayer().clearAnnounceFantasy();
} else if (WorldSave.getCurrentSave().getPlayer().hasAnnounceCustom()) { } else if (WorldSave.getCurrentSave().getPlayer().hasAnnounceCustom()) {
MapStage.getInstance().showDeckAwardDialog("{GRADIENT}Custom Deck Mode!{ENDGRADIENT}\n"+ WorldSave.getCurrentSave().getPlayer().getName()+ "'s Deck: "+ MapStage.getInstance().showDeckAwardDialog("{GRADIENT}Custom Deck Mode!{ENDGRADIENT}\n" + WorldSave.getCurrentSave().getPlayer().getName() + "'s Deck: " +
WorldSave.getCurrentSave().getPlayer().getSelectedDeck().getName()+ WorldSave.getCurrentSave().getPlayer().getSelectedDeck().getName() +
"\nSome enemies will use Genetic AI Decks randomly.", WorldSave.getCurrentSave().getPlayer().getSelectedDeck()); "\nSome enemies will use Genetic AI Decks randomly.", WorldSave.getCurrentSave().getPlayer().getSelectedDeck());
WorldSave.getCurrentSave().getPlayer().clearAnnounceCustom(); WorldSave.getCurrentSave().getPlayer().clearAnnounceCustom();
} }
@@ -287,7 +271,6 @@ public class WorldStage extends GameStage implements SaveFileContent {
@Override @Override
public void enter() { public void enter() {
getPlayerSprite().LoadPos(); getPlayerSprite().LoadPos();
getPlayerSprite().setMovementDirection(Vector2.Zero); getPlayerSprite().setMovementDirection(Vector2.Zero);
for (Actor actor : foregroundSprites.getChildren()) { for (Actor actor : foregroundSprites.getChildren()) {
@@ -297,12 +280,10 @@ public class WorldStage extends GameStage implements SaveFileContent {
collidingPoint = point; collidingPoint = point;
} }
} }
} }
setBounds(WorldSave.getCurrentSave().getWorld().getWidthInPixels(), WorldSave.getCurrentSave().getWorld().getHeightInPixels()); setBounds(WorldSave.getCurrentSave().getWorld().getWidthInPixels(), WorldSave.getCurrentSave().getWorld().getHeightInPixels());
GridPoint2 pos = background.translateFromWorldToChunk(player.getX(), player.getY()); GridPoint2 pos = background.translateFromWorldToChunk(player.getX(), player.getY());
background.loadChunk(pos.x,pos.y); background.loadChunk(pos.x, pos.y);
handlePointsOfInterestCollision(); handlePointsOfInterestCollision();
} }
@@ -315,57 +296,49 @@ public class WorldStage extends GameStage implements SaveFileContent {
public void load(SaveFileData data) { public void load(SaveFileData data) {
try { try {
clearCache(); clearCache();
List<Float> timeouts = (List<Float>) data.readObject("timeouts");
List<String> names = (List<String>) data.readObject("names");
List<Float> x = (List<Float>) data.readObject("x");
List<Float> timeouts= (List<Float>) data.readObject("timeouts"); List<Float> y = (List<Float>) data.readObject("y");
List<String> names = (List<String>) data.readObject("names"); for (int i = 0; i < timeouts.size(); i++) {
List<Float> x = (List<Float>) data.readObject("x");
List<Float> y = (List<Float>) data.readObject("y");
for(int i=0;i<timeouts.size();i++)
{
EnemySprite sprite = new EnemySprite(WorldData.getEnemy(names.get(i))); EnemySprite sprite = new EnemySprite(WorldData.getEnemy(names.get(i)));
sprite.setX(x.get(i)); sprite.setX(x.get(i));
sprite.setY(y.get(i)); sprite.setY(y.get(i));
enemies.add(Pair.of(timeouts.get(i),sprite)); enemies.add(Pair.of(timeouts.get(i), sprite));
foregroundSprites.addActor(sprite); foregroundSprites.addActor(sprite);
} }
globalTimer=data.readFloat("globalTimer"); globalTimer = data.readFloat("globalTimer");
} } catch (Exception e) {
catch (Exception e)
{
} }
} }
public void clearCache() { public void clearCache() {
for (Pair<Float, EnemySprite> enemy : enemies)
for(Pair<Float, EnemySprite> enemy:enemies)
foregroundSprites.removeActor(enemy.getValue()); foregroundSprites.removeActor(enemy.getValue());
enemies.clear(); enemies.clear();
background.clear(); background.clear();
player=null; player = null;
} }
@Override @Override
public SaveFileData save() { public SaveFileData save() {
SaveFileData data=new SaveFileData(); SaveFileData data = new SaveFileData();
List<Float> timeouts=new ArrayList<>(); List<Float> timeouts = new ArrayList<>();
List<String> names=new ArrayList<>(); List<String> names = new ArrayList<>();
List<Float> x=new ArrayList<>(); List<Float> x = new ArrayList<>();
List<Float> y=new ArrayList<>(); List<Float> y = new ArrayList<>();
for(Pair<Float, EnemySprite> enemy:enemies) for (Pair<Float, EnemySprite> enemy : enemies) {
{
timeouts.add(enemy.getKey()); timeouts.add(enemy.getKey());
names.add(enemy.getValue().getData().name); names.add(enemy.getValue().getData().name);
x.add(enemy.getValue().getX()); x.add(enemy.getValue().getX());
y.add(enemy.getValue().getY()); y.add(enemy.getValue().getY());
} }
data.storeObject("timeouts",timeouts); data.storeObject("timeouts", timeouts);
data.storeObject("names",names); data.storeObject("names", names);
data.storeObject("x",x); data.storeObject("x", x);
data.storeObject("y",y); data.storeObject("y", y);
data.store("globalTimer",globalTimer); data.store("globalTimer", globalTimer);
return data; return data;
} }
@@ -376,23 +349,19 @@ public class WorldStage extends GameStage implements SaveFileContent {
public void removeNearestEnemy() { public void removeNearestEnemy() {
float shortestDist = Float.MAX_VALUE;
float shortestDist=Float.MAX_VALUE; EnemySprite enemy = null;
EnemySprite enemy=null;
for (Pair<Float, EnemySprite> pair : enemies) { for (Pair<Float, EnemySprite> pair : enemies) {
float dist= pair.getValue().pos().sub(player.pos()).len(); float dist = pair.getValue().pos().sub(player.pos()).len();
if(dist<shortestDist) if (dist < shortestDist) {
{ shortestDist = dist;
shortestDist=dist; enemy = pair.getValue();
enemy=pair.getValue();
} }
} }
if(enemy!=null) if (enemy != null) {
{
enemy.playEffect(Paths.EFFECT_KILL); enemy.playEffect(Paths.EFFECT_KILL);
removeEnemy(enemy); removeEnemy(enemy);
player.playEffect(Paths.TRIGGER_KILL); player.playEffect(Paths.TRIGGER_KILL);
} }
} }
} }

View File

@@ -229,13 +229,15 @@ public class Controls {
switch (fontName) { switch (fontName) {
case "blackbig": case "blackbig":
case "big": case "big":
getSkin().getFont("default").getData().setScale(2, 2); return getBitmapFont("default", 2);
return getSkin().getFont("default");
default: default:
getSkin().getFont("default").getData().setScale(1, 1); return getBitmapFont("default", 1);
return getSkin().getFont("default");
} }
} }
static public BitmapFont getBitmapFont(String fontName, float scaleXY) {
getSkin().getFont(fontName).getData().setScale(scaleXY, scaleXY);
return getSkin().getFont("default");
}
static public Skin getSkin() { static public Skin getSkin() {
FileHandle skinFile = Config.instance().getFile(Paths.SKIN); FileHandle skinFile = Config.instance().getFile(Paths.SKIN);

View File

@@ -1,41 +1,44 @@
package forge.screens; package forge.screens;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import forge.Forge; import forge.Forge;
import forge.Graphics; import forge.Graphics;
import forge.adventure.scene.ArenaScene; import forge.adventure.scene.ArenaScene;
import forge.adventure.util.Config; import forge.adventure.util.Config;
import forge.adventure.util.Controls;
import forge.animation.ForgeAnimation; import forge.animation.ForgeAnimation;
import forge.assets.FSkin; import forge.assets.FSkin;
import forge.assets.FSkinImage; import forge.assets.FSkinImage;
import forge.assets.FSkinTexture; import forge.assets.FSkinTexture;
import forge.gui.FThreads; import forge.gui.FThreads;
import forge.gui.GuiBase;
import forge.sound.SoundSystem; import forge.sound.SoundSystem;
import forge.toolbox.FContainer; import forge.toolbox.FContainer;
import forge.toolbox.FProgressBar; import forge.toolbox.FProgressBar;
import forge.util.MyRandom;
public class TransitionScreen extends FContainer { public class TransitionScreen extends FContainer {
private BGAnimation bgAnimation; private BGAnimation bgAnimation;
private FProgressBar progressBar; private FProgressBar progressBar;
Runnable runnable; Runnable runnable;
TextureRegion textureRegion, screenUIBackground, playerAvatar, vsTexture; TextureRegion textureRegion, screenUIBackground, playerAvatar;
String enemyAtlasPath; Texture vsTexture;
String enemyAtlasPath, playerAvatarName, enemyAvatarName;
private String message = ""; private String message = "";
boolean matchTransition, isloading, isIntro, isFadeMusic, isArenaScene; boolean matchTransition, isloading, isIntro, isFadeMusic, isArenaScene;
GlyphLayout layout;
public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading) { public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading) {
this(proc, screen, enterMatch, loading, false, false); this(proc, screen, enterMatch, loading, false, false);
} }
public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading, String loadingMessage) { public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading, String loadingMessage) {
this(proc, screen, enterMatch, loading, false, false, loadingMessage, null, null, ""); this(proc, screen, enterMatch, loading, false, false, loadingMessage, null, "", "", "");
} }
public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading, boolean intro, boolean fadeMusic) { public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading, boolean intro, boolean fadeMusic) {
this(proc, screen, enterMatch, loading, intro, fadeMusic, "", null, null, ""); this(proc, screen, enterMatch, loading, intro, fadeMusic, "", null, "", "", "");
} }
public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading, boolean intro, boolean fadeMusic, String loadingMessage, TextureRegion vsIcon, TextureRegion player, String enemy) { public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading, boolean intro, boolean fadeMusic, String loadingMessage, TextureRegion player, String enemyAtlas, String playerName, String enemyName) {
progressBar = new FProgressBar(); progressBar = new FProgressBar();
progressBar.setMaximum(100); progressBar.setMaximum(100);
progressBar.setPercentMode(true); progressBar.setPercentMode(true);
@@ -57,8 +60,11 @@ public class TransitionScreen extends FContainer {
screenUIBackground = null; screenUIBackground = null;
} }
playerAvatar = player; playerAvatar = player;
enemyAtlasPath = enemy; playerAvatarName = playerName;
vsTexture = vsIcon; enemyAvatarName = enemyName;
enemyAtlasPath = enemyAtlas;
vsTexture = Forge.getAssets().fallback_skins().get(2);
layout = new GlyphLayout();
} }
public FProgressBar getProgressBar() { public FProgressBar getProgressBar() {
@@ -128,45 +134,59 @@ public class TransitionScreen extends FContainer {
g.draw(progressBar); g.draw(progressBar);
} }
} else if (matchTransition) { } else if (matchTransition) {
float screenW = Forge.isLandscapeMode() ? Forge.getScreenWidth() : Forge.getScreenHeight();
float screenH = Forge.isLandscapeMode() ? Forge.getScreenHeight() : Forge.getScreenWidth();
float scale = screenW/4;
float centerX = screenW/2;
float centerY = screenH/2;
TextureRegion enemyAvatar = Config.instance().getAtlas(enemyAtlasPath).createSprite("Avatar");
enemyAvatar.flip(true, false);
BitmapFont font = Controls.getBitmapFont("default", 5f);
if (textureRegion != null) { if (textureRegion != null) {
if (isArenaScene) { if (isArenaScene)
float screenW = Forge.isLandscapeMode() ? Forge.getScreenWidth() : Forge.getScreenHeight(); g.drawImage(screenUIBackground, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight());
float screenH = Forge.isLandscapeMode() ? Forge.getScreenHeight() : Forge.getScreenWidth(); else
float scale = screenW/4; g.drawImage(FSkinTexture.ADV_BG_TEXTURE, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight());
float centerX = screenW/2; g.setAlphaComposite(1-percentage);
float centerY = screenH/2; g.drawImage(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight());
TextureRegion enemyAvatar = Config.instance().getAtlas(enemyAtlasPath).createSprite("Avatar"); g.setAlphaComposite(oldAlpha);
enemyAvatar.flip(true, false);
g.drawChromatic(screenUIBackground, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), 1.1f*percentage);
if (Forge.isLandscapeMode()) {
g.drawImage(playerAvatar, scale / 3 * percentage, centerY - scale / 2, scale, scale);
g.drawImage(enemyAvatar, screenW - scale - (percentage * scale / 3), centerY - scale / 2, scale, scale);
float vsScale = (screenW / 3.2f) * percentage;
g.startRotateTransform(screenW/2, screenH/2, 180-(180*percentage));
g.drawImage(vsTexture, centerX - vsScale / 2, centerY - vsScale / 2, vsScale, vsScale);
g.endTransform();
} else {
g.drawImage(playerAvatar, centerY - scale / 2, scale / 3 * percentage, scale, scale);
g.drawImage(enemyAvatar,centerY - scale / 2 ,screenW - scale - (percentage * scale / 3), scale, scale);
float vsScale = (screenW / 3.2f) * percentage;
g.startRotateTransform(screenH/2, screenW/2, 180-(180*percentage));
g.drawImage(vsTexture, centerY - vsScale / 2, centerX - vsScale / 2, vsScale, vsScale);
g.endTransform();
}
g.setAlphaComposite(1-(percentage+0.6f));
g.drawImage(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight());
g.setAlphaComposite(oldAlpha);
} else {
if (GuiBase.isAndroid()) {
g.drawChromatic(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), percentage);
} else {
int max = Forge.isLandscapeMode() ? Forge.getScreenHeight() / 32 : Forge.getScreenWidth() / 32;
int min = Forge.isLandscapeMode() ? Forge.getScreenHeight() / 64 : Forge.getScreenWidth() / 64;
int val = MyRandom.getRandom().nextInt(max - min) + min;
g.drawPixelatedWarp(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), val * percentage);
}
}
} }
if (Forge.isLandscapeMode()) {
//player
float playerAvatarX = (screenW/4 - scale/2) * percentage;
float playerAvatarY = centerY - scale/2;
g.drawImage(playerAvatar, playerAvatarX, playerAvatarY, scale, scale);
layout.setText(font, playerAvatarName);
g.drawText(playerAvatarName, font, screenW/4 - layout.width/2, playerAvatarY - layout.height, Color.WHITE, percentage);
//enemy
float enemyAvatarX = screenW - screenW/4 - (scale/2 * percentage);
float enemyAvatarY = centerY - scale/2;
g.drawImage(enemyAvatar, enemyAvatarX, enemyAvatarY, scale, scale);
layout.setText(font, enemyAvatarName);
g.drawText(enemyAvatarName, font, screenW - screenW/4 - layout.width/2, enemyAvatarY - layout.height, Color.WHITE, percentage);
//vs
float vsScale = (screenW / 3.2f);
g.drawHueShift(vsTexture, centerX - vsScale / 2, centerY - vsScale / 2, vsScale, vsScale, percentage*4);
} else {
//enemy
float enemyAvatarX = centerY - scale / 2;
float enemyAvatarY = scale / 3 * percentage;
g.drawImage(enemyAvatar, enemyAvatarX, enemyAvatarY, scale, scale);
//player
float playerAvatarX = centerY - scale / 2;
float playerAvatarY = screenW - scale - (percentage * scale / 3);
g.drawImage(playerAvatar, playerAvatarX, playerAvatarY, scale, scale);
//vs
float vsScale = (screenW / 3.2f);
g.drawHueShift(vsTexture, centerY - vsScale / 2, centerX - vsScale / 2, vsScale, vsScale, percentage*4);
//names
layout.setText(font, enemyAvatarName);
g.drawText(enemyAvatarName, font, centerY - layout.width/2, screenW - scale/4, Color.WHITE, percentage);
layout.setText(font, playerAvatarName);
g.drawText(playerAvatarName, font, centerY - layout.width/2, 0 + scale/4, Color.WHITE, percentage);
}
//reset bitmapfont
Controls.getBitmapFont("default");
} else if (isIntro) { } else if (isIntro) {
if (textureRegion != null) { if (textureRegion != null) {
if (Forge.advStartup) { if (Forge.advStartup) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 67 KiB