mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 23:28:52 +07:00
Circle collision initial commit
This commit is contained in:
parent
3f93b5c63b
commit
40008f44ac
@ -24,7 +24,7 @@ import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityPhysics;
|
||||
import io.anuke.ucore.entities.EntityQuery;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
import io.anuke.ucore.util.Atlas;
|
||||
|
||||
@ -302,7 +302,7 @@ public class Control extends Module{
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
EntityPhysics.initPhysics();
|
||||
EntityQuery.init();
|
||||
|
||||
Platform.instance.updateRPC();
|
||||
|
||||
|
@ -17,7 +17,7 @@ import io.anuke.ucore.core.Events;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.EntityPhysics;
|
||||
import io.anuke.ucore.entities.EntityQuery;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@ -39,8 +39,8 @@ public class Logic extends Module{
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
EntityPhysics.initPhysics();
|
||||
EntityPhysics.collisions().setCollider(tilesize, world::solid);
|
||||
EntityQuery.init();
|
||||
EntityQuery.collisions().setCollider(tilesize, world::solid);
|
||||
}
|
||||
|
||||
public void play(){
|
||||
@ -167,11 +167,11 @@ public class Logic extends Module{
|
||||
|
||||
for(EntityGroup group : unitGroups){
|
||||
if(!group.isEmpty()){
|
||||
EntityPhysics.collideGroups(bulletGroup, group);
|
||||
EntityQuery.collideGroups(bulletGroup, group);
|
||||
}
|
||||
}
|
||||
|
||||
EntityPhysics.collideGroups(bulletGroup, playerGroup);
|
||||
EntityQuery.collideGroups(bulletGroup, playerGroup);
|
||||
|
||||
world.pathfinder().update();
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.EntityPhysics;
|
||||
import io.anuke.ucore.entities.EntityQuery;
|
||||
import io.anuke.ucore.entities.trait.Entity;
|
||||
import io.anuke.ucore.io.ByteBufferOutput;
|
||||
import io.anuke.ucore.io.CountableByteArrayOutputStream;
|
||||
@ -508,7 +508,7 @@ public class NetServer extends Module{
|
||||
|
||||
returnArray.clear();
|
||||
if(represent.isClipped()){
|
||||
EntityPhysics.getNearby(group, viewport, entity -> {
|
||||
EntityQuery.getNearby(group, viewport, entity -> {
|
||||
if(((SyncTrait) entity).isSyncing() && viewport.contains(entity.getX(), entity.getY())){
|
||||
returnArray.add(entity);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import io.anuke.mindustry.maps.generation.WorldGenerator;
|
||||
import io.anuke.mindustry.world.blocks.OreBlock;
|
||||
import io.anuke.ucore.core.Events;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.EntityPhysics;
|
||||
import io.anuke.ucore.entities.EntityQuery;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
@ -222,7 +222,7 @@ public class World extends Module{
|
||||
}
|
||||
}
|
||||
|
||||
EntityPhysics.resizeTree(0, 0, tiles.length * tilesize, tiles[0].length * tilesize);
|
||||
EntityQuery.resizeTree(0, 0, tiles.length * tilesize, tiles[0].length * tilesize);
|
||||
|
||||
generating = false;
|
||||
Events.fire(new WorldLoadEvent());
|
||||
@ -251,7 +251,7 @@ public class World extends Module{
|
||||
Map map = new Map("Sector " + sector.x + ", " + sector.y, new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null);
|
||||
setMap(map);
|
||||
|
||||
EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize);
|
||||
EntityQuery.resizeTree(0, 0, width * tilesize, height * tilesize);
|
||||
|
||||
generator.generateMap(tiles, sector);
|
||||
|
||||
@ -267,7 +267,7 @@ public class World extends Module{
|
||||
|
||||
createTiles(width, height);
|
||||
|
||||
EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize);
|
||||
EntityQuery.resizeTree(0, 0, width * tilesize, height * tilesize);
|
||||
|
||||
try{
|
||||
generator.loadTileData(tiles, MapIO.readTileData(map, true), map.meta.hasOreGen(), 0);
|
||||
|
@ -487,10 +487,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
updateMech();
|
||||
}
|
||||
|
||||
if(isLocal){
|
||||
avoidOthers(8f);
|
||||
}
|
||||
|
||||
updateBuilding(this);
|
||||
|
||||
x = Mathf.clamp(x, 0, world.width() * tilesize);
|
||||
|
@ -15,7 +15,6 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.EntityPhysics;
|
||||
import io.anuke.ucore.entities.impl.DestructibleEntity;
|
||||
import io.anuke.ucore.entities.trait.DamageTrait;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
@ -193,17 +192,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
return tile == null ? (Floor) Blocks.air : tile.floor();
|
||||
}
|
||||
|
||||
public void avoidOthers(float avoidRange){
|
||||
|
||||
EntityPhysics.getNearby(getGroup(), x, y, avoidRange * 2f, t -> {
|
||||
if(t == this || (t instanceof Unit && (((Unit) t).isDead() || (((Unit) t).isFlying() != isFlying()) || ((Unit) t).getCarrier() == this) || getCarrier() == t))
|
||||
return;
|
||||
float dst = distanceTo(t);
|
||||
if(dst > avoidRange) return;
|
||||
velocity.add(moveVector.set(x, y).sub(t.getX(), t.getY()).setLength(1f * (1f - (dst / avoidRange)) / getMass()));
|
||||
});
|
||||
}
|
||||
|
||||
/**Updates velocity and status effects.*/
|
||||
public void updateVelocityStatus(float drag, float maxVelocity){
|
||||
Floor floor = getFloorOn();
|
||||
|
@ -8,7 +8,7 @@ import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.EntityPhysics;
|
||||
import io.anuke.ucore.entities.EntityQuery;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.function.Predicate;
|
||||
import io.anuke.ucore.util.EnumSet;
|
||||
@ -213,11 +213,11 @@ public class Units{
|
||||
|
||||
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
|
||||
if(!group.isEmpty()){
|
||||
EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit) entity));
|
||||
EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity));
|
||||
}
|
||||
|
||||
//now check all players
|
||||
EntityPhysics.getNearby(playerGroup, rect, player -> {
|
||||
EntityQuery.getNearby(playerGroup, rect, player -> {
|
||||
if(((Unit) player).team == team) cons.accept((Unit) player);
|
||||
});
|
||||
}
|
||||
@ -230,7 +230,7 @@ public class Units{
|
||||
|
||||
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
|
||||
if(!group.isEmpty()){
|
||||
EntityPhysics.getNearby(group, rect, entity -> {
|
||||
EntityQuery.getNearby(group, rect, entity -> {
|
||||
if(entity.distanceTo(x, y) <= radius){
|
||||
cons.accept((Unit) entity);
|
||||
}
|
||||
@ -238,7 +238,7 @@ public class Units{
|
||||
}
|
||||
|
||||
//now check all players
|
||||
EntityPhysics.getNearby(playerGroup, rect, player -> {
|
||||
EntityQuery.getNearby(playerGroup, rect, player -> {
|
||||
if(((Unit) player).team == team && player.distanceTo(x, y) <= radius){
|
||||
cons.accept((Unit) player);
|
||||
}
|
||||
@ -253,12 +253,12 @@ public class Units{
|
||||
for(Team team : Team.all){
|
||||
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
|
||||
if(!group.isEmpty()){
|
||||
EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit) entity));
|
||||
EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity));
|
||||
}
|
||||
}
|
||||
|
||||
//now check all enemy players
|
||||
EntityPhysics.getNearby(playerGroup, rect, player -> cons.accept((Unit) player));
|
||||
EntityQuery.getNearby(playerGroup, rect, player -> cons.accept((Unit) player));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,12 +270,12 @@ public class Units{
|
||||
for(Team other : targets){
|
||||
EntityGroup<BaseUnit> group = unitGroups[other.ordinal()];
|
||||
if(!group.isEmpty()){
|
||||
EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit) entity));
|
||||
EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity));
|
||||
}
|
||||
}
|
||||
|
||||
//now check all enemy players
|
||||
EntityPhysics.getNearby(playerGroup, rect, player -> {
|
||||
EntityQuery.getNearby(playerGroup, rect, player -> {
|
||||
if(targets.contains(((Player) player).team)){
|
||||
cons.accept((Unit) player);
|
||||
}
|
||||
|
@ -306,7 +306,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
}
|
||||
|
||||
if(!Net.client()){
|
||||
avoidOthers(4f + type.hitsize);
|
||||
|
||||
if(spawner != -1 && (world.tile(spawner) == null || world.tile(spawner).entity == null)){
|
||||
damage(health);
|
||||
|
@ -16,7 +16,7 @@ import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.EntityPhysics;
|
||||
import io.anuke.ucore.entities.EntityQuery;
|
||||
import io.anuke.ucore.entities.impl.BaseEntity;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
@ -127,7 +127,7 @@ public class ForceProjector extends Block {
|
||||
float realRadius = realRadius(entity);
|
||||
|
||||
if(!entity.broken){
|
||||
EntityPhysics.getNearby(bulletGroup, tile.drawx(), tile.drawy(), realRadius*2f, bullet -> {
|
||||
EntityQuery.getNearby(bulletGroup, tile.drawx(), tile.drawy(), realRadius*2f, bullet -> {
|
||||
AbsorbTrait trait = (AbsorbTrait)bullet;
|
||||
if(trait.canBeAbsorbed() && trait.getTeam() != tile.getTeam() && isInsideHexagon(trait.getX(), trait.getY(), realRadius * 2f, tile.drawx(), tile.drawy())){
|
||||
trait.absorb();
|
||||
|
Loading…
Reference in New Issue
Block a user