mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 11:17:11 +07:00
circles were a mistake
This commit is contained in:
parent
40008f44ac
commit
f175bf2c82
@ -67,6 +67,7 @@ public class UnitTypes implements ContentList{
|
||||
maxVelocity = 0.8f;
|
||||
speed = 0.15f;
|
||||
drag = 0.4f;
|
||||
mass = 4f;
|
||||
range = 10f;
|
||||
rotatespeed = 0.06f;
|
||||
weaponOffsetX = 1;
|
||||
@ -97,7 +98,8 @@ public class UnitTypes implements ContentList{
|
||||
revenant = new UnitType("revenant", Revenant.class, Revenant::new){{
|
||||
health = 250;
|
||||
mass = 4f;
|
||||
speed = 0.14f*mass;
|
||||
hitsize = 12f;
|
||||
speed = 0.14f;
|
||||
maxVelocity = 1.4f;
|
||||
drag = 0.01f;
|
||||
isFlying = true;
|
||||
|
@ -10,9 +10,9 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.Unlocks;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.Saves;
|
||||
import io.anuke.mindustry.game.Unlocks;
|
||||
import io.anuke.mindustry.input.DefaultKeybinds;
|
||||
import io.anuke.mindustry.input.DesktopInput;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
|
@ -166,8 +166,14 @@ public class Logic extends Module{
|
||||
}
|
||||
|
||||
for(EntityGroup group : unitGroups){
|
||||
if(!group.isEmpty()){
|
||||
EntityQuery.collideGroups(bulletGroup, group);
|
||||
if(group.isEmpty()) continue;
|
||||
|
||||
EntityQuery.collideGroups(bulletGroup, group);
|
||||
EntityQuery.collideGroups(group, playerGroup);
|
||||
|
||||
for(EntityGroup other : unitGroups){
|
||||
if(other == group || other.isEmpty()) continue;
|
||||
EntityQuery.collideGroups(group, other);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
@ -31,7 +30,6 @@ import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.impl.EffectEntity;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.entities.trait.Entity;
|
||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.function.Predicate;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
@ -340,45 +338,7 @@ public class Renderer extends RendererModule{
|
||||
}
|
||||
|
||||
public <T extends DrawTrait> void drawAndInterpolate(EntityGroup<T> group, Predicate<T> toDraw, Consumer<T> drawer){
|
||||
EntityDraw.drawWith(group, toDraw, t -> {
|
||||
float lastx = t.getX(), lasty = t.getY(), lastrot = 0f;
|
||||
|
||||
if(threads.doInterpolate() && threads.isEnabled() && t instanceof SolidTrait){
|
||||
SolidTrait s = (SolidTrait) t;
|
||||
|
||||
lastrot = s.getRotation();
|
||||
|
||||
if(s.lastUpdated() != 0){
|
||||
float timeSinceUpdate = TimeUtils.timeSinceMillis(s.lastUpdated());
|
||||
float alpha = Math.min(timeSinceUpdate / s.updateSpacing(), 1f);
|
||||
|
||||
tmpVector1.set(s.lastPosition().x, s.lastPosition().y)
|
||||
.lerp(tmpVector2.set(lastx, lasty), alpha);
|
||||
s.setRotation(Mathf.slerp(s.lastPosition().z, lastrot, alpha));
|
||||
|
||||
s.setX(tmpVector1.x);
|
||||
s.setY(tmpVector1.y);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO extremely hacky
|
||||
if(t instanceof Player && ((Player) t).getCarry() != null && ((Player) t).getCarry() instanceof Player && ((Player) ((Player) t).getCarry()).isLocal){
|
||||
((Player) t).x = ((Player) t).getCarry().getX();
|
||||
((Player) t).y = ((Player) t).getCarry().getY();
|
||||
}
|
||||
|
||||
drawer.accept(t);
|
||||
|
||||
t.setX(lastx);
|
||||
t.setY(lasty);
|
||||
|
||||
if(threads.doInterpolate() && threads.isEnabled()){
|
||||
|
||||
if(t instanceof SolidTrait){
|
||||
((SolidTrait) t).setRotation(lastrot);
|
||||
}
|
||||
}
|
||||
});
|
||||
EntityDraw.drawWith(group, toDraw, drawer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -232,6 +232,21 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxVelocity(){
|
||||
return mech.maxSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<BuildRequest> getPlaceQueue(){
|
||||
return placeQueue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "Player{" + id + ", mech=" + mech.name + ", local=" + isLocal + ", " + x + ", " + y + "}\n";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed(){
|
||||
dropCarryLocal();
|
||||
@ -440,10 +455,11 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
hitTime -= Timers.delta();
|
||||
|
||||
if(Float.isNaN(x) || Float.isNaN(y)){
|
||||
TileEntity core = getClosestCore();
|
||||
if(core != null){
|
||||
set(core.x, core.y);
|
||||
}
|
||||
//throw new RuntimeException("NaN found!");
|
||||
velocity.set(0f, 0f);
|
||||
x = 0;
|
||||
y = 0;
|
||||
setDead(true);
|
||||
}
|
||||
|
||||
if(isDead()){
|
||||
@ -465,7 +481,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
interpolate();
|
||||
updateBuilding(this); //building happens even with non-locals
|
||||
status.update(this); //status effect updating also happens with non locals for effect purposes
|
||||
updateVelocityStatus(mech.drag, mech.maxSpeed); //velocity too, for visual purposes
|
||||
updateVelocityStatus(); //velocity too, for visual purposes
|
||||
|
||||
if(getCarrier() != null){
|
||||
x = getCarrier().getX();
|
||||
@ -570,7 +586,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
velocity.add(movement);
|
||||
}
|
||||
float prex = x, prey = y;
|
||||
updateVelocityStatus(mech.drag, mech.maxSpeed);
|
||||
updateVelocityStatus();
|
||||
moved = distanceTo(prex, prey) > 0.01f;
|
||||
}else{
|
||||
velocity.setZero();
|
||||
@ -644,7 +660,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
rotation = Mathf.slerpDelta(rotation, velocity.angle(), velocity.len() / 10f);
|
||||
}
|
||||
|
||||
updateVelocityStatus(mech.drag, mech.maxSpeed);
|
||||
updateVelocityStatus();
|
||||
|
||||
//hovering effect
|
||||
x += Mathf.sin(Timers.time() + id * 999, 25f, 0.08f);
|
||||
@ -734,16 +750,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
this.dead = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<BuildRequest> getPlaceQueue(){
|
||||
return placeQueue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "Player{" + id + ", mech=" + mech.name + ", local=" + isLocal + ", " + x + ", " + y + "}\n";
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region read and write methods
|
||||
|
@ -16,14 +16,12 @@ import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.impl.DestructibleEntity;
|
||||
import io.anuke.ucore.entities.trait.DamageTrait;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Fill;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@ -39,7 +37,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
public static final float velocityPercision = 8f;
|
||||
/**Maximum absolute value of a velocity vector component.*/
|
||||
public static final float maxAbsVelocity = 127f / velocityPercision;
|
||||
private static final Vector2 moveVector = new Vector2();
|
||||
|
||||
public UnitInventory inventory = new UnitInventory(this);
|
||||
public float rotation;
|
||||
@ -50,7 +47,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
protected Team team = Team.blue;
|
||||
|
||||
protected CarryTrait carrier;
|
||||
protected Vector2 velocity = new Translator(0f, 0.0001f);
|
||||
protected float drownTime;
|
||||
|
||||
@Override
|
||||
@ -58,16 +54,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRotation(){
|
||||
return rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(float rotation){
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarryTrait getCarrier(){
|
||||
return carrier;
|
||||
@ -108,8 +94,8 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
|
||||
@Override
|
||||
public boolean collides(SolidTrait other){
|
||||
return other instanceof DamageTrait && other
|
||||
instanceof TeamTrait && state.teams.areEnemies((((TeamTrait) other).getTeam()), team) && !isDead();
|
||||
return true;//other instanceof DamageTrait && other
|
||||
// instanceof TeamTrait && state.teams.areEnemies((((TeamTrait) other).getTeam()), team) && !isDead();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,10 +179,9 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
}
|
||||
|
||||
/**Updates velocity and status effects.*/
|
||||
public void updateVelocityStatus(float drag, float maxVelocity){
|
||||
public void updateVelocityStatus(){
|
||||
Floor floor = getFloorOn();
|
||||
|
||||
|
||||
if(isCarried()){ //carried units do not take into account velocity normally
|
||||
set(carrier.getX(), carrier.getY());
|
||||
velocity.set(carrier.getVelocity());
|
||||
@ -207,7 +192,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
|
||||
status.update(this);
|
||||
|
||||
velocity.limit(maxVelocity).scl(status.getSpeedMultiplier());
|
||||
velocity.limit(getMaxVelocity()).scl(status.getSpeedMultiplier());
|
||||
|
||||
if(isFlying()){
|
||||
x += velocity.x / getMass() * Timers.delta();
|
||||
@ -255,12 +240,12 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
}
|
||||
|
||||
float px = x, py = y;
|
||||
move(velocity.x / getMass() * floor.speedMultiplier * Timers.delta(), velocity.y / getMass() * floor.speedMultiplier * Timers.delta());
|
||||
move(velocity.x * floor.speedMultiplier * Timers.delta(), velocity.y * floor.speedMultiplier * Timers.delta());
|
||||
if(Math.abs(px - x) <= 0.0001f) velocity.x = 0f;
|
||||
if(Math.abs(py - y) <= 0.0001f) velocity.y = 0f;
|
||||
}
|
||||
|
||||
velocity.scl(Mathf.clamp(1f - drag * (isFlying() ? 1f : floor.dragMultiplier) * Timers.delta()));
|
||||
velocity.scl(Mathf.clamp(1f - getDrag() * (isFlying() ? 1f : floor.dragMultiplier) * Timers.delta()));
|
||||
}
|
||||
|
||||
public void applyEffect(StatusEffect effect, float intensity){
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.entities.bullet;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
@ -69,15 +68,9 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
|
||||
bullet.type = type;
|
||||
bullet.lifeScl = lifetimeScl;
|
||||
|
||||
//translate bullets backwards, purely for visual reasons
|
||||
float backDelta = Timers.delta();
|
||||
|
||||
bullet.lastPosition().set(x - bullet.velocity.x * backDelta, y - bullet.velocity.y * backDelta, bullet.angle());
|
||||
bullet.setLastUpdated(TimeUtils.millis());
|
||||
bullet.setUpdateSpacing((long) ((Timers.delta() / 60f) * 1000));
|
||||
bullet.set(x, y);
|
||||
|
||||
bullet.add();
|
||||
|
||||
return bullet;
|
||||
}
|
||||
|
||||
@ -199,7 +192,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
|
||||
super.update();
|
||||
|
||||
if(type.hitTiles && collidesTiles() && !supressCollision && initialized){
|
||||
world.raycastEach(world.toTile(lastPosition().x), world.toTile(lastPosition().y), world.toTile(x), world.toTile(y), (x, y) -> {
|
||||
world.raycastEach(world.toTile(x), world.toTile(y), world.toTile(x + velocity.x), world.toTile(y + velocity.y), (x, y) -> {
|
||||
|
||||
Tile tile = world.tile(x, y);
|
||||
if(tile == null) return false;
|
||||
|
@ -114,6 +114,8 @@ public class Lightning extends SolidEntity implements Poolable, DrawTrait, SyncT
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void getHitbox(Rectangle rectangle){}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package io.anuke.mindustry.entities.traits;
|
||||
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.ucore.entities.trait.PosTrait;
|
||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
import io.anuke.ucore.entities.trait.VelocityTrait;
|
||||
|
||||
/**
|
||||
@ -15,19 +14,11 @@ public interface TargetTrait extends PosTrait, VelocityTrait{
|
||||
Team getTeam();
|
||||
|
||||
default float getTargetVelocityX(){
|
||||
if(this instanceof SolidTrait){
|
||||
return getX() - ((SolidTrait) this).lastPosition().x;
|
||||
}else{
|
||||
return getVelocity().x;
|
||||
}
|
||||
return getVelocity().x;
|
||||
}
|
||||
|
||||
default float getTargetVelocityY(){
|
||||
if(this instanceof SolidTrait){
|
||||
return getY() - ((SolidTrait) this).lastPosition().y;
|
||||
}else{
|
||||
return getVelocity().y;
|
||||
}
|
||||
return getVelocity().y;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -319,7 +319,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
updateTargeting();
|
||||
|
||||
state.update();
|
||||
updateVelocityStatus(type.drag, type.maxVelocity);
|
||||
updateVelocityStatus();
|
||||
|
||||
if(target != null) behavior();
|
||||
|
||||
@ -344,6 +344,11 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxVelocity(){
|
||||
return type.maxVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed(){
|
||||
spawner = -1;
|
||||
|
@ -119,7 +119,7 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
public void update(){
|
||||
super.update();
|
||||
|
||||
stuckTime = !vec.set(x, y).sub(lastPosition().x, lastPosition().y).isZero(0.0001f) ? 0f : stuckTime + Timers.delta();
|
||||
stuckTime = !getVelocity().isZero(0.0001f) ? 0f : stuckTime + Timers.delta();
|
||||
|
||||
if(!velocity.isZero(0.0001f) && (Units.invalidateTarget(target, this) || (distanceTo(target) > getWeapon().getAmmo().getRange()))){
|
||||
rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.rotatespeed);
|
||||
|
@ -57,7 +57,7 @@ public class DeflectorWall extends Wall{
|
||||
|
||||
bullet.getHitbox(rect2);
|
||||
|
||||
Vector2 position = Physics.raycastRect(bullet.lastPosition().x, bullet.lastPosition().y, bullet.x, bullet.y,
|
||||
Vector2 position = Physics.raycastRect(bullet.x, bullet.y, bullet.x + bullet.getVelocity().x, bullet.y + bullet.getVelocity().y,
|
||||
rect.setCenter(entity.x, entity.y).setSize(size * tilesize + rect2.width + rect2.height));
|
||||
|
||||
if(position != null){
|
||||
@ -70,7 +70,7 @@ public class DeflectorWall extends Wall{
|
||||
bullet.getVelocity().y *= -1;
|
||||
}
|
||||
|
||||
bullet.updateVelocity(0f);
|
||||
bullet.updateVelocity();
|
||||
bullet.resetOwner(entity, Team.none);
|
||||
bullet.scaleTime(1f);
|
||||
bullet.supress();
|
||||
|
Loading…
Reference in New Issue
Block a user