Skip to content
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

[Feature]: Kills + health pickup + enemigos tienen cada vez más vida #35

Merged
merged 1 commit into from
Jun 19, 2023
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
9 changes: 0 additions & 9 deletions Assets/BulletEnemy1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,8 @@ private void OnTriggerEnter2D(Collider2D other)

GameObject.Destroy(gameObject);
}

private void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("COLISION");

// var health = other.gameObject.GetComponent<Health>();
// if (health != null)
// {
// health.Damage(UnityEngine.Random.Range(minDamage, maxDamage));
// }

GameObject.Destroy(gameObject);
}
}
2 changes: 0 additions & 2 deletions Assets/Enemy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ private void OnTriggerEnter2D(Collider2D other)
{
playerHealth.TakeDamage();
}

//GameObject.Destroy(gameObject);
}
}
2 changes: 0 additions & 2 deletions Assets/GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public void OnPauseButton()
{
pauseMenu.Open();
}

// check for player, if player is dead, show game over menu
private void Update()
{
if (GameObject.FindWithTag("Player") == null)
Expand Down
4 changes: 3 additions & 1 deletion Assets/GameOverMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
public class GameOverMenu : MonoBehaviour
{
public TextMeshProUGUI scoreText;
public TextMeshProUGUI killsText;

public void Start()
{
string playerScore = PlayerPrefs.GetFloat("Player Score").ToString();
string playerKills = PlayerPrefs.GetInt("Kills").ToString();
scoreText.text = "Score: " + playerScore;
killsText.text = "Kills: " + playerKills;

}
public void OnMainMenu()
{
// Load the "MainMenu" scene
SceneManager.LoadScene("MainMenu");
}
}
25 changes: 1 addition & 24 deletions Assets/Health.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,16 @@ public class Health : MonoBehaviour
{
public float current;
public float total;

// public GameObject deathFxPrefab;

// public CinemachineImpulseSource deathImpulseSource;

public float factor => current / total;

// public UnityEvent<float> onDamageUnityEvent;

public void Damage(float damage)
{
current -= damage;

if (damage > 0)
{
// onDamageUnityEvent.Invoke(damage);
// gameObject.BroadcastMessage("OnDamage", damage, SendMessageOptions.DontRequireReceiver);

// EventosGenerales.OnPersonajeDamaged(this.gameObject, damage);
}

if (current <= 0)
{
// if (deathImpulseSource != null)
// {
// deathImpulseSource.GenerateImpulse();
// }

// EventosGenerales.OnPersonajeDeath(this.gameObject, damage);

// GameObject.Instantiate(deathFxPrefab, transform.position, transform.rotation);

GameObject.Destroy(gameObject);
PlayerPrefs.SetInt("Kills", PlayerPrefs.GetInt("Kills") + 1);
return;
}
}
Expand Down
7 changes: 0 additions & 7 deletions Assets/HealthBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ public class HealthBar : MonoBehaviour
public CanvasGroup canvasGroup;
public Transform bar;

// public Animator animator;

// public void OnDamage(float damage)
// {
// animator.SetTrigger("hit");
// }

private void Update()
{
canvasGroup.alpha = health.factor < 1 ? 1 : 0;
Expand Down
26 changes: 26 additions & 0 deletions Assets/HealthPickup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
using UnityEngine.UI;

public class HealthPickup : MonoBehaviour
{
public GameObject healthPickup;
public float spawnInterval = 14f;

private void Start()
{
StartCoroutine(SpawnPickups());
}

private IEnumerator SpawnPickups()
{
while (true)
{
yield return new WaitForSeconds(spawnInterval);
Instantiate(healthPickup, transform.position, Quaternion.identity);
}
}
}
11 changes: 11 additions & 0 deletions Assets/HealthPickup.cs.meta

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

26 changes: 26 additions & 0 deletions Assets/HealthPickupElem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HealthPickupElem : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("TRIGGER here");
if (collision.gameObject.CompareTag("Player"))
{
collision.gameObject.GetComponent<PlayerHealth>().IncreaseLife();
GameObject.Destroy(gameObject);
}
}

private void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("COLISION here");
if (collision.gameObject.CompareTag("Player"))
{
collision.gameObject.GetComponent<PlayerHealth>().IncreaseLife();
GameObject.Destroy(gameObject);
}
}
}
11 changes: 11 additions & 0 deletions Assets/HealthPickupElem.cs.meta

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

1 change: 0 additions & 1 deletion Assets/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

public class MainMenu : MonoBehaviour
{
// onClick event handler for the "Play" button
public void OnPlay()
{
SceneManager.LoadScene("Game");
Expand Down
12 changes: 8 additions & 4 deletions Assets/PlayerHealth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void TakeDamage()

if (currentLives == 0)
{
// Player loses, handle game over logic here
GameOver();
}
else
Expand All @@ -56,7 +55,6 @@ private IEnumerator InvincibilityCoroutine()

while (Time.time < endTime)
{
// Toggle the visibility of the player sprite
spriteRenderer.enabled = !spriteRenderer.enabled;

yield return new WaitForSeconds(blinkInterval);
Expand Down Expand Up @@ -86,7 +84,14 @@ private IEnumerator ShakeCameraCoroutine()
mainCameraTransform.localPosition = originalCameraLocalPosition;
}


public void IncreaseLife()
{
if (currentLives < maxLives)
{
currentLives++;
UpdateLifeImages();
}
}


private void UpdateLifeImages()
Expand All @@ -102,7 +107,6 @@ private void UpdateLifeImages()

private void GameOver()
{
// destroy player
Destroy(gameObject);
}
}
1 change: 1 addition & 0 deletions Assets/Prefabs/enemyDiagonal.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
current: 1
total: 1
scoreManager: {fileID: 0}
--- !u!114 &6386699792755839327
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
1 change: 1 addition & 0 deletions Assets/Prefabs/enemyRed1.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
current: 2
total: 2
scoreManager: {fileID: 0}
--- !u!95 &7718103853326042173
Animator:
serializedVersion: 5
Expand Down
1 change: 1 addition & 0 deletions Assets/Prefabs/enemyRed2.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
current: 3
total: 3
scoreManager: {fileID: 0}
--- !u!114 &7384598717728045027
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Loading