Skip to content

Commit

Permalink
Turret controller sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
MEEPofFaith committed Jun 9, 2024
1 parent 2789c3c commit d300d2d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 assets/sprites/blocks/logic/turret-controller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 58 additions & 3 deletions src/extrasandredux/world/blocks/logic/TurretController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package extrasandredux.world.blocks.logic;

import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.geom.*;
import arc.scene.ui.*;
Expand All @@ -8,6 +10,7 @@
import arc.util.*;
import arc.util.io.*;
import extrasandredux.util.*;
import mindustry.entities.units.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
Expand All @@ -20,13 +23,17 @@
import static mindustry.Vars.*;

public class TurretController extends Block{
protected TextureRegion modeRegion;
protected TextureRegion plugRegion0, plugRegion1;

public TurretController(String name){
super(name);
ESRUtls.applySandboxDefaults(this, Category.logic);

update = true;
solid = true;
rotate = true;
rotateDraw = false;
configurable = true;
saveConfig = false;

Expand All @@ -38,13 +45,44 @@ public TurretController(String name){
});
}

@Override
public void load(){
super.load();

modeRegion = Core.atlas.find(name + "-mode");
plugRegion0 = Core.atlas.find(name + "-plug0");
plugRegion1 = Core.atlas.find(name + "-plug1");
}

@Override
protected TextureRegion[] icons(){
return new TextureRegion[]{Core.atlas.find(name + "-preview")};
}

@Override
public TextureRegion getPlanRegion(BuildPlan plan, Eachable<BuildPlan> list){
return region;
}

@Override
public boolean canPlaceOn(Tile tile, Team team, int rotation){
//Assumes this block is 1x1. Too lazy to bother with anything larger because I won't make something larger.
Tile front = tile.nearby(rotation);
return front != null && front.build instanceof TurretBuild;
}

@Override
public void drawPlanRegion(BuildPlan plan, Eachable<BuildPlan> list){
super.drawPlanRegion(plan, list);
drawPlug(plan.x * 8f, plan.y * 8f, plan.rotation);
}

public void drawPlug(float x, float y, int rotation){
TextureRegion region = rotation > 1 ? plugRegion1 : plugRegion0;
float flip = rotation % 2 == 0 ? 1 : -1;
Draw.rect(region, x, y, region.width / 4f, flip * region.height / 4f, rotation * 90f);
}

public class TurretControllerBuild extends Building{
public ControlState controlState = ControlState.off;
/** x = angle, y = distance */
Expand Down Expand Up @@ -115,6 +153,17 @@ public void buildConfiguration(Table table){
});
}

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

Draw.color(controlState.modeColor);
Draw.rect(modeRegion, x, y);
Draw.color();
Draw.z(Layer.block + 0.01f);
drawPlug(x, y, rotation);
}

@Override
public void drawSelect(){
Building front = front();
Expand Down Expand Up @@ -143,12 +192,18 @@ public void read(Reads read, byte revision){
}

public enum ControlState{
off,
on,
disable;
off(Pal.darkerGray),
on(Pal.heal),
disable(Color.red);

public Color modeColor;

public static ControlState[] all = values();

ControlState(Color modeColor){
this.modeColor = modeColor;
}

public ControlState next(){
int next = ordinal() + 1;
if(next >= all.length) next = 0;
Expand Down

0 comments on commit d300d2d

Please sign in to comment.