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/03b118d1e0a4662d1a00b33c6ac6890c to your computer and use it in GitHub Desktop.
Save cep21/03b118d1e0a4662d1a00b33c6ac6890c to your computer and use it in GitHub Desktop.
Original spaceship
type Ship struct {
Health int
LocX float64
LocY float64
Size float64
}
func (s *Ship) Heal(amnt int) {
if s.Health >= 0 {
s.Health += amnt
}
}
func (s *Ship) Harm(amnt int) {
if s.Health >= 0 {
s.Health -= amnt
}
}
func (s *Ship) Intersects(other Ship) bool {
dist := math.Sqrt(math.Pow(s.LocX-other.LocX, 2) + math.Pow(s.LocY-other.LocY, 2))
return dist < s.Size+other.Size
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment