blob: 1b2155ad3609be5b0ebb132e0bd51cc15ba34dc1 (
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
|
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 Vector3 spawnPoint;
private Camera _camera;
private PlayerInput playerInput;
private InputAction use, move, jump;
protected override void Awake()
{
base.Awake();
_camera = FindObjectOfType<Camera>();
playerInput = GetComponent<PlayerInput>();
move = playerInput.currentActionMap.FindAction("Move");
jump = playerInput.currentActionMap.FindAction("Jump");
use = playerInput.currentActionMap.FindAction("Use");
jump.started += context => Jump();
use.started += context => Use();
}
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);
}
DeathCheck();
}
protected void DeathCheck()
{
if(health <= 0)
{
MainCamera.GetComponent<LevelController>().ResetLevel();
ResetStats();
health = stats.maxHealth;
transform.position = spawnPoint;
}
}
protected void ResetStats()
{
stats = baseStats + activeItem.stats;
}
}
}
|