Skip to content

Commit

Permalink
Overhauled production code
Browse files Browse the repository at this point in the history
* Added cash system and IHaveCost interface for actors
* Size of infantry increased
* Changed logic update frequency to 20 times per second
  • Loading branch information
Cr0s committed May 15, 2014
1 parent feeb325 commit d2838ab
Show file tree
Hide file tree
Showing 29 changed files with 1,110 additions and 484 deletions.
Binary file modified assets/hires.mix
Binary file not shown.
Binary file removed assets/purppals-xcc.mix
Binary file not shown.
5 changes: 5 additions & 0 deletions src/cr0s/javara/entity/IHaveCost.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cr0s.javara.entity;

public interface IHaveCost {
public int getBuildingCost();
}
28 changes: 28 additions & 0 deletions src/cr0s/javara/entity/actor/EntityActor.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package cr0s.javara.entity.actor;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;

import org.newdawn.slick.Graphics;

import cr0s.javara.entity.Entity;
import cr0s.javara.entity.INotifySelected;
import cr0s.javara.entity.actor.activity.Activity;
import cr0s.javara.entity.infantry.EntityInfantry;
import cr0s.javara.gameplay.Player;
import cr0s.javara.gameplay.Team;
import cr0s.javara.gameplay.Team.Alignment;
import cr0s.javara.order.IOrderIssuer;
import cr0s.javara.order.IOrderResolver;
import cr0s.javara.order.InputAttributes;
Expand All @@ -24,13 +29,18 @@ public abstract class EntityActor extends Entity implements IOrderIssuer, IOrder
protected HashMap<String, Integer[]> selectedSounds;

protected int unitVersion = 0; // for same voice per unit
public Alignment unitProductionAlingment = Alignment.NEUTRAL;

public LinkedList<Class> requiredToBuild;

public EntityActor(float posX, float posY, Team team, Player owner,
final float aSizeWidth, final float aSizeHeight) {
super(posX, posY, team, owner, aSizeWidth, aSizeHeight);

this.ordersList = new ArrayList<>();
this.selectedSounds = new HashMap<>();

requiredToBuild = new LinkedList<>();
}

@Override
Expand Down Expand Up @@ -104,4 +114,22 @@ public void playSelectedSound() {

public void playOrderSound() {
}

public EntityActor newInstance() {
Constructor ctor;

try {
ctor = (this.getClass()).getDeclaredConstructor(Float.class, Float.class, Team.class, Player.class);
ctor.setAccessible(true);
EntityActor newEntity = ((EntityActor) ctor.newInstance(this.posX, this.posY, this.team, this.owner));

return newEntity;
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}


return null;
}
}
16 changes: 14 additions & 2 deletions src/cr0s/javara/entity/building/EntityAdvPowerPlant.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

import cr0s.javara.entity.IHaveCost;
import cr0s.javara.entity.ISelectable;
import cr0s.javara.entity.IShroudRevealer;
import cr0s.javara.gameplay.Player;
import cr0s.javara.gameplay.Team;
import cr0s.javara.gameplay.Team.Alignment;
import cr0s.javara.main.Main;
import cr0s.javara.resources.ResourceManager;
import cr0s.javara.resources.ShpTexture;

