-
Notifications
You must be signed in to change notification settings - Fork 1
Add player dead state #80
base: master
Are you sure you want to change the base?
Conversation
} | ||
|
||
func (d deadState) draw(batch graphics.Batch) { | ||
if d.lag <= TombstoneImageDuration { |
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.
if d.lag <= TombstoneImageDuration { | |
if d.lag <= TombstoneImageDuration { |
Let's put this in update and create a new field called: shouldShow. Then use it here for guarding
func (ts Tombstone) getWidth() int { | ||
return ts.width | ||
} |
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.
func (ts Tombstone) getWidth() int { | |
return ts.width | |
} |
We can directly access width in the same package
var _ state = (*trappedState)(nil) | ||
|
||
type trappedState struct { | ||
*sharedState | ||
jelly *Jelly | ||
prevDirection direction.Direction | ||
trappedLag int64 |
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.
trappedLag int64 | |
lag int64 |
|
||
func (s sharedState) update(timeElapsed time.Duration) { | ||
return | ||
showMarker bool |
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.
showMarker bool |
@@ -99,6 +98,10 @@ func (s *sharedState) incrementAvailableCandy() { | |||
} | |||
} | |||
|
|||
func (s *sharedState) shouldShowMarker() bool { | |||
return s.showMarker |
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.
return s.showMarker | |
return true |
func (t *trappedState) update(timeElapsed time.Duration) state { | ||
t.trappedLag += timeElapsed.Nanoseconds() | ||
if t.trappedLag >= trapTimeOut { | ||
t.showMarker = false |
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 mean you already entered dead state. Dead state will take care of the marker.
@@ -62,6 +67,7 @@ func newStandingStateOnSquare( | |||
availableCandy: character.initialCandyLimit, | |||
character: character, | |||
pubSub: pubSub, | |||
showMarker: true, |
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.
showMarker: true, |
func (d *deadState) update(timeElapsed time.Duration) state { | ||
d.lag += timeElapsed.Nanoseconds() | ||
return d | ||
} |
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.
Let's just override shouldShowMarker function and return false.
Co-authored-by: Magic Coder <[email protected]>
Screenshots
High Level
This PR is to move a player to a dead state when the he/she is trapped in the jelly for more than 5 seconds.
Detailed Explanation
Per game rule, a player can die and be removed from the game after being trapped for 5 seconds. I did 3 things:
added a dead state for the player, drawing a tombstone after a player is dead.
removed marker when the player is in the dead state
removed tombstone from the game after 0.5 seconds