mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-14 17:57:56 +07:00
Trail experiment
This commit is contained in:
@ -11,6 +11,7 @@ mindustry.entities.def.PuddleComp=7
|
|||||||
mindustry.entities.def.TileComp=8
|
mindustry.entities.def.TileComp=8
|
||||||
mindustry.type.Weather.WeatherComp=9
|
mindustry.type.Weather.WeatherComp=9
|
||||||
phantom=10
|
phantom=10
|
||||||
|
reaper=14
|
||||||
titan=13
|
titan=13
|
||||||
vanguard=11
|
vanguard=11
|
||||||
wraith=12
|
wraith=12
|
@ -0,0 +1 @@
|
|||||||
|
{fields:[{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
|
@ -49,9 +49,8 @@ public class PhysicsProcess implements AsyncProcess{
|
|||||||
//add bodies to entities that have none
|
//add bodies to entities that have none
|
||||||
FixtureDef fd = new FixtureDef();
|
FixtureDef fd = new FixtureDef();
|
||||||
fd.shape = new CircleShape(entity.hitSize() / 2f);
|
fd.shape = new CircleShape(entity.hitSize() / 2f);
|
||||||
//TODO does this scale well?
|
fd.density = 5f;
|
||||||
fd.density = 5f; //5.0f * entity.mass();
|
fd.restitution = 0.0f;
|
||||||
fd.restitution = 0.05f;
|
|
||||||
fd.filter.maskBits = fd.filter.categoryBits = (grounded ? ground : flying).maskBits;
|
fd.filter.maskBits = fd.filter.categoryBits = (grounded ? ground : flying).maskBits;
|
||||||
|
|
||||||
def.position.set(entity);
|
def.position.set(entity);
|
||||||
@ -93,6 +92,8 @@ public class PhysicsProcess implements AsyncProcess{
|
|||||||
|
|
||||||
//write velocity
|
//write velocity
|
||||||
ref.body.setLinearVelocity(ref.velocity);
|
ref.body.setLinearVelocity(ref.velocity);
|
||||||
|
|
||||||
|
ref.lastVelocity.set(ref.velocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
physics.step(Core.graphics.getDeltaTime(), 8, 8);
|
physics.step(Core.graphics.getDeltaTime(), 8, 8);
|
||||||
@ -101,6 +102,8 @@ public class PhysicsProcess implements AsyncProcess{
|
|||||||
for(PhysicRef ref : refs){
|
for(PhysicRef ref : refs){
|
||||||
//get delta vector
|
//get delta vector
|
||||||
ref.delta.set(ref.body.getPosition()).sub(ref.lastPosition);
|
ref.delta.set(ref.body.getPosition()).sub(ref.lastPosition);
|
||||||
|
|
||||||
|
ref.velocity.set(ref.body.getLinearVelocity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +119,8 @@ public class PhysicsProcess implements AsyncProcess{
|
|||||||
|
|
||||||
//save last position
|
//save last position
|
||||||
ref.position.set(entity);
|
ref.position.set(entity);
|
||||||
|
|
||||||
|
entity.vel().add(ref.velocity).sub(ref.lastVelocity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +144,7 @@ public class PhysicsProcess implements AsyncProcess{
|
|||||||
Physicsc entity;
|
Physicsc entity;
|
||||||
Body body;
|
Body body;
|
||||||
boolean wasGround = true;
|
boolean wasGround = true;
|
||||||
Vec2 lastPosition = new Vec2(), delta = new Vec2(), velocity = new Vec2(), position = new Vec2();
|
Vec2 lastPosition = new Vec2(), delta = new Vec2(), velocity = new Vec2(), lastVelocity = new Vec2(), position = new Vec2();
|
||||||
|
|
||||||
public PhysicRef(Physicsc entity, Body body){
|
public PhysicRef(Physicsc entity, Body body){
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
|
@ -17,7 +17,7 @@ public class UnitTypes implements ContentList{
|
|||||||
public static @EntityDef({Unitc.class, Legsc.class}) UnitType dagger;
|
public static @EntityDef({Unitc.class, Legsc.class}) UnitType dagger;
|
||||||
public static @EntityDef({Unitc.class, WaterMovec.class}) UnitType vanguard;
|
public static @EntityDef({Unitc.class, WaterMovec.class}) UnitType vanguard;
|
||||||
public static @EntityDef({Unitc.class, Minerc.class}) UnitType draug;
|
public static @EntityDef({Unitc.class, Minerc.class}) UnitType draug;
|
||||||
public static @EntityDef({Unitc.class}) UnitType wraith;
|
public static @EntityDef({Unitc.class, Trailc.class}) UnitType wraith;
|
||||||
public static @EntityDef({Unitc.class}) UnitType reaper;
|
public static @EntityDef({Unitc.class}) UnitType reaper;
|
||||||
public static @EntityDef({Unitc.class}) UnitType spirit;
|
public static @EntityDef({Unitc.class}) UnitType spirit;
|
||||||
public static @EntityDef({Unitc.class, Builderc.class}) UnitType phantom;
|
public static @EntityDef({Unitc.class, Builderc.class}) UnitType phantom;
|
||||||
@ -86,9 +86,9 @@ public class UnitTypes implements ContentList{
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
reaper = new UnitType("reaper"){{
|
reaper = new UnitType("reaper"){{
|
||||||
speed = 1f;
|
speed = 1.1f;
|
||||||
accel = 0.08f;
|
accel = 0.08f;
|
||||||
drag = 0f;
|
drag = 0.05f;
|
||||||
mass = 30f;
|
mass = 30f;
|
||||||
flying = true;
|
flying = true;
|
||||||
health = 75000;
|
health = 75000;
|
||||||
|
9
core/src/mindustry/entities/def/TrailComp.java
Normal file
9
core/src/mindustry/entities/def/TrailComp.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package mindustry.entities.def;
|
||||||
|
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
|
import mindustry.graphics.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
abstract class TrailComp{
|
||||||
|
transient Trail trail = new Trail();
|
||||||
|
}
|
43
core/src/mindustry/graphics/Trail.java
Normal file
43
core/src/mindustry/graphics/Trail.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package mindustry.graphics;
|
||||||
|
|
||||||
|
import arc.graphics.*;
|
||||||
|
import arc.graphics.g2d.*;
|
||||||
|
import arc.math.*;
|
||||||
|
import arc.math.geom.*;
|
||||||
|
import arc.struct.*;
|
||||||
|
import arc.util.pooling.*;
|
||||||
|
|
||||||
|
public class Trail{
|
||||||
|
private static final int length = 20;
|
||||||
|
private Array<Vec3> points = new Array<>();
|
||||||
|
private float lastX = -1, lastY = -1;
|
||||||
|
|
||||||
|
public void draw(Color color, float width){
|
||||||
|
Draw.color(color);
|
||||||
|
|
||||||
|
for(int i = 0; i < points.size - 1; i++){
|
||||||
|
Vec3 c = points.get(i);
|
||||||
|
Vec3 n = points.get(i + 1);
|
||||||
|
float size = width * 1f / length;
|
||||||
|
|
||||||
|
float cx = Mathf.sin(c.z) * i * size, cy = Mathf.cos(c.z) * i * size, nx = Mathf.sin(n.z) * (i + 1) * size, ny = Mathf.cos(n.z) * (i + 1) * size;
|
||||||
|
Fill.quad(c.x - cx, c.y - cy, c.x + cx, c.y + cy, n.x + nx, n.y + ny, n.x - nx, n.y - ny);
|
||||||
|
}
|
||||||
|
|
||||||
|
Draw.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(float x, float y){
|
||||||
|
if(points.size > length){
|
||||||
|
Pools.free(points.first());
|
||||||
|
points.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float angle = -Angles.angle(x, y, lastX, lastY);
|
||||||
|
|
||||||
|
points.add(Pools.obtain(Vec3.class, Vec3::new).set(x, y, (angle) * Mathf.degRad));
|
||||||
|
|
||||||
|
lastX = x;
|
||||||
|
lastY = y;
|
||||||
|
}
|
||||||
|
}
|
@ -542,7 +542,11 @@ public class DesktopInput extends InputHandler{
|
|||||||
unit.lookAt(mouseAngle);
|
unit.lookAt(mouseAngle);
|
||||||
}else{
|
}else{
|
||||||
if(!unit.vel().isZero(0.01f)){
|
if(!unit.vel().isZero(0.01f)){
|
||||||
unit.lookAt(unit.vel().angle());
|
if(unit.type().flying){
|
||||||
|
unit.rotation(unit.vel().angle());
|
||||||
|
}else{
|
||||||
|
unit.lookAt(unit.vel().angle());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +189,15 @@ public class UnitType extends UnlockableContent{
|
|||||||
public void drawEngine(Unitc unit){
|
public void drawEngine(Unitc unit){
|
||||||
if(!unit.isFlying()) return;
|
if(!unit.isFlying()) return;
|
||||||
|
|
||||||
|
if(unit instanceof Trailc){
|
||||||
|
Trail trail = ((Trailc)unit).trail();
|
||||||
|
|
||||||
|
float cx = unit.x() + Angles.trnsx(unit.rotation() + 180, engineOffset),
|
||||||
|
cy = unit.y() + Angles.trnsy(unit.rotation() + 180, engineOffset);
|
||||||
|
trail.update(cx, cy);
|
||||||
|
trail.draw(unit.team().color, (engineSize + Mathf.absin(Time.time(), 2f, engineSize / 4f) * unit.elevation()));
|
||||||
|
}
|
||||||
|
|
||||||
Draw.color(unit.team().color);
|
Draw.color(unit.team().color);
|
||||||
Fill.circle(
|
Fill.circle(
|
||||||
unit.x() + Angles.trnsx(unit.rotation() + 180, engineOffset),
|
unit.x() + Angles.trnsx(unit.rotation() + 180, engineOffset),
|
||||||
|
Reference in New Issue
Block a user