Last active
April 1, 2020 19:43
-
-
Save kawzar/37585b043c1fb497319cd60b89b05855 to your computer and use it in GitHub Desktop.
Tamagotchi (Introducción a la programación de videojuegos desde cero! - Clase #4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Tamagotchi : MonoBehaviour | |
{ | |
// El estomago de nuestra mascota | |
public float stomach = 100; | |
// La vida social de nuestra mascota | |
public float social = 100; | |
// El valor alimenticio de las galletitas | |
private float cookies = 2.5f; | |
// El valor alimenticio del sobrecito | |
private float pouch = 5; | |
// El valor alimenticio del pollo | |
private float chicken = 10; | |
// La ultima vez que actualizamos las stats | |
private float statsLastUpdate = 0; | |
// Update is called once per frame | |
void Update() | |
{ | |
if (social > 0 && stomach > 0) | |
{ | |
// Actualizamos las stats | |
UpdateStats(); | |
if (Input.GetKeyDown(KeyCode.Alpha1)) | |
{ | |
// Alimentamos con cookies | |
Feed(cookies); | |
} | |
if (Input.GetKeyDown(KeyCode.Alpha2)) | |
{ | |
// Alimentar pouch | |
} | |
if (Input.GetKeyDown(KeyCode.Alpha3)) | |
{ | |
// Alimentar pollo | |
} | |
// Si aprieto la barra espaciadora, se baña | |
// Por ultimo, mostramos mensajes en caso que sea necesario | |
ShowMessages(); | |
} | |
} | |
private void Feed(float foodValue) | |
{ | |
// Aca va el codigo para alimentar al animal. | |
// Food value va a depender de el alimento que le damos | |
// Actualizar el valor de stomach segun corresponda | |
// Acordarse de chequear que no se pase de 100! | |
} | |
private void Shower() | |
{ | |
// Bañarse mejora la sociabilidad en 2.5f | |
// cuidado! social nunca debe ser mayor a 100 | |
} | |
private string GetHungryMessage(float value) | |
{ | |
return "Su mascota tiene hambre! Estomago: " + value; | |
} | |
private string GetSocialMessage(float value) | |
{ | |
// Hacer que devuelva un mensaje indicando que necesita bañarse! | |
return ""; | |
} | |
private void ShowMessages() | |
{ | |
if (stomach == 0 || social == 0) | |
{ | |
print("SU MASCOTA HA MUERTO"); | |
} | |
else | |
{ | |
if (stomach < 30) | |
{ | |
print(GetHungryMessage(stomach)); | |
} | |
if (social < 30) | |
{ | |
print(GetSocialMessage(social)); | |
} | |
} | |
} | |
private void UpdateStats() | |
{ | |
// Si pasaron 1.5 segundos desde que actualizamos las stats, actualizamos de nuevo | |
if (Time.time - statsLastUpdate >= 1.5f) | |
{ | |
// Nos fijamos de no pasarnos de 0 cuando restamos | |
if (stomach - 0.25f >= 0) | |
{ | |
stomach -= 0.25f; | |
} | |
else | |
{ | |
stomach = 0; | |
} | |
// Nos fijamos de no pasarnos de 0 cuando restamos | |
if (social - 0.25f >= 0) | |
{ | |
social -= 0.25f; | |
} | |
else | |
{ | |
social = 0; | |
} | |
statsLastUpdate = Time.time; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment