mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-16 20:20:57 +01:00
fix #7: use only left mouse button to draw, it toggles cell state
This commit is contained in:
@@ -82,17 +82,16 @@ Usage of ./golsky:
|
|||||||
|
|
||||||
While it runs, there are a couple of commands you can use:
|
While it runs, there are a couple of commands you can use:
|
||||||
|
|
||||||
* left mouse click: set a cell to alife (also pauses the game)
|
|
||||||
* right mouse click: set a cell to dead
|
|
||||||
* space: pause or resume the game
|
* space: pause or resume the game
|
||||||
* while game is paused: press n to forward one step
|
* while game is paused: press n to forward one step
|
||||||
* page up: speed up
|
* page up: speed up
|
||||||
* page down: slow down
|
* page down: slow down
|
||||||
* Mouse wheel: zoom in or out
|
* Mouse wheel: zoom in or out
|
||||||
* move mouse while left mouse button pressed: move canvas
|
* move mouse while left mouse button pressed: move canvas
|
||||||
* i: enter "insert" (draw) mode: use left mouse to set cells alife and right
|
* i: enter "insert" (draw) mode: use left mouse to toggle cells alife state.
|
||||||
button to dead. Leave with "space". While in insert mode, use middle mouse
|
Leave with insert mode "space". While in insert mode, use middle mouse
|
||||||
button to drag grid.
|
button to drag the grid.
|
||||||
* r: reset to 1:1 zoom
|
* r: reset to 1:1 zoom
|
||||||
* escape: open menu
|
* escape: open menu
|
||||||
* s: save game state to file (can be loaded with -l)
|
* s: save game state to file (can be loaded with -l)
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const (
|
|||||||
DEFAULT_CELLSIZE = 4
|
DEFAULT_CELLSIZE = 4
|
||||||
DEFAULT_ZOOMFACTOR = 400
|
DEFAULT_ZOOMFACTOR = 400
|
||||||
DEFAULT_GEOM = "640x384"
|
DEFAULT_GEOM = "640x384"
|
||||||
DEFAULT_THEME = "standard" // "light" // inverse => "dark"
|
DEFAULT_THEME = "standard"
|
||||||
)
|
)
|
||||||
|
|
||||||
const KEYBINDINGS string = `
|
const KEYBINDINGS string = `
|
||||||
@@ -62,9 +62,9 @@ const KEYBINDINGS string = `
|
|||||||
- PAGE DOWN: slow down
|
- PAGE DOWN: slow down
|
||||||
- MOUSE WHEEL: zoom in or out
|
- MOUSE WHEEL: zoom in or out
|
||||||
- LEFT MOUSE BUTTON: use to drag canvas, keep clicked and move mouse
|
- LEFT MOUSE BUTTON: use to drag canvas, keep clicked and move mouse
|
||||||
- I: enter "insert" (draw) mode: use left mouse to set cells alife and right
|
- I: enter "insert" (draw) mode: use left mouse to toggle a cells alife state.
|
||||||
button to dead. Leave with "space". While in insert mode, use middle mouse
|
Leave with insert mode with "space". While in insert mode, use middle mouse
|
||||||
button to drag grid.
|
button to drag the grid.
|
||||||
- R: reset to 1:1 zoom
|
- R: reset to 1:1 zoom
|
||||||
- ESCAPE: open menu, o: open options menu
|
- ESCAPE: open menu, o: open options menu
|
||||||
- S: save game state to file (can be loaded with -l)
|
- S: save game state to file (can be loaded with -l)
|
||||||
|
|||||||
10
src/play.go
10
src/play.go
@@ -264,10 +264,8 @@ func (scene *ScenePlay) CheckInput() {
|
|||||||
func (scene *ScenePlay) CheckDrawingInput() {
|
func (scene *ScenePlay) CheckDrawingInput() {
|
||||||
if scene.Config.Drawmode {
|
if scene.Config.Drawmode {
|
||||||
switch {
|
switch {
|
||||||
case ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft):
|
case inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft):
|
||||||
scene.ToggleCellOnCursorPos(Alive)
|
scene.ToggleCellOnCursorPos()
|
||||||
case ebiten.IsMouseButtonPressed(ebiten.MouseButtonRight):
|
|
||||||
scene.ToggleCellOnCursorPos(Dead)
|
|
||||||
case inpututil.IsKeyJustPressed(ebiten.KeyEscape):
|
case inpututil.IsKeyJustPressed(ebiten.KeyEscape):
|
||||||
scene.Config.Drawmode = false
|
scene.Config.Drawmode = false
|
||||||
}
|
}
|
||||||
@@ -465,14 +463,14 @@ func (scene *ScenePlay) Update() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set a cell to alive or dead
|
// set a cell to alive or dead
|
||||||
func (scene *ScenePlay) ToggleCellOnCursorPos(alive uint8) {
|
func (scene *ScenePlay) ToggleCellOnCursorPos() {
|
||||||
// use cursor pos relative to the world
|
// use cursor pos relative to the world
|
||||||
worldX, worldY := scene.Camera.ScreenToWorld(ebiten.CursorPosition())
|
worldX, worldY := scene.Camera.ScreenToWorld(ebiten.CursorPosition())
|
||||||
x := int(worldX) / scene.Config.Cellsize
|
x := int(worldX) / scene.Config.Cellsize
|
||||||
y := int(worldY) / scene.Config.Cellsize
|
y := int(worldY) / scene.Config.Cellsize
|
||||||
|
|
||||||
if x > -1 && y > -1 && x < scene.Config.Width && y < scene.Config.Height {
|
if x > -1 && y > -1 && x < scene.Config.Width && y < scene.Config.Height {
|
||||||
scene.Grids[scene.Index].Data[y][x].State = alive
|
scene.Grids[scene.Index].Data[y][x].State ^= 1
|
||||||
scene.History.Age[y][x] = 1
|
scene.History.Age[y][x] = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user