2019-04-27 14:40:09 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
2019-04-29 19:53:45 +02:00
|
|
|
|
using UnityEngine.SceneManagement;
|
2019-04-27 14:40:09 +02:00
|
|
|
|
|
2019-04-28 16:28:31 +02:00
|
|
|
|
public enum ControlMode {
|
|
|
|
|
Move,
|
|
|
|
|
Attack
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 16:34:50 +02:00
|
|
|
|
public class EntityPlayer : Entity
|
2019-04-27 14:40:09 +02:00
|
|
|
|
{
|
2019-04-28 16:28:31 +02:00
|
|
|
|
protected ControlMode controlMode;
|
2019-04-28 18:12:27 +02:00
|
|
|
|
protected Animator animator;
|
2019-04-28 16:28:31 +02:00
|
|
|
|
|
|
|
|
|
protected override void Start() {
|
|
|
|
|
base.Start();
|
2019-04-28 18:12:27 +02:00
|
|
|
|
animator = GetComponent<Animator>();
|
2019-04-28 16:28:31 +02:00
|
|
|
|
controlMode = ControlMode.Move;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void Update()
|
2019-04-27 14:40:09 +02:00
|
|
|
|
{
|
2019-04-28 16:28:31 +02:00
|
|
|
|
CheckForControlModeChange();
|
|
|
|
|
if(controlMode == ControlMode.Move) CheckForMovementInput();
|
2019-04-29 19:53:45 +02:00
|
|
|
|
if(controlMode == ControlMode.Attack) CheckForAttackInput();
|
|
|
|
|
CheckForTurnSkipInput();
|
2019-04-28 16:28:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void CheckForControlModeChange() {
|
|
|
|
|
if(Input.GetKeyDown(KeyCode.Escape)) {
|
|
|
|
|
controlMode = ControlMode.Move;
|
|
|
|
|
messageBar.Write("Control mode: Move", Color.cyan);
|
2019-04-28 18:45:59 +02:00
|
|
|
|
animator.SetBool("IsWalking", true);
|
2019-04-28 16:28:31 +02:00
|
|
|
|
}
|
|
|
|
|
if(Input.GetKeyDown(KeyCode.A)) {
|
|
|
|
|
controlMode = ControlMode.Attack;
|
|
|
|
|
messageBar.Write("Control mode: Attack", Color.cyan);
|
2019-04-28 18:45:59 +02:00
|
|
|
|
animator.SetBool("IsWalking", false);
|
2019-04-28 16:28:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void CheckForAttackInput() {
|
|
|
|
|
bool hasAttacked = false;
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.LeftArrow))
|
|
|
|
|
{
|
|
|
|
|
hasAttacked = GetComponent<PlayerAttack>().Attack(MapPosition + Vector2Int.left);
|
2019-04-28 18:12:27 +02:00
|
|
|
|
spriteRenderer.flipX = true;
|
2019-04-28 16:28:31 +02:00
|
|
|
|
}
|
|
|
|
|
else if (Input.GetKeyDown(KeyCode.RightArrow))
|
|
|
|
|
{
|
|
|
|
|
hasAttacked = GetComponent<PlayerAttack>().Attack(MapPosition + Vector2Int.right);
|
2019-04-28 18:12:27 +02:00
|
|
|
|
spriteRenderer.flipX = false;
|
2019-04-28 16:28:31 +02:00
|
|
|
|
}
|
|
|
|
|
else if (Input.GetKeyDown(KeyCode.UpArrow))
|
|
|
|
|
{
|
|
|
|
|
hasAttacked = GetComponent<PlayerAttack>().Attack(MapPosition + Vector2Int.up);
|
|
|
|
|
}
|
|
|
|
|
else if (Input.GetKeyDown(KeyCode.DownArrow))
|
|
|
|
|
{
|
|
|
|
|
hasAttacked = GetComponent<PlayerAttack>().Attack(MapPosition + Vector2Int.down);
|
|
|
|
|
}
|
|
|
|
|
if(hasAttacked) {
|
|
|
|
|
//Turn happens!
|
|
|
|
|
turnHandler.OnTurn();
|
|
|
|
|
}
|
2019-04-27 14:40:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 16:28:31 +02:00
|
|
|
|
protected void CheckForMovementInput()
|
2019-04-27 14:40:09 +02:00
|
|
|
|
{
|
2019-04-27 17:28:38 +02:00
|
|
|
|
bool hasMoved = false;
|
2019-04-28 16:28:31 +02:00
|
|
|
|
if (Input.GetKeyDown(KeyCode.LeftArrow))
|
2019-04-27 14:40:09 +02:00
|
|
|
|
{
|
2019-04-27 22:19:35 +02:00
|
|
|
|
if (map.CanMoveTo(MapPosition + Vector2Int.left)) {
|
2019-04-27 17:57:01 +02:00
|
|
|
|
transform.Translate(Vector3.left);
|
|
|
|
|
hasMoved = true;
|
2019-04-28 18:12:27 +02:00
|
|
|
|
spriteRenderer.flipX = true;
|
2019-04-27 17:57:01 +02:00
|
|
|
|
}
|
2019-04-27 14:40:09 +02:00
|
|
|
|
}
|
2019-04-28 16:28:31 +02:00
|
|
|
|
else if (Input.GetKeyDown(KeyCode.RightArrow))
|
2019-04-27 14:40:09 +02:00
|
|
|
|
{
|
2019-04-27 22:19:35 +02:00
|
|
|
|
if (map.CanMoveTo(MapPosition + Vector2Int.right)) {
|
2019-04-27 17:28:38 +02:00
|
|
|
|
transform.Translate(Vector3.right);
|
2019-04-27 17:57:01 +02:00
|
|
|
|
hasMoved = true;
|
2019-04-28 18:12:27 +02:00
|
|
|
|
spriteRenderer.flipX = false;
|
2019-04-27 17:28:38 +02:00
|
|
|
|
}
|
2019-04-27 14:40:09 +02:00
|
|
|
|
}
|
2019-04-28 16:28:31 +02:00
|
|
|
|
else if (Input.GetKeyDown(KeyCode.UpArrow))
|
2019-04-27 14:40:09 +02:00
|
|
|
|
{
|
2019-04-27 22:19:35 +02:00
|
|
|
|
if (map.CanMoveTo(MapPosition + Vector2Int.up)) {
|
2019-04-27 17:28:38 +02:00
|
|
|
|
transform.Translate(Vector3.up);
|
2019-04-27 17:57:01 +02:00
|
|
|
|
hasMoved = true;
|
2019-04-27 17:28:38 +02:00
|
|
|
|
}
|
2019-04-27 14:40:09 +02:00
|
|
|
|
}
|
2019-04-28 16:28:31 +02:00
|
|
|
|
else if (Input.GetKeyDown(KeyCode.DownArrow))
|
2019-04-27 14:40:09 +02:00
|
|
|
|
{
|
2019-04-27 22:19:35 +02:00
|
|
|
|
if (map.CanMoveTo(MapPosition + Vector2Int.down)) {
|
2019-04-27 17:28:38 +02:00
|
|
|
|
transform.Translate(Vector3.down);
|
2019-04-27 17:57:01 +02:00
|
|
|
|
hasMoved = true;
|
2019-04-27 17:28:38 +02:00
|
|
|
|
}
|
2019-04-27 14:40:09 +02:00
|
|
|
|
}
|
2019-04-27 17:57:01 +02:00
|
|
|
|
if(hasMoved) {
|
2019-04-28 14:11:21 +02:00
|
|
|
|
//Check for pickuppable items
|
2019-04-28 16:28:31 +02:00
|
|
|
|
List<Entity> entities = turnHandler.GetEntitiesAtPosition(MapPosition);
|
2019-04-28 14:11:21 +02:00
|
|
|
|
foreach(Entity entity in entities) {
|
2019-04-28 16:34:50 +02:00
|
|
|
|
if(entity is EntityItem) {
|
|
|
|
|
EntityItem item = entity as EntityItem;
|
2019-04-28 14:11:21 +02:00
|
|
|
|
item.OnPickup(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Turn happens!
|
2019-04-27 22:19:35 +02:00
|
|
|
|
turnHandler.OnTurn();
|
2019-04-27 17:57:01 +02:00
|
|
|
|
}
|
2019-04-27 14:40:09 +02:00
|
|
|
|
}
|
2019-04-29 15:27:26 +02:00
|
|
|
|
|
2019-04-29 19:53:45 +02:00
|
|
|
|
protected void CheckForTurnSkipInput() {
|
|
|
|
|
if(Input.GetKeyDown(KeyCode.Space)) {
|
|
|
|
|
messageBar.Write("Skipped turn.", Color.cyan);
|
|
|
|
|
turnHandler.OnTurn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//This is not an error wtf
|
2019-04-29 15:31:08 +02:00
|
|
|
|
public override void OnNewLevel() {}
|
2019-04-29 19:53:45 +02:00
|
|
|
|
|
|
|
|
|
public override void Die() {
|
|
|
|
|
SceneManager.LoadScene("Dead", LoadSceneMode.Single);
|
|
|
|
|
}
|
2019-04-27 14:40:09 +02:00
|
|
|
|
}
|