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.type.Weather.WeatherComp=9
|
||||
phantom=10
|
||||
reaper=14
|
||||
titan=13
|
||||
vanguard=11
|
||||
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
|
||||
FixtureDef fd = new FixtureDef();
|
||||
fd.shape = new CircleShape(entity.hitSize() / 2f);
|
||||
//TODO does this scale well?
|
||||
fd.density = 5f; //5.0f * entity.mass();
|
||||
fd.restitution = 0.05f;
|
||||
fd.density = 5f;
|
||||
fd.restitution = 0.0f;
|
||||
fd.filter.maskBits = fd.filter.categoryBits = (grounded ? ground : flying).maskBits;
|
||||
|
||||
def.position.set(entity);
|
||||
@ -93,6 +92,8 @@ public class PhysicsProcess implements AsyncProcess{
|
||||
|
||||
//write velocity
|
||||
ref.body.setLinearVelocity(ref.velocity);
|
||||
|
||||
ref.lastVelocity.set(ref.velocity);
|
||||
}
|
||||
|
||||
physics.step(Core.graphics.getDeltaTime(), 8, 8);
|
||||
@ -101,6 +102,8 @@ public class PhysicsProcess implements AsyncProcess{
|
||||
for(PhysicRef ref : refs){
|
||||
//get delta vector
|
||||
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
|
||||
ref.position.set(entity);
|
||||
|
||||
entity.vel().add(ref.velocity).sub(ref.lastVelocity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +144,7 @@ public class PhysicsProcess implements AsyncProcess{
|
||||
Physicsc entity;
|
||||
Body body;
|
||||
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){
|
||||
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, WaterMovec.class}) UnitType vanguard;
|
||||
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 spirit;
|
||||
public static @EntityDef({Unitc.class, Builderc.class}) UnitType phantom;
|
||||
@ -86,9 +86,9 @@ public class UnitTypes implements ContentList{
|
||||
}};
|
||||
|
||||
reaper = new UnitType("reaper"){{
|
||||
speed = 1f;
|
||||
speed = 1.1f;
|
||||
accel = 0.08f;
|
||||
drag = 0f;
|
||||
drag = 0.05f;
|
||||
mass = 30f;
|
||||
flying = true;
|
||||
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);
|
||||
}else{
|
||||
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){
|
||||
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);
|
||||
Fill.circle(
|
||||
unit.x() + Angles.trnsx(unit.rotation() + 180, engineOffset),
|
||||
|
Reference in New Issue
Block a user