-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.ericc.the.game.agencies; | ||
|
||
import com.badlogic.ashley.core.Entity; | ||
import com.ericc.the.game.Direction; | ||
import com.ericc.the.game.Mappers; | ||
import com.ericc.the.game.actions.Action; | ||
import com.ericc.the.game.actions.Actions; | ||
import com.ericc.the.game.actions.MovementAction; | ||
import com.ericc.the.game.components.PositionComponent; | ||
import com.ericc.the.game.components.SafetyMapComponent; | ||
import com.ericc.the.game.components.StatsComponent; | ||
import com.ericc.the.game.helpers.Charge; | ||
import com.ericc.the.game.helpers.Moves; | ||
import com.ericc.the.game.map.Map; | ||
import com.ericc.the.game.utils.GridPoint; | ||
|
||
public class CowAgency implements Agency { | ||
public static final int RADIUS = 5; | ||
private RandomWalk randomWalk = new RandomWalk(); | ||
|
||
@Override | ||
public Action chooseAction(PositionComponent pos, StatsComponent stats) { | ||
Map map = pos.map; | ||
for (int x = pos.xy.x - RADIUS; x < pos.xy.x + RADIUS; ++x) { | ||
for (int y = pos.xy.y - RADIUS; y < pos.xy.y + RADIUS; ++y) { | ||
Entity target = map.collisionMap.get(new GridPoint(x, y)); | ||
if (target == null) | ||
continue; | ||
|
||
if (Mappers.player.has(target)) { | ||
if (stats.health < 0.5 * stats.maxHealth) { | ||
SafetyMapComponent sm = Mappers.safety.get(target); | ||
if (sm.distance == null) | ||
return Actions.WAIT; | ||
int min = 1000000; | ||
GridPoint minMove = null; | ||
for (GridPoint move : Moves.moves) { | ||
GridPoint point = pos.xy.add(move); | ||
if (pos.map.isPassable(point) && sm.distance[point.x][point.y] < min) { | ||
min = sm.distance[point.x][point.y]; | ||
minMove = move; | ||
} | ||
} | ||
if (minMove == null) | ||
return Actions.WAIT; | ||
else | ||
return new MovementAction(Direction.fromGridPoint(minMove), 2000 / stats.agility, MovementAction.MovementType.WALK); | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (stats.health < 0.7 * stats.maxHealth) { | ||
return Actions.SELFHEAL(); | ||
} | ||
|
||
return randomWalk.chooseAction(pos, stats); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.ericc.the.game.drops; | ||
|
||
import com.ericc.the.game.Models; | ||
import com.ericc.the.game.items.Item; | ||
import com.ericc.the.game.items.ItemType; | ||
import com.ericc.the.game.effects.Heal; | ||
|
||
public class CowDrop implements Drop { | ||
@Override | ||
public Item drop() { | ||
double choice = Math.random(); | ||
if (choice < 0.5) return new Item("Cow meat", Models.food, ItemType.CARRIED, new Heal(50)); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.ericc.the.game.entities; | ||
|
||
import com.badlogic.ashley.core.Entity; | ||
import com.ericc.the.game.Models; | ||
import com.ericc.the.game.agencies.ChargeToPlayerAgency; | ||
import com.ericc.the.game.agencies.CowAgency; | ||
import com.ericc.the.game.components.*; | ||
import com.ericc.the.game.drops.CowDrop; | ||
import com.ericc.the.game.drops.ExampleDrop; | ||
import com.ericc.the.game.map.Map; | ||
import com.ericc.the.game.utils.GridPoint; | ||
|
||
public class Cow extends Entity { | ||
public Cow(GridPoint xy, Map map) { | ||
add(new PositionComponent(xy, map)); | ||
add(new RenderableComponent(Models.tank)); // TODO add new model | ||
add(new StatsComponent(10, 10, 50, 200, 0)); | ||
add(new AgencyComponent(new CowAgency(), false)); | ||
add(new CollisionComponent(CollisionComponent.Type.LIVING)); | ||
add(new ExperienceWorthComponent(100)); | ||
add(new HealthBarComponent(Models.healthBar)); | ||
add(new AnimationComponent()); | ||
add(new DropComponent(new CowDrop())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...c/com/ericc/the/game/components/Item.java → core/src/com/ericc/the/game/items/Item.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...m/ericc/the/game/components/ItemType.java → ...rc/com/ericc/the/game/items/ItemType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters