switched to go coded animation system, LDTK is not used for this anymore

This commit is contained in:
2024-04-08 18:51:25 +02:00
parent 2793710819
commit f23bdaf121
15 changed files with 233 additions and 240 deletions

View File

@@ -14,62 +14,66 @@ import (
var Project = LoadLDTK("levels")
var Tiles = InitTiles()
type TileAnimation struct {
OnCollision bool // wether to animate a collision
OnDestruction bool // wether to animate destruction
OnIdle bool // wether to animate during idling
CollisionSheet AnimationSet // an entry in assets.Animations[name]
DestructionSheet AnimationSet
IdleSheet AnimationSet
}
// Tile: contains image, identifier (as used in level data) and
// additional properties
type Tile struct {
Id, Ref string
Sprite *ebiten.Image
ToggleSprite *ebiten.Image
Solid bool // wall brick
Player bool // player sphere
IsPrimary bool // primary player sphere
Renderable bool // visible, has sprite
Velocity bool // movable
Collectible bool // collectible, vanishes once collected
Transient bool // turns into brick wall when traversed
Destroyable bool // turns into empty floor when bumped into twice
Animation int // -1=unused, 0-3 = show image of slice
Tiles []*ebiten.Image // has N sprites
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
Bond bool // denotes an entity which can have a relation to another
Door bool // a door, can be manipulated by a switch
Switch bool // opens|closes a door
AnimateOnDestruct bool // wether to animate destruction
AnimationTrigger string // dynamically configured via LDTP
AnimationSpriteSheet AnimationSet // which sprites to use (refers to an entry in assets.Animations[name])
Id, Ref string
Sprite *ebiten.Image
ToggleSprite *ebiten.Image
Solid bool // wall brick
Player bool // player sphere
IsPrimary bool // primary player sphere
Renderable bool // visible, has sprite
Velocity bool // movable
Collectible bool // collectible, vanishes once collected
Transient bool // turns into brick wall when traversed
Destroyable bool // turns into empty floor when bumped into twice
Tiles []*ebiten.Image // has N sprites
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
Bond bool // denotes an entity which can have a relation to another
Door bool // a door, can be manipulated by a switch
Switch bool // opens|closes a door
Animation TileAnimation
}
func (tile *Tile) Clone() *Tile {
newtile := &Tile{
Id: tile.Id,
Ref: tile.Ref,
Sprite: tile.Sprite,
ToggleSprite: tile.ToggleSprite,
Solid: tile.Solid,
Player: tile.Player,
IsPrimary: tile.IsPrimary,
Renderable: tile.Renderable,
Velocity: tile.Velocity,
Collectible: tile.Collectible,
Transient: tile.Transient,
Destroyable: tile.Destroyable,
Animation: tile.Animation,
Tiles: tile.Tiles,
TileNames: tile.TileNames,
Obstacle: tile.Obstacle,
Direction: tile.Direction,
Alpha: tile.Alpha,
Shader: tile.Shader,
Bond: tile.Bond,
Door: tile.Door,
Switch: tile.Switch,
AnimateOnDestruct: tile.AnimateOnDestruct,
AnimationSpriteSheet: tile.AnimationSpriteSheet,
AnimationTrigger: tile.AnimationTrigger,
Id: tile.Id,
Ref: tile.Ref,
Sprite: tile.Sprite,
ToggleSprite: tile.ToggleSprite,
Solid: tile.Solid,
Player: tile.Player,
IsPrimary: tile.IsPrimary,
Renderable: tile.Renderable,
Velocity: tile.Velocity,
Collectible: tile.Collectible,
Transient: tile.Transient,
Destroyable: tile.Destroyable,
Tiles: tile.Tiles,
TileNames: tile.TileNames,
Obstacle: tile.Obstacle,
Direction: tile.Direction,
Alpha: tile.Alpha,
Shader: tile.Shader,
Bond: tile.Bond,
Door: tile.Door,
Switch: tile.Switch,
Animation: tile.Animation,
}
return newtile
@@ -115,6 +119,12 @@ func NewTileCollectible() *Tile {
Solid: false,
Renderable: true,
Collectible: true,
Animation: TileAnimation{
OnDestruction: true,
DestructionSheet: Animations["collectible-detonating"],
OnIdle: true,
IdleSheet: Animations["collectible-idle"],
},
}
}
@@ -128,17 +138,6 @@ func NewTileObstacle(direction int) *Tile {
}
}
func NewTileAnimation(class []string) *Tile {
sprites := GetSprites(class)
return &Tile{
Solid: false,
Renderable: false,
Animation: 0,
Tiles: sprites,
}
}
func NewTileTranswall() *Tile {
return &Tile{
Solid: false,
@@ -191,39 +190,22 @@ func InitTiles() TileRegistry {
"ObstacleSouth": NewTileObstacle(config.South),
"ObstacleWest": NewTileObstacle(config.West),
"ObstacleEast": NewTileObstacle(config.East),
"Animation": NewTileAnimation([]string{
"collectible-detonating1",
"collectible-detonating2",
"collectible-detonating3",
"collectible-detonating4",
"collectible-detonating5",
"collectible-detonating6",
"collectible-detonating7",
"collectible-detonating8",
"collectible-detonating9",
"collectible-detonating10",
"collectible-detonating11",
"collectible-detonating12",
"collectible-detonating13",
"collectible-detonating14",
"collectible-detonating15",
}),
"Transient": NewTileTranswall(),
"HiddenDoor": NewTileHiddenDoor("damage"),
"HiddenDoor2": NewTileHiddenDoor("damage"),
"HiddenDoor3": NewTileHiddenDoor("damage"),
"HiddenDoor4": NewTileHiddenDoor("damage"),
"HiddenDoor5": NewTileHiddenDoor("damage"),
"HiddenDoor6": NewTileHiddenDoor("damage"),
"HiddenDoor7": NewTileHiddenDoor("damage"),
"HiddenDoor8": NewTileHiddenDoor("damage"),
"HiddenDoor9": NewTileHiddenDoor("damage"),
"HiddenDoor10": NewTileHiddenDoor("damage"),
"HiddenDoor11": NewTileHiddenDoor("damage"),
"HiddenDoor12": NewTileHiddenDoor("damage"),
"HiddenDoor13": NewTileHiddenDoor("damage"),
"Switch": NewTileSwitch(),
"Door": NewTileDoor(),
"Transient": NewTileTranswall(),
"HiddenDoor": NewTileHiddenDoor("damage"),
"HiddenDoor2": NewTileHiddenDoor("damage"),
"HiddenDoor3": NewTileHiddenDoor("damage"),
"HiddenDoor4": NewTileHiddenDoor("damage"),
"HiddenDoor5": NewTileHiddenDoor("damage"),
"HiddenDoor6": NewTileHiddenDoor("damage"),
"HiddenDoor7": NewTileHiddenDoor("damage"),
"HiddenDoor8": NewTileHiddenDoor("damage"),
"HiddenDoor9": NewTileHiddenDoor("damage"),
"HiddenDoor10": NewTileHiddenDoor("damage"),
"HiddenDoor11": NewTileHiddenDoor("damage"),
"HiddenDoor12": NewTileHiddenDoor("damage"),
"HiddenDoor13": NewTileHiddenDoor("damage"),
"Switch": NewTileSwitch(),
"Door": NewTileDoor(),
}
}

View File

@@ -60,6 +60,9 @@ type AnimationSet struct {
File string
}
// names in the registry match the sprite set png file name, the JSON
// file names are irrelevant as they point to the matching file using
// the "image" field.
type AnimationRegistry map[string]AnimationSet
//go:embed sprites/*.png fonts/*.ttf levels/*.ldtk shaders/*.kg sprites/*.json

View File

@@ -1,42 +1,42 @@
{ "frames": [
{
"filename": "collectible 0.ase",
"filename": "collectible #Detonation 0.ase",
"frame": { "x": 0, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
"sourceSize": { "w": 64, "h": 64 },
"duration": 100
"duration": 20
},
{
"filename": "collectible 1.ase",
"filename": "collectible #Detonation 1.ase",
"frame": { "x": 64, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
"sourceSize": { "w": 64, "h": 64 },
"duration": 100
"duration": 20
},
{
"filename": "collectible 2.ase",
"filename": "collectible #Detonation 2.ase",
"frame": { "x": 128, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
"sourceSize": { "w": 64, "h": 64 },
"duration": 100
"duration": 20
},
{
"filename": "collectible 3.ase",
"filename": "collectible #Detonation 3.ase",
"frame": { "x": 192, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
"sourceSize": { "w": 64, "h": 64 },
"duration": 100
"duration": 20
},
{
"filename": "collectible 4.ase",
"filename": "collectible #Detonation 4.ase",
"frame": { "x": 256, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ -45,7 +45,7 @@
"duration": 100
},
{
"filename": "collectible 5.ase",
"filename": "collectible #Detonation 5.ase",
"frame": { "x": 320, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ -54,7 +54,7 @@
"duration": 100
},
{
"filename": "collectible 6.ase",
"filename": "collectible #Detonation 6.ase",
"frame": { "x": 384, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ -63,7 +63,7 @@
"duration": 100
},
{
"filename": "collectible 7.ase",
"filename": "collectible #Detonation 7.ase",
"frame": { "x": 448, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ -72,7 +72,7 @@
"duration": 100
},
{
"filename": "collectible 8.ase",
"filename": "collectible #Detonation 8.ase",
"frame": { "x": 512, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ -81,7 +81,7 @@
"duration": 100
},
{
"filename": "collectible 9.ase",
"filename": "collectible #Detonation 9.ase",
"frame": { "x": 576, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ -90,7 +90,7 @@
"duration": 100
},
{
"filename": "collectible 10.ase",
"filename": "collectible #Detonation 10.ase",
"frame": { "x": 640, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ -99,7 +99,7 @@
"duration": 100
},
{
"filename": "collectible 11.ase",
"filename": "collectible #Detonation 11.ase",
"frame": { "x": 704, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ -108,7 +108,7 @@
"duration": 100
},
{
"filename": "collectible 12.ase",
"filename": "collectible #Detonation 12.ase",
"frame": { "x": 768, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ -117,22 +117,13 @@
"duration": 100
},
{
"filename": "collectible 13.ase",
"filename": "collectible #Detonation 13.ase",
"frame": { "x": 832, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
"sourceSize": { "w": 64, "h": 64 },
"duration": 100
},
{
"filename": "collectible 14.ase",
"frame": { "x": 896, "y": 0, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
"sourceSize": { "w": 64, "h": 64 },
"duration": 100
}
],
"meta": {
@@ -140,9 +131,10 @@
"version": "1.x-dev",
"image": "collectible-detonating.png",
"format": "I8",
"size": { "w": 960, "h": 64 },
"size": { "w": 896, "h": 64 },
"scale": "1",
"frameTags": [
{ "name": "Detonation", "from": 1, "to": 14, "direction": "forward" }
],
"layers": [
{ "name": "Yellow Sphere", "opacity": 255, "blendMode": "normal" },

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

View File

@@ -1,38 +1,38 @@
{ "frames": [
{
"filename": "collectible #Idle 0.ase",
"frame": { "x": 0, "y": 0, "w": 64, "h": 64 },
"filename": "collectible-idle 0.ase",
"frame": { "x": 0, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
"sourceSize": { "w": 64, "h": 64 },
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
},
{
"filename": "collectible #Idle 1.ase",
"frame": { "x": 64, "y": 0, "w": 64, "h": 64 },
"filename": "collectible-idle 1.ase",
"frame": { "x": 32, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
"sourceSize": { "w": 64, "h": 64 },
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
},
{
"filename": "collectible #Idle 2.ase",
"frame": { "x": 128, "y": 0, "w": 64, "h": 64 },
"filename": "collectible-idle 2.ase",
"frame": { "x": 64, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
"sourceSize": { "w": 64, "h": 64 },
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
},
{
"filename": "collectible #Idle 3.ase",
"frame": { "x": 192, "y": 0, "w": 64, "h": 64 },
"filename": "collectible-idle 3.ase",
"frame": { "x": 96, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
"sourceSize": { "w": 64, "h": 64 },
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 200
}
],
@@ -40,26 +40,13 @@
"app": "http://www.aseprite.org/",
"version": "1.x-dev",
"image": "collectible-idle.png",
"format": "I8",
"size": { "w": 256, "h": 64 },
"format": "RGBA8888",
"size": { "w": 128, "h": 32 },
"scale": "1",
"frameTags": [
{ "name": "Detonation", "from": 1, "to": 14, "direction": "forward" },
{ "name": "Idle", "from": 15, "to": 18, "direction": "forward" }
],
"layers": [
{ "name": "Yellow Sphere", "opacity": 255, "blendMode": "normal" },
{ "name": "Layer 8", "opacity": 255, "blendMode": "normal" },
{ "name": "Layer 7", "opacity": 255, "blendMode": "normal" },
{ "name": "Layer 6", "opacity": 255, "blendMode": "normal" },
{ "name": "Layer 5", "opacity": 255, "blendMode": "normal" },
{ "name": "Layer 4", "opacity": 255, "blendMode": "normal" },
{ "name": "Layer 3", "opacity": 255, "blendMode": "normal" },
{ "name": "Layer 2", "opacity": 255, "blendMode": "normal" },
{ "name": "Layer 1", "opacity": 255, "blendMode": "normal" },
{ "name": "Blitz Outer", "opacity": 70, "blendMode": "normal" },
{ "name": "Blitz Middle", "opacity": 84, "blendMode": "normal" },
{ "name": "Blitz Inner", "opacity": 97, "blendMode": "normal" }
{ "name": "Layer 1", "opacity": 255, "blendMode": "normal" }
],
"slices": [
]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 685 B

After

Width:  |  Height:  |  Size: 931 B

Binary file not shown.