|
@@ -1,5 +1,6 @@
|
|
package tile
|
|
package tile
|
|
|
|
|
|
|
|
+import "fmt"
|
|
import "gitlab.com/beoran/ebsgo/monolog"
|
|
import "gitlab.com/beoran/ebsgo/monolog"
|
|
// import "os"
|
|
// import "os"
|
|
// import "math"
|
|
// import "math"
|
|
@@ -72,7 +73,7 @@ type Tile struct {
|
|
/* Automatic shadow mask number. */
|
|
/* Automatic shadow mask number. */
|
|
ShadowMask int
|
|
ShadowMask int
|
|
/* Tiled-style animation frames. */
|
|
/* Tiled-style animation frames. */
|
|
- Frames []Frame
|
|
|
|
|
|
+ Frames []*Frame
|
|
/* Active frame for TMX-style animations. */
|
|
/* Active frame for TMX-style animations. */
|
|
ActiveFrame int
|
|
ActiveFrame int
|
|
};
|
|
};
|
|
@@ -103,6 +104,13 @@ func NewSet(sheet * al.Bitmap, tile_w, tile_h, firstgid int) * Set {
|
|
return set
|
|
return set
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (set * Set) Close() {
|
|
|
|
+ if set.Sheet != nil {
|
|
|
|
+ set.Sheet.Destroy()
|
|
|
|
+ set.Sheet = nil
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
func (tile * Tile) Init(set * Set, index int) {
|
|
func (tile * Tile) Init(set * Set, index int) {
|
|
tile.Tileset = set
|
|
tile.Tileset = set
|
|
tile.Index = index
|
|
tile.Index = index
|
|
@@ -202,6 +210,9 @@ func (frame * Frame) Init(index int, duration float64) {
|
|
frame.Duration = duration
|
|
frame.Duration = duration
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (frame Frame) String() string {
|
|
|
|
+ return fmt.Sprintf("frame: %d", frame.Index)
|
|
|
|
+}
|
|
|
|
|
|
/** Gets the nth frame of Tiled style animations for this tile
|
|
/** Gets the nth frame of Tiled style animations for this tile
|
|
* or NULL if no such animation frame. */
|
|
* or NULL if no such animation frame. */
|
|
@@ -209,13 +220,13 @@ func (tile Tile) Frame(index int) * Frame {
|
|
if nil == tile.Frames{
|
|
if nil == tile.Frames{
|
|
return nil
|
|
return nil
|
|
} else {
|
|
} else {
|
|
- return &tile.Frames[index]
|
|
|
|
|
|
+ return tile.Frames[index]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/** Gets the amount of Tiled style animations for this tile, or 0 if none. */
|
|
/** Gets the amount of Tiled style animations for this tile, or 0 if none. */
|
|
func (tile Tile) FrameCount() int {
|
|
func (tile Tile) FrameCount() int {
|
|
- if nil == tile.Frames {
|
|
|
|
|
|
+ if nil == tile.Frames {
|
|
return 0
|
|
return 0
|
|
} else {
|
|
} else {
|
|
return len(tile.Frames)
|
|
return len(tile.Frames)
|
|
@@ -224,14 +235,8 @@ func (tile Tile) FrameCount() int {
|
|
|
|
|
|
/** Adds a Tiled-style animation frame to the tile. */
|
|
/** Adds a Tiled-style animation frame to the tile. */
|
|
func (tile * Tile) AddAnimationFrame(index int, duration float64) (frame * Frame) {
|
|
func (tile * Tile) AddAnimationFrame(index int, duration float64) (frame * Frame) {
|
|
- if (nil == tile.Frames) {
|
|
|
|
- tile.Frames = make([]Frame, 1)
|
|
|
|
- frame = &tile.Frames[0]
|
|
|
|
- } else {
|
|
|
|
- frame = &Frame{}
|
|
|
|
- tile.Frames = append(tile.Frames, *frame)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ frame = &Frame{}
|
|
|
|
+ tile.Frames = append(tile.Frames, frame)
|
|
frame.Init(index, duration)
|
|
frame.Init(index, duration)
|
|
return frame
|
|
return frame
|
|
}
|
|
}
|
|
@@ -254,18 +259,18 @@ func (tile * Tile) UpdateAnimation(dt float64) {
|
|
if nil == frame { /* Animation overshot itself */
|
|
if nil == frame { /* Animation overshot itself */
|
|
tile.ActiveFrame = 0
|
|
tile.ActiveFrame = 0
|
|
frame = tile.Frame(tile.ActiveFrame)
|
|
frame = tile.Frame(tile.ActiveFrame)
|
|
- if nil == frame {
|
|
|
|
|
|
+ if nil == frame { /* Tile has no frames at all. */
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- monolog.Log("TILE", "Animation for tile: %d %d %f %f\n",
|
|
|
|
- tile.ActiveFrame, frame.Index, frame.Duration, tile.Time)
|
|
|
|
|
|
+ /* monolog.Log("TILE", "Animation for tile: %d %d %f %f\n",
|
|
|
|
+ tile.ActiveFrame, frame.Index, frame.Duration, tile.Time) */
|
|
|
|
|
|
|
|
|
|
tile.Time += dt // advance animation time of tile.
|
|
tile.Time += dt // advance animation time of tile.
|
|
// Don't animate if not enough time has passed
|
|
// Don't animate if not enough time has passed
|
|
- if tile.Time < frame.Duration {
|
|
|
|
|
|
+ if tile.Time < (frame.Duration * 10.0) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
// advance the animation frame, loop it around if needed.
|
|
// advance the animation frame, loop it around if needed.
|
|
@@ -282,8 +287,8 @@ func (tile * Tile) UpdateAnimation(dt float64) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- monolog.Log("TILE", "Animation for tile: %d %d %f %f %b\n",
|
|
|
|
- tile.ActiveFrame, frame.Index, frame.Duration, tile.Time)
|
|
|
|
|
|
+ monolog.Log("TILE", "Animation for tile: %d %d %d %d %v\n",
|
|
|
|
+ tile.ActiveFrame, frame.Index, frame.Duration, tile.Time, tile.Frames)
|
|
|
|
|
|
// Get the active tile to use from the animation frame
|
|
// Get the active tile to use from the animation frame
|
|
active = frame.Index
|
|
active = frame.Index
|
|
@@ -296,7 +301,7 @@ func (tile * Tile) UpdateAnimation(dt float64) {
|
|
tile.Active = active
|
|
tile.Active = active
|
|
// Finally recalculate tile position.
|
|
// Finally recalculate tile position.
|
|
tile.Recalculate()
|
|
tile.Recalculate()
|
|
- monolog.Log("TILE", "Updated animation for tile: %d\n", tile.Active)
|
|
|
|
|
|
+ monolog.Log("TILE", "Updated animation for tile: %d %d\n", tile.Active, frame.Index)
|
|
}
|
|
}
|
|
|
|
|
|
/* Animates the tile. Animates the tile if it has animation frames. */
|
|
/* Animates the tile. Animates the tile if it has animation frames. */
|