summaryrefslogtreecommitdiff
path: root/tilemap.go
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2024-04-21 21:23:21 +0100
committerdavidovski <david@davidovski.xyz>2024-04-21 21:23:21 +0100
commit2d6d9f97093544e0d2faccc94f3b8bf369c03819 (patch)
treecab6b58d90a066b743764dfa91fcabfc87e9ba0e /tilemap.go
parent64757d18c4b2669c46f2dc88293cf2f0ea1887db (diff)
add placing objects
Diffstat (limited to 'tilemap.go')
-rw-r--r--tilemap.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/tilemap.go b/tilemap.go
index b24bdb6..0bdb401 100644
--- a/tilemap.go
+++ b/tilemap.go
@@ -5,7 +5,6 @@ import (
"log"
"image"
_ "image/png"
- "github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
@@ -64,7 +63,7 @@ func NewTilemap(layers [][]int, mapWidth int) Tilemap {
tilemap.surface = ebiten.NewImage(mapWidth*tilemap.tileSize, len(layers[0])/mapWidth*tilemap.tileSize)
var err error
- tilemap.tilesImage, _, err = ebitenutil.NewImageFromFile("tiles.png")
+ tilemap.tilesImage = tilesImage
if err != nil {
log.Fatal(err)
@@ -89,6 +88,11 @@ func (tm * Tilemap) CalculateCollisions() {
}
}
+
+func Collide(r1 image.Rectangle, r2 image.Rectangle) bool {
+ return ! ( r2.Min.X > r1.Max.X || r2.Max.X < r1.Min.X || r2.Min.Y > r1.Max.Y || r2.Max.Y < r1.Min.Y)
+}
+
func (t * Tilemap) Collide(x, y, width, height int) bool {
r1 := image.Rect(
x,
@@ -111,8 +115,8 @@ func (t * Tilemap) Collide(x, y, width, height int) bool {
func (t * Tilemap) CollideObject(object *GameObject) bool {
width := object.image.Bounds().Dx()
height := object.image.Bounds().Dy()
- x := int(object.x*float32(t.tileSize))
- y := int(object.y*float32(t.tileSize))
+ x := int(object.x)
+ y := int(object.y)
return t.Collide(x, y, width, height)
}