@@ -4,41 +4,163 @@
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Timeline;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenCallback;
import aurelienribon.tweenengine.TweenEquations;
import no.zandulum.wizzy.core.assets.Assets;
import no.zandulum.wizzy.core.graphics.Draw;
import no.zandulum.wizzy.core.spells.Fireball;
import no.zandulum.wizzy.core.spells.Firebreath;
import no.zandulum.wizzy.core.spells.AbstractSpell;
import no.zandulum.wizzy.core.tweens.TweenGlobal;
import no.zandulum.wizzy.core.tweens.TweenableFloat;
import no.zandulum.wizzy.core.tweens.accessors.FloatAccessor;

public class Hand extends AbstractGameObject {

public static final int WIDTH = 24, HEIGHT = 24, LEFT = -1, RIGHT = 1, DIAMETER = Player.WIDTH * 2 / 3;
public static final int WIDTH = 8, HEIGHT = 8, LEFT = -1, RIGHT = 1, DIAMETER = Player.WIDTH * 2 / 3;
public static final float DELAY = 0.5f;

Player player;
int orientation;
TweenableFloat frontOffset;
TweenableFloat sideOffset;
boolean isHandCasting = false;

public AbstractSpell spell;

public Hand(Player player, float x, float y, int orientation) {
super(x, y, WIDTH, HEIGHT);
Sprite sprite = new Sprite(Assets.hand);
setSprite(sprite);
this.player = player;
this.orientation = orientation;
frontOffset = new TweenableFloat(0);
sideOffset = new TweenableFloat(0);

// TODO choose what spell
if (orientation == RIGHT) {
spell = new Fireball(player, this);
} else if (orientation == LEFT) {
spell = new Firebreath(player, this);
}
}

@Override
public void draw(SpriteBatch batch) {
Draw.sprite(batch, sprite, getX(), getY(), getWidth() * getScale(), getHeight() * getScale(), scale, scale, rot,
Color.WHITE, orientation == LEFT);
Color.RED, orientation == LEFT);
}

@Override
public void update(float delta) {
followPlayer(player, delta);
spellLogic(delta);
}

private void spellLogic(float delta) {
spell.update(delta);
}

private void followPlayer(Player player, float delta) {
float targetX = player.getCenterX() + orientation * DIAMETER - WIDTH / 2;
float targetY = player.getCenterY();
float targetX = (float) (player.getCenterX()
+ Math.cos(getRotation() + Math.PI / 2) * (orientation * (DIAMETER + sideOffset.getValue())) - WIDTH / 2
+ Math.sin(getRotation() + Math.PI / 2) * (WIDTH + frontOffset.getValue()));
float targetY = (float) (player.getCenterY() - HEIGHT / 2
+ Math.sin(getRotation() + Math.PI / 2) * (orientation * (DIAMETER + sideOffset.getValue()))
- Math.cos(getRotation() + Math.PI / 2) * (WIDTH + frontOffset.getValue()));
setX(getX() * DELAY + targetX * (1 - DELAY));
setY(getY() * DELAY + targetY * (1 - DELAY));
setRotation(player.getRotation());
}

public void cast(boolean cast) {
switch (spell.getCastType()) {
case CHARGE:
break;
case HOLD:
if (cast) {
TweenGlobal.start(holdCastStart());
isHandCasting = true;
} else if (!cast) {
TweenGlobal.start(holdCastStop());
isHandCasting = false;
spell.cast(false);
}
break;
case SINGLE:
if (cast && !isHandCasting) {
isHandCasting = true;
TweenGlobal.start(singleCast());
}
break;
default:
break;
}
}

// Tweens

private Timeline holdCastStart() {
Timeline holdCastStart = Timeline.createParallel()
.push(Tween.to(sideOffset, FloatAccessor.TYPE_VALUE, 0.1f).target(-20f).ease(TweenEquations.easeInExpo))
.push(Tween.to(frontOffset, FloatAccessor.TYPE_VALUE, 0.1f).target(16f)
.setCallback(new TweenCallback() {
@Override
public void onEvent(int arg0, BaseTween<?> arg1) {
if (arg0 == TweenCallback.COMPLETE) {
if (isHandCasting) {
spell.cast(true);
}
}
}
}));
return holdCastStart;
}

