mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-17 04:30:57 +01:00
made wrap mode switchable, new default: off
This commit is contained in:
@@ -30,6 +30,7 @@ Based on: https://youtu.be/FWSR_7kZuYg?si=ix1dmo76D8AmF25F
|
|||||||
* game patterns can be loaded using RLE files, see https://catagolue.hatsya.com/home
|
* game patterns can be loaded using RLE files, see https://catagolue.hatsya.com/home
|
||||||
* you can paint your own patterns in the game
|
* 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
|
* the game can also be started with an empty grid, which is easier to paint patterns
|
||||||
|
* wrap around grid mode can be enabled
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
|
|||||||
32
game.go
32
game.go
@@ -45,7 +45,8 @@ type Game struct {
|
|||||||
Markmode bool // enabled with 'c'
|
Markmode bool // enabled with 'c'
|
||||||
MarkTaken bool // true when mouse1 pressed
|
MarkTaken bool // true when mouse1 pressed
|
||||||
MarkDone bool // true when mouse1 released, copy cells between Mark+Point
|
MarkDone bool // true when mouse1 released, copy cells between Mark+Point
|
||||||
Mark, Point image.Point
|
Mark, Point image.Point // area to marks+save
|
||||||
|
Wrap bool // wether wraparound mode is in place or not
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
func (game *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||||
@@ -551,13 +552,28 @@ func (game *Game) Init() {
|
|||||||
func (game *Game) CountNeighbors(x, y int) int64 {
|
func (game *Game) CountNeighbors(x, y int) int64 {
|
||||||
var sum int64
|
var sum int64
|
||||||
|
|
||||||
// so we look ad all 8 neighbors surrounding us. In case we are on
|
for nbgX := -1; nbgX < 2; nbgX++ {
|
||||||
// an edge, then we'll look at the neighbor on the other side of
|
for nbgY := -1; nbgY < 2; nbgY++ {
|
||||||
// the grid, thus wrapping lookahead around.
|
fmt.Printf("nbgX: %d, nbgY: %d\n", nbgX, nbgY)
|
||||||
for i := -1; i < 2; i++ {
|
|
||||||
for j := -1; j < 2; j++ {
|
var col, row int
|
||||||
col := (x + i + game.Width) % game.Width
|
if game.Wrap {
|
||||||
row := (y + j + game.Height) % game.Height
|
// In wrap mode we look at all the 8 neighbors surrounding us.
|
||||||
|
// In case we are on an edge we'll look at the neighbor on the
|
||||||
|
// other side of the grid, thus wrapping lookahead around
|
||||||
|
// using the mod() function.
|
||||||
|
col = (x + nbgX + game.Width) % game.Width
|
||||||
|
row = (y + nbgY + game.Height) % game.Height
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// In traditional grid mode the edges are deadly
|
||||||
|
if x+nbgX < 0 || x+nbgX >= game.Width || y+nbgY < 0 || y+nbgY >= game.Height {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
col = x + nbgX
|
||||||
|
row = y + nbgY
|
||||||
|
}
|
||||||
|
|
||||||
sum += game.Grids[game.Index].Data[row][col]
|
sum += game.Grids[game.Index].Data[row][col]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
main.go
3
main.go
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "v0.0.5"
|
VERSION = "v0.0.6"
|
||||||
Alive = 1
|
Alive = 1
|
||||||
Dead = 0
|
Dead = 0
|
||||||
)
|
)
|
||||||
@@ -60,6 +60,7 @@ func main() {
|
|||||||
pflag.BoolVarP(&game.Empty, "empty", "e", false, "start with an empty screen")
|
pflag.BoolVarP(&game.Empty, "empty", "e", false, "start with an empty screen")
|
||||||
pflag.BoolVarP(&game.Invert, "invert", "i", false, "invert colors (dead cell: black)")
|
pflag.BoolVarP(&game.Invert, "invert", "i", false, "invert colors (dead cell: black)")
|
||||||
pflag.BoolVarP(&game.ShowEvolution, "show-evolution", "s", false, "show evolution tracks")
|
pflag.BoolVarP(&game.ShowEvolution, "show-evolution", "s", false, "show evolution tracks")
|
||||||
|
pflag.BoolVarP(&game.Wrap, "wrap-around", "w", false, "wrap around grid mode")
|
||||||
|
|
||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user