123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- package tile
- import "gitlab.com/beoran/al5go/al"
- import "gitlab.com/beoran/ebsgo/engine/physics"
- type Map struct {
- Background *al.Bitmap
- Panes []*Pane
- Sets []*Set
- GridW int
- GridH int
- }
- const (
- TEXTURE_TILE = "tile"
- TEXTURE_PLAYER = "play"
- TEXTURE_GEAR = "gear"
- TEXTURE_WEAPON = "arms"
- TEXTURE_FOE = "foes"
- TEXTURE_ITEM = "item"
- )
- func (tm * Map) Init(tw, th int) {
- tm.GridW = tw
- tm.GridH = th
- tm.Panes = nil
- }
- func NewMap(tw, th int) * Map{
- tm := &Map{}
- tm.Init(tw, th)
- return tm
- }
- func (tm * Map) Pane(index int) * Pane {
- if index < 0 { return nil; }
- if index >= len(tm.Panes) { return nil; }
- return tm.Panes[index]
- }
- func (tm * Map) AddPane(pane * Pane) * Pane {
- tm.Panes = append(tm.Panes, pane)
- return pane
- }
- func (tm * Map) NewPane(set * Set, tw, th int, name string) * Pane {
- pane := NewPane(set, tw, th, name)
- return tm.AddPane(pane)
- }
- func (tm * Map) Set(index int) * Set {
- if index < 0 { return nil; }
- if index >= len(tm.Sets) { return nil; }
- return tm.Sets[index]
- }
- func (tm * Map) AddSet(set * Set) * Set {
- tm.Sets = append(tm.Sets, set)
- return set
- }
- func (tm * Map) NewSet(sheet * al.Bitmap, tile_w, tile_h, firstgid int) * Set {
- set := NewSet(sheet, tile_w, tile_h, firstgid)
- return tm.AddSet(set)
- }
- func (tm * Map) LookupTmxTileset(tmx_index int) * Set{
- for _, set := range tm.Sets {
- if tmx_index >= set.FirstGID {
- return set
- }
- }
- return nil
- }
- func (tm * Map) Tile(l, x, y int) * Tile {
- pane := tm.Pane(l)
- if pane == nil { return nil; }
- return pane.Tile(x, y)
- }
- func (tm * Map) SetTile(l, x, y int, tile * Tile) * Tile {
- pane := tm.Pane(l)
- if pane == nil { return nil }
- return pane.SetTile(x, y, tile)
- }
- func (tm * Map) SetTileIndex(l, x, y, index int) * Tile {
- pane := tm.Pane(l)
- if pane == nil { return nil }
- return pane.SetTileIndex(x, y, index)
- }
- func (tm * Map) Draw(camera * physics.Camera) {
-
- for i := 0 ; i < len(tm.Panes) ; i ++ {
- pane := tm.Panes[i]
- if pane != nil {
- pane.DrawTiles(camera)
- if ( i % 2 ) == 0 {
- pane.DrawBlends(camera)
-
- } else if (i % 2) == 1 {
-
- }
- }
- }
- }
- func (tm * Map) Update(dt float64) {
- for i := 0 ; i < len(tm.Panes) ; i ++ {
- pane := tm.Panes[i]
- if pane != nil {
- pane.Update(dt)
- }
- }
- }
- func (tm * Map) Close() {
- for i := 0 ; i < len(tm.Panes) ; i ++ {
- pane := tm.Panes[i]
- if pane != nil {
- pane.Close()
- }
- tm.Panes[i] = nil
- }
- for i := 0 ; i < len(tm.Sets) ; i ++ {
- pane := tm.Sets[i]
- if pane != nil {
- pane.Close()
- }
- tm.Sets[i] = nil
- }
- }
- func (tm * Map) SetupAfterLoad() {
- for i := 0 ; i < len(tm.Panes) ; i ++ {
- pane := tm.Panes[i]
- if pane != nil {
- pane.InitBlend(i)
- }
- }
- }
|