enhanced doc, fixed drawing when zooming or moving canvas

This commit is contained in:
2024-05-23 15:23:06 +02:00
parent ab51a27b4c
commit 8241cf83f2
2 changed files with 34 additions and 16 deletions

View File

@@ -4,6 +4,21 @@ I wanted to play around a little bit with GOL in golang and here's the
result. It's a simple game using result. It's a simple game using
[ebitengine](https://github.com/hajimehoshi/ebiten/). [ebitengine](https://github.com/hajimehoshi/ebiten/).
# Features
* flexible parameters as grid and cell size
* colors can be inverted
* game grid lines can be enabled or disabled
* game speed can be adjusted on startup and in-game
* you can zoom in and out of the canvas and move it around
* game can be paused any time
* it can be run step-wise
* game state can be saved any time and loaded later on startup
* various Life rules can be used, the rule format `B[0-9]+/S[0-9]+` is fully supported
* game patterns can be loaded using RLE files, see https://catagolue.hatsya.com/home
* you can paint your own patterns in the game
* the game can also be started with an empty grid, which is easier to paint patterns
# Build and install # Build and install
Just execute: `go build .` and use the resulting executable. Just execute: `go build .` and use the resulting executable.
@@ -16,19 +31,21 @@ The game has a couple of commandline options:
```default ```default
Usage of ./gameoflife: Usage of ./gameoflife:
-c, --cellsize int cell size in pixels (default 8) -c, --cellsize int cell size in pixels (default 8)
-d, --debug show debug info -d, --debug show debug info
-D, --density int density of random cells (default 10) -D, --density int density of random cells (default 10)
-e, --empty start with an empty screen -e, --empty start with an empty screen
-H, --height int grid height in cells (default 40) -H, --height int grid height in cells (default 40)
-i, --invert invert colors (dead cell: black) -i, --invert invert colors (dead cell: black)
-n, --nogrid do not draw grid lines -l, --load-state-file string game state file
-p, --paused do not start simulation (use space to start) -n, --nogrid do not draw grid lines
-r, --rule string game rule (default "B3/S23") -p, --paused do not start simulation (use space to start)
-s, --show-evolution show evolution tracks -f, --rle-file string RLE pattern file
-t, --tps int game speed in ticks per second (default 60) -r, --rule string game rule (default "B3/S23")
-v, --version show version -s, --show-evolution show evolution tracks
-W, --width int grid width in cells (default 40) -t, --ticks-per-generation int game speed: the higher the slower (default: 10) (default 10)
-v, --version show version
-W, --width int grid width in cells (default 40)
``` ```
While it runs, there are a couple of commands you can use: While it runs, there are a couple of commands you can use:

View File

@@ -243,9 +243,10 @@ func (game *Game) Update() error {
// set a cell to alive or dead // set a cell to alive or dead
func (game *Game) ToggleCellOnCursorPos(alive int) { func (game *Game) ToggleCellOnCursorPos(alive int) {
xPX, yPX := ebiten.CursorPosition() // use cursor pos relative to the world
x := xPX / game.Cellsize worldX, worldY := game.Camera.ScreenToWorld(ebiten.CursorPosition())
y := yPX / game.Cellsize x := int(worldX) / game.Cellsize
y := int(worldY) / game.Cellsize
//fmt.Printf("cell at %d,%d\n", x, y) //fmt.Printf("cell at %d,%d\n", x, y)