Day 3 - Coding


This marks the fourth day of the game jam, and the third day actively coding my game. According to WakaTime I have put 13 hours into my project over the last 3 days, That includes

  • 11h 30m in Go
  • 56m in Markdown
  • 30m in Makefile
  • 15m in Text
So far my project is divided up into 4 packages. I will probably divide it up more in the future, but let's take a look at each of the packages

Package Main

This is just setting up some basic information for my project such as title, screen size, and player starting position. I also initialize the game, level, and player packages here.

Package Game

This is the package that orchestrates the rest of the game.

This owns the `Updatable` and `Drawable` interfaces we use through the rest of our packages.

type Updatable interface{
    Update()
} 
type Drawable interface {
    Draw(screen *ebiten.Image)
}
type Game struct {
    AudioContext *audio.Context
    screenWidth  int
    screenHeight int
    Components   []interface{}
}
func(g *Game) Update() error {
    for _, c := range g.Components{
        if updatable, ok := c.(Updatable); ok {
            updatable.Update()
        }
    }
}
func(g *Game) Draw(screen *ebiten.Image) error {
    for _, c := range g.Components{
        if drawable, ok := c.(Drawable); ok {
            drawable.Draw(screen)
        }
    }
}

This allows me to just register my components when I create them in main

g := game.New(screenWidth, screenHeight)
l := level.New(playerStartX, playerStartY)
p := player.New(g.AudioContext, playerStartX, playerStartY)
p.Level = l
g.Components = append(g.Components, p)
g.Components = append(g.Components, l)

This way as long as I have a function in each package that matches that interface I am able to just register them and have them run. I did this to help some nasty cyclic dependency issues I ran into early on.


Package Player

The player package controls all aspects of the player.

I do have a Level interface so I can inject the Level package in to prevent tightly coupling the packages together.

type Level interface {
    IsWalkable(x, y int) bool
    UpdateBoard(x, y, dx, dy int)
    UpdateCamera(x, y int)
} 

This is so the player can be in control of handling the players movement, yet still allow the board to enforce the actual movement rules. 

Package Level

Currently the Level package is getting to big. I just implemented a camera to track the player and allow them to explore levels larger than the default screen size. The Camera should probably be moved to its own package, but I will keep it in its own file here for now so I have more time to work on the dialog system I still need to implement.

Currently all maps are hand drawn in ASCII and loaded into the Level MapGrid for display and exploration.

While this game is too simple to suffer from any performance issues, I like to code as if I would face them. With that in mind I decided to use Row Major indexing for my arrays.

Row Major indexing can be confusing for people who are used to specifying gird[x][y] like you do in many game engines. Instead you have to specify grid[y][x] because it handles each row in order. This actually caused me a few movement bugs I spent an hour hunting down because I am so used to using Column Major.

A lot left to do

I still need to implement the dialog system, and the general story telling system.  

I may end up cutting the smaller side puzzles I was planning in favor of flushing out the dialog more in the time I have. I won't have much time to code again until next weekend.

Files

the-social-contract 11 MB
Version 0.1.0 1 day ago
the-social-shift-html5.zip Play in browser
Version 0.1.0 1 day ago
the-social-contract.exe 11 MB
Version 0.1.0 1 day ago

Get The Social Contract

Leave a comment

Log in with itch.io to leave a comment.