Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Add player dead state #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

yijia-cc
Copy link
Contributor

@yijia-cc yijia-cc commented Apr 1, 2021

Screenshots

image

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:

  1. added a dead state for the player, drawing a tombstone after a player is dead.

  2. removed marker when the player is in the dead state

  3. removed tombstone from the game after 0.5 seconds

@magicoder10 magicoder10 changed the title Feature-add-player-dead-state Add player dead state Apr 1, 2021
game/player/dead.go Outdated Show resolved Hide resolved
}

func (d deadState) draw(batch graphics.Batch) {
if d.lag <= TombstoneImageDuration {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines +13 to +15
func (ts Tombstone) getWidth() int {
return ts.width
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
trappedLag int64
lag int64


func (s sharedState) update(timeElapsed time.Duration) {
return
showMarker bool
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
showMarker bool

@@ -99,6 +98,10 @@ func (s *sharedState) incrementAvailableCandy() {
}
}

func (s *sharedState) shouldShowMarker() bool {
return s.showMarker
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return s.showMarker
return true

func (t *trappedState) update(timeElapsed time.Duration) state {
t.trappedLag += timeElapsed.Nanoseconds()
if t.trappedLag >= trapTimeOut {
t.showMarker = false
Copy link
Owner

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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
showMarker: true,

func (d *deadState) update(timeElapsed time.Duration) state {
d.lag += timeElapsed.Nanoseconds()
return d
}
Copy link
Owner

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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants