Skip to content

Commit

Permalink
changes player hit name again
Browse files Browse the repository at this point in the history
  • Loading branch information
Grafne23 committed Jul 27, 2018
1 parent 44f86de commit 354045d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions server/arena/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (a *Arena) holeCollisions() {

for name, player := range a.Players {
if areCirclesColliding(player.Position, models.PlayerRadius, hole.Position, hole.Radius) {
playerScored := player.PlayerHitMe
playerScored := player.LastPlayerHit
if playerScored != nil {
playerScored.AddPoints(models.PointsPerPlayer)
go database.UpdatePlayerScore(playerScored)
Expand All @@ -210,7 +210,7 @@ func (a *Arena) holeCollisions() {

for i, junk := range a.Junk {
if areCirclesColliding(junk.Position, models.JunkRadius, hole.Position, hole.Radius) {
playerScored := junk.PlayerHitMe
playerScored := junk.LastPlayerHit
if playerScored != nil {
playerScored.AddPoints(models.PointsPerJunk)
}
Expand Down
14 changes: 7 additions & 7 deletions server/models/junk.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const (

// Junk a position and velocity struct describing it's state and player struct to identify rewarding points
type Junk struct {
Position Position `json:"position"`
Velocity Velocity `json:"-"`
Color string `json:"color"`
PlayerHitMe *Player `json:"-"`
Debounce int `json:"-"`
jDebounce int
Position Position `json:"position"`
Velocity Velocity `json:"-"`
Color string `json:"color"`
LastPlayerHit *Player `json:"-"`
Debounce int `json:"-"`
jDebounce int
}

// CreateJunk initializes and returns an instance of a Junk
Expand Down Expand Up @@ -72,7 +72,7 @@ func (j *Junk) HitBy(p *Player) {
}

j.Color = p.Color //Assign junk to last recently hit player color
j.PlayerHitMe = p
j.LastPlayerHit = p

if p.Velocity.Dx < 0 {
j.Velocity.Dx = math.Min(p.Velocity.Dx*BumpFactor, -MinimumBump)
Expand Down
8 changes: 4 additions & 4 deletions server/models/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Player struct {
Angle float64 `json:"angle"`
Controls KeysPressed `json:"-"`
Points int `json:"points"`
PlayerHitMe *Player `json:"-"`
LastPlayerHit *Player `json:"-"`
pointsDebounce int
pDebounce int
mutex sync.Mutex
Expand Down Expand Up @@ -150,7 +150,7 @@ func (p *Player) UpdatePosition(height float64, width float64) {
if p.pointsDebounce > 0 {
p.pointsDebounce--
} else {
p.PlayerHitMe = nil
p.LastPlayerHit = nil
p.pointsDebounce = 0
}
}
Expand All @@ -176,8 +176,8 @@ func (p *Player) HitPlayer(ph *Player) {
ph.Velocity.Dx = (ph.Velocity.Dx * -VelocityTransferFactor) + (initalVelocity.Dx * VelocityTransferFactor)
ph.Velocity.Dy = (ph.Velocity.Dy * -VelocityTransferFactor) + (initalVelocity.Dy * VelocityTransferFactor)

ph.PlayerHitMe = p
p.PlayerHitMe = ph
ph.LastPlayerHit = p
p.LastPlayerHit = ph
p.pointsDebounce = PointsDebounceTicks
ph.pointsDebounce = PointsDebounceTicks
p.pDebounce = PlayerDebounceTicks
Expand Down

0 comments on commit 354045d

Please sign in to comment.