Skip to content

Instantly share code, notes, and snippets.

@cep21
Last active May 28, 2019 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cep21/db5a89e3ffa8fc7b5dc74eee4c07363f to your computer and use it in GitHub Desktop.
Save cep21/db5a89e3ffa8fc7b5dc74eee4c07363f to your computer and use it in GitHub Desktop.
Abstracted space ship
type Ship2 struct {
GameKillable
PhysicalObject
}
type PhysicalObject struct {
LocX float64
LocY float64
Size float64
}
func (s *PhysicalObject) Intersects(other PhysicalObject) bool {
dist := math.Sqrt(math.Pow(s.LocX-other.LocX, 2) + math.Pow(s.LocY-other.LocY, 2))
return dist < s.Size+other.Size
}
type GameKillable struct {
Health int
}
func (s *GameKillable) Heal(amnt int) {
if s.Health >= 0 {
s.Health += amnt
}
}
func (s *GameKillable) Harm(amnt int) {
if s.Health >= 0 {
s.Health -= amnt
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment