-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graeme/playerbumpin #249
Graeme/playerbumpin #249
Conversation
@@ -168,12 +168,12 @@ func (a *Arena) playerCollisions() { | |||
memo := make(map[*models.Player]*models.Player) | |||
for _, player := range a.Players { | |||
for _, playerHit := range a.Players { | |||
if player == playerHit || memo[playerHit] == player { | |||
if player == playerHit || memo[player] == playerHit { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
continue | ||
} | ||
if areCirclesColliding(player.Position, models.PlayerRadius, playerHit.Position, models.PlayerRadius) { | ||
memo[playerHit] = player | ||
player.HitPlayer(playerHit, a.Height, a.Width) | ||
player.HitPlayer(playerHit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
server/models/player.go
Outdated
Angle float64 `json:"angle"` | ||
Controls KeysPressed `json:"-"` | ||
Points int `json:"points"` | ||
PlayerHitMe *Player `json:"-"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename this to LastPlayerHit? It'll keep the naming of this property consistent with our Junk type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That variable, like the junk one, keeps track of the player that hit that player. Not the last player that that player hit. How confusing is that ;).
I renamed the junk one to match this one, is that okay? I want it to be clear to everyone lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow 😖Can you elaborate?
From my understanding right now, if two players collide, their LastPlayerHit is always each other. There isn't a concept of who hit who right? So there probably isn't a need to differentiate between "Player B that hit Player A and the last player that Player A hit" <- am I understanding your comment correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good point. Yeah I just had it in my head that it mattered from when I started but switched at some point to it not mattering. Okay, LastPlayerHit is best then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I see. Yeah LastPlayerHit is good enough :)
server/models/player.go
Outdated
initalVelocity := p.Velocity | ||
// HitPlayer calculates collision, update Player's velocity based on calculation of hitting another player | ||
func (p *Player) HitPlayer(ph *Player) { | ||
if p.pDebounce == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid the extra nest, let's just return early here 🤓🐦
@@ -205,3 +205,83 @@ func TestKeyHandler(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func TestPlayerBumpPlayer(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 🔥 🔥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job. Thanks the adding the tests for this new functionality.
Just a few comments about naming and returning early.
Great! If you're up for it, you can try squashing those last 4 or 5 commits, otherwise feel free to merge whenever you are ready. |
6dfa527
to
6cf6b86
Compare
Squashed those commits, much cleaner I agree. Needs your review again though now Brian. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
🎟️ Ticket(s): Closes #210
👷 Changes
Changes player to player collision to not directly modify either players position. Also adds a period to award points to a player if another player is killed within a number of ticks after a collision with the still alive player.
🔦 Testing Instructions
Play a bit and see if you bump a player into a hole you are given points. And if you bump a player and then much later they drive themselves into a hole you are not awarded points.