private Timeline holdCastStop() {
Timeline holdCastStop = Timeline.createParallel()
.push(Tween.to(sideOffset, FloatAccessor.TYPE_VALUE, 0.2f).target(0).ease(TweenEquations.easeOutExpo))
.push(Tween.to(frontOffset, FloatAccessor.TYPE_VALUE, 0.2f).target(0).setCallback(new TweenCallback() {
@Override
public void onEvent(int arg0, BaseTween<?> arg1) {
if (arg0 == TweenCallback.COMPLETE) {
isHandCasting = false;
}
}
}));

return holdCastStop;
}

private Timeline singleCast() {
Timeline singleCast = Timeline.createParallel()
.push(Tween.to(sideOffset, FloatAccessor.TYPE_VALUE, 0.1f).target(-20f).ease(TweenEquations.easeInExpo))
.push(Tween.to(frontOffset, FloatAccessor.TYPE_VALUE, 0.2f).target(16f)
.setCallback(new TweenCallback() {
@Override
public void onEvent(int arg0, BaseTween<?> arg1) {
spell.cast(true);
if (arg0 == TweenCallback.COMPLETE) {
TweenGlobal.start(Timeline.createParallel()
.push(Tween.to(sideOffset, FloatAccessor.TYPE_VALUE, 0.2f).target(0f)
.ease(TweenEquations.easeOutBack))
.push(Tween.to(frontOffset, FloatAccessor.TYPE_VALUE, 0.2f).target(0f)
.setCallback(new TweenCallback() {
@Override
public void onEvent(int arg0, BaseTween<?> arg1) {
if (arg0 == TweenCallback.COMPLETE) {
spell.cast(false);
isHandCasting = false;
}
}
})));
}
}
}));
return singleCast;
}

}
@@ -1,5 +1,6 @@
package no.zandulum.wizzy.core.gameobjects;

import com.badlogic.gdx.Input;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputAdapter;

