Skip to content

Commit

Permalink
#14: a bit more towards a working crafting screen
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-t committed Nov 8, 2017
1 parent 1e2dc75 commit fb90ae3
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
public class Name extends Component
{
public final String name;
public final String tag;

public Name()
{
this.name = "";
this.tag = "";
}

public Name(final String name)
public Name(final String name, final String tag)
{
this.name = name;
this.tag = tag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
*/
public abstract class AbstractScreen extends PassiveSystem implements Screen
{
public static final Letter[] ALL = Letter.values();

PlayerManager pManager;

public enum Letter
Expand Down Expand Up @@ -90,7 +92,7 @@ void drawList(final AsciiPanel terminal, final List<String> list)

for (int i = 0, starty = terminal.getHeightInCharacters() / 2 - size / 2; i < size; i++)
{
final String entry = list.get(i);
final String entry = ALL[i] + " " + list.get(i);

terminal.writeCenter(entry, starty + (size < maxSize / 2 ? i * 2 : i));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public float handleKeys(final BitVector keys)
@Override
public void display(final AsciiPanel terminal)
{
terminal.clear(' ');

drawHeader(terminal);

drawList(terminal, sCraft.getRecipeNames());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@ public void display(final AsciiPanel terminal)

final ArrayList<String> elements = new ArrayList<>();
final IntBag items = inv.items;
for (int i = 0, size = items.size(); i < size; i++)
for (int i = 0, j = 0, size = items.size(); i < size; i++)
{
final int itemId = items.get(i);

if (!canDraw(itemId))
{
j++;
continue;
}

elements.add(String.format("%s %s %s",
Letter.values()[i],
elements.add(String.format("%s %s",
mName.get(itemId).name.toLowerCase(),
mEquip.has(itemId) ? " [WORN]" : ""));
}
Expand All @@ -102,10 +104,15 @@ int getItem(final BitVector keys)
return -1;

final int playerId = pManager.getEntitiesOfPlayer("player").get(0).getId();
final Inventory i = mInventory.get(playerId);
final Inventory inv = mInventory.get(playerId);

for (int i = 0, j = 0, size = inv.items.size(); i < size; i++, j++)
{
final int itemId = inv.items.get(i);

if (pos < i.items.size())
return i.items.get(pos);
if (canDraw(itemId) && j == pos)
return itemId;
}

return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ else if (keys.get(KeyEvent.VK_W))

return 0f;
}
else if (keys.get(KeyEvent.VK_C))
{
keys.clear();

Main.pause();

screen.select(CraftScreen.class);

return 0f;
}
else if (keys.get(KeyEvent.VK_ESCAPE))
{
keys.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected void initialize()
map.obstacles.set(id, x, y);
pManager.setPlayer(world.getEntity(id), "player");
edit.create(Inventory.class);
edit.add(new Name("You"));
edit.add(new Name("You", "you"));

// add a herd of buffalos
int groupId = sGroup.createGroup();
Expand Down Expand Up @@ -125,7 +125,7 @@ protected void initialize()
edit.create(Alertness.class).value = 0.0f;
edit.create(Sprite.class).set('b', Util.BROWN.darker().darker());
// edit.create(Sprite.class).set(Character.forDigit(id, 10), Util.BROWN.darker().darker());
edit.add(new Name("A buffalo"));
edit.add(new Name("A big buffalo", "buffalo"));

map.obstacles.set(id, x, y);
}
Expand Down Expand Up @@ -160,7 +160,7 @@ protected void initialize()
edit.create(Position.class).set(x, y);
edit.create(Alertness.class).value = 0.0f;
edit.create(Sprite.class).set('r', Color.LIGHT_GRAY);
edit.add(new Name("A rabbit"));
edit.add(new Name("A cute rabbit", "rabbit"));

map.obstacles.set(id, x, y);
}
Expand Down Expand Up @@ -201,7 +201,7 @@ protected void initialize()
edit.create(Alertness.class).value = 0.0f;
edit.create(Sprite.class).set('w', Color.DARK_GRAY);
// edit.create(Sprite.class).set(Character.forDigit(id, 10), Color.DARK_GRAY);
edit.add(new Name("A wolf"));
edit.add(new Name("A ferocious wolf", "wolf"));

map.obstacles.set(id, x, y);
}
Expand Down Expand Up @@ -237,7 +237,7 @@ protected void initialize()
edit.create(Alertness.class).value = 0.0f;
edit.create(Sprite.class).set('p', Util.BROWN.darker().darker());
// edit.create(Sprite.class).set(Character.forDigit(id, 10), Util.BROWN.darker());
edit.add(new Name("A puma"));
edit.add(new Name("A strong puma", "puma"));

map.obstacles.set(id, x, y);
}
Expand Down Expand Up @@ -276,7 +276,7 @@ protected void initialize()
edit.create(Position.class).set(x, y);
edit.create(Alertness.class).value = 0.0f;
edit.create(Sprite.class).set('f', Color.CYAN.darker());
edit.add(new Name("A fish"));
edit.add(new Name("A colorful fish", "fish"));

map.obstacles.set(id, x, y);
}
Expand Down Expand Up @@ -360,19 +360,9 @@ protected void initialize()
if (!map.items.isEmpty(x, y))
continue;

switch (r.nextInt(3))
{
case 0:
id = sTree.makeTrunk(x, y);
map.items.set(id, x, y);
break;

case 1:
case 2:
id = sTree.makeBranch(x, y);
map.items.set(id, x, y);
break;
}
sTree.makeTrunk(map.getFirstTotallyFree(x, y, -1));
sTree.makeBranch(map.getFirstTotallyFree(x, y, -1));
sTree.makeVine(map.getFirstTotallyFree(x, y, -1));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public int makeStone(final int x, final int y)
edit.create(Sprite.class).set('o', Color.DARK_GRAY.brighter());
edit.create(Weapon.class).set(WeaponType.BLUNT, 1);
edit.create(Wearable.class);
edit.add(new Name("A stone"));
edit.add(new Name("A round stone", "stone"));

map.items.set(id, x, y);

Expand All @@ -100,7 +100,7 @@ public int makeBoulder(final int x, final int y)
edit.create(LightBlocker.class);
edit.create(Pushable.class);
edit.create(Crushable.class);
edit.add(new Name("A boulder"));
edit.add(new Name("A big boulder", "boulder"));

map.obstacles.set(id, x, y);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected void process(final int entityId)
edit.create(Sprite.class).set('$', Color.RED.darker().darker(), false);
edit.create(Corpse.class);
edit.create(Health.class).set(size.value + 3);
edit.add(new Name(name.name + "'s corpse"));
edit.add(new Name(name.name + "'s corpse", "corpse"));

map.items.set(corpseId, p2.x, p2.y);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.github.fabioticconi.alone.components.*;
import com.github.fabioticconi.alone.components.actions.ActionContext;
import com.github.fabioticconi.alone.components.attributes.Strength;
import com.github.fabioticconi.alone.constants.Cell;
import com.github.fabioticconi.alone.constants.WeaponType;
import com.github.fabioticconi.alone.messages.CannotMsg;
import com.github.fabioticconi.alone.messages.CutMsg;
Expand Down Expand Up @@ -74,7 +75,7 @@ public int makeTree(final int x, final int y)
edit.create(Sprite.class).set('T', Color.GREEN.darker(), true);
edit.create(LightBlocker.class);
edit.create(Tree.class);
edit.add(new Name("A tree"));
edit.add(new Name("A mature tree", "tree"));

map.obstacles.set(id, x, y);

Expand All @@ -92,8 +93,8 @@ public int makeTrunk(final int x, final int y)

final EntityEdit edit = world.edit(id);
edit.create(Position.class).set(x, y);
edit.create(Sprite.class).set('-', Util.BROWN.brighter());
edit.add(new Name("A tree trunk"));
edit.create(Sprite.class).set((char)22, Util.BROWN.brighter());
edit.add(new Name("A fallen tree", "trunk"));

map.items.set(id, x, y);

Expand All @@ -114,7 +115,26 @@ public int makeBranch(final int x, final int y)
edit.create(Sprite.class).set('/', Util.BROWN.brighter());
edit.create(Weapon.class).set(WeaponType.BLUNT, 1);
edit.create(Wearable.class);
edit.add(new Name("A branch"));
edit.add(new Name("A sturdy branch", "branch"));

map.items.set(id, x, y);

return id;
}

public int makeVine(final Point p)
{
return makeVine(p.x, p.y);
}

public int makeVine(final int x, final int y)
{
final int id = world.create();

final EntityEdit edit = world.edit(id);
edit.create(Position.class).set(x, y);
edit.create(Sprite.class).set((char)239, Cell.GRASS.col);
edit.add(new Name("A thin, flexible branch", "vine"));

map.items.set(id, x, y);

Expand Down Expand Up @@ -171,7 +191,7 @@ public void doAction()

makeTrunk(map.getFirstTotallyFree(p.x, p.y, -1));
makeBranch(map.getFirstTotallyFree(p.x, p.y, -1));
makeBranch(map.getFirstTotallyFree(p.x, p.y, -1));
makeVine(map.getFirstTotallyFree(p.x, p.y, -1));

// consume a fixed amount of stamina
sStamina.consume(actorId, cost);
Expand Down

0 comments on commit fb90ae3

Please sign in to comment.