...

Source file src/gitlab.com/tslocum/venture/pkg/world/logic.go

Documentation: gitlab.com/tslocum/venture/pkg/world

     1  package world
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/hajimehoshi/ebiten"
     7  )
     8  
     9  // Logic is an invisible node.
    10  type Logic struct {
    11  	UpdateFunc func(screen *ebiten.Image) error
    12  
    13  	nodes []Node
    14  	sync.Mutex
    15  }
    16  
    17  // NewLogic returns a new Logic node.
    18  func NewLogic(updateFunc func(screen *ebiten.Image) error) *Logic {
    19  	if updateFunc == nil {
    20  		updateFunc = func(screen *ebiten.Image) error {
    21  			return nil
    22  		}
    23  	}
    24  	return &Logic{UpdateFunc: updateFunc}
    25  }
    26  
    27  // AddNode adds a node.
    28  func (l *Logic) AddNode(node Node) {
    29  	l.Lock()
    30  	defer l.Unlock()
    31  
    32  	l.nodes = append(l.nodes, node)
    33  }
    34  
    35  func (l *Logic) Hit(x float64, y float64) bool {
    36  	return true
    37  }
    38  
    39  func (l *Logic) HitTest(x float64, y float64) bool {
    40  	return false
    41  }
    42  
    43  // Nodes returns any contained nodes.
    44  func (l *Logic) Nodes() []Node {
    45  	l.Lock()
    46  	defer l.Unlock()
    47  
    48  	return l.nodes
    49  }
    50  
    51  // Update calls UpdateFunc.
    52  func (l *Logic) Update(screen *ebiten.Image) error {
    53  	return l.UpdateFunc(screen)
    54  }
    55  
    56  // Draw does nothing.
    57  func (l *Logic) Draw(screen *ebiten.Image) {
    58  	// Do nothing
    59  }
    60  

View as plain text