Last active
May 28, 2019 17:53
-
-
Save cep21/03b118d1e0a4662d1a00b33c6ac6890c to your computer and use it in GitHub Desktop.
Original spaceship
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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