Commit b49e831e authored by Luke A Smith's avatar Luke A Smith

Merge branch 'Organization' into 'master'

Organization

See merge request !26
parents dc5f8507 b179b448
using UnityEngine;
using System.Collections;
public class Boss : MonoBehaviour {
private Rigidbody2D rb;
public float speed = 1f;
public GameObject[] waypoints;
private Transform currentWaypoint;
public float distanceThreshold = 0.5f;
public GameObject projectile;
public float attackCooldown = 2.0f;
public float attackRandom = 1.0f;
private float lastAttack = 0;
public float projectileSpeed = 5;
public int health = 100;
public GameObject diety;
// Use this for initialization
void Start () {
waypoints = GameObject.FindGameObjectsWithTag("Waypoint");
rb = GetComponent<Rigidbody2D>();
PickWaypoint();
}
// Update is called once per frame
void Update () {
if (currentWaypoint) {
if (Vector2.Distance(transform.position, currentWaypoint.position) < distanceThreshold) {
PickWaypoint();
} else {
Vector2 dir = currentWaypoint.position - transform.position;
Vector2 force = new Vector2(dir.x, dir.y) * speed;
rb.AddForce(Vector2.ClampMagnitude(force, speed));
}
}
if(Time.time > lastAttack) {
lastAttack = Time.time + attackCooldown + Random.Range(0, attackRandom);
Shoot(0);
Shoot(90);
Shoot(180);
Shoot(270);
}
}
void PickWaypoint() {
currentWaypoint = waypoints[Random.Range(0, waypoints.Length)].transform;
}
void Shoot(int angle) {
float rad = (angle + 90) * Mathf.Deg2Rad;
Vector2 vel = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad)) * projectileSpeed;
GameObject projectile_clone = Instantiate(projectile, transform.position, Quaternion.identity) as GameObject;
projectile_clone.GetComponent<Rigidbody2D>().velocity = vel;
projectile_clone.transform.eulerAngles = new Vector3(0, 0, angle);
}
void GetHit(int amount) {
health -= health;
if (health <= 0) {
Die();
}
}
void Die() {
Instantiate(diety, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
using UnityEngine;
using System.Collections;
public class Boss : MonoBehaviour {
private Rigidbody2D rb;
public float speed = 1f;
public GameObject[] waypoints;
private Transform currentWaypoint;
public float distanceThreshold = 0.5f;
public GameObject projectile;
public float attackCooldown = 2.0f;
public float attackRandom = 1.0f;
private float lastAttack = 0;
public float projectileSpeed = 5;
public int health = 100;
public GameObject diety;
// Use this for initialization
void Start () {
waypoints = GameObject.FindGameObjectsWithTag("Waypoint");
rb = GetComponent<Rigidbody2D>();
PickWaypoint();
}
// Update is called once per frame
void Update () {
if (currentWaypoint) {
if (Vector2.Distance(transform.position, currentWaypoint.position) < distanceThreshold) {
PickWaypoint();
} else {
Vector2 dir = currentWaypoint.position - transform.position;
Vector2 force = new Vector2(dir.x, dir.y) * speed;
rb.AddForce(Vector2.ClampMagnitude(force, speed));
}
}
if(Time.time > lastAttack) {
lastAttack = Time.time + attackCooldown + Random.Range(0, attackRandom);
Shoot(0);
Shoot(90);
Shoot(180);
Shoot(270);
}
}
void PickWaypoint() {
currentWaypoint = waypoints[Random.Range(0, waypoints.Length)].transform;
}
void Shoot(int angle) {
float rad = (angle + 90) * Mathf.Deg2Rad;
Vector2 vel = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad)) * projectileSpeed;
GameObject projectile_clone = Instantiate(projectile, transform.position, Quaternion.identity) as GameObject;
projectile_clone.GetComponent<Rigidbody2D>().velocity = vel;
projectile_clone.transform.eulerAngles = new Vector3(0, 0, angle);
}
void GetHit(int amount) {
health -= health;
if (health <= 0) {
Die();
}
}
void Die() {
Instantiate(diety, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
using UnityEngine;
using System.Collections;
public class EnemyProjectile : MonoBehaviour {
// TEMPORARY
// Does not damage player
void OnCollisionEnter2D(Collision2D col) {
Destroy(gameObject);
}
}
using UnityEngine;
using System.Collections;
public class EnemyProjectile : MonoBehaviour {
// TEMPORARY
// Does not damage player
void OnCollisionEnter2D(Collision2D col) {
Destroy(gameObject);
}
}
using UnityEngine;
using System.Collections;
public class RandomSprite : MonoBehaviour {
public Sprite[] tiles;
// Use this for initialization
void Start () {
GetComponent<SpriteRenderer>().sprite = tiles[Random.Range(0, tiles.Length)];
}
}
using UnityEngine;
using System.Collections;
public class RandomSprite : MonoBehaviour {
public Sprite[] tiles;
// Use this for initialization
void Start () {
GetComponent<SpriteRenderer>().sprite = tiles[Random.Range(0, tiles.Length)];
}
}
using UnityEngine;
using System.Collections;
public class WalkParticles : MonoBehaviour {
private ParticleSystem ps;
private ParticleSystem.EmissionModule module;
private HeroMobility hm;
public float speedThreshold = 0.001f;
// Use this for initialization
void Start () {
ps = GetComponentInChildren<ParticleSystem>();
module = ps.emission;
hm = GetComponent<HeroMobility>();
}
// Update is called once per frame
void LateUpdate () {
if (hm.deltaPos.sqrMagnitude > speedThreshold) {
if (!ps.isPlaying) {
ps.Simulate(0.0f, true, false);
module.enabled = true;
ps.Play();
}
} else {
if (ps.isPlaying) {
module.enabled = false;
ps.Stop();
}
}
}
}
using UnityEngine;
using System.Collections;
public class WalkParticles : MonoBehaviour {
private ParticleSystem ps;
private ParticleSystem.EmissionModule module;
private HeroMobility hm;
public float speedThreshold = 0.001f;
// Use this for initialization
void Start () {
ps = GetComponentInChildren<ParticleSystem>();
module = ps.emission;
hm = GetComponent<HeroMobility>();
}
// Update is called once per frame
void LateUpdate () {
if (hm.deltaPos.sqrMagnitude > speedThreshold) {
if (!ps.isPlaying) {
ps.Simulate(0.0f, true, false);
module.enabled = true;
ps.Play();
}
} else {
if (ps.isPlaying) {
module.enabled = false;
ps.Stop();
}
}
}
}
using UnityEngine;
using System.Collections;
public class WaterShield : MonoBehaviour {
private float timerOfShield = 0.0f;
public float durationOfShield = 2.0f;
public GameObject projectilePrefab;
public int projectileSpeed = 5;
public int numberOfProjectiles = 5;
private GameObject player;
[HideInInspector]
public Vector2 playerDirection;
void Start() {
player = GameObject.FindGameObjectWithTag("Player");
}
void Update () {
playerDirection = player.GetComponent<Actions>().GetLastDirection();
transform.position = player.transform.position;
timerOfShield += Time.deltaTime;
if(timerOfShield >= durationOfShield) {
Explode();
Destroy(this.gameObject);
}
}
void Explode() {
for(int i = 0; i < numberOfProjectiles; i++) {
GameObject waterShieldProjectile = (GameObject)Instantiate(projectilePrefab, transform.position, Quaternion.identity);
waterShieldProjectile.GetComponent<WaterShieldProjectile>().direction = Rotate(playerDirection, 20 - (i * 10));
waterShieldProjectile.GetComponent<WaterShieldProjectile>().speed = projectileSpeed;
}
}
public Vector2 Rotate(Vector2 v, float degrees) {
float sin = Mathf.Sin(degrees * Mathf.Deg2Rad);
float cos = Mathf.Cos(degrees * Mathf.Deg2Rad);
float tx = v.x;
float ty = v.y;
v.x = (cos * tx) - (sin * ty);
v.y = (sin * tx) + (cos * ty);
return v;
}
}
using UnityEngine;
using System.Collections;
public class WaterShield : MonoBehaviour {
private float timerOfShield = 0.0f;
public float durationOfShield = 2.0f;
public GameObject projectilePrefab;
public int projectileSpeed = 5;
public int numberOfProjectiles = 5;
private GameObject player;
[HideInInspector]
public Vector2 playerDirection;
void Start() {
player = GameObject.FindGameObjectWithTag("Player");
}
void Update () {
playerDirection = player.GetComponent<Actions>().GetLastDirection();
transform.position = player.transform.position;
timerOfShield += Time.deltaTime;
if(timerOfShield >= durationOfShield) {
Explode();
Destroy(this.gameObject);
}
}
void Explode() {
for(int i = 0; i < numberOfProjectiles; i++) {
GameObject waterShieldProjectile = (GameObject)Instantiate(projectilePrefab, transform.position, Quaternion.identity);
waterShieldProjectile.GetComponent<WaterShieldProjectile>().direction = Rotate(playerDirection, 20 - (i * 10));
waterShieldProjectile.GetComponent<WaterShieldProjectile>().speed = projectileSpeed;
}
}
public Vector2 Rotate(Vector2 v, float degrees) {
float sin = Mathf.Sin(degrees * Mathf.Deg2Rad);
float cos = Mathf.Cos(degrees * Mathf.Deg2Rad);
float tx = v.x;
float ty = v.y;
v.x = (cos * tx) - (sin * ty);
v.y = (sin * tx) + (cos * ty);
return v;
}
}
using UnityEngine;
using System.Collections;
public class ZSort : MonoBehaviour {
private SpriteRenderer sr;
public float offset = 0;
void Start () {
sr = GetComponent<SpriteRenderer>();
if (sr) {
sr.sortingLayerName = "Moving";
offset += sr.sprite.bounds.extents.y;
}
}
void LateUpdate () {
if (sr) {
sr.sortingOrder = (int)((transform.position.y - offset) * -100);
}
}
}
using UnityEngine;
using System.Collections;
public class ZSort : MonoBehaviour {
private SpriteRenderer sr;
public float offset = 0;
void Start () {
sr = GetComponent<SpriteRenderer>();
if (sr) {
sr.sortingLayerName = "Moving";
offset += sr.sprite.bounds.extents.y;
}
}
void LateUpdate () {
if (sr) {
sr.sortingOrder = (int)((transform.position.y - offset) * -100);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment