Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 76 additions & 154 deletions GeckoAndCricket/Assets/Scripts/BaseScripts/BaseCharacter.cs

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions GeckoAndCricket/Assets/Scripts/BaseScripts/BaseWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class BaseWorld : MonoBehaviour
public float gravityMultiplier = 1f;

// Public:
public static BaseWorld World;
public static BaseSurfaceTypes FloorType;
public static BaseSurfaceTypes WallType;
public static GameObject Player;
public static BaseWorld world;
public static BaseSurfaceTypes floorType;
public static BaseSurfaceTypes wallType;
public static GameObject player;

// Private:
private float _gravityScale;
Expand All @@ -34,13 +34,13 @@ public ref float GetGravityScale()

private void Awake()
{
if (World == null)
if (world == null)
{
World = this;
world = this;
}

FloorType ??= new FloorTypes(floorLayers);
WallType ??= new WallTypes(wallLayers);
floorType ??= new FloorTypes(floorLayers);
wallType ??= new WallTypes(wallLayers);

}
}
Expand Down
25 changes: 11 additions & 14 deletions GeckoAndCricket/Assets/Scripts/BulletEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using EnemiesScripts;
using UnityEngine;

Expand All @@ -8,19 +6,18 @@ public class BulletEvent : MonoBehaviour
private void OnTriggerEnter2D(Collider2D collider)
{
Destroy(gameObject);
if (collider.tag == "EnemyWeakPoint")
if (collider.tag != "EnemyWeakPoint") return;

GameObject enemy = collider.transform.parent.gameObject;
if (enemy.GetComponent<BatAI>() == null)
{
GameObject enemy = collider.transform.parent.gameObject;
if (enemy.GetComponent<BatAI>() == null)
{
Debug.Log("Pierwszy if");
Destroy(enemy);
}
else if(!enemy.GetComponent<BatAI>().isImmune)
{
Debug.Log("Drugi if");
Destroy(enemy);
}
//Debug.Log("Pierwszy if");
Destroy(enemy);
}
else if(!enemy.GetComponent<BatAI>().isImmune)
{
//Debug.Log("Drugi if");
Destroy(enemy);
}
}
}
135 changes: 74 additions & 61 deletions GeckoAndCricket/Assets/Scripts/EnemiesScripts/BatAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,102 @@ namespace EnemiesScripts
{
public class BatAI : MonoBehaviour
{
[SerializeField] GameObject path;
private List<Vector3> BatPathPositions = new List<Vector3>();
private int currentPosition;
public bool detectPlayer = false;
PolygonCollider2D batVisionCollider;
public bool isImmune = true;
public static float checkTimer = 3f;
public float currentCheckTimer = checkTimer;
[SerializeField] private GameObject path;

// public variables:
public const float CheckTimer = 3f;
public float currentCheckTimer = CheckTimer;
public float speedTime = 10f;

// public flags:
public bool detectPlayer;
public bool isImmune = true;

// private variables:
private int _currentPosition;

private readonly List<Vector3> _batPathPositions = new List<Vector3>();
private PolygonCollider2D _batVisionCollider;


// Start is called before the first frame update
void Start()
{
batVisionCollider = this.gameObject.transform.GetChild(0).GetComponent<PolygonCollider2D>();
foreach (Transform child in path.transform) {
BatPathPositions.Add(child.position);
}
currentPosition = 0;
transform.position = BatPathPositions[0];

}

// Update is called once per frame
void Update()
#region BatAI
private void CheckTerrain()
{
Attack();
CheckTerrain();
}
void Attack() {
if (detectPlayer)
if (isImmune)
{
batVisionCollider.enabled = false;
isImmune = false;
if (currentPosition == 1)
if (currentCheckTimer <= 0)
{
speedTime = 20f;
_batVisionCollider.enabled = !_batVisionCollider.enabled;
currentCheckTimer = CheckTimer;
}
else
{
speedTime = 10f;
}
if (currentPosition <= 1 && transform.position != BatPathPositions[currentPosition + 1]) {
transform.position = Vector3.MoveTowards(transform.position, BatPathPositions[currentPosition + 1], speedTime * Time.deltaTime);
if (transform.position == BatPathPositions[currentPosition + 1]) {
currentPosition += 1;
}
}
else {
if (transform.position != BatPathPositions[0])
{
transform.position = Vector3.MoveTowards(transform.position, BatPathPositions[0], speedTime * Time.deltaTime);
}
else {
currentPosition = 0;
detectPlayer = false;
isImmune = true;
}
currentCheckTimer -= Time.deltaTime;
}
}
else
{
currentCheckTimer = CheckTimer;
}
}
void CheckTerrain() {
if (isImmune)

private void Attack()
{
if (!detectPlayer) return;

_batVisionCollider.enabled = false;
isImmune = false;

speedTime = _currentPosition == 1 ? 20f : 10f;

if (_currentPosition <= 1 && transform.position != _batPathPositions[_currentPosition + 1])
{
if (currentCheckTimer <= 0)
transform.position = Vector3.MoveTowards(transform.position, _batPathPositions[_currentPosition + 1], speedTime * Time.deltaTime);
if (transform.position == _batPathPositions[_currentPosition + 1])
{
batVisionCollider.enabled = !batVisionCollider.enabled;
currentCheckTimer = checkTimer;
_currentPosition += 1;
}
else
}
else
{
if (transform.position != _batPathPositions[0])
{
currentCheckTimer -= Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, _batPathPositions[0], speedTime * Time.deltaTime);
}
else
{
_currentPosition = 0;
detectPlayer = false;
isImmune = true;
}
}
else {
currentCheckTimer = checkTimer;
}
}
#endregion

#region Unity
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player") {
if (collision.CompareTag("Player"))
{
detectPlayer = true;
}
}

private void Start()
{
_batVisionCollider = gameObject.transform.GetChild(0).GetComponent<PolygonCollider2D>();
foreach (Transform child in path.transform)
_batPathPositions.Add(child.position);

_currentPosition = 0;
transform.position = _batPathPositions[0];

}

private void Update()
{
Attack();
CheckTerrain();
}
#endregion
}
}
139 changes: 75 additions & 64 deletions GeckoAndCricket/Assets/Scripts/EnemiesScripts/FrogAI.cs
Original file line number Diff line number Diff line change
@@ -1,90 +1,101 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BaseScripts;
using BaseScripts.SurfaceTypes;
using PlayerScripts;
using UnityEngine;