public class EntityAdvPowerPlant extends EntityBuilding implements ISelectable, IPowerProducer, IShroudRevealer {
public class EntityAdvPowerPlant extends EntityBuilding implements ISelectable, IPowerProducer, IShroudRevealer, IHaveCost {
private Image normal, corrupted;
private final String TEXTURE_NAME = "apwr.shp";
private final String MAKE_TEXTURE_NAME = "apwrmake.shp";
Expand All @@ -25,8 +27,9 @@ public class EntityAdvPowerPlant extends EntityBuilding implements ISelectable,
private static final int POWER_PRODUCTION_LEVEL = 60;

private static final int SHROUD_REVEALING_RANGE = 7;
private static final int BUILDING_COST = 500;

public EntityAdvPowerPlant(Integer tileX, Integer tileY, Team team, Player player) {
public EntityAdvPowerPlant(Float tileX, Float tileY, Team team, Player player) {
super(tileX, tileY, team, player, WIDTH_TILES * 24, HEIGHT_TILES * 24, "xxx xxx xxx ~~~");

setBibType(BibType.MIDDLE);
Expand All @@ -38,6 +41,10 @@ public EntityAdvPowerPlant(Integer tileX, Integer tileY, Team team, Player playe
this.buildingSpeed = 35;
this.makeTextureName = MAKE_TEXTURE_NAME;
initTextures();

this.unitProductionAlingment = Alignment.NEUTRAL;

this.requiredToBuild.add(EntityRadarDome.class);
}

private void initTextures() {
Expand Down Expand Up @@ -115,5 +122,10 @@ public int getRevealingRange() {
@Override
public Image getTexture() {
return normal;
}

@Override
public int getBuildingCost() {
return BUILDING_COST;
}
}
220 changes: 116 additions & 104 deletions src/cr0s/javara/entity/building/EntityBarracks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,131 +6,143 @@
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

import cr0s.javara.entity.IHaveCost;
import cr0s.javara.entity.ISelectable;
import cr0s.javara.entity.IShroudRevealer;
import cr0s.javara.gameplay.Player;
import cr0s.javara.gameplay.Team;
import cr0s.javara.gameplay.Team.Alignment;
import cr0s.javara.main.Main;
import cr0s.javara.resources.ResourceManager;
import cr0s.javara.resources.ShpTexture;

public class EntityBarracks extends EntityBuilding implements ISelectable, IPowerConsumer, IShroudRevealer {
public class EntityBarracks extends EntityBuilding implements ISelectable, IPowerConsumer, IShroudRevealer, IHaveCost {

private SpriteSheet sheet;

private int animIndex = 0;
private int animDelayTicks = 0;
private static final int ANIM_DELAY_TICKS = 2;

private final String TEXTURE_NAME = "barr.shp";
private final String MAKE_TEXTURE_NAME = "barrmake.shp";

public static final int WIDTH_TILES = 2;
public static final int HEIGHT_TILES = 3;
private SpriteSheet sheet;

private static final int TEXTURE_WIDTH = 48;
private static final int TEXTURE_HEIGHT = 48;

private static final int POWER_CONSUMPTION_LEVEL = 10;
private static final int SHROUD_REVEALING_RANGE = 10;

public EntityBarracks(Integer tileX, Integer tileY, Team team, Player player) {
super(tileX, tileY, team, player, WIDTH_TILES * 24, HEIGHT_TILES * 24, "xx xx ~~");

setBibType(BibType.SMALL);
setProgressValue(-1);

setMaxHp(50);
setHp(getMaxHp());

this.buildingSpeed = 35;
this.makeTextureName = MAKE_TEXTURE_NAME;

initTextures();
}
private int animIndex = 0;
private int animDelayTicks = 0;
private static final int ANIM_DELAY_TICKS = 2;

private void initTextures() {
ShpTexture tex = ResourceManager.getInstance().getConquerTexture(TEXTURE_NAME);
sheet = new SpriteSheet(tex.getAsCombinedImage(owner.playerColor), tex.getAsImage(0, owner.playerColor).getWidth(), tex.getAsImage(0, owner.playerColor).getHeight());
}

@Override
public void renderEntity(Graphics g) {
float nx = posX;
float ny = posY;

int corruptionShift = 0;

if (this.getHp() > this.getMaxHp() / 2) {
corruptionShift = 0;
} else {
corruptionShift = 10;
}

sheet.startUse();
sheet.getSubImage(0, corruptionShift + animIndex).drawEmbedded(posX, posY, this.getTextureWidth(), this.getTextureHeight());
sheet.endUse();

// Draw bounding box if debug mode is on
if (Main.DEBUG_MODE) {
g.setLineWidth(2);
g.setColor(owner.playerColor);
g.draw(boundingBox);
g.setLineWidth(1);
}
}
private final String TEXTURE_NAME = "barr.shp";
private final String MAKE_TEXTURE_NAME = "barrmake.shp";

public static final int WIDTH_TILES = 2;
public static final int HEIGHT_TILES = 3;

private static final int TEXTURE_WIDTH = 48;
private static final int TEXTURE_HEIGHT = 48;

private static final int POWER_CONSUMPTION_LEVEL = 10;
private static final int SHROUD_REVEALING_RANGE = 10;

private static final int BUILDING_COST = 400;

public EntityBarracks(Float tileX, Float tileY, Team team, Player player) {
super(tileX, tileY, team, player, WIDTH_TILES * 24, HEIGHT_TILES * 24, "xx xx ~~");

setBibType(BibType.SMALL);
setProgressValue(-1);

setMaxHp(50);
setHp(getMaxHp());

this.buildingSpeed = 35;
this.makeTextureName = MAKE_TEXTURE_NAME;

initTextures();
this.unitProductionAlingment = Alignment.SOVIET;

@Override
public boolean shouldRenderedInPass(int passnum) {
return passnum == 0;
}
this.requiredToBuild.add(EntityPowerPlant.class);
}

@Override
public void updateEntity(int delta) {
if (animDelayTicks++ > ANIM_DELAY_TICKS) {
animDelayTicks = 0;

this.animIndex = (this.animIndex + 1) % 10;
}
}
private void initTextures() {
ShpTexture tex = ResourceManager.getInstance().getConquerTexture(TEXTURE_NAME);
sheet = new SpriteSheet(tex.getAsCombinedImage(owner.playerColor), tex.getAsImage(0, owner.playerColor).getWidth(), tex.getAsImage(0, owner.playerColor).getHeight());
}

@Override
public void select() {
this.isSelected = true;
}
@Override
public void renderEntity(Graphics g) {
float nx = posX;
float ny = posY;

@Override
public void cancelSelect() {
this.isSelected = false;
}
int corruptionShift = 0;

@Override
public boolean isSelected() {
return this.isSelected;
if (this.getHp() > this.getMaxHp() / 2) {
corruptionShift = 0;
} else {
corruptionShift = 10;
}

@Override
public float getHeightInTiles() {
return this.tileHeight;
}
sheet.startUse();
sheet.getSubImage(0, corruptionShift + animIndex).drawEmbedded(posX, posY, this.getTextureWidth(), this.getTextureHeight());
sheet.endUse();

@Override
public float getWidthInTiles() {
return this.tileWidth;
// Draw bounding box if debug mode is on
if (Main.DEBUG_MODE) {
g.setLineWidth(2);
g.setColor(owner.playerColor);
g.draw(boundingBox);
g.setLineWidth(1);
}
}

@Override
public int getConsumptionLevel() {
return this.POWER_CONSUMPTION_LEVEL;
}
@Override
public boolean shouldRenderedInPass(int passnum) {
return passnum == 0;
}

@Override
public int getRevealingRange() {
return this.SHROUD_REVEALING_RANGE;
}

@Override
public Image getTexture() {
return sheet.getSubImage(0, 0);
@Override
public void updateEntity(int delta) {
if (animDelayTicks++ > ANIM_DELAY_TICKS) {
animDelayTicks = 0;

this.animIndex = (this.animIndex + 1) % 10;
}
}

@Override
public void select() {
this.isSelected = true;
}

@Override
public void cancelSelect() {
this.isSelected = false;
}

@Override
public boolean isSelected() {
return this.isSelected;
}

@Override
public float getHeightInTiles() {
return this.tileHeight;
}

@Override
public float getWidthInTiles() {
return this.tileWidth;
}

@Override
public int getConsumptionLevel() {
return this.POWER_CONSUMPTION_LEVEL;
}

@Override
public int getRevealingRange() {
return this.SHROUD_REVEALING_RANGE;
}

@Override
public Image getTexture() {
return sheet.getSubImage(0, 0);
}

@Override
public int getBuildingCost() {
return BUILDING_COST;
}
}
Loading

0 comments on commit d2838ab

Please sign in to comment.