@@ -11,6 +12,7 @@ public class LocalPlayer extends Player {
int lastDir = 0;
int updateRate = 2;
double nextUpdate = updateRate;
Cursor cursor;

public LocalPlayer(String name, float x, float y) {
super(name, x, y);
@@ -20,17 +22,54 @@ public LocalPlayer(String name, float x, float y) {
public void update(float delta) {
super.update(delta);
networkLogic(delta);
lastDir = movement.toInt();
controllerLogic(delta);
}

private void controllerLogic(float delta) {
setRotation(angleTo(cursor.getCenterX(), cursor.getCenterY()));
}

@Override
public void onSpawn() {
super.onSpawn();
initInput();
cursor = new Cursor(this, getCenterX(), getCenterY());
getGameContext().spawn(cursor);
}

private void initInput() {
getGameContext().addInputProcessor(new InputAdapter() {

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {

if (button == Input.Buttons.LEFT) {
right.cast(true);
return true;
} else if (button == Input.Buttons.RIGHT) {
left.cast(true);
return true;
} else {
return false;
}

}

@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {

if (button == Input.Buttons.LEFT) {
right.cast(false);
return true;
} else if (button == Input.Buttons.RIGHT) {
left.cast(false);
return true;
} else {
return false;
}

}

@Override
public boolean keyDown(int keycode) {
switch (keycode) {
@@ -71,6 +110,14 @@ public boolean keyUp(int keycode) {
});
}

@Override
protected void move(float delta) {
float oldX = getX(), oldY = getY();
super.move(delta);
cursor.setX(cursor.getX() + (getX() - oldX));
cursor.setY(cursor.getY() + (getY() - oldY));
}

@Override
public void onDespawn() {
super.onDespawn();
@@ -83,11 +130,15 @@ private void networkLogic(float delta) {
nextUpdate = getGameContext().getTicks() + updateRate;
lastDir = movement.toInt();
try {
Client.getInstance().send(PacketBuilder.move(name, getX(), getY(), lastDir));
System.out.println("Sending movement packet...");
Client.getInstance().send(PacketBuilder.move(name, getX(), getY(), lastDir, rot));
} catch (Exception e) {
e.printStackTrace();
}
}
lastDir = movement.toInt();
}

public Cursor getCursor() {
return cursor;
}
}
@@ -5,9 +5,9 @@
import no.zandulum.wizzy.core.assets.Assets;

public class Player extends AbstractGameObject {
public static final int WIDTH = 64, HEIGHT = 64;
public static final float ACCELERATION = 4000;
public static final float MAX_SPEED = 250;
public static final int WIDTH = 32, HEIGHT = 32;
public static final float ACCELERATION = 2000;
public static final float MAX_SPEED = 150;

public MovementDirection movement;
String name;
@@ -19,6 +19,7 @@ public Player(String name, float x, float y) {
super(x, y, WIDTH, HEIGHT);
this.name = name;
setSprite(new Sprite(Assets.wizzy));
sprite.setOrigin(WIDTH / 2, HEIGHT / 2);
movement = new MovementDirection();
setMaxSpeed(MAX_SPEED);
}
@@ -50,18 +51,19 @@ private void movementLogic(float delta) {
}

if (movement.up) {
acceleration.y = ACCELERATION;
} else if (movement.down) {
acceleration.y = -ACCELERATION;
} else if (movement.down) {
acceleration.y = ACCELERATION;
} else {
acceleration.y = 0;
}
move(delta);
}

public void updateFromPacket(float new_x, float new_y, int new_dir) {
public void updateFromPacket(float new_x, float new_y, int new_dir, float lookDir) {
setX(new_x);
setY(new_y);
setRotation(lookDir);
this.movement.updatefromInt(new_dir);
}

@@ -0,0 +1,26 @@
package no.zandulum.wizzy.core.gameobjects.particles;

import no.zandulum.wizzy.core.gameobjects.AbstractGameObject;

public abstract class AbstractParticle extends AbstractGameObject {

float timeToLive;

public AbstractParticle(float x, float y, float width, float height, float timeToLive) {
super(x, y, width, height);
this.timeToLive = timeToLive;
}

@Override
public void update(float delta) {
if (timeToLive >= 0 && getAliveTime() > timeToLive) {
getGameContext().despawn(this);
return;
}
updateParticle(delta);
move(delta);
}

public abstract void updateParticle(float delta);

}
@@ -0,0 +1,30 @@
package no.zandulum.wizzy.core.gameobjects.particles;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;

import no.zandulum.wizzy.core.assets.Assets;

public class FireParticle extends AbstractParticle {

public static final int WIDTH = 4, HEIGHT = 4;
public static final float TTL = 0.7f;

public FireParticle(float x, float y) {
super(x, y, WIDTH, HEIGHT, TTL);
setSprite(new Sprite(Assets.fire3));
sprite.setColor(Color.ORANGE);
}

@Override
public void onSpawn() {
super.onSpawn();
getGameContext().bringToBack(this);
}

@Override
public void updateParticle(float delta) {
setScale(1 - getAliveTime() / TTL);
}

}
@@ -9,22 +9,32 @@
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.viewport.ScalingViewport;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.Viewport;

import no.zandulum.wizzy.core.WizzyGame;
import no.zandulum.wizzy.core.defs.Defs;
import no.zandulum.wizzy.core.gamecontext.GameContext;
import no.zandulum.wizzy.core.screens.mousehandles.MouseHandle;

public abstract class AbstractGameScreen implements Screen {

protected final WizzyGame game;

public final static float SCALE = 2f;
public final static float INV_SCALE = 1.f / SCALE;

public final static float VP_WIDTH = Defs.WIDTH * INV_SCALE;
public final static float VP_HEIGHT = Defs.HEIGHT * INV_SCALE;

protected final OrthographicCamera camera;
protected final OrthographicCamera hudCamera;
protected final Viewport viewport;
protected final Stage stage;
protected GameContext gameContext;

protected final MouseHandle mouseHandle;

private final SpriteBatch batch, hudBatch;

public ShapeRenderer shapes;
@@ -37,14 +47,19 @@ public abstract class AbstractGameScreen implements Screen {

public AbstractGameScreen(WizzyGame game) {
this.game = game;
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
hudCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
stage = new Stage(new ScalingViewport(Scaling.stretch, Defs.WIDTH, Defs.HEIGHT, camera));
camera = new OrthographicCamera();
camera.setToOrtho(true);
hudCamera = new OrthographicCamera();
viewport = new ExtendViewport(VP_WIDTH, VP_HEIGHT, camera);
stage = new Stage(viewport);

mouseHandle = new MouseHandle(camera, viewport);

batch = new SpriteBatch();
shapes = new ShapeRenderer();
hudBatch = new SpriteBatch();
hudBatch.enableBlending();
gameContext = new GameContext(game);
gameContext = new GameContext(game, mouseHandle);

}

@@ -56,12 +71,10 @@ public void render(float delta) {
Gdx.gl.glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT
| (Gdx.graphics.getBufferFormat().coverageSampling ? GL20.GL_COVERAGE_BUFFER_BIT_NV : 0));
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
draw(batch, delta);
batch.end();
// hudCamera.lookAt(camera.position);
hudCamera.zoom = camera.zoom;
hudCamera.update();
hudBatch.begin();
@@ -86,11 +99,7 @@ public void render(float delta) {

@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
camera.setToOrtho(false, Defs.WIDTH, Defs.HEIGHT);
camera.update();
hudCamera.setToOrtho(false, width, height);
hudCamera.update();
viewport.update(width, height, true);
}

@Override
@@ -181,6 +190,10 @@ public WizzyGame getGame() {
return game;
}

public MouseHandle getMouseHandle() {
return mouseHandle;
}

protected SpriteBatch getSpriteBatch() {
return batch;
}
@@ -2,6 +2,7 @@

import java.util.HashMap;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;

@@ -15,6 +16,7 @@
public class GameScreen extends AbstractGameScreen {
private HashMap<String, Player> players;
private ClientListener clientListener;
LocalPlayer player;

public GameScreen(WizzyGame game) {
super(game);
@@ -39,7 +41,6 @@ public void onHello(String name) {
Player player = new Player(name, 50, 50);
players.put(name, player);
gameContext.spawn(player);
System.out.println("Spawning " + name);
}

@Override
@@ -48,7 +49,6 @@ public void onHelloBack(String[] names) {
Player player = new Player(name, 50, 50);
players.put(name, player);
gameContext.spawn(player);
System.out.println("Spawning " + name);
}
}

@@ -59,11 +59,10 @@ public void onGoodbye(String name) {
}

@Override
public void onMove(String name, float x, float y, int dir) {
public void onMove(String name, float x, float y, int dir, float lookDir) {
if (players.containsKey(name)) {
Player p = players.get(name);
p.updateFromPacket(x, y, dir);
System.out.println("Updating " + name + ": (x: " + p.getX() + ", y: " + p.getY() + ")");
p.updateFromPacket(x, y, dir, lookDir);
} else {
System.out.println("Could not find player " + name);
}
@@ -74,12 +73,23 @@ public void onMove(String name, float x, float y, int dir) {

@Override
protected void debugDraw(ShapeRenderer renderer) {

/*
* renderer.begin(); for (GameObject go : gameContext.getObjects()) {
* go.debugDraw(renderer); } renderer.end();
*/
}

@Override
protected void update(float delta) {
gameContext.update(delta);
cameraLogic(delta);
}

private void cameraLogic(float delta) {
float targetX = player.getCursor().getCenterX() + player.velocity().x / 4;
float targetY = player.getCursor().getCenterY() + player.velocity().y / 4;
camera.position.x = camera.position.x * 0.95f + targetX * 0.05f;
camera.position.y = camera.position.y * 0.95f + targetY * 0.05f;
}

@Override
@@ -95,7 +105,7 @@ protected void drawHud(SpriteBatch hudBatch, float delta) {

@Override
protected void onShow() {

Gdx.input.setCursorCatched(true);
players = new HashMap<>();

Client c = Client.getInstance();
@@ -105,7 +115,8 @@ protected void onShow() {
e.printStackTrace();
}
c.send(PacketBuilder.hello(c.getName()));
gameContext.spawn(new LocalPlayer(c.getName(), 50, 50));
player = new LocalPlayer(c.getName(), 50, 50);
gameContext.spawn(player);
}

}
@@ -60,7 +60,7 @@ protected void debugDraw(ShapeRenderer renderer) {

@Override
protected void update(float delta) {
logString = "";
logString = "Connections: \n";
for(Entry<String, String> e : connections.entrySet()){
logString += e.getKey() + "\n";
}
@@ -0,0 +1,19 @@
package no.zandulum.wizzy.core.screens.mousehandles;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.viewport.Viewport;

public class MouseHandle {
Camera camera;
Viewport viewport;

public MouseHandle(Camera camera, Viewport viewport) {
this.camera = camera;
this.viewport = viewport;
}

public void screenCoordsToWorldCoords(Vector3 m) {
camera.unproject(m, 0, 0, viewport.getScreenWidth(), viewport.getScreenHeight());
}
}
@@ -0,0 +1,81 @@
package no.zandulum.wizzy.core.spells;

import no.zandulum.wizzy.core.gameobjects.Hand;
import no.zandulum.wizzy.core.gameobjects.Player;
import no.zandulum.wizzy.core.utils.Cooldown;

public abstract class AbstractSpell {

public enum CastType {
SINGLE, HOLD, CHARGE
}

protected Player caster;
protected Hand castingHand;
protected CastType castType;

private Cooldown cooldown;
private boolean casting;

public AbstractSpell(Player caster, Hand castingHand, CastType castType, Cooldown cooldown) {
this.castingHand = castingHand;
this.setCaster(caster);
this.setCastType(castType);
this.cooldown = cooldown;
}

public abstract void onCast();

public CastType getCastType() {
return castType;
}

public void setCastType(CastType castType) {
this.castType = castType;
}

public void update(float delta) {
if (!cooldown.isReady()) {
cooldown.update(delta);
}

if (isCasting()) {
switch (castType) {
case CHARGE:
break;
case HOLD:
if (cooldown.isReady()) {
cooldown.start();
onCast();
}
break;
case SINGLE:
if (cooldown.isReady()) {
cooldown.start();
onCast();
}
break;
default:
break;

}
}
}

public void cast(boolean casting) {
this.casting = casting;
}

public boolean isCasting() {
return casting;
}

public Player getCaster() {
return caster;
}

public void setCaster(Player caster) {
this.caster = caster;
}

}
@@ -0,0 +1,19 @@
package no.zandulum.wizzy.core.spells;

import no.zandulum.wizzy.core.gameobjects.Hand;
import no.zandulum.wizzy.core.gameobjects.Player;
import no.zandulum.wizzy.core.spells.projectiles.FireballProjectile;
import no.zandulum.wizzy.core.utils.Cooldown;

public class Fireball extends AbstractSpell {

public Fireball(Player caster, Hand hand) {
super(caster, hand, CastType.SINGLE, new Cooldown(0.5f));
}

@Override
public void onCast() {
caster.getGameContext().spawn(new FireballProjectile(this, castingHand.getCenterX(), castingHand.getCenterY()));
}

}
@@ -0,0 +1,31 @@
package no.zandulum.wizzy.core.spells;

import no.zandulum.wizzy.core.gameobjects.Hand;
import no.zandulum.wizzy.core.gameobjects.Player;
import no.zandulum.wizzy.core.spells.projectiles.FirebreathProjectile;
import no.zandulum.wizzy.core.utils.Cooldown;

public class Firebreath extends AbstractSpell {

public static final float SPREAD = 0.3f;

public Firebreath(Player caster, Hand hand) {
super(caster, hand, CastType.HOLD, new Cooldown(0.03f));
}

@Override
public void onCast() {
int noOfProjectiles = (int) (Math.random() * 7) + 1;
for (int i = 0; i < noOfProjectiles; i++) {
FirebreathProjectile fp = new FirebreathProjectile(this, castingHand.getCenterX(),
castingHand.getCenterY());
fp.setRotation((float) (caster.getRotation() + (Math.random() * SPREAD * 2 - SPREAD)));
fp.velocity().x = caster.velocity().x / 2
+ (float) (Math.cos(fp.getRotation()) * FirebreathProjectile.SPEED);
fp.velocity().y = caster.velocity().y / 2
+ (float) (Math.sin(fp.getRotation()) * FirebreathProjectile.SPEED);
caster.getGameContext().spawn(fp);
}
}

}
@@ -0,0 +1,37 @@
package no.zandulum.wizzy.core.spells.projectiles;

import no.zandulum.wizzy.core.gameobjects.AbstractGameObject;
import no.zandulum.wizzy.core.spells.AbstractSpell;

public abstract class AbstractProjectile extends AbstractGameObject {

float timeToLive;
AbstractSpell spell;

public AbstractProjectile(AbstractSpell spell, float x, float y, float width, float height, float timeToLive) {
super(x, y, width, height);
this.timeToLive = timeToLive;
this.spell = spell;
this.acceleration.x = EPSILON;
this.acceleration.y = EPSILON;
}

@Override
public void onSpawn() {
super.onSpawn();
getGameContext().bringToBack(this);
}

@Override
public void update(float delta) {
if (timeToLive >= 0 && getAliveTime() > timeToLive) {
getGameContext().despawn(this);
return;
}
move(delta);
updateProjectile(delta);
}

public abstract void updateProjectile(float delta);

}
@@ -0,0 +1,48 @@
package no.zandulum.wizzy.core.spells.projectiles;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;

import aurelienribon.tweenengine.Tween;
import no.zandulum.wizzy.core.assets.Assets;
import no.zandulum.wizzy.core.gameobjects.particles.FireParticle;
import no.zandulum.wizzy.core.spells.Fireball;
import no.zandulum.wizzy.core.tweens.TweenGlobal;
import no.zandulum.wizzy.core.tweens.accessors.ColorAccessor;

public class FireballProjectile extends AbstractProjectile {

public static final int WIDTH = 12, HEIGHT = 12;
public static final float SPEED = 200f, TTL = 2.0f;

private Texture[] textures;
private int ti;
private Color fireColor;

public FireballProjectile(Fireball spell, float x, float y) {
super(spell, x, y, WIDTH, HEIGHT, TTL);
setRotation(spell.getCaster().getRotation());
velocity().x = spell.getCaster().velocity().x + (float) (Math.cos(rot) * SPEED);
velocity().y = spell.getCaster().velocity().y + (float) (Math.sin(rot) * SPEED);

textures = new Texture[] { Assets.fire, Assets.fire2, Assets.fire3 };

setSprite(new Sprite(textures[0]));
fireColor = new Color(Color.ORANGE);
sprite.setColor(fireColor);
TweenGlobal.start(Tween.to(fireColor, ColorAccessor.TYPE_RGBA, TTL / 4)
.target(fireColor.r, 1.0f, fireColor.b, fireColor.a).repeatYoyo(4, 0));
}

@Override
public void updateProjectile(float delta) {
sprite.setColor(fireColor);
if (getGameContext().getTicks() % 8 == 0) {
getGameContext().spawn(
new FireParticle(getCenterX() - FireParticle.WIDTH / 2, getCenterY() - FireParticle.HEIGHT / 2));
sprite.setTexture(textures[(ti++) % textures.length]);
}
}

}
@@ -0,0 +1,40 @@
package no.zandulum.wizzy.core.spells.projectiles;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;

import no.zandulum.wizzy.core.assets.Assets;
import no.zandulum.wizzy.core.gameobjects.particles.FireParticle;
import no.zandulum.wizzy.core.spells.Firebreath;

public class FirebreathProjectile extends AbstractProjectile {

public static final int WIDTH = 6, HEIGHT = 6;
public static final float SPEED = 100f, TTL = 0.8f;

private Texture[] textures;
private int ti;

public FirebreathProjectile(Firebreath spell, float x, float y) {
super(spell, x, y, WIDTH, HEIGHT, TTL);

textures = new Texture[] { Assets.fire, Assets.fire2, Assets.fire3 };
ti = (int) (Math.random() * 2);
setSprite(new Sprite(textures[ti]));

Color color = new Color(Color.ORANGE);
color.g = (float) (Math.random() * 0.5f + 0.5f);
sprite.setColor(color);
}

@Override
public void updateProjectile(float delta) {
if (getGameContext().getTicks() % 8 == 0) {
getGameContext().spawn(
new FireParticle(getCenterX() - FireParticle.WIDTH / 2, getCenterY() - FireParticle.HEIGHT / 2));
sprite.setTexture(textures[(ti++) % textures.length]);
}
}

}
@@ -0,0 +1,52 @@
package no.zandulum.wizzy.core.tweens;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

import aurelienribon.tweenengine.Timeline;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenAccessor;
import aurelienribon.tweenengine.TweenManager;
import no.zandulum.wizzy.core.tweens.accessors.ColorAccessor;
import no.zandulum.wizzy.core.tweens.accessors.FloatAccessor;
import no.zandulum.wizzy.core.tweens.accessors.Vector2Accessor;
import no.zandulum.wizzy.core.tweens.accessors.Vector3Accessor;

public class TweenGlobal {
private static TweenManager manager;
private static Map<Class<?>, TweenAccessor<?>> accessors;

public static void init() {
// Required for tweening colors
Tween.setCombinedAttributesLimit(4);
manager = new TweenManager();
accessors = new HashMap<>();
accessors.put(Vector2.class, new Vector2Accessor());
accessors.put(Vector3.class, new Vector3Accessor());
accessors.put(Color.class, new ColorAccessor());
accessors.put(TweenableFloat.class, new FloatAccessor());
register();
}

private static void register() {
for (Entry<Class<?>, TweenAccessor<?>> entry : accessors.entrySet()) {
Tween.registerAccessor(entry.getKey(), entry.getValue());
}
}

public static void update(float delta) {
manager.update(delta);
}

public static void start(Tween tween) {
tween.start(manager);
}
public static void start(Timeline timeline) {
timeline.start(manager);
}
}
@@ -0,0 +1,18 @@
package no.zandulum.wizzy.core.tweens;

public class TweenableFloat {
private float value;

public TweenableFloat(float value) {
setValue(value);
}

public float getValue() {
return value;
}

public void setValue(float value) {
this.value = value;
}

}
@@ -0,0 +1,42 @@
package no.zandulum.wizzy.core.tweens.accessors;

import com.badlogic.gdx.graphics.Color;

import aurelienribon.tweenengine.TweenAccessor;

public class ColorAccessor implements TweenAccessor<Color> {

public static final int TYPE_RGBA = 1, TYPE_A = 2;

@Override
public int getValues(Color c, int type, float[] returnVals) {
switch (type) {
case TYPE_RGBA:
returnVals[0] = c.r;
returnVals[1] = c.g;
returnVals[2] = c.b;
returnVals[3] = c.a;
return 4;
case TYPE_A:
returnVals[0] = c.a;
return 1;
}
return 0;
}

@Override
public void setValues(Color c, int type, float[] newVals) {
switch (type) {
case TYPE_RGBA:
c.r = newVals[0];
c.g = newVals[1];
c.b = newVals[2];
c.a = newVals[3];
break;
case TYPE_A:
c.a = newVals[0];
break;
}
}

}
@@ -0,0 +1,29 @@
package no.zandulum.wizzy.core.tweens.accessors;

import aurelienribon.tweenengine.TweenAccessor;
import no.zandulum.wizzy.core.tweens.TweenableFloat;

public class FloatAccessor implements TweenAccessor<TweenableFloat> {

public static final int TYPE_VALUE = 1;

@Override
public int getValues(TweenableFloat v, int type, float[] returnVals) {
switch (type) {
case TYPE_VALUE:
returnVals[0] = v.getValue();
return 1;
}
return 0;
}

@Override
public void setValues(TweenableFloat v, int type, float[] newVals) {
switch (type) {
case TYPE_VALUE:
v.setValue(newVals[0]);
break;
}
}

}
@@ -0,0 +1,44 @@
package no.zandulum.wizzy.core.tweens.accessors;

import com.badlogic.gdx.math.Vector2;

import aurelienribon.tweenengine.TweenAccessor;

public class Vector2Accessor implements TweenAccessor<Vector2> {

public static final int TYPE_XY = 0, TYPE_X = 1, TYPE_Y = 2;

@Override
public int getValues(Vector2 v, int type, float[] returnVals) {
switch (type) {
case TYPE_X:
returnVals[0] = v.x;
return 1;
case TYPE_Y:
returnVals[0] = v.y;
return 1;
case TYPE_XY:
returnVals[0] = v.x;
returnVals[1] = v.y;
return 2;
}
return 0;
}

@Override
public void setValues(Vector2 v, int type, float[] newVals) {
switch (type) {
case TYPE_X:
v.x = newVals[0];
break;
case TYPE_Y:
v.y = newVals[0];
break;
case TYPE_XY:
v.x = newVals[0];
v.y = newVals[1];
break;
}
}

}
@@ -0,0 +1,34 @@
package no.zandulum.wizzy.core.tweens.accessors;

import com.badlogic.gdx.math.Vector3;

import aurelienribon.tweenengine.TweenAccessor;

public class Vector3Accessor implements TweenAccessor<Vector3> {

public static final int TYPE_XYZ = 0;

@Override
public int getValues(Vector3 v, int type, float[] returnVals) {
switch (type) {
case TYPE_XYZ:
returnVals[0] = v.x;
returnVals[1] = v.y;
returnVals[2] = v.z;
return 3;
}
return 0;
}

@Override
public void setValues(Vector3 v, int type, float[] newVals) {
switch (type) {
case TYPE_XYZ:
v.x = newVals[0];
v.y = newVals[1];
v.z = newVals[2];
break;
}
}

}
@@ -0,0 +1,27 @@
package no.zandulum.wizzy.core.utils;

public class Cooldown {
float seconds;
float counter;

public Cooldown(float seconds) {
this.seconds = seconds;
}

public boolean isReady() {
return counter <= 0;
}

public void start() {
counter = seconds;
}

public void update(float delta) {
if (counter > 0) {
counter -= delta;
} else {
counter = 0;
}

}
}
@@ -84,9 +84,10 @@ private void handleServerMessage(String message) {
float new_x = Float.parseFloat(data[2]);
float new_y = Float.parseFloat(data[3]);
int new_dir = Integer.parseInt(data[4]);
float new_look_dir = Float.parseFloat(data[5]);

for (ClientListener cl : listeners) {
cl.onMove(moving_name, new_x, new_y, new_dir);
cl.onMove(moving_name, new_x, new_y, new_dir, new_look_dir);
}
break;
case Defs.GOODBYE_PACKET:
@@ -7,7 +7,7 @@ public interface ClientListener {

void onHello(String name);

void onMove(String name, float x, float y, int dir);
void onMove(String name, float x, float y, int movementDir, float lookDir);

void onHelloBack(String[] names);

@@ -17,8 +17,8 @@ public static final String helloBack(String[] names) {
return String.format("%s%s%s", Defs.HELLO_BACK_PACKET, Defs.DELIMITER, String.join(Defs.SUB_DELIMITER, names));
}

public static final String move(String name, float x, float y, int dir) {
return String.format(Locale.ROOT, "%s%s%s%s%f%s%f%s%d", Defs.MOVE_PACKET, Defs.DELIMITER, name, Defs.DELIMITER,
x, Defs.DELIMITER, y, Defs.DELIMITER, dir);
public static final String move(String name, float x, float y, int movementDir, float lookDir) {
return String.format(Locale.ROOT, "%s%s%s%s%f%s%f%s%d%s%f", Defs.MOVE_PACKET, Defs.DELIMITER, name, Defs.DELIMITER,
x, Defs.DELIMITER, y, Defs.DELIMITER, movementDir, Defs.DELIMITER, lookDir);
}
}
@@ -30,7 +30,7 @@ public Server(InetSocketAddress address) throws UnknownHostException {

public static Server getInstance() throws UnknownHostException {
if (instance == null) {
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 54545);
InetSocketAddress address = new InetSocketAddress("192.168.38.105", 1337);
instance = new Server(address);
}
return instance;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,10 +4,16 @@
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;

import no.zandulum.wizzy.core.WizzyGame;
import no.zandulum.wizzy.core.defs.Defs;

public class wizzyDesktop {
public static void main (String[] args) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.useHDPI = true;
config.foregroundFPS = 120;
config.fullscreen = true;
config.width = (int) 1680;
config.height = (int) 1050;
new LwjglApplication(new WizzyGame(), config);
}
}
@@ -3,11 +3,10 @@
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;

import no.zandulum.wizzy.core.WizzyGame;
import no.zandulum.wizzy.core.WizzyGameServer;

public class wizzyServerDesktop {
public static void main (String[] args) {
public static void main(String[] args) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
new LwjglApplication(new WizzyGameServer(), config);
}
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -18,13 +18,13 @@
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx</artifactId>
<version>1.9.0</version>
<version>1.9.6</version>
</dependency>

<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-platform</artifactId>
<version>1.9.0</version>
<version>1.9.6</version>
<classifier>natives-armeabi</classifier>
<scope>provided</scope>
</dependency>
@@ -33,20 +33,20 @@
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-backend-lwjgl</artifactId>
<version>1.9.0</version>
<version>1.9.6</version>
</dependency>

<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-platform</artifactId>
<version>1.9.0</version>
<version>1.9.6</version>
<classifier>natives-desktop</classifier>
</dependency>

<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-platform</artifactId>
<version>1.9.0</version>
<version>1.9.6</version>
<classifier>natives-armeabi-v7a</classifier>
<scope>provided</scope>
</dependency>
@@ -55,23 +55,23 @@
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx</artifactId>
<version>1.9.0</version>
<version>1.9.6</version>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-backend-gwt</artifactId>
<version>1.9.0</version>
<version>1.9.6</version>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-backend-gwt</artifactId>
<version>1.9.0</version>
<version>1.9.6</version>
</dependency>
</dependencies>
</dependencyManagement>