accmltr / scala-games

A game engine for writing games in Scala.
MIT License
4 stars 0 forks source link

Anchors #41

Closed accmltr closed 8 months ago

accmltr commented 9 months ago

Add conceptual anchor points to all classes which exist in the 2D space, and have them be extendable in subclasses.

You should be able to set and get anchor points, such that the following is possible:

val rect = RectSdf(
  width = 100
  height = 30
)
val text = Text()

// The MyCustomPlayer class is an imaginary user defined class which sets its 
// gun position based on player aim and player character behavior. This is added
// as an anchor point to the class.
val player = MyCustomPlayer(
  health = 10
  radius = 22.3
)

def loop(): Unit = 
  // player has already been updated at this point...

  // Have the rect's bottom left corner be moved onto the gun position with an offset added to it
  rect.anchor.bottomLeft = player.anchor.gunPos + Vector2(10,10)

  // Display the ammo count and move the text
  text.content = s"${player.ammo}/${player.maxAmmo}"
  text.anchor.center = rect.anchor.center

Some global anchors to consider: