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