-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scenes.cs
143 lines (127 loc) · 4.87 KB
/
Scenes.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
/*============================================================================
Copyright (C) 2016 akitsu sanae
https://github.com/akitsu-sanae/shape-of-kani
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
============================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace shape_of_kani
{
class Title : asd.Scene
{
public Title()
{
var title = new asd.TextObject2D();
title.Font = Resource.Font;
title.Text = "蟹の形";
title.Position = new asd.Vector2DF(100, 100);
layer.AddObject(title);
var label = new asd.TextObject2D();
label.Font = Resource.Font;
label.Text = "Press Z to Start!!";
label.Position = new asd.Vector2DF(200, 200);
layer.AddObject(label);
AddLayer(layer);
}
protected override void OnUpdated()
{
if (asd.Engine.Keyboard.GetKeyState(asd.Keys.Z) == asd.KeyState.Push)
asd.Engine.ChangeScene(new Game());
}
private asd.Layer2D layer = new asd.Layer2D();
}
class Game : asd.Scene
{
public Game()
{
for (var i=0; i<50; i++)
{
var target = new Charactor();
target.Position = new asd.Vector2DF(
(float)Resource.Rand.NextDouble() * asd.Engine.WindowSize.X,
(float)Resource.Rand.NextDouble() * asd.Engine.WindowSize.Y);
targets.Add(target);
gameLayer.AddObject(target);
}
gameLayer.AddObject(player);
AddLayer(gameLayer);
scoreLabel.Font = Resource.SmallFont;
scoreLabel.Text = "Score: ";
scoreLayer.AddObject(scoreLabel);
AddLayer(scoreLayer);
stopWatch.Start();
}
protected override void OnUpdated()
{
foreach (var target in targets)
{
if (target.Text == player.Text && (target.Position - player.Position).Length < 32)
{
stopWatch.Stop();
score += 100000 / (stopWatch.ElapsedMilliseconds == 0 ? 1 : stopWatch.ElapsedMilliseconds);
scoreLabel.Text = "Score: " + score.ToString();
stopWatch.Restart();
target.Dispose();
}
}
targets.RemoveAll(t => !t.IsAlive);
if (targets.Count == 0)
asd.Engine.ChangeScene(new Clear(score));
}
Player player = new Player();
List<Charactor> targets = new List<Charactor>();
private asd.Layer2D gameLayer = new asd.Layer2D();
private asd.Layer2D scoreLayer = new asd.Layer2D();
System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
private asd.TextObject2D scoreLabel = new asd.TextObject2D();
long score = 0;
}
class Clear : asd.Scene
{
public Clear(long score)
{
List<long> scores = new List<long>();
scores.Add(score);
using (var reader = new System.IO.StreamReader("score.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
scores.Add(int.Parse(line));
}
scores.Sort();
scores.Reverse();
scores = scores.Take(10).ToList();
System.IO.File.WriteAllLines("score.txt", scores.Select(s => s.ToString()));
var rank = scores.IndexOf(score);
var layer = new asd.Layer2D();
if (rank != -1)
{
var new_record_label = new asd.TextObject2D();
new_record_label.Text = "New Record!!!";
new_record_label.Font = Resource.SmallFont;
new_record_label.Position = new asd.Vector2DF(100, 50);
layer.AddObject(new_record_label);
}
for (int i = 0; i < 10; i++)
{
var score_label = new asd.TextObject2D();
score_label.Text = scores[i].ToString();
score_label.Font = Resource.SmallFont;
score_label.Position = new asd.Vector2DF(100, 100 + Resource.FontSize / 2 * i);
if (i == rank)
score_label.Color = new asd.Color(255, 255, 0);
layer.AddObject(score_label);
}
AddLayer(layer);
}
protected override void OnUpdated()
{
if (asd.Engine.Keyboard.GetKeyState(asd.Keys.Z) == asd.KeyState.Push)
asd.Engine.ChangeScene(new Title());
}
}
}