-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class MonsterCarDamage : MonoBehaviour | ||
{ | ||
public void OnCollisionEnter2D(Collision2D other) //if we collide with police car | ||
{ | ||
if (other.gameObject.tag == "Player") | ||
{ | ||
MonsterCarHealthManager.instance.DamageMonsterCar(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class MonsterCarHealthManager : MonoBehaviour | ||
{ | ||
|
||
public static MonsterCarHealthManager instance; | ||
public int currentHealth; | ||
public int maxHealth; | ||
public GameObject explosion; | ||
public AudioSource carExplosion; | ||
public void Awake() | ||
{ | ||
instance = this; | ||
} | ||
private void Start() | ||
{ | ||
currentHealth = maxHealth; | ||
} | ||
public void DamageMonsterCar() | ||
{ | ||
currentHealth--; | ||
if (currentHealth <= 0) | ||
{ | ||
Instantiate(explosion, transform.position, transform.rotation); | ||
gameObject.SetActive(false); | ||
carExplosion.Play(); | ||
GameManager.instance.KillMonsterCar(); | ||
} | ||
} | ||
public void Respawn() | ||
{ | ||
gameObject.SetActive(true); | ||
currentHealth = maxHealth + 1; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class AICars : MonoBehaviour | ||
{ | ||
public float accelerator; | ||
public float turnpower = 1; | ||
public float turnspeed = 4; | ||
Rigidbody2D rb; | ||
internal bool isAIMovement; | ||
private float friction = 1.5f; | ||
private float currentSpeed; | ||
private Vector2 curSpeed; | ||
float currentAcc; | ||
private bool isMoving; | ||
|
||
public AudioSource engine; | ||
public float maxEngineSound; | ||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
rb = GetComponent<Rigidbody2D>(); | ||
currentAcc = accelerator; | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (engine != null) | ||
{ | ||
engine.pitch=1f+((rb.velocity.magnitude / maxEngineSound) * 3f) ; | ||
} | ||
} | ||
|
||
// Update is called once per frame | ||
void FixedUpdate() | ||
{ | ||
if (isMoving) | ||
{ | ||
rb.AddForce(transform.up * currentAcc); | ||
} | ||
if (!isMoving) | ||
{ | ||
rb.drag = friction * 2; | ||
} | ||
} | ||
|
||
public void Movement(string turning,bool isPaddlePressed) | ||
{ | ||
if (turning == "left") | ||
{ | ||
transform.Rotate(Vector3.forward * (currentSpeed + currentSpeed)); | ||
} | ||
else if (turning == "right") | ||
{ | ||
transform.Rotate(Vector3.forward * -(currentSpeed + currentSpeed)); | ||
} | ||
if (isPaddlePressed) | ||
{ | ||
isMoving = true; | ||
} | ||
|
||
currentSpeed = curSpeed.magnitude / turnspeed; | ||
curSpeed = new Vector2(rb.velocity.x, rb.velocity.y); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class AIMovement : MonoBehaviour | ||
{ | ||
List<GameObject> routes; | ||
private Vector3 nextPoint; | ||
public GameObject AIPathHolder; | ||
private bool isAccPressed = false; | ||
AICars driver; | ||
int totalWayPoints; | ||
int currentIndex; | ||
private bool nextPos; | ||
private string turning; | ||
AIPathway wayPoint; | ||
internal Transform currentWayPoint; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
driver = GetComponent<AICars>(); | ||
if (AIPathHolder != null) | ||
{ | ||
driver.isAIMovement = true; | ||
wayPoint = AIPathHolder.GetComponent<AIPathway>(); | ||
routes = wayPoint.route; | ||
currentIndex = 0; | ||
totalWayPoints = routes.Count; | ||
currentWayPoint = routes[0].transform; | ||
} | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
if (!nextPos) | ||
{ | ||
nextPoint = currentWayPoint.position; | ||
nextPos = true; | ||
} | ||
Vector3 relativeVector = transform.InverseTransformPoint(nextPoint); | ||
turning = null; | ||
|
||
if (relativeVector.x > 0.5f) | ||
{ | ||
turning = "right"; | ||
} | ||
else if (relativeVector.x < -0.5f) | ||
{ | ||
turning = "left"; | ||
} | ||
float dist = Vector2.Distance(transform.position, nextPoint); | ||
isAccPressed = true; | ||
if (dist < 2) | ||
{ | ||
currentIndex++; | ||
if (currentIndex >= totalWayPoints) | ||
{ | ||
currentIndex = 0; | ||
} | ||
currentWayPoint = routes[currentIndex].transform; | ||
nextPos = false; | ||
} | ||
} | ||
|
||
private void FixedUpdate() | ||
{ | ||
if (driver.isAIMovement) | ||
{ | ||
driver.Movement(turning, isAccPressed); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
[ExecuteInEditMode] | ||
public class AIPathway : MonoBehaviour | ||
{ | ||
public List<GameObject> route; | ||
public bool drawLine = true; | ||
private void Awake() | ||
{ | ||
if (route == null) | ||
{ | ||
route = new List<GameObject>(); | ||
} | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
#if UNITY_EDITOR | ||
if (!EditorApplication.isPlaying) | ||
{ | ||
if (route == null) | ||
{ | ||
route = new List<GameObject>(); | ||
} | ||
route.Clear(); | ||
foreach (Transform node in transform) | ||
{ | ||
route.Add(node.gameObject); | ||
} | ||
} | ||
if (route != null && route.Count > 1) | ||
{ | ||
if (drawLine)//for checkbox | ||
{ | ||
DrawLine(); | ||
} | ||
} | ||
#endif | ||
} | ||
private void DrawLine() | ||
{ | ||
int index = 0; | ||
Vector3 lastPos = route[index].transform.position; | ||
for (int i = 0; i < route.Count; i++) | ||
{ | ||
Debug.DrawLine(lastPos, route[index].transform.position); | ||
lastPos = route[index].transform.position; | ||
if (index == route.Count - 1) | ||
{ | ||
Debug.DrawLine(lastPos, route[0].transform.position); | ||
} | ||
index++; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
|
||
public class AIVictoryFullMonsterTruck : MonoBehaviour | ||
{ | ||
public int currentLap; | ||
public int maxLap; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
currentLap = maxLap; | ||
} | ||
private void OnTriggerEnter2D(Collider2D other) | ||
{ | ||
if (other.tag == "FullMonsterCar") | ||
{ | ||
currentLap--; | ||
if (currentLap <= 0) | ||
{ | ||
SceneManager.LoadScene("AIVictory"); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.