Browse Source

ghosts

master
Josh 2 years ago
parent
commit
ae396f0560
  1. 2
      unity/Assets/Game.cs
  2. 2436
      unity/Assets/Scenes/SampleScene.unity
  3. 93
      unity/Assets/Scripts/DragonMovement.cs
  4. 11
      unity/Assets/Scripts/Wraparound.cs

2
unity/Assets/Game.cs

@ -10,7 +10,7 @@ public class Game : MonoBehaviour
[SerializeField] GameObject _cloudPrefab;
[SerializeField] GameObject _birdPrefab;
const int NUM_CLOUDS = 6;
const int NUM_CLOUDS = 8;
const float START_X = 1300;
[SerializeField] Text _victoryMessage;
[SerializeField] Text _restartMessage;

2436
unity/Assets/Scenes/SampleScene.unity

File diff suppressed because it is too large

93
unity/Assets/Scripts/DragonMovement.cs

@ -17,12 +17,12 @@ public class DragonMovement : MonoBehaviour
[SerializeField] GameObject _flash;
[SerializeField] string _dragonName;
[SerializeField] Color _color;
[SerializeField] TrailRenderer _trail;
[SerializeField] List<SpriteRenderer> _ammoGui = new List<SpriteRenderer>();
[SerializeField] List<SpriteRenderer> _ammoGui2 = new List<SpriteRenderer>();
[SerializeField] GameObject _ammoNormal;
[SerializeField] GameObject _ammoGlide;
const float GLIDE_TIME = 0.6f;
ArrayList _ghosts = new ArrayList();
float _stunTime = 0f;
float _debugCurSpeed;
@ -31,6 +31,7 @@ public class DragonMovement : MonoBehaviour
int _ammo = 0;
float _speedBoostTime = 0f;
float _timeToUpdateGhosts = 0f;
public enum AttackType
{
@ -154,19 +155,31 @@ public class DragonMovement : MonoBehaviour
}
void Start()
{
GameObject ghostContainer = GameObject.Find("Ghosts");
for (int i = 0; i < 5; ++i)
{
GameObject ghost = transform.Find("Ghost" + (i + 1).ToString()).gameObject;
ghost.transform.parent = ghostContainer.transform;
_ghosts.Add(ghost);
}
Ammo = 0;
_rigidbody = this.GetComponent<Rigidbody2D>();
_animator = this.GetComponent<Animator>();
_trail.startColor = _color;
_trail.endColor = _color;
Ammo = 5;
_attackType = AttackType.CONE;
//Ammo = 5;
//_attackType = AttackType.CONE;
}
private void Update()
{
_speedBoostTime -= Time.deltaTime;
_timeToUpdateGhosts -= Time.deltaTime;
if (_timeToUpdateGhosts < 0)
{
UpdateGhosts();
}
if (Input.GetKeyDown(FlapKey) && _stunTime <0f)
{
@ -216,11 +229,6 @@ public class DragonMovement : MonoBehaviour
}
}
public void ClearTrail()
{
_trail.Clear();
}
void FixedUpdate()
{
if (_flapTime > 0f && _stunTime < 0f)
@ -249,14 +257,8 @@ public class DragonMovement : MonoBehaviour
float verticalSpeed = 0f;
const float GLIDE_TIME = 0.6f;
if (_flapTime < - GLIDE_TIME)
{
if (_trail.enabled == false)
{
_trail.Clear();
_trail.enabled = true;
}
_ammoNormal.SetActive(false);
_ammoGlide.SetActive(true);
_animator.Play("speedup");
@ -264,28 +266,10 @@ public class DragonMovement : MonoBehaviour
}
else
{
_trail.enabled = false;
//
}
/* //old cloud behavior
if (_inCloud)
{
if (_flapTime < 0)
_flapTime = 0;
if (_animator.GetCurrentAnimatorStateInfo(0).IsName("speedup"))
{
_animator.Play("glide");
}
horizontalSpeed = -3f;
if (_rigidbody.velocity.y > 0)
verticalSpeed = -2f;
else if (_rigidbody.velocity.y < 0)
verticalSpeed = 2f;
}
*/
if (_stunTime > 0f)
@ -320,4 +304,41 @@ public class DragonMovement : MonoBehaviour
{
_flash.SetActive(false);
}
void UpdateGhosts()
{
if (_flapTime >= - GLIDE_TIME)
{
foreach (GameObject ghost in _ghosts)
{
ghost.transform.position = new Vector3(-10000, -10000, -10000);
}
}
else
{
for (int i = _ghosts.Count - 1; i >= 0; --i)
{
GameObject thisGhost = (GameObject)_ghosts[i];
GameObject prevGhost;
if (i == 0)
{
prevGhost = this.gameObject;
}
else
prevGhost = (GameObject)_ghosts[i - 1];
thisGhost.GetComponent<SpriteRenderer>().sprite = prevGhost.GetComponent<SpriteRenderer>().sprite;
//thisGhost.scale = prevGhost.scale;
//make the horizontal offset increase with the amount of time in the glide, capping out at -12, and starting out at -5
thisGhost.transform.position = new Vector3(prevGhost.transform.position.x - 12f, prevGhost.transform.position.y, prevGhost.transform.position.z + .1f);
//if (i == 0 && _hidden)
//{
//thisGhost.transform.position = new Vector3(-10000, -10000, 0.1f);
//}
}
}
_timeToUpdateGhosts = .025f;
}
}

11
unity/Assets/Scripts/Wraparound.cs

@ -11,15 +11,6 @@ public class Wraparound : MonoBehaviour
}
void ClearTrail()
{
DragonMovement dragonMovement = GetComponent<DragonMovement>();
if (dragonMovement)
{
dragonMovement.ClearTrail();
}
}
// Update is called once per frame
void Update()
{
@ -28,13 +19,11 @@ public class Wraparound : MonoBehaviour
if (this.transform.position.y < 0)
{
this.transform.position = new Vector3(transform.position.x, transform.position.y + SCREEN_HEIGHT, transform.position.z);
ClearTrail();
}
if (this.transform.position.y > SCREEN_HEIGHT)
{
this.transform.position = new Vector3(transform.position.x, transform.position.y - SCREEN_HEIGHT, transform.position.z);
ClearTrail();
}
if (_justVertical == false)

Loading…
Cancel
Save