diff --git a/cmd/tins2020/res/images/hover.png b/cmd/tins2020/res/images/hover.png new file mode 100644 index 0000000..efea337 Binary files /dev/null and b/cmd/tins2020/res/images/hover.png differ diff --git a/cmd/tins2020/res/textures.txt b/cmd/tins2020/res/textures.txt index af6d0d0..70fff51 100644 --- a/cmd/tins2020/res/textures.txt +++ b/cmd/tins2020/res/textures.txt @@ -2,6 +2,7 @@ tile-dirt: images/tile_dirt.png tile-grass: images/tile_grass.png tile-snow: images/tile_snow.png +hover: images/hover.png cactus-small-1: images/cactus_short_NE.png cactus-small-2: images/cactus_short_NW.png diff --git a/context.go b/context.go index b61b152..8644241 100644 --- a/context.go +++ b/context.go @@ -38,6 +38,8 @@ func (c *Context) Init(renderer *sdl.Renderer) { c.Renderer = renderer c.Fonts.Init(c.Resources.Copy()) c.Textures.Init(renderer, c.Resources.Copy()) + + c.Renderer.SetDrawBlendMode(sdl.BLENDMODE_BLEND) } func (c *Context) Quit() { c.ShouldQuit = true } diff --git a/terrainrenderer.go b/terrainrenderer.go index 69d9ca2..84c0b90 100644 --- a/terrainrenderer.go +++ b/terrainrenderer.go @@ -64,7 +64,9 @@ func (r *terrainRenderer) Handle(ctx *Context, event sdl.Event) { } func (r *terrainRenderer) Render(ctx *Context) { - toTileTexture := func(temp, humid float64) *Texture { + hover := Pt(int32(geom.Round32(r.hover.X)), int32(geom.Round32(r.hover.Y))) + toTileTexture := func(x, y int32) *Texture { + temp := r.terrain.Temp.Value(x, y) if temp < .35 { return ctx.Textures.Texture("tile-snow") } @@ -141,16 +143,14 @@ func (r *terrainRenderer) Render(ctx *Context) { // horizontal: [191, 321) = 130 // vertical: [267,332) = 65 - hover := Pt(int32(geom.Round32(r.hover.X)), int32(geom.Round32(r.hover.Y))) r.project.visibleTiles(func(x, y int32, pos Point) { - if x == hover.X && y == hover.Y { - return - } - temp := r.terrain.Temp.Value(x, y) - humid := r.terrain.Humid.Value(x, y) - text := toTileTexture(temp, humid) + text := toTileTexture(x, y) rect := r.project.screenToTileRect(pos) text.Copy(ctx.Renderer, rect) + + if x == hover.X && y == hover.Y { + ctx.Textures.Texture("hover").Copy(ctx.Renderer, rect) + } }) r.project.visibleTiles(func(x, y int32, pos Point) { @@ -160,7 +160,7 @@ func (r *terrainRenderer) Render(ctx *Context) { } placeX, placeY := r.terrain.PlaceX.Value(x, y), r.terrain.PlaceY.Value(x, y) - pos = r.project.mapToScreenF(float32(x)-.2+float32(.8*placeX-.4), float32(y)-.2+float32(.8*placeY-.4)) + pos = r.project.mapToScreenF(float32(x)-.2+float32(.9*placeX-.45), float32(y)-.2+float32(.9*placeY-.45)) text.Copy(ctx.Renderer, r.project.screenToTileRect(pos)) })