public class FrogAI : BaseCharacter
namespace EnemiesScripts
{
private bool mustPatrol;
public bool mustTurn;
public bool grapplingPlayer;
// Start is called before the first frame update
void Start()
{
mustPatrol = true;
grapplingPlayer = false;
}
// Update is called once per frame
void Update()
public class FrogAI : BaseCharacter
{
if (IsTouchingWall && IsGrounded || FloorType == BaseWorld.FloorType.Lava)
// public flags:
public bool mustTurn;
public bool grapplingPlayer;

// private flags:
private bool _mustPatrol;

#region FrogAI
private void Patrol()
{
Flip();
float x = movementSpeed;
float y = Mathf.Abs(jumpForce/2);

if (isGrounded)
Move(ref x, ref y);
}
if (mustPatrol)

private void Attack()
{
Patrol();
}
else {
Attack();
float x = movementSpeed*3;
float y = Mathf.Abs(jumpForce / 1.5f);

if (isGrounded && !grapplingPlayer)
Move(ref x, ref y);
}
}
void Patrol() {
float x = movementSpeed;
float y = Mathf.Abs(jumpForce/2);
if (IsGrounded)
public void Move(float x,float y)
{
Move(x,y);
base.Move(ref x, ref y);
}

}
void Attack() {
float x = movementSpeed*3;
float y = Mathf.Abs(jumpForce / 1.5f);
if (IsGrounded && !grapplingPlayer)
private void Flip()
{
Move(x,y);
_mustPatrol = false;
movementSpeed *= -1;
_mustPatrol = true;
}
}
public void Move(float x,float y){
base.Move(ref x, ref y);
}
void Flip()
{
mustPatrol = false;
movementSpeed *= -1;
mustPatrol = true;
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player")) {
mustPatrol = false;
#endregion

#region Unity
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
_mustPatrol = false;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.CompareTag("Player"))

private void OnTriggerExit2D(Collider2D collision)
{
mustPatrol = true;
if (!collision.CompareTag("Player")) return;

_mustPatrol = true;
grapplingPlayer = false;
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player")) {

private void OnCollisionEnter2D(Collision2D collision)
{
if (!collision.gameObject.CompareTag("Player")) return;

grapplingPlayer = true;
gameObject.GetComponent<BoxCollider2D>().isTrigger = true;
Transform grapple = collision.gameObject.transform.Find("GrapplePosition").transform;
this.transform.parent = grapple;
this.transform.position = grapple.position;
Rigidbody.isKinematic = true;
Rigidbody.velocity = new Vector2(0f, 0f);

Transform frogTransform = transform;

frogTransform.parent = grapple;
frogTransform.position = grapple.position;
characterRigidbody.isKinematic = true;
characterRigidbody.velocity = new Vector2(0f, 0f);
collision.gameObject.GetComponent<Player>().isGrappled = true;
}

private void Start()
{
_mustPatrol = true;
grapplingPlayer = false;
}



private void Update()
{
if (isTouchingWall && isGrounded || floorType == BaseWorld.floorType.Lava)
{
Flip();
}
if (_mustPatrol)
{
Patrol();
}
else {
Attack();
}
}
#endregion
}
}
Loading