Skip to content

Commit

Permalink
Insects fixed!
Browse files Browse the repository at this point in the history
  • Loading branch information
Slotterleet committed Apr 7, 2024
1 parent 392f84a commit 876912a
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 5 deletions.
Binary file modified res/sprites/units/bugs/bug-small-segment0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sprites/units/bugs/bug-small-segment1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/sprites/units/bugs/bug-small-segment2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/sprites/units/bugs/bug-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/fos/content/FOSUnitTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class FOSUnitTypes {
// PLAYER UNITS
lord, king;

public static @Annotations.EntityDef({Bugc.class, Crawlc.class}) UnitType
public static @Annotations.EntityDef({Bugc.class, FOSCrawlc.class}) UnitType
// CRAWLING INSECTS
bugSmall, bugMedium;

Expand Down
5 changes: 4 additions & 1 deletion src/fos/controllers/EvolutionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ public float getFactoryEvo() {
}

public float getSectorEvo() {
return FOSPlanets.lumoni.sectors.count(Sector::isCaptured) * sectorCoefficient;
return !Vars.state.isCampaign() ? 0 :
FOSPlanets.lumoni.sectors.count(Sector::isCaptured) * sectorCoefficient;
}

public float getResearchEvo() {
if (!Vars.state.isCampaign()) return 0;

// JAVA SUCKS.
final int[] counter = {0};
Vars.content.each(c -> {
Expand Down
116 changes: 115 additions & 1 deletion src/fos/type/units/comp/FOSCrawlComp.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,118 @@
package fos.type.units.comp;

public class FOSCrawlComp {
import arc.math.*;
import arc.math.geom.Vec2;
import arc.util.Time;
import mindustry.Vars;
import mindustry.ai.Pathfinder;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.game.Team;
import mindustry.gen.*;
import mindustry.type.UnitType;
import mindustry.world.Tile;
import mindustry.world.blocks.environment.Floor;

import static mindustry.Vars.*;

/**
* A stripped-down version of CrawlComp without solidity() method
* to avoid conflicts with other components.
* This is VERY cursed.
*/
@Component
public abstract class FOSCrawlComp implements Posc, Rotc, Hitboxc, Unitc {
@Import
float x, y, speedMultiplier, rotation, hitSize;
@Import
UnitType type;
@Import
Team team;
@Import
Vec2 vel;

transient Floor lastDeepFloor;
transient float lastCrawlSlowdown = 1f;
transient float segmentRot, crawlTime = Mathf.random(100f);

// there goes the solidity().

@Override
@Replace
public int pathType(){
return Pathfinder.costLegs;
}

@Override
@Replace
public float floorSpeedMultiplier(){
Floor on = isFlying() ? Blocks.air.asFloor() : floorOn();
//TODO take into account extra blocks
return (on.isDeep() ? 0.45f : on.speedMultiplier) * speedMultiplier * lastCrawlSlowdown;
}

@Override
public void add(){
//reset segment rotation on add
segmentRot = rotation;
}

@Override
@Replace
public Floor drownFloor(){
return lastDeepFloor;
}

@Override
public void update(){
if(moving()){
segmentRot = Angles.moveToward(segmentRot, rotation, type.segmentRotSpeed * Time.delta);

int radius = (int)Math.max(0, hitSize / tilesize * 2f);
int count = 0, solids = 0, deeps = 0;
lastDeepFloor = null;

//calculate tiles under this unit, and apply slowdown + particle effects
for(int cx = -radius; cx <= radius; cx++){
for(int cy = -radius; cy <= radius; cy++){
if(cx*cx + cy*cy <= radius){
count ++;
Tile t = Vars.world.tileWorld(x + cx*tilesize, y + cy*tilesize);
if(t != null){

if(t.solid()){
solids ++;
}

if(t.floor().isDeep()){
deeps ++;
lastDeepFloor = t.floor();
}

//TODO area damage to units
if(t.build != null && t.build.team != team){
t.build.damage(team, type.crushDamage * Time.delta * state.rules.unitDamage(team));
}

if(Mathf.chanceDelta(0.025)){
Fx.crawlDust.at(t.worldx(), t.worldy(), t.floor().mapColor);
}
}else{
solids ++;
}
}
}
}

//when most blocks under this unit cannot be drowned in, do not drown
if((float)deeps / count < 0.75f){
lastDeepFloor = null;
}

lastCrawlSlowdown = Mathf.lerpDelta(1f, type.crawlSlowdown, Mathf.clamp((float)solids / count / type.crawlSlowdownFrac));
}
segmentRot = Angles.clampRange(segmentRot, rotation, type.segmentMaxRot);

crawlTime += vel.len() * Time.delta;
}
}
37 changes: 35 additions & 2 deletions src/fos/type/units/types/BugUnitType.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package fos.type.units.types;

import arc.graphics.Color;
import arc.graphics.g2d.*;
import arc.math.*;
import fos.ai.*;
import fos.content.FOSStatuses;
import fos.gen.FOSCrawlc;
import mindustry.content.*;
import mindustry.gen.Sounds;
import mindustry.gen.*;
import mindustry.type.UnitType;
import mindustry.world.meta.BlockFlag;

Expand All @@ -16,7 +19,7 @@ public BugUnitType(String name, boolean flying) {
lightOpacity = lightRadius = 0f;
drawCell = false;
drawBody = false;
outlineColor = Color.valueOf("5a2a1b");
outlineColor = Color.valueOf("452319");
createScorch = false;
createWreck = false;
deathExplosionEffect = Fx.none;
Expand All @@ -33,4 +36,34 @@ public BugUnitType(String name, boolean flying, boolean melee) {
this(name, flying);
if (melee) this.range = 0.01f;
}

@Override
public void draw(Unit unit) {
super.draw(unit);

if (unit instanceof FOSCrawlc c) {
drawCrawl(c);
}
}

public void drawCrawl(FOSCrawlc crawl) {
Unit unit = (Unit)crawl;
applyColor(unit);

TextureRegion[] regions = segmentRegions;
for(int i = 0; i < segments; i++){
float trns = Mathf.sin(crawl.crawlTime() + i * segmentPhase, segmentScl, segmentMag);

//at segment 0, rotation = segmentRot, but at the last segment it is rotation
float rot = Mathf.slerp(crawl.segmentRot(), unit.rotation, i / (float)(segments - 1));
float tx = Angles.trnsx(rot, trns), ty = Angles.trnsy(rot, trns);

//shadow
Draw.color(0f, 0f, 0f, 0.2f);
//Draw.rect(regions[i], unit.x + tx + 2f, unit.y + ty - 2f, rot - 90);
applyColor(unit);

Draw.rect(regions[i], unit.x + tx, unit.y + ty, rot - 90);
}
}
}

0 comments on commit 876912a

Please sign in to comment.