Added GroundUnitType, compile fixed
This commit is contained in:
@@ -25,7 +25,7 @@ allprojects {
|
|||||||
appName = 'Mindustry'
|
appName = 'Mindustry'
|
||||||
gdxVersion = '1.9.8'
|
gdxVersion = '1.9.8'
|
||||||
aiVersion = '1.8.1'
|
aiVersion = '1.8.1'
|
||||||
uCoreVersion = 'cfc0943'
|
uCoreVersion = '0176aaa'
|
||||||
|
|
||||||
getVersionString = {
|
getVersionString = {
|
||||||
String buildVersion = getBuildVersion()
|
String buildVersion = getBuildVersion()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#Autogenerated file. Do not modify.
|
#Autogenerated file. Do not modify.
|
||||||
#Thu Mar 15 21:41:26 EDT 2018
|
#Fri Mar 16 00:30:24 EDT 2018
|
||||||
version=release
|
version=release
|
||||||
androidBuildCode=524
|
androidBuildCode=525
|
||||||
name=Mindustry
|
name=Mindustry
|
||||||
code=3.4
|
code=3.4
|
||||||
build=custom build
|
build=custom build
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class Logic extends Module {
|
|||||||
state.allyTeams.clear();
|
state.allyTeams.clear();
|
||||||
state.enemyTeams.clear();
|
state.enemyTeams.clear();
|
||||||
state.enemyTeams.add(Team.red);
|
state.enemyTeams.add(Team.red);
|
||||||
state.team = Team.none;
|
state.team = Team.blue;
|
||||||
|
|
||||||
Timers.clear();
|
Timers.clear();
|
||||||
Entities.clear();
|
Entities.clear();
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class Player extends Unit{
|
|||||||
public int clientid = -1;
|
public int clientid = -1;
|
||||||
public boolean isLocal = false;
|
public boolean isLocal = false;
|
||||||
public Timer timer = new Timer(4);
|
public Timer timer = new Timer(4);
|
||||||
public float footRotation, walktime;
|
public float walktime;
|
||||||
|
|
||||||
private Vector2 movement = new Vector2();
|
private Vector2 movement = new Vector2();
|
||||||
private Translator tr = new Translator();
|
private Translator tr = new Translator();
|
||||||
@@ -59,7 +59,6 @@ public class Player extends Unit{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemoteShoot(BulletType type, float x, float y, float rotation, short data) {
|
public void onRemoteShoot(BulletType type, float x, float y, float rotation, short data) {
|
||||||
//TODO shoot!
|
|
||||||
Weapon weapon = Upgrade.getByID((byte)data);
|
Weapon weapon = Upgrade.getByID((byte)data);
|
||||||
weapon.shoot(player, x, y, rotation);
|
weapon.shoot(player, x, y, rotation);
|
||||||
}
|
}
|
||||||
@@ -101,7 +100,7 @@ public class Player extends Unit{
|
|||||||
public void onDeath(){
|
public void onDeath(){
|
||||||
dead = true;
|
dead = true;
|
||||||
if(Net.active()){
|
if(Net.active()){
|
||||||
NetEvents.handlePlayerDeath();
|
NetEvents.handleUnitDeath(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Effects.effect(Fx.explosion, this);
|
Effects.effect(Fx.explosion, this);
|
||||||
@@ -145,12 +144,14 @@ public class Player extends Unit{
|
|||||||
|
|
||||||
//Draw.alpha(hitTime / hitDuration);
|
//Draw.alpha(hitTime / hitDuration);
|
||||||
|
|
||||||
for(int i : Mathf.signs){
|
if(!mech.flying) {
|
||||||
tr.trns(footRotation, ft * i);
|
for (int i : Mathf.signs) {
|
||||||
Draw.rect(mname + "-leg", x + tr.x, y + tr.y, 12f * i, 12f - Mathf.clamp(ft*i, 0, 2), footRotation- 90);
|
tr.trns(baseRotation, ft * i);
|
||||||
}
|
Draw.rect(mname + "-leg", x + tr.x, y + tr.y, 12f * i, 12f - Mathf.clamp(ft * i, 0, 2), baseRotation - 90);
|
||||||
|
}
|
||||||
|
|
||||||
Draw.rect(mname + "-base", x, y,footRotation- 90);
|
Draw.rect(mname + "-base", x, y,baseRotation- 90);
|
||||||
|
}
|
||||||
|
|
||||||
Draw.rect(mname, x, y, rotation -90);
|
Draw.rect(mname, x, y, rotation -90);
|
||||||
|
|
||||||
@@ -252,7 +253,7 @@ public class Player extends Unit{
|
|||||||
|
|
||||||
if(!movement.isZero()){
|
if(!movement.isZero()){
|
||||||
walktime += Timers.delta();
|
walktime += Timers.delta();
|
||||||
footRotation = Mathf.slerpDelta(footRotation, movement.angle(), 0.13f);
|
baseRotation = Mathf.slerpDelta(baseRotation, movement.angle(), 0.13f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!shooting){
|
if(!shooting){
|
||||||
@@ -318,6 +319,7 @@ public class Player extends Unit{
|
|||||||
data.putFloat(interpolator.target.y);
|
data.putFloat(interpolator.target.y);
|
||||||
}
|
}
|
||||||
data.putFloat(rotation);
|
data.putFloat(rotation);
|
||||||
|
data.putFloat(baseRotation);
|
||||||
data.putShort((short)health);
|
data.putShort((short)health);
|
||||||
data.put((byte)(dashing ? 1 : 0));
|
data.put((byte)(dashing ? 1 : 0));
|
||||||
}
|
}
|
||||||
@@ -326,14 +328,15 @@ public class Player extends Unit{
|
|||||||
public void read(ByteBuffer data, long time) {
|
public void read(ByteBuffer data, long time) {
|
||||||
float x = data.getFloat();
|
float x = data.getFloat();
|
||||||
float y = data.getFloat();
|
float y = data.getFloat();
|
||||||
float angle = data.getFloat();
|
float rot = data.getFloat();
|
||||||
|
float baseRot = data.getFloat();
|
||||||
short health = data.getShort();
|
short health = data.getShort();
|
||||||
byte dashing = data.get();
|
byte dashing = data.get();
|
||||||
|
|
||||||
this.health = health;
|
this.health = health;
|
||||||
this.dashing = dashing == 1;
|
this.dashing = dashing == 1;
|
||||||
|
|
||||||
interpolator.read(this.x, this.y, x, y, angle, time);
|
interpolator.read(this.x, this.y, x, y, rot, baseRot, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,8 +18,11 @@ public abstract class SyncEntity extends DestructibleEntity{
|
|||||||
protected Interpolator interpolator = new Interpolator();
|
protected Interpolator interpolator = new Interpolator();
|
||||||
/**smoothed position and rotation*/
|
/**smoothed position and rotation*/
|
||||||
private Vector3 spos = new Vector3();
|
private Vector3 spos = new Vector3();
|
||||||
/**the general rotation.*/
|
|
||||||
|
/**rotation of the top, usually used as the 'shoot' direction.*/
|
||||||
public float rotation;
|
public float rotation;
|
||||||
|
/**rotation of the base, usually leg rotation for mechs.*/
|
||||||
|
public float baseRotation;
|
||||||
|
|
||||||
/**Called when a death event is recieved remotely.*/
|
/**Called when a death event is recieved remotely.*/
|
||||||
public abstract void onRemoteDeath();
|
public abstract void onRemoteDeath();
|
||||||
@@ -42,6 +45,7 @@ public abstract class SyncEntity extends DestructibleEntity{
|
|||||||
x = interpolator.pos.x;
|
x = interpolator.pos.x;
|
||||||
y = interpolator.pos.y;
|
y = interpolator.pos.y;
|
||||||
rotation = interpolator.rotation;
|
rotation = interpolator.rotation;
|
||||||
|
baseRotation = interpolator.baseRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Same as draw, but for interpolated drawing at low tick speeds.*/
|
/**Same as draw, but for interpolated drawing at low tick speeds.*/
|
||||||
@@ -93,16 +97,17 @@ public abstract class SyncEntity extends DestructibleEntity{
|
|||||||
//used for movement
|
//used for movement
|
||||||
public Vector2 target = new Vector2();
|
public Vector2 target = new Vector2();
|
||||||
public Vector2 last = new Vector2();
|
public Vector2 last = new Vector2();
|
||||||
public float targetrot;
|
public float targetrot, targetBaseRot;
|
||||||
public float spacing = 1f;
|
public float spacing = 1f;
|
||||||
public float time;
|
public float time;
|
||||||
|
|
||||||
//current state
|
//current state
|
||||||
public Vector2 pos = new Vector2();
|
public Vector2 pos = new Vector2();
|
||||||
public float rotation;
|
public float rotation, baseRotation;
|
||||||
|
|
||||||
public void read(float cx, float cy, float x, float y, float angle, long sent){
|
public void read(float cx, float cy, float x, float y, float rotation, float baseRotation, long sent){
|
||||||
targetrot = angle;
|
targetrot = rotation;
|
||||||
|
targetBaseRot = baseRotation;
|
||||||
time = 0f;
|
time = 0f;
|
||||||
last.set(cx, cy);
|
last.set(cx, cy);
|
||||||
target.set(x, y);
|
target.set(x, y);
|
||||||
@@ -117,6 +122,7 @@ public abstract class SyncEntity extends DestructibleEntity{
|
|||||||
Mathf.lerp2(pos.set(last), target, time);
|
Mathf.lerp2(pos.set(last), target, time);
|
||||||
|
|
||||||
rotation = Mathf.slerpDelta(rotation, targetrot, 0.6f);
|
rotation = Mathf.slerpDelta(rotation, targetrot, 0.6f);
|
||||||
|
baseRotation = Mathf.slerpDelta(baseRotation, targetBaseRot, 0.6f);
|
||||||
|
|
||||||
if(target.dst(pos) > 128){
|
if(target.dst(pos) > 128){
|
||||||
pos.set(target);
|
pos.set(target);
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package io.anuke.mindustry.entities.units;
|
||||||
|
|
||||||
|
import io.anuke.ucore.graphics.Draw;
|
||||||
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
import io.anuke.ucore.util.Translator;
|
||||||
|
|
||||||
|
public abstract class GroundUnitType extends UnitType{
|
||||||
|
protected Translator tr = new Translator();
|
||||||
|
|
||||||
|
public GroundUnitType(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(BaseUnit unit) {
|
||||||
|
float walktime = 0; //TODO!
|
||||||
|
|
||||||
|
float ft = Mathf.sin(walktime, 6f, 2f);
|
||||||
|
|
||||||
|
for (int i : Mathf.signs) {
|
||||||
|
tr.trns(unit.baseRotation, ft * i);
|
||||||
|
Draw.rect(name + "-leg", unit.x + tr.x, unit.y + tr.y, 12f * i, 12f - Mathf.clamp(ft * i, 0, 2), unit.baseRotation - 90);
|
||||||
|
}
|
||||||
|
|
||||||
|
Draw.rect(name + "-base", unit.x, unit.y, unit.baseRotation- 90);
|
||||||
|
|
||||||
|
Draw.rect(name, unit.x, unit.y, unit.rotation -90);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void behavior(BaseUnit unit) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,17 @@ package io.anuke.mindustry.entities.units;
|
|||||||
|
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import io.anuke.mindustry.entities.BulletType;
|
import io.anuke.mindustry.entities.BulletType;
|
||||||
|
import io.anuke.mindustry.graphics.Fx;
|
||||||
|
import io.anuke.mindustry.net.Net;
|
||||||
|
import io.anuke.mindustry.net.NetEvents;
|
||||||
|
import io.anuke.ucore.core.Effects;
|
||||||
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
import static io.anuke.mindustry.Vars.world;
|
import static io.anuke.mindustry.Vars.world;
|
||||||
|
|
||||||
public class UnitType {
|
public abstract class UnitType {
|
||||||
private static byte lastid = 0;
|
private static byte lastid = 0;
|
||||||
private static Array<UnitType> types = new Array<>();
|
private static Array<UnitType> types = new Array<>();
|
||||||
|
|
||||||
@@ -22,6 +27,7 @@ public class UnitType {
|
|||||||
protected float rotatespeed = 0.1f;
|
protected float rotatespeed = 0.1f;
|
||||||
protected float mass = 1f;
|
protected float mass = 1f;
|
||||||
protected boolean isFlying;
|
protected boolean isFlying;
|
||||||
|
protected float drag = 0.1f;
|
||||||
|
|
||||||
public UnitType(String name){
|
public UnitType(String name){
|
||||||
this.id = lastid++;
|
this.id = lastid++;
|
||||||
@@ -29,53 +35,56 @@ public class UnitType {
|
|||||||
types.add(this);
|
types.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(BaseUnit enemy){
|
public abstract void draw(BaseUnit unit);
|
||||||
|
|
||||||
|
public void drawOver(BaseUnit unit){
|
||||||
|
//TODO doesn't do anything
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(BaseUnit unit){
|
||||||
|
if(Net.client()){
|
||||||
|
unit.interpolate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO logic
|
||||||
|
|
||||||
|
unit.x += unit.velocity.x / mass;
|
||||||
|
unit.y += unit.velocity.y / mass;
|
||||||
|
|
||||||
|
unit.velocity.scl(Mathf.clamp(1f-drag* Timers.delta()));
|
||||||
|
|
||||||
|
behavior(unit);
|
||||||
|
|
||||||
|
unit.x = Mathf.clamp(unit.x, 0, world.width() * tilesize);
|
||||||
|
unit.y = Mathf.clamp(unit.y, 0, world.height() * tilesize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void behavior(BaseUnit unit);
|
||||||
|
|
||||||
|
public void updateTargeting(BaseUnit unit){
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawOver(BaseUnit enemy){
|
public void onShoot(BaseUnit unit, BulletType type, float rotation){
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(BaseUnit enemy){
|
public void onDeath(BaseUnit unit){
|
||||||
//TODO
|
//TODO other things, such as enemies?
|
||||||
enemy.x = Mathf.clamp(enemy.x, 0, world.width() * tilesize);
|
Effects.effect(Fx.explosion, unit);
|
||||||
enemy.y = Mathf.clamp(enemy.y, 0, world.height() * tilesize);
|
|
||||||
|
if(Net.server()){
|
||||||
|
NetEvents.handleUnitDeath(unit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void move(BaseUnit enemy){
|
public void onRemoteDeath(BaseUnit unit){
|
||||||
//TODO
|
onDeath(unit);
|
||||||
|
unit.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void behavior(BaseUnit enemy){
|
public void removed(BaseUnit unit){
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateTargeting(BaseUnit enemy){
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateShooting(BaseUnit enemy){
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shoot(BaseUnit enemy){
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onShoot(BaseUnit enemy, BulletType type, float rotation){
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDeath(BaseUnit enemy){
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onRemoteDeath(BaseUnit enemy){
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removed(BaseUnit enemy){
|
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import com.badlogic.gdx.graphics.Color;
|
|||||||
|
|
||||||
public enum Team {
|
public enum Team {
|
||||||
none(Color.DARK_GRAY),
|
none(Color.DARK_GRAY),
|
||||||
blue(Color.BLUE),
|
blue(Color.ROYAL),
|
||||||
red(Color.RED);
|
red(Color.SCARLET);
|
||||||
|
|
||||||
public final Color color;
|
public final Color color;
|
||||||
|
|
||||||
|
|||||||
@@ -28,11 +28,10 @@ public class NetEvents {
|
|||||||
Net.send(new GameOverPacket(), SendMode.tcp);
|
Net.send(new GameOverPacket(), SendMode.tcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void handleUnitDeath(Unit entity){
|
||||||
public static void handleUnitDeath(Unit enemy){
|
|
||||||
EntityDeathPacket packet = new EntityDeathPacket();
|
EntityDeathPacket packet = new EntityDeathPacket();
|
||||||
packet.id = enemy.id;
|
packet.id = entity.id;
|
||||||
packet.group = (byte)enemy.getGroup().getID();
|
packet.group = (byte)entity.getGroup().getID();
|
||||||
Net.send(packet, SendMode.tcp);
|
Net.send(packet, SendMode.tcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,12 +48,6 @@ public class NetEvents {
|
|||||||
Net.send(packet, SendMode.udp);
|
Net.send(packet, SendMode.udp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handlePlayerDeath(){
|
|
||||||
EntityDeathPacket packet = new EntityDeathPacket();
|
|
||||||
packet.id = Vars.player.id;
|
|
||||||
Net.send(packet, SendMode.tcp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handleBlockConfig(Tile tile, byte data){
|
public static void handleBlockConfig(Tile tile, byte data){
|
||||||
BlockConfigPacket packet = new BlockConfigPacket();
|
BlockConfigPacket packet = new BlockConfigPacket();
|
||||||
packet.data = data;
|
packet.data = data;
|
||||||
|
|||||||
Reference in New Issue
Block a user