Last active
May 28, 2019 17:53
-
-
Save cep21/db5a89e3ffa8fc7b5dc74eee4c07363f to your computer and use it in GitHub Desktop.
Abstracted space ship
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 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