added hidden doors/destroyable walls, fixed game reloading (tile clone)

This commit is contained in:
2024-02-25 14:05:44 +01:00
parent ab07bc23e3
commit b0a8060d5b
15 changed files with 271 additions and 39 deletions

View File

@@ -4,7 +4,7 @@ Background: background-lila
#######
# #
#o #
# t #
#> S <#
# #

View File

@@ -4,13 +4,13 @@ Background: background-lila
##########
# v#
########W#
# v #
# #
#S s#
# #
#^ #
##########
############
# o #
######## #

View File

@@ -25,18 +25,42 @@ type Tile struct {
Id byte
Sprite *ebiten.Image
Class string
Solid bool
Player bool
IsPrimary bool
Renderable bool
Velocity bool
Collectible bool
Transient bool
Particle int // -1=unused, 0-3 = show image of slice
Tiles []*ebiten.Image
TileNames []string // same thing, only the names
Obstacle bool
Direction int // obstacles
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
Particle 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
}
func (tile *Tile) Clone() *Tile {
newtile := &Tile{
Id: tile.Id,
Sprite: tile.Sprite,
Class: tile.Class,
Solid: tile.Solid,
Player: tile.Player,
IsPrimary: tile.IsPrimary,
Renderable: tile.Renderable,
Velocity: tile.Velocity,
Collectible: tile.Collectible,
Transient: tile.Transient,
Destroyable: tile.Destroyable,
Particle: tile.Particle,
Tiles: tile.Tiles,
TileNames: tile.TileNames,
Obstacle: tile.Obstacle,
Direction: tile.Direction,
}
return newtile
}
const (
@@ -128,7 +152,7 @@ func NewTileTranswall(class []string) *Tile {
}
return &Tile{
Id: '*',
Id: 't',
Class: "transwall",
Solid: false,
Renderable: true,
@@ -139,6 +163,27 @@ 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)
}
return &Tile{
Id: 'W',
Class: "hiddendoor",
Solid: false,
Renderable: true,
Destroyable: true,
Tiles: sprites,
Sprite: sprites[0], // initially use the first
TileNames: names,
}
}
// used to map level data bytes to actual tiles
type TileRegistry map[byte]*Tile
@@ -164,7 +209,8 @@ type RawLevel struct {
func InitTiles() TileRegistry {
return TileRegistry{
' ': {Id: ' ', Class: "floor", Renderable: false},
'#': NewTileBlock("block-grey32"),
//'#': NewTileBlock("block-grey32"),
'#': NewTileBlock("block-greycolored"),
'B': NewTileBlock("block-orange-32"),
'S': NewTilePlayer(Primary),
's': NewTilePlayer(Secondary),
@@ -183,6 +229,7 @@ func InitTiles() TileRegistry {
"particle-ring-6",
}),
't': NewTileTranswall([]string{"transwall", "block-orange-32"}),
'W': NewTileHiddenDoor([]string{"block-greycolored", "block-greycolored-damaged"}),
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB