Added hover effect for terrain.
This commit is contained in:
parent
c02fb342a7
commit
72da0ef462
BIN
cmd/tins2020/res/images/hover.png
Normal file
BIN
cmd/tins2020/res/images/hover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
@ -2,6 +2,7 @@
|
|||||||
tile-dirt: images/tile_dirt.png
|
tile-dirt: images/tile_dirt.png
|
||||||
tile-grass: images/tile_grass.png
|
tile-grass: images/tile_grass.png
|
||||||
tile-snow: images/tile_snow.png
|
tile-snow: images/tile_snow.png
|
||||||
|
hover: images/hover.png
|
||||||
|
|
||||||
cactus-small-1: images/cactus_short_NE.png
|
cactus-small-1: images/cactus_short_NE.png
|
||||||
cactus-small-2: images/cactus_short_NW.png
|
cactus-small-2: images/cactus_short_NW.png
|
||||||
|
@ -38,6 +38,8 @@ func (c *Context) Init(renderer *sdl.Renderer) {
|
|||||||
c.Renderer = renderer
|
c.Renderer = renderer
|
||||||
c.Fonts.Init(c.Resources.Copy())
|
c.Fonts.Init(c.Resources.Copy())
|
||||||
c.Textures.Init(renderer, c.Resources.Copy())
|
c.Textures.Init(renderer, c.Resources.Copy())
|
||||||
|
|
||||||
|
c.Renderer.SetDrawBlendMode(sdl.BLENDMODE_BLEND)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Quit() { c.ShouldQuit = true }
|
func (c *Context) Quit() { c.ShouldQuit = true }
|
||||||
|
@ -64,7 +64,9 @@ func (r *terrainRenderer) Handle(ctx *Context, event sdl.Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *terrainRenderer) Render(ctx *Context) {
|
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 {
|
if temp < .35 {
|
||||||
return ctx.Textures.Texture("tile-snow")
|
return ctx.Textures.Texture("tile-snow")
|
||||||
}
|
}
|
||||||
@ -141,16 +143,14 @@ func (r *terrainRenderer) Render(ctx *Context) {
|
|||||||
// horizontal: [191, 321) = 130
|
// horizontal: [191, 321) = 130
|
||||||
// vertical: [267,332) = 65
|
// 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) {
|
r.project.visibleTiles(func(x, y int32, pos Point) {
|
||||||
if x == hover.X && y == hover.Y {
|
text := toTileTexture(x, y)
|
||||||
return
|
|
||||||
}
|
|
||||||
temp := r.terrain.Temp.Value(x, y)
|
|
||||||
humid := r.terrain.Humid.Value(x, y)
|
|
||||||
text := toTileTexture(temp, humid)
|
|
||||||
rect := r.project.screenToTileRect(pos)
|
rect := r.project.screenToTileRect(pos)
|
||||||
text.Copy(ctx.Renderer, rect)
|
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) {
|
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)
|
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))
|
text.Copy(ctx.Renderer, r.project.screenToTileRect(pos))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user