blob: 0973c5acebba555f4321d39de239b43f1282208d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
using MontanaJohns.Core.Interfaces;
using MontanaJohns.Items;
using UnityEngine;
using UnityEngine.InputSystem;
namespace MontanaJohns.Actors
{
[RequireComponent(typeof(Rigidbody2D))]
public class Player : Actor, IFollowable
{
public Transform ActorTransform => _transform;
public Camera MainCamera => _camera;
public GameObject projectilePrefab;
public Transform firePoint;
public Vector3 spawnPoint;
private Camera _camera;
private PlayerInput playerInput;
private InputAction use, move, jump, attack, cancel;
protected override void Awake()
{
base.Awake();
_camera = FindObjectOfType<Camera>();
playerInput = GetComponent<PlayerInput>();
use = move = jump = attack = cancel = null;
move = playerInput.currentActionMap.FindAction("Move");
jump = playerInput.currentActionMap.FindAction("Jump");
attack = playerInput.currentActionMap.FindAction("Attack");
use = playerInput.currentActionMap.FindAction("Use");
cancel = playerInput.currentActionMap.FindAction("Cancel");
jump.started += context => Jump();
use.started += context => Use();
//attack.started += context => Fire();
cancel.started += context => Cancel();
}
protected override void Start()
{
base.Start();
GameObject loadedItem = (GameObject)Instantiate(Resources.Load("ActiveItems/Whip"));
activeItem = loadedItem.GetComponent<Whip>();
ResetStats();
spawnPoint = transform.position;
}
protected void Update()
{
((IFollowable)this).Follow();
if(isGrappling)
{
base.Grapple(move.ReadValue<Vector2>().x, move.ReadValue<Vector2>().y, (Vector2)grapplePoint);
}
else
{
base.Move(move.ReadValue<Vector2>().x);
if (isMoving && !_animator.GetBool("airborn") && !_audio.isPlaying("RunningOnGrass")) _audio.Play("RunningOnGrass");
else if (!isMoving || _animator.GetBool("airborn")) _audio.Stop("RunningOnGrass");
}
DeathCheck();
}
protected void DeathCheck()
{
if(health <= 0)
{
MainCamera.GetComponent<LevelController>().ResetLevel();
if (isGrappling)
Use();
ResetStats();
health = stats.maxHealth;
transform.position = spawnPoint;
}
}
protected void ResetStats()
{
stats = baseStats + activeItem.stats;
}
protected void Fire()
{
Instantiate(projectilePrefab, firePoint.position, firePoint.rotation);
_audio.Play("Gunshot");
}
}
}
|