Initial game loop

My design for the initial game loop is simple, but we need to break it down a bit into two parts: Main character is gathering herbs, and a building is producing herbs. Herbs we’ll for now store as a simple field in the main game model – the model being a structure that contains the whole state for the game at the moment.

The character I’m planning to give an “action” to. The game will store an action and after a given delay will act on the action – this could be as short as a single cycle. Each cycle will update the action, so theoretically the actions could be affected by the game. Once the action is complete, is is removed, although an auto-repeat may be useful. The main character can have one action at once, but there may be more actors in the future – perhaps you have a familiar, a controlled demon or a spirit guide.

I chose to do an action based approach rather than instant click-to-produce because

  • Clicking repeatedly encourages auto-clickers and I don’t want to need a third-party tool to play my game.
  • I want a slower pace of game and clicking is a manic distraction to the strategy of how you build up your character.
  • This still gives some choices of how you play if there are a choice of actions; a quicker action will give fewer resources in total, but will allow you to gather more in total.

The second part of the main game loop will be the herb garden processing. This is perhaps simpler – a building is constructed outside the game loop by using resources, so at that point the model contains a building. On each update of the game model, the building will produce resources.

Resources I am modelling as a float rather than an int. This does mean you can have 0.3 herbs, but for the sake of the game this is something that I can think can be overlooked.

So far in my implementation I’ve got as far as actions. I’m hitting a few blocks as I get to grips with how Elm stores data. I don’t have constructions yet, but currently the model is:

type ResourceType
  = Herb
  | Pumpkin

type ActionResult 
  = Gather ResourceType
  | Create
type alias Action = 
  { result : ActionResult
  , amount : Float
  , time : Int

type alias ResourceRecord =
  { amount : Float

type alias Model =
  { actions : List Action
  , resources : Dict ResourceType ResourceRecord
  , ticks : Int

I think I have a few things to think about at the moment:

  • My resource record is simply a float at the moment – does it really need to have anything else? In an imperative world I’d store things like a cache of the production rate here.
  • The actions are a list of actions, but I think this probably also should be a dictionary of actor to action, and Actor a new type. If I need multiple actions per actor (eg queues) I can add that later.
  • The Create action and Pumpkin resource is a placeholder to remind me that I can add new actions that way. I’m still new to this language!
  • Action currently stores the amount it’s going to produce. I could make this derived from the actor and the model (the actor would presumably have some stats that influence the action), but I think I would prefer to pre-calculate it – this means that any action-changing short-term abilities would need to be applied at the same time as the action is started. This avoids insisting the player plays the game at the end of the cycle, which can be frustrating as it’s hard to plan exact timing and fit that around your day to day life.
  • Ticks on the main object is a way to know how long this game has been running. It might be moved into another type later – stats is definitely important to this game.

Anyway. That’s some first steps. Still to do are making the actions correctly produce resources, making the action unique so that only one happens for each actor, and then on to constructions.

Leave a Reply

Your email address will not be published. Required fields are marked *