Skip to content

Commit

Permalink
Add a new mob (cow)
Browse files Browse the repository at this point in the history
  • Loading branch information
agluszak committed Jul 21, 2019
1 parent acd030d commit 0569b1b
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/src/com/ericc/the/game/actions/UseItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.badlogic.ashley.core.Entity;
import com.ericc.the.game.Mappers;
import com.ericc.the.game.components.InventoryComponent;
import com.ericc.the.game.components.Item;
import com.ericc.the.game.items.Item;
import com.ericc.the.game.effects.Effect;

public class UseItem extends Action {
Expand Down
5 changes: 2 additions & 3 deletions core/src/com/ericc/the/game/agencies/AstarAgency.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

public class AstarAgency implements Agency {
public static final int RADIUS = 5;
public int moveDelay = 33;
private RandomWalk randomWalk = new RandomWalk();

@Override
Expand Down Expand Up @@ -45,9 +44,9 @@ public Action chooseAction(PositionComponent pos, StatsComponent stats) {
if (minMove == null)
return Actions.WAIT;
else
return new MovementAction(Direction.fromGridPoint(minMove), moveDelay, MovementAction.MovementType.RUN);
return new MovementAction(Direction.fromGridPoint(minMove), 2000 / stats.agility, MovementAction.MovementType.RUN);
} else {
return Charge.returnAction(pos, x, y, map, moveDelay, stats);
return Charge.returnAction(pos, x, y, map, 2000 / stats.agility, stats);
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions core/src/com/ericc/the/game/agencies/CowAgency.java
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ericc.the.game.components;

import com.badlogic.ashley.core.Component;
import com.ericc.the.game.items.Item;

import java.util.ArrayList;
import java.util.List;
Expand Down
1 change: 1 addition & 0 deletions core/src/com/ericc/the/game/components/LootComponent.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ericc.the.game.components;

import com.badlogic.ashley.core.Component;
import com.ericc.the.game.items.Item;

public class LootComponent implements Component {
public Item item;
Expand Down
15 changes: 15 additions & 0 deletions core/src/com/ericc/the/game/drops/CowDrop.java
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;
}
}
2 changes: 1 addition & 1 deletion core/src/com/ericc/the/game/drops/Drop.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ericc.the.game.drops;

import com.ericc.the.game.components.Item;
import com.ericc.the.game.items.Item;

public interface Drop {
Item drop();
Expand Down
4 changes: 2 additions & 2 deletions core/src/com/ericc/the/game/drops/ExampleDrop.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ericc.the.game.drops;

import com.ericc.the.game.Models;
import com.ericc.the.game.components.Item;
import com.ericc.the.game.components.ItemType;
import com.ericc.the.game.items.Item;
import com.ericc.the.game.items.ItemType;
import com.ericc.the.game.effects.AddArrows;
import com.ericc.the.game.effects.GrantInvulnerability;
import com.ericc.the.game.effects.Heal;
Expand Down
1 change: 1 addition & 0 deletions core/src/com/ericc/the/game/effects/Kill.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.ericc.the.game.Mappers;
import com.ericc.the.game.components.*;
import com.ericc.the.game.entities.Loot;
import com.ericc.the.game.items.Item;

public class Kill implements Effect {
private Entity killer;
Expand Down
2 changes: 2 additions & 0 deletions core/src/com/ericc/the/game/effects/MoveBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.badlogic.ashley.core.Entity;
import com.ericc.the.game.Mappers;
import com.ericc.the.game.components.*;
import com.ericc.the.game.items.Item;
import com.ericc.the.game.items.ItemType;
import com.ericc.the.game.utils.GridPoint;

public class MoveBy implements Effect {
Expand Down
25 changes: 25 additions & 0 deletions core/src/com/ericc/the/game/entities/Cow.java
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()));
}
}
1 change: 1 addition & 0 deletions core/src/com/ericc/the/game/entities/Loot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.badlogic.ashley.core.Entity;
import com.ericc.the.game.components.*;
import com.ericc.the.game.effects.SetAnimation;
import com.ericc.the.game.items.Item;
import com.ericc.the.game.map.Map;
import com.ericc.the.game.utils.GridPoint;

Expand Down
2 changes: 1 addition & 1 deletion core/src/com/ericc/the/game/entities/MobMage.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class MobMage extends Entity {
public MobMage(GridPoint xy, Map map) {
add(new PositionComponent(xy, map));
add(new RenderableComponent(Models.mage)); // TODO add new model
add(new RenderableComponent(Models.mage));
add(new StatsComponent(45, 30, 5, 50, 200, true));
add(new AgencyComponent(new AstarAgency(), false));
add(new CollisionComponent(CollisionComponent.Type.LIVING));
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/ericc/the/game/entities/MobTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class MobTank extends Entity {
public MobTank(GridPoint xy, Map map) {
add(new PositionComponent(xy, map));
add(new RenderableComponent(Models.tank)); // TODO add new model
add(new RenderableComponent(Models.tank));
add(new StatsComponent(45, 30, 5, 150, 0));
add(new AgencyComponent(new ChargeToPlayerAgency(), false));
add(new CollisionComponent(CollisionComponent.Type.LIVING));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ericc.the.game.components;
package com.ericc.the.game.items;

import com.ericc.the.game.components.Model;
import com.ericc.the.game.effects.Effect;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ericc.the.game.components;
package com.ericc.the.game.items;

public enum ItemType {
CARRIED, INSTANT
Expand Down
9 changes: 8 additions & 1 deletion core/src/com/ericc/the/game/map/LevelFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,17 @@ private static void generateBossMobs(Map map, ArrayList<Entity> entities, int ct
}
}

private static void generateCows(Map map, ArrayList<Entity> entities, int ctr) {
for (int i = 0; i < ctr; i++) {
Cow mob = new Cow(map.getRandomPassableTile(), map);
entities.add(mob);
}
}

private static void generateMobs(int levelNumber, Map map, ArrayList<Entity> entities) {
if (levelNumber == 0) {
generateCows(map, entities, 5);
generateMageMobs(map, entities, 10);
generateTankMobs(map, entities, 2);
generateStandardMobs(map, entities, 3);
generateArcherMobs(map, entities, 2);
} else if (levelNumber == 1) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/ericc/the/game/ui/screens/GameOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.ericc.the.game.Mappers;
import com.ericc.the.game.Media;
import com.ericc.the.game.components.InventoryComponent;
import com.ericc.the.game.components.Item;
import com.ericc.the.game.items.Item;
import com.ericc.the.game.entities.Player;
import com.ericc.the.game.ui.actors.*;

Expand Down

0 comments on commit 0569b1b

Please sign in to comment.