forked from vaibhav899050/PastClones-IGDC-GameDev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerscript.cs
365 lines (310 loc) · 10.5 KB
/
playerscript.cs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using TMPro;
using UnityEngine.SceneManagement;
public class playerscript : MonoBehaviour
{
public float speed = 10f;
public TMP_Text t1;
public TMP_Text t2;
public GameObject player;
public List<replay> InputRecord = new List<replay>();
public List<replay> InputRecord1 = new List<replay>();
public List<replay> InputRecord2 = new List<replay>();
public List<List<replay>> clonereplay = new List<List<replay>>();
public float jumpforce = 5f;
Rigidbody2D rb;
public GameObject clone1;
public GameObject clone2;
public GameObject clone3;
public GameObject wonui;
public Transform groundcheck;
public LayerMask groundlayer;
public LayerMask clonelayer;
bool isgrounded;
bool isgroundclone;
int spacepress = 0;
public int cloneid = 0;
public int clonenum = 0;
public spwan sc;
public Vector2 spawnpoint;
public Vector2 spawnpoint1;
public Vector2 spawnpoint2;
public Vector2 spawnpoint3;
public Vector2 spawnpoint4;
public int newcloneid;
int i = 0;
public float gravity = 10f;
public GameObject pause;
public AudioSource jump;
public LayerMask flag;
bool iswon;
public float s1;
public float s2;
public float s3;
public int num;
public string n1;
public string n2;
public string n3;
public float period = 1f;
private float nextActionTime = 0.0f;
public float starttime;
private string cs;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
spawnpoint = new Vector2(-6.78f, -3.5f);
//spawnpoint1 = new Vector2(-0.05f, -0.01f);
spawnpoint2 = new Vector2(-7.65f, -3.51f);
spawnpoint3 = new Vector2(-8.77f, -3.51f);
spawnpoint4 = new Vector2(-9.72f, -3.51f);
Time.timeScale = 1f;
cs = "/"+SceneManager.GetActiveScene().name +".json";
//newcloneid = sc.cloneid1;
string path1 = File.ReadAllText(Application.persistentDataPath + "/playernum.json");
select playerdata1 = JsonUtility.FromJson<select>(path1);
num = playerdata1.num;
string path2 = File.ReadAllText(Application.persistentDataPath + "/player.json");
numplayer playerdata2 = JsonUtility.FromJson<numplayer>(path2);
n1 = playerdata2.name1;
n2 = playerdata2.name2;
n3 = playerdata2.name3;
starttime = Time.time;
string path = File.ReadAllText(Application.persistentDataPath + cs);
levelscore playerdata = JsonUtility.FromJson<levelscore>(path);
//System.IO.File.WriteAllText(path, gamed);
//string gamed = System.IO.File.ReadAllText(path);
s1 = playerdata.s1;
s2 = playerdata.s2;
s3 = playerdata.s3;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape) && !iswon)
{
pause.SetActive(true);
Time.timeScale = 0f;
}
if(i < 5 && Input.GetKeyDown(KeyCode.K))
{
//spwanobj();
i++;
newcloneid = i;
if (i == 1)
{
player.transform.position = spawnpoint2;
}
if (i == 2)
{
player.transform.position = spawnpoint3;
}
if (i == 3)
{
player.transform.position = spawnpoint4;
}
}
float t = Time.time - starttime;
if (t > nextActionTime && !iswon)
{
nextActionTime += period;
t += 1;
//i++;
}
isgrounded = Physics2D.OverlapCapsule(groundcheck.position, new Vector2(0.99f, 0.16f), CapsuleDirection2D.Horizontal, 0, groundlayer);
iswon = Physics2D.OverlapCapsule(groundcheck.position, new Vector2(0.99f, 0.16f), CapsuleDirection2D.Horizontal, 0, flag);
isgroundclone = Physics2D.OverlapCapsule(groundcheck.position, new Vector2(0.99f, 0.16f), CapsuleDirection2D.Horizontal, 0, clonelayer);
if (iswon)
{
if (num == 1)
{
//levelscore playerdata = new levelscore();
levelscore playerdata = new levelscore();
if (s1 != 0)
{
if (t < s1)
{
s1 = t;
}
}
else
{
s1 = t;
}
playerdata.s1 = s1;
playerdata.s2 = s2;
playerdata.s3 = s3;
string gamed = JsonUtility.ToJson(playerdata, true);
string path = Application.persistentDataPath + cs;
//n3.SetActive(true);
Debug.Log(path);
File.WriteAllText(path, gamed);
}
if (num == 2)
{
levelscore playerdata1 = new levelscore();
if (s2 != 0)
{
if (t < s2)
{
s2 = t;
}
}
else
{
s2 = t;
}
playerdata1.s1 = s1;
playerdata1.s2 = s2;
playerdata1.s3 = s3;
string gamed = JsonUtility.ToJson(playerdata1, true);
string path = Application.persistentDataPath + cs;
//n3.SetActive(true);
Debug.Log(path);
File.WriteAllText(path, gamed);
}
if (num == 3)
{
levelscore playerdata2 = new levelscore();
playerdata2.s1 = s1;
playerdata2.s2 = s2;
if (s3 != 0)
{
if (t<s3)
{
s3 = t;
}
}
else
{
s3 = t;
}
playerdata2.s3 = s3;
string gamed = JsonUtility.ToJson(playerdata2, true);
string path = Application.persistentDataPath + cs;
//n3.SetActive(true);
Debug.Log(path);
File.WriteAllText(path, gamed);
}
string path1 = File.ReadAllText(Application.persistentDataPath + cs);
levelscore player = JsonUtility.FromJson<levelscore>(path1);
//System.IO.File.WriteAllText(path, gamed);
//string gamed = System.IO.File.ReadAllText(path);
s1 = player.s1;
s2 = player.s2;
s3 = player.s3;
t2.text = s1 + "\n\n" + s2 + "\n\n" + s3;
t1.text = n1 + "\n\n" + n2 + "\n\n" + n3;
wonui.SetActive(true);
Time.timeScale = 0f;
}
}
// Update is called once per frame
void FixedUpdate()
{
float horizontal = Input.GetAxisRaw("Horizontal");
if (Input.GetKey(KeyCode.W))
{
spacepress = 1;
}
else
{
spacepress = 0;
}
//replay temp = new replay { x = horizontal , y = spacepress};
//InputRecord.Add(temp);
player.transform.position =new Vector3(player.transform.position.x + horizontal * speed * Time.fixedDeltaTime, player.transform.position.y);
if (Input.GetKey(KeyCode.W))
{
if(isgroundclone|| isgrounded)
{
rb.velocity = new Vector2(rb.velocity.x, jumpforce);
jump.Play();
}
}
if (newcloneid == 0)
{
replay temp = new replay { x = horizontal, y = spacepress };
InputRecord.Add(temp);
}
else if (newcloneid == 1)
{
replay temp1 = new replay { x = horizontal, y = spacepress };
InputRecord1.Add(temp1);
}
else if (newcloneid == 2)
{
replay temp2 = new replay { x = horizontal, y = spacepress };
InputRecord2.Add(temp2);
}
/*if (Input.GetKeyDown(KeyCode.K))
{
clonenum += 1;
player.transform.position = spawnpoint;
}*/
/*if (clone1.activeSelf != true)
{
replay temp1 = new replay { x = horizontal, y = spacepress };
InputRecord.Add(temp1);
}
if (clone1.activeSelf == true && clone2.activeSelf != true)
{
replay temp2 = new replay { x = horizontal, y = spacepress };
InputRecord1.Add(temp2);
}
if (Input.GetKeyDown(KeyCode.K))
{
if (clone1.activeSelf != true)
{
clone1.SetActive(true);
clone1.transform.position = spawnpoint;
}
if(clone1.activeSelf==true && clone2.activeSelf != true)
{
clone2.SetActive(true);
clone2.transform.position = spawnpoint;
}
}*/
/*if (clonenum == 0)
{
replay temp1 = new replay { x = horizontal, y = spacepress };
InputRecord.Add(temp1);
if (Input.GetKeyDown(KeyCode.K))
{
clone1.SetActive(true);
clone1.transform.position = spawnpoint;
player.transform.position = spawnpoint;
clonenum += 1;
}
}
if (clonenum == 1)
{
replay temp2 = new replay { x = horizontal, y = spacepress };
InputRecord1.Add(temp2);
if (Input.GetKeyDown(KeyCode.K))
{
clone2.SetActive(true);
clone2.transform.position = spawnpoint;
clone1.transform.position = spawnpoint;
player.transform.position = spawnpoint;
clonenum += 1;
}
}
if (clonenum == 2)
{
replay temp3 = new replay { x = horizontal, y = spacepress };
InputRecord2.Add(temp3);
}*/
//Debug.Log(clonenum);
/*if (Input.GetKeyDown(KeyCode.K))
{
cloneid += 1;
Debug.Log(cloneid+" "+ InputRecord.Count);
clonereplay.Add(InputRecord);
Debug.Log("h" + clonereplay.Count);
InputRecord.Clear();
}*/
}
}