| @@ -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); | ||
| } | ||
|
|
||
| } |
| @@ -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; | ||
| } | ||
|
|
||
| } | ||
| } |
| @@ -7,7 +7,7 @@ public interface ClientListener { | ||
|
|
||
| void onHello(String name); | ||
|
|
||
| void onMove(String name, float x, float y, int movementDir, float lookDir); | ||
|
|
||
| void onHelloBack(String[] names); | ||
|
|
||