]> git.cameronkatri.com Git - gmtk-gamejam.git/blob - Assets/Scripts/PlayerController.cs
Merge branch 'master' of git.cameronkatri.com:gmtk-gamejam
[gmtk-gamejam.git] / Assets / Scripts / PlayerController.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Linq;
5 using UnityEngine;
6
7 public class PlayerController : MonoBehaviour
8 {
9 [SerializeField] private List<Rigidbody2D> segments;
10 [SerializeField] private float sensitivity;
11
12 [SerializeField] private Rigidbody2D ballPrefab;
13 [SerializeField] private float ballSpeed;
14
15 private void Update()
16 {
17 if (Input.GetKey(KeyCode.D))
18 {
19 segments[0].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[0].transform.position - Vector2.up * 0.5f);
20 }
21 else if (Input.GetKey(KeyCode.A))
22 {
23 segments[0].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[0].transform.position - Vector2.up * 0.5f);
24 }
25
26 if (Input.GetKey(KeyCode.L))
27 {
28 segments[1].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[1].transform.position + Vector2.up * 0.5f);
29 }
30 else if (Input.GetKey(KeyCode.J))
31 {
32 segments[1].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[1].transform.position + Vector2.up * 0.5f);
33 }
34
35 if (Input.GetKey(KeyCode.RightArrow))
36 {
37 segments[2].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[2].transform.position + Vector2.up * 0.5f);
38 }
39 else if (Input.GetKey(KeyCode.LeftArrow))
40 {
41 segments[2].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[2].transform.position + Vector2.up * 0.5f);
42 }
43
44 if (Input.GetKeyDown(KeyCode.Space))
45 {
46 var ball = Instantiate(ballPrefab);
47 ball.transform.position = segments.Last().position;
48 ball.AddForce((Vector2.right + Vector2.up) * ballSpeed);
49 }
50 }
51 }