fixed hiddendoor tiles, now uses destruct shader no spriteset
9
TODO.md
@ -29,12 +29,9 @@
|
||||
- Player can collect collectible hidden under obstacle (should be
|
||||
fixed when above is fixed)
|
||||
|
||||
- With new tileset images, hidden doors visually not working
|
||||
anymore. So I need entit-tiles containing the wall tiles AND I need
|
||||
to add a shader for a wall destruct animation. Otherwise I'd have to
|
||||
store lots of images pairs, and I can't do that in LDTK.
|
||||
|
||||
- https://www.quasilyte.dev/blog/post/ebitengine-shaders/#round-1-applying-the-damage-mask
|
||||
- Star Obstacle doesn't do any damage!
|
||||
|
||||
- Remove Sprite from Tile{}, not used anymore
|
||||
|
||||
## Collider Rework [abandoned: see branch collider-system, fails]
|
||||
|
||||
|
||||
@ -33,6 +33,8 @@ type Tile struct {
|
||||
TileNames []string // same thing, only the names
|
||||
Obstacle bool // is an obstacle/enemy
|
||||
Direction int // obstacle business end shows into this direction
|
||||
Shader *ebiten.Shader
|
||||
Alpha *ebiten.Image
|
||||
}
|
||||
|
||||
func (tile *Tile) Clone() *Tile {
|
||||
@ -53,6 +55,8 @@ func (tile *Tile) Clone() *Tile {
|
||||
TileNames: tile.TileNames,
|
||||
Obstacle: tile.Obstacle,
|
||||
Direction: tile.Direction,
|
||||
Alpha: tile.Alpha,
|
||||
Shader: tile.Shader,
|
||||
}
|
||||
|
||||
return newtile
|
||||
@ -158,24 +162,16 @@ func NewTileTranswall(class []string) *Tile {
|
||||
}
|
||||
}
|
||||
|
||||
func NewTileHiddenDoor(class []string) *Tile {
|
||||
sprites := []*ebiten.Image{}
|
||||
names := []string{}
|
||||
|
||||
for _, sprite := range class {
|
||||
sprites = append(sprites, Assets[sprite])
|
||||
names = append(names, sprite)
|
||||
}
|
||||
|
||||
func NewTileHiddenDoor(class, alpha string) *Tile {
|
||||
return &Tile{
|
||||
Id: 'W',
|
||||
Class: "hiddendoor",
|
||||
Solid: false,
|
||||
Renderable: true,
|
||||
Destroyable: true,
|
||||
Tiles: sprites,
|
||||
Sprite: sprites[0], // initially use the first
|
||||
TileNames: names,
|
||||
Sprite: Assets[class],
|
||||
Alpha: Assets[alpha],
|
||||
Shader: Shaders["destruct"],
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,15 +192,21 @@ func InitTiles() TileRegistry {
|
||||
"ObstacleWest": NewTileObstacle("obstacle-west", config.West),
|
||||
"ObstacleEast": NewTileObstacle("obstacle-east", config.East),
|
||||
"Particle": NewTileParticle([]string{
|
||||
//"particle-ring-1",
|
||||
"particle-ring-1",
|
||||
"particle-ring-2",
|
||||
"particle-ring-3",
|
||||
"particle-ring-4",
|
||||
"particle-ring-5",
|
||||
"particle-ring-6",
|
||||
}),
|
||||
"Transient": NewTileTranswall([]string{"transwall", "block-orange-32"}),
|
||||
"HiddenDoor": NewTileHiddenDoor([]string{"block-greycolored", "block-greycolored-damaged"}),
|
||||
"Transient": NewTileTranswall([]string{"transwall", "block-orange-32"}),
|
||||
"HiddenDoor": NewTileHiddenDoor("block-greycolored", "damage"),
|
||||
"HiddenDoor2": NewTileHiddenDoor("block-greycolored", "damage"),
|
||||
"HiddenDoor3": NewTileHiddenDoor("block-greycolored", "damage"),
|
||||
"HiddenDoor4": NewTileHiddenDoor("block-greycolored", "damage"),
|
||||
"HiddenDoor5": NewTileHiddenDoor("block-greycolored", "damage"),
|
||||
"HiddenDoor6": NewTileHiddenDoor("block-greycolored", "damage"),
|
||||
"HiddenDoor7": NewTileHiddenDoor("block-greycolored", "damage"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
49
assets/loader-shaders.go
Normal file
@ -0,0 +1,49 @@
|
||||
package assets
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"log/slog"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type ShaderRegistry map[string]*ebiten.Shader
|
||||
|
||||
var Shaders = LoadShaders("shaders")
|
||||
|
||||
func LoadShaders(dir string) ShaderRegistry {
|
||||
shaders := ShaderRegistry{}
|
||||
|
||||
entries, err := assetfs.ReadDir(dir)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to read shaders dir %s: %s", dir, err)
|
||||
}
|
||||
|
||||
for _, file := range entries {
|
||||
path := filepath.Join(dir, file.Name())
|
||||
fd, err := assetfs.Open(path)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to open shader file %s: %s", file.Name(), err)
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
name := strings.TrimSuffix(file.Name(), ".kg")
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
buf.ReadFrom(fd)
|
||||
|
||||
shader, err := ebiten.NewShader([]byte(buf.Bytes()))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
shaders[name] = shader
|
||||
|
||||
slog.Debug("loaded shader asset", "path", path)
|
||||
}
|
||||
|
||||
return shaders
|
||||
}
|
||||
@ -15,7 +15,7 @@ import (
|
||||
// Maps image name to image data
|
||||
type AssetRegistry map[string]*ebiten.Image
|
||||
|
||||
//go:embed sprites/*.png fonts/*.ttf levels/*.ldtk
|
||||
//go:embed sprites/*.png fonts/*.ttf levels/*.ldtk shaders/*.kg
|
||||
var assetfs embed.FS
|
||||
|
||||
var Assets = LoadImages("sprites")
|
||||
|
||||
36
assets/shaders/destruct.kg
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright 2020 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build ignore
|
||||
|
||||
//kage:unit pixels
|
||||
|
||||
package main
|
||||
|
||||
var Damaged int
|
||||
|
||||
const HP float = 0
|
||||
|
||||
func Fragment(_ vec4, texCoord vec2, _ vec4) vec4 {
|
||||
wallpx := imageSrc0At(texCoord) // A pixel from the wall tile
|
||||
mask := imageSrc1At(texCoord) // A pixel from the damage mask image
|
||||
|
||||
if Damaged == 1 && (wallpx.a != 0.0 && mask.a != 0.0) {
|
||||
alpha := clamp(HP+(1.0-mask.a), 0.0, 1.0)
|
||||
// Create a darker pixel if it's inside a damage mask.
|
||||
return vec4(wallpx.r*alpha, wallpx.g*alpha, wallpx.b*alpha, wallpx.a)
|
||||
}
|
||||
|
||||
return wallpx // Otherwise, leave a pixel color as is
|
||||
}
|
||||
BIN
assets/sprites/damage.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
assets/sprites/primarymap.png
Normal file
|
After Width: | Height: | Size: 148 KiB |
@ -7,7 +7,10 @@ import (
|
||||
// virtual location, aka tile address
|
||||
|
||||
type Renderable struct {
|
||||
Image *ebiten.Image
|
||||
Image *ebiten.Image
|
||||
DamageImage *ebiten.Image
|
||||
Damaged int
|
||||
Shader *ebiten.Shader
|
||||
}
|
||||
|
||||
type Particle struct {
|
||||
|
||||
@ -52,7 +52,8 @@ func NewLevel(game *Game, cellsize int, plan *ldtkgo.Level) *Level {
|
||||
|
||||
systemlist = append(systemlist, systems.NewTransientSystem(game.World, gridcontainer))
|
||||
|
||||
systemlist = append(systemlist, systems.NewDestroyableSystem(game.World, gridcontainer))
|
||||
systemlist = append(systemlist, systems.NewDestroyableSystem(game.World, gridcontainer,
|
||||
game.Cellsize))
|
||||
|
||||
systemlist = append(systemlist, systems.NewHudSystem(game.World, plan))
|
||||
|
||||
@ -146,7 +147,7 @@ func LevelToSlice(game *Game, level *ldtkgo.Level, tilesize int) (Map, Map) {
|
||||
tile := assets.Tiles["default"]
|
||||
|
||||
// FIXME: load from LDTK file
|
||||
tile.Sprite = assets.Assets["tilemap"].SubImage(
|
||||
tile.Sprite = assets.Assets["primarymap"].SubImage(
|
||||
image.Rect(tileData.Src[0],
|
||||
tileData.Src[1],
|
||||
tileData.Src[0]+layer.GridSize,
|
||||
@ -163,14 +164,15 @@ func LevelToSlice(game *Game, level *ldtkgo.Level, tilesize int) (Map, Map) {
|
||||
|
||||
case ldtkgo.LayerTypeEntity:
|
||||
// load mobile tiles (they call them entities) using static map map.png.
|
||||
tileset := assets.Assets["map"]
|
||||
tileset := assets.Assets["primarymap"]
|
||||
|
||||
for _, entity := range layer.Entities {
|
||||
if entity.TileRect != nil {
|
||||
tile := assets.Tiles[entity.Identifier]
|
||||
|
||||
slog.Debug("LOAD TILE", "tile", entity.TileRect)
|
||||
|
||||
tileRect := entity.TileRect
|
||||
//slog.Debug("tilerect", "x", tileRect.X, "y", tileRect.Y, "which", entity.Identifier)
|
||||
|
||||
tile.Sprite = tileset.SubImage(
|
||||
image.Rect(tileRect.X, tileRect.Y,
|
||||
|
||||
@ -109,10 +109,17 @@ func NewGrid(world *ecs.World,
|
||||
entity := doormapper.New()
|
||||
pos, render, destroyable = doormapper.Get(entity)
|
||||
destroyable.Sprites = tile.Tiles
|
||||
render.DamageImage = tile.Alpha
|
||||
render.Shader = tile.Shader
|
||||
render.Damaged = 0
|
||||
default:
|
||||
log.Fatalln("unsupported tile type encountered")
|
||||
}
|
||||
|
||||
// FIXME: this image is never being used because it is
|
||||
// being overwritten in game/levels.go:LevelToSlice(). The
|
||||
// image is taken from the LDTK map, not from the Tile{}
|
||||
// definition anymore
|
||||
render.Image = tile.Sprite
|
||||
|
||||
default:
|
||||
|
||||
BIN
src/mixed-walls/church_0.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
src/mixed-walls/church_1.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src/mixed-walls/church_2.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src/mixed-walls/church_3.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src/mixed-walls/church_4.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src/mixed-walls/cobalt_stone_10.png
Normal file
|
After Width: | Height: | Size: 514 B |
BIN
src/mixed-walls/cobalt_stone_11.png
Normal file
|
After Width: | Height: | Size: 516 B |
BIN
src/mixed-walls/cobalt_stone_12.png
Normal file
|
After Width: | Height: | Size: 519 B |
BIN
src/mixed-walls/cobalt_stone_6.png
Normal file
|
After Width: | Height: | Size: 497 B |
BIN
src/mixed-walls/cobalt_stone_7.png
Normal file
|
After Width: | Height: | Size: 498 B |
BIN
src/mixed-walls/cobalt_stone_8.png
Normal file
|
After Width: | Height: | Size: 510 B |
BIN
src/mixed-walls/cobalt_stone_9.png
Normal file
|
After Width: | Height: | Size: 511 B |
BIN
src/mixed-walls/crystal_wall_0.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/mixed-walls/crystal_wall_12.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/mixed-walls/crystal_wall_1_0.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
src/mixed-walls/crystal_wall_4.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/mixed-walls/crystal_wall_6.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
src/mixed-walls/crystal_wall_8.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/mixed-walls/crystal_wall_blue.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/crystal_wall_brown.png
Normal file
|
After Width: | Height: | Size: 917 B |
BIN
src/mixed-walls/crystal_wall_cyan.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/crystal_wall_green.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/crystal_wall_lightblue.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/crystal_wall_lightcyan.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/crystal_wall_lightgray.png
Normal file
|
After Width: | Height: | Size: 910 B |
BIN
src/mixed-walls/crystal_wall_lightgreen.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/crystal_wall_lightmagenta.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/crystal_wall_lightred.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/crystal_wall_magenta.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/crystal_wall_red.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/crystal_wall_white.png
Normal file
|
After Width: | Height: | Size: 975 B |
BIN
src/mixed-walls/crystal_wall_yellow.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/mixed-walls/emerald_1.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/mixed-walls/emerald_2.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src/mixed-walls/emerald_3.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
src/mixed-walls/emerald_4.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
src/mixed-walls/emerald_5.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/mixed-walls/emerald_6.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
src/mixed-walls/emerald_8.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/mixed-walls/lab-metal_0.png
Normal file
|
After Width: | Height: | Size: 290 B |
BIN
src/mixed-walls/lab-metal_1.png
Normal file
|
After Width: | Height: | Size: 354 B |
BIN
src/mixed-walls/lab-metal_2.png
Normal file
|
After Width: | Height: | Size: 385 B |
BIN
src/mixed-walls/lab-metal_3.png
Normal file
|
After Width: | Height: | Size: 383 B |
BIN
src/mixed-walls/lab-metal_4.png
Normal file
|
After Width: | Height: | Size: 395 B |
BIN
src/mixed-walls/lab-stone_0.png
Normal file
|
After Width: | Height: | Size: 360 B |
BIN
src/mixed-walls/lab-stone_1.png
Normal file
|
After Width: | Height: | Size: 375 B |
BIN
src/mixed-walls/lab-stone_2.png
Normal file
|
After Width: | Height: | Size: 384 B |
BIN
src/mixed-walls/marble_wall_1.png
Normal file
|
After Width: | Height: | Size: 813 B |
BIN
src/mixed-walls/marble_wall_10.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/mixed-walls/marble_wall_11.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/mixed-walls/marble_wall_12.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/mixed-walls/marble_wall_2.png
Normal file
|
After Width: | Height: | Size: 931 B |
BIN
src/mixed-walls/marble_wall_3.png
Normal file
|
After Width: | Height: | Size: 843 B |
BIN
src/mixed-walls/marble_wall_4.png
Normal file
|
After Width: | Height: | Size: 874 B |
BIN
src/mixed-walls/marble_wall_5.png
Normal file
|
After Width: | Height: | Size: 882 B |
BIN
src/mixed-walls/marble_wall_6.png
Normal file
|
After Width: | Height: | Size: 956 B |
BIN
src/mixed-walls/marble_wall_7.png
Normal file
|
After Width: | Height: | Size: 934 B |
BIN
src/mixed-walls/marble_wall_8.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
src/mixed-walls/marble_wall_9.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/mixed-walls/permarock_red_0.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/mixed-walls/relief_0.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/mixed-walls/relief_1.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/mixed-walls/relief_2.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/mixed-walls/relief_3.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/mixed-walls/relief_brown_0.png
Normal file
|
After Width: | Height: | Size: 561 B |
BIN
src/mixed-walls/relief_brown_1.png
Normal file
|
After Width: | Height: | Size: 571 B |
BIN
src/mixed-walls/relief_brown_2.png
Normal file
|
After Width: | Height: | Size: 565 B |
BIN
src/mixed-walls/relief_brown_3.png
Normal file
|
After Width: | Height: | Size: 566 B |
BIN
src/mixed-walls/slime_stone_0.png
Normal file
|
After Width: | Height: | Size: 453 B |
BIN
src/mixed-walls/slime_stone_1.png
Normal file
|
After Width: | Height: | Size: 454 B |
BIN
src/mixed-walls/slime_stone_2.png
Normal file
|
After Width: | Height: | Size: 362 B |
BIN
src/mixed-walls/stone2_brown_2_new.png
Normal file
|
After Width: | Height: | Size: 581 B |
BIN
src/mixed-walls/stone2_brown_2_old.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/mixed-walls/stone2_brown_3_new.png
Normal file
|
After Width: | Height: | Size: 573 B |
BIN
src/mixed-walls/stone2_brown_3_old.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/mixed-walls/stone2_dark_2_new.png
Normal file
|
After Width: | Height: | Size: 847 B |
BIN
src/mixed-walls/stone2_dark_2_old.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/mixed-walls/stone2_dark_3_new.png
Normal file
|
After Width: | Height: | Size: 887 B |
BIN
src/mixed-walls/stone2_dark_3_old.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/mixed-walls/stone2_gray_2_new.png
Normal file
|
After Width: | Height: | Size: 954 B |
BIN
src/mixed-walls/stone2_gray_2_old.png
Normal file
|
After Width: | Height: | Size: 797 B |
BIN
src/mixed-walls/stone2_gray_3_new.png
Normal file
|
After Width: | Height: | Size: 977 B |
BIN
src/mixed-walls/stone2_gray_3_old.png
Normal file
|
After Width: | Height: | Size: 771 B |
BIN
src/mixed-walls/stone_2_brown0.png
Normal file
|
After Width: | Height: | Size: 555 B |
BIN
src/mixed-walls/stone_2_brown1.png
Normal file
|
After Width: | Height: | Size: 590 B |
BIN
src/mixed-walls/stone_2_brown_0.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/mixed-walls/stone_2_brown_1.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
src/mixed-walls/stone_2_dark0.png
Normal file
|
After Width: | Height: | Size: 847 B |
BIN
src/mixed-walls/stone_2_dark1.png
Normal file
|
After Width: | Height: | Size: 835 B |