Skip to content
Snippets Groups Projects

Added close to complete skeleton boss

Merged Alexander Gatland requested to merge alexander into main
24 files
+ 2591
0
Compare changes
  • Side-by-side
  • Inline
Files
24
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System;
namespace BigSock {
public partial class SkeletonBossController : EnemyController {
protected EmptyCollider chargeCollider;
public SkeletonBossState State { get; protected set; } = SkeletonBossState.Idle;
protected bool isInCharge = false;
protected DateTime timer = DateTime.Now;
protected DateTime nextChargeTime = DateTime.Now;
protected static readonly TimeSpan CHARGE_COOLDOWN = new TimeSpan(0, 0, 0, 5, 0);
protected static readonly TimeSpan CHARGE_WAIT_TIME = new TimeSpan(0, 0, 0, 0, 25);
protected static readonly TimeSpan SECOND_CHARGE_WAIT_TIME = new TimeSpan(0, 0, 0, 0, 800);
protected static readonly TimeSpan FINISH_CHARGE_WAIT_TIME = new TimeSpan(0, 0, 0, 0, 450);
public double LeapForce => MovementSpeed*8;
protected override void Start() {
base.Start();
chargeCollider = transform.Find("ChargeCollider").GetComponent<EmptyCollider>();
chargeCollider.OnColliderEnter2D_Action += Charge_OnColliderEnter2D;
chargeCollider.OnColliderStay2D_Action += Charge_OnColliderStay2D;
chargeCollider.OnColliderExit2D_Action += Charge_OnColliderExit2D;
}
protected override void Update() {
Regenerate();
if (target != null && (State == SkeletonBossState.Idle || State == SkeletonBossState.Walking)){
/* //walk
float step = speed * Time.deltaTime;
transform.position = Vector2.MoveTowards(transform.position, target.position, step);
//distance = Vector3.Distance (transform.position, target.position);
//roter
RotateAnimation();
*/
var movement = (new Vector2(target.position.x, target.position.y) - rb.position).normalized;
TryMove(movement);
RotateAnimation(movement);
}
else if (State == SkeletonBossState.Charge && DateTime.Now >= timer) {
var pos = target.position; //target.position;
var temp = (pos - rb.transform.position);
temp.z = 0;
var direction = temp.normalized;
//rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse);
Charge(direction, LeapForce);
timer = DateTime.Now + SECOND_CHARGE_WAIT_TIME;
State = SkeletonBossState.SecondCharge;
}
else if (State == SkeletonBossState.SecondCharge && DateTime.Now >= timer) {
var pos = target.position; //target.position;
var temp = (pos - rb.transform.position);
temp.z = 0;
var direction = temp.normalized;
//rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse);
Charge(direction, LeapForce*2);
timer = DateTime.Now + FINISH_CHARGE_WAIT_TIME;
State = SkeletonBossState.FinishAttack;
}
else if (State == SkeletonBossState.FinishAttack && DateTime.Now >= timer) {
State = SkeletonBossState.Walking;
m_Animator.SetTrigger("walk");
}
}
protected virtual bool Charge(Vector2 direction, double leapForce) {
if(direction != Vector2.zero) {
rb.AddForce((float) leapForce * direction, ForceMode2D.Impulse);
return true;
}
return false;
}
}
/*
Attack
*/
public partial class SkeletonBossController {
protected virtual void Charge_OnColliderEnter2D(Collider2D other) {
if (other.gameObject.tag == "Player") isInCharge = !isInCharge;
}
protected virtual void Charge_OnColliderStay2D(Collider2D other) {
var player = other.gameObject.GetComponent<PlayerController>();
if(player != null) {
if (DateTime.Now >= nextChargeTime) {
m_Animator.SetTrigger("attack");
timer = DateTime.Now + CHARGE_WAIT_TIME;
State = SkeletonBossState.Charge;
nextChargeTime = DateTime.Now + CHARGE_COOLDOWN;
}
}
}
protected virtual void Charge_OnColliderExit2D(Collider2D other) {
if (other.gameObject.tag == "Player") isInCharge = !isInCharge;
//State = SkeletonBossState.Walking;
}
}
public partial class SkeletonBossController {
protected override void Move_OnColliderEnter2D(Collider2D other) {
//Debug.Log("enter");
if (other.gameObject.tag == "Player" && State != SkeletonBossState.Charge && State != SkeletonBossState.SecondCharge && State != SkeletonBossState.FinishAttack){
//Debug.Log("enter if");
m_Animator.SetTrigger("walk");
target = other.transform;
}
}
protected override void Move_OnColliderExit2D(Collider2D other) {
if (other.gameObject.tag == "Player"){
m_Animator.SetTrigger("idle");
target = other.transform;
target = null;
}
}
}
public partial class SkeletonBossController {
}
/*
The different states the slime can be in.
*/
public enum SkeletonBossState {
Idle, Walking, Attacking, Charge, SecondCharge, FinishAttack, Death
}
}
Loading