Skip to content

Commit

Permalink
Added infantry production
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr0s committed May 15, 2014
1 parent d2838ab commit a9e71aa
Show file tree
Hide file tree
Showing 14 changed files with 396 additions and 89 deletions.
6 changes: 6 additions & 0 deletions src/cr0s/javara/entity/MobileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,10 @@ public void resolveOrder(Order order) {
this.moveTo(order.targetPosition);
}
}


public void setCellPos(Point exitPoint) {
this.posX = exitPoint.getX() * 24;
this.posY = exitPoint.getY() * 24;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cr0s.javara.entity.actor.activity.activities.Turn.RotationDirection;
import cr0s.javara.entity.building.EntityBuilding;
import cr0s.javara.entity.infantry.EntityInfantry;
import cr0s.javara.entity.infantry.EntityInfantry.AnimationState;
import cr0s.javara.entity.vehicle.common.EntityMcv;
import cr0s.javara.render.World;
import cr0s.javara.util.PointsUtil;
Expand Down Expand Up @@ -115,17 +116,17 @@ private Point popPath(MobileEntity me) {
blocker.notifyBlocking(me);
this.hasNotifiedBlocker = true;
}

// Wait a bit
if (!this.hasWaited) {
this.waitTicksRemaining = me.getWaitAverageTime() + me.world.getRandomInt(-me.getWaitSpreadTime(), me.getWaitSpreadTime());

//System.out.println("Waiting time: " + this.waitTicksRemaining);
this.hasWaited = true;
((EntityInfantry) me).setCurrentAnimationState(AnimationState.WAITING);
}

if (--this.waitTicksRemaining >= 0) { // We're waiting now
//System.out.println("\tWaiting ticks: " + this.waitTicksRemaining);
return null;
}

Expand All @@ -134,6 +135,8 @@ private Point popPath(MobileEntity me) {

return null;
}

((EntityInfantry) me).setCurrentAnimationState(AnimationState.MOVING);

if (--this.ticksBeforeRepath <= 0) {
this.ticksBeforeRepath = this.REPATHING_INTERVAL_TICKS;
Expand Down
60 changes: 59 additions & 1 deletion src/cr0s/javara/entity/building/EntityBarracks.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package cr0s.javara.entity.building;

import java.util.ArrayList;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.geom.Point;
import org.newdawn.slick.util.pathfinding.Path;

import cr0s.javara.entity.IHaveCost;
import cr0s.javara.entity.ISelectable;
import cr0s.javara.entity.IShroudRevealer;
import cr0s.javara.entity.MobileEntity;
import cr0s.javara.entity.actor.EntityActor;
import cr0s.javara.gameplay.Player;
import cr0s.javara.gameplay.Team;
import cr0s.javara.gameplay.Team.Alignment;
import cr0s.javara.main.Main;
import cr0s.javara.render.EntityBlockingMap.SubCell;
import cr0s.javara.resources.ResourceManager;
import cr0s.javara.resources.ShpTexture;
import cr0s.javara.util.CellChooser;

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

Expand All @@ -37,7 +45,10 @@ public class EntityBarracks extends EntityBuilding implements ISelectable, IPowe
private static final int SHROUD_REVEALING_RANGE = 10;

private static final int BUILDING_COST = 400;


private Point rallyPoint;
private Point exitPoint;

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

Expand Down Expand Up @@ -145,4 +156,51 @@ public Image getTexture() {
public int getBuildingCost() {
return BUILDING_COST;
}

public void deployEntity(EntityActor newInstance) {
if (newInstance instanceof MobileEntity) {
final MobileEntity me = (MobileEntity) newInstance;

me.isVisible = true;
newInstance.setWorld(this.world);

world.spawnEntityInWorld(newInstance);

Path p = new Path();
p.appendStep((int) exitPoint.getX(), (int) exitPoint.getY());
p.appendStep((int) rallyPoint.getX(), (int) rallyPoint.getY());

SubCell freeSubCell = world.blockingEntityMap.getFreeSubCell(rallyPoint, SubCell.CENTER);
if (freeSubCell != null) {
me.currentSubcell = freeSubCell;
me.desiredSubcell = freeSubCell;
me.setCellPos(exitPoint);

me.startMovingByPath(p, this);
} else {
SubCell sc = SubCell.CENTER;

MobileEntity blocker = world.getMobileEntityInCell(exitPoint);
if (blocker != null) {
blocker.nudge(me, true);
}

blocker = world.getMobileEntityInCell(rallyPoint);
if (blocker != null) {
blocker.nudge(me, true);
}

me.setCellPos(exitPoint);
me.currentSubcell = sc;
me.desiredSubcell = sc;
me.startMovingByPath(p, this);
}
}
}

@Override
public void onBuildFinished() {
this.exitPoint = new Point((posX) / 24, (posY + 1 * 24) / 24);
this.rallyPoint = new Point((posX + 24) / 24, (posY + 2 * 24) / 24);
}
}
22 changes: 17 additions & 5 deletions src/cr0s/javara/entity/infantry/EntityGrenadeTrooper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SpriteSheet;

import cr0s.javara.entity.IHaveCost;
import cr0s.javara.entity.ISelectable;
import cr0s.javara.entity.actor.activity.activities.MoveInfantry;
import cr0s.javara.gameplay.Player;
Expand All @@ -15,9 +16,15 @@
import cr0s.javara.resources.ResourceManager;
import cr0s.javara.resources.ShpTexture;

public class EntityGrenadeTrooper extends EntityInfantry implements ISelectable {
public class EntityGrenadeTrooper extends EntityInfantry implements ISelectable, IHaveCost {

public EntityGrenadeTrooper(float posX, float posY, Team team, Player owner,
private final int BUILD_COST = 160;

public EntityGrenadeTrooper(Float posX, Float posY, Team team, Player owner) {
this(posX, posY, team, owner, SubCell.CENTER);
}

public EntityGrenadeTrooper(Float posX, Float posY, Team team, Player owner,
SubCell sub) {
super(posX, posY, team, owner, sub);

Expand All @@ -29,11 +36,11 @@ public EntityGrenadeTrooper(float posX, float posY, Team team, Player owner,
this.currentFrame = 0;

this.standSequence = new Sequence(texture, 0, 8, 0, 0, owner.playerColor);
this.runSequence = new Sequence(texture, 16, 8, 6, 5, owner.playerColor);
this.runSequence = new Sequence(texture, 16, 8, 6, 2, owner.playerColor);
this.runSequence.setIsLoop(true);

this.idleSequences.add(new Sequence(texture, 384, 0, 14, 10, owner.playerColor));
this.idleSequences.add(new Sequence(texture, 399, 0, 16, 10, owner.playerColor));
this.idleSequences.add(new Sequence(texture, 384, 0, 14, 2, owner.playerColor));
this.idleSequences.add(new Sequence(texture, 399, 0, 16, 2, owner.playerColor));
}

@Override
Expand Down Expand Up @@ -78,4 +85,9 @@ public void cancelSelect() {
public boolean isSelected() {
return this.isSelected;
}

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

0 comments on commit a9e71aa

Please sign in to comment.