]> git.cameronkatri.com Git - gmtk-gamejam.git/blob - Assets/Scripts/Controllers/Player/PlayerSegment.cs
Add VFX
[gmtk-gamejam.git] / Assets / Scripts / Controllers / Player / PlayerSegment.cs
1 using System;
2 using UnityEngine;
3
4 namespace Controllers.Player
5 {
6 [RequireComponent(typeof(Rigidbody2D))]
7 public class PlayerSegment : MonoBehaviour
8 {
9 internal float sensitivity;
10 internal float verticalSensitivity;
11
12 internal bool moveleft;
13 internal bool moveright;
14
15 [Header("Controls")]
16 [SerializeField] public Control left;
17 [SerializeField] public Control right;
18
19 [Header("Settings")]
20 [SerializeField] public Vector3 forceOrigin;
21 [SerializeField] public float height;
22 [SerializeField] public bool isRoot;
23 [SerializeField] public bool isTop;
24
25 [Header("References")]
26 [SerializeField] private GameController game;
27 [SerializeField] private bool callFoulOnContact;
28 [SerializeField] public Transform flipper;
29
30 public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
31 private Rigidbody2D _rigidbody;
32
33 private void FixedUpdate()
34 {
35 if (moveleft)
36 {
37 Rigidbody.AddForceAtPosition(
38 Vector2.left * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
39 transform.position + (height * forceOrigin));
40 }
41 if (moveright)
42 {
43 Rigidbody.AddForceAtPosition(
44 Vector2.right * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
45 transform.position + (height * forceOrigin));
46 }
47 }
48
49 private void OnCollisionEnter2D(Collision2D other)
50 {
51 if (!callFoulOnContact) return;
52 Debug.Log("ENTERED");
53 Debug.Log(other.gameObject.CompareTag("Ground"));
54 Debug.Log(game.player.HasBall);
55 Debug.Log("---");
56 if (game.player.HasBall && other.gameObject.CompareTag("Ground"))
57 game.player.Foul("LOOSE BALL FOUL");
58 }
59 }
60
61 [Serializable]
62 public struct Control
63 {
64 public KeyCode keyCode;
65 public GameObject icon;
66 public GameObject leg;
67 public GameObject arm;
68 }
69 }