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