Implementation of the classic Sokoban in Go, using Pixel 2D Game library.
$ go get github.com/csixteen/sokoban/cmd/sokoban
The project uses Go modules, so you'll need a version of Go more recent than 1.11. You will also need to have pkger installed.
$ make bin
go build -o soko cmd/sokoban/*.go
$ ./soko
- Arrows Up, Down, Left and Right - move the character to the adjacent cell
q
- quits the gamer
- resets the level
The levels are defined in the levels.dat
file. Each level is specified as a number of consecutive lines, all with the same length (essentially, a matrix).
The matrices in levels.dat
will be rendered 90 degrees rotated anti-clockwise. I still haven't fixed this, but I don't think it's that big of a deal. Here is the matrix that corresponds to the level on the screenshot:
wwwwwwww
wffwfffw
wjbggbfw
wfbgbffw
wffggbfw
wffffffw
wfwwfwww
wwwwwwww
You'll have to run make bin
after you make changes to levels.dat.
These are the current board elements:
w
- wall (unmovable)b
- block (movable)f
- floorg
- goal (where you need to put the block onto)o
- block on a goal (becomes unmovable)h
- player facing leftj
- player facing downk
- player facing upl
- player facing right
$ make test
go test -v pkg/utils/*.go
=== RUN TestPushToStack
--- PASS: TestPushToStack (0.00s)
=== RUN TestPopFromStack
--- PASS: TestPopFromStack (0.00s)
=== RUN TestPopFromEmptyStack
--- PASS: TestPopFromEmptyStack (0.00s)
=== RUN TestTopFromEmptyStack
--- PASS: TestTopFromEmptyStack (0.00s)
PASS
ok command-line-arguments (cached)
go test -v pkg/types/*.go
=== RUN TestNewBoard
--- PASS: TestNewBoard (0.00s)
=== RUN TestMovePlayer
--- PASS: TestMovePlayer (0.00s)
=== RUN TestMovePlayerTwoBlocks
--- PASS: TestMovePlayerTwoBlocks (0.00s)
PASS
ok command-line-arguments (cached)
- Fix the orientation of the board. Right now, the level description in
levels.dat
results in a board that is rotated 90 degrees anti-clockwise when the window is rendered. - Add more levels.
- Keep track of time that it takes to complete each level and display it.
- Keep track of solved levels, so that the player doesn't have to start all over from Level 1 every single time.
- Provide the ability to choose from previously solved levels.
There is still lots of room for improving things. Pull-requests with bug fixes or improvements are more than welcome.
- Pixel 2D Game library: https://github.com/faiface/pixel
- SpriteSheets: https://kenney.nl/assets/sokoban
- Pkger: https://github.com/markbates/pkger. I'm using this tool to embedded the static assets into the binary. Thanks to skuzzymiglet for the suggestion.