Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
589 changes: 589 additions & 0 deletions Assets/Prefabs/PlayerAvatar.prefab

Large diffs are not rendered by default.

32 changes: 31 additions & 1 deletion Assets/Scripts/PlayerAvatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class PlayerAvatar : MonoBehaviour {
public float airDeceleration;
public float groundDeceleration;

public AudioSource[] jumpSounds;
public AudioSource takeDamageSound;
public AudioSource dieSound;
public AudioSource playerSpawnSound;

private GameObject[] spawns;

private HumanPlayer humanPlayer;
Expand All @@ -38,11 +43,17 @@ void Start() {

// Update is called once per frame
void Update() {
if (isDead()) {
return;
}

this.handleMovement();
this.handleWraparound();
}

void respawn() {
playerSpawnSound.Play();

this.rb = this.GetComponent<Rigidbody2D>();
this.boxCollider = this.GetComponent<BoxCollider2D>();
this.grounded = false;
Expand Down Expand Up @@ -103,11 +114,15 @@ private void handleWraparound() {
}

private void takeDamage(int amount, GameObject source) {
takeDamageSound.Play();

this.hitpoints -= amount;
if (this.hitpoints <= 0) {
dieSound.Play();

// Die!
this.humanPlayer.AddDeath();
Destroy(gameObject);
StartCoroutine(scheduleForDestruction());

// Give a kill to whoever pwn'd this player
PlayerAvatar killer = source.GetComponent<PlayerAvatar>();
Expand All @@ -117,6 +132,20 @@ private void takeDamage(int amount, GameObject source) {
}
}

private bool isDead() {
return hitpoints <= 0;
}

// scheduleForDestruction
// FUTURE: move all sound to a SoundManager, which exists independent of this
// -or- don't use Destroy(gameObject) to manage killing of PlayerAvatar
public IEnumerator scheduleForDestruction() {
// give time for death sounds to play (<1s)
// FUTURE: add a death animation
yield return new WaitForSeconds(0.2f);
Destroy(gameObject);
}

public void SetHumanPlayer(HumanPlayer hp) {
humanPlayer = hp;
}
Expand Down Expand Up @@ -156,6 +185,7 @@ public void _onMove(InputValue value) {

public void _onJump() {
if (this.grounded) {
jumpSounds[Random.Range(0, jumpSounds.Length)].Play();
this.m_isJumping = true;
}
}
Expand Down
8 changes: 8 additions & 0 deletions Assets/Sounds.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Sounds/Effects.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Sounds/Effects/Death.wav
Git LFS file not shown
22 changes: 22 additions & 0 deletions Assets/Sounds/Effects/Death.wav.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Sounds/Effects/Jump1.wav
Git LFS file not shown
22 changes: 22 additions & 0 deletions Assets/Sounds/Effects/Jump1.wav.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Sounds/Effects/Jump2.wav
Git LFS file not shown
22 changes: 22 additions & 0 deletions Assets/Sounds/Effects/Jump2.wav.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Sounds/Effects/Jump3.wav
Git LFS file not shown
22 changes: 22 additions & 0 deletions Assets/Sounds/Effects/Jump3.wav.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Sounds/Effects/Spawn.wav
Git LFS file not shown
22 changes: 22 additions & 0 deletions Assets/Sounds/Effects/Spawn.wav.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Sounds/Effects/TakeDamage.wav
Git LFS file not shown
22 changes: 22 additions & 0 deletions Assets/Sounds/Effects/TakeDamage.wav.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.