2018-04-22 23:50:39 +02:00
|
|
|
|
using Assets.Scripts.Entities.Attack;
|
2018-04-21 18:45:26 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class Player : Mob {
|
2018-04-23 19:14:18 +02:00
|
|
|
|
|
|
|
|
|
Rigidbody2D body;
|
2018-04-22 23:50:39 +02:00
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private GameObject bulletPrefab;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
Transform bulletSpawn;
|
2018-04-23 19:50:04 +02:00
|
|
|
|
//[SerializeField]
|
|
|
|
|
//private int carDamage = 5;
|
2018-04-22 23:50:39 +02:00
|
|
|
|
|
|
|
|
|
private float nextAttackTime;
|
2018-04-21 18:45:26 +02:00
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
public Player() : base(100) { }
|
2018-04-21 18:45:26 +02:00
|
|
|
|
|
2018-04-22 23:50:39 +02:00
|
|
|
|
private void Start() {
|
2018-04-24 01:53:28 +02:00
|
|
|
|
SingleShot s = new SingleShot(this.gameObject, 6, 0.2f, 20);
|
2018-04-22 23:50:39 +02:00
|
|
|
|
s.SetPrefab(bulletPrefab);
|
|
|
|
|
s.SetSpawn(bulletSpawn);
|
2018-04-23 19:14:18 +02:00
|
|
|
|
body = GetComponent<Rigidbody2D>();
|
2018-04-22 23:50:39 +02:00
|
|
|
|
SetAttack(s);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 17:48:22 +02:00
|
|
|
|
void Update() {
|
|
|
|
|
if (Input.GetAxis("Reset") > 0)
|
|
|
|
|
{
|
|
|
|
|
GameController.instance.GetUI().Restart();
|
|
|
|
|
}
|
2018-04-22 23:50:39 +02:00
|
|
|
|
if ( Time.timeSinceLevelLoad >= nextAttackTime && attack != null) {
|
2018-04-23 16:24:59 +02:00
|
|
|
|
if ( Input.GetAxis("Fire") > 0 ) {
|
2018-04-22 23:50:39 +02:00
|
|
|
|
attack.Attack();
|
2018-04-23 21:25:35 +02:00
|
|
|
|
nextAttackTime = Time.timeSinceLevelLoad + attack.GetCooldownTime(); // Todo put in attack()
|
2018-04-22 23:50:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-23 19:31:50 +02:00
|
|
|
|
// scale particle emissions by speed
|
2018-04-23 19:14:18 +02:00
|
|
|
|
float velocity = body.velocity.magnitude;
|
2018-04-23 23:22:07 +02:00
|
|
|
|
ParticleSystem[] particles = GetComponentsInChildren<ParticleSystem>();
|
|
|
|
|
foreach (ParticleSystem particle in particles) {
|
|
|
|
|
ParticleSystem.EmissionModule emission = particle.emission;
|
|
|
|
|
emission.rateOverTime = velocity * (velocity / 4) * 20 + 10;
|
|
|
|
|
}
|
2018-04-22 23:50:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Collision checking. Player is going to die on any collision with a wall.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="collision"></param>
|
|
|
|
|
private void OnCollisionEnter2D(Collision2D collision) {
|
2018-04-21 19:50:12 +02:00
|
|
|
|
Debug.Log("Collision");
|
2018-04-22 15:59:14 +02:00
|
|
|
|
if ( collision.collider.tag == "wall" ) {
|
2018-04-24 01:53:28 +02:00
|
|
|
|
//InflictDamage(maxHP / 2);
|
|
|
|
|
Death();
|
2018-04-24 15:58:27 +02:00
|
|
|
|
} else if (collision.collider.tag == "rock")
|
|
|
|
|
{
|
|
|
|
|
InflictDamage(maxHP / 10);
|
|
|
|
|
//Death();
|
|
|
|
|
}
|
|
|
|
|
else if ( collision.collider.tag == "Enemy" ) {
|
2018-04-22 05:57:26 +02:00
|
|
|
|
Mob m = collision.collider.GetComponent(typeof(Mob)) as Mob;
|
2018-04-22 15:59:14 +02:00
|
|
|
|
if ( m != null ) {
|
2018-04-23 01:25:50 +02:00
|
|
|
|
//m.InflictDamage(carDamage);
|
|
|
|
|
//InflictDamage(carDamage); // TODO
|
2018-04-22 05:57:26 +02:00
|
|
|
|
}
|
2018-04-21 19:50:12 +02:00
|
|
|
|
}
|
2018-04-22 15:59:14 +02:00
|
|
|
|
}
|
2018-04-21 19:50:12 +02:00
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is called when a Player died.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override void Death() {
|
2018-04-22 19:43:29 +02:00
|
|
|
|
Debug.Log("Player died...");
|
2018-04-24 00:04:59 +02:00
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
|
GameController.instance.GetAudioControl().SfxStop(AudioControl.Sfx.slowdriving);
|
|
|
|
|
GameController.instance.GetAudioControl().SfxStop(AudioControl.Sfx.driving);
|
|
|
|
|
GameController.instance.GetAudioControl().SfxPlay(AudioControl.Sfx.explosion);
|
2018-04-23 19:11:12 +02:00
|
|
|
|
GameController.instance.EndGame(GameController.EndedCause.DIED);
|
2018-04-22 15:59:14 +02:00
|
|
|
|
}
|
2018-04-21 18:45:26 +02:00
|
|
|
|
}
|