Skip to content

Instantly share code, notes, and snippets.

@AzureBoers
Created April 23, 2018 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AzureBoers/75f6da540aa6dc9d527f14ef5fe77d30 to your computer and use it in GitHub Desktop.
Save AzureBoers/75f6da540aa6dc9d527f14ef5fe77d30 to your computer and use it in GitHub Desktop.
LD41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DamageEnemy : MonoBehaviour
{
public int damageToGive;
private int currentDamage;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Enemy")
{
currentDamage = damageToGive;
other.gameObject.GetComponent<HealthForEnemys>().HurtEnemy(currentDamage);
// Destroy(other.gameObject);
}
}
}
using UnityEngine;
public class EnemyTimer : MonoBehaviour {
float timer;
public float waitTime = 5f;
public GameObject Enemy;
private bool respawn;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
timer += Time.deltaTime;
if (timer > waitTime)
{
Instantiate(Enemy, transform.position, transform.rotation);
print("Timer is done");
timer = 0f;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Garden : MonoBehaviour {
public float plantTimeCounter;
public float plantTime;
private LD41Manager manager;
private HealPlayer heal;
public string LevelLoad;
public GameObject plant;
private bool NewPlant;
private bool seedPlanted;
private bool fullGrow;
private bool NoPlant;
public GameObject fullPlant;
// Use this for initialization
void Start () {
heal = FindObjectOfType<HealPlayer>();
manager = FindObjectOfType<LD41Manager>();
seedPlanted = false;
fullGrow = false;
fullPlant.SetActive(false);
NoPlant = true;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.P) && manager.coinCount >= 1)
{
manager.AddCoins(-1);
plant.SetActive(true);
seedPlanted = true;
NoPlant = false;
fullPlant.SetActive(false);
}
if (seedPlanted == true || NewPlant == true)
{
plantTimeCounter = plantTime;
}
if (plantTimeCounter > 0)
{
plantTimeCounter -= Time.time;
if (plantTimeCounter <= 0 && seedPlanted == true)
{
plant.SetActive(false);
fullPlant.SetActive(true);
if (Input.GetKeyDown(KeyCode.E))
{
plantTimeCounter = plantTime;
NewPlant = true;
UnPlant();
manager.healthCount += 1;
if (manager.healthCount > manager.maxHealth)
{
manager.healthCount = manager.maxHealth;
}
manager.UpdateHeartMeter();
NoPlant = true;
}
}
}
}
public void UnPlant()
{
plantTimeCounter = 0f;
plantTime = 30f;
NoPlant = true;
seedPlanted = false;
plant.SetActive(false);
fullPlant.SetActive(false);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealPlayer : MonoBehaviour {
private Garden garden;
private LD41Manager manager;
public int HP;
private void Start()
{
manager = FindObjectOfType<LD41Manager>();
garden = FindObjectOfType<Garden>();
}
void Update()
{
}
public void Heal()
{
garden.fullPlant.SetActive(false);
manager.healthCount += HP;
if (manager.healthCount > manager.maxHealth)
{
manager.healthCount = manager.maxHealth;
}
manager.UpdateHeartMeter();
Destroy(gameObject);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealthForEnemys : MonoBehaviour {
public int MaxHealth;
public int CurrentHealth;
public GameObject seed;
public int deathCount;
private LD41Manager manager;
// Use this for initialization
void Start () {
CurrentHealth = MaxHealth;
manager = FindObjectOfType<LD41Manager>();
}
// Update is called once per frame
void Update () {
if (CurrentHealth <= 0)
{
manager.DeathCount(deathCount);
Instantiate(seed, transform.position, transform.rotation);
Destroy(gameObject);
}
}
public void HurtEnemy(int damageToGive)
{
CurrentHealth -= damageToGive;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LD41Manager : MonoBehaviour {
public int coinCount;
public int deaths;
public string LevelToLoad;
public string WinScreen;
public Text Seed1;
public Text seedText;
public Text deathText;
public Image heart1;
public Image heart2;
public Image heart3;
public Sprite heartFull;
public Sprite heartHalf;
public Sprite heartZero;
public int maxHealth;
public int healthCount;
// Use this for initialization
void Start () {
healthCount = maxHealth;
}
// Update is called once per frame
void Update () {
if(healthCount <= 0)
{
SceneManager.LoadScene(LevelToLoad);
}
}
public void DeathCount(int countdeath)
{
deaths += countdeath;
deathText.text = "Death: " + deaths;
if(deaths == 20)
{
SceneManager.LoadScene(WinScreen);
}
}
public void AddCoins(int coinsToAdd)
{
coinCount += coinsToAdd;
seedText.text = "Seeds: " + coinCount;
}
public void PlayerHurt(int damageToTake)
{
healthCount -= damageToTake;
UpdateHeartMeter();
}
public void UpdateHeartMeter()
{
switch (healthCount)
{
case 6:
heart1.sprite = heartFull;
heart2.sprite = heartFull;
heart3.sprite = heartFull;
return;
case 5:
heart1.sprite = heartFull;
heart2.sprite = heartFull;
heart3.sprite = heartHalf;
return;
case 4:
heart1.sprite = heartFull;
heart2.sprite = heartFull;
heart3.sprite = heartZero;
return;
case 3:
heart1.sprite = heartFull;
heart2.sprite = heartHalf;
heart3.sprite = heartZero;
return;
case 2:
heart1.sprite = heartFull;
heart2.sprite = heartZero;
heart3.sprite = heartZero;
return;
case 1:
heart1.sprite = heartHalf;
heart2.sprite = heartZero;
heart3.sprite = heartZero;
return;
case 0:
heart1.sprite = heartZero;
heart2.sprite = heartZero;
heart3.sprite = heartZero;
return;
default:
heart1.sprite = heartZero;
heart2.sprite = heartZero;
heart3.sprite = heartZero;
return;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Ld41Menu : MonoBehaviour {
public string LevelToLoad;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void Quit()
{
Application.Quit();
}
public void StartGame()
{
SceneManager.LoadScene(LevelToLoad);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControllor : MonoBehaviour
{
[SerializeField]
public float moveSpeed;
public float currentMoveSpeed;
public float diagonalMoveMod;
private Animator anim;
private Rigidbody2D myRigidbody;
public bool playerMoving;
public Vector2 lastMove;
//Attacking
private bool attacking;
public float attackTime;
private float attackTimeCounter;
//Magic
private bool magic;
public float magicTime;
private float magicTimeCounter;
//Tells if the player is there or not
private static bool playerExist;
public string startPoint;
public bool canMove;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
myRigidbody = GetComponent<Rigidbody2D>();
if (!playerExist)
{
playerExist = true;
DontDestroyOnLoad(transform.gameObject);
}
else
{
Destroy(gameObject);
}
canMove = true;
}
// Update is called once per frame
void Update()
{
playerMoving = false;
if (!canMove)
{
myRigidbody.velocity = Vector2.zero;
return;
}
if (!attacking)
{
if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
{
transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * currentMoveSpeed * Time.deltaTime, 0f, 0f));
myRigidbody.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * currentMoveSpeed, myRigidbody.velocity.x);
playerMoving = true;
lastMove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
}
if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
{
transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical") * currentMoveSpeed * Time.deltaTime, 0f));
myRigidbody.velocity = new Vector2(myRigidbody.velocity.y, Input.GetAxisRaw("Vertical") * currentMoveSpeed);
playerMoving = true;
lastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
}
if (Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f)
{
myRigidbody.velocity = new Vector2(0f, myRigidbody.velocity.x);
}
if (Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.y, 0f);
}
//This line is for attacking with swords
if (Input.GetButtonDown("Attack"))
{
attackTimeCounter = attackTime;
attacking = true;
myRigidbody.velocity = Vector2.zero;
anim.SetBool("Attack", true);
}
if (Input.GetKeyDown(KeyCode.G))
{
}
if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) > 0.5f && (Input.GetAxisRaw("Vertical")) > 0.5f)
{
currentMoveSpeed = moveSpeed * diagonalMoveMod;
}
else
{
currentMoveSpeed = moveSpeed;
}
}
if(attackTimeCounter > 0)
{
attackTimeCounter -= Time.deltaTime;
}
if(attackTimeCounter <= 0)
{
attacking = false;
anim.SetBool("Attack", false);
}
anim.SetFloat("x", Input.GetAxisRaw("Horizontal"));
anim.SetFloat("y", Input.GetAxisRaw("Vertical"));
anim.SetBool("PlayerMoving", playerMoving);
anim.SetFloat("LastMoveX", lastMove.x);
anim.SetFloat("LastMoveY", lastMove.y);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Seed : MonoBehaviour {
private LD41Manager thelevelManager;
public int coinValue;
// Use this for initialization
void Start()
{
thelevelManager = FindObjectOfType<LD41Manager>();
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
thelevelManager.AddCoins(coinValue);
Destroy(gameObject);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour {
public float speed;
public GameObject attacktarger;
public Transform target;
public int damageToGive;
private LD41Manager manager;
// Use this for initialization
void Start () {
manager = FindObjectOfType<LD41Manager>();
// target = attacktarger.p;
}
// Update is called once per frame
void Update () {
transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Player")
{
manager.PlayerHurt(damageToGive);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment