LessNoise.Sh some signal

Roguelike Dev Day 8: Last Several Chapters

(3 minutes) programming, rust, game, roguelike

Ever Onward

Moving on to Chapter 10 now. I'm mostly just reading through the tutorial now. I have all the code downloaded, and I read through it on my own machine to understand it, but I haven't been writing or even copy/pasting the code from the book.

Also, it's Saturday today, so I'm doing this in the morning. We'll see if I can get through a larger chunk of the book today.

Ranged Magic Scrolls

Before I read this, I want to stop and think: How would I implement ranged magic scrolls using the ECS I know about?

They would use the existing Item component. I'd make a Scroll component that hold information about what effect(s) it has, and I suppose a Ranged component that describes how an item can cause effects at a distance... Or something like that.

On second thought, Item and Ranged plus some type of Description for UI might be enough. Description would only hold information for describing the item to users textually, and Ranged would have all the information about effects and their targetable areas.

Let's see how this book implements ranged magic scrolls...

Oh I'm liking this. I haven't finished yet, but they immediately implement a Consumable component and change the Potion component to a ProvidesHealing component.

And for the scrolls the book is implementing separate Ranged and InflictsDamage components.

...

And we're implementing several different ranged items. I'm liking this.

...

I've finished reading chapter 10, and I've played the game at this point, and noticed that item effects target all entities with a position in range: including other items on the ground. I suppose for this to work there needs to be a way of targeting appropriate entities for a given effect. Maybe with components like Confusable and Burnable? Or maybe all entities with an AI system are confusable...

Also, I can use potions to bring myself back from the dead. And fireball spells can make my HP go negative.

Loading and Saving

Time for Chapter 11.

...

I finished reading. This chapter seemed more hacky.

I kept running into problems like it failing to compile if I had more than 16 component types!

The fix was to write a custom macro and then call it like this

serialize_individually!(
    ecs,
    serializer,
    data,
    Position,
    Renderable,
    Player,
    Viewshed,
    Monster,
    Name,
    BlocksTile,
    CombatStats,
    SufferDamage,
    WantsToMelee,
    Item,
    Consumable,
    Ranged,
    InflictsDamage,
    AreaOfEffect,
    Confusion,
    ProvidesHealing,
    InBackpack,
    WantsToPickupItem,
    WantsToUseItem,
    WantsToDropItem,
    SerializationHelper
);

And then make a similar macro & macro call for deserializing.

Also, how does this relate to configuration files? I'd like to be able to configure some entities (like monsters & animals) in my game in text files and let users mod them. This serialization stuff so far though makes text that isn't very human-readable, though; here's a piece of what it looks like.

[
  { "marker": [14], "components": [null] },
  { "marker": [12], "components": [{ "x": 28, "y": 5 }] },
  { "marker": [11], "components": [{ "x": 47, "y": 23 }] },
  { "marker": [10], "components": [null] },
  { "marker": [9], "components": [{ "x": 40, "y": 32 }] },
  { "marker": [8], "components": [{ "x": 25, "y": 19 }] }
]

I'm going to stop for lunch, and then I'll continue.

Multiple Levels

And on to Chapter 12! Boy, Saturdays are great for this.

This chapter is about implementing multiple levels/depths for the dungeon, so you can go up & down.

In my game the closest things to levels are islands. They're accessible from any direction in an open world by a flying/gliding character, so they're a little different from caverns. Oh and they move relative to each other.

None of that really means anything until I make the game, though. 😅

...

I read through the chapter, and played the game a bit.

It's a very simple change. The player can go "down," which generates a new map with new items & monsters. The old map becomes inaccessible—the player can't go upstairs, and the map's data is thrown away.

As it is, the game hasn't handled the player's death, so I can "descend" as far as I like; nothing about the levels changes as I descend, though.

Difficulty

Now starting Chapter 13.

The first step is adding a "wait" key, to let the player skip their turn. I think I want my game to be real time, with a "pause" button.

...

I read the code and played the game for several levels. The ramp up was a nice change. The game finally crashed when I collected more items than could be displayed, though. 😆

Wearable Items

And now in Chapter 14.

...

That seemed pretty familiar. Lots of components and systems for everything.

Also, that was the last chapter in the first section of the tutorial. 🎉

Good place to stop.