summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2019-07-08 02:00:16 +0200
committerDimitri Sokolyuk <demon@dim13.org>2019-07-08 02:00:16 +0200
commit49e544d1b788f6db63ac76199cbbcf77eda9ca00 (patch)
tree643666632812a6a0ee66ca7c1ac315be4e361b87
parentbb63ee8843d80be42bf64eca2f8eb9139cc72480 (diff)
...
-rw-r--r--fire/main.go31
1 files changed, 13 insertions, 18 deletions
diff --git a/fire/main.go b/fire/main.go
index 1f8f035..093ef2a 100644
--- a/fire/main.go
+++ b/fire/main.go
@@ -5,7 +5,6 @@ package main
import (
"errors"
"flag"
- "fmt"
"image"
"image/color"
"log"
@@ -14,7 +13,6 @@ import (
"github.com/disintegration/imaging"
"github.com/hajimehoshi/ebiten"
- "github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/inpututil"
)
@@ -58,9 +56,8 @@ var palette = color.Palette{
}
type drawContext struct {
- img *image.Paletted
- isOn bool
- debug bool
+ img *image.Paletted
+ on bool
}
func newDrawContext(x, y int) *drawContext {
@@ -69,16 +66,19 @@ func newDrawContext(x, y int) *drawContext {
return &drawContext{img: img}
}
-func (dc *drawContext) toggle() *drawContext {
- var c uint8
- if !dc.isOn {
- c = uint8(len(palette) - 1)
+func seed(img *image.Paletted, c int) {
+ for x := 0; x < img.Bounds().Max.X; x++ {
+ img.SetColorIndex(x, 0, uint8(c))
}
- r := dc.img.Bounds().Max
- for x := 0; x < r.X; x++ {
- dc.img.SetColorIndex(x, 0, c)
+}
+
+func (dc *drawContext) toggle() *drawContext {
+ if dc.on {
+ seed(dc.img, 0)
+ } else {
+ seed(dc.img, len(palette)-1)
}
- dc.isOn = !dc.isOn
+ dc.on = !dc.on
return dc
}
@@ -100,17 +100,12 @@ func (dc *drawContext) update(screen *ebiten.Image) error {
switch {
case inpututil.IsKeyJustPressed(ebiten.KeyQ):
return errors.New("exit")
- case inpututil.IsKeyJustPressed(ebiten.KeyD):
- dc.debug = !dc.debug
case inpututil.IsKeyJustPressed(ebiten.KeySpace):
dc.toggle()
}
drawTo(dc.img)
if !ebiten.IsDrawingSkipped() {
screen.ReplacePixels(imaging.FlipV(dc.img).Pix)
- if dc.debug {
- ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f", ebiten.CurrentTPS()))
- }
}
return nil
}