This commit is contained in:
2023-02-13 12:21:38 +05:30
parent b72a198547
commit 557b009b72
7536 changed files with 4110476 additions and 650 deletions

View File

@@ -17,7 +17,7 @@ public class Drawer : MonoBehaviour
public Slider drawingFuel;
public float drawingFuelConsumption = 0.05f;
// public LayerMask drawMask;
bool dragging = false;
public void OnMouseDown(BaseEventData e){
if (drawn) { return; }
@@ -28,8 +28,6 @@ public class Drawer : MonoBehaviour
lineRenderer.SetPositions(new Vector3[0]);
points = new List<Vector3>();
drawn = true;
GameManager.StartGame();
// lineRenderer.transform.position = new Vector3(0, 0, 10);
//lineRenderer.GetComponent<Rigidbody2D>().simulated = false;
@@ -39,16 +37,24 @@ public class Drawer : MonoBehaviour
Vector3 startedPoint = new Vector3();
public void OnMouseDrag(BaseEventData e) {
if(gameStarted){return;}
if(drawingFuel.value <= 0){return;}
PointerEventData ped = (PointerEventData) e as PointerEventData;
Vector3 worldPos = Camera.main.ScreenToWorldPoint(ped.position);
if(points.Count > 3 && !drawn){
drawn = true;
GameManager.StartGame();
}
if(points.Count> 0) {
RaycastHit2D hit = Physics2D.Linecast(points[points.Count - 1], worldPos);
if (hit.collider != null)
{
return;
}
}
points.Add(worldPos);
UpdateLine();
@@ -58,7 +64,10 @@ public class Drawer : MonoBehaviour
public void OnMouseUp(BaseEventData e)
{
dragging= false;
if(points.Count <= 3){return;}
FinishDrawing();
}
@@ -72,8 +81,11 @@ public class Drawer : MonoBehaviour
}
bool drawn = false;
bool gameStarted = false;
void FinishDrawing()
{
gameStarted = true;
List<Vector2> points3 = new List<Vector2>();
foreach(Vector2 point in points)
{
@@ -86,7 +98,7 @@ public class Drawer : MonoBehaviour
//edgeCollider2D.SetPoints(points3);
edgeCollider2D.SetPath(0, points3);
edgeCollider2D.GetComponent<Rigidbody2D>().simulated = true;
GameManager.Player.GetComponent<Rigidbody2D>().simulated=true;
GameManager.Player.GetComponent<Rigidbody2D>().isKinematic=false;
}

View File

@@ -6,9 +6,9 @@ public class Enemy : MonoBehaviour
{
public float moveSpeed = 0.1f;
public bool canSeePlayer = false;
public float distanceThreshold = 0.1f;
public float playerDistanceThreshold = 0.1f;
public float dodgeTime = 0.2f;
float distanceThreshold = 0.45f;
float playerDistanceThreshold = 1f;
float dodgeTime = 0.25f;
float dodgeTimer = 0;
public LayerMask linecastLayer;
float offset;
@@ -25,9 +25,6 @@ public class Enemy : MonoBehaviour
{
if (GameManager.Player == null) { return; }
RaycastHit2D hit = Physics2D.Linecast(transform.position, GameManager.Player.position, linecastLayer);
if (hit.collider == null) {
canSeePlayer = true;
@@ -39,7 +36,7 @@ public class Enemy : MonoBehaviour
{
canSeePlayer = false;
float distanceToBarrier = Vector2.Distance(transform.position, hit.point);
if (distanceToBarrier < distanceThreshold)
if (distanceToBarrier < distanceThreshold && distanceToBarrier > 0.001f)
{
dodgeTimer = 0;
}
@@ -61,19 +58,36 @@ public class Enemy : MonoBehaviour
if (dodgeTimer < dodgeTime)
{
dodgeTimer += Time.deltaTime;
if(!attacked){
Drawer.instance.lineRenderer.GetComponent<Rigidbody2D>().AddForce(((Vector2)transform.position- hit.point) * -attackForce);
attacked=true;
}
if (dodgeTimer > dodgeTime/100f || true)
{
debugColor = Color.red;
Vector3 new_direction = (hit.point - (Vector2)transform.position).normalized;
transform.Translate(-new_direction * moveSpeed * 1.2f, Space.World);
Vector3 newPos = transform.position + (-new_direction * moveSpeed);
RaycastHit2D hitBack = Physics2D.Linecast(transform.position, newPos, linecastLayer);
if(hitBack.collider != null){
return;
}
transform.Translate(-new_direction * moveSpeed * 0.5f, Space.World);
return;
}
}
attacked=false;
transform.Translate(direction * moveSpeed, Space.World);
debugColor = Color.white;
}
bool attacked =false;
float attackForce =50;
}

View File

@@ -50,20 +50,34 @@ public class GameManager : MonoBehaviour
beesReleased = true;
ReleaseTheBees();
}
SetFace(0);
foreach(GameObject bee in bees){
if(Vector2.Distance(player.position, bee.transform.position) < 2.5f){
SetFace(1);
}
}
timerTxt.text = (game_end_timer - t).ToString("n0");
}else{
StopTheBees();
GameWon();
SetFace(0);
}
}
async void ReleaseTheBees()
void ReleaseTheBees()
{
StartCoroutine(releaseTheBees());
}
IEnumerator releaseTheBees(){
foreach(GameObject enemy in bees)
{
enemy.SetActive(true);
await Task.Delay(200);
// await Task.Delay(200);
yield return new WaitForSeconds(0.2f);
}
}
@@ -80,9 +94,17 @@ public class GameManager : MonoBehaviour
instance.gameOverPanel.SetActive(true);
instance.gameStarted = false;
SetFace(2);
// instance.player.GetComponent<SpriteRenderer>().sprite = instance.sadFace;
}
public static void SetFace(int index){
instance.player.GetChild(0).gameObject.SetActive(0 == index);
instance.player.GetChild(1).gameObject.SetActive(1 == index);
instance.player.GetChild(2).gameObject.SetActive(2 == index);
}
public static void GameWon(){
instance.gameStarted = false;
instance.gameWonPanel.SetActive(true);
@@ -120,6 +142,7 @@ public class GameManager : MonoBehaviour
}
public void BackToMenu(){
Debug.Log("Loading menu");
SceneManager.LoadScene(0);
}
}