Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Final Push
Push
  • Loading branch information
aps16104 committed May 6, 2020
1 parent e483df3 commit 07bb02f
Show file tree
Hide file tree
Showing 49 changed files with 61 additions and 100 deletions.
4 changes: 4 additions & 0 deletions Platformer/Assets/Boss_Run.cs
Expand Up @@ -4,17 +4,21 @@ using UnityEngine;

public class Boss_Run : StateMachineBehaviour
{
//state machine behavior takes from animations states

//speed and range of the circle
public float speed = 2.5f;
public float attackRange = 1f;

refernces
Transform player;
Rigidbody2D rb;
Boss boss;

// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{

speed = (Random.Range(2f, 4f));

player = GameObject.FindGameObjectWithTag("Player").transform;
Expand Down
12 changes: 12 additions & 0 deletions Platformer/Assets/Enemy2.cs
Expand Up @@ -5,19 +5,24 @@ using UnityEngine.UI;

public class Enemy2 : MonoBehaviour
{
//Basically the same script as the other enemies

//Health
public float maxHealth = 75; //health
public float currentHealth;

//Health bar UI
public GameObject healthBarUI;
public Slider slider;
public GameObject enemie;
public Transform ghost;

//not used
public int Shurikendamage = 10;

public GameObject score; //shuriken

//references
public GameObject bullet;
public Transform shotSpawn;
public float fireRate;
Expand All @@ -27,6 +32,7 @@ public class Enemy2 : MonoBehaviour

void Start()
{
//ghost position there so it can drop score there
currentHealth = maxHealth;
slider.value = CalculateHealth();
ghost.position = new Vector3(ghost.position.x, ghost.position.y, ghost.position.z);
Expand All @@ -37,6 +43,7 @@ public class Enemy2 : MonoBehaviour

void Update()
{
//failed attempt at healthbar being inactive on start
slider.value = CalculateHealth();

if (currentHealth < maxHealth)
Expand All @@ -49,6 +56,8 @@ public class Enemy2 : MonoBehaviour

}

//can he fire

void CheckIfTimeToFire()
{
if (Time.time > nextFire)
Expand All @@ -58,6 +67,7 @@ public class Enemy2 : MonoBehaviour
}
}

//take damage function
public void TakeDamage(int damage)
{
healthBarUI.SetActive(true);
Expand All @@ -80,6 +90,8 @@ public class Enemy2 : MonoBehaviour
Destroy(enemie);
}

//collide with bullet

private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Bullet"))
Expand Down
27 changes: 22 additions & 5 deletions Platformer/Assets/Scripts/PlatformController.cs
Expand Up @@ -4,29 +4,34 @@ using System.Collections.Generic;

public class PlatformController : RaycastController
{

//what layer to intereact with
public LayerMask passengerMask;

//way points to move to
public Vector3[] localWaypoints;
Vector3[] globalWaypoints;

//Basic data for the moving platform
public float speed;
public bool cyclic;
public float waitTime;
[Range(0, 2)]
public float easeAmount;

//to calculate speed and move time
int fromWaypointIndex;
float percentBetweenWaypoints;
float nextMoveTime;

List<PassengerMovement> passengerMovement;
Dictionary<Transform, Controller2D> passengerDictionary = new Dictionary<Transform, Controller2D>();

//ovveride raycast controller start
public override void Start()
{
base.Start();

//waypoint setup
globalWaypoints = new Vector3[localWaypoints.Length];
for (int i = 0; i < localWaypoints.Length; i++)
{
Expand All @@ -36,9 +41,9 @@ public class PlatformController : RaycastController

void Update()
{

//call updateraycast origins
UpdateRaycastOrigins();

//velocity of platform
Vector3 velocity = CalculatePlatformMovement();

CalculatePassengerMovement(velocity);
Expand All @@ -48,34 +53,42 @@ public class PlatformController : RaycastController
MovePassengers(false);
}

//platform slowing down aka ease
float Ease(float x)
{
float a = easeAmount + 1;
return Mathf.Pow(x, a) / (Mathf.Pow(x, a) + Mathf.Pow(1 - x, a));
}

//calculate movement of the platform
Vector3 CalculatePlatformMovement()
{

//dont move
if (Time.time < nextMoveTime)
{
return Vector3.zero;
}

//Calculating the next movement
fromWaypointIndex %= globalWaypoints.Length;
int toWaypointIndex = (fromWaypointIndex + 1) % globalWaypoints.Length;
//distance between points, references global waypoints
float distanceBetweenWaypoints = Vector3.Distance(globalWaypoints[fromWaypointIndex], globalWaypoints[toWaypointIndex]);
percentBetweenWaypoints += Time.deltaTime * speed / distanceBetweenWaypoints;
percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints);
//eased oercentage
float easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints);

//Lerp, which you talked about in class before
Vector3 newPos = Vector3.Lerp(globalWaypoints[fromWaypointIndex], globalWaypoints[toWaypointIndex], easedPercentBetweenWaypoints);

//if its more than 1% between waypoints
if (percentBetweenWaypoints >= 1)
{
percentBetweenWaypoints = 0;
fromWaypointIndex++;

//if it goes in a cyclic nature
if (!cyclic)
{
if (fromWaypointIndex >= globalWaypoints.Length - 1)
Expand All @@ -90,6 +103,7 @@ public class PlatformController : RaycastController
return newPos - transform.position;
}

//move the passangers before the platform moves
void MovePassengers(bool beforeMovePlatform)
{
foreach (PassengerMovement passenger in passengerMovement)
Expand All @@ -106,6 +120,7 @@ public class PlatformController : RaycastController
}
}

//calculate how fast to move passanger before platform
void CalculatePassengerMovement(Vector3 velocity)
{
HashSet<Transform> movedPassengers = new HashSet<Transform>();
Expand Down Expand Up @@ -189,6 +204,8 @@ public class PlatformController : RaycastController
}
}

//struct to keep some variables as well as passenger movement

struct PassengerMovement
{
public Transform transform;
Expand All @@ -205,7 +222,7 @@ public class PlatformController : RaycastController
}
}

//Draw the little crosses so we can see
//Draw the little crosses so we can see, aka the waypoints
void OnDrawGizmos()
{
if (localWaypoints != null)
Expand Down
7 changes: 7 additions & 0 deletions Platformer/Assets/Scripts/Player&Enemy/Boss.cs
Expand Up @@ -43,19 +43,24 @@ public class Boss : MonoBehaviour


}

//this way the sprite is alwyas facing the correct direction
public void LookAtPlayer()
{
//ysed local scale
Vector3 flipped = transform.localScale;
flipped.z *= -1f;

if (transform.position.x > player.position.x && isFlipped)
{
//not flipped
transform.localScale = flipped;
transform.Rotate(0f, 180f, 0f);
isFlipped = false;
}
else if (transform.position.x < player.position.x && !isFlipped)
{
//flipped
transform.localScale = flipped;
transform.Rotate(0f, 180f, 0f);
isFlipped = true;
Expand All @@ -78,6 +83,7 @@ public class Boss : MonoBehaviour
}
if (currentHealth <= 0)
{
//drop score and key
Instantiate(key, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Expand All @@ -99,6 +105,7 @@ public class Boss : MonoBehaviour

}

//if hi tby bullet
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Bullet"))
Expand Down
4 changes: 4 additions & 0 deletions Platformer/Assets/Scripts/Player&Enemy/BossWeapon.cs
Expand Up @@ -4,6 +4,7 @@ using UnityEngine;

public class BossWeapon : MonoBehaviour
{
//same as user weapon really, enraged attack just makes faster
public int attackDamage = 20;
public int enragedAttackDamage = 40;

Expand All @@ -13,6 +14,7 @@ public class BossWeapon : MonoBehaviour

public void Attack()
{
//attack circle
Vector3 pos = transform.position;
pos += transform.right * attackOffset.x;
pos += transform.up * attackOffset.y;
Expand All @@ -24,6 +26,7 @@ public class BossWeapon : MonoBehaviour
}
}

//same as attack up their but animated more often
public void EnragedAttack()
{
Vector3 pos = transform.position;
Expand All @@ -37,6 +40,7 @@ public class BossWeapon : MonoBehaviour
}
}

//draw circle in scene view
void OnDrawGizmosSelected()
{
Vector3 pos = transform.position;
Expand Down
1 change: 1 addition & 0 deletions Platformer/Assets/Scripts/Player&Enemy/Enemy.cs
Expand Up @@ -5,6 +5,7 @@ using UnityEngine.UI;

public class Enemy : MonoBehaviour
{
//Used this script for most of the enemies, all the basics really. animation, health and UI health bar which was commented out in Enemy2

public Animator animator;
public float maxHealth = 75; //health
Expand Down
1 change: 1 addition & 0 deletions Platformer/Assets/Scripts/Player&Enemy/EnemyPatrol.cs
Expand Up @@ -9,6 +9,7 @@ public class EnemyPatrol : MonoBehaviour
public GameObject Ghost;
public SpriteRenderer mySpriteRenderer;

//Initialize RG and randomize speed, reference sprite renderer so
void Start()
{
speed = (Random.Range(1f, 1.5f));
Expand Down
11 changes: 5 additions & 6 deletions Platformer/Assets/Scripts/Player&Enemy/Spawner1.cs
Expand Up @@ -4,25 +4,29 @@ using UnityEngine;

public class Spawner1 : MonoBehaviour
{
//spawner from spaceshooter

public GameObject hazard;
public int hazardCount;
public float spawnWait;
public float startWait;
public float waveWait;
public Transform spawnhere;


//start the courotine right away
void Start()
{
StartCoroutine(SpawnWaves());
}

//start spawning
IEnumerator SpawnWaves()
{
yield return new WaitForSeconds(startWait);

while (true)
{
//setup to handle multiple enemies
for (int i = 0; i < hazardCount; i++)
{
//First Enemy
Expand Down Expand Up @@ -51,9 +55,4 @@ public class Spawner1 : MonoBehaviour
}
}

//By level Enemy Updating
void Update()
{

}
}
2 changes: 1 addition & 1 deletion Platformer/Assets/_Scenes/Level1.unity
Expand Up @@ -1016705,7 +1016705,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1684384561}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 594.72, y: 74.72, z: 0}
m_LocalPosition: {x: 594.72, y: 74.75, z: 0}
m_LocalScale: {x: 0.15, y: 0.15, z: 1}
m_Children:
- {fileID: 18796688}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
13 changes: 0 additions & 13 deletions Platformer/Builds/Final-Playtest2/Build/Final-Playtest2.json

This file was deleted.

Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions Platformer/Builds/Final-Playtest2/Build/UnityLoader.js

This file was deleted.

24 changes: 0 additions & 24 deletions Platformer/Builds/Final-Playtest2/TemplateData/UnityProgress.js

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 07bb02f

Please sign in to comment.