Skip to content

Commit 6593a9d

Browse files
committed
tunti1411
1 parent a398cb0 commit 6593a9d

File tree

4 files changed

+111
-21
lines changed

4 files changed

+111
-21
lines changed

Assets/Patterns/1. Command/Rebind keys/Scripts/AudioManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private void Awake()
2020
{
2121
Debug.Log("instance exists");
2222
Destroy(this);
23-
//Destroy(gameObject);
23+
Destroy(gameObject);
2424
}
2525
}
2626
// Start is called before the first frame update

Assets/Patterns/1. Command/Rebind keys/Scripts/GameController.cs

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections;
22
using System.Collections.Generic;
33
using UnityEngine;
4+
using UnityEngine.SceneManagement;
45

56
namespace CommandPattern.RebindKeys
67
{
@@ -61,22 +62,22 @@ void Update()
6162
//If we were moving with speed * Time.deltaTime, the undo system would be more comlicated to implement.
6263
//When we undo, the Time.deltaTime may be different so we end up at another position than we previously had
6364
//You could solve this by saving the Time.deltaTime somewhere
64-
if (Input.GetKeyDown(KeyCode.W))
65-
{
66-
ExecuteNewCommand(buttonW);
67-
}
68-
else if (Input.GetKeyDown(KeyCode.A))
69-
{
70-
ExecuteNewCommand(buttonA);
71-
}
72-
else if (Input.GetKeyDown(KeyCode.S))
73-
{
74-
ExecuteNewCommand(buttonS);
75-
}
76-
else if (Input.GetKeyDown(KeyCode.D))
77-
{
78-
ExecuteNewCommand(buttonD);
79-
}
65+
//if (Input.GetKeyDown(KeyCode.W))
66+
//{
67+
// ExecuteNewCommand(buttonW);
68+
//}
69+
//else if (Input.GetKeyDown(KeyCode.A))
70+
//{
71+
// ExecuteNewCommand(buttonA);
72+
//}
73+
//else if (Input.GetKeyDown(KeyCode.S))
74+
//{
75+
// ExecuteNewCommand(buttonS);
76+
//}
77+
//else if (Input.GetKeyDown(KeyCode.D))
78+
//{
79+
// ExecuteNewCommand(buttonD);
80+
//}
8081
//Undo with u (ctrl + z is sometimes interfering with the editor's undo system)
8182
else if (Input.GetKeyDown(KeyCode.U))
8283
{
@@ -128,6 +129,34 @@ void Update()
128129

129130
isReplaying = true;
130131
}
132+
133+
//check gamestate example
134+
switch (GameManager.gamestate)
135+
{
136+
case GameState.REPLAYING:
137+
break;
138+
case GameState.PLAYING:
139+
//check inputs for player movement INSERT MOVEMENT HERE!!
140+
HandlePlayInput();
141+
break;
142+
case GameState.PAUSE:
143+
//check input for the pause key
144+
145+
//if (Input.GetKeyDown(KeyCode.P))
146+
//{
147+
// Time.timeScale = 1;
148+
// GameManager.gamestate = GameState.PAUSE;
149+
// Debug.Log("unpaused");
150+
//}
151+
HandlePauseInput();
152+
break;
153+
case GameState.GAME_OVER:
154+
//check if game over
155+
break;
156+
157+
158+
}
159+
131160
}
132161

133162

@@ -182,5 +211,48 @@ private void SwapKeys(ref Command key1, ref Command key2)
182211

183212
key2 = temp;
184213
}
214+
void HandlePlayInput() {
215+
if (Input.GetKeyDown(KeyCode.W))
216+
{
217+
ExecuteNewCommand(buttonW);
218+
}
219+
else if (Input.GetKeyDown(KeyCode.A))
220+
{
221+
ExecuteNewCommand(buttonA);
222+
}
223+
else if (Input.GetKeyDown(KeyCode.S))
224+
{
225+
ExecuteNewCommand(buttonS);
226+
}
227+
else if (Input.GetKeyDown(KeyCode.D))
228+
{
229+
ExecuteNewCommand(buttonD);
230+
}
231+
//movement here
232+
if (Input.GetKeyDown(KeyCode.P))
233+
{
234+
Time.timeScale = 0;
235+
Debug.Log("paused");
236+
GameManager.gamestate = GameState.PAUSE;
237+
238+
}
239+
}
240+
void HandlePauseInput() {
241+
242+
if (Input.GetKeyDown(KeyCode.P))
243+
{
244+
245+
Time.timeScale = 1;
246+
GameManager.gamestate = GameState.PLAYING;
247+
Debug.Log("unpaused");
248+
}
249+
if (Input.GetKeyDown(KeyCode.Escape))
250+
{
251+
Time.timeScale = 1;
252+
GameManager.gamestate = GameState.MENU;
253+
SceneManager.LoadScene(0);
254+
255+
}
256+
}
185257
}
186258
}

Assets/Patterns/1. Command/Rebind keys/Scripts/GameManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,25 @@
33
using UnityEngine;
44
using UnityEngine.SceneManagement;
55

6+
7+
8+
public enum GameState
9+
{
10+
MENU = 100,
11+
PLAYING = 101,
12+
PAUSE = 102,
13+
GAME_OVER = 103,
14+
REPLAYING = 104
15+
16+
}
617
public class GameManager : MonoBehaviour
718
{
819
public static GameManager Instance { get; private set; }
920
// Start is called before the first frame update
1021

22+
23+
24+
public static GameState gamestate = GameState.MENU;
1125

1226
public AudioSource baseMusic;
1327
public AudioSource battleMusic;
@@ -29,6 +43,8 @@ private void Awake()
2943
}
3044
public static void Startgame()
3145
{
46+
//Switching state menu->play
47+
GameManager.gamestate = GameState.PLAYING;
3248
//SceneManager.LoadScene(1);
3349
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex +1);
3450
}

Assets/Patterns/1. Command/Rebind keys/Scripts/Player.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ public void KillEnemy()
3333
// Update is called once per frame
3434
void Update()
3535
{
36-
if (Input.GetKeyDown(KeyCode.Escape))
37-
{
38-
SceneManager.LoadScene(0);
36+
37+
//if (Input.GetKeyDown(KeyCode.Escape))
38+
//{
39+
// GameManager.gamestate = GameState.MENU;
40+
// SceneManager.LoadScene(0);
3941

40-
}
42+
//}
4143
}
4244
}

0 commit comments

Comments
 (0)