mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-16 20:20:57 +01:00
draw the grid explicitly thus leading to full cells w/o the grid
This commit is contained in:
61
src/play.go
61
src/play.go
@@ -46,22 +46,22 @@ type ScenePlay struct {
|
||||
|
||||
Clear bool
|
||||
|
||||
Grids []*Grid // 2 grids: one current, one next
|
||||
History History // holds state of past dead cells for evolution traces
|
||||
Index int // points to current grid
|
||||
Generations int64 // Stats
|
||||
TicksElapsed int // tick counter for game speed
|
||||
Camera Camera // for zoom+move
|
||||
World, Cache *ebiten.Image // actual image we render to
|
||||
WheelTurned bool // when user turns wheel multiple times, zoom faster
|
||||
Dragging bool // middle mouse is pressed, move canvas
|
||||
LastCursorPos []float64 // used to check if the user is dragging
|
||||
MarkTaken bool // true when mouse1 pressed
|
||||
MarkDone bool // true when mouse1 released, copy cells between Mark+Point
|
||||
Mark, Point image.Point // area to marks+save
|
||||
RunOneStep bool // mutable flags from config
|
||||
TPG int // current game speed (ticks per game)
|
||||
Theme Theme
|
||||
Grids []*Grid // 2 grids: one current, one next
|
||||
History History // holds state of past dead cells for evolution traces
|
||||
Index int // points to current grid
|
||||
Generations int64 // Stats
|
||||
TicksElapsed int // tick counter for game speed
|
||||
Camera Camera // for zoom+move
|
||||
World, Cache, GridImage *ebiten.Image // actual image we render to
|
||||
WheelTurned bool // when user turns wheel multiple times, zoom faster
|
||||
Dragging bool // middle mouse is pressed, move canvas
|
||||
LastCursorPos []float64 // used to check if the user is dragging
|
||||
MarkTaken bool // true when mouse1 pressed
|
||||
MarkDone bool // true when mouse1 released, copy cells between Mark+Point
|
||||
Mark, Point image.Point // area to marks+save
|
||||
RunOneStep bool // mutable flags from config
|
||||
TPG int // current game speed (ticks per game)
|
||||
Theme Theme
|
||||
}
|
||||
|
||||
func NewPlayScene(game *Game, config *Config) Scene {
|
||||
@@ -485,6 +485,13 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
|
||||
}
|
||||
}
|
||||
|
||||
if scene.Config.ShowGrid {
|
||||
// draw the pre-drawn grid onto the world
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(0, 0)
|
||||
scene.World.DrawImage(scene.GridImage, op)
|
||||
}
|
||||
|
||||
scene.DrawMark(scene.World)
|
||||
|
||||
scene.Camera.Render(scene.World, screen)
|
||||
@@ -589,6 +596,13 @@ func (scene *ScenePlay) InitCache() {
|
||||
}
|
||||
|
||||
for y := 0; y < scene.Config.Height; y++ {
|
||||
// horizontal grid line
|
||||
vector.StrokeLine(scene.GridImage,
|
||||
float32(0), float32(y*scene.Config.Cellsize),
|
||||
float32(scene.Config.Width*scene.Config.Cellsize), float32(y*scene.Config.Cellsize),
|
||||
1, scene.Theme.Color(ColGrid), false,
|
||||
)
|
||||
|
||||
for x := 0; x < scene.Config.Width; x++ {
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(
|
||||
@@ -597,6 +611,13 @@ func (scene *ScenePlay) InitCache() {
|
||||
)
|
||||
|
||||
scene.Cache.DrawImage(scene.Theme.Tile(ColDead), op)
|
||||
|
||||
// vertical grid line
|
||||
vector.StrokeLine(scene.GridImage,
|
||||
float32(x*scene.Config.Cellsize), float32(0),
|
||||
float32(x*scene.Config.Cellsize), float32(scene.Config.Height*scene.Config.Cellsize),
|
||||
1, scene.Theme.Color(ColGrid), false,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -615,6 +636,7 @@ func (scene *ScenePlay) InitGrid() {
|
||||
}
|
||||
|
||||
scene.History = NewHistory(scene.Config.Height, scene.Config.Width)
|
||||
|
||||
}
|
||||
|
||||
func (scene *ScenePlay) Init() {
|
||||
@@ -642,10 +664,17 @@ func (scene *ScenePlay) Init() {
|
||||
scene.Config.Height*scene.Config.Cellsize,
|
||||
)
|
||||
|
||||
scene.GridImage = ebiten.NewImage(
|
||||
scene.Config.Width*scene.Config.Cellsize,
|
||||
scene.Config.Height*scene.Config.Cellsize,
|
||||
)
|
||||
|
||||
scene.Theme = scene.Config.ThemeManager.GetCurrentTheme()
|
||||
scene.InitCache()
|
||||
|
||||
if scene.Config.DelayedStart && !scene.Config.Empty {
|
||||
// do not fill the grid when the main menu comes up first, the
|
||||
// user decides interactively what to do
|
||||
scene.Config.Empty = true
|
||||
scene.InitGrid()
|
||||
scene.Config.Empty = false
|
||||
|
||||
@@ -155,8 +155,8 @@ func (manager *ThemeManager) SetCurrentTheme(theme string) {
|
||||
func FillCell(tile *ebiten.Image, cellsize int, col color.RGBA) {
|
||||
vector.DrawFilledRect(
|
||||
tile,
|
||||
float32(1),
|
||||
float32(1),
|
||||
float32(0),
|
||||
float32(0),
|
||||
float32(cellsize),
|
||||
float32(cellsize),
|
||||
col, false,
|
||||
|
||||
Reference in New Issue
Block a user