mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
example/mapeditor: Update
This commit is contained in:
parent
dee7b1a328
commit
9b1aee1a21
@ -17,9 +17,18 @@ package mapeditor
|
|||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||||
|
"image/color"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type MapTool int
|
||||||
|
|
||||||
|
const (
|
||||||
|
MapToolScroll MapTool = iota
|
||||||
|
MapToolPen
|
||||||
|
MapToolFill
|
||||||
|
)
|
||||||
|
|
||||||
var mapToolsImage *ebiten.Image
|
var mapToolsImage *ebiten.Image
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -32,6 +41,7 @@ func init() {
|
|||||||
|
|
||||||
type MapTools struct {
|
type MapTools struct {
|
||||||
focused bool
|
focused bool
|
||||||
|
current MapTool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMapTools() *MapTools {
|
func NewMapTools() *MapTools {
|
||||||
@ -41,7 +51,13 @@ func NewMapTools() *MapTools {
|
|||||||
func (m *MapTools) Update() {
|
func (m *MapTools) Update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MapTools) Current() MapTool {
|
||||||
|
return m.current
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MapTools) Draw(i *ebiten.Image, x, y, width, height int) error {
|
func (m *MapTools) Draw(i *ebiten.Image, x, y, width, height int) error {
|
||||||
|
i.DrawFilledRect(x+int(m.current)*32, y, 32, 32, color.White)
|
||||||
|
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.GeoM.Translate(float64(x), float64(y))
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
op.GeoM.Scale(2, 2)
|
op.GeoM.Scale(2, 2)
|
||||||
|
@ -60,9 +60,13 @@ func (m *MapView) Update(input *Input, ox, oy, width, height int, tileSet *TileS
|
|||||||
if input.MouseButtonState(ebiten.MouseButtonLeft) == 1 {
|
if input.MouseButtonState(ebiten.MouseButtonLeft) == 1 {
|
||||||
m.focused = true
|
m.focused = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch m.mapTools.Current() {
|
||||||
|
case MapToolPen:
|
||||||
if m.focused && ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
|
if m.focused && ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
|
||||||
m.m.SetTile(m.cursorX, m.cursorY, selectedTile)
|
m.m.SetTile(m.cursorX, m.cursorY, selectedTile)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +76,7 @@ func (m *MapView) Draw(i *ebiten.Image, x, y, width, height int) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.cursorX != -1 && m.cursorY != -1 {
|
if m.mapTools.Current() != MapToolScroll && m.cursorX != -1 && m.cursorY != -1 {
|
||||||
sx := mapX + m.cursorX*TileWidth
|
sx := mapX + m.cursorX*TileWidth
|
||||||
sy := mapY + m.cursorY*TileHeight
|
sy := mapY + m.cursorY*TileHeight
|
||||||
i.DrawRect(sx, sy, TileWidth, TileHeight, color.Black)
|
i.DrawRect(sx, sy, TileWidth, TileHeight, color.Black)
|
||||||
|
Loading…
Reference in New Issue
Block a user