aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go73
1 files changed, 1 insertions, 72 deletions
diff --git a/main.go b/main.go
index 10702a0..3042b06 100644
--- a/main.go
+++ b/main.go
@@ -11,8 +11,7 @@ import (
type Action string
const (
- Selecting Action = "selecting"
- PlacingWall Action = "placing-wall"
+ Selecting Action = "selecting"
)
type Tile struct {
@@ -30,25 +29,8 @@ func (t Tile) CollisionBounds() Rectangle {
return Rectangle{t.Position, t.Position.Add(t.Size)}
}
-type Block struct {
- Tile
- typ BlockType
-}
-
-type BlockType int
-
-const (
- WallBlock BlockType = iota
- IronBlock
-)
-
-func (b Block) CollisionBounds() Rectangle {
- return b.Tile.CollisionBounds().Sub(b.Size.Div(2))
-}
-
var soilColor = color.RGBA{0x60, 0x40, 0x20, 0xff}
var soil = NewTile(Point{2800, 2000}, Point{200, 200}, soilColor)
-var wallButton = NewTile(Point{100, 100}, Point{50, 50}, color.RGBA{0x00, 0x00, 0x00, 0xff})
type Selection struct {
IsActive bool
@@ -59,14 +41,10 @@ type Game struct {
Persons []*Person
CurrentAction Action
Selection Selection
- Blocks []Block
}
func (g *Game) getBlocked() map[Point]bool {
blocked := map[Point]bool{}
- for _, w := range g.Blocks {
- blocked[w.Position] = true
- }
return blocked
}
@@ -112,54 +90,19 @@ func (g *Game) updateSelecting(cursor Point) {
}
}
-func (g *Game) updatePlacingWall(cursor Point) {
- if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft) {
- if cursor.In(soil.Bounds()) {
- position := cursor.Sub(soil.Position).Div(100).Mul(100).Add(Point{50, 50})
- g.Blocks = append(g.Blocks, Block{NewTile(Point{100, 100}, position, color.RGBA{0x00, 0x00, 0x00, 0xff}), WallBlock})
- }
- }
-}
-
func (g *Game) Update() error {
x, y := ebiten.CursorPosition()
cursor := Point{x, y}
- if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft) && cursor.In(wallButton.CollisionBounds()) {
- if g.CurrentAction == PlacingWall {
- g.CurrentAction = Selecting
- } else {
- g.CurrentAction = PlacingWall
- }
- }
if inpututil.IsKeyJustReleased(ebiten.KeyEscape) {
g.CurrentAction = Selecting
}
switch g.CurrentAction {
case Selecting:
g.updateSelecting(cursor)
- case PlacingWall:
- if g.Selection.IsActive {
- g.Selection.IsActive = false
- }
- g.updatePlacingWall(cursor)
}
for _, p := range g.Persons {
p.Update()
}
- soilCursor := cursor.Sub(soil.Position)
- isIronHovered := false
- for _, w := range g.Blocks {
- if w.typ == IronBlock {
- if soilCursor.In(w.CollisionBounds()) {
- isIronHovered = true
- }
- }
- }
- if isIronHovered {
- ebiten.SetCursorShape(ebiten.CursorShapeCrosshair)
- } else {
- ebiten.SetCursorShape(ebiten.CursorShapeDefault)
- }
return nil
}
@@ -168,13 +111,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
screenClick := Point{x, y}
screen.Fill(color.RGBA{0x80, 0xa0, 0xc0, 0xff})
soil.Fill(soilColor)
- for _, w := range g.Blocks {
- bounds := w.Image.Bounds()
- op := &ebiten.DrawImageOptions{}
- op.GeoM.Translate(float64(w.Position.X-bounds.Dx()/2), float64(w.Position.Y-bounds.Dy()/2))
- soil.DrawImage(w.Image, op)
-
- }
for _, p := range g.Persons {
bounds := p.Image().Bounds()
op := &ebiten.DrawImageOptions{}
@@ -191,9 +127,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(soil.Position.X), float64(soil.Position.Y))
screen.DrawImage(soil.Image, op)
- op = &ebiten.DrawImageOptions{}
- op.GeoM.Translate(float64(wallButton.Position.X), float64(wallButton.Position.Y))
- screen.DrawImage(wallButton.Image, op)
if g.Selection.IsActive {
vector.StrokeRect(screen, float32(g.Selection.Start.X), float32(g.Selection.Start.Y), float32(screenClick.X-g.Selection.Start.X), float32(screenClick.Y-g.Selection.Start.Y), 10.0, color.RGBA{256 * 3 / 16, 256 * 3 / 16, 256 * 3 / 16, 256 / 4}, true)
}
@@ -212,10 +145,6 @@ func main() {
game.Persons = append(game.Persons, &mainPerson)
game.Persons = append(game.Persons, &nonPlayerPerson)
game.CurrentAction = Selecting
- for i := 0; i < 10; i++ {
- game.Blocks = append(game.Blocks, Block{NewTile(Point{100, 100}, Point{350 + i*100, 350}, color.RGBA{0x00, 0x00, 0x00, 0xff}), WallBlock})
- }
- game.Blocks = append(game.Blocks, Block{NewTile(Point{100, 100}, Point{1250, 1250}, color.RGBA{0x80, 0x80, 0x80, 0xff}), IronBlock})
if err := ebiten.RunGame(game); err != nil {
panic(err)
}