file_name
stringlengths 6
86
| file_path
stringlengths 45
249
| content
stringlengths 47
6.26M
| file_size
int64 47
6.26M
| language
stringclasses 1
value | extension
stringclasses 1
value | repo_name
stringclasses 767
values | repo_stars
int64 8
14.4k
| repo_forks
int64 0
1.17k
| repo_open_issues
int64 0
788
| repo_created_at
stringclasses 767
values | repo_pushed_at
stringclasses 767
values |
---|---|---|---|---|---|---|---|---|---|---|---|
RandomRotationSingleParticleGenerator.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomRotationSingleParticleGenerator.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import java.util.Random;
import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator;
import seventh.shared.TimeStep;
/**
* Randomly assigns a rotation factor to a particle
*
* @author Tony
*
*/
public class RandomRotationSingleParticleGenerator implements SingleParticleGenerator {
public RandomRotationSingleParticleGenerator() {
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.BatchedParticleGenerator.SingleParticleGenerator#onGenerateParticle(int, seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) {
Random rand = particles.emitter.getRandom();
float rotation = rand.nextInt(360);
particles.rotation[index] = rotation;
}
}
| 951 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
BlendingSpriteParticleRenderer.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/BlendingSpriteParticleRenderer.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Sprite;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.effects.particle_system.Emitter.ParticleRenderer;
import seventh.math.Vector2f;
import seventh.shared.TimeStep;
/**
* @author Tony
*
*/
public class BlendingSpriteParticleRenderer implements ParticleRenderer {
/**
*
*/
public BlendingSpriteParticleRenderer() {
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.Emitter.ParticleRenderer#update(seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void update(TimeStep timeStep, ParticleData particles) {
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.Emitter.ParticleRenderer#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, float, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) {
int src = canvas.getSrcBlendFunction();
int dst = canvas.getDstBlendFunction();
//canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_FUNC_ADD);
canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
Gdx.gl20.glBlendEquation(GL20.GL_FUNC_ADD);
Vector2f cameraPos = camera.getRenderPosition(alpha);
for(int i = 0; i < particles.numberOfAliveParticles; i++) {
Sprite sprite = particles.sprite[i];
Vector2f pos = particles.pos[i];
sprite.setPosition(pos.x - cameraPos.x, pos.y - cameraPos.y);
sprite.setScale(particles.scale[i]);
sprite.setColor(particles.color[i]);
sprite.setRotation(particles.rotation[i]);
canvas.drawRawSprite(sprite);
}
canvas.setBlendFunction(src, dst);
}
}
| 2,033 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
RandomSpriteSingleParticleGenerator.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomSpriteSingleParticleGenerator.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import java.util.Random;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator;
import seventh.shared.TimeStep;
/**
* Randomly assigns a {@link Texture} to a particle
*
* @author Tony
*
*/
public class RandomSpriteSingleParticleGenerator implements SingleParticleGenerator {
private TextureRegion[] regions;
/**
*
*/
public RandomSpriteSingleParticleGenerator(TextureRegion ... regions) {
this.regions = regions;
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.BatchedParticleGenerator.SingleParticleGenerator#onGenerateParticle(int, seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) {
Random rand = particles.emitter.getRandom();
particles.sprite[index].set(new Sprite(this.regions[rand.nextInt(this.regions.length)]));
particles.sprite[index].setFlip(false, true);
// particles.sprite[index] = new Sprite(this.regions[rand.nextInt(this.regions.length)]);
// particles.sprite[index].flip(false, true);
}
}
| 1,417 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
KillIfAttachedIsDeadUpdater.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/KillIfAttachedIsDeadUpdater.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import seventh.client.entities.ClientEntity;
import seventh.client.gfx.effects.particle_system.Emitter.ParticleUpdater;
import seventh.shared.TimeStep;
/**
* Stop the emitter if the attached entity is dead
*
* @author Tony
*
*/
public class KillIfAttachedIsDeadUpdater implements ParticleUpdater {
/**
*
*/
public KillIfAttachedIsDeadUpdater() {
}
@Override
public void reset() {
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.Emitter.ParticleUpdater#update(seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void update(TimeStep timeStep, ParticleData particles) {
Emitter emitter = particles.emitter;
ClientEntity ent = emitter.attachedTo();
if(ent!=null && !ent.isAlive()) {
emitter.stop();
}
}
}
| 964 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ParticleData.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/ParticleData.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import seventh.math.Vector2f;
import seventh.shared.Timer;
/**
* Contains particle data
*
* @author Tony
*
*/
public class ParticleData {
public final int maxParticles;
public int numberOfAliveParticles;
public Emitter emitter;
public Vector2f[] pos;
public Vector2f[] vel;
public boolean[] isAlive;
public Timer[] timeToLive;
public float[] scale;
public float[] rotation;
public float[] speed;
public Color[] color;
public Sprite[] sprite;
public ParticleData(int maxParticles) {
this.maxParticles = maxParticles;
this.numberOfAliveParticles = 0;
this.pos = new Vector2f[maxParticles];
this.vel = new Vector2f[maxParticles];
this.isAlive = new boolean[maxParticles];
this.timeToLive = new Timer[maxParticles];
this.scale = new float[maxParticles];
this.rotation = new float[maxParticles];
this.speed = new float[maxParticles];
this.color = new Color[maxParticles];
this.sprite = new Sprite[maxParticles];
for(int i = 0; i < maxParticles; i++) {
this.pos[i] = new Vector2f();
this.vel[i] = new Vector2f();
this.timeToLive[i] = new Timer(false, 0);
this.color[i] = new Color(1,1,1,1);
this.sprite[i] = new Sprite();
this.scale[i] = 1.0f;
}
}
public int spawnParticle() {
int index = -1;
if(this.numberOfAliveParticles < this.maxParticles) {
index = this.numberOfAliveParticles;
this.numberOfAliveParticles++;
}
return index;
}
public void reset() {
this.numberOfAliveParticles = 0;
for(int i = 0; i < maxParticles; i++) {
this.pos[i].zeroOut();
this.vel[i].zeroOut();
this.timeToLive[i].reset();
this.color[i].set(1, 1, 1, 1);
this.isAlive[i] = false;
this.scale[i] = 1.0f;
this.rotation[i] = 0f;
}
}
public void kill(int index) {
if(index > -1 && index < this.numberOfAliveParticles) {
int endIndex = this.numberOfAliveParticles-1;
this.pos[index].set(this.pos[endIndex]);
this.vel[index].set(this.vel[endIndex]);
Timer tmp = this.timeToLive[index];
this.timeToLive[index] = this.timeToLive[endIndex];
this.timeToLive[endIndex] = tmp;
this.scale[index] = this.scale[endIndex];
this.rotation[index] = this.rotation[endIndex];
this.color[index].set(this.color[endIndex]);
this.isAlive[endIndex] = false;
this.numberOfAliveParticles--;
}
}
}
| 2,993 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
AlphaDecayUpdater.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/AlphaDecayUpdater.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import seventh.client.gfx.effects.particle_system.Emitter.ParticleUpdater;
import seventh.shared.TimeStep;
/**
* Decays the alpha value of the particle color
*
* @author Tony
*
*/
public class AlphaDecayUpdater implements ParticleUpdater {
private final float endingAlpha;
private final float decayFactor;
private final long startTime;
private long startDecayAfterTime;
public AlphaDecayUpdater(float endingAlpha, float decayFactor) {
this(0L, endingAlpha, decayFactor);
}
public AlphaDecayUpdater(long startDecayAfterTime, float endingAlpha, float decayFactor) {
this.startTime = startDecayAfterTime;
this.startDecayAfterTime = startDecayAfterTime;
this.endingAlpha = endingAlpha;
this.decayFactor = decayFactor;
}
@Override
public void reset() {
this.startDecayAfterTime = this.startTime;
}
@Override
public void update(TimeStep timeStep, ParticleData particles) {
this.startDecayAfterTime -= timeStep.getDeltaTime();
if(this.startDecayAfterTime < 0) {
for(int i = 0; i < particles.numberOfAliveParticles; i++) {
particles.color[i].a *= this.decayFactor;
if(particles.color[i].a < this.endingAlpha) {
particles.color[i].a = this.endingAlpha;
}
}
}
}
}
| 1,501 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
RandomSpeedSingleParticleGenerator.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomSpeedSingleParticleGenerator.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import java.util.Random;
import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator;
import seventh.shared.Randomizer;
import seventh.shared.TimeStep;
/**
* Randomly assigns a speed factor to a particle
*
* @author Tony
*
*/
public class RandomSpeedSingleParticleGenerator implements SingleParticleGenerator {
private final float minSpeed, maxSpeed;
/**
*
*/
public RandomSpeedSingleParticleGenerator(float minSpeed, float maxSpeed) {
this.minSpeed = minSpeed;
this.maxSpeed = maxSpeed;
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.BatchedParticleGenerator.SingleParticleGenerator#onGenerateParticle(int, seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) {
Random rand = particles.emitter.getRandom();
float speed = (float)Randomizer.getRandomRange(rand, this.minSpeed, this.maxSpeed);
particles.speed[index] = speed;
}
}
| 1,189 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
RandomMovementParticleUpdater.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomMovementParticleUpdater.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import java.util.Random;
import seventh.client.gfx.effects.particle_system.Emitter.ParticleUpdater;
import seventh.math.Vector2f;
import seventh.shared.TimeStep;
/**
* Moves a particle
*
* @author Tony
*
*/
public class RandomMovementParticleUpdater implements ParticleUpdater {
private float currentMaxSpeed;
private final float maxSpeed;
private final float maxSpeedDecay;
private final float minSpeed;
public RandomMovementParticleUpdater(float maxSpeed) {
this(maxSpeed, 0, maxSpeed);
}
/**
* @param maxSpeed
* @param maxSpeedDecay
* @param minSpeed
*/
public RandomMovementParticleUpdater(float maxSpeed, float maxSpeedDecay, float minSpeed) {
this.maxSpeed = maxSpeed;
this.maxSpeedDecay = maxSpeedDecay;
this.minSpeed = minSpeed;
this.currentMaxSpeed = maxSpeed;
}
@Override
public void reset() {
this.currentMaxSpeed = this.maxSpeed;
}
@Override
public void update(TimeStep timeStep, ParticleData particles) {
float dt = (float)timeStep.asFraction();
Random rand = particles.emitter.getRandom();
for(int i = 0; i < particles.numberOfAliveParticles; i++) {
Vector2f pos = particles.pos[i];
Vector2f vel = particles.vel[i];
float speed = particles.speed[i];
float newX = (pos.x + vel.x * speed * dt);
float newY = (pos.y + vel.y * speed * dt);
pos.set(newX, newY);
float s = rand.nextFloat();
speed = s * this.currentMaxSpeed;
this.currentMaxSpeed -= this.maxSpeedDecay;
if(this.currentMaxSpeed < this.minSpeed) {
this.currentMaxSpeed = this.minSpeed;
}
particles.speed[i] = speed;
}
}
}
| 2,027 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ScaleUpdater.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/ScaleUpdater.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import seventh.client.gfx.effects.particle_system.Emitter.ParticleUpdater;
import seventh.shared.TimeStep;
/**
* @author Tony
*
*/
public class ScaleUpdater implements ParticleUpdater {
private final float endingScale;
private final float decayFactor;
private final boolean isMin;
/**
* @param endingScale
* @param decayFactor
*/
public ScaleUpdater(float endingScale, float decayFactor) {
this.endingScale = endingScale;
this.decayFactor = decayFactor;
this.isMin = decayFactor < 0;
}
@Override
public void reset() {
}
@Override
public void update(TimeStep timeStep, ParticleData particles) {
for(int i = 0; i < particles.numberOfAliveParticles; i++) {
particles.scale[i] += this.decayFactor;
if(this.isMin) {
if(particles.scale[i] < this.endingScale) {
particles.scale[i] = this.endingScale;
}
}
else if(particles.scale[i] > this.endingScale) {
particles.scale[i] = this.endingScale;
}
}
}
}
| 1,238 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TriangleParticleRenderer.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/TriangleParticleRenderer.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import com.badlogic.gdx.graphics.Color;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.effects.particle_system.Emitter.ParticleRenderer;
import seventh.math.Vector2f;
import seventh.shared.TimeStep;
/**
* @author Tony
*
*/
public class TriangleParticleRenderer implements ParticleRenderer {
private float base;
private Vector2f a, b, c;
public TriangleParticleRenderer() {
this(1.0f);
}
/**
* @param base
*/
public TriangleParticleRenderer(float base) {
this.base = base;
this.a = new Vector2f();
this.b = new Vector2f();
this.c = new Vector2f();
}
@Override
public void update(TimeStep timeStep, ParticleData particles) {
}
@Override
public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) {
Vector2f cameraPos = camera.getRenderPosition(alpha);
for(int i = 0; i < particles.numberOfAliveParticles; i++) {
Vector2f pos = particles.pos[i];
float x = pos.x - cameraPos.x,
y = pos.y - cameraPos.y;
float hypot = particles.scale[i];
float base2 = (float)Math.sqrt((hypot*hypot) - (this.base*this.base));
this.a.set(x, y);
this.b.set(x + this.base, y);
this.c.set(x, y + base2);
float rot = (float)Math.toRadians(particles.rotation[i]);
Vector2f.Vector2fSubtract(b, a, b);
Vector2f.Vector2fRotate(b, rot, b);
Vector2f.Vector2fAdd(b, a, b);
Vector2f.Vector2fSubtract(c, a, c);
Vector2f.Vector2fRotate(c, rot, c);
Vector2f.Vector2fAdd(c, a, c);
Color color = particles.color[i];
canvas.fillTriangle(a.x, a.y, b.x, b.y, c.x, c.y, Color.argb8888(color));
}
}
}
| 2,116 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
RectParticleRenderer.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RectParticleRenderer.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import com.badlogic.gdx.graphics.Color;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.effects.particle_system.Emitter.ParticleRenderer;
import seventh.math.Vector2f;
import seventh.shared.TimeStep;
/**
* @author Tony
*
*/
public class RectParticleRenderer implements ParticleRenderer {
private final int width, height;
/**
* a default width/height of 1
*/
public RectParticleRenderer() {
this(1,1);
}
public RectParticleRenderer(int width, int height) {
this.width = width;
this.height = height;
}
@Override
public void update(TimeStep timeStep, ParticleData particles) {
}
@Override
public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) {
Vector2f cameraPos = camera.getRenderPosition(alpha);
for(int i = 0; i < particles.numberOfAliveParticles; i++) {
Vector2f pos = particles.pos[i];
float x = pos.x - cameraPos.x, y = pos.y - cameraPos.y;
Color color = particles.color[i];
canvas.fillRect(x, y, width, height, Color.argb8888(color));
}
}
}
| 1,340 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
SetPositionSingleParticleGenerator.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/SetPositionSingleParticleGenerator.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator;
import seventh.math.Vector2f;
import seventh.shared.TimeStep;
/**
* Spawns a particle at the position of the {@link Emitter}
*
* @author Tony
*
*/
public class SetPositionSingleParticleGenerator implements SingleParticleGenerator {
@Override
public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) {
Vector2f pos = particles.pos[index];
pos.set(particles.emitter.getPos());;
}
}
| 625 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
MovementParticleUpdater.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/MovementParticleUpdater.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import seventh.client.gfx.effects.particle_system.Emitter.ParticleUpdater;
import seventh.math.Vector2f;
import seventh.shared.TimeStep;
/**
* Moves a particle
*
* @author Tony
*
*/
public class MovementParticleUpdater implements ParticleUpdater {
private final float minSpeed, speedDecay;
/**
*
*/
public MovementParticleUpdater(float minSpeed, float speedDecay) {
this.minSpeed = minSpeed;
this.speedDecay = speedDecay;
}
@Override
public void reset() {
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.Emitter.ParticleUpdater#update(seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void update(TimeStep timeStep, ParticleData particles) {
float dt = (float)timeStep.asFraction();
for(int i = 0; i < particles.numberOfAliveParticles; i++) {
Vector2f pos = particles.pos[i];
Vector2f vel = particles.vel[i];
float speed = particles.speed[i];
float newX = (pos.x + vel.x * speed * dt);
float newY = (pos.y + vel.y * speed * dt);
pos.set(newX, newY);
speed -= this.speedDecay;
if(speed < this.minSpeed) {
speed = this.minSpeed;
}
particles.speed[i] = speed;
}
}
}
| 1,541 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
CircleParticleRenderer.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/CircleParticleRenderer.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import com.badlogic.gdx.graphics.Color;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.effects.particle_system.Emitter.ParticleRenderer;
import seventh.math.Vector2f;
import seventh.shared.TimeStep;
/**
* @author Tony
*
*/
public class CircleParticleRenderer implements ParticleRenderer {
private float radius;
/**
* defaults to a radius of 1
*/
public CircleParticleRenderer() {
this(1f);
}
/**
* @param radius
*/
public CircleParticleRenderer(float radius) {
this.radius = radius;
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.Emitter.ParticleRenderer#update(seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void update(TimeStep timeStep, ParticleData particles) {
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.Emitter.ParticleRenderer#render(seventh.client.gfx.Canvas, seventh.client.gfx.Camera, float, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) {
Vector2f cameraPos = camera.getRenderPosition(alpha);
for(int i = 0; i < particles.numberOfAliveParticles; i++) {
Vector2f pos = particles.pos[i];
float x = pos.x - cameraPos.x, y = pos.y - cameraPos.y;
Color color = particles.color[i];
canvas.fillCircle(this.radius, x, y, Color.argb8888(color));
}
}
}
| 1,732 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
RandomScaleSingleParticleGenerator.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomScaleSingleParticleGenerator.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import java.util.Random;
import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator;
import seventh.shared.Randomizer;
import seventh.shared.TimeStep;
/**
* Randomly assigns a scaling factor to a particle
*
* @author Tony
*
*/
public class RandomScaleSingleParticleGenerator implements SingleParticleGenerator {
private final float minScale, maxScale;
/**
*
*/
public RandomScaleSingleParticleGenerator(float minScale, float maxScale) {
this.minScale = minScale;
this.maxScale = maxScale;
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.BatchedParticleGenerator.SingleParticleGenerator#onGenerateParticle(int, seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) {
Random rand = particles.emitter.getRandom();
float scale = (float)Randomizer.getRandomRange(rand, this.minScale, this.maxScale);
particles.scale[index] = scale;
}
}
| 1,191 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
RandomColorSingleParticleGenerator.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/client/gfx/effects/particle_system/RandomColorSingleParticleGenerator.java | /*
* see license.txt
*/
package seventh.client.gfx.effects.particle_system;
import java.util.Random;
import com.badlogic.gdx.graphics.Color;
import seventh.client.gfx.effects.particle_system.BatchedParticleGenerator.SingleParticleGenerator;
import seventh.shared.TimeStep;
/**
* Randomly assigns a {@link Color} to a particle
*
* @author Tony
*
*/
public class RandomColorSingleParticleGenerator implements SingleParticleGenerator {
private Color[] colors;
public RandomColorSingleParticleGenerator(Color ... colors) {
this.colors = colors;
}
/* (non-Javadoc)
* @see seventh.client.gfx.particle_system.BatchedParticleGenerator.SingleParticleGenerator#onGenerateParticle(int, seventh.shared.TimeStep, seventh.client.gfx.particle_system.ParticleData)
*/
@Override
public void onGenerateParticle(int index, TimeStep timeStep, ParticleData particles) {
Random rand = particles.emitter.getRandom();
particles.color[index].set(this.colors[rand.nextInt(this.colors.length)]);
}
}
| 1,073 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
MapLoader.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/MapLoader.java | /*
* leola-live
* see license.txt
*/
package seventh.map;
import leola.vm.types.LeoMap;
/**
* @author Tony
*
*/
public interface MapLoader {
/**
* Loads a {@link Map}
*
* @param map
* @param loadAssets
* @return
* @throws Exception
*/
public Map loadMap(LeoMap map, MapObjectFactory mapObjectsFactory, boolean loadAssets) throws Exception;
}
| 405 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Tileset.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/Tileset.java | /*
* leola-live
* see license.txt
*/
package seventh.map;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import leola.vm.types.LeoMap;
import leola.vm.types.LeoObject;
import seventh.client.gfx.AnimatedImage;
import seventh.client.gfx.Art;
import seventh.client.gfx.TextureUtil;
import seventh.map.Tile.SurfaceType;
/**
* @author Tony
*
*/
public class Tileset {
private TextureRegion[] image;
private int startId;
private LeoMap props;
public Tileset(int startId, TextureRegion[] image, LeoMap props) {
this.startId = startId;
this.image = image;
this.props = props;
}
/**
* Frees the texture memory
*/
public void destroy() {
if(this.image != null && this.image.length > 0) {
TextureRegion tex = this.image[0];
if(tex != null) {
tex.getTexture().dispose();
}
}
}
/**
* @return the startId
*/
public int getStartId() {
return startId;
}
/**
* @param tileid
* @return the {@link SurfaceType}
*/
public SurfaceType getSurfaceType(int tileid) {
if(props != null) {
String id = Integer.toString(toIndex(tileid));
LeoObject p = props.getByString(id);
if(LeoObject.isTrue(p)) {
LeoObject s = p.getObject("surface");
if(LeoObject.isTrue(s)) {
return SurfaceType.fromString(s.toString());
}
}
}
return SurfaceType.UNKNOWN;
}
/**
* @param tileid
* @return true if this tile id is an animation
*/
public boolean isAnimatedImage(int tileid) {
if(props != null) {
String id = Integer.toString(toIndex(tileid));
LeoObject p = props.getByString(id);
if(LeoObject.isTrue(p)) {
LeoObject animation = p.getObject("animation");
if(LeoObject.isTrue(animation)) {
return true;
}
}
}
return false;
}
/**
* @param tileid
* @return the {@link AnimatedImage} for this tile id
*/
public AnimatedImage getAnimatedImage(int tileid) {
if(props != null) {
String id = Integer.toString(toIndex(tileid));
LeoObject p = props.getByString(id);
if(LeoObject.isTrue(p)) {
LeoObject animation = p.getObject("animation");
if(LeoObject.isTrue(animation)) {
TextureRegion tex = Art.loadImage(animation.toString());
int rowNum = tex.getRegionHeight() / 32;
int colNum = tex.getRegionWidth() / 32;
LeoObject rows = p.getObject("rows");
LeoObject cols = p.getObject("cols");
if(LeoObject.isTrue(rows)) {
rowNum = Integer.valueOf(rows.toString());
}
if(LeoObject.isTrue(cols)) {
colNum = Integer.valueOf(cols.toString());
}
int frameTime = 800;
LeoObject fps = p.getObject("fps");
if(LeoObject.isTrue(fps)) {
frameTime = Integer.valueOf(fps.toString());
}
int numberOfFrames = rowNum * colNum;
int[] frames = new int[numberOfFrames];
for(int i = 0; i < numberOfFrames; i++) {
frames[i] = frameTime;
}
return new AnimatedImage(TextureUtil.splitImage(tex, rowNum, colNum), Art.newAnimation(frames));
}
}
}
return null;
}
private int toIndex(int id) {
return id - startId;
}
/**
* @param id
* @return
*/
public TextureRegion getTile(int id) {
int index = toIndex(id);
if ( index < 0 || index >= image.length ) {
return null;
}
return image[index];
}
public Integer getTileId(int id) {
int index = toIndex(id);
return index + 1;
}
}
| 4,416 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TilesetAtlas.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/TilesetAtlas.java | /*
* leola-live
* see license.txt
*/
package seventh.map;
import java.util.ArrayList;
import java.util.List;
import seventh.client.gfx.AnimatedImage;
import seventh.map.Tile.SurfaceType;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
/**
* @author Tony
*
*/
public class TilesetAtlas {
private List<Tileset> tilesets;
/**
*
*/
public TilesetAtlas() {
this.tilesets = new ArrayList<Tileset>();
}
public void addTileset(Tileset t) {
this.tilesets.add(t);
}
public TextureRegion getTile(int id) {
for(Tileset t : tilesets) {
TextureRegion img = t.getTile(id);
if(img != null) {
return img;
}
}
return null;
}
/**
* @param id
* @return true if the tile id is an animated image
*/
public boolean isAnimatedTile(int id) {
for(Tileset t : tilesets) {
TextureRegion img = t.getTile(id);
if(img != null) {
return t.isAnimatedImage(id);
}
}
return false;
}
public AnimatedImage getAnimatedTile(int id) {
for(Tileset t : tilesets) {
TextureRegion img = t.getTile(id);
if(img != null) {
return t.getAnimatedImage(id);
}
}
return null;
}
public SurfaceType getTileSurfaceType(int id) {
for(Tileset t : tilesets) {
SurfaceType type = t.getSurfaceType(id);
if(type != SurfaceType.UNKNOWN) {
return type;
}
}
return SurfaceType.UNKNOWN;
}
public Integer getTileId(int id) {
Tileset bestmatch = null;
for(Tileset t : tilesets) {
if(id >= t.getStartId()) {
if(bestmatch == null || bestmatch.getStartId() < t.getStartId()) {
bestmatch = t;
}
}
}
if(bestmatch != null) {
return bestmatch.getTileId(id);
}
return -1;
}
/**
* Frees the allocated textures
*/
public void destroy() {
for(Tileset t : tilesets) {
t.destroy();
}
}
}
| 2,335 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Map.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/Map.java | /*
* leola-live
* see license.txt
*/
package seventh.map;
import java.util.List;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.Renderable;
import seventh.graph.GraphNode;
import seventh.map.Tile.SurfaceType;
import seventh.math.OBB;
import seventh.math.Rectangle;
import seventh.math.Vector2f;
import seventh.shared.Debugable;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
/**
* A Scene represents a renderable world in which characters can interact, essentially it's a
* game world, the game world is comprised of multiple linked {@link Map}s.
*
* @author Tony
*
*/
public abstract interface Map extends Renderable, Debugable {
/**
* Scene Definition
* @author Tony
*
*/
public static class SceneDef {
/**
* Map Layer
*/
private Layer[] backgroundLayers;
/**
* Foreground layer
*/
private Layer[] foregroundLayers;
/**
* X Dimension
*/
private int dimensionX;
/**
* Y Dimension
*/
private int dimensionY;
/**
* Tile width
*/
private int tileWidth;
/**
* Tile height
*/
private int tileHeight;
/**
* Background Image
*/
private TextureRegion backgroundImage;
private SurfaceType[][] surfaces;
private TilesetAtlas atlas;
private List<MapObject> mapObjects;
private MapObjectFactory mapObjectsFactory;
/**
* @param mapObjectsFactory the mapObjectsFactory to set
*/
public void setMapObjectsFactory(MapObjectFactory mapObjectsFactory) {
this.mapObjectsFactory = mapObjectsFactory;
}
/**
* @return the mapObjectsFactory
*/
public MapObjectFactory getMapObjectsFactory() {
return mapObjectsFactory;
}
/**
* @param mapObjects the mapObjects to set
*/
public void setMapObjects(List<MapObject> mapObjects) {
this.mapObjects = mapObjects;
}
/**
* @return the mapObjects
*/
public List<MapObject> getMapObjects() {
return mapObjects;
}
/**
* @return the surfaces
*/
public SurfaceType[][] getSurfaces() {
return surfaces;
}
/**
* @param surfaces the surfaces to set
*/
public void setSurfaces(SurfaceType[][] surfaces) {
this.surfaces = surfaces;
}
/**
* @return the layers
*/
public Layer[] getBackgroundLayers() {
return backgroundLayers;
}
/**
* @param layers the layers to set
*/
public void setBackgroundLayers(Layer[] layers) {
this.backgroundLayers = layers;
}
/**
* @return the foregroundLayers
*/
public Layer[] getForegroundLayers() {
return foregroundLayers;
}
/**
* @param foregroundLayers the foregroundLayers to set
*/
public void setForegroundLayers(Layer[] foregroundLayers) {
this.foregroundLayers = foregroundLayers;
}
/**
* @return the dimensionX
*/
public int getDimensionX() {
return dimensionX;
}
/**
* @param dimensionX the dimensionX to set
*/
public void setDimensionX(int dimensionX) {
this.dimensionX = dimensionX;
}
/**
* @return the dimensionY
*/
public int getDimensionY() {
return dimensionY;
}
/**
* @param dimensionY the dimensionY to set
*/
public void setDimensionY(int dimensionY) {
this.dimensionY = dimensionY;
}
/**
* @return the tileWidth
*/
public int getTileWidth() {
return tileWidth;
}
/**
* @param tileWidth the tileWidth to set
*/
public void setTileWidth(int tileWidth) {
this.tileWidth = tileWidth;
}
/**
* @return the tileHeight
*/
public int getTileHeight() {
return tileHeight;
}
/**
* @param tileHeight the tileHeight to set
*/
public void setTileHeight(int tileHeight) {
this.tileHeight = tileHeight;
}
/**
* @return the backgroundImage
*/
public TextureRegion getBackgroundImage() {
return backgroundImage;
}
/**
* @param backgroundImage the backgroundImage to set
*/
public void setBackgroundImage(TextureRegion backgroundImage) {
this.backgroundImage = backgroundImage;
}
/**
* @param atlas the atlas to set
*/
public void setAtlas(TilesetAtlas atlas) {
this.atlas = atlas;
}
/**
* @return the atlas
*/
public TilesetAtlas getAtlas() {
return atlas;
}
}
/**
* Initialize the Scene
*
* @param info
* @throws MyriadException
*/
public abstract void init(SceneDef info) throws Exception;
/**
* Free resources
*/
public abstract void destroy();
/**
* @return the backgroundLayers
*/
public Layer[] getBackgroundLayers();
/**
* @return the collidableLayers
*/
public Layer[] getCollidableLayers();
/**
* @return the foregroundLayers
*/
public Layer[] getForegroundLayers();
/**
* Render this object.
*
* @param renderer
* @param camera
* @param alpha
*/
public void renderForeground(Canvas canvas, Camera camera, float alpha);
/**
* Renders a solid layer over the set of viewable tiles (Fog of War)
*/
public abstract void renderSolid(Canvas canvas, Camera camera, float alpha);
/**
* Retrieve a Tile.
*
* @param layer
* @param x - x array coordinate
* @param y - y array coordinate
* @return
*/
public abstract Tile getTile(int layer, int x, int y);
public abstract Tile getDestructableTile(int x, int y);
/**
* Retrieve a Tile.
*
* @param x - x array coordinate
* @param y - y array coordinate
* @return
*/
public abstract Tile getCollidableTile(int x, int y);
/**
* Get a {@link Tile} from world coordinates
* @param layer
* @param x - x in world coordinate space
* @param y - y in world coordinate space
* @return
*/
public abstract Tile getWorldTile(int layer, int x, int y);
/**
* Retrieves the {@link SurfaceType} given the supplied x and y index
* @param x
* @param y
* @return the {@link SurfaceType}
*/
public abstract SurfaceType getSurfaceTypeByIndex(int x, int y);
/**
* Retrieves the {@link SurfaceType} given the supplied world coordinates
* @param x
* @param y
* @return the {@link SurfaceType}
*/
public abstract SurfaceType getSurfaceTypeByWorld(int x, int y);
/**
* Get a {@link Tile} from world coordinates
*
* @param x - x in world coordinate space
* @param y - y in world coordinate space
* @return
*/
public abstract Tile getWorldCollidableTile(int x, int y);
/**
* Determines if there is a collidable tile at the location.
*
* @param x
* @param y
* @return true if there is a collidable tile at this location
*/
public abstract boolean hasCollidableTile(int x, int y);
/**
* Determines if there is a collidable tile at the location.
*
* @param x
* @param y
* @return true if there is a collidable tile at this location
*/
public abstract boolean hasWorldCollidableTile(int x, int y);
/**
* Queries to see if there is a heightMask from world coordinates
*
* @param x - x in world coordinate space
* @param y - y in world coordinate space
* @return true if there is a height mask; false otherwise
*/
public abstract boolean hasHeightMask(int worldX, int worldY);
/**
* Check for a collision given a {@link Rectangle}
*
* @param rect
* @return true if a collision occurs, false otherwise
*/
public abstract boolean rectCollides(Rectangle rect);
/**
* Check for a collision given a {@link OBB}
*
* @param oob
* @return true if a collision occurs, false otherwise
*/
public abstract boolean rectCollides(OBB oob);
/**
* Check for a collision given a {@link Rectangle}
*
* @param rect
* @param heightMask
* @return true if a collision occurs, false otherwise
*/
public abstract boolean rectCollides(Rectangle rect, int heightMask);
/**
* Check for a collision given a {@link Rectangle}
*
* @param rect
* @param heightMask
* @param collisionTilePos - if there is a collision, the tile indexes that caused the collision
* @return true if a collision occurs, false otherwise
*/
public abstract boolean rectCollides(Rectangle rect, int heightMask, Vector2f collisionTilePos);
/**
* Check for a collision given a point
*
* @param x
* @param y
* @return true if a collision occurs, false otherwise
*/
public abstract boolean pointCollides(int x, int y);
/**
* Check for a collision given a point
*
* @param x
* @param y
* @param heightMask
* @return true if a collision occurs, false otherwise
*/
public abstract boolean pointCollides(int x, int y, int heightMask);
/**
* Check for a collision given the line
* @param a - start of the line
* @param b - end of the line
* @return true if a collision occurs, false otherwise
*/
public abstract boolean lineCollides(Vector2f a, Vector2f b);
/**
* Check for a collision given the line
* @param a - start of the line
* @param b - end of the line
* @param heightMask
* @return true if a collision occurs, false otherwise
*/
public abstract boolean lineCollides(Vector2f a, Vector2f b, int heightMask);
/**
* Check the {@link Map} boundaries
* @param worldX
* @param worldY
* @return true if out of bounds
*/
public abstract boolean checkBounds(int worldX, int worldY);
/**
* Checks the map boundaries based on tile coordinates
* @param x
* @param y
* @return true if out of bounds
*/
public boolean checkTileBounds(int x, int y);
/**
* Get the {@link Map}s width
* @return
*/
public abstract int getMapWidth();
/**
* Get the {@link Map}s height
* @return
*/
public abstract int getMapHeight();
/**
* @return the tile width
*/
public abstract int getTileWidth();
/**
* @return the tile height
*/
public abstract int getTileHeight();
public int getTileWorldWidth();
public int getTileWorldHeight();
/**
* Creates a new {@link MapGraph}
* @param factory
* @return the new {@link MapGraph}
*/
public <E> MapGraph<E> createMapGraph(GraphNodeFactory<E> factory);
@SuppressWarnings("rawtypes")
public <E> void addNode(GraphNodeFactory<E> factory, GraphNode[][] nodes, GraphNode<Tile, E> node, int x, int y);
/**
* Convert world coordinates to tile coordinates
*
* @param x
* @param y
* @return
*/
public abstract Vector2f worldToTile(int x, int y);
public abstract int worldToTileX(int x);
public abstract int worldToTileY(int y);
/**
* Convert tile coordinates to world coordinates
*
* @param tx
* @param ty
* @return
*/
public abstract Vector2f tileToWorld(int tx, int ty);
public abstract int tileToWorldX(int x);
public abstract int tileToWorldY(int y);
/**
* Get {@link MapObject}s.
*
* @return Get {@link MapObject}s.
*/
public abstract List<MapObject> getMapObjects();
/**
* @param layer
* @param centerX
* @param centerY
* @param radius
* @param tiles -- same tileset returned
* @return a list of tiles within the circle
*/
public abstract List<Tile> getTilesInCircle(int layer, int centerX, int centerY, int radius, List<Tile> tiles);
/**
* @param centerX
* @param centerY
* @param radius
* @param tiles -- same tileset returned
* @return a list of tiles within the circle
*/
public abstract List<Tile> getTilesInCircle(int centerX, int centerY, int radius, List<Tile> tiles);
/**
* Get the tiles inside the {@link Rectangle}
*
* @param bounds
* @param tiles
* @return a list of tiles within the {@link Rectangle}
*/
public abstract List<Tile> getTilesInRect(Rectangle bounds, List<Tile> tiles);
/**
* Get the tiles inside the {@link Rectangle}
*
* @param layer
* @param bounds
* @param tiles
* @return a list of tiles within the {@link Rectangle}
*/
public abstract List<Tile> getTilesInRect(int layer, Rectangle bounds, List<Tile> tiles);
/**
* Gets the Collision tiles that match up against the supplied 'checkAgainst' tiles
* @param checkAgainst the tiles to match up against
* @param results the result set to return (output parameter)
* @return the same results object passed
*/
public List<Tile> getCollisionTilesAt(List<Tile> checkAgainst, List<Tile> results);
/**
* Sets the mask on the tiles
* @param tiles
* @param mask
*/
public abstract void setMask(List<Tile> tiles, int mask);
/**
* Restore the tiles that have been destroyed
*/
public abstract void restoreDestroyedTiles();
/**
* Removes a destructable tile at the supplied tile index.
*
* @param tileX
* @param tileY
*/
public abstract boolean removeDestructableTileAt(int tileX, int tileY);
/**
* Removes a destructable tile at the supplied world coordinates
*
* @param worldX
* @param worldY
*/
public abstract boolean removeDestructableTileAtWorld(int worldX, int worldY);
/**
* Returns a list of tile indexes that have been removed.
* @return Returns a list of tile indexes that have been removed.
*/
public abstract List<Tile> getRemovedTiles();
public abstract boolean removeDestructableTilesAt(int[] tilePositions);
public abstract void addTile(Tile tile);
public abstract List<Tile> getAddedTiles();
public abstract void removeAddedTiles();
public abstract TilesetAtlas geTilesetAtlas();
public abstract MapObjectFactory getMapObjectFactory();
}
| 15,559 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
AnimatedTile.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/AnimatedTile.java | /*
* see license.txt
*/
package seventh.map;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import seventh.client.gfx.AnimatedImage;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.shared.TimeStep;
/**
* An animated tile
*
* @author Tony
*
*/
public class AnimatedTile extends Tile {
private AnimatedImage image;
/**
* @param image
* @param width
* @param height
*/
public AnimatedTile(AnimatedImage image, int tileId, int layer, int width, int height) {
super(null, tileId, layer, width, height);
this.image = image;
this.image.loop(true);
}
/**
* @return the animated image
*/
public AnimatedImage getAnimatedImage() {
return image;
}
@Override
public void update(TimeStep timeStep) {
image.update(timeStep);
}
@Override
public void render(Canvas canvas, Camera camera, float alpha) {
TextureRegion tex = image.getCurrentImage();
canvas.drawScaledImage(tex, getRenderX(), getRenderY(), getWidth(), getHeight(), 0xFFFFFFFF);
}
}
| 1,146 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
MapGraph.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/MapGraph.java | /*
* leola-live
* see license.txt
*/
package seventh.map;
import java.util.List;
import java.util.Random;
import seventh.ai.basic.Zone;
import seventh.game.Game;
import seventh.graph.AStarGraphSearch;
import seventh.graph.GraphNode;
import seventh.graph.GraphSearchPath;
import seventh.math.Vector2f;
/**
* A {@link GraphNode} of the {@link Map}
*
* @author Tony
*
*/
@SuppressWarnings("all")
public class MapGraph<T> {
public GraphNode[][] graph;
private seventh.map.Map map;
private Random random;
private int width, height;
private GraphSearchPath<Tile, T> defaultSearchPath;
/**
*
*/
public MapGraph(Map map, GraphNode[][] graph) {
this.map = map;
this.graph = graph;
this.height = graph.length;
this.width = graph[0].length;
this.random = new Random();
this.defaultSearchPath = new AStarGraphSearch<>();
}
/**
* Removes a node, when removing this will make that tile
* not walkable.
*
* @param x the tileX position
* @param y the tileY position
*/
public void removeNode(int x, int y) {
GraphNode<Tile, T> node = graph[y][x];
if(node != null) {
node.edges().removeEdges();
graph[y][x] = null;
}
}
/**
* Adds a node, making this tile walkable
*
* @param x the tileX position
* @param y the tileY position
*/
public void addNode(int x, int y) {
Tile tile = this.map.getTile(0, x, y);
if(tile != null) {
GraphNode<Tile, T> node = new GraphNode<Tile, T>(tile);
graph[y][x] = node;
this.map.addNode(null, graph, node, x, y);
}
}
/**
* @param x
* @param y
* @return get the {@link GraphNode} by the x and y index (not world coordinates)
*/
public GraphNode<Tile, T> getNodeByIndex(int x, int y) {
return (GraphNode<Tile, T>)graph[y][x];
}
/**
* @param wx
* @param wy
* @return the graph node at a world coordinate
*/
public GraphNode<Tile, T> getNodeByWorld(int wx, int wy) {
int tileOffset_x = 0;// (wx % map.getTileWidth());
int x = (tileOffset_x + wx) / map.getTileWidth();
int tileOffset_y = 0; //(wy % map.getTileHeight());
int y = (tileOffset_y + wy) / map.getTileHeight();
if(map.checkTileBounds(x, y)) {
return null;
}
return x<width && y<height ? (GraphNode<Tile, T>)graph[y][x] : null;
}
public GraphNode<Tile, T> getNearestNodeByWorld(Vector2f pos) {
return getNearestNodeByWorld((int)pos.x, (int)pos.y);
}
public GraphNode<Tile, T> getNearestNodeByWorld(int wx, int wy) {
GraphNode<Tile, T> node = getNodeByWorld(wx, wy);
if(node != null) return node;
node = getNodeByWorld(wx+map.getTileHeight(), wy);
if(node != null) return node;
node = getNodeByWorld(wx-map.getTileHeight(), wy);
if(node != null) return node;
node = getNodeByWorld(wx, wy + map.getTileWidth());
if(node != null) return node;
node = getNodeByWorld(wx, wy - map.getTileWidth());
if(node != null) return node;
node = getNodeByWorld(wx + map.getTileHeight(), wy + map.getTileWidth());
if(node != null) return node;
node = getNodeByWorld(wx - map.getTileHeight(), wy - map.getTileWidth());
if(node != null) return node;
node = getNodeByWorld(wx - map.getTileHeight(), wy + map.getTileWidth());
if(node != null) return node;
node = getNodeByWorld(wx + map.getTileHeight(), wy - map.getTileWidth());
return node;
}
/**
* Calculate the estimated cost of the path from the start to destination
*
* @param start
* @param destination
* @return the estimated cost of moving from start to destination
*/
public int pathCost(Vector2f start, Vector2f destination) {
List<GraphNode<Tile, T>> newPath = this.findPath(this.defaultSearchPath, start, destination);
int cost = newPath.size() * 32;
return cost;
}
/**
* Finds a path, avoiding the supplied {@link Zone}s
*
*
* @param start
* @param destination
* @param zonesToAvoid
* @return the list of node to travel to reach the destination
*/
public List<GraphNode<Tile, T>> findPathAvoidZones(GraphSearchPath<Tile, T> searchPath, Vector2f start, Vector2f destination, final List<Zone> zonesToAvoid) {
GraphNode<Tile, T> startNode = getNearestNodeByWorld(start);
GraphNode<Tile, T> destNode = getNearestNodeByWorld(destination);
List<GraphNode<Tile, T>> resultPath = searchPath.search(startNode, destNode);
return resultPath;
}
/**
* Finds a fuzzy (meaning not necessarily the most optimal but different) path between the start and end point
*
* @param start
* @param destination
* @return the list of node to travel to reach the destination
*/
public List<GraphNode<Tile, T>> findPath(GraphSearchPath<Tile, T> searchPath, Vector2f start, Vector2f destination) {
GraphNode<Tile, T> startNode = getNearestNodeByWorld(start);
GraphNode<Tile, T> destNode = getNearestNodeByWorld(destination);
List<GraphNode<Tile, T>> resultPath = searchPath.search(startNode, destNode);
return resultPath;
}
}
| 5,772 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
OrthoMap.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/OrthoMap.java | /*
* leola-live
* see license.txt
*/
package seventh.map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.effects.ShadeTiles;
import seventh.graph.Edge;
import seventh.graph.Edges.Directions;
import seventh.graph.GraphNode;
import seventh.map.Tile.SurfaceType;
import seventh.math.OBB;
import seventh.math.Rectangle;
import seventh.math.Vector2f;
import seventh.shared.TimeStep;
/**
* The {@link OrthoMap} can be used for Top-down or Side-scrollers
*
* @author Tony
*
*/
public class OrthoMap implements Map {
/**
* Scene Width
*/
private int mapWidth;
/**
* Scene Width
*/
private int mapHeight;
/**
* Tile width
*/
private int tileWidth;
/**
* Tile width
*/
private int tileHeight;
private int maxX;
private int maxY;
/**
* Current map location
*/
private Vector2f mapOffset;
private Rectangle worldBounds;
/**
* Layers
*/
private Layer[] backgroundLayers,
foregroundLayers,
collidableLayers,
destructableLayer;
/**
* original destructable layer; used for comparison to get delta
*/
//private boolean[][] originalLayer;
private List<Tile> destroyedTiles;
private List<Tile> addedTiles;
/**
* The current frames viewport
*/
private Rectangle currentFrameViewport;
/**
* Background image
*/
private TextureRegion backgroundImage;
/**
* The surfaces
*/
private SurfaceType[][] surfaces;
private TilesetAtlas atlas;
private java.util.Map<Integer, TextureRegion> shadeTilesLookup;
private Vector2f collisionTilePos;
private List<MapObject> mapObjects;
private MapObjectFactory mapObjectsFactory;
private List<MapObject> backgroundMapObjects;
private List<MapObject> foregroundMapObjects;
private Layer collisionLayerToAddTiles;
/**
* Constructs a new {@link OrthoMap}.
*/
public OrthoMap(boolean loadAssets) {
this.currentFrameViewport = new Rectangle();
this.destroyedTiles = new ArrayList<Tile>();
this.addedTiles = new ArrayList<>();
this.collisionTilePos = new Vector2f();
this.backgroundMapObjects = new ArrayList<>();
this.foregroundMapObjects = new ArrayList<>();
if(loadAssets) {
this.shadeTilesLookup = new HashMap<Integer, TextureRegion>();
}
destroy();
}
@Override
public List<MapObject> getMapObjects() {
return this.mapObjects;
}
/**
* @return the backgroundLayers
*/
public Layer[] getBackgroundLayers() {
return backgroundLayers;
}
/**
* @return the collidableLayers
*/
public Layer[] getCollidableLayers() {
return collidableLayers;
}
/**
* @return the foregroundLayers
*/
public Layer[] getForegroundLayers() {
return foregroundLayers;
}
/* (non-Javadoc)
* @see seventh.map.Map#hasCollidableTile(int, int)
*/
@Override
public boolean hasCollidableTile(int x, int y) {
return getCollidableTile(x, y) != null;
}
/* (non-Javadoc)
* @see seventh.map.Map#hasWorldCollidableTile(int, int)
*/
@Override
public boolean hasWorldCollidableTile(int x, int y) {
return getWorldCollidableTile(x, y) != null;
}
/*
* (non-Javadoc)
* @see seventh.map.Map#getCollisionTilesAt(java.util.List, java.util.List)
*/
public List<Tile> getCollisionTilesAt(List<Tile> checkAgainst, List<Tile> results) {
for(int i = 0; i < checkAgainst.size(); i++) {
Tile checkMe = checkAgainst.get(i);
int xIndex = checkMe.getXIndex();
int yIndex = checkMe.getYIndex();
for (int j = 0; j < this.collidableLayers.length; j++) {
Tile tile = getTile(this.collidableLayers[j].getIndex(), xIndex, yIndex);
if (tile != null) {
results.add(tile);
break;
}
}
}
return results;
}
/*
* (non-Javadoc)
* @see leola.live.game.Map#checkBounds(int, int)
*/
public boolean checkBounds(int x, int y) {
// return (x <= 0 || y <= 0 || x >= this.mapWidth - this.tileWidth || y >= this.mapHeight - this.tileHeight);
return (x < 0 || y < 0 || x >= this.mapWidth || y >= this.mapHeight);
}
/*
* (non-Javadoc)
* @see leola.live.game.Map#checkTileBounds(int, int)
*/
public boolean checkTileBounds(int x, int y) {
return (x < 0 || y < 0 || x >= this.maxX || y >= this.maxY);
}
/* (non-Javadoc)
* @see seventh.map.Map#getTilesInRect(seventh.math.Rectangle, java.util.List)
*/
@Override
public List<Tile> getTilesInRect(Rectangle bounds, List<Tile> tiles) {
return getTilesInRect(0, bounds, tiles);
}
/*
* (non-Javadoc)
* @see seventh.map.Map#getTilesInRect(int, seventh.math.Rectangle, java.util.List)
*/
@Override
public List<Tile> getTilesInRect(int layer, Rectangle bounds, List<Tile> tiles) {
List<Tile> result = (tiles == null) ? new ArrayList<Tile>() : tiles;
result.clear();
for(int y = bounds.y;
y <= (bounds.y + bounds.height);
y += tileHeight) {
for(int x = bounds.x;
x <= (bounds.x + bounds.width);
x += tileWidth ) {
if(!checkBounds(x, y)) {
Tile tile = getWorldTile(layer, x, y);
if(tile != null) {
result.add(tile);
}
}
}
}
return result;
}
/* (non-Javadoc)
* @see leola.live.game.Map#getTilesInCircle(int, int, float, java.util.List)
*/
@Override
public List<Tile> getTilesInCircle(int layer, int centerX, int centerY, int radius,
List<Tile> tiles) {
List<Tile> result = (tiles == null) ? new ArrayList<Tile>() : tiles;
result.clear();
int length = (radius * 2) + 1;
for(int y = centerY - (length / 2);
y <= (centerY + (length / 2));
y += tileHeight) {
for(int x = centerX - (length / 2);
x <= (centerX + (length / 2));
x += tileWidth ) {
if(!checkBounds(x, y)) {
Tile tile = getWorldTile(layer, x, y);
if(tile != null) {
result.add(tile);
}
}
}
}
return result;
}
/* (non-Javadoc)
* @see leola.live.game.Map#getTilesInCircle(int, int, float, java.util.List)
*/
@Override
public List<Tile> getTilesInCircle(int centerX, int centerY, int radius,
List<Tile> tiles) {
return getTilesInCircle(0, centerX, centerY, radius, tiles);
}
@Override
public boolean pointCollides(int x, int y) {
return pointCollides(x, y, 1);
}
/* (non-Javadoc)
* @see leola.live.game.Map#pointCollides(int, int)
*/
@Override
public boolean pointCollides(int x, int y, int heightMask) {
if (checkBounds(x, y)) {
return true;
}
int tileOffset_x = 0;//(x % this.tileWidth);
int wx = (tileOffset_x + x) / this.tileWidth;
int tileOffset_y = 0;//(y % this.tileHeight);
int wy = (tileOffset_y + y) / this.tileHeight;
for (int i = 0; i < this.collidableLayers.length; i++) {
//Tile tile = this.backgroundLayers[this.collidableLayers[i].getIndex()].getRow(wy)[wx];
Tile tile = this.collidableLayers[i].getRow(wy)[wx];
if (tile != null) {
int tileHeightMask = tile.getHeightMask();
if(tileHeightMask > 0) {
if ((tileHeightMask & heightMask) == tileHeightMask && (tile.pointCollide(x, y))) {
return true;
}
}
else if( tile.pointCollide(x, y) ) {
return true;
}
}
}
return false;
}
@Override
public boolean rectCollides(Rectangle rect) {
return rectCollides(rect, 1);
}
/* (non-Javadoc)
* @see seventh.map.Map#rectCollides(seventh.math.OOB)
*/
@Override
public boolean rectCollides(OBB oob) {
if(!worldBounds.contains(oob)) {
return true;
}
return lineCollides(oob.topLeft, oob.topRight, 0) ||
lineCollides(oob.topRight, oob.bottomRight, 0) ||
lineCollides(oob.bottomRight, oob.bottomLeft, 0) ||
lineCollides(oob.bottomLeft, oob.topLeft, 0);
// return lineCollides(oob.center, oob.topLeft) ||
// lineCollides(oob.center, oob.topRight) ||
// lineCollides(oob.center, oob.bottomRight) ||
// lineCollides(oob.center, oob.bottomLeft);
}
/* (non-Javadoc)
* @see leola.live.game.Map#rectCollides(leola.live.math.Rectangle)
*/
@Override
public boolean rectCollides(Rectangle rect, int heightMask, Vector2f collisionTilePos) {
collisionTilePos.set(-1, -1);
if(!worldBounds.contains(rect)) {
return true;
}
// screen pixel x,y coordinate to draw the current tile to
int pixelX = 0;
int pixelY = 0;
int indexX = 0;
int indexY = 0;
int toIndex_x = 0, toIndex_y = 0;
// Current Tile offset (to pixels)
int tileOffset_x = -(rect.x % this.tileWidth);
toIndex_x = (tileOffset_x + rect.x) / this.tileWidth;
// current tile y offset (to pixels)
int tileOffset_y = -(rect.y % this.tileHeight);
toIndex_y = (tileOffset_y + rect.y) / this.tileHeight;
indexY = toIndex_y;
for (pixelY = tileOffset_y;
pixelY < rect.height && indexY < this.maxY;
pixelY += this.tileHeight, indexY++) {
for (pixelX = tileOffset_x, indexX = toIndex_x;
pixelX < rect.width && indexX < this.maxX;
pixelX += this.tileWidth, indexX++) {
if ( (indexY >= 0 && indexX >= 0) && (indexY < this.maxY && indexX < this.maxX) ) {
for (int i = 0; i < collidableLayers.length; i++) {
Layer layer = collidableLayers[i];
Tile tile = layer.getRow(indexY)[indexX];
if (tile != null) {
int tileHeightMask = tile.getHeightMask();
if(tileHeightMask > 0) {
if ( (tileHeightMask & heightMask) == tileHeightMask && (tile.rectCollide(rect)) ) {
collisionTilePos.set(tile.getX(), tile.getY());
return true;
}
}
else if( tile.rectCollide(rect) ) {
collisionTilePos.set(tile.getX(), tile.getY());
return true;
}
}
}
}
}
}
return false;
}
/* (non-Javadoc)
* @see leola.live.game.Map#rectCollides(leola.live.math.Rectangle)
*/
@Override
public boolean rectCollides(Rectangle rect, int heightMask) {
return rectCollides(rect, heightMask, this.collisionTilePos);
}
@Override
public boolean lineCollides(Vector2f a, Vector2f b) {
return lineCollides(a, b, 1);
}
/* (non-Javadoc)
* @see leola.live.game.Map#lineCollides(leola.live.math.Vector2f, leola.live.math.Vector2f)
*/
@Override
public boolean lineCollides(Vector2f a, Vector2f b, int heightMask) {
// Uses the Bresenham Line Algorithm
int x1 = (int)b.x;
int y1 = (int)b.y;
int x0 = (int)a.x;
int y0 = (int)a.y;
int dx = Math.abs(x1 - x0);
int dy = Math.abs(y1 - y0);
int sx = 0;
int sy = 0;
if (x0 < x1) sx = 1; else sx = -1;
if (y0 < y1) sy = 1; else sy = -1;
int err = dx - dy;
do {
if(this.pointCollides(x0, y0, heightMask)) {
return true;
}
if(x0 == x1 && y0 == y1) {
break;
}
int e2 = err * 2;
if(e2 > -dy) {
err = err - dy;
x0 = x0 + sx;
}
if(x0 == x1 && y0 == y1) {
if(this.pointCollides(x0, y0, heightMask)) {
return true;
}
break;
}
if(e2 < dx) {
err = err + dx;
y0 = y0 + sy;
}
if(checkBounds(x0, y0)) {
return true;
}
} while( true );
return false;
}
/* (non-Javadoc)
* @see leola.live.game.Map#setMask(java.util.List, int)
*/
@Override
public void setMask(List<Tile> tiles, int mask) {
if(tiles != null ) {
int s = tiles.size();
for(int i = 0; i < s; i++) {
tiles.get(i).setMask(mask);
}
}
}
/*
* (non-Javadoc)
*
* @see org.myriad.render.scene.Scene#freeScene()
*/
public void destroy() {
if (this.backgroundLayers != null) {
for (int i = 0; i < this.backgroundLayers.length; i++) {
Layer layer = this.backgroundLayers[i];
if (layer == null) {
continue;
}
for(int j = 0; j < this.backgroundLayers[i].numberOfRows(); j++) {
this.backgroundLayers[i].destroy();
}
this.backgroundLayers[i] = null;
}
}
this.backgroundLayers = null;
if (this.foregroundLayers != null) {
for (int i = 0; i < this.foregroundLayers.length; i++) {
Layer layer = this.foregroundLayers[i];
if (layer == null) {
continue;
}
for(int j = 0; j < this.foregroundLayers[i].numberOfRows(); j++) {
this.foregroundLayers[i].destroy();
}
this.foregroundLayers[i] = null;
}
}
this.foregroundLayers = null;
this.collidableLayers=null;
this.surfaces = null;
this.mapOffset = null;
this.backgroundImage = null;
this.mapHeight = 0;
this.mapWidth = 0;
this.maxX = 0;
this.maxY = 0;
this.tileHeight = 0;
this.tileWidth = 0;
this.destroyedTiles.clear();
this.destructableLayer = null;
if(this.backgroundImage != null) {
this.backgroundImage.getTexture().dispose();
}
if(this.atlas != null) {
this.atlas.destroy();
}
if(this.mapObjects != null) {
for(MapObject object : this.mapObjects) {
object.destroy();
}
this.mapObjects.clear();
this.foregroundMapObjects.clear();
this.backgroundMapObjects.clear();
}
}
/* (non-Javadoc)
* @see seventh.map.Map#getTileWorldHeight()
*/
@Override
public int getTileWorldHeight() {
return maxY;
}
/* (non-Javadoc)
* @see seventh.map.Map#getTileWorldWidth()
*/
@Override
public int getTileWorldWidth() {
return maxX;
}
/*
* (non-Javadoc)
*
* @see org.myriad.render.scene.Scene#getMapHeight()
*/
public int getMapHeight() {
return this.mapHeight;
}
/*
* (non-Javadoc)
*
* @see org.myriad.render.scene.Scene#getMapWidth()
*/
public int getMapWidth() {
return this.mapWidth;
}
/*
* (non-Javadoc)
*
* @see org.myriad.render.scene.Scene#getScreenTile(int, int, int)
*/
public Tile getWorldTile(int layer, int x, int y) {
if(checkBounds(x, y)) {
return null;
}
// Vector2f w = worldToTile(x, y);
int tileOffset_x = 0;//(x % this.tileWidth);
int wx = (tileOffset_x + x) / this.tileWidth;
int tileOffset_y = 0;//(y % this.tileHeight);
int wy = (tileOffset_y + y) / this.tileHeight;
return getTile(layer, wx, wy);
}
/* (non-Javadoc)
* @see seventh.map.Map#getWorldCollidableTile(int, int)
*/
@Override
public Tile getWorldCollidableTile(int x, int y) {
if(checkBounds(x, y)) {
return null;
}
// Vector2f w = worldToTile(x, y);
int tileOffset_x = 0;//(x % this.tileWidth);
int wx = (tileOffset_x + x) / this.tileWidth;
int tileOffset_y = 0;//(y % this.tileHeight);
int wy = (tileOffset_y + y) / this.tileHeight;
return getCollidableTile(wx, wy);
}
/* (non-Javadoc)
* @see leola.live.game.Map#hasHeightMask(int, int)
*/
@Override
public boolean hasHeightMask(int worldX, int worldY) {
// Vector2f w = worldToTile(x, y);
int tileOffset_x = 0;//(x % this.tileWidth);
int wx = (tileOffset_x + worldX) / this.tileWidth;
int tileOffset_y = 0;//(y % this.tileHeight);
int wy = (tileOffset_y + worldY) / this.tileHeight;
int numberOfLayers = this.collidableLayers.length;
for(int i = 0; i < numberOfLayers; i++) {
if(checkBounds(worldX, worldY)) {
continue;
}
Tile tile = this.collidableLayers[i].getRow(wy)[wx];
if(tile != null && tile.getHeightMask() > 0) {
return true;
}
}
return false;
}
/*
* (non-Javadoc)
*
* @see org.myriad.render.scene.Scene#getTile(int, int, int)
*/
public Tile getTile(int layer, int x, int y) {
return this.backgroundLayers[layer].getRow(y)[x];
}
@Override
public Tile getDestructableTile(int x, int y) {
for(int i = 0; i < destructableLayer.length; i++) {
if(destructableLayer[i].collidable()) {
continue;
}
Tile tile = destructableLayer[i].getRow(y)[x];
if(tile != null) {
return tile;
}
}
return null;
}
/* (non-Javadoc)
* @see seventh.map.Map#getCollidableTile(int, int)
*/
@Override
public Tile getCollidableTile(int x, int y) {
for(int i = 0; i < collidableLayers.length; i++) {
Tile tile = collidableLayers[i].getRow(y)[x];
if(tile != null) {
return tile;
}
}
return null;
}
/*
* (non-Javadoc)
*
* @see
* org.myriad.render.scene.Scene#init(org.myriad.render.scene.Scene.SceneDef
* )
*/
public void init(SceneDef info) throws Exception {
destroy();
List<Layer> collidableLayers = new ArrayList<Layer>();
List<Layer> destructableLayers = new ArrayList<Layer>();
int bgSize = info.getBackgroundLayers().length;
this.backgroundLayers = new Layer[bgSize];
for(int i = 0; i < bgSize; i++) {
this.backgroundLayers[i] = info.getBackgroundLayers()[i];
if(this.backgroundLayers[i].collidable()) {
collidableLayers.add(this.backgroundLayers[i]);
}
if(this.backgroundLayers[i].isDestructable()) {
destructableLayers.add(this.backgroundLayers[i]);
}
}
int fgSize = info.getForegroundLayers().length;
this.foregroundLayers = new Layer[fgSize];
for(int i = 0; i < fgSize; i++) {
this.foregroundLayers[i] = info.getForegroundLayers()[i];
// if(this.foregroundLayers[i].collidable()) {
// collidableLayers.add(this.foregroundLayers[i]);
// }
if(this.foregroundLayers[i].isDestructable()) {
destructableLayers.add(this.foregroundLayers[i]);
}
}
this.collidableLayers = new Layer[collidableLayers.size()];
this.collidableLayers = collidableLayers.toArray(this.collidableLayers);
this.destructableLayer = new Layer[destructableLayers.size()];
this.destructableLayer = destructableLayers.toArray(this.destructableLayer);
this.backgroundImage = info.getBackgroundImage();
this.maxX = info.getDimensionX();
this.maxY = info.getDimensionY();
this.tileWidth = info.getTileWidth();
this.tileHeight = info.getTileHeight();
Vector2f worldCoordinates = tileToWorld(this.maxX, this.maxY);
this.mapWidth = (int)worldCoordinates.x;
this.mapHeight = (int)worldCoordinates.y;
this.worldBounds = new Rectangle(0, 0, this.mapWidth, this.mapHeight);
this.atlas = info.getAtlas();
this.mapObjects = info.getMapObjects();
this.mapObjectsFactory = info.getMapObjectsFactory();
for(int i = 0; i < this.mapObjects.size(); i++) {
MapObject object = this.mapObjects.get(i);
if(object.isForeground()) {
this.foregroundMapObjects.add(object);
}
else {
this.backgroundMapObjects.add(object);
}
}
for(int i = 0; i < this.destructableLayer.length; i++) {
Layer layer = this.destructableLayer[i];
// TODO: Add height mask one too?
if(layer.collidable() && layer.isDestructable() && layer.getHeightMask() == 0) {
this.collisionLayerToAddTiles = layer;
}
}
this.surfaces = info.getSurfaces();
if(this.shadeTilesLookup != null) {
this.shadeTilesLookup = createShadeLookup(75);
}
}
/**
* Creates the shade lookup table
* @param startAlpha
* @return the shade lookup table
*/
private java.util.Map<Integer, TextureRegion> createShadeLookup(int startAlpha) {
java.util.Map<Integer, TextureRegion> shadeTilesLookup = new HashMap<>();
TextureRegion[] shadeTiles = new ShadeTiles(startAlpha, tileWidth, tileHeight).createShadeTiles();
shadeTilesLookup.put(Tile.TILE_NORTH_INVISIBLE, shadeTiles[0]);
shadeTilesLookup.put(Tile.TILE_EAST_INVISIBLE, shadeTiles[1]);
shadeTilesLookup.put(Tile.TILE_SOUTH_INVISIBLE, shadeTiles[2]);
shadeTilesLookup.put(Tile.TILE_WEST_INVISIBLE, shadeTiles[3]);
shadeTilesLookup.put(Tile.TILE_NORTH_INVISIBLE|Tile.TILE_EAST_INVISIBLE, shadeTiles[4]);
shadeTilesLookup.put(Tile.TILE_NORTH_INVISIBLE|Tile.TILE_WEST_INVISIBLE, shadeTiles[5]);
shadeTilesLookup.put(Tile.TILE_SOUTH_INVISIBLE|Tile.TILE_EAST_INVISIBLE, shadeTiles[6]);
shadeTilesLookup.put(Tile.TILE_SOUTH_INVISIBLE|Tile.TILE_WEST_INVISIBLE, shadeTiles[7]);
shadeTilesLookup.put(Tile.TILE_NORTH_INVISIBLE|Tile.TILE_WEST_INVISIBLE|Tile.TILE_EAST_INVISIBLE, shadeTiles[8]);
shadeTilesLookup.put(Tile.TILE_SOUTH_INVISIBLE|Tile.TILE_WEST_INVISIBLE|Tile.TILE_EAST_INVISIBLE, shadeTiles[9]);
shadeTilesLookup.put(Tile.TILE_NORTH_INVISIBLE|Tile.TILE_SOUTH_INVISIBLE|Tile.TILE_WEST_INVISIBLE, shadeTiles[10]);
shadeTilesLookup.put(Tile.TILE_NORTH_INVISIBLE|Tile.TILE_SOUTH_INVISIBLE|Tile.TILE_EAST_INVISIBLE, shadeTiles[11]);
shadeTilesLookup.put(Tile.TILE_SOUTH_INVISIBLE|Tile.TILE_NORTH_INVISIBLE, shadeTiles[12]);
shadeTilesLookup.put(Tile.TILE_EAST_INVISIBLE|Tile.TILE_WEST_INVISIBLE, shadeTiles[13]);
shadeTilesLookup.put(Tile.TILE_NORTH_INVISIBLE|Tile.TILE_EAST_INVISIBLE|
Tile.TILE_SOUTH_INVISIBLE|Tile.TILE_WEST_INVISIBLE, shadeTiles[14]);
return shadeTilesLookup;
}
/* (non-Javadoc)
* @see leola.live.game.Map#createMapGraph(leola.live.game.GraphNodeFactory)
*/
@Override
@SuppressWarnings("all")
public <E> MapGraph<E> createMapGraph(GraphNodeFactory<E> factory) {
int numberOfRows = backgroundLayers[0].numberOfRows();
int numberOfColumns = backgroundLayers[0].getRow(0).length;
GraphNode[][] nodes = new GraphNode[numberOfRows][numberOfColumns];
for(int i = 0; i < numberOfRows; i++) {
nodes[i] = new GraphNode[numberOfColumns];
}
// first build all graph nodes.
for(int y = 0; y < numberOfRows; y++) {
for(int x = 0; x < numberOfColumns; x++ ) {
boolean isCollidable = false;
for(int i = 0; i < collidableLayers.length; i++) {
if (collidableLayers[i] != null) {
Tile tile = collidableLayers[i].getRow(y)[x];
isCollidable = tile != null;
if(isCollidable) {
break;
}
}
}
if(!isCollidable) {
Tile tile = this.getTile(0, x, y);
if(tile != null) {
GraphNode<Tile, E> node = new GraphNode<Tile, E>(tile);
nodes[y][x] = node;
}
}
}
}
// now let's build the edge nodes
for(int y = 0; y < numberOfRows; y++) {
for(int x = 0; x < numberOfColumns; x++ ) {
GraphNode<Tile, E> node = nodes[y][x];
if(node == null) continue;
addNode(factory, nodes, node, x, y, false);
}
}
return new MapGraph<E>(this, nodes);
}
@SuppressWarnings("all")
@Override
public <E> void addNode(GraphNodeFactory<E> factory, GraphNode[][] nodes, GraphNode<Tile, E> node, int x, int y) {
addNode(factory, nodes, node, x, y, true);
}
@SuppressWarnings("all")
private <E> void addNode(GraphNodeFactory<E> factory, GraphNode[][] nodes, GraphNode<Tile, E> node, int x, int y, boolean addAdjacent) {
int numberOfRows = backgroundLayers[0].numberOfRows();
int numberOfColumns = backgroundLayers[0].getRow(0).length;
nodes[y][x] = node;
GraphNode<Tile, E> nw = null;
if(y > 0 && x > 0) nw = nodes[y - 1][x - 1];
GraphNode<Tile, E> n = null;
if(y > 0) n = nodes[y - 1][x];
GraphNode<Tile, E> ne = null;
if(y > 0 && x < numberOfColumns - 1) ne = nodes[y - 1][x + 1];
GraphNode<Tile, E> e = null;
if(x < numberOfColumns - 1) e = nodes[y][x + 1];
GraphNode<Tile, E> se = null;
if(y < numberOfRows - 1 && x < numberOfColumns - 1) se = nodes[y + 1][x + 1];
GraphNode<Tile, E> s = null;
if(y < numberOfRows - 1) s = nodes[y + 1][x];
GraphNode<Tile, E> sw = null;
if(y < numberOfRows - 1 && x > 0) sw = nodes[y + 1][x - 1];
GraphNode<Tile, E> w = null;
if(x > 0) w = nodes[y][x - 1];
if (n != null) {
node.addEdge(Directions.N, new Edge<Tile, E>(node, n, factory == null? null:factory.createEdgeData(this, node, n)));
if(addAdjacent) n.addEdge(Directions.N.invertedDirection(), new Edge<Tile, E>(n, node, factory == null? null:factory.createEdgeData(this, n, node)));
}
if (ne != null && (n != null || e != null)) {
node.addEdge(Directions.NE, new Edge<Tile, E>(node, ne, factory == null? null:factory.createEdgeData(this, node, ne)));
if(addAdjacent) ne.addEdge(Directions.NE.invertedDirection(), new Edge<Tile, E>(ne, node, factory == null? null:factory.createEdgeData(this, ne, node)));
}
if (e != null) {
node.addEdge(Directions.E, new Edge<Tile, E>(node, e, factory == null? null:factory.createEdgeData(this, node, e)));
if(addAdjacent) e.addEdge(Directions.E.invertedDirection(), new Edge<Tile, E>(e, node, factory == null? null:factory.createEdgeData(this, e, node)));
}
if (se != null && (s != null || e != null)) {
node.addEdge(Directions.SE, new Edge<Tile, E>(node, se, factory == null? null:factory.createEdgeData(this, node, se)));
if(addAdjacent) se.addEdge(Directions.SE.invertedDirection(), new Edge<Tile, E>(se, node, factory == null? null:factory.createEdgeData(this, se, node)));
}
if (s != null) {
node.addEdge(Directions.S, new Edge<Tile, E>(node, s, factory == null? null:factory.createEdgeData(this, node, s)));
if(addAdjacent) s.addEdge(Directions.S.invertedDirection(), new Edge<Tile, E>(s, node, factory == null? null:factory.createEdgeData(this, s, node)));
}
if (sw != null && (s != null || w != null)) {
node.addEdge(Directions.SW, new Edge<Tile, E>(node, sw, factory == null? null:factory.createEdgeData(this, node, sw)));
if(addAdjacent) sw.addEdge(Directions.SW.invertedDirection(), new Edge<Tile, E>(sw, node, factory == null? null:factory.createEdgeData(this, sw, node)));
}
if (w != null) {
node.addEdge(Directions.W, new Edge<Tile, E>(node, w, factory == null? null:factory.createEdgeData(this, node, w)));
if(addAdjacent) w.addEdge(Directions.W.invertedDirection(), new Edge<Tile, E>(w, node, factory == null? null:factory.createEdgeData(this, w, node)));
}
if (nw != null && (n != null || w != null) ) {
node.addEdge(Directions.NW, new Edge<Tile, E>(node, nw, factory == null? null:factory.createEdgeData(this, node, nw)));
if(addAdjacent) nw.addEdge(Directions.NW.invertedDirection(), new Edge<Tile, E>(nw, node, factory==null? null:factory.createEdgeData(this, nw, node)));
}
}
/* (non-Javadoc)
* @see leola.live.game.Map#getTileHeight()
*/
public int getTileHeight() {
return this.tileHeight;
}
/* (non-Javadoc)
* @see leola.live.game.Map#getTileWidth()
*/
public int getTileWidth() {
return this.tileWidth;
}
/*
* (non-Javadoc)
*
* @see org.myriad.render.scene.Scene#tileToWorld(int, int)
*/
public Vector2f tileToWorld(int tx, int ty) {
return new Vector2f(tx * this.tileWidth, ty * this.tileHeight);
}
@Override
public int tileToWorldX(int x) {
return x * this.tileWidth;
}
@Override
public int tileToWorldY(int y) {
return y * this.tileHeight;
}
/*
* (non-Javadoc)
*
* @see org.myriad.render.scene.Scene#worldToTile(int, int)
*/
public Vector2f worldToTile(int x, int y) {
Vector2f w = new Vector2f();
int tileOffset_x = 0;//(x % this.tileWidth);
w.x = (tileOffset_x + x) / this.tileWidth;
int tileOffset_y = 0;//(y % this.tileHeight);
w.y = (tileOffset_y + y) / this.tileHeight;
return (w);
}
/* (non-Javadoc)
* @see seventh.map.Map#worldToTileX(int)
*/
@Override
public int worldToTileX(int x) {
int tileOffset_x = 0;//(x % this.tileWidth);
return (tileOffset_x + x) / this.tileWidth;
}
/* (non-Javadoc)
* @see seventh.map.Map#worldToTileY(int)
*/
@Override
public int worldToTileY(int y) {
int tileOffset_y = 0;//(y % this.tileHeight);
return (tileOffset_y + y) / this.tileHeight;
}
/*
* (non-Javadoc)
*
* @see org.myriad.render.Renderable#render(org.myriad.render.Renderer,
* org.myriad.render.Camera)
*/
public void render(Canvas canvas, Camera camera, float alpha) {
//Vector2f camPos = camera.getPosition();
Vector2f camPos = camera.getRenderPosition(alpha);
Rectangle viewport = camera.getViewPort();
// remember the current frames viewport
this.currentFrameViewport.setBounds(viewport);
this.mapOffset = camPos;
// the viewport x, and y location
int vx = viewport.getX();
int vy = viewport.getY();
// screen pixel x,y coordinate to draw the current tile to
int pixelX = 0;
int pixelY = 0;
int indexX = 0;
int indexY = 0;
int toIndex_x = 0, toIndex_y = 0;
int camPosX = (int)(camPos.x);
int camPosY = (int)(camPos.y);
// Current Tile offset (to pixels)
int tileOffset_x = -(camPosX % this.tileWidth);
toIndex_x = (tileOffset_x + camPosX) / this.tileWidth;
// current tile y offset (to pixels)
int tileOffset_y = -( camPosY % this.tileHeight);
toIndex_y = (tileOffset_y + camPosY) / this.tileHeight;
// render the background
renderBackground(canvas, camera);
indexY = toIndex_y;
for (pixelY = tileOffset_y;
pixelY < viewport.getHeight() && indexY < this.maxY;
pixelY += this.tileHeight, indexY++) {
for (pixelX = tileOffset_x, indexX = toIndex_x;
pixelX < viewport.getWidth() && indexX < this.maxX;
pixelX += this.tileWidth, indexX++) {
if ((indexY >= 0 && indexX >= 0) && (indexY < this.maxY && indexX < this.maxX)) {
//for(int i = this.backgroundLayers.length - 1; i >= 0; i--)
for(int i = 0; i < this.backgroundLayers.length; i++)
{
Layer layer = this.backgroundLayers[i];
if (layer == null) {
continue;
}
if (layer.isPropertyLayer()) {
continue;
}
Tile tile = layer.getRow(indexY)[indexX];
if (tile != null) {
tile.setRenderingPosition(pixelX + vx, pixelY + vy);
tile.render(canvas, camera, alpha);
//break;
// helpful debug stuff
// canvas.setFont("Arial", 8);
//String text = "(" + indexX + "," + indexY +")";
//canvas.drawString(text, pixelX + vx + 16 - (canvas.getWidth(text)/2) , pixelY + vy + 16, 0xff00ff00);
//canvas.drawRect(pixelX + vx, pixelY + vy, tile.getWidth(), tile.getHeight(), 0xff00ff00);
// if(layer.collidable()) {
// canvas.drawRect(pixelX + vx, pixelY + vy, tile.getWidth(), tile.getHeight(), 0xff00ffff);
// }
}
}
}
}
}
renderMapObjects(canvas, camera, alpha, this.backgroundMapObjects);
}
/* (non-Javadoc)
* @see org.myriad.render.scene.Scene#renderForeground(org.myriad.render.Renderer, org.myriad.render.Camera, org.myriad.core.TimeUnit)
*/
public void renderForeground(Canvas canvas, Camera camera, float alpha) {
Vector2f camPos = camera.getRenderPosition(alpha);
Rectangle viewport = camera.getViewPort();
// the viewport x, and y location
int vx = viewport.getX();
int vy = viewport.getY();
// screen pixel x,y coordinate to draw the current tile to
int pixelX = 0;
int pixelY = 0;
int indexX = 0;
int indexY = 0;
int toIndex_x = 0, toIndex_y = 0;
// Current Tile offset (to pixels)
int tileOffset_x = -((int)camPos.x % this.tileWidth);
toIndex_x = (tileOffset_x + (int)camPos.x) / this.tileWidth;
// current tile y offset (to pixels)
int tileOffset_y = -((int)camPos.y % this.tileHeight);
toIndex_y = (tileOffset_y + (int)camPos.y) / this.tileHeight;
indexY = toIndex_y;
for (pixelY = tileOffset_y;
pixelY < viewport.getHeight() && indexY < this.maxY;
pixelY += this.tileHeight, indexY++) {
for (pixelX = tileOffset_x, indexX = toIndex_x;
pixelX < viewport.getWidth() && indexX < this.maxX;
pixelX += this.tileWidth, indexX++) {
if ((indexY >= 0 && indexX >= 0) && (indexY < this.maxY && indexX < this.maxX)) {
for(int i = 0; i < this.foregroundLayers.length; i++) {
Layer layer = this.foregroundLayers[i];
if (layer == null) {
continue;
}
if (layer.isPropertyLayer()) {
continue;
}
Tile tile = layer.getRow(indexY)[indexX];
if (tile != null) {
tile.setRenderingPosition(pixelX + vx, pixelY + vy);
tile.render(canvas, camera, alpha);
}
}
}
}
}
renderMapObjects(canvas, camera, alpha, this.foregroundMapObjects);
}
/*
* (non-Javadoc)
* @see leola.live.game.Map#renderSolid(leola.live.gfx.Canvas, leola.live.gfx.Camera)
*/
public void renderSolid(Canvas canvas, Camera camera, float alpha) {
//Vector2f camPos = camera.getPosition();
Vector2f camPos = camera.getRenderPosition(alpha);
Rectangle viewport = camera.getViewPort();
int currentColor = canvas.getColor();
// this.shadeTilesLookup = createShadeLookup(45);
// the viewport x, and y location
int vx = viewport.getX();
int vy = viewport.getY();
// screen pixel x,y coordinate to draw the current tile to
float pixelX = 0;
float pixelY = 0;
int indexX = 0;
int indexY = 0;
float toIndex_x = 0, toIndex_y = 0;
// Current Tile offset (to pixels)
float tileOffset_x = -(camPos.x % this.tileWidth);
toIndex_x = (tileOffset_x + camPos.x) / this.tileWidth;
// current tile y offset (to pixels)
float tileOffset_y = -((int)camPos.y % this.tileHeight);
toIndex_y = (tileOffset_y + (int)camPos.y) / this.tileHeight;
indexY = (int)toIndex_y;
Layer layer = this.backgroundLayers[0];
for (pixelY = tileOffset_y;
pixelY < viewport.getHeight() && indexY < this.maxY;
pixelY += this.tileHeight, indexY++) {
for (pixelX = tileOffset_x, indexX = (int)toIndex_x;
pixelX < viewport.getWidth() && indexX < this.maxX;
pixelX += this.tileWidth, indexX++) {
if ((indexY >= 0 && indexX >= 0) && (indexY < this.maxY && indexX < this.maxX)) {
Tile tile = layer.getRow(indexY)[indexX];
if (tile != null) {
int mask = tile.getMask();
if(mask == 0) {
canvas.fillRect(pixelX + vx, pixelY + vy, tileWidth, tileHeight, currentColor);
}
else if (mask > 1) {
float px = pixelX + vx;
float py = pixelY + vy;
TextureRegion image = this.shadeTilesLookup.get(mask - 1);
if(image != null) {
canvas.drawImage(image, px, py, null);
}
}
}
}
}
}
}
/*
* (non-Javadoc)
*
* @see org.myriad.render.Renderable#update(org.myriad.core.TimeStep)
*/
public void update(TimeStep timeStep) {
if (this.mapOffset == null || this.currentFrameViewport == null) {
return;
}
Vector2f camPos = this.mapOffset;
Rectangle viewport = this.currentFrameViewport;
// screen pixel x,y coordinate to draw the current tile to
int pixelX = 0;
int pixelY = 0;
int indexX = 0;
int indexY = 0;
int toIndex_x = 0, toIndex_y = 0;
// Current Tile offset (to pixels)
int tileOffset_x = -((int)camPos.x % this.tileWidth);
// to next index
toIndex_x = (tileOffset_x + (int)camPos.x) / this.tileWidth;
// current tile y offset (to pixels)
int tileOffset_y = -((int)camPos.y % this.tileHeight);
toIndex_y = (tileOffset_y + (int)camPos.y) / this.tileHeight;
indexY = toIndex_y;
for (pixelY = tileOffset_x;
pixelY < viewport.getHeight() && indexY < this.maxY;
pixelY += this.tileHeight, indexY++) {
for (pixelX = toIndex_y, indexX = toIndex_x;
pixelX < viewport.getWidth() && indexX < this.maxX;
pixelX += this.tileWidth, indexX++) {
if ((indexY >= 0 && indexX >= 0) && (indexY < this.maxY && indexX < this.maxX)) {
for (Layer layer : this.backgroundLayers) {
if (layer == null) {
continue;
}
if (!layer.hasAnimations()) {
continue;
}
Tile tile = layer.getRow(indexY)[indexX];
if (tile != null) {
tile.update(timeStep);
}
}
for (Layer layer : this.foregroundLayers) {
if (layer == null) {
continue;
}
if (!layer.hasAnimations()) {
continue;
}
Tile tile = layer.getRow(indexY)[indexX];
if (tile != null) {
tile.update(timeStep);
}
}
}
}
}
}
private void renderMapObjects(Canvas canvas, Camera camera, float alpha, List<MapObject> mapObjects) {
Rectangle viewport = camera.getWorldViewPort();
for(int i = 0; i < mapObjects.size(); i++) {
MapObject object = mapObjects.get(i);
if(viewport.intersects(object.getBounds())) {
object.render(canvas, camera, alpha);
}
}
}
/**
* Render the background image
*
* @param r
* @param camera
*/
private void renderBackground(Canvas canvas, Camera camera) {
if (this.backgroundImage == null) {
return;
}
Rectangle viewport = camera.getViewPort();
canvas.drawScaledImage(this.backgroundImage
, viewport.getX()
, viewport.getY()
, viewport.getWidth()
, viewport.getHeight(), 0xFFFFFFFF);
}
/* (non-Javadoc)
* @see seventh.map.Map#getSurfaceTypeByIndex(int, int)
*/
@Override
public SurfaceType getSurfaceTypeByIndex(int x, int y) {
return this.surfaces[y][x];
}
/* (non-Javadoc)
* @see seventh.map.Map#getSurfaceTypeByWorld(int, int)
*/
@Override
public SurfaceType getSurfaceTypeByWorld(int x, int y) {
if(checkBounds(x, y)) {
return null;
}
int tileOffset_x = 0;
int wx = (tileOffset_x + x) / this.tileWidth;
int tileOffset_y = 0;
int wy = (tileOffset_y + y) / this.tileHeight;
return this.surfaces[wy][wx];
}
/* (non-Javadoc)
* @see seventh.map.Map#getRemovedTiles()
*/
@Override
public List<Tile> getRemovedTiles() {
return this.destroyedTiles;
}
/* (non-Javadoc)
* @see seventh.map.Map#removeDestructableTilesAt(int[])
*/
@Override
public boolean removeDestructableTilesAt(int[] tilePositions) {
if(tilePositions != null) {
for(int i = 0; i < tilePositions.length; i += 2) {
removeDestructableTileAt(tilePositions[i + 0], tilePositions[i + 1]);
}
}
return true; // TODO
}
/* (non-Javadoc)
* @see seventh.map.Map#removeDestructableTileAt(float, float)
*/
@Override
public boolean removeDestructableTileAtWorld(int worldX, int worldY) {
if(checkBounds(worldX, worldY)) {
return false;
}
int tileOffset_x = 0;
int wx = (tileOffset_x + worldX) / this.tileWidth;
int tileOffset_y = 0;
int wy = (tileOffset_y + worldY) / this.tileHeight;
return removeDestructableTileAt(wx, wy);
}
/* (non-Javadoc)
* @see seventh.map.Map#removeDestructableTileAt(int, int)
*/
@Override
public boolean removeDestructableTileAt(int tileX, int tileY) {
if(checkTileBounds(tileX, tileY)) {
return false;
}
boolean wasRemoved = false;
for(int i = 0; i < this.destructableLayer.length; i++) {
Layer layer = this.destructableLayer[i];
Tile tile = layer.getRow(tileY)[tileX];
if(tile != null) {
if(!tile.isDestroyed()) {
this.destroyedTiles.add(tile);
tile.setDestroyed(true);
layer.getRow(tileY)[tileX] = null;
wasRemoved = true;
}
}
}
return wasRemoved;
}
/* (non-Javadoc)
* @see seventh.map.Map#restoreDestroyedTiles()
*/
@Override
public void restoreDestroyedTiles() {
for(int index = 0; index < this.destroyedTiles.size(); index++) {
Tile tile = this.destroyedTiles.get(index);
Layer layer = this.backgroundLayers[tile.getLayer()];
layer.addTile(tile);
tile.setDestroyed(false);
}
this.destroyedTiles.clear();
}
@Override
public void addTile(Tile tile) {
this.backgroundLayers[tile.getLayer()].addTile(tile);
this.addedTiles.add(tile);
if(this.collisionLayerToAddTiles != null) {
Tile collisionTile = new Tile(null, tile.getTileId(),
this.collisionLayerToAddTiles.getIndex(), tile.getWidth(), tile.getHeight());
collisionTile.setCollisionMask(tile.getCollisionMask());
collisionTile.setHeightMask(tile.getHeightMask());
collisionTile.setPosition(tile.getX(), tile.getY());
collisionTile.setIndexPosition(tile.getXIndex(), tile.getYIndex());
this.collisionLayerToAddTiles.addTile(collisionTile);
}
}
@Override
public List<Tile> getAddedTiles() {
return this.addedTiles;
}
@Override
public void removeAddedTiles() {
for(int index = 0; index < this.addedTiles.size(); index++) {
Tile tile = this.addedTiles.get(index);
Layer layer = this.backgroundLayers[tile.getLayer()];
layer.removeTile(tile);
if(this.destructableLayer.length > 0) {
this.destructableLayer[0].removeTile(tile);
}
}
this.addedTiles.clear();
}
@Override
public TilesetAtlas geTilesetAtlas() {
return this.atlas;
}
@Override
public MapObjectFactory getMapObjectFactory() {
return this.mapObjectsFactory;
}
/* (non-Javadoc)
* @see seventh.shared.Debugable#getDebugInformation()
*/
@Override
public DebugInformation getDebugInformation() {
DebugInformation me = new DebugInformation();
me.add("width", this.mapWidth)
.add("height", this.mapHeight)
.add("tileWidth", this.tileWidth)
.add("tileHeight", this.tileHeight)
.add("maxX", this.maxX)
.add("maxY", this.maxY);
String[] tiles = new String[this.maxY];
for(int i = 0; i < tiles.length; i++) {
tiles[i] = "\"";
}
Layer[] layers = getCollidableLayers();
for(int y = 0; y < getTileWorldHeight(); y++) {
for(int x = 0; x < getTileWorldWidth(); x++) {
Tile topTile = null;
for(int i = 0; i < layers.length; i++) {
Tile tile = layers[i].getRow(y)[x];
if(tile != null) {
topTile = tile;
break;
}
}
if(topTile != null) {
tiles[y] += "X";
}
else {
tiles[y] += "O";
}
}
}
for(int i = 0; i < tiles.length; i++) {
tiles[i] += "\"";
}
me.add("tiles", tiles);
return me;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return getDebugInformation().toString();
}
}
| 52,592 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TileData.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/TileData.java | /*
* see license.txt
*/
package seventh.map;
/**
* @author Tony
*
*/
public class TileData {
public int type;
public int tileX, tileY;
}
| 152 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Layer.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/Layer.java | /*
* leola-live
* see license.txt
*/
package seventh.map;
/**
* A {@link Layer} in a {@link Map}.
*
* @author Tony
*
*/
public class Layer {
/**
* Iterator callback for iterating over a {@link Layer}s
* {@link Tile}s
* @author Tony
*
*/
public static interface LayerTileIterator {
public void onTile(Tile tile, int x, int y);
}
/**
* Underlying layer
*/
private Tile[][] rows;
/**
* Collidables
*/
private boolean canCollide;
/**
* If its a foreground layers
*/
private boolean isForeground;
private boolean isVisible;
/**
* If this is a property layer and
* doesn't have render data
*/
private boolean isPropertyLayer;
/**
* If this layer can be destroyed
*/
private boolean isDestructable;
/**
* If this layer has animations
*/
private boolean hasAnimation;
private int index;
private int heightMask;
private String name;
/**
* Constructs a {@link Layer}.
*/
public Layer(String name,
boolean collidable,
boolean isForeground,
boolean isDestructable,
boolean isVisible,
int index,
int heightMask,
int numberOfRows) {
this.name = name;
this.rows = new Tile[numberOfRows][];
this.canCollide = collidable;
this.isForeground = isForeground;
this.isDestructable = isDestructable;
this.isVisible = isVisible;
this.isPropertyLayer = collidable;
this.index = index;
this.heightMask = heightMask;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the heightMask
*/
public int getHeightMask() {
return heightMask;
}
/**
* Applies the height mask to this layer
*/
public void applyHeightMask() {
for(int rowIndex = 0; rowIndex < this.rows.length; rowIndex++) {
Tile[] row = this.rows[rowIndex];
for(int i = 0; i < row.length; i++) {
Tile t = row[i];
if(t != null) {
t.setHeightMask(heightMask);
}
}
}
}
/**
* @return the index
*/
public int getIndex() {
return index;
}
/**
* If the tiles on this layer are collidable.
*
* @return
*/
public boolean collidable() {
return this.canCollide;
}
/**
* @return the isForeground
*/
public boolean isForeground() {
return isForeground;
}
/**
* @return the isDestructable
*/
public boolean isDestructable() {
return isDestructable;
}
/**
* @return the isPropertyLayer
*/
public boolean isPropertyLayer() {
return isPropertyLayer;
}
/**
* @return the isVisible
*/
public boolean isVisible() {
return isVisible;
}
/**
* @param isForeground the isForeground to set
*/
public void setForeground(boolean isForeground) {
this.isForeground = isForeground;
}
/**
* The number of rows in this layer.
*
* @return
*/
public int numberOfRows() {
return this.rows.length;
}
/**
* Get a row in the layer.
*
* @param i
* @return
*/
public Tile[] getRow(int i) {
return this.rows[i];
}
/**
* Add a row.
*
* @param row
*/
public void addRow(int index, Tile[] row) {
this.rows[index] = row;
for(int i = 0; i < row.length; i++) {
Tile t = row[i];
if(t != null) {
t.setHeightMask(heightMask);
}
}
}
public void addTile(Tile tile) {
this.rows[tile.getYIndex()][tile.getXIndex()] = tile;
}
public void removeTile(Tile tile) {
this.rows[tile.getYIndex()][tile.getXIndex()] = null;
}
/**
* Iterate over each {@link Tile} in this {@link Layer}
* @param it
*/
public void foreach(LayerTileIterator it) {
int worldHeight = this.rows.length;
for(int y = 0; y < worldHeight; y++) {
Tile[] row = getRow(y);
int worldWidth = row.length;
for(int x = 0; x < worldWidth; x++) {
Tile tile = row[x];
it.onTile(tile, x, y);
}
}
}
public boolean hasAnimations() {
return this.hasAnimation;
}
public void setContainsAnimations(boolean hasAnimations) {
this.hasAnimation = hasAnimations;
}
public void destroy() {
for(int rowIndex = 0; rowIndex < this.rows.length; rowIndex++) {
Tile[] row = this.rows[rowIndex];
for(int i = 0; i < row.length;i++) {
row[i] = null;
}
this.rows[rowIndex] = null;
}
}
}
| 5,256 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
MapObjectData.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/MapObjectData.java | /*
* see license.txt
*/
package seventh.map;
import leola.vm.types.LeoMap;
/**
* @author Tony
*
*/
public class MapObjectData {
public String id;
public String type;
public String name;
public float rotation;
public float x, y, width, height;
public LeoMap properties;
}
| 308 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TiledMapLoader.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/TiledMapLoader.java | /*
* leola-live
* see license.txt
*/
package seventh.map;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import leola.vm.types.LeoArray;
import leola.vm.types.LeoMap;
import leola.vm.types.LeoObject;
import leola.vm.types.LeoString;
import seventh.client.gfx.TextureUtil;
import seventh.map.Map.SceneDef;
import seventh.map.Tile.SurfaceType;
/**
* @author Tony
*
*/
public class TiledMapLoader implements MapLoader {
private static final int FLIPPED_HORIZONTALLY_FLAG = 0x80000000;
private static final int FLIPPED_VERTICALLY_FLAG = 0x40000000;
private static final int FLIPPED_DIAGONALLY_FLAG = 0x20000000;
/**
* Loads an {@link OrthoMap} created from the "Tiled" program.
*
* @param map
* @return
* @throws Exception
*/
public Map loadMap(LeoMap map, MapObjectFactory mapObjectsFactory, boolean loadAssets) throws Exception {
SceneDef def = new SceneDef();
int width = map.getInt("width");
int height = map.getInt("height");
int tileWidth = map.getInt("tilewidth");
int tileHeight = map.getInt("tileheight");
def.setDimensionX(width);
def.setDimensionY(height);
def.setTileWidth(tileWidth);
def.setTileHeight(tileHeight);
SurfaceType[][] surfaces = new SurfaceType[height][width];
def.setSurfaces(surfaces);
LeoArray tilesets = map.getByString("tilesets").as();
TilesetAtlas atlas = parseTilesets(tilesets, loadAssets);
LeoArray layers = map.getByString("layers").as();
List<Layer> mapLayers = parseLayers(layers, atlas, loadAssets, tileWidth, tileHeight, surfaces);
List<MapObject> mapObjects = parseMapObjects(layers, mapObjectsFactory);
List<Layer> backgroundLayers = new ArrayList<Layer>();
List<Layer> foregroundLayers = new ArrayList<Layer>();
for(Layer layer : mapLayers) {
if(layer.isForeground()) {
foregroundLayers.add(layer);
}
else {
backgroundLayers.add(layer);
}
}
def.setBackgroundLayers(backgroundLayers.toArray(new Layer[backgroundLayers.size()]));
def.setForegroundLayers(foregroundLayers.toArray(new Layer[foregroundLayers.size()]));
def.setAtlas(atlas);
def.setMapObjects(mapObjects);
def.setMapObjectsFactory(mapObjectsFactory);
Map theMap = new OrthoMap(loadAssets);
theMap.init(def);
return theMap;
}
/**
* Parses the {@link SurfaceType}s layer
* @param surfaces
* @param data
* @param width
* @param tileWidth
* @param tileHeight
*/
private void parseSurfaces(SurfaceType[][] surfaces, TilesetAtlas atlas, LeoArray data, int width, int tileWidth, int tileHeight) {
int y = -1; // account for zero
for(int x = 0; x < data.size(); x++) {
if(x % width == 0) {
y++;
}
int tileId = data.get(x).asInt();
int surfaceId = atlas.getTileId(tileId) - 1; /* minus one to get back to zero based */
surfaces[y][x % width] = SurfaceType.fromId(surfaceId);
}
}
private List<Layer> parseLayers(LeoArray layers,TilesetAtlas atlas, boolean loadImages, int tileWidth, int tileHeight, SurfaceType[][] surfaces) throws Exception {
List<Layer> mapLayers = new ArrayList<Layer>(layers.size());
int index = 0;
for(LeoObject l : layers) {
LeoMap layer = l.as();
String layerType = layer.getString("type");
if("tilelayer".equalsIgnoreCase(layerType)) {
Layer mapLayer = parseLayer(layer, index, atlas, loadImages, tileWidth, tileHeight, surfaces);
if(mapLayer != null) {
mapLayers.add(mapLayer);
if(!mapLayer.isForeground()) {
index++;
}
}
}
}
return mapLayers;
}
private List<MapObject> parseMapObjects(LeoArray layers, MapObjectFactory mapObjectsFactory) {
List<MapObject> mapObjects = new ArrayList<>();
for(LeoObject l : layers) {
LeoMap layer = l.as();
String layerType = layer.getString("type");
if ("objectgroup".equalsIgnoreCase(layerType)) {
LeoArray objects = layer.getArray("objects");
for(LeoObject obj : objects) {
MapObjectData data = LeoObject.fromLeoObject(obj, MapObjectData.class);
MapObject object = mapObjectsFactory.createMapObject(data);
if(object != null) {
mapObjects.add(object);
}
}
}
}
return mapObjects;
}
private Layer parseLayer(LeoMap layer, int index, TilesetAtlas atlas, boolean loadImages, int tileWidth, int tileHeight, SurfaceType[][] surfaces) {
LeoArray data = layer.getByString("data").as();
int width = layer.getInt("width");
int height = layer.getInt("height");
boolean isCollidable = false;
boolean isForeground = false;
boolean isSurfaceTypes = false;
boolean isDestructable = false;
boolean isVisible = layer.getBoolean("visible");
int heightMask = 0;
if (layer.has(LeoString.valueOf("properties"))) {
LeoMap properties = layer.getByString("properties").as();
isCollidable = properties.getString("collidable").equals("true");
isForeground = properties.getString("foreground").equals("true");
isDestructable = properties.getString("destructable").equals("true");
if(properties.containsKeyByString("heightMask")) {
String strMask = properties.getString("heightMask");
heightMask = Integer.parseInt(strMask);
}
if(properties.containsKeyByString("surfaces")) {
isSurfaceTypes = true;
}
}
// surface sounds are not a proper layer, so therefore we return
// null to indicate that this wasn't a normal layer and shouldn't be
// added to the layers
if(isSurfaceTypes) {
parseSurfaces(surfaces, atlas, data, width, tileWidth, tileHeight);
return null;
}
Layer mapLayer = new Layer(layer.getString("name"),
isCollidable,
isForeground,
isDestructable,
isVisible,
index,
heightMask,
height);
Tile[] row = null; //new Tile[width];
int y = -tileHeight; // account for zero
int rowIndex = 0;
for(int x = 0; x < data.size(); x++) {
int tileId = data.get(x).asInt();
boolean flippedHorizontally = (tileId & FLIPPED_HORIZONTALLY_FLAG) != 0;
boolean flippedVertically = (tileId & FLIPPED_VERTICALLY_FLAG) != 0;
boolean flippedDiagonally = (tileId & FLIPPED_DIAGONALLY_FLAG) != 0;
tileId &= ~(FLIPPED_HORIZONTALLY_FLAG |
FLIPPED_VERTICALLY_FLAG |
FLIPPED_DIAGONALLY_FLAG);
if(x % width == 0) {
row = new Tile[width];
mapLayer.addRow(rowIndex++, row);
y+=tileHeight;
}
if(loadImages) {
TextureRegion image = atlas.getTile(tileId);
if(image != null) {
Tile tile = null;
if(atlas.isAnimatedTile(tileId)) {
tile = new AnimatedTile(atlas.getAnimatedTile(tileId), tileId, index, tileWidth, tileHeight);
mapLayer.setContainsAnimations(true);
}
else {
tile = new Tile(image, tileId, index, tileWidth, tileHeight);
}
tile.setPosition((x % width) * tileWidth, y);
// tile.setSurfaceType(atlas.getTileSurfaceType(tileId));
tile.setFlips(flippedHorizontally, flippedVertically, flippedDiagonally);
if(isCollidable) {
int collisionId = atlas.getTileId(tileId);
tile.setCollisionMaskById(collisionId);
}
row[x % width] = tile;
}
else {
row[x % width] = null;
}
}
// if we are headless...
else {
if(tileId != 0) {
Tile tile = new Tile(null, tileId, index, tileWidth, tileHeight);
tile.setPosition( (x % width) * tileWidth, y);
// tile.setSurfaceType(atlas.getTileSurfaceType(tileId));
if(isCollidable) {
int collisionId = atlas.getTileId(tileId);
tile.setCollisionMaskById(collisionId);
}
row[x % width] = tile;
}
else {
row[x % width] = null;
}
}
}
if(!isForeground) {
index++;
}
mapLayer.applyHeightMask();
return mapLayer;
}
private TilesetAtlas parseTilesets(LeoArray tilesets, boolean loadImages) throws Exception {
if(tilesets.isEmpty()) {
throw new IllegalArgumentException("There must be at least 1 tileset");
}
TilesetAtlas atlas = new TilesetAtlas();
for(LeoObject t : tilesets) {
LeoMap tileset = t.as();
// skip the sourced tilesets
if(t.hasObject("source")) {
// HACK: Updated version of Tiled which no longer supports inlining
// shared tilests (lame)
String source = tileset.getString("source");
if(source.endsWith("collidables.tsx")) {
tileset.putByString("image", LeoString.valueOf("./assets/gfx/tiles/collision_tileset.png"));
tileset.putByString("name", LeoString.valueOf("collidables"));
}
else if(source.endsWith("city.tsx")) {
tileset.putByString("image", LeoString.valueOf("./assets/gfx/tiles/cs2dnorm.png"));
tileset.putByString("name", LeoString.valueOf("city"));
}
else if(source.endsWith("surface_types.tsx")) {
tileset.putByString("image", LeoString.valueOf("./assets/gfx/tiles/surface_types.png"));
tileset.putByString("name", LeoString.valueOf("surfaces"));
}
tileset.putByString("tilewidth", LeoObject.valueOf(32));
tileset.putByString("tileheight", LeoObject.valueOf(32));
}
int firstgid = tileset.getInt("firstgid");
int margin = tileset.getInt("margin");
int spacing = tileset.getInt("spacing");
int tilewidth = tileset.getInt("tilewidth");
int tileheight = tileset.getInt("tileheight");
LeoMap tilesetprops = null;
LeoObject props = tileset.getByString("tileproperties");
if(LeoObject.isTrue(props) && props.isMap()) {
tilesetprops = props.as();
}
TextureRegion image = null;
TextureRegion[] images = null;
if(loadImages) {
String imagePath = tileset.getString("image");
// override to local assets tile directory
if(!new File(imagePath).exists()) {
imagePath = "./assets/gfx/tiles" + imagePath.substring(imagePath.lastIndexOf("/"), imagePath.length());
}
image = TextureUtil.loadImage(imagePath);
image.flip(false, true);
image.getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
image.getTexture().setWrap(TextureWrap.MirroredRepeat, TextureWrap.MirroredRepeat);
images = TextureUtil.toTileSet(image, tilewidth, tileheight, margin, spacing);
}
atlas.addTileset(new Tileset(firstgid, images, tilesetprops));
}
return atlas;
}
}
| 13,626 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
GraphNodeFactory.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/GraphNodeFactory.java | /*
* leola-live
* see license.txt
*/
package seventh.map;
import seventh.graph.Edge;
import seventh.graph.GraphNode;
/**
* Creates {@link GraphNode} and {@link Edge} data elements.
*
* @author Tony
*
*/
public interface GraphNodeFactory<T> {
/**
* @param map
* @param left
* @param right
* @return a new edge data
*/
public T createEdgeData(Map map, GraphNode<Tile, T> left, GraphNode<Tile, T> right);
}
| 458 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
DefaultMapObjectFactory.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/DefaultMapObjectFactory.java | /*
* see license.txt
*/
package seventh.map;
import java.io.File;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import leola.vm.Leola;
import leola.vm.types.LeoArray;
import leola.vm.types.LeoMap;
import leola.vm.types.LeoObject;
import seventh.client.ClientGame;
import seventh.client.entities.ClientEntity;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.TextureUtil;
import seventh.game.Game;
import seventh.game.entities.Entity;
import seventh.game.entities.vehicles.Vehicle;
import seventh.game.weapons.Bullet;
import seventh.map.Tile.CollisionMask;
import seventh.map.Tile.SurfaceType;
import seventh.math.OBB;
import seventh.math.Rectangle;
import seventh.math.Vector2f;
import seventh.shared.Cons;
import seventh.shared.JSON;
/**
* @author Tony
*
*/
public class DefaultMapObjectFactory implements MapObjectFactory {
public static class ImageData {
public String path;
public int x, y, width, height;
}
public static class MapObjectDefinition {
public String type;
public float width, height;
public float imageWidth, imageHeight;
public boolean isCollidable;
public boolean allowRotation;
public boolean centerSprite;
public boolean isForeground;
public int heightMask;
public String surfaceType;
public ImageData image;
public LeoObject onTouched;
public LeoObject onLoad;
}
public static class TileDefinition {
public int type;
public int layer;
public int tileId;
public int collisionMaskId = CollisionMask.ALL_SOLID.ordinal();
public int heightMask = 0;
public int width = 32, height = 32;
}
private static class DefaultMapObject extends MapObject {
private OBB obb;
private int heightMask;
private boolean isCollidable;
private boolean isForeground;
private boolean centerSprite;
private boolean loadAssets;
private Sprite sprite;
private SurfaceType surfaceType;
private LeoObject onTouched;
private LeoObject onLoad;
public DefaultMapObject(boolean loadAssets, MapObjectDefinition definition, MapObjectData data) {
super(data);
this.loadAssets = loadAssets;
this.pos.set(data.x, data.y);
this.surfaceType = SurfaceType.fromString(definition.surfaceType);
Rectangle rect = new Rectangle((int)data.width, (int)data.height);
rect.setLocation(pos);
if(definition.width != 0 && definition.height != 0) {
rect.setSize((int)definition.width, (int)definition.height);
}
float imageWidth = rect.width;
float imageHeight = rect.height;
if(definition.imageWidth != 0) {
imageWidth = definition.imageWidth;
}
if(definition.imageHeight != 0) {
imageHeight = definition.imageHeight;
}
this.centerSprite = definition.centerSprite;
this.onTouched = definition.onTouched;
this.onLoad = definition.onLoad;
this.rotation = data.rotation;
float rotRadians = (float) Math.toRadians(data.rotation);
this.obb = new OBB(rect);
this.obb.rotateAround(pos, rotRadians);
if(definition.allowRotation) {
int length = (int)this.obb.length();
this.bounds.setSize(length, length);
this.bounds.centerAround(this.obb.getCenter());
}
else {
this.bounds.set(rect);
}
this.heightMask = definition.heightMask;
this.isCollidable = definition.isCollidable;
this.isForeground = definition.isForeground;
if(data.properties != null) {
if(data.properties.containsKeyByString("heightMask")) {
String heightMask = data.properties.getString("heightMask");
this.heightMask = Integer.valueOf(heightMask);
}
if(data.properties.containsKeyByString("collidable")) {
this.isCollidable = true;
}
if(data.properties.containsKeyByString("onTouched")) {
this.onTouched = LeoObject.valueOf(data.properties.getString("onTouched"));
}
if(data.properties.containsKeyByString("onLoad")) {
this.onLoad = LeoObject.valueOf(data.properties.getString("onLoad"));
}
}
//
// TODO: Manage these resources, must delete after map load,
// and only load them again if they weren't loaded before
//
if(loadAssets && definition.image != null) {
ImageData image = definition.image;
TextureRegion texture = TextureUtil.loadImage(image.path);
if(image.width > 0) {
texture = TextureUtil.subImage(texture, image.x, image.y, image.width, image.height);
}
this.sprite = new Sprite(texture);
//this.sprite.setPosition(data.x, data.y);
this.sprite.setSize(imageWidth, imageHeight);
this.sprite.setOrigin(0, 0); // TileD origin coordinates
this.sprite.setRotation(data.rotation);
}
}
@Override
public void onLoad(Game game) {
if(this.onLoad != null) {
LeoObject func = null;
if(this.onLoad.isFunction()) {
func = this.onLoad;
}
else {
func = game.getGameType().getRuntime().get(this.onLoad.toString());
}
if(func!=null) {
LeoObject result = func.call(game.asScriptObject(), asScriptObject());
if(result.isError()) {
Cons.println("*** ERROR: Error onLoad MapObject: " + result);
}
}
}
}
@Override
public void onClientLoad(ClientGame game) {
if(this.onLoad != null) {
LeoObject func = null;
if(this.onLoad.isFunction()) {
func = this.onLoad;
}
else {
func = game.getRuntime().get(this.onLoad.toString());
}
if(func!=null) {
LeoObject result = func.call(game.asScriptObject(), asScriptObject());
if(result.isError()) {
Cons.println("*** ERROR: Error onLoad MapObject: " + result);
}
}
}
}
@Override
public void destroy() {
if(loadAssets) {
if(this.sprite != null) {
this.sprite.getTexture().dispose();
}
}
}
@Override
public Vector2f getCenterPos() {
this.centerPos.set(this.obb.getCenter());
return this.centerPos;
}
@Override
public boolean isCollidable() {
return this.isCollidable;
}
@Override
public boolean isForeground() {
return this.isForeground;
}
@Override
public SurfaceType geSurfaceType() {
return this.surfaceType;
}
@Override
public boolean isTouching(Rectangle bounds) {
if(!this.bounds.intersects(bounds)) {
return false;
}
if(this.rotation == 0) {
return true;
}
return this.obb.expensiveIntersects(bounds);
}
@Override
public boolean isTouching(Entity ent) {
if(!this.bounds.intersects(ent.getBounds())) {
return false;
}
if(ent instanceof Vehicle) {
Vehicle vehicle = (Vehicle)ent;
return vehicle.getOBB().intersects(bounds);
}
if(ent instanceof Bullet) {
Bullet bullet = (Bullet)ent;
if(bullet.getOwnerHeightMask() == this.heightMask) {
if(this.rotation == 0) {
return true;
}
return this.obb.expensiveIntersects(bullet.getBounds());
}
return false;
}
if(this.rotation == 0) {
return true;
}
return this.obb.expensiveIntersects(ent.getBounds());
}
@Override
public boolean onTouch(Game game, Entity ent) {
if(this.onTouched != null) {
LeoObject func = null;
if(this.onTouched.isFunction()) {
func = this.onTouched;
}
else {
func = game.getGameType().getRuntime().get(this.onTouched.toString());
}
if(func!=null) {
LeoObject result = func.call(game.asScriptObject(), ent.asScriptObject(), asScriptObject());
if(result.isError()) {
Cons.println("*** ERROR: Error touching MapObject: " + result);
}
return result.isTrue();
}
}
return true;
}
@Override
public boolean onClientTouch(ClientGame game, ClientEntity ent) {
if(this.onTouched != null) {
LeoObject func = null;
if(this.onTouched.isFunction()) {
func = this.onTouched;
}
else {
func = game.getRuntime().get(this.onTouched.toString());
}
if(func!=null) {
LeoObject result = func.call(game.asScriptObject(), ent.asScriptObject(), asScriptObject());
if(result.isError()) {
Cons.println("*** ERROR: Error touching MapObject: " + result);
}
return result.isTrue();
}
}
return true;
}
@Override
public void render(Canvas canvas, Camera camera, float alpha) {
if(this.loadAssets && this.sprite != null) {
Vector2f cameraPos = camera.getRenderPosition(alpha);
Vector2f pos = centerSprite ? getCenterPos() : this.pos;
float x = pos.x - cameraPos.x;
float y = pos.y - cameraPos.y;
this.sprite.setPosition(x, y);
canvas.drawRawSprite(this.sprite);
//canvas.drawRect(bounds.x - cameraPos.x, bounds.y - cameraPos.y, bounds.width, bounds.height, 0xff00ff00);
//center.x-width/2f, center.y+height/2f
//obb.setLocation(/*pos.x +*/ center.x-bounds.width/2f, /*pos.y +*/ center.y+bounds.height/2f);
// DebugDraw.drawRectRelative(bounds.x, bounds.y, bounds.width, bounds.height, 0xffffff00);
// DebugDraw.fillRectRelative((int)obb.center.x, (int)obb.center.y, 5, 5, 0xffff0000);
}
//DebugDraw.drawOOBRelative(obb, 0xff00ff00);
//DebugDraw.drawRectRelative(getBounds(), 0xff00ff00);
}
}
private Map<String, MapObjectDefinition> objectDefinitions;
private Map<Integer, TileDefinition> tileDefinitions;
private boolean loadAssets;
/**
*
*/
public DefaultMapObjectFactory(Leola runtime, String mapFile, boolean loadAssets) throws Exception {
this.loadAssets = loadAssets;
this.objectDefinitions = new HashMap<>();
this.tileDefinitions = new HashMap<>();
loadObjectFile(runtime, "./assets/maps/map-objects.leola");
loadObjectFile(runtime, mapFile + ".objects.leola");
}
private void loadObjectFile(Leola runtime, String fileName) throws Exception {
File objectsFile = new File(fileName);
if(objectsFile.exists()) {
String contents = new String(Files.readAllBytes(objectsFile.toPath()));
LeoMap objectData = JSON.parseJson(runtime, contents).as();
if(objectData != null) {
LeoArray objects = objectData.getArray("objects");
if(objects != null) {
for(LeoObject object : objects) {
MapObjectDefinition definition = LeoObject.fromLeoObject(object, MapObjectDefinition.class);
this.objectDefinitions.put(definition.type.toLowerCase(), definition);
}
}
LeoArray tiles = objectData.getArray("tiles");
if(tiles != null) {
int typeIndex = 0;
for(LeoObject tile : tiles) {
TileDefinition definition = LeoObject.fromLeoObject(tile, TileDefinition.class);
definition.type = typeIndex;
this.tileDefinitions.put(definition.type, definition);
typeIndex++;
}
}
}
}
}
/**
* @return the objectDefinitions
*/
public Map<String, MapObjectDefinition> getObjectDefinitions() {
return objectDefinitions;
}
/**
* @return the tileDefinitions
*/
public Map<Integer, TileDefinition> getTileDefinitions() {
return tileDefinitions;
}
@Override
public MapObject createMapObject(MapObjectData data) {
MapObjectDefinition definition = this.objectDefinitions.get(data.type.toLowerCase());
if(definition == null) {
return null;
}
return new DefaultMapObject(loadAssets, definition, data);
}
@Override
public Tile createMapTile(TilesetAtlas atlas, TileData data) {
TileDefinition definition = this.tileDefinitions.get(data.type);
if(definition == null) {
return null;
}
Tile tile = new Tile(loadAssets ? atlas.getTile(definition.tileId) : null, definition.tileId,
definition.layer, definition.width, definition.height);
tile.setPosition(data.tileX * definition.width, data.tileY * definition.height);
tile.setIndexPosition(data.tileX, data.tileY);
tile.setCollisionMaskById(definition.collisionMaskId);
tile.setHeightMask(definition.heightMask);
tile.setFlips(false, false, false);
tile.setType(data.type);
return tile;
}
}
| 16,068 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
MapLoaderUtil.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/MapLoaderUtil.java | /*
* see license.txt
*/
package seventh.map;
import java.io.File;
import java.nio.file.Files;
import leola.vm.Leola;
import leola.vm.types.LeoMap;
import seventh.shared.JSON;
/**
* Map loading routine
*
* @author Tony
*
*/
public class MapLoaderUtil {
/**
* Loads a {@link Map}
*
* @param runtime
* @param mapFile the map file
* @param loadAssets whether or not to load the Assets along with the map
* @return the {@link Map}
* @throws Exception
*/
public static Map loadMap(Leola runtime, String mapFile, boolean loadAssets) throws Exception {
File file = new File(mapFile);
String contents = new String(Files.readAllBytes(file.toPath()));
MapObjectFactory factory = new DefaultMapObjectFactory(runtime, mapFile, loadAssets);
LeoMap mapData = JSON.parseJson(runtime, contents).as();
MapLoader mapLoader = new TiledMapLoader();
Map map = mapLoader.loadMap(mapData, factory, loadAssets);
return map;
}
}
| 1,051 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
MapObjectFactory.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/MapObjectFactory.java | /*
* see license.txt
*/
package seventh.map;
/**
* Creates {@link MapObject} instances based off of the {@link MapObjectData}
*
* @author Tony
*
*/
public interface MapObjectFactory {
public MapObject createMapObject(MapObjectData data);
public Tile createMapTile(TilesetAtlas atlas, TileData data);
}
| 321 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Tile.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/Tile.java | /*
* leola-live
* see license.txt
*/
package seventh.map;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.Renderable;
import seventh.client.gfx.TextureUtil;
import seventh.math.Circle;
import seventh.math.OBB;
import seventh.math.Rectangle;
import seventh.math.Triangle;
import seventh.math.Vector2f;
import seventh.shared.TimeStep;
/**
* A Tile represents the smallest element in a game map.
*
* @author Tony
*
*/
public class Tile implements Renderable {
public static final int TILE_INVISIBLE = 0;
public static final int TILE_VISIBLE = 1;
public static final int TILE_NORTH_INVISIBLE = 2;
public static final int TILE_SOUTH_INVISIBLE = 4;
public static final int TILE_EAST_INVISIBLE = 8;
public static final int TILE_WEST_INVISIBLE = 16;
/**
* The type of surface the world {@link Tile} has.
*
* @author Tony
*
*/
public static enum SurfaceType {
UNKNOWN,
CEMENT,
METAL,
WOOD,
GRASS,
DIRT,
SAND,
WATER,
GLASS,
;
private static SurfaceType[] values = values();
public static SurfaceType fromId(int id) {
if(id < 0 || id >= values().length) {
return UNKNOWN;
}
return values[id];
}
public static SurfaceType fromString(String type) {
SurfaceType result = UNKNOWN;
try {
if(type != null) {
result = SurfaceType.valueOf(type.toUpperCase());
}
}
catch(IllegalArgumentException e) {
}
return result;
}
}
public static enum CollisionMask {
NO_COLLISION(0) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
return false;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
return false;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
return false;
}
},
ALL_SOLID(1) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
return true;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
return true;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
return true;
}
},
WEST_HALF_SOLID(2) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.width /= 2;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.width /= 2;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.width /= 2;
return a.intersects(b);
}
},
EAST_HALF_SOLID(3) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.x += (a.width / 2);
a.width /= 2;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.x += (a.width / 2);
a.width /= 2;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.x += (a.width / 2);
a.width /= 2;
return a.intersects(b);
}
},
NORTH_HALF_SOLID(4) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.height /= 2;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.height /= 2;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.height /= 2;
return a.intersects(b);
}
},
SOUTH_HALF_SOLID(5) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.y += (a.height / 2);
a.height /= 2;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.y += (a.height / 2);
a.height /= 2;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.y += (a.height / 2);
a.height /= 2;
return a.intersects(b);
}
},
NORTH_WEST_HALF_SOLID(6) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int height = a.height;
a.height /= 2;
boolean north = a.contains(x, y);
if(!north) {
a.height = height;
a.width /= 2;
return a.contains(x, y);
}
return true;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int height = a.height;
a.height /= 2;
boolean north = oob.intersects(a);
if(!north) {
a.height = height;
a.width /= 2;
return oob.intersects(a);
}
return true;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int height = a.height;
a.height /= 2;
boolean north = a.intersects(b);
if(!north) {
a.height = height;
a.width /= 2;
return a.intersects(b);
}
return true;
}
},
NORTH_EAST_HALF_SOLID(7) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int width = a.width;
int height = a.height;
a.height /= 2;
boolean north = a.contains(x, y);
if(!north) {
a.height = height;
a.x += (width / 2);
a.width /= 2;
return a.contains(x, y);
}
return true;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int width = a.width;
int height = a.height;
a.height /= 2;
boolean north = oob.intersects(a);
if(!north) {
a.height = height;
a.x += (width / 2);
a.width /= 2;
return oob.intersects(a);
}
return true;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int width = a.width;
int height = a.height;
a.height /= 2;
boolean north = a.intersects(b);
if(!north) {
a.height = height;
a.x += (width / 2);
a.width /= 2;
return a.intersects(b);
}
return true;
}
},
SOUTH_WEST_HALF_SOLID(8) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int height = a.height;
a.height /= 2;
a.y += a.height;
boolean south = a.contains(x, y);
if(!south) {
a.height = height;
a.width /= 2;
return a.contains(x, y);
}
return true;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int height = a.height;
a.height /= 2;
a.y += a.height;
boolean south = oob.intersects(a);
if(!south) {
a.height = height;
a.width /= 2;
return oob.intersects(a);
}
return true;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int height = a.height;
a.height /= 2;
a.y += a.height;
boolean south = a.intersects(b);
if(!south) {
a.height = height;
a.width /= 2;
return a.intersects(b);
}
return true;
}
},
SOUTH_EAST_HALF_SOLID(9) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(SOUTH_HALF_SOLID.pointCollide(a, x, y)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_HALF_SOLID.pointCollide(a, x, y)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, OBB b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(SOUTH_HALF_SOLID.rectCollide(a, b)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_HALF_SOLID.rectCollide(a, b)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(SOUTH_HALF_SOLID.rectCollide(a, b)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_HALF_SOLID.rectCollide(a, b)) {
return true;
}
return false;
}
},
NORTH_SLICE_SOLID(10) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.height = 5;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.height = 5;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.height = 5;
return a.intersects(b);
}
},
SOUTH_SLICE_SOLID(11) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.y += a.height - 5;
a.height = 5;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.y += a.height - 5;
a.height = 5;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.y += a.height - 5;
a.height = 5;
return a.intersects(b);
}
},
WEST_SLICE_SOLID(12) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.width = 5;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.width = 5;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.width = 5;
return a.intersects(b);
}
},
EAST_SLICE_SOLID(13) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.x += a.width - 5;
a.width = 5;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.x += a.width - 5;
a.width = 5;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.x += a.width - 5;
a.width = 5;
return a.intersects(b);
}
},
NORTH_EAST_SLICE_SOLID(14) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(NORTH_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(NORTH_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(NORTH_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
return false;
}
},
NORTH_WEST_SLICE_SOLID(15) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(NORTH_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
a.set(ax, ay, width, height);
if(WEST_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(NORTH_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
a.set(ax, ay, width, height);
if(WEST_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(NORTH_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
a.set(ax, ay, width, height);
if(WEST_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
return false;
}
},
SOUTH_WEST_SLICE_SOLID(16) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(SOUTH_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
a.set(ax, ay, width, height);
if(WEST_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(SOUTH_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
a.set(ax, ay, width, height);
if(WEST_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(SOUTH_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
a.set(ax, ay, width, height);
if(WEST_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
return false;
}
},
SOUTH_EAST_SLICE_SOLID(17) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(SOUTH_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(SOUTH_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(SOUTH_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
return false;
}
},
NORTH_SOUTH_SLICE_SOLID(18) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(NORTH_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
a.set(ax, ay, width, height);
if(SOUTH_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(NORTH_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
a.set(ax, ay, width, height);
if(SOUTH_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(NORTH_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
a.set(ax, ay, width, height);
if(SOUTH_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
return false;
}
},
WEST_EAST_SLICE_SOLID(19) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(WEST_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_SLICE_SOLID.pointCollide(a, x, y)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(WEST_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_SLICE_SOLID.rectCollide(a, oob)) {
return true;
}
return false;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
if(WEST_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
a.set(ax, ay, width, height);
if(EAST_SLICE_SOLID.rectCollide(a, b)) {
return true;
}
return false;
}
},
SOUTH_EAST_BOX_SOLID(20) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax + width / 2, ay + height / 2, width / 2, height / 2);
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax + width / 2, ay + height / 2, width / 2, height / 2);
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax + width / 2, ay + height / 2, width / 2, height / 2);
return a.intersects(b);
}
},
NORTH_WEST_BOX_SOLID(21) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax, ay, width / 2, height / 2);
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax, ay, width / 2, height / 2);
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax, ay, width / 2, height / 2);
return a.intersects(b);
}
},
NORTH_EAST_BOX_SOLID(22) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax + width / 2, ay, width / 2, height / 2);
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax + width / 2, ay, width / 2, height / 2);
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax + width / 2, ay, width / 2, height / 2);
return a.intersects(b);
}
},
SOUTH_WEST_BOX_SOLID(23) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax, ay + height / 2, width / 2, height / 2);
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax, ay + height / 2, width / 2, height / 2);
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
int ax = a.x;
int ay = a.y;
int width = a.width;
int height = a.height;
a.set(ax, ay + height / 2, width / 2, height / 2);
return a.intersects(b);
}
},
MIDDLE_VERTICAL_SLICE_SOLID(24) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.x += a.width / 2;
a.width = 5;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.x += a.width / 2;
a.width = 5;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.x += a.width / 2;
a.width = 5;
return a.intersects(b);
}
},
MIDDLE_HORIZONTAL_SLICE_SOLID(25) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.y += a.height / 2;
a.height = 5;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.y += a.height / 2;
a.height = 5;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.y += a.height / 2;
a.height = 5;
return a.intersects(b);
}
},
UPPER_LEFT_TRIANGLE(26) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
float x0 = a.x;
float y0 = a.y;
float x1 = a.x + a.width;
float y1 = a.y;
float x2 = a.x;
float y2 = a.y + a.height;
return Triangle.pointIntersectsTriangle(x, y, x0, y0, x1, y1, x2, y2);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
return true;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
float x0 = a.x;
float y0 = a.y;
float x1 = a.x + a.width;
float y1 = a.y;
float x2 = a.x;
float y2 = a.y + a.height;
return Triangle.rectangleIntersectsTriangle(b, x0, y0, x1, y1, x2, y2);
}
},
UPPER_RIGHT_TRIANGLE(27) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
float x0 = a.x;
float y0 = a.y;
float x1 = a.x + a.width;
float y1 = a.y;
float x2 = a.x + a.width;
float y2 = a.y + a.height;
return Triangle.pointIntersectsTriangle(x, y, x0, y0, x1, y1, x2, y2);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
return true;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
float x0 = a.x;
float y0 = a.y;
float x1 = a.x + a.width;
float y1 = a.y;
float x2 = a.x + a.width;
float y2 = a.y + a.height;
return Triangle.rectangleIntersectsTriangle(b, x0, y0, x1, y1, x2, y2);
}
},
BOTTOM_LEFT_TRIANGLE(28) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
float x0 = a.x;
float y0 = a.y;
float x1 = a.x + a.width;
float y1 = a.y + a.height;
float x2 = a.x;
float y2 = a.y + a.height;
return Triangle.pointIntersectsTriangle(x, y, x0, y0, x1, y1, x2, y2);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
return true;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
float x0 = a.x;
float y0 = a.y;
float x1 = a.x + a.width;
float y1 = a.y + a.height;
float x2 = a.x;
float y2 = a.y + a.height;
return Triangle.rectangleIntersectsTriangle(b, x0, y0, x1, y1, x2, y2);
}
},
BOTTOM_RIGHT_TRIANGLE(29) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
float x0 = a.x + a.width;
float y0 = a.y;
float x1 = a.x + a.width;
float y1 = a.y + a.height;
float x2 = a.x;
float y2 = a.y + a.height;
return Triangle.pointIntersectsTriangle(x, y, x0, y0, x1, y1, x2, y2);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
return true;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
float x0 = a.x + a.width;
float y0 = a.y;
float x1 = a.x + a.width;
float y1 = a.y + a.height;
float x2 = a.x;
float y2 = a.y + a.height;
return Triangle.rectangleIntersectsTriangle(b, x0, y0, x1, y1, x2, y2);
}
},
CENTER_CIRCLE(30) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
float circleX = a.x + a.width / 2;
float circleY = a.y + a.height / 2;
float radius = 16f;
return Circle.circleContainsPoint(circleX, circleY, radius, x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
return true;
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
float circleX = a.x + a.width / 2;
float circleY = a.y + a.height / 2;
float radius = 16f;
return Circle.circleIntersectsRect(circleX, circleY, radius, b);
}
},
CENTER_VERTICAL_SOLID(31) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.x += 8;
a.width /= 2;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.x += 8;
a.width /= 2;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.x += 8;
a.width /= 2;
return a.intersects(b);
}
},
CENTER_HORIZONTAL_SOLID(32) {
@Override
public boolean pointCollide(Rectangle a, int x, int y) {
a.y += 8;
a.height /= 2;
return a.contains(x, y);
}
@Override
public boolean rectCollide(Rectangle a, OBB oob) {
a.y += 8;
a.height /= 2;
return oob.intersects(a);
}
@Override
public boolean rectCollide(Rectangle a, Rectangle b) {
a.y += 8;
a.height /= 2;
return a.intersects(b);
}
}
;
private int id;
private CollisionMask(int id) {
this.id = id;
}
// public abstract void setBounds(Rectangle rect);
public abstract boolean rectCollide(Rectangle a, Rectangle b);
public abstract boolean rectCollide(Rectangle a, OBB oob);
public abstract boolean pointCollide(Rectangle a, int x, int y);
private static CollisionMask[] values = values();
public static CollisionMask fromId(int id) {
for(CollisionMask m : values) {
if(m.id == id) {
return m;
}
}
return null;
}
}
/**
* Flip masks
*/
private static final int isFlippedHorizontal = (1 << 0),
isFlippedVert = (1 << 1),
isFlippedDiagnally = (1 << 2);
private int x,y;
private int width, height;
private int xIndex, yIndex;
private int layer;
private Sprite sprite;
private int renderX, renderY;
private int mask;
private int heightMask;
private int flipMask;
private CollisionMask collisionMask;
private Rectangle bounds;
private Vector2f centerPos;
private SurfaceType surfaceType;
private boolean isDestroyed;
private float u,u2,v,v2;
/**
* When this tile is added by
* a player, a type is attached to it
*/
private int type;
/**
* The tile ID
*/
private int tileId;
/**
*
*/
public Tile(TextureRegion image, int tileId, int layer, int width, int height) {
this.tileId = tileId;
this.layer = layer;
this.width = width;
this.height = height;
this.bounds = new Rectangle();
this.centerPos = new Vector2f();
this.collisionMask = CollisionMask.NO_COLLISION;
this.surfaceType = SurfaceType.CEMENT;
this.isDestroyed = false;
/* Account for texture bleeding,
* we offset the u/v coordinates
* to be nudged in ward of the sprite
*
* u,u2,v,v2 are data members for now
* as this allows me to quickly move this
* code to the render() method for quick
* responsive feedback
*/
if(image != null) {
this.sprite = new Sprite(image);
this.u = image.getU();
this.u2 = image.getU2();
this.v = image.getV();
this.v2 = image.getV2();
// this value is some what arbitrary
// as this looks the best
float adjustX = 0.0125f / width;
float adjustY = 0.0125f / height;
sprite.setU(u + adjustX);
sprite.setU2(u2 - adjustX);
sprite.setV(v - adjustY);
sprite.setV2(v2 + adjustY);
}
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + x;
result = prime * result + y;
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Tile other = (Tile) obj;
if (x != other.x)
return false;
if (y != other.y)
return false;
return true;
}
/**
* @return the tileId
*/
public int getTileId() {
return tileId;
}
/**
* @return the type
*/
public int getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(int type) {
this.type = type;
}
/**
* @return the surfaceType
*/
public SurfaceType getSurfaceType() {
return surfaceType;
}
/**
* @param surfaceType the surfaceType to set
*/
public void setSurfaceType(SurfaceType surfaceType) {
this.surfaceType = surfaceType;
}
/**
* @return the layer
*/
public int getLayer() {
return layer;
}
/**
* @return the height
*/
public int getHeight() {
return height;
}
/**
* @return the width
*/
public int getWidth() {
return width;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
/**
* @return the centerPos
*/
public Vector2f getCenterPos() {
this.centerPos.set(this.x + this.width / 2,
this.y + this.height / 2);
return centerPos;
}
/**
* @return the xIndex
*/
public int getXIndex() {
return xIndex;
}
/**
* @return the yIndex
*/
public int getYIndex() {
return yIndex;
}
/**
* @param collisionMask the collisionMask to set
*/
public void setCollisionMask(CollisionMask collisionMask) {
this.collisionMask = collisionMask;
}
/**
* @return the collisionMask
*/
public CollisionMask getCollisionMask() {
return collisionMask;
}
public void setCollisionMaskById(int id) {
this.collisionMask = CollisionMask.fromId(id);
if(this.collisionMask == null) {
this.collisionMask = CollisionMask.ALL_SOLID;
}
}
/**
* @param mask the mask to set
*/
public void setMask(int mask) {
this.mask = mask;
}
/**
* @return the mask
*/
public int getMask() {
return mask;
}
/**
* @param heightMask the heightMask to set
*/
public void setHeightMask(int heightMask) {
this.heightMask = heightMask;
}
/**
* @return the heightMask
*/
public int getHeightMask() {
return heightMask;
}
/**
* @return the isDestroyed
*/
public boolean isDestroyed() {
return isDestroyed;
}
/**
* @param isDestroyed the isDestroyed to set
*/
public void setDestroyed(boolean isDestroyed) {
this.isDestroyed = isDestroyed;
}
public boolean isFlippedHorizontal() {
return (this.flipMask & isFlippedHorizontal) != 0;
}
public boolean isFlippedVertical() {
return (this.flipMask & isFlippedVert) != 0;
}
public boolean isFlippedDiagnally() {
return (this.flipMask & isFlippedDiagnally) != 0;
}
public void setFlips(boolean isFlippedHorizontal, boolean isFlippedVert, boolean isFlippedDiagnally) {
if(isFlippedDiagnally) this.flipMask |= Tile.isFlippedDiagnally;
if(isFlippedHorizontal) this.flipMask |= Tile.isFlippedHorizontal;
if(isFlippedVert) this.flipMask |= Tile.isFlippedVert;
if(this.sprite == null) return;
TextureUtil.setFlips(this.sprite, isFlippedHorizontal, isFlippedVert, isFlippedDiagnally);
}
/**
* Sets the index position
* @param x
* @param y
*/
public void setIndexPosition(int x, int y) {
this.xIndex = x; this.yIndex = y;
}
/**
* @param position the position to set
*/
public void setPosition(int x, int y) {
this.x = x; this.y = y;
this.xIndex = this.x / this.width;
this.yIndex = this.y / this.height;
}
public void setRenderingPosition(int x, int y) {
this.renderX = x; this.renderY = y;
}
/**
* @return the renderX
*/
public int getRenderX() {
return renderX;
}
/**
* @return the renderY
*/
public int getRenderY() {
return renderY;
}
/**
* Determines if a point collides with this tile
* @param x
* @param y
* @return true if the point collides, false otherwise
*/
public boolean pointCollide(int x, int y) {
bounds.set(this.x, this.y, width, height);
return this.collisionMask.pointCollide(bounds, x, y);
}
/**
* Determines if the {@link Rectangle} collides with this tile
* @param rect
* @return true if the rectangle collides, false otherwise
*/
public boolean rectCollide(Rectangle rect) {
bounds.set(this.x, this.y, width, height);
return this.collisionMask.rectCollide(bounds, rect);
}
/**
* @return the bounds
*/
public Rectangle getBounds() {
bounds.set(this.x, this.y, width, height);
return bounds;
}
/**
* @return the image
*/
public Sprite getImage() {
return this.sprite;
}
/* (non-Javadoc)
* @see leola.live.gfx.Renderable#update(leola.live.TimeStep)
*/
@Override
public void update(TimeStep timeStep) {
}
/* (non-Javadoc)
* @see leola.live.gfx.Renderable#render(leola.live.gfx.Canvas, leola.live.gfx.Camera, long)
*/
@Override
public void render(Canvas canvas, Camera camera, float alpha) {
if(!this.isDestroyed) {
sprite.setPosition(renderX, renderY);
canvas.drawRawSprite(sprite);
// Vector2f pos = camera.getRenderPosition(alpha);
// float x = (this.x - pos.x);
// float y = (this.y - pos.y);
// canvas.drawScaledImage(image, x, y, width, height, 0xFFFFFFFF);
// Vector2f pos = camera.getRenderPosition(alpha);
// float x = (this.x - pos.x);
// float y = (this.y - pos.y);
// sprite.setPosition(x, y);
// canvas.drawRawSprite(sprite);
}
}
}
| 52,350 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
MapObject.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/map/MapObject.java | /*
* see license.txt
*/
package seventh.map;
import leola.vm.types.LeoMap;
import leola.vm.types.LeoObject;
import seventh.client.ClientGame;
import seventh.client.entities.ClientEntity;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.Renderable;
import seventh.game.Game;
import seventh.game.entities.Entity;
import seventh.map.Tile.SurfaceType;
import seventh.math.Rectangle;
import seventh.math.Vector2f;
import seventh.shared.TimeStep;
/**
* @author Tony
*
*/
public class MapObject implements Renderable {
private String id;
private String type;
protected Vector2f pos;
protected Vector2f centerPos;
protected float rotation;
protected Rectangle bounds;
protected MapObjectData data;
private LeoObject scriptObj;
public MapObject(MapObjectData data) {
this.data = data;
this.id = data.id;
this.type = data.type;
this.pos = new Vector2f();
this.centerPos = new Vector2f();
this.bounds = new Rectangle();
this.scriptObj = LeoObject.valueOf(this);
}
/**
* @return this script object
*/
public LeoObject asScriptObject() {
return this.scriptObj;
}
public LeoMap getProperties() {
return this.data.properties;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @return the type
*/
public String getType() {
return type;
}
/**
* @return the rotation
*/
public float getRotation() {
return rotation;
}
/**
* @return the pos
*/
public Vector2f getPos() {
return pos;
}
/**
* @return the centerPos
*/
public Vector2f getCenterPos() {
this.centerPos.set(pos);
this.centerPos.x += bounds.width / 2;
this.centerPos.y += bounds.height / 2;
return centerPos;
}
public Rectangle getBounds() {
return bounds;
}
public boolean isCollidable() {
return true;
}
public boolean isForeground() {
return false;
}
public SurfaceType geSurfaceType() {
return SurfaceType.UNKNOWN;
}
public boolean isTouching(Rectangle bounds) {
return false;
}
/**
* If this {@link MapObject} touches the supplied {@link Entity}
*
* @param ent
* @return true if touching
*/
public boolean isTouching(Entity ent) {
return false;
}
/**
* This {@link MapObject} is touched by an {@link Entity}
*
* @param game
* @param ent
* @return true if this should block the entity
*/
public boolean onTouch(Game game, Entity ent) {
return true;
}
/**
* This {@link MapObject} is touched by a {@link ClientEntity}
*
* @param game
* @param ent
* @return true if this should block the entity
*/
public boolean onClientTouch(ClientGame game, ClientEntity ent) {
return true;
}
public void destroy() {
}
/**
* The map was just loaded (server side)
*
* @param game
*/
public void onLoad(Game game) {
}
/**
* The map was just loaded (client side)
*
* @param game
*/
public void onClientLoad(ClientGame game) {
}
@Override
public void update(TimeStep timeStep) {
}
@Override
public void render(Canvas canvas, Camera camera, float alpha) {
}
}
| 3,646 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
BombExplodedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/BombExplodedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
/**
* @author Tony
*
*/
public class BombExplodedMessage extends AbstractNetMessage {
/**
*
*/
public BombExplodedMessage() {
super(BufferIO.BOMB_EXPLODED);
}
}
| 265 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
RconTokenMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/RconTokenMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.server.ServerContext;
/**
* Remote Control message token sent from the server to the client
*
* @author Tony
*
*/
public class RconTokenMessage extends AbstractNetMessage {
private long token;
/**
*/
public RconTokenMessage() {
this(ServerContext.INVALID_RCON_TOKEN);
}
/**
* @param command
*/
public RconTokenMessage(long token) {
super(BufferIO.RCON_TOKEN_MESSAGE);
this.token = token;
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(netspark.IOBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
token = buffer.getLong();
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(netspark.IOBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putLong(token);
}
/**
* @return the token
*/
public long getToken() {
return token;
}
/**
* @param token the token to set
*/
public void setToken(long token) {
this.token = token;
}
}
| 1,299 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerConnectedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerConnectedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class PlayerConnectedMessage extends AbstractNetMessage {
public int playerId;
public String name;
/**
*
*/
public PlayerConnectedMessage() {
super(BufferIO.PLAYER_CONNECTED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
name = BufferIO.readString(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
BufferIO.writeString(buffer, name != null ? name : "");
}
}
| 974 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
GameEventMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/GameEventMessage.java | /*
* The Seventh
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.events.GameEvent.EventType;
import seventh.math.Vector2f;
import seventh.math.Vector4f;
/**
* @author Tony
*
*/
public class GameEventMessage extends AbstractNetMessage {
public EventType eventType;
public Vector2f pos;
public Vector2f pos2;
public float rotation;
public String path;
public int playerId1;
public int playerId2;
public Vector4f light;
public GameEventMessage() {
super(BufferIO.GAME_EVENT);
}
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
this.eventType = EventType.fromNet(buffer.getIntBits(EventType.numberOfBits()));
switch(this.eventType) {
case CustomSound:
this.path = BufferIO.readString(buffer);
break;
case CustomTrigger:
break;
case EnemySpawned:
this.playerId1 = BufferIO.readPlayerId(buffer);
this.pos = new Vector2f();
this.pos.x = BufferIO.readPos(buffer);
this.pos.y = BufferIO.readPos(buffer);
break;
case Message:
this.path = BufferIO.readString(buffer);
break;
case LightAdjust:
this.light = new Vector4f();
int r = buffer.getUnsignedByte();
int g = buffer.getUnsignedByte();
int b = buffer.getUnsignedByte();
int intensity = buffer.getUnsignedByte();
this.light.x = (float)r / 255f;
this.light.y = (float)g / 255f;
this.light.z = (float)b / 255f;
this.light.w = (float)intensity / 255f;
break;
case BrokenGlass:
this.pos = new Vector2f();
this.pos.x = BufferIO.readPos(buffer);
this.pos.y = BufferIO.readPos(buffer);
this.rotation = BufferIO.readAngle(buffer);
break;
default:
break;
}
}
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putIntBits(this.eventType.ordinal(), EventType.numberOfBits());
switch(this.eventType) {
case CustomSound:
BufferIO.writeString(buffer, this.path);
break;
case CustomTrigger:
break;
case EnemySpawned:
BufferIO.writePlayerId(buffer, this.playerId1);
BufferIO.writePos(buffer, this.pos.x);
BufferIO.writePos(buffer, this.pos.y);
break;
case Message:
BufferIO.writeString(buffer, this.path);
break;
case LightAdjust:
buffer.putUnsignedByte( (int)(255f * this.light.x) );
buffer.putUnsignedByte( (int)(255f * this.light.y) );
buffer.putUnsignedByte( (int)(255f * this.light.z) );
buffer.putUnsignedByte( (int)(255f * this.light.w) );
break;
case BrokenGlass:
BufferIO.writePos(buffer, this.pos.x);
BufferIO.writePos(buffer, this.pos.y);
BufferIO.writeAngle(buffer, (int)this.rotation);
break;
default:
break;
}
}
}
| 3,587 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
BombPlantedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/BombPlantedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class BombPlantedMessage extends AbstractNetMessage {
public int bombTargetId;
/**
* @param bombTargetId
*/
public BombPlantedMessage(int bombTargetId) {
this();
this.bombTargetId = bombTargetId;
}
/**
*
*/
public BombPlantedMessage() {
super(BufferIO.BOMB_PLANTED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(harenet.IOBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
bombTargetId = buffer.getUnsignedByte();
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(harenet.IOBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putUnsignedByte(bombTargetId);
}
}
| 987 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
RoundEndedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/RoundEndedMessage.java | /*
* The Seventh
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.net.NetGameStats;
/**
* @author Tony
*
*/
public class RoundEndedMessage extends AbstractNetMessage {
public byte winnerTeamId;
public NetGameStats stats;
/**
*
*/
public RoundEndedMessage() {
super(BufferIO.ROUND_ENDED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
winnerTeamId = BufferIO.readTeamId(buffer);
stats = new NetGameStats();
stats.read(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writeTeamId(buffer, winnerTeamId);
stats.write(buffer);
}
}
| 1,012 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerKilledMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerKilledMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.entities.Entity.Type;
/**
* @author Tony
*
*/
public class PlayerKilledMessage extends AbstractNetMessage {
public int playerId;
public int killedById;
public Type deathType;
public int posX;
public int posY;
/**
*
*/
public PlayerKilledMessage() {
super(BufferIO.PLAYER_KILLED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
killedById = BufferIO.readPlayerId(buffer);
deathType = BufferIO.readType(buffer);
posX = buffer.getIntBits(13); // max X & Y of 256x256 tiles (32x32 tiles) ~8191
posY = buffer.getIntBits(13);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
BufferIO.writePlayerId(buffer, killedById);
BufferIO.writeType(buffer, deathType);
buffer.putIntBits(posX, 13);
buffer.putIntBits(posY, 13);
}
}
| 1,377 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
SpectatingPlayerMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/SpectatingPlayerMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class SpectatingPlayerMessage extends AbstractNetMessage {
public int playerIdBeingWatched;
/**
*
*/
public SpectatingPlayerMessage() {
super(BufferIO.SPECTATING_PLAYER);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerIdBeingWatched = BufferIO.readPlayerId(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerIdBeingWatched);
}
}
| 885 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ConnectAcceptedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/ConnectAcceptedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.net.NetGameState;
/**
* @author Tony
*
*/
public class ConnectAcceptedMessage extends AbstractNetMessage {
public int playerId;
public NetGameState gameState;
/**
*
*/
public ConnectAcceptedMessage() {
super(BufferIO.CONNECT_ACCEPTED);
}
/* (non-Javadoc)
* @see seventh.network.messages.NetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
this.playerId = BufferIO.readPlayerId(buffer);
gameState = new NetGameState();
gameState.read(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.NetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
gameState.write(buffer);
}
}
| 1,035 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ClientDisconnectMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/ClientDisconnectMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
/**
* @author Tony
*
*/
public class ClientDisconnectMessage extends AbstractNetMessage {
/**
*
*/
public ClientDisconnectMessage() {
super(BufferIO.CLIENT_DISCONNECTED);
}
}
| 272 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerDisconnectedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerDisconnectedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class PlayerDisconnectedMessage extends AbstractNetMessage {
public int playerId;
/**
*
*/
public PlayerDisconnectedMessage() {
super(BufferIO.PLAYER_DISCONNECTED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
}
}
| 856 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TileRemovedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/TileRemovedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* A tile has been removed from the world
*
* @author Tony
*
*/
public class TileRemovedMessage extends AbstractNetMessage {
/** Should be viewed as Unsigned Bytes */
public int x, y;
public TileRemovedMessage() {
super(BufferIO.TILE_REMOVED);
}
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
this.x = buffer.getUnsignedByte();
this.y = buffer.getUnsignedByte();
}
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putUnsignedByte(this.x);
buffer.putUnsignedByte(this.y);
}
}
| 737 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerSpawnedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerSpawnedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class PlayerSpawnedMessage extends AbstractNetMessage {
public int playerId;
public int posX;
public int posY;
/**
*
*/
public PlayerSpawnedMessage() {
super(BufferIO.PLAYER_SPAWNED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
posX = buffer.getIntBits(13); // max X & Y of 256x256 tiles (32x32 tiles) ~8191
posY = buffer.getIntBits(13);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
buffer.putIntBits(posX, 13);
buffer.putIntBits(posY, 13);
}
}
| 1,083 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
BombDisarmedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/BombDisarmedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class BombDisarmedMessage extends AbstractNetMessage {
public int bombTargetId;
public BombDisarmedMessage(int bombTargetId) {
this();
this.bombTargetId = bombTargetId;
}
public BombDisarmedMessage() {
super(BufferIO.BOMB_DIARMED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(harenet.IOBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
bombTargetId = buffer.getUnsignedByte();
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(harenet.IOBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putUnsignedByte(bombTargetId);
}
}
| 932 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerSwitchWeaponClassMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerSwitchWeaponClassMessage.java | /*
* The Seventh
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.entities.Entity.Type;
/**
* @author Tony
*
*/
public class PlayerSwitchWeaponClassMessage extends AbstractNetMessage {
public Type weaponType;
/**
*
*/
public PlayerSwitchWeaponClassMessage() {
super(BufferIO.PLAYER_WEAPON_CLASS_CHANGE);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
weaponType = BufferIO.readType(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writeType(buffer, weaponType);
}
}
| 923 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
FlagReturnedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/FlagReturnedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class FlagReturnedMessage extends AbstractNetMessage {
public int flagId;
public int returnedBy;
/**
*
*/
public FlagReturnedMessage() {
super(BufferIO.FLAG_RETURNED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
this.flagId = buffer.getUnsignedByte();
this.returnedBy = buffer.getUnsignedByte();
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putUnsignedByte(flagId);
buffer.putUnsignedByte(returnedBy);
}
}
| 941 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerSwitchPlayerClassMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerSwitchPlayerClassMessage.java | /*
* The Seventh
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.PlayerClass;
/**
* @author Tony
*
*/
public class PlayerSwitchPlayerClassMessage extends AbstractNetMessage {
public int playerId;
public PlayerClass playerClass;
/**
*
*/
public PlayerSwitchPlayerClassMessage() {
super(BufferIO.PLAYER_CLASS_CHANGE);
}
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
playerClass = BufferIO.readPlayerClassType(buffer);
}
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
BufferIO.writePlayerClassType(buffer, playerClass);
}
}
| 841 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerAwardMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerAwardMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.PlayerAwardSystem.Award;
/**
* @author Tony
*
*/
public class PlayerAwardMessage extends AbstractNetMessage {
public int playerId;
public Award award;
public byte killStreak;
public PlayerAwardMessage() {
super(BufferIO.PLAYER_AWARD);
}
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
award = Award.fromNetValue(buffer.getByteBits(Award.numOfBits()));
switch(award) {
case KillRoll:
case KillStreak:
killStreak = buffer.getByteBits(4);
break;
default:
break;
}
}
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
buffer.putByteBits(award.netValue(), Award.numOfBits());
switch(award) {
case KillRoll:
case KillStreak:
buffer.putByteBits(killStreak, 4);
break;
default:
break;
}
}
}
| 1,273 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TileAddedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/TileAddedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.net.NetMapAddition;
/**
* A tile has been added to the world
*
* @author Tony
*
*/
public class TileAddedMessage extends AbstractNetMessage {
public NetMapAddition tile;
public TileAddedMessage() {
super(BufferIO.TILE_ADDED);
}
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
this.tile = new NetMapAddition();
this.tile.read(buffer);
}
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
tile.write(buffer);
}
}
| 668 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
GameStatsMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/GameStatsMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.net.NetGameStats;
/**
* @author Tony
*
*/
public class GameStatsMessage extends AbstractNetMessage {
public NetGameStats stats;
/**
*
*/
public GameStatsMessage() {
super(BufferIO.GAME_STATS);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
stats = new NetGameStats();
stats.read(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
stats.write(buffer);
}
}
| 860 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
GamePartialStatsMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/GamePartialStatsMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.net.NetGamePartialStats;
/**
* Just a partial game statistics update
*
* @author Tony
*
*/
public class GamePartialStatsMessage extends AbstractNetMessage {
public NetGamePartialStats stats;
/**
*
*/
public GamePartialStatsMessage() {
super(BufferIO.GAME_PARTIAL_STATS);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
stats = new NetGamePartialStats();
stats.read(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
stats.write(buffer);
}
}
| 948 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ClientReadyMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/ClientReadyMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
/**
* @author Tony
*
*/
public class ClientReadyMessage extends AbstractNetMessage {
/**
*
*/
public ClientReadyMessage() {
super(BufferIO.CLIENT_READY);
}
}
| 255 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerSwitchTeamMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerSwitchTeamMessage.java | /*
* The Seventh
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class PlayerSwitchTeamMessage extends AbstractNetMessage {
public int playerId;
public byte teamId;
/**
*
*/
public PlayerSwitchTeamMessage() {
super(BufferIO.PLAYER_SWITCH_TEAM);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
teamId = BufferIO.readTeamId(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
BufferIO.writeTeamId(buffer, teamId);
}
}
| 976 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerSwitchTileMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerSwitchTileMessage.java | /*
* The Seventh
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class PlayerSwitchTileMessage extends AbstractNetMessage {
public int newTileId;
/**
*
*/
public PlayerSwitchTileMessage() {
super(BufferIO.PLAYER_SWITCH_TILE);
}
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
newTileId = BufferIO.readTileType(buffer);
}
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writeTileType(buffer, newTileId);
}
}
| 649 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TilesRemovedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/TilesRemovedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* A set of tiles has been removed from the world
*
* @author Tony
*
*/
public class TilesRemovedMessage extends AbstractNetMessage {
public int length;
/** Should be viewed as Unsigned Bytes, they are stored in the form
* of even index = x, odd index = y, example: [1,0,4,7] => tiles at: (1,0) and (4,7) */
public int[] tiles;
public TilesRemovedMessage() {
super(BufferIO.TILES_REMOVED);
}
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
this.length = buffer.getInt();
if(this.length > 0) {
this.tiles = new int[this.length];
for(int i = 0; i < this.tiles.length; i += 2) {
int x = buffer.getUnsignedByte();
int y = buffer.getUnsignedByte();
this.tiles[i + 0] = x;
this.tiles[i + 1] = y;
}
}
}
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putInt(this.length);
if(this.length > 0) {
for(int i = 0; i < this.tiles.length; i += 2) {
buffer.putUnsignedByte(this.tiles[i + 0]);
buffer.putUnsignedByte(this.tiles[i + 1]);
}
}
}
}
| 1,404 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
FlagStolenMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/FlagStolenMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class FlagStolenMessage extends AbstractNetMessage {
public int flagId;
public int stolenBy;
/**
*
*/
public FlagStolenMessage() {
super(BufferIO.FLAG_STOLEN);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
this.flagId = buffer.getUnsignedByte();
this.stolenBy = buffer.getUnsignedByte();
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putUnsignedByte(flagId);
buffer.putUnsignedByte(stolenBy);
}
}
| 924 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
RconMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/RconMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* Remote Control message
*
* @author Tony
*
*/
public class RconMessage extends AbstractNetMessage {
private String command;
/**
*/
public RconMessage() {
this("");
}
/**
* @param command
*/
public RconMessage(String command) {
super(BufferIO.RCON_MESSAGE);
this.command = command;
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(netspark.IOBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
this.command = BufferIO.readBigString(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(netspark.IOBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writeBigString(buffer, command);
}
/**
* @return the command
*/
public String getCommand() {
return command;
}
/**
* @param command the command to set
*/
public void setCommand(String command) {
this.command = command;
}
}
| 1,244 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerCommanderMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerCommanderMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* Determines if a Player is converted to or from a Commander
*
* @author Tony
*
*/
public class PlayerCommanderMessage extends AbstractNetMessage {
public int playerId;
public boolean isCommander;
/**
*
*/
public PlayerCommanderMessage() {
super(BufferIO.PLAYER_COMMANDER);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
isCommander = buffer.getBooleanBit();
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
buffer.putBooleanBit(isCommander);
}
}
| 1,028 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerNameChangeMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerNameChangeMessage.java | /*
* The Seventh
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class PlayerNameChangeMessage extends AbstractNetMessage {
public String name;
/**
*
*/
public PlayerNameChangeMessage() {
super(BufferIO.PLAYER_NAME_CHANGE);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
name = BufferIO.readString(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writeString(buffer, name);
}
}
| 859 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
RoundStartedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/RoundStartedMessage.java | /*
* The Seventh
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.net.NetGameState;
/**
* @author Tony
*
*/
public class RoundStartedMessage extends AbstractNetMessage {
public NetGameState gameState;
/**
*
*/
public RoundStartedMessage() {
super(BufferIO.ROUND_STARTED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
gameState = new NetGameState();
gameState.read(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
gameState.write(buffer);
}
}
| 900 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
GameReadyMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/GameReadyMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.net.NetGameState;
/**
* @author Tony
*
*/
public class GameReadyMessage extends AbstractNetMessage {
public NetGameState gameState;
/**
*
*/
public GameReadyMessage() {
super(BufferIO.GAME_READY);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
gameState = new NetGameState();
gameState.read(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
gameState.write(buffer);
}
}
| 868 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ConnectRequestMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/ConnectRequestMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* Client is attempting to connect to the server
*
* @author Tony
*
*/
public class ConnectRequestMessage extends AbstractNetMessage {
/**
* Client name
*/
public String name;
/**
*
*/
public ConnectRequestMessage() {
super(BufferIO.CONNECT_REQUEST);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
name = BufferIO.readString(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writeString(buffer, name);
}
}
| 919 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TilesAddedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/TilesAddedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.net.NetMapAdditions;
/**
* A number of tiles have been added to the world
*
* @author Tony
*
*/
public class TilesAddedMessage extends AbstractNetMessage {
public NetMapAdditions tiles;
public TilesAddedMessage() {
super(BufferIO.TILES_ADDED);
}
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
this.tiles = new NetMapAdditions();
this.tiles.read(buffer);
}
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
this.tiles.write(buffer);
}
}
| 695 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerInputMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerInputMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class PlayerInputMessage extends AbstractNetMessage {
public int keys;
public float orientation;
/**
*
*/
public PlayerInputMessage() {
super(BufferIO.PLAYER_INPUT);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
keys = buffer.getInt();
orientation = buffer.getFloat();
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putInt(keys);
buffer.putFloat(orientation);
}
}
| 895 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
GameEndedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/GameEndedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.net.NetGameStats;
/**
* @author Tony
*
*/
public class GameEndedMessage extends AbstractNetMessage {
public NetGameStats stats;
/**
*
*/
public GameEndedMessage() {
super(BufferIO.GAME_ENDED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
stats = new NetGameStats();
stats.read(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
stats.write(buffer);
}
}
| 864 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
BufferIO.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/BufferIO.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import harenet.messages.NetMessage;
import harenet.messages.NetMessageFactory;
import seventh.game.PlayerClass;
import seventh.game.entities.Entity.State;
import seventh.game.entities.Entity.Type;
import seventh.game.net.NetBomb;
import seventh.game.net.NetBombTarget;
import seventh.game.net.NetBullet;
import seventh.game.net.NetDoor;
import seventh.game.net.NetDroppedItem;
import seventh.game.net.NetEntity;
import seventh.game.net.NetExplosion;
import seventh.game.net.NetFire;
import seventh.game.net.NetFlag;
import seventh.game.net.NetLight;
import seventh.game.net.NetPlayer;
import seventh.game.net.NetPlayerPartial;
import seventh.game.net.NetRocket;
import seventh.game.net.NetSmoke;
import seventh.game.net.NetTank;
import seventh.game.weapons.Weapon.WeaponState;
import seventh.math.Rectangle;
import seventh.math.Vector2f;
/**
* Some {@link IOBuffer} utilities
*
* @author Tony
*
*/
public class BufferIO {
public static final byte BOMB_DIARMED = 1;
public static final byte BOMB_EXPLODED = 2;
public static final byte BOMB_PLANTED = 3;
public static final byte CLIENT_DISCONNECTED = 4;
public static final byte CLIENT_READY = 5;
public static final byte CONNECT_ACCEPTED = 6;
public static final byte CONNECT_REQUEST = 7;
public static final byte GAME_ENDED = 8;
public static final byte GAME_READY = 9;
public static final byte GAME_STATS = 10;
public static final byte GAME_PARTIAL_STATS = 11;
public static final byte GAME_UPDATE = 12;
public static final byte PLAYER_CONNECTED = 13;
public static final byte PLAYER_DISCONNECTED = 14;
public static final byte PLAYER_KILLED = 15;
public static final byte PLAYER_SPAWNED = 16;
public static final byte PLAYER_SWITCH_TEAM = 17;
public static final byte PLAYER_NAME_CHANGE = 18;
public static final byte PLAYER_WEAPON_CLASS_CHANGE = 19;
public static final byte PLAYER_CLASS_CHANGE = 20;
public static final byte PLAYER_SPEECH = 21;
public static final byte PLAYER_COMMANDER = 22;
public static final byte PLAYER_AWARD = 23;
public static final byte PLAYER_SWITCH_TILE = 24;
public static final byte PLAYER_INPUT = 25;
public static final byte ROUND_ENDED = 26;
public static final byte ROUND_STARTED = 27;
public static final byte SPECTATING_PLAYER = 28;
public static final byte TEAM_TEXT = 29;
public static final byte TEXT = 30;
public static final byte RCON_MESSAGE = 31;
public static final byte RCON_TOKEN_MESSAGE = 32;
public static final byte AI_COMMAND = 33;
public static final byte TILE_REMOVED = 34;
public static final byte TILES_REMOVED = 35;
public static final byte TILE_ADDED = 36;
public static final byte TILES_ADDED = 37;
public static final byte FLAG_CAPTURED = 38;
public static final byte FLAG_RETURNED = 39;
public static final byte FLAG_STOLEN = 40;
public static final byte GAME_EVENT = 41;
/**
* The Seventh {@link NetMessageFactory} implementation
*
* @author Tony
*
*/
public static class SeventhNetMessageFactory implements NetMessageFactory {
/*
* (non-Javadoc)
* @see harenet.messages.NetMessageFactory#readNetMessage(harenet.IOBuffer)
*/
public NetMessage readNetMessage(IOBuffer buffer) {
NetMessage message = null;
byte type = buffer.getByteBits(6); // must match AbstractNetMessage.write
switch(type) {
case BOMB_DIARMED: message = new BombDisarmedMessage();
break;
case BOMB_EXPLODED: message = new BombExplodedMessage();
break;
case BOMB_PLANTED: message = new BombPlantedMessage();
break;
case CLIENT_DISCONNECTED : message = new ClientDisconnectMessage();
break;
case CLIENT_READY: message = new ClientReadyMessage();
break;
case CONNECT_ACCEPTED: message = new ConnectAcceptedMessage();
break;
case CONNECT_REQUEST: message = new ConnectRequestMessage();
break;
case GAME_ENDED: message = new GameEndedMessage();
break;
case GAME_READY: message = new GameReadyMessage();
break;
case GAME_STATS: message = new GameStatsMessage();
break;
case GAME_PARTIAL_STATS: message = new GamePartialStatsMessage();
break;
case GAME_UPDATE: message = new GameUpdateMessage();
break;
case PLAYER_CONNECTED: message = new PlayerConnectedMessage();
break;
case PLAYER_DISCONNECTED: message = new PlayerDisconnectedMessage();
break;
case PLAYER_KILLED: message = new PlayerKilledMessage();
break;
case PLAYER_SPAWNED: message = new PlayerSpawnedMessage();
break;
case PLAYER_SWITCH_TEAM : message = new PlayerSwitchTeamMessage();
break;
case PLAYER_NAME_CHANGE: message = new PlayerNameChangeMessage();
break;
case PLAYER_WEAPON_CLASS_CHANGE: message = new PlayerSwitchWeaponClassMessage();
break;
case PLAYER_CLASS_CHANGE: message = new PlayerSwitchPlayerClassMessage();
break;
case PLAYER_SPEECH: message = new PlayerSpeechMessage();
break;
case PLAYER_SWITCH_TILE: message = new PlayerSwitchTileMessage();
break;
case PLAYER_INPUT: message = new PlayerInputMessage();
break;
case PLAYER_COMMANDER: message = new PlayerCommanderMessage();
break;
case PLAYER_AWARD: message = new PlayerAwardMessage();
break;
case ROUND_ENDED: message = new RoundEndedMessage();
break;
case ROUND_STARTED: message = new RoundStartedMessage();
break;
case SPECTATING_PLAYER: message = new SpectatingPlayerMessage();
break;
case TEAM_TEXT: message = new TeamTextMessage();
break;
case TEXT: message = new TextMessage();
break;
case RCON_MESSAGE: message = new RconMessage();
break;
case RCON_TOKEN_MESSAGE: message = new RconTokenMessage();
break;
case AI_COMMAND: message = new AICommandMessage();
break;
case TILE_REMOVED: message = new TileRemovedMessage();
break;
case TILES_REMOVED: message = new TilesRemovedMessage();
break;
case TILE_ADDED: message = new TileAddedMessage();
break;
case TILES_ADDED: message = new TilesAddedMessage();
break;
case FLAG_CAPTURED: message = new FlagCapturedMessage();
break;
case FLAG_RETURNED: message = new FlagReturnedMessage();
break;
case FLAG_STOLEN: message = new FlagStolenMessage();
break;
case GAME_EVENT: message = new GameEventMessage();
break;
default: throw new IllegalArgumentException("Unknown type: " + type);
}
message.read(buffer);
return message;
}
}
public static void writePos(IOBuffer buffer, float worldPos) {
writePos(buffer, (int) worldPos);
}
public static void writePos(IOBuffer buffer, int worldPos) {
buffer.putIntBits(worldPos, 13);
}
public static int readPos(IOBuffer buffer) {
return buffer.getIntBits(13);
}
public static void writeWeaponState(IOBuffer buffer, WeaponState state) {
buffer.putByteBits(state.netValue(), WeaponState.numOfBits());
}
public static WeaponState readWeaponState(IOBuffer buffer) {
byte state = buffer.getByteBits(WeaponState.numOfBits());
return WeaponState.fromNet(state);
}
public static void writeState(IOBuffer buffer, State state) {
buffer.putByteBits(state.netValue(), State.numOfBits());
}
public static State readState(IOBuffer buffer) {
byte state = buffer.getByteBits(State.numOfBits());
return State.fromNetValue(state);
}
public static void writeType(IOBuffer buffer, Type type) {
buffer.putByteBits(type.netValue(), Type.numOfBits());
}
public static Type readType(IOBuffer buffer) {
byte type = buffer.getByteBits(Type.numOfBits());
return Type.fromNet(type);
}
public static int numPlayerIdBits() {
return 5;
}
public static void writePlayerId(IOBuffer buffer, int playerId) {
buffer.putIntBits(playerId, numPlayerIdBits());
}
public static int readPlayerId(IOBuffer buffer) {
return buffer.getIntBits(numPlayerIdBits());
}
public static void writeTeamId(IOBuffer buffer, byte teamId) {
buffer.putByteBits(teamId, 2);
}
public static byte readTeamId(IOBuffer buffer) {
return buffer.getByteBits(2);
}
public static void writeAngle(IOBuffer buffer, int degrees) {
int bangle = (degrees * 256) / 360;
buffer.putUnsignedByte(bangle);
}
public static short readAngle(IOBuffer buffer) {
int bangle = buffer.getUnsignedByte();
int degree = (bangle * 360) / 256;
return (short)degree;
}
public static Vector2f readVector2f(IOBuffer buffer) {
Vector2f v = new Vector2f();
v.x = readPos(buffer);
v.y = readPos(buffer);
return v;
}
public static void writeVector2f(IOBuffer buffer, Vector2f v) {
writePos(buffer, v.x);
writePos(buffer, v.y);
}
public static Rectangle readRect(IOBuffer buffer) {
Rectangle r = new Rectangle();
r.x = readPos(buffer);
r.y = readPos(buffer);
r.width = readPos(buffer);
r.height = readPos(buffer);
return r;
}
public static void writeRect(IOBuffer buffer, Rectangle r) {
writePos(buffer, r.x);
writePos(buffer, r.y);
writePos(buffer, r.width);
writePos(buffer, r.height);
}
public static void writeString(IOBuffer buffer, String str) {
byte[] chars = str.getBytes();
int len = chars.length;
buffer.putUnsignedByte(len);
for(int i = 0; i < len; i++) {
buffer.putByte(chars[i]);
}
}
public static String readString(IOBuffer buffer) {
int len = buffer.getUnsignedByte();
byte[] chars = new byte[len];
for(int i = 0; i < len; i++) {
chars[i] = buffer.getByte();
}
return new String(chars);
}
public static void writeBigString(IOBuffer buffer, String str) {
byte[] chars = str.getBytes();
int len = chars.length;
buffer.putShort((short)len);
for(int i = 0; i < len; i++) {
buffer.putByte(chars[i]);
}
}
public static String readBigString(IOBuffer buffer) {
int len = buffer.getShort();
byte[] chars = new byte[len];
for(int i = 0; i < len; i++) {
chars[i] = buffer.getByte();
}
return new String(chars);
}
public static int readTileType(IOBuffer buffer) {
return buffer.getIntBits(8);
}
public static void writeTileType(IOBuffer buffer, int tileType) {
buffer.putIntBits(tileType, 8);
}
public static void writePlayerClassType(IOBuffer buffer, PlayerClass playerClass) {
buffer.putByteBits(PlayerClass.toNet(playerClass), 3);
}
public static PlayerClass readPlayerClassType(IOBuffer buffer) {
return PlayerClass.fromNet(buffer.getByteBits(3));
}
public static NetEntity readEntity(IOBuffer buffer) {
NetEntity result = null;
byte type = buffer.getByteBits(Type.numOfBits());
/* so the entity can re-read the type */
buffer.bitPosition(buffer.bitPosition() - Type.numOfBits());
Type entType = Type.fromNet(type);
switch(entType) {
case ROCKET:
result = new NetRocket();
break;
case SMOKE_GRENADE:
case NAPALM_GRENADE:
case GRENADE:
case BULLET: {
result = new NetBullet();
break;
}
case DROPPED_ITEM: {
result = new NetDroppedItem();
break;
}
case BOMB: {
result = new NetBomb();
break;
}
case BOMB_TARGET: {
result = new NetBombTarget();
break;
}
case PLAYER_PARTIAL: {
result = new NetPlayerPartial();
break;
}
case PLAYER: {
result = new NetPlayer();
break;
}
case EXPLOSION: {
result = new NetExplosion();
break;
}
case FIRE: {
result = new NetFire();
break;
}
case SMOKE: {
result = new NetSmoke();
break;
}
case LIGHT_BULB: {
result = new NetLight();
break;
}
case DOOR: {
result = new NetDoor();
break;
}
case SHERMAN_TANK: {
result = new NetTank(Type.SHERMAN_TANK);
break;
}
case PANZER_TANK: {
result = new NetTank(Type.PANZER_TANK);
break;
}
case ALLIED_FLAG: {
result = new NetFlag(Type.ALLIED_FLAG);
break;
}
case AXIS_FLAG: {
result = new NetFlag(Type.AXIS_FLAG);
break;
}
default: {
result = new NetEntity();
}
}
result.read(buffer);
return result;
}
}
| 15,205 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TeamTextMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/TeamTextMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class TeamTextMessage extends AbstractNetMessage {
public int playerId;
public String message;
/**
*
*/
public TeamTextMessage() {
super(BufferIO.TEAM_TEXT);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
message = BufferIO.readString(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
BufferIO.writeString(buffer, message);
}
}
| 941 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
GameUpdateMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/GameUpdateMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.game.net.NetGameUpdate;
/**
* @author Tony
*
*/
public class GameUpdateMessage extends AbstractNetMessage {
public NetGameUpdate netUpdate;
/**
*
*/
public GameUpdateMessage() {
super(BufferIO.GAME_UPDATE);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
netUpdate = new NetGameUpdate();
netUpdate.read(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
netUpdate.write(buffer);
}
}
| 882 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
AbstractNetMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/AbstractNetMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import harenet.messages.NetMessage;
/**
* @author Tony
*
*/
public class AbstractNetMessage implements NetMessage {
protected byte type;
/**
* @param type
*/
public AbstractNetMessage(byte type) {
this.type = type;
}
/* (non-Javadoc)
* @see seventh.network.messages.NetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
// type is read from the Header
}
/* (non-Javadoc)
* @see seventh.network.messages.NetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
buffer.putByteBits(type, 6); // must match SeventhNetMessageFactory
}
}
| 802 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
PlayerSpeechMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/PlayerSpeechMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class PlayerSpeechMessage extends AbstractNetMessage {
public int playerId;
public int posX;
public int posY;
public byte speechCommand;
/**
*
*/
public PlayerSpeechMessage() {
super(BufferIO.PLAYER_SPEECH);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
posX = buffer.getIntBits(13); // max X & Y of 256x256 tiles (32x32 tiles) ~8191
posY = buffer.getIntBits(13);
speechCommand = buffer.getByteBits(4);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
buffer.putIntBits(posX, 13);
buffer.putIntBits(posY, 13);
buffer.putByteBits(speechCommand, 4);
}
}
| 1,214 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
AICommandMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/AICommandMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
import seventh.ai.AICommand;
/**
* Sends an AI Command to a bot
*
* @author Tony
*
*/
public class AICommandMessage extends AbstractNetMessage {
public int botId;
public AICommand command;
public AICommandMessage() {
this(new AICommand());
}
public AICommandMessage(AICommand cmd) {
super(BufferIO.AI_COMMAND);
this.command = cmd;
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(harenet.IOBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
botId = buffer.getUnsignedByte();
command.read(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(harenet.IOBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putUnsignedByte(botId);
command.write(buffer);
}
}
| 1,077 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TextMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/TextMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class TextMessage extends AbstractNetMessage {
public int playerId;
public String message;
/**
*
*/
public TextMessage() {
super(BufferIO.TEXT);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
playerId = BufferIO.readPlayerId(buffer);
message = BufferIO.readString(buffer);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
BufferIO.writePlayerId(buffer, playerId);
BufferIO.writeString(buffer, message);
}
}
| 928 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
FlagCapturedMessage.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/network/messages/FlagCapturedMessage.java | /*
* see license.txt
*/
package seventh.network.messages;
import harenet.IOBuffer;
/**
* @author Tony
*
*/
public class FlagCapturedMessage extends AbstractNetMessage {
public int flagId;
public int capturedBy;
/**
*
*/
public FlagCapturedMessage() {
super(BufferIO.FLAG_CAPTURED);
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#read(java.nio.ByteBuffer)
*/
@Override
public void read(IOBuffer buffer) {
super.read(buffer);
this.flagId = buffer.getUnsignedByte();
this.capturedBy = buffer.getUnsignedByte();
}
/* (non-Javadoc)
* @see seventh.network.messages.AbstractNetMessage#write(java.nio.ByteBuffer)
*/
@Override
public void write(IOBuffer buffer) {
super.write(buffer);
buffer.putUnsignedByte(flagId);
buffer.putUnsignedByte(this.capturedBy);
}
}
| 946 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ScrollBar.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/ScrollBar.java | /*
* see license.txt
*/
package seventh.ui;
import seventh.client.gfx.Theme;
import seventh.client.inputs.Inputs;
import seventh.math.Rectangle;
import seventh.math.Vector2f;
import seventh.shared.EventDispatcher;
import seventh.ui.events.ButtonEvent;
import seventh.ui.events.OnButtonClickedListener;
import seventh.ui.events.OnScrollBarListener;
import seventh.ui.events.ScrollBarEvent;
/**
* Scroll bar allows for a viewport of a {@link Scrollable} pane.
*
* @author Tony
*
*/
public class ScrollBar extends Widget {
/**
* Scroll bar orientation
*
* @author Tony
*
*/
public enum Orientation {
Horizontal,
Vertical,
}
private static final int BUTTON_ENDS_SIZE = 15;
private Button top, bottom, handle;
private float currentPosition;
private float adjustAmount;
private int scrollIncrement;
private Orientation orientation;
private boolean isDragging;
private Vector2f dragSpot, dragOffset;
private Scrollable pane;
/**
* @param dispatcher
* @param maxPosition
*/
public ScrollBar(Scrollable pane, EventDispatcher dispatcher) {
super(dispatcher);
this.pane = pane;
this.orientation = Orientation.Vertical;
this.currentPosition = 0;
this.adjustAmount = 0.1f;
this.scrollIncrement = 1;
this.dragSpot = new Vector2f();
this.dragOffset = new Vector2f();
this.isDragging = false;
this.top = new Button();
this.top.getBounds().setSize(15, 15);
this.top.addOnButtonClickedListener(new OnButtonClickedListener() {
@Override
public void onButtonClicked(ButtonEvent event) {
moveBy(-getAdjustAmount());
}
});
this.bottom = new Button();
this.bottom.getBounds().setSize(15, 15);
this.bottom.addOnButtonClickedListener(new OnButtonClickedListener() {
@Override
public void onButtonClicked(ButtonEvent event) {
moveBy(+getAdjustAmount());
}
});
this.handle = new Button();
addWidget(this.top);
addWidget(this.bottom);
addWidget(this.handle);
calculateHandlePosition();
addInputListener(new Inputs() {
@Override
public boolean scrolled(int amount) {
if(amount < 0) {
moveBy(-getAdjustAmount());
}
else {
moveBy(+getAdjustAmount());
}
return true;
}
@Override
public boolean touchDragged(int x, int y, int pointer) {
if(isDragging) {
switch(getOrientation()) {
case Horizontal: {
moveHandle((int) (x + dragOffset.x), y);
break;
}
case Vertical: {
moveHandle(x, (int) (y + dragOffset.y));
return true;
}
}
}
return super.touchDragged(x, y, pointer);
}
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
isDragging = false;
return super.touchUp(x, y, pointer, button);
}
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
// determine if we've clicked on the scroll bar
if(getBounds().contains(x, y)) {
// ignore if we're touching one of the three buttons
if(top.getScreenBounds().contains(x, y)) {
return false;
}
if(bottom.getScreenBounds().contains(x, y)) {
return false;
}
if(handle.getScreenBounds().contains(x, y)) {
isDragging = true;
dragSpot.set(x, y);
Vector2f handlePos = handle.getScreenPosition();
Vector2f.Vector2fSubtract(handlePos, dragSpot, dragOffset);
return true;
}
// determine if we need to scroll up or down
final int handleX = handle.getScreenBounds().x;
final int handleY = handle.getScreenBounds().y;
switch(getOrientation()) {
case Horizontal: {
if(x < handleX) {
moveBy(-getAdjustAmount());
}
else if(x > handleX) {
moveBy(+getAdjustAmount());
}
break;
}
case Vertical: {
if(y < handleY) {
moveBy(-getAdjustAmount());
}
else if(y > handleY) {
moveBy(+getAdjustAmount());
}
break;
}
}
return true;
}
return super.touchDown(x, y, pointer, button);
}
});
}
/**
* @return the adjustAmount
*/
private float getAdjustAmount() {
return adjustAmount;
}
/**
* @return the scrollIncrement
*/
public int getScrollIncrement() {
return scrollIncrement;
}
/**
* @param scrollIncrement the scrollIncrement to set
*/
public void setScrollIncrement(int scrollIncrement) {
this.scrollIncrement = scrollIncrement;
this.calculateHandlePosition();
}
/**
* @return the currentPosition
*/
public float getCurrentPosition() {
return currentPosition;
}
/**
* Move the handle by an amount (ranges from 0 - 1.0)
*
* @param delta
*/
public void moveBy(float delta) {
float newPosition = this.currentPosition + delta;
if(delta != 0) {
move(newPosition);
}
}
/**
* Move the handle to a position (0 - 1.0 based)
*
* @param position
*/
public void move(float position) {
float previousPos = this.currentPosition;
this.currentPosition = position;
if(position < 0) {
this.currentPosition = 0;
}
else if(position > 1f) {
this.currentPosition = 1f;
}
calculateHandlePosition();
// only fire an event if we had a scroll motion;
// if adjustAmount is 1 that means nothing to scroll
if(this.adjustAmount < 1f) {
int movementDelta = 0;
// calculate the number of scrolls we actually took
float delta = this.currentPosition - previousPos;
float amount = 0;
while(amount < Math.abs(delta)) {
amount += this.adjustAmount;
movementDelta++;
}
if(delta < 0) {
movementDelta *= -1;
}
fireScrollBarEvent(new ScrollBarEvent(this, movementDelta));
}
}
public void addScrollBarListener(OnScrollBarListener listener) {
this.getEventDispatcher().addEventListener(ScrollBarEvent.class, listener);
}
/**
* Moves the scroll bar handle to the desired position
*
* @param x
* @param y
*/
public void moveHandle(int x, int y) {
final int handleSize = getHandleSize();
switch(this.orientation) {
case Horizontal: {
// TODO
break;
}
case Vertical: {
int height = getBounds().height - (handleSize + BUTTON_ENDS_SIZE*2);
if(height == 0) {
height = 1;
}
int targetY = y - (getBounds().y + BUTTON_ENDS_SIZE);
if(targetY < 0) {
targetY = 0;
}
else if(targetY > height) {
targetY = height;
}
// We must ensure that the position is a valid position
// based on the 'adjustAmount'
float newPosition = (float)targetY / (float)height;
float properPosition = 0;
while(properPosition < newPosition) {
properPosition += this.adjustAmount;
}
newPosition = properPosition;
move(newPosition);
break;
}
}
}
@Override
public void setTheme(Theme theme) {
super.setTheme(theme);
this.top.setTheme(theme);
this.bottom.setTheme(theme);
this.handle.setTheme(theme);
}
/**
* @return the orientation
*/
public Orientation getOrientation() {
return orientation;
}
/**
* @param orientation the orientation to set
*/
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
calculateHandlePosition();
}
/**
* Calculates the percentage adjustments to the scrollbar
*/
private void calculateAdjustments() {
switch(this.orientation) {
case Horizontal: {
// TODO
}
case Vertical: {
Rectangle viewport = pane.getViewport();
int viewportHeight = viewport.height;
int maxHeight = pane.getTotalHeight();
if(maxHeight <= 0 || maxHeight < viewportHeight) {
maxHeight = viewportHeight;
}
if(this.scrollIncrement > 0) {
int scrollableArea = maxHeight - viewportHeight;
int numberOfScrolls = scrollableArea / this.scrollIncrement;
if( (scrollableArea % this.scrollIncrement) > 0) {
numberOfScrolls++;
}
// 1 is weird, because we want to account for it (as in scroll one); but
// we overload adjustAmount 1 to mean no scroll, so this is a work-around
if(numberOfScrolls == 1) {
this.adjustAmount = 0.5f;
}
else if(numberOfScrolls > 0) {
this.adjustAmount = 1.0f / (float) numberOfScrolls;
}
else {
this.adjustAmount = 1f;
}
}
}
}
}
/**
* Calculates the scrollbar handle position, this must be invoked if
* the {@link Scrollable} pane has adjusted in size
*/
public void calculateHandlePosition() {
calculateAdjustments();
switch(this.orientation) {
case Horizontal: {
// TODO
break;
}
case Vertical: {
int handleSize = getHandleSize();
int height = getBounds().height - (handleSize + BUTTON_ENDS_SIZE*2);
int offset = (int)((float)height * this.currentPosition);
Rectangle bounds = this.handle.getBounds();
bounds.x = 0;
bounds.y = BUTTON_ENDS_SIZE + offset;
bounds.width = getBounds().width;
bounds.height = handleSize;
this.top.getBounds().set(0, 0, getBounds().width, BUTTON_ENDS_SIZE);
this.bottom.getBounds().set(0, getBounds().height - BUTTON_ENDS_SIZE, getBounds().width, BUTTON_ENDS_SIZE);
break;
}
}
}
private int getHandleSize() {
final int minHandleSize = BUTTON_ENDS_SIZE * 3;
switch(this.orientation) {
case Horizontal: {
// TODO
return minHandleSize;
}
case Vertical: {
Rectangle viewport = pane.getViewport();
int viewportHeight = viewport.height;
int maxHeight = pane.getTotalHeight();
if(maxHeight <= 0 || maxHeight < viewportHeight) {
maxHeight = viewportHeight;
}
int handleSize = minHandleSize;
if(maxHeight > 0) {
handleSize = (int) (((float)viewportHeight / (float) maxHeight) * (float)viewportHeight);
}
if(handleSize < minHandleSize) {
handleSize = minHandleSize;
}
if(handleSize > maxHeight) {
handleSize = maxHeight;
}
return handleSize - (BUTTON_ENDS_SIZE * 2);
}
}
return minHandleSize;
}
protected void fireScrollBarEvent(ScrollBarEvent event) {
this.getEventDispatcher().sendNow(event);
}
/**
* @return the top
*/
public Button getTopButton() {
return top;
}
/**
* @return the bottom
*/
public Button getBottomButton() {
return bottom;
}
/**
* @return the handle
*/
public Button getHandleButton() {
return handle;
}
}
| 14,448 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Label.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/Label.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
import seventh.client.gfx.Theme;
/**
* A Simple text label.
*
* @author Tony
*
*/
public class Label extends Widget {
/**
* Text alignment.
*
* @author Tony
*
*/
public enum TextAlignment {
CENTER
, LEFT
, RIGHT
, TOP
, BOTTOM
}
/**
* Text alignment
*/
private TextAlignment horizontalTextAlignment;
private TextAlignment verticalTextAlignment;
/**
* The text on the label
*/
private String text;
private String font;
/**
* Text size
*/
private float textSize;
/**
* Ignore carriage return
*/
private boolean ignoreCR;
private boolean shadow;
private boolean colorEncoding;
private boolean monospaced;
/**
* @param text
*/
public Label(String text) {
this.text = text;
this.textSize = 12;
this.ignoreCR = true;
this.shadow = true;
this.colorEncoding = true;
this.monospaced = false;
this.horizontalTextAlignment = TextAlignment.CENTER;
this.verticalTextAlignment = TextAlignment.CENTER;
this.font = Theme.DEFAULT_FONT;
}
/**
*/
public Label() {
this("");
}
/**
* @return the font
*/
public String getFont() {
return font;
}
/**
* @param font the font to set
*/
public void setFont(String font) {
this.font = font;
}
/**
* @return the text
*/
public String getText() {
return text;
}
/**
* @param text the text to set
*/
public void setText(String text) {
this.text = text;
}
/**
* @return the textSize
*/
public float getTextSize() {
return textSize;
}
/**
* @param textSize the textSize to set
*/
public void setTextSize(float textSize) {
this.textSize = textSize;
}
/**
* @param colorEncoding the colorEncoding to set
*/
public void setColorEncoding(boolean colorEncoding) {
this.colorEncoding = colorEncoding;
}
/**
* @return the monospaced
*/
public boolean isMonospaced() {
return monospaced;
}
/**
* @param monospaced the monospaced to set
*/
public void setMonospaced(boolean monospaced) {
this.monospaced = monospaced;
}
/**
* @return the colorEncoding
*/
public boolean isColorEncoding() {
return colorEncoding;
}
/**
* @return the shadow
*/
public boolean isShadowed() {
return shadow;
}
/**
* @param shadow the shadow to set
*/
public void setShadow(boolean shadow) {
this.shadow = shadow;
}
/**
* @return the ignoreCR
*/
public boolean ignoreCR() {
return ignoreCR;
}
/**
* @param ignoreCR the ignoreCR to set
*/
public void setIgnoreCR(boolean ignoreCR) {
this.ignoreCR = ignoreCR;
}
/**
* @param horizontalTextAlignment the horizontalTextAlignment to set
*/
public void setHorizontalTextAlignment(TextAlignment textAlignment) {
this.horizontalTextAlignment = textAlignment;
}
/**
* @return the horizontalTextAlignment
*/
public TextAlignment getHorizontalTextAlignment() {
return horizontalTextAlignment;
}
/**
* @param verticalTextAlignment the verticalTextAlignment to set
*/
public void setVerticalTextAlignment(TextAlignment verticalTextAlignment) {
this.verticalTextAlignment = verticalTextAlignment;
}
/**
* @return the verticalTextAlignment
*/
public TextAlignment getVerticalTextAlignment() {
return verticalTextAlignment;
}
}
| 5,497 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Slider.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/Slider.java | /*
* see license.txt
*/
package seventh.ui;
import seventh.client.gfx.Theme;
import seventh.client.inputs.Inputs;
import seventh.client.sfx.Sounds;
import seventh.math.Rectangle;
import seventh.shared.EventDispatcher;
import seventh.ui.events.HoverEvent;
import seventh.ui.events.OnSliderMovedListener;
import seventh.ui.events.SliderMovedEvent;
/**
* @author Tony
*
*/
public class Slider extends Widget implements Hoverable {
private static final int MAX_INDEX = 100;
private int index;
private int heldX;
private Button handle;
private boolean isHandleHeld;
private boolean isHovering;
private SliderMovedEvent event;
private Rectangle sliderHitbox;
/**
* @param eventDispatcher
*/
public Slider(EventDispatcher eventDispatcher) {
super(eventDispatcher);
this.event = new SliderMovedEvent(this, this);
this.handle = new Button(eventDispatcher);
this.handle.getBounds().setSize(15, 18);
this.handle.getBounds().setLocation(0, -7);
this.sliderHitbox = new Rectangle();
moveHandle(0);
addWidget(handle);
addInputListener(new Inputs() {
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
isHandleHeld = false;
heldX = 0;
return false;
}
@Override
public boolean touchDragged(int x, int y, int pointer) {
if(isHandleHeld) {
moveHandleTo(x);
return true;
}
return false;
}
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
if (handle.getScreenBounds().contains(x, y)) {
isHandleHeld = true;
heldX = Math.max(x - handle.getBounds().x - getBounds().x, 0);
return true;
}
else {
sliderHitbox.set(getScreenBounds());
sliderHitbox.height *= 4;
sliderHitbox.y -= (getScreenBounds().height * 2);
if(sliderHitbox.contains(x, y)) {
moveHandleTo(x);
return true;
}
}
return false;
}
@Override
public boolean mouseMoved(int x, int y) {
super.mouseMoved(x, y);
if ( !isDisabled() ) {
if ( getScreenBounds().contains(x, y) ) {
setHovering(true);
return false;
}
}
setHovering(false);
return false;
}
});
}
/**
*
*/
public Slider() {
this(new EventDispatcher());
}
public void addSliderMoveListener(OnSliderMovedListener l) {
getEventDispatcher().addEventListener(SliderMovedEvent.class, l);
}
public void removeSliderMoveListener(OnSliderMovedListener l) {
getEventDispatcher().removeEventListener(SliderMovedEvent.class, l);
}
/**
* @param isHovering the isHovering to set
*/
private void setHovering(boolean isHovering) {
if(isHovering) {
if(!this.isHovering) {
Sounds.playGlobalSound(Sounds.uiHover);
getEventDispatcher().sendNow(new HoverEvent(this, this, isHovering));
}
}
else {
if(this.isHovering) {
getEventDispatcher().sendNow(new HoverEvent(this, this, isHovering));
}
}
this.isHovering = isHovering;
}
/**
* @return the isHovering
*/
@Override
public boolean isHovering() {
return isHovering;
}
/* (non-Javadoc)
* @see seventh.ui.Widget#setTheme(seventh.client.gfx.Theme)
*/
@Override
public void setTheme(Theme theme) {
super.setTheme(theme);
this.handle.setBackgroundColor(theme.getBackgroundColor());
}
/**
* @return the handle
*/
public Button getHandle() {
return handle;
}
private void moveHandleTo(int x) {
int maxX = getBounds().x + getBounds().width;// - handle.getBounds().width/2;
int minX = getBounds().x;
int newIndex = (x - minX) - heldX;
if(x <= maxX && x >= minX) {
handle.getBounds().x = newIndex;
}
if(newIndex >= 0 && newIndex <= MAX_INDEX) {
index = newIndex;
getEventDispatcher().sendNow(event);
}
}
/**
* @return the index
*/
public int getIndex() {
return index;
}
/**
* Moves the index value
* @param index
*/
public void moveHandle(int index) {
if(index > MAX_INDEX) {
index = MAX_INDEX;
}
else if(index < 0) {
index = 0;
}
// int width = getBounds().width - handle.getBounds().width;
float percentage = (float)index / (float)MAX_INDEX;
float x = getBounds().width * percentage;
moveHandleTo( getBounds().x + (int)x );
}
}
| 5,690 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Dialog.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/Dialog.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
import seventh.math.Rectangle;
/**
* A simple dialog box
*
* @author Tony
*
*/
public class Dialog extends Widget {
/**
* The text message
*/
private Label text;
/**
* @param eventDispatcher
* @param text
*/
public Dialog(String text) {
this.text = new Label(text);
addWidget(this.text);
}
/**
*
*/
public Dialog() {
this("");
}
/*
* (non-Javadoc)
* @see com.fived.ricochet.ui.Widget#setBounds(org.myriad.shared.math.Rectangle)
*/
@Override
public void setBounds(Rectangle bounds) {
super.setBounds(bounds);
this.text.getBounds().width = bounds.width;
this.text.getBounds().height = bounds.height;
}
/**
*
* @return the text label
*/
public Label getTextLabel() {
return this.text;
}
/**
* @return the text
*/
public String getText() {
return text.getText();
}
/**
* @param text the text to set
*/
public void setText(String text) {
this.text.setText(text);
}
}
| 2,753 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Panel.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/Panel.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
/**
* A {@link Panel} is just a means for grouping widgets together.
* @author Tony
*
*/
public class Panel extends Widget {
}
| 1,732 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Button.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/Button.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
import seventh.client.gfx.Theme;
import seventh.client.inputs.Inputs;
import seventh.client.sfx.Sounds;
import seventh.math.Rectangle;
import seventh.shared.EventDispatcher;
import seventh.ui.events.ButtonEvent;
import seventh.ui.events.HoverEvent;
import seventh.ui.events.OnButtonClickedListener;
/**
* A simple button for actions.
*
* @author Tony
*
*/
public class Button extends Widget implements Hoverable {
/**
* Text on the button if
* any.
*/
private Label label;
/**
* If the button is being pressed.
*/
private boolean isPressed;
/**
* If we are hovering over the
* button
*/
private boolean isHovering;
private float hoverTextSize;
private float normalTextSize;
private boolean border;
/**
* Button event to reuse for
* this button.
*/
private ButtonEvent buttonEvent;
/**
* @param eventDispatcher
*/
public Button(EventDispatcher eventDispatcher) {
super(eventDispatcher);
this.label = new Label();
addWidget(this.label);
this.normalTextSize = 28;
this.hoverTextSize = 34;
this.label.setTextSize(28);
this.border = true;
this.buttonEvent = new ButtonEvent(this, this);
addInputListener(new Inputs() {
/* (non-Javadoc)
* @see seventh.client.Inputs#mouseMoved(int, int)
*/
@Override
public boolean mouseMoved(int x, int y) {
super.mouseMoved(x, y);
if ( !isDisabled() ) {
if ( getScreenBounds().contains(x, y) ) {
setHovering(true);
return false;
}
}
setHovering(false);
return false;
}
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
if ( !isDisabled() ) {
if ( getScreenBounds().contains(x, y) ) {
setPressed(true);
click();
return true;
}
}
setPressed(false);
return false;
}
/* (non-Javadoc)
* @see seventh.client.Inputs#touchDown(int, int, int, int)
*/
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
setPressed(false);
if ( !isDisabled() ) {
if ( getScreenBounds().contains(x, y) ) {
return true;
}
}
return false;
}
});
}
/**
*/
public Button() {
this(new EventDispatcher());
}
/**
* Adds a listener
* @param l
*/
public void addOnButtonClickedListener(OnButtonClickedListener l) {
this.getEventDispatcher().addEventListener(ButtonEvent.class, l);
}
/**
* Removes a listener
* @param l
*/
public void removeOnButtonClickedListener(OnButtonClickedListener l) {
this.getEventDispatcher().removeEventListener(ButtonEvent.class, l);
}
/**
* @param border the border to set
*/
public void setBorder(boolean border) {
this.border = border;
}
/**
* @return true if there is a border
*/
public boolean hasBorder() {
return this.border;
}
/*
* (non-Javadoc)
* @see com.fived.ricochet.ui.Widget#setBounds(org.myriad.shared.math.Rectangle)
*/
@Override
public void setBounds(Rectangle bounds) {
super.setBounds(bounds);
this.label.getBounds().width = bounds.width;
this.label.getBounds().height = bounds.height;
}
/* (non-Javadoc)
* @see seventh.ui.Widget#setTheme(seventh.client.gfx.Theme)
*/
@Override
public void setTheme(Theme theme) {
super.setTheme(theme);
if(theme != null) {
label.setFont(theme.getPrimaryFontName());
}
}
/**
* @return the text label
*/
public Label getTextLabel() {
return this.label;
}
/**
* @return the text
*/
public String getText() {
return this.label.getText();
}
/**
* @param text the text to set
*/
public void setText(String text) {
this.label.setText(text);
}
public void setTextSize(float size) {
this.label.setTextSize(size);
this.normalTextSize = size;
}
public void setHoverTextSize(float size) {
this.hoverTextSize = size;
}
/**
* @return the isPressed
*/
public boolean isPressed() {
return isPressed;
}
/**
* Set if the button was pressed.
* @param pressed
*/
private void setPressed(boolean pressed) {
if ( pressed ) {
this.label.getBounds().y = 5;
if(!this.isPressed) {
Sounds.playGlobalSound(Sounds.uiSelect);
}
}
else {
this.label.getBounds().y = 0;
}
this.isPressed = pressed;
}
/**
* @param isHovering the isHovering to set
*/
public void setHovering(boolean isHovering) {
if(isHovering) {
this.label.setTextSize(this.hoverTextSize);
Theme theme = getTheme();
if(theme != null) {
this.label.setForegroundColor(theme.getHoverColor());
}
if(!this.isHovering) {
Sounds.playGlobalSound(Sounds.uiHover);
getEventDispatcher().sendNow(new HoverEvent(this, this, isHovering));
}
}
else {
this.label.setTextSize(this.normalTextSize);
Theme theme = getTheme();
if(theme != null) {
this.label.setForegroundColor(theme.getForegroundColor());
}
// we stopped hovering
if(this.isHovering) {
getEventDispatcher().sendNow(new HoverEvent(this, this, isHovering));
}
}
this.isHovering = isHovering;
}
/**
* @return the isHovering
*/
@Override
public boolean isHovering() {
return isHovering;
}
/**
* Click the button.
*/
public void click() {
this.getEventDispatcher().sendNow(this.buttonEvent);
}
}
| 8,847 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
UserInterfaceManager.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/UserInterfaceManager.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
import java.util.List;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.CompoundCursor;
import seventh.client.gfx.Cursor;
import seventh.client.gfx.ImageCursor;
import seventh.client.gfx.ReticleCursor;
import seventh.client.inputs.Inputs;
import seventh.shared.EventDispatcher;
import seventh.shared.TimeStep;
/**
* Use the {@link UserInterfaceManager} to add any {@link Widget}s and register them to the
* designated {@link EventDispatcher} and delegates user input to each component.
*
* @author Tony
*
*/
public class UserInterfaceManager extends Inputs {
/**
* Widgets
*/
private List<Widget> widgets;
private CompoundCursor cursor;
public UserInterfaceManager(UserInterfaceManager parent) {
this.cursor = parent.getCursor();
this.widgets = parent.widgets;
}
/**
* @param eventDispatcher
*/
public UserInterfaceManager() {
this.cursor = new CompoundCursor(new ImageCursor().setImageOffset(4, 4),
new ReticleCursor());
// pretty big hack, should be passed in a cleaner
// manner
this.widgets = Widget.globalInputListener.getGlobalWidgets();
Widget.globalInputListener.cursor = this.cursor;
}
public Cursor menuCursor() {
return this.cursor.activateA().getActive();
}
public Cursor gameCursor() {
return this.cursor.activateB().getActive();
}
public void hideMouse() {
this.cursor.setVisible(false);
}
public void showMouse() {
this.cursor.setVisible(true);
}
/**
* @return the cursor
*/
public CompoundCursor getCursor() {
return cursor;
}
/**
* @param cursor the cursor to set
*/
public void setCursor(CompoundCursor cursor) {
this.cursor = cursor;
}
/**
* Destroys the widgets
*/
public void destroy() {
Widget.globalInputListener.destroy();
}
/**
* Checks to see if the {@link Cursor} is hovering over
* any {@link Widget}s
*/
public void checkIfCursorIsHovering() {
/*boolean isHovering = false;
int size = this.widgets.size();
for(int i = 0; i < size; i++) {
Widget w = this.widgets.get(i);
if(w instanceof Hoverable && !w.isDisabled()) {
Hoverable h = (Hoverable)w;
if(h.isHovering()) {
isHovering = true;
break;
}
}
}
getCursor().setColor(isHovering ? 0xafff0000 : 0xafffff00);*/
}
/* (non-Javadoc)
* @see seventh.client.Inputs#keyDown(int)
*/
@Override
public boolean keyDown(int key) {
return Widget.globalInputListener.keyDown(key);
}
/* (non-Javadoc)
* @see seventh.client.Inputs#keyUp(int)
*/
@Override
public boolean keyUp(int key) {
return Widget.globalInputListener.keyUp(key);
}
/* (non-Javadoc)
* @see seventh.client.Inputs#mouseMoved(int, int)
*/
@Override
public boolean mouseMoved(int x, int y) {
cursor.moveTo(x, y);
return Widget.globalInputListener.mouseMoved(cursor.getX(), cursor.getY());
}
/* (non-Javadoc)
* @see seventh.client.Inputs#touchDown(int, int, int, int)
*/
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
return Widget.globalInputListener.touchDown(cursor.getX(), cursor.getY(), pointer, button);
}
/* (non-Javadoc)
* @see seventh.client.Inputs#touchUp(int, int, int, int)
*/
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
return Widget.globalInputListener.touchUp(cursor.getX(), cursor.getY(), pointer, button);
}
/* (non-Javadoc)
* @see seventh.client.Inputs#keyTyped(char)
*/
@Override
public boolean keyTyped(char key) {
return Widget.globalInputListener.keyTyped(key);
}
/* (non-Javadoc)
* @see seventh.client.Inputs#scrolled(int)
*/
@Override
public boolean scrolled(int amount) {
return Widget.globalInputListener.scrolled(amount);
}
/* (non-Javadoc)
* @see seventh.client.Inputs#touchDragged(int, int, int)
*/
@Override
public boolean touchDragged(int x, int y, int pointer) {
cursor.moveTo(x, y);
return Widget.globalInputListener.touchDragged(cursor.getX(), cursor.getY(), pointer);
}
/* (non-Javadoc)
* @see org.myriad.render.Renderable#render(org.myriad.render.Renderer, org.myriad.render.Camera, org.myriad.core.TimeUnit)
*/
public void render(Canvas canvas) {
this.cursor.render(canvas);
}
/* (non-Javadoc)
* @see org.myriad.render.Renderable#update(org.myriad.core.TimeStep)
*/
public void update(TimeStep timeStep) {
this.cursor.update(timeStep);
}
}
| 6,662 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ImagePanel.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/ImagePanel.java | /*
* see license.txt
*/
package seventh.ui;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
/**
* @author Tony
*
*/
public class ImagePanel extends Panel {
private TextureRegion image;
public ImagePanel(TextureRegion image) {
this.image = image;
}
/**
* @return the image
*/
public TextureRegion getImage() {
return image;
}
/**
* @param image the image to set
*/
public void setImage(TextureRegion image) {
this.image = image;
}
}
| 541 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Styling.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/Styling.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
/**
* UI Styling.
*
* @author Tony
*
*/
public interface Styling {
public static final int BLACK = 0xFF000000;
public static final int WHITE = 0xFFffFFff;
public static final int RED = 0xFFff0000;
/**
* Styles a button.
*
* @param button
*/
public void styleButton(Button button);
/**
* Styles a Dialog
*
* @param dialog
*/
public void styleDialog(Dialog dialog);
}
| 2,053 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
MessageBoard.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/MessageBoard.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
import seventh.shared.TimeStep;
/**
* Displays informative messages to the user. The messages are placed on
* a queue and displayed one message at a time. A message is popped off the
* queue once it expires.
*
* @author Tony
*
*/
public class MessageBoard extends Widget {
/**
* Messages on the board
*/
private Queue<Message> messages;
/**
* Text Size
*/
private float textSize;
/**
* Cache messages
*/
// private ObjectPool<Message> msgPool;
/**
* Message
*
* @author Tony
*
*/
public static class Message {
public static final int FLICKER_EFFECT = (1 << 1);
public static final int FADE_EFFECT = (1 << 2);
String message;
long expire;
int effect;
void reset(String message, long expire, int effect) {
this.message = message;
this.expire = expire;
this.effect = effect;
}
/**
* @return the message
*/
public String getMessage() {
return message;
}
/**
* @return the expire
*/
public long getExpire() {
return expire;
}
/**
* @return the effect
*/
public int getEffect() {
return effect;
}
}
/**
* Size of the message board
* @param messageBoardSize
*/
public MessageBoard(int messageBoardSize) {
this.messages = new LinkedList<Message>();
this.textSize = 12.0f;
// this.msgPool = new ObjectPool<Message>(new ObjectFactory<Message>() {
// public Message create() {
// return new Message();
// }
// }, messageBoardSize);
this.setForegroundColor(Styling.BLACK);
}
/**
* Updates the message board, removes any expired messages.
*
* @param timeStep
*/
public void update(TimeStep timeStep) {
if ( !this.messages.isEmpty() ) {
// determine if the message has expired.
Message msg = this.messages.peek();
msg.expire -= timeStep.getDeltaTime();
if ( msg.expire <= 0) {
this.messages.poll();
// this.msgPool.destroy(msg);
}
}
}
/**
* @return the textSize
*/
public float getTextSize() {
return textSize;
}
/**
* @param textSize the textSize to set
*/
public void setTextSize(float textSize) {
this.textSize = textSize;
}
/**
* Clears the message board
*/
public void clearMessages() {
// while(!this.messages.isEmpty()) {
// Message msg = this.messages.poll();
// this.msgPool.destroy(msg);
// }
this.messages.clear();
}
/**
* Adds a message to the board, which will expire.
*
* @param message
* @param expire
*/
public void addMessage(String message, TimeUnit expire) {
addMessage(message, expire);
}
/**
* Adds a message to the board, which will expire.
*
* @param message
* @param expire
* @param effect
*/
public void addMessage(String message, long expire, int effect) {
Message msg = new Message(); //this.msgPool.create();
if ( msg != null ) {
msg.reset(message, expire, effect);
this.messages.add(msg);
}
}
/**
* Gets the messages
*
* @return maybe null if no message is posted
*/
public Message getCurrentMessage() {
return this.messages.peek();
}
}
| 5,583 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ProgressBar.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/ProgressBar.java | /**
*
*/
package seventh.ui;
import seventh.shared.EventDispatcher;
/**
* A progress bar
*
* @author Tony
*
*/
public class ProgressBar extends Widget {
public static final int MAX_PROGRESS = 100;
private int progress;
public ProgressBar() {
this(new EventDispatcher());
}
/**
* @param eventDispatcher
*/
public ProgressBar(EventDispatcher eventDispatcher) {
super(eventDispatcher);
}
/**
* The progress is from a scale of 0-100
*
* @param progress the progress to set
*/
public void setProgress(int progress) {
this.progress = progress;
if(this.progress < 0) {
this.progress = 0;
}
if(this.progress > MAX_PROGRESS) {
this.progress = MAX_PROGRESS;
}
}
/**
* @return the progress
*/
public int getProgress() {
return progress;
}
/**
* @return the percentage completed
*/
public float getPercentCompleted() {
return (float)progress / (float)MAX_PROGRESS;
}
}
| 1,101 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Checkbox.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/Checkbox.java | /*
* see license.txt
*/
package seventh.ui;
import seventh.client.gfx.Theme;
import seventh.client.inputs.Inputs;
import seventh.client.sfx.Sounds;
import seventh.shared.EventDispatcher;
import seventh.ui.Label.TextAlignment;
import seventh.ui.events.CheckboxEvent;
import seventh.ui.events.HoverEvent;
import seventh.ui.events.OnCheckboxClickedListener;
/**
* @author Tony
*
*/
public class Checkbox extends Widget implements Hoverable {
private boolean isHovering;
private boolean isChecked;
private Label label;
/**
* @param eventDispatcher
*/
public Checkbox(boolean isChecked, EventDispatcher eventDispatcher) {
super(eventDispatcher);
getBounds().setSize(18, 18);
this.isChecked = isChecked;
this.label = new Label();
this.label.getBounds().add(getBounds().width + 8, getBounds().height - 5);
this.label.setHorizontalTextAlignment(TextAlignment.LEFT);
addWidget(label);
addInputListener(new Inputs() {
@Override
public boolean mouseMoved(int x, int y) {
super.mouseMoved(x, y);
if ( !isDisabled() ) {
if ( getScreenBounds().contains(x, y)) {
setHovering(true);
return false;
}
}
setHovering(false);
return false;
}
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
if(getScreenBounds().contains(x, y)) {
setChecked(!isChecked() );
return true;
}
return false;
}
});
}
/**
*
*/
public Checkbox(boolean isChecked) {
this(isChecked, new EventDispatcher());
}
/* (non-Javadoc)
* @see seventh.ui.Widget#setTheme(seventh.client.gfx.Theme)
*/
@Override
public void setTheme(Theme theme) {
super.setTheme(theme);
label.setFont(theme.getSecondaryFontName());
label.setTextSize(14);
}
public void addCheckboxClickedListener(OnCheckboxClickedListener l) {
getEventDispatcher().addEventListener(CheckboxEvent.class, l);
}
public void removeCheckboxClickedListener(OnCheckboxClickedListener l) {
getEventDispatcher().removeEventListener(CheckboxEvent.class, l);
}
/**
* @param isHovering the isHovering to set
*/
private void setHovering(boolean isHovering) {
if(isHovering) {
if(!this.isHovering) {
Sounds.playGlobalSound(Sounds.uiHover);
getEventDispatcher().sendNow(new HoverEvent(this, this, isHovering));
}
}
else {
if(this.isHovering) {
getEventDispatcher().sendNow(new HoverEvent(this, this, isHovering));
}
}
this.isHovering = isHovering;
}
/**
* @return the isHovering
*/
@Override
public boolean isHovering() {
return isHovering;
}
/**
* @return the isChecked
*/
public boolean isChecked() {
return isChecked;
}
/**
* @param isChecked the isChecked to set
*/
public void setChecked(boolean isChecked) {
this.isChecked = isChecked;
Sounds.playGlobalSound(Sounds.uiSelect);
getEventDispatcher().sendNow(new CheckboxEvent(this, this));
}
/**
* @return the label
*/
public Label getLabel() {
return label;
}
/**
* Sets the label text
* @param text
*/
public void setLabelText(String text) {
this.label.setText(text);
}
}
| 4,042 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
DefaultStyling.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/DefaultStyling.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
/**
* Creates a default {@link Styling}.
*
* @author Tony
*
*/
public class DefaultStyling implements Styling {
/**
* Background color
*/
private static final int BACKGROUND_COLOR = BLACK;//new Vector3f(0.5f, 0.0f, 0.05f);
/* (non-Javadoc)
* @see com.fived.ricochet.ui.Styling#styleButton(com.fived.ricochet.ui.Button)
*/
public void styleButton(Button button) {
button.setBackgroundColor(RED);
button.setBackgroundAlpha(80);
button.setGradiantColor(BLACK);
button.setEnableGradiant(true);
}
/* (non-Javadoc)
* @see com.fived.ricochet.ui.Styling#styleDialog(com.fived.ricochet.ui.Dialog)
*/
public void styleDialog(Dialog dialog) {
// dialog.setBackgroundColor(BACKGROUND_COLOR);
// dialog.setBackgroundAlpha(0.35f);
// dialog.setForegroundColor(Renderer.WHITE);
dialog.setBackgroundColor(BACKGROUND_COLOR);
dialog.setBackgroundAlpha(1);
dialog.setForegroundColor(WHITE);
for( Widget widget: dialog.getWidgets()) {
if ( widget instanceof Button ) {
styleButton((Button)widget);
}
}
}
}
| 2,848 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Hoverable.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/Hoverable.java | /*
* see license.txt
*/
package seventh.ui;
import seventh.client.gfx.Cursor;
/**
* If the {@link Widget} can be hovered over by the {@link Cursor}
*
* @author Tony
*
*/
public interface Hoverable {
/**
* If the {@link Cursor} is hovering over this {@link Widget}
*
* @return true if the {@link Cursor} is hovering over this {@link Widget}
*/
public boolean isHovering();
}
| 415 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
SystemStyles.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/SystemStyles.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
/**
* Predefined styles.
*
* @author Tony
*
*/
public class SystemStyles {
/**
* Default style
*/
public static final Styling DEFAULT_STYLE = new DefaultStyling();
}
| 1,784 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
KeyInput.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/KeyInput.java | /*
* see license.txt
*/
package seventh.ui;
import com.badlogic.gdx.Input.Keys;
import seventh.client.inputs.Inputs;
import seventh.shared.EventDispatcher;
/**
* @author Tony
*
*/
public class KeyInput extends Widget {
private int key;
private String keymap;
private boolean isDone, isCancelled;
/**
* @param eventDispatcher
*/
public KeyInput(EventDispatcher eventDispatcher) {
super(eventDispatcher);
reset();
addInputListener(new Inputs() {
/* (non-Javadoc)
* @see seventh.client.Inputs#keyDown(int)
*/
@Override
public boolean keyDown(int k) {
if(isDisabled()) {
return false;
}
if(k == Keys.ESCAPE) {
isCancelled = true;
return true;
}
super.keyDown(k);
key = k;
return true;
}
/* (non-Javadoc)
* @see seventh.client.Inputs#keyUp(int)
*/
@Override
public boolean keyUp(int k) {
if(isDisabled()) {
return false;
}
super.keyUp(k);
isDone = true;
return true;
}
/* (non-Javadoc)
* @see seventh.client.Inputs#mouseMoved(int, int)
*/
@Override
public boolean mouseMoved(int x, int y) {
return true;
}
/* (non-Javadoc)
* @see seventh.client.Inputs#touchDragged(int, int, int)
*/
@Override
public boolean touchDragged(int x, int y, int pointer) {
return true;
}
/* (non-Javadoc)
* @see seventh.client.Inputs#touchUp(int, int, int, int)
*/
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
if(isDisabled()) {
return false;
}
if (!super.touchUp(x, y, pointer, button) ) {
isDone = true;
}
return true;
}
/* (non-Javadoc)
* @see seventh.client.Inputs#touchDown(int, int, int, int)
*/
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
if(isDisabled()) {
return false;
}
key = button;
super.touchDown(x, y, pointer, button);
return true;
}
});
}
/**
*
*/
public KeyInput() {
this(new EventDispatcher());
}
public void reset() {
this.isCancelled = false;
this.isDone = false;
this.key = -1;
this.keymap = null;
}
/**
* @param keymap the keymap to set
*/
public void setKeymap(String keymap) {
this.keymap = keymap;
}
/**
* @return the keymap
*/
public String getKeymap() {
return keymap;
}
/**
* @return the isCancelled
*/
public boolean isCancelled() {
return isCancelled;
}
/**
* @return the isDone
*/
public boolean isDone() {
return isDone;
}
/**
* @return the key
*/
public int getKey() {
return key;
}
}
| 3,830 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Scrollable.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/Scrollable.java | /*
* see license.txt
*/
package seventh.ui;
import seventh.math.Rectangle;
/**
* @author Tony
*
*/
public interface Scrollable {
Rectangle getViewport();
int getTotalHeight();
int getTotalWidth();
}
| 220 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Widget.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/Widget.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import seventh.client.gfx.Cursor;
import seventh.client.gfx.Theme;
import seventh.client.inputs.Inputs;
import seventh.math.Rectangle;
import seventh.math.Vector2f;
import seventh.shared.EventDispatcher;
import seventh.ui.events.HoverEvent;
import seventh.ui.events.OnHoverListener;
/**
* The bases for all widgets.
*
* @author Tony
*
*/
public class Widget {
/**
* The global input listener
*/
static WidgetInputListener globalInputListener = new WidgetInputListener();
/**
* Id Generator
*/
private static AtomicInteger idGenerator = new AtomicInteger();
/**
* Contains the widget bounds
*/
private Rectangle bounds;
/**
* Color
*/
private int backgroundColor;
/**
* Foreground color
*/
private int foregroundColor;
/**
* Alpha
*/
private int backgroundAlpha;
/**
* Foreground alpha
*/
private int foregroundAlpha;
/**
* If this widget can listen to user input
*/
private boolean focus;
/**
* Event Dispatcher
*/
private EventDispatcher eventDispatcher;
/**
* Widgets
*/
private List<Widget> widgets;
/**
* Key Listeners
*/
private List<Inputs> inputListeners;
/**
* Disable
*/
private boolean disabled;
/**
* Can this widget be seen
*/
private boolean visible;
/**
* Id
*/
private int id;
/**
* Name of this widget
*/
private String name;
/**
* Parent widget
*/
private Widget parent;
/**
* Screen position
*/
private Vector2f screenPosition;
/**
* Screen bounds
*/
private Rectangle screenBounds;
/**
* enable gradiant
*/
private boolean enableGradiant;
/**
* Gradiant color
*/
private int gradiantColor;
private int borderColor;
private int borderWidth;
/**
* The theme
*/
private Theme theme;
/**
* @param eventDispatcher
*/
public Widget(EventDispatcher eventDispatcher) {
this.eventDispatcher = eventDispatcher;
this.id = idGenerator.getAndIncrement();
this.bounds = new Rectangle();
this.backgroundColor = 0;
this.backgroundAlpha = 255;
this.foregroundColor = 0xffFFffFF;
this.foregroundAlpha = 255;
this.enableGradiant = true;
this.gradiantColor = 0xff999999;// new Vector3f(0.63f,0.63f,0.63f);
this.focus = true;
this.borderColor = 0;
this.borderWidth = 0;
this.screenPosition = new Vector2f();
this.screenBounds = new Rectangle();
this.widgets = new ArrayList<Widget>();
this.inputListeners = new ArrayList<Inputs>();
this.disabled = false;
this.visible = true;
this.parent = null;
this.name = "";
globalInputListener.addWidget(this);
}
public void setTheme(Theme theme) {
if(theme != null) {
setForegroundColor(theme.getForegroundColor());
setBackgroundColor(theme.getBackgroundColor());
this.theme = theme;
}
}
/**
* @return the theme
*/
public Theme getTheme() {
return theme;
}
/**
* @param eventDispatcher
*/
public Widget() {
this(new EventDispatcher());
}
/**
* @return the unique id for this widget
*/
public int getId() {
return this.id;
}
/**
* Destroy this {@link Widget}.
*/
public void destroy() {
destroyChildren();
this.parent = null;
this.inputListeners.clear();
globalInputListener.removeWidget(this);
}
/**
* Destroys the children widgets
*/
protected void destroyChildren() {
for(Widget w : this.widgets) {
w.destroy();
}
this.widgets.clear();
}
/**
* @return
*/
protected EventDispatcher getEventDispatcher() {
return this.eventDispatcher;
}
public void addInputListenerToFront(Inputs input) {
this.inputListeners.add(0, input);
}
public void addInputListener(Inputs input) {
this.inputListeners.add(input);
}
public void removeInputListener(Inputs input) {
this.inputListeners.remove(input);
}
public void addOnHoverListener(OnHoverListener l) {
getEventDispatcher().addEventListener(HoverEvent.class, l);
}
/**
* Fire a {@link KeyEvent}
* @param keyEvent
* @param isPressed
* @return true if the event was consumed
*/
protected boolean fireKeyTypedEvent(char keyEvent) {
int size = this.inputListeners.size();
boolean isConsumed = false;
for(int i = 0; i < size; i++ ) {
Inputs l = this.inputListeners.get(i);
isConsumed = l.keyTyped(keyEvent);
/* is the event done with? */
if ( isConsumed ) {
return true;
}
}
return false;
}
/**
* Fire a {@link KeyEvent}
* @param keyEvent
* @param isPressed
* @return true if the event was consumed
*/
protected boolean fireKeyEvent(int keyEvent, boolean isPressed) {
int size = this.inputListeners.size();
boolean isConsumed = false;
for(int i = 0; i < size; i++ ) {
Inputs l = this.inputListeners.get(i);
if ( isPressed ) {
isConsumed = l.keyDown(keyEvent);
}
else {
isConsumed = l.keyUp(keyEvent);
}
/* is the event done with? */
if ( isConsumed ) {
return true;
}
}
return false;
}
/**
* Fire a {@link MouseEvent}
* @param mouseEvent
* @param isPressed
* @return true if the event was consumed
*/
protected boolean fireMouseEvent(int mx, int my, int pointer, int mouseEvent, boolean isPressed) {
int size = this.inputListeners.size();
boolean isConsumed = false;
for(int i = 0; i < size; i++ ) {
Inputs l = this.inputListeners.get(i);
if ( isPressed ) {
isConsumed = l.touchDown(mx, my, pointer, mouseEvent);
}
else {
isConsumed = l.touchUp(mx, my, pointer, mouseEvent);
}
/* is the event done with? */
if ( isConsumed ) {
return true;
}
}
return false;
}
/**
* Fire a {@link MouseEvent}
* @param mouseEvent
* @param isPressed
* @return true if the event was consumed
*/
protected boolean fireMouseMotionEvent(int mx, int my) {
int size = this.inputListeners.size();
for(int i = 0; i < size; i++ ) {
Inputs l = this.inputListeners.get(i);
/* is the event done with? */
if ( l.mouseMoved(mx, my) ) {
return true;
}
}
return false;
}
/**
* Fire a mouse scrolled event
* @param amount
* @return true if the event was consumed
*/
protected boolean fireMouseScrolledEvent(int amount) {
int size = this.inputListeners.size();
for(int i = 0; i < size; i++ ) {
Inputs l = this.inputListeners.get(i);
/* is the event done with? */
if ( l.scrolled(amount) ) {
return true;
}
}
return false;
}
/**
* Fire a touch dragged event
*
* @param mouseEvent
* @param isPressed
* @return true if the event was consumed
*/
protected boolean fireTouchDraggedEvent(int mx, int my, int btn) {
int size = this.inputListeners.size();
for(int i = 0; i < size; i++ ) {
Inputs l = this.inputListeners.get(i);
/* is the event done with? */
if ( l.touchDragged(mx, my, btn) ) {
return true;
}
}
return false;
}
/**
* @return the mouse {@link Cursor}
*/
public Cursor getCursor() {
return globalInputListener.cursor;
}
/**
* @return the parent
*/
public Widget getParent() {
return parent;
}
/**
* @param parent the parent to set
*/
public void setParent(Widget parent) {
this.parent = parent;
}
/**
* @return the focus
*/
public boolean hasFocus() {
return focus;
}
/**
* @param focus the focus to set
*/
public void setFocus(boolean focus) {
this.focus = focus;
}
/**
* @return the bounds - the bounds position is relative to the
* parent widgets bounds.
*/
public Rectangle getBounds() {
return bounds;
}
/**
* Get the screen coordinates.
* @return the screen position of this widget.
*/
public Vector2f getScreenPosition() {
/* Get the position of this widget */
this.screenPosition.set(this.bounds.x, this.bounds.y);
/* now get the position of the parent widgets */
for(Widget p = this.parent; p != null; p = p.getParent()) {
this.screenPosition.x += p.bounds.x;
this.screenPosition.y += p.bounds.y;
}
return this.screenPosition;
}
/**
* Get the screen coordinates with width and height of the Widget.
* @return
*/
public Rectangle getScreenBounds() {
this.screenBounds.set(getScreenPosition(), this.bounds.width, this.bounds.height);
return this.screenBounds;
}
/**
* @param bounds the bounds to set
*/
public void setBounds(Rectangle bounds) {
this.bounds = bounds;
}
/**
* @return the color
*/
public int getBackgroundColor() {
return backgroundColor;
}
/**
* @param color the color to set
*/
public void setBackgroundColor(int color) {
this.backgroundColor = color;
}
/**
* @return the alpha
*/
public int getBackgroundAlpha() {
return backgroundAlpha;
}
/**
* @param alpha the alpha to set
*/
public void setBackgroundAlpha(int alpha) {
this.backgroundAlpha = alpha;
}
/**
* @return the foregroundColor
*/
public int getForegroundColor() {
return foregroundColor;
}
/**
* @param foregroundColor the foregroundColor to set
*/
public void setForegroundColor(int foregroundColor) {
this.foregroundColor = foregroundColor;
}
/**
* @return the foregroundAlpha
*/
public int getForegroundAlpha() {
return foregroundAlpha;
}
/**
* @param foregroundAlpha the foregroundAlpha to set
*/
public void setForegroundAlpha(int foregroundAlpha) {
this.foregroundAlpha = foregroundAlpha;
}
/**
* @return the enableGradiant
*/
public boolean gradiantEnabled() {
return enableGradiant;
}
/**
* @param enableGradiant the enableGradiant to set
*/
public void setEnableGradiant(boolean enableGradiant) {
this.enableGradiant = enableGradiant;
}
/**
* @return the gradiantColor
*/
public int getGradiantColor() {
return gradiantColor;
}
/**
* @param gradiantColor the gradiantColor to set
*/
public void setGradiantColor(int gradiantColor) {
this.gradiantColor = gradiantColor;
}
/**
* @param w
*/
public void addWidget(Widget w) {
if ( w != null ) {
w.setParent(this);
this.widgets.add(w);
}
}
/**
* @param w
*/
public void removeWidget(Widget w) {
if ( w != null ) {
if ( this.widgets.remove(w) ) {
w.setParent(null);
}
}
}
/**
* @return
*/
public List<Widget> getWidgets() {
return this.widgets;
}
/**
* @return the disabled
*/
public boolean isDisabled() {
return disabled;
}
/**
* @param disabled the disabled to set
*/
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
/**
* @return the visable
*/
public boolean isVisible() {
return visible;
}
/**
* @param visable the visible to set
*/
public void setVisible(boolean visible) {
this.visible = visible;
}
/**
* @return the borderColor
*/
public int getBorderColor() {
return borderColor;
}
/**
* @param borderColor the borderColor to set
*/
public void setBorderColor(int borderColor) {
this.borderColor = borderColor;
}
/**
* @return the borderWidth
*/
public int getBorderWidth() {
return borderWidth;
}
/**
* @param borderWidth the borderWidth to set
*/
public void setBorderWidth(int borderWidth) {
this.borderWidth = borderWidth;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* Hide the button, disabling it.
*/
public void hide() {
setDisabled(true);
setVisible(false);
int size = this.widgets.size();
for(int i = 0; i < size; i++) {
this.widgets.get(i).hide();
}
}
/**
* Show the button, enabling it.
*/
public void show() {
setDisabled(false);
setVisible(true);
int size = this.widgets.size();
for(int i = 0; i < size; i++) {
this.widgets.get(i).show();
}
}
/**
* Global Widget listener. This gets bound to the Myriad {@link InputSystem}
* @author Tony
*
*/
static class WidgetInputListener extends Inputs {
/**
* The mouse cursor
*/
public Cursor cursor;
/**
* Widgets
*/
private List<Widget> globalWidgets;
/**
* Are we destroying right now?
*/
private boolean isDestroying;
/**
*/
public WidgetInputListener() {
this.globalWidgets = new ArrayList<Widget>();
this.isDestroying = false;
}
/**
* Destroys the widgets
*/
public void destroy() {
this.isDestroying = true;
for(Widget w: this.globalWidgets) {
w.destroy();
}
this.globalWidgets.clear();
this.isDestroying = false;
}
/**
* @return the globalWidgets
*/
public List<Widget> getGlobalWidgets() {
return globalWidgets;
}
/**
* @param w
*/
public void addWidget(Widget w) {
this.globalWidgets.add(w);
}
/**
* @param w
*/
public void removeWidget(Widget w) {
// don't remove from this list if
// we are destroying all Widgets - avoids
// concurrent modification exception
if ( !this.isDestroying ) {
this.globalWidgets.remove(w);
}
}
/* (non-Javadoc)
* @see seventh.client.Inputs#keyTyped(char)
*/
@Override
public boolean keyTyped(char key) {
int size = globalWidgets.size();
for(int i = 0; i < size; i++) {
Widget widget = this.globalWidgets.get(i);
if ( widget.hasFocus() && !widget.isDisabled() ) {
if ( widget.fireKeyTypedEvent(key) ) {
return true;
}
}
}
return false;
}
/*
* (non-Javadoc)
* @see seventh.client.Inputs#keyDown(int)
*/
public boolean keyDown(int event) {
int size = globalWidgets.size();
for(int i = 0; i < size; i++) {
Widget widget = this.globalWidgets.get(i);
if ( widget.hasFocus() && !widget.isDisabled() ) {
if ( widget.fireKeyEvent(event, true) ) {
return true;
}
}
}
return false;
}
/* (non-Javadoc)
* @see org.myriad.input.KeyListener#keyReleased(org.myriad.input.KeyEvent)
*/
public boolean keyUp(int event) {
int size = globalWidgets.size();
for(int i = 0; i < size; i++) {
Widget widget = this.globalWidgets.get(i);
if ( widget.hasFocus() && !widget.isDisabled() ) {
if ( widget.fireKeyEvent(event, false) ) {
return true;
}
}
}
return false;
}
/* (non-Javadoc)
* @see seventh.client.Inputs#touchDown(int, int, int, int)
*/
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
int size = globalWidgets.size();
for(int i = 0; i < size; i++) {
Widget widget = this.globalWidgets.get(i);
if ( /*widget.hasFocus() &&*/ !widget.isDisabled() ) {
if ( widget.fireMouseEvent(x, y, pointer, button, true) ) {
return true;
}
}
}
return false;
}
/* (non-Javadoc)
* @see org.myriad.input.MouseListener#mouseButtonReleased(org.myriad.input.MouseEvent)
*/
public boolean touchUp(int x, int y, int pointer, int button) {
int size = globalWidgets.size();
for(int i = 0; i < size; i++) {
Widget widget = this.globalWidgets.get(i);
if ( /*widget.hasFocus() &&*/ !widget.isDisabled() ) {
if ( widget.fireMouseEvent(x, y, pointer, button, false) ) {
return true;
}
}
}
return false;
}
/* (non-Javadoc)
* @see seventh.client.Inputs#touchDragged(int, int, int)
*/
@Override
public boolean touchDragged(int x, int y, int pointer) {
int size = globalWidgets.size();
for(int i = 0; i < size; i++) {
Widget widget = this.globalWidgets.get(i);
if ( /*widget.hasFocus() &&*/ ! widget.isDisabled() ) {
if ( widget.fireTouchDraggedEvent(x, y, pointer) ) {
return true;
}
}
}
return false;
}
/* (non-Javadoc)
* @see seventh.client.Inputs#mouseMoved(int, int)
*/
@Override
public boolean mouseMoved(int x, int y) {
int size = globalWidgets.size();
for(int i = 0; i < size; i++) {
Widget widget = this.globalWidgets.get(i);
if ( /*widget.hasFocus() &&*/ !widget.isDisabled() ) {
if ( widget.fireMouseMotionEvent(x, y) ) {
return true;
}
}
}
return false;
}
/* (non-Javadoc)
* @see seventh.client.Inputs#scrolled(int)
*/
@Override
public boolean scrolled(int amount) {
int size = globalWidgets.size();
for(int i = 0; i < size; i++) {
Widget widget = this.globalWidgets.get(i);
if ( /*widget.hasFocus() &&*/ !widget.isDisabled() ) {
if ( widget.fireMouseScrolledEvent(amount) ) {
return true;
}
}
}
return false;
}
}
}
| 22,775 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TextBox.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/TextBox.java | /*
* see license.txt
*/
package seventh.ui;
import java.util.ArrayList;
import java.util.List;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import seventh.client.gfx.Theme;
import seventh.client.inputs.Inputs;
import seventh.client.sfx.Sounds;
import seventh.shared.EventDispatcher;
import seventh.ui.Label.TextAlignment;
import seventh.ui.events.TextBoxActionEvent;
import seventh.ui.events.TextBoxActionListener;
/**
* A simple text box
*
* @author Tony
*
*/
public class TextBox extends Widget implements Hoverable {
private StringBuilder inputBuffer;
private int cursorIndex;
private boolean isCtrlDown;
private boolean isHovering;
private Label label;
private Label textLbl;
private int maxSize;
private List<TextBoxActionListener> textBoxActionListeners;
/**
* @param eventDispatcher
*/
public TextBox(EventDispatcher eventDispatcher) {
super(eventDispatcher);
this.textBoxActionListeners = new ArrayList<TextBoxActionListener>();
this.inputBuffer = new StringBuilder();
this.cursorIndex = 0;
this.isCtrlDown = false;
this.label = new Label();
this.label.setHorizontalTextAlignment(TextAlignment.LEFT);
// addWidget(label);
this.textLbl = new Label();
this.textLbl.setColorEncoding(false);
this.textLbl.setMonospaced(true);
this.textLbl.setHorizontalTextAlignment(TextAlignment.LEFT);
// addWidget(textLbl);
this.maxSize = 32;
addInputListener(new Inputs() {
@Override
public boolean mouseMoved(int x, int y) {
super.mouseMoved(x, y);
if (!isDisabled()) {
if (getScreenBounds().contains(x, y)) {
if(!hasFocus()) {
setHovering(true);
}
return false;
}
}
setHovering(false);
return false;
}
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
if (!isDisabled()) {
if (getScreenBounds().contains(x, y)) {
setFocus(true);
return false;
}
}
setFocus(false);
return false;
}
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
return super.touchUp(x, y, pointer, button);
}
public boolean keyDown(int key) {
if(isDisabled() || !hasFocus()) {
return false;
}
switch(key) {
case Keys.LEFT: {
cursorIndex--;
if(cursorIndex < 0) {
cursorIndex = 0;
}
break;
}
case Keys.RIGHT: {
cursorIndex++;
if(cursorIndex >= inputBuffer.length()) {
cursorIndex = inputBuffer.length();
}
break;
}
case Keys.HOME: {
cursorIndex = 0;
break;
}
case Keys.END: {
cursorIndex = inputBuffer.length();
break;
}
case Keys.CONTROL_LEFT:
case Keys.CONTROL_RIGHT:
isCtrlDown = true;
break;
case Keys.V:
if(isCtrlDown) {
String contents = Gdx.app.getClipboard().getContents();
if(contents != null) {
inputBuffer.insert(cursorIndex, contents);
setText(inputBuffer.toString());
}
}
break;
default: {
}
}
return true;
}
@Override
public boolean keyUp(int key) {
if(isDisabled() || !hasFocus()) {
return false;
}
switch(key) {
case Keys.CONTROL_LEFT:
case Keys.CONTROL_RIGHT:
isCtrlDown = false;
break;
default: {
}
}
return true;
}
@Override
public boolean keyTyped(char key) {
if(isDisabled() || !hasFocus()) {
return false;
}
switch(key) {
case /*Keys.BACKSPACE*/8: {
if(cursorIndex > 0) {
inputBuffer.deleteCharAt(--cursorIndex);
if(cursorIndex < 0) {
cursorIndex = 0;
}
}
Sounds.playGlobalSound(Sounds.uiKeyType);
break;
}
case /*Keys.FORWARD_DEL*/127: {
if(cursorIndex<inputBuffer.length()) {
inputBuffer.deleteCharAt(cursorIndex);
}
Sounds.playGlobalSound(Sounds.uiKeyType);
break;
}
case '\r':
case '\n': {
fireTextBoxActionEvent(new TextBoxActionEvent(this, TextBox.this));
break;
}
default: {
char c = key;
if(c > 31 && c < 127 && c != 96 && inputBuffer.length() < maxSize) {
inputBuffer.insert(cursorIndex, key);
cursorIndex++;
Sounds.playGlobalSound(Sounds.uiKeyType);
}
}
}
return true;
}
});
}
/**
*
*/
public TextBox() {
this(new EventDispatcher());
}
/* (non-Javadoc)
* @see seventh.ui.Widget#destroy()
*/
@Override
public void destroy() {
super.destroy();
this.label.destroy();
this.textLbl.destroy();
}
/**
* Distributes the {@link TextBoxActionEvent} to each listener
* @param event
*/
protected void fireTextBoxActionEvent(TextBoxActionEvent event) {
for(TextBoxActionListener l : this.textBoxActionListeners) {
l.onEnterPressed(event);
}
}
public void addTextBoxActionListener(TextBoxActionListener l) {
this.textBoxActionListeners.add(l);
}
public void removeTextBoxActionListener(TextBoxActionListener l) {
this.textBoxActionListeners.remove(l);
}
/**
* @param isHovering the isHovering to set
*/
private void setHovering(boolean isHovering) {
if(isHovering) {
if(!this.isHovering) {
Sounds.playGlobalSound(Sounds.uiHover);
}
}
this.isHovering = isHovering;
}
/**
* @return the isHovering
*/
@Override
public boolean isHovering() {
return isHovering;
}
/**
* @param maxSize the maxSize to set
*/
public void setMaxSize(int maxSize) {
this.maxSize = maxSize;
}
/**
* @return the maxSize
*/
public int getMaxSize() {
return maxSize;
}
/**
* @param text
*/
public void setText(String text) {
if(text.length() > maxSize) {
text = text.substring(0, maxSize);
}
this.inputBuffer.delete(0, this.inputBuffer.length());
this.inputBuffer.append(text);
this.cursorIndex = this.inputBuffer.length();
}
@Override
public void setFocus(boolean focus) {
super.setFocus(focus);
if(focus) {
Sounds.playGlobalSound(Sounds.uiSelect);
}
}
/**
* @return the text in the textbox
*/
public String getText() {
return this.inputBuffer.toString();
}
/**
* @return the label
*/
public Label getLabel() {
return label;
}
/**
* @return the textLbl
*/
public Label getTextLabel() {
textLbl.setText(getText());
return textLbl;
}
/**
* Sets the text of the label
* @param labelText
*/
public void setLabelText(String labelText) {
this.label.setText(labelText);
}
/**
* @return the label text
*/
public String getLabelText() {
return this.label.getText();
}
public void setFont(String font) {
this.label.setFont(font);
this.textLbl.setFont(font);
}
public void setTextSize(float size) {
this.label.setTextSize(size);
this.textLbl.setTextSize(size);
}
/* (non-Javadoc)
* @see seventh.ui.Widget#setTheme(seventh.client.gfx.Theme)
*/
@Override
public void setTheme(Theme theme) {
super.setTheme(theme);
this.label.setTheme(theme);
this.textLbl.setTheme(theme);
}
/**
* @return the cursorIndex
*/
public int getCursorIndex() {
return this.cursorIndex;
}
}
| 10,654 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
LevelButton.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/LevelButton.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui;
/**
* Represents a Level Button.
*
* @author Tony
*
*/
public class LevelButton extends Button {
/**
* Label
*/
private Label label;
/**
* If its highlighted
*/
private boolean highlighted;
/**
* If the player has completed this level
*/
private boolean completed;
/**
* Score if available
*/
private int score;
/**
* The levels name
*/
private String levelName;
/**
* @param button
*/
public LevelButton() {
// this.button = button;
this.label = new Label();
// this.addWidget(this.button);
this.addWidget(this.label);
}
/**
* @return the highlighted
*/
public boolean isHighlighted() {
return highlighted;
}
/**
* @param highlighted the highlighted to set
*/
public void setHighlighted(boolean highlighted) {
this.highlighted = highlighted;
}
/**
* @return the completed
*/
public boolean isCompleted() {
return completed;
}
/**
* @param completed the completed to set
*/
public void setCompleted(boolean completed) {
this.completed = completed;
}
/**
* @return the score
*/
public int getScore() {
return score;
}
/**
* @param score the score to set
*/
public void setScore(int score) {
this.score = score;
}
/**
* @return the button
*/
// public Button getButton() {
// return button;
// }
/**
* @return the label
*/
public Label getLabel() {
return label;
}
/**
* @return the levelName
*/
public String getLevelName() {
return levelName;
}
/**
* @param levelName the levelName to set
*/
public void setLevelName(String levelName) {
this.levelName = levelName;
}
}
| 3,594 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ListBox.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/ListBox.java | /*
* see license.txt
*/
package seventh.ui;
import java.util.ArrayList;
import java.util.List;
import seventh.math.Rectangle;
import seventh.math.Vector2f;
import seventh.shared.EventDispatcher;
import seventh.ui.Label.TextAlignment;
import seventh.ui.events.ListHeaderChangedEvent;
import seventh.ui.events.ListItemChangedEvent;
import seventh.ui.events.OnListHeaderChangedListener;
import seventh.ui.events.OnListItemChangedListener;
/**
* @author Tony
*
*/
public class ListBox extends Widget implements Scrollable {
private List<Button> items;
private List<Button> columnHeaders;
private int index;
private int headerHeight;
private int headerMargin;
private int margin;
private Rectangle viewport;
/**
* @param eventDispatcher
*/
public ListBox(EventDispatcher eventDispatcher) {
super(eventDispatcher);
this.headerHeight = 30;
this.headerMargin = 10;
this.items = new ArrayList<>();
this.columnHeaders = new ArrayList<>();
this.viewport = new Rectangle();
this.margin = 5;
}
/**
*
*/
public ListBox() {
this(new EventDispatcher());
}
/**
* @return the index
*/
public int getIndex() {
return index;
}
/**
* @param index the index to set
*/
public void setIndex(int index) {
this.index = index;
}
/**
* Updates to the next index
*/
public void nextIndex() {
this.index++;
if(this.index >= this.items.size()) {
if(this.items.isEmpty()) {
this.index = 0;
}
else {
this.index = this.items.size() - 1;
}
}
}
/**
* Updates to the previous index.
*/
public void previousIndex() {
this.index--;
if(this.index < 0) {
this.index = 0;
}
}
public void addListItemChangedListener(OnListItemChangedListener listener) {
this.getEventDispatcher().addEventListener(ListItemChangedEvent.class, listener);
}
public void addListHeaderChangedListener(OnListHeaderChangedListener listener) {
this.getEventDispatcher().addEventListener(ListHeaderChangedEvent.class, listener);
}
/**
* Adds a button for column header
*
* @param button
*/
public ListBox addColumnHeader(String header, int width) {
Button button = new Button();
button.getBounds().setSize(width, 15);
button.setText(header);
button.setTextSize(12);
button.setHoverTextSize(15);
button.setEnableGradiant(false);
button.setTheme(getTheme());
button.getTextLabel().setHorizontalTextAlignment(TextAlignment.LEFT);
button.getTextLabel().setForegroundColor(0xffffffff);
this.columnHeaders.add(button);
calculateHeaderPositions();
addWidget(button);
this.getEventDispatcher().sendNow(new ListHeaderChangedEvent(this, button, true));
return this;
}
private void calculateHeaderPositions() {
Vector2f pos = new Vector2f(10, 20);
for(Button button : this.columnHeaders) {
button.getBounds().setLocation(pos);
pos.x += button.getBounds().width;
}
}
/**
* Adds an item to the list
* @param button
*/
public ListBox addItem(Button button) {
this.items.add(button);
addWidget(button);
this.getEventDispatcher().sendNow(new ListItemChangedEvent(this, button, true));
return this;
}
/**
* Removes items
* @param button
*/
public void remoteItem(Button button) {
this.items.remove(button);
remoteInternalItem(button);
}
/**
* Removes items
* @param button
*/
private void remoteInternalItem(Button button) {
this.getEventDispatcher().sendNow(new ListItemChangedEvent(this, button, false));
removeWidget(button);
}
/**
* Remove all items
*/
public void removeAll() {
for(Button item : this.items) {
remoteInternalItem(item);
}
this.items.clear();
}
/**
* @return the items
*/
public List<Button> getItems() {
return items;
}
/**
* @return the columnHeaders
*/
public List<Button> getColumnHeaders() {
return columnHeaders;
}
/**
* @return the margin
*/
public int getMargin() {
return margin;
}
/**
* @param margin the margin to set
*/
public void setMargin(int margin) {
this.margin = margin;
}
/**
* @return the headerHeight
*/
public int getHeaderHeight() {
return headerHeight;
}
/**
* @param headerHeight the headerHeight to set
*/
public void setHeaderHeight(int headerHeight) {
this.headerHeight = headerHeight;
}
/**
* @return the headerMargin
*/
public int getHeaderMargin() {
return headerMargin;
}
/**
* @param headerMargin the headerMargin to set
*/
public void setHeaderMargin(int headerMargin) {
this.headerMargin = headerMargin;
}
@Override
public Rectangle getViewport() {
this.viewport.set(getBounds());
this.viewport.height -= (getHeaderHeight());// + getHeaderMargin());
return this.viewport;
}
@Override
public int getTotalHeight() {
int sum = 0;
for(int i = 0; i < this.items.size(); i++) {
sum += this.items.get(i).getBounds().height + this.margin;
}
return sum;
}
@Override
public int getTotalWidth() {
return getBounds().width;
}
}
| 6,079 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ButtonView.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/view/ButtonView.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui.view;
import com.badlogic.gdx.graphics.Color;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.Colors;
import seventh.client.gfx.Renderable;
import seventh.client.gfx.Theme;
import seventh.math.Rectangle;
import seventh.shared.TimeStep;
import seventh.ui.Button;
import seventh.ui.Label;
import seventh.ui.Widget;
/**
* Renders a {@link Button}
*
* @author Tony
*
*/
public class ButtonView implements Renderable {
/**
* The Button
*/
private Button button;
/**
* Renders a label
*/
private LabelView labelView;
private Color srcColor, dstColor, currentColor;
private float time;
/**
* @param button
*/
public ButtonView(Button button) {
this.button = button;
this.srcColor = new Color();
this.dstColor = new Color();
this.currentColor = new Color();
this.labelView = new LabelView(this.button.getTextLabel()) {
@Override
protected void setColor(Canvas renderer, Label label) {
renderer.setColor(Color.argb8888(currentColor), (int)(currentColor.a * 255) );
//super.setColor(renderer, label);
}
};
}
/* (non-Javadoc)
* @see org.myriad.render.Renderable#render(org.myriad.render.Renderer, org.myriad.render.Camera, org.myriad.core.TimeUnit)
*/
public void render(Canvas renderer, Camera camera, float alpha) {
if ( this.button.isVisible() ) {
if ( this.button.gradiantEnabled() ) {
renderGradiantBackground(this.button, renderer, camera, alpha);
}
this.labelView.render(renderer, camera, alpha);
}
}
private void renderGradiantBackground(Widget w, Canvas renderer, Camera camera, float alpha) {
int gradiant = w.getGradiantColor();
int bg = w.getBackgroundColor();
Rectangle bounds = w.getScreenBounds();
int a = w.getBackgroundAlpha();
for(int i = 0; i < bounds.height; i++ ) {
// Vector3f.Vector3fSubtract(bg, gradiant, this.scratch1);
int scratch = Colors.subtract(bg, gradiant);
// this.scratch1.x *= (1.0f / (bounds.height/1.5f));
// this.scratch1.y *= (1.0f / (bounds.height/1.5f));
//
// Vector3f.Vector3fAdd(scratch2, scratch1, scratch2);
// renderer.setColor(scratch2, a);
int col = (a << 24) | scratch;
renderer.drawLine(bounds.x, bounds.y + i, bounds.x + bounds.width, bounds.y + i, col);
}
}
/* (non-Javadoc)
* @see org.myriad.render.Renderable#update(org.myriad.core.TimeStep)
*/
public void update(TimeStep timeStep) {
if(button.isHovering()) {
Theme theme = button.getTheme();
Color.argb8888ToColor(this.srcColor, button.getForegroundColor());
Color.argb8888ToColor(this.dstColor, (theme != null) ? theme.getHoverColor() : button.getForegroundColor());
time += timeStep.asFraction() * 0.79;
float t = (float)Math.cos(time);
this.currentColor.set(this.srcColor.lerp(dstColor, t));
}
else {
time = 0;
Color.argb8888ToColor(currentColor, this.button.getForegroundColor());
currentColor.a = this.button.getForegroundAlpha() / 255;
}
}
/**
* @return the button
*/
public Button getButton() {
return button;
}
}
| 5,264 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
ScrollBarView.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/view/ScrollBarView.java | /*
* see license.txt
*/
package seventh.ui.view;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.Colors;
import seventh.client.gfx.Renderable;
import seventh.math.Rectangle;
import seventh.shared.TimeStep;
import seventh.ui.Button;
import seventh.ui.ScrollBar;
/**
* @author Tony
*
*/
public class ScrollBarView implements Renderable {
private ScrollBar scrollBar;
/**
* @param scrollBar
*/
public ScrollBarView(ScrollBar scrollBar) {
this.scrollBar = scrollBar;
}
@Override
public void update(TimeStep timeStep) {
}
private void renderButton(Canvas canvas, Button btn) {
Rectangle bounds = btn.getScreenBounds();
canvas.fillRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xff383e18);
int a = 240;
if(btn.isHovering()) {
a = 100;
canvas.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, scrollBar.getForegroundColor());
}
canvas.fillRect(bounds.x, bounds.y, bounds.width, bounds.height, Colors.setAlpha(0xff282c0c, a));
canvas.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xff000000);
if(btn.isHovering()) {
canvas.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, Colors.setAlpha(scrollBar.getForegroundColor(), 180));
}
final int stripColor = scrollBar.getForegroundColor();
switch(this.scrollBar.getOrientation()) {
case Horizontal: {
break;
}
case Vertical: {
int width = bounds.height;
int stichesWidth = 21;
int y = bounds.y + (width / 2) + (stichesWidth / 5);
int stichHeight = bounds.width - 5;
//y += stichesWidth/5;
canvas.drawLine(bounds.x + (stichHeight / 2) , y, bounds.x + (bounds.width - (stichHeight / 2)), y, stripColor);
break;
}
}
}
private void renderHandle(Canvas canvas, Button btn) {
renderButton(canvas, btn);
Rectangle bounds = btn.getScreenBounds();
final int stripColor = scrollBar.getForegroundColor();
switch(this.scrollBar.getOrientation()) {
case Horizontal: {
int width = bounds.width;
int stichesWidth = 21;
int x = bounds.x + (width / 2) - stichesWidth;
int stichHeight = bounds.height / 3;
canvas.drawLine(x, bounds.y + (bounds.height - stichHeight), x, bounds.y + stichHeight, stripColor);
x += stichesWidth/3;
canvas.drawLine(x, bounds.y + (bounds.height - stichHeight), x, bounds.y + stichHeight, stripColor);
x += stichesWidth/3;
canvas.drawLine(x, bounds.y + (bounds.height - stichHeight), x, bounds.y + stichHeight, stripColor);
break;
}
case Vertical: {
int width = bounds.height;
int stichesWidth = 21;
int y = bounds.y + (width / 2) + (stichesWidth / 5);
int stichHeight = bounds.width - 5;
canvas.drawLine(bounds.x + (stichHeight / 2) , y, bounds.x + (bounds.width - (stichHeight / 2)), y, stripColor);
y += stichesWidth/5;
canvas.drawLine(bounds.x + (stichHeight / 2) , y, bounds.x + (bounds.width - (stichHeight / 2)), y, stripColor);
y += stichesWidth/5;
canvas.drawLine(bounds.x + (stichHeight / 2) , y, bounds.x + (bounds.width - (stichHeight / 2)), y, stripColor);
break;
}
}
}
@Override
public void render(Canvas canvas, Camera camera, float alpha) {
Rectangle bounds = this.scrollBar.getScreenBounds();
canvas.fillRect(bounds.x, bounds.y, bounds.width, bounds.height, this.scrollBar.getBackgroundColor());
canvas.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xff000000);
renderButton(canvas, this.scrollBar.getTopButton());
renderButton(canvas, this.scrollBar.getBottomButton());
renderHandle(canvas, this.scrollBar.getHandleButton());
}
}
| 4,410 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
TextBoxView.java | /FileExtraction/Java_unseen/tonysparks_seventh/src/seventh/ui/view/TextBoxView.java | /*
**************************************************************************************
*Myriad Engine *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com) *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
package seventh.ui.view;
import seventh.client.gfx.Camera;
import seventh.client.gfx.Canvas;
import seventh.client.gfx.RenderFont;
import seventh.client.gfx.Renderable;
import seventh.math.Rectangle;
import seventh.shared.TimeStep;
import seventh.shared.Timer;
import seventh.ui.Button;
import seventh.ui.TextBox;
import seventh.ui.Widget;
/**
* Renders a {@link Button}
*
* @author Tony
*
*/
public class TextBoxView implements Renderable {
/**
* The text box
*/
private TextBox textBox;
/**
* Renders a label
*/
private LabelView labelView, textView;
private Timer blinkTimer;
private boolean showCursor;
/**
* @param box
*/
public TextBoxView(TextBox box) {
this.textBox = box;
this.labelView = new LabelView(box.getLabel());
this.textView = new LabelView(box.getTextLabel());
this.blinkTimer = new Timer(true, 500);
this.showCursor = true;
}
/* (non-Javadoc)
* @see org.myriad.render.Renderable#render(org.myriad.render.Renderer, org.myriad.render.Camera, org.myriad.core.TimeUnit)
*/
public void render(Canvas renderer, Camera camera, float alpha) {
if ( this.textBox.isVisible() ) {
Rectangle bounds = textBox.getBounds();
String labelText = textBox.getLabelText();
renderer.setFont(textBox.getTextLabel().getFont(), (int)textBox.getTextLabel().getTextSize());
int textHeight = renderer.getHeight("W");
int originalX = bounds.x;
int originalY = bounds.y;
renderGradiantBackground(textBox, renderer, camera, alpha);
if(textBox.hasFocus() || textBox.isHovering()) {
renderer.drawRect(bounds.x - 1, bounds.y - 1, bounds.width + 2, bounds.height + 2, //textBox.getForegroundColor());
0x5ff1f401);
// 0xff393939);
}
final int xTextOffset = 0;
Rectangle lbounds = this.textBox.getTextLabel().getBounds();//update the text
lbounds.set(bounds);
lbounds.x += xTextOffset;
lbounds.y += (lbounds.height / 2) - textHeight / 3;
this.textView.render(renderer, camera, alpha);
if(showCursor && textBox.hasFocus()) {
String text = textBox.getText();
float textWidth = RenderFont.getTextWidth(renderer, text.substring(0, textBox.getCursorIndex()), false, true) + 5;
renderer.setFont(textBox.getTextLabel().getFont(), (int)textBox.getTextLabel().getTextSize());
RenderFont.drawShadedString(renderer, "_", lbounds.x + textWidth, lbounds.y + textHeight - 5, textBox.getForegroundColor());
}
bounds.x = originalX;
int width = (int)RenderFont.getTextWidth(renderer, labelText);
lbounds = this.textBox.getLabel().getBounds();
lbounds.set(bounds);
lbounds.x = bounds.x - (width + 20);
lbounds.y = originalY + 5;
this.labelView.render(renderer, camera, alpha);
}
}
private void renderGradiantBackground(Widget w, Canvas renderer, Camera camera, float alpha) {
// int gradiant = w.getGradiantColor();
// int bg = w.getBackgroundColor();
Rectangle bounds = w.getScreenBounds();
// int a = 0;//w.getBackgroundAlpha();
/*for(int i = 0; i < bounds.height; i++ ) {
// Vector3f.Vector3fSubtract(bg, gradiant, this.scratch1);
// int scratch = Colors.subtract(bg, gradiant);
// this.scratch1.x *= (1.0f / (bounds.height/1.5f));
// this.scratch1.y *= (1.0f / (bounds.height/1.5f));
//
// Vector3f.Vector3fAdd(scratch2, scratch1, scratch2);
// renderer.setColor(scratch2, a);
//int col = (a << 24) | scratch;
int col = 0xff383e18;
renderer.drawLine(bounds.x, bounds.y + i, bounds.x + bounds.width, bounds.y + i, col);
}*/
// renderer.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y, 0xff000000);
// renderer.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, 0xff000000);
renderer.fillRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xff383e18);
renderer.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, 0xff000000);
}
/* (non-Javadoc)
* @see org.myriad.render.Renderable#update(org.myriad.core.TimeStep)
*/
public void update(TimeStep timeStep) {
this.blinkTimer.update(timeStep);
if(this.blinkTimer.isTime()) {
this.showCursor = !this.showCursor;
}
}
/**
* @return the textBox
*/
public TextBox getTextBox() {
return textBox;
}
}
| 6,708 | Java | .java | tonysparks/seventh | 49 | 30 | 7 | 2014-05-05T22:57:09Z | 2019-11-27T01:44:13Z |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.