-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkif.html
More file actions
255 lines (213 loc) · 7.71 KB
/
Copy pathkif.html
File metadata and controls
255 lines (213 loc) · 7.71 KB
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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>蛇 vs 馬 TD 再生</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<style>
body {
margin: 0;
background: #111;
color: #fff;
font-family: sans-serif;
text-align: center;
}
canvas {
display: block;
margin: auto;
background: #222;
touch-action: none;
}
#ui {
text-align: center;
padding: 6px;
}
button {
margin: 4px;
padding: 6px;
}
textarea {
width: 90%;
height: 120px;
background: #222;
color: #0f0;
font-family: monospace;
margin: 8px 0;
border: 1px solid #555;
padding: 6px;
}
textarea:disabled {
background: #333;
color: #888;
}
</style>
</head>
<body>
<h2>再生</h2>
<div id="ui">
<textarea id="kif-input" placeholder="ここに棋譜(JSON)を貼り付けてください"></textarea>
<br>
<button id="load-kif-btn">読み込み&再生</button>
</div>
<div id="ui">
再生速度: <span id="speed">x1</span>
<button onclick="setSpeed(1)">x1</button>
<button onclick="setSpeed(2)">x2</button>
<button onclick="setSpeed(3)">x3</button>
<button onclick="setSpeed(5)">x5</button>
<button onclick="setSpeed(10)">x10</button>
</div>
<div id="ui">
お金: <span id="cost">10</span> |
生存: <span id="time">0</span>s
</div>
<canvas id="game" width="360" height="560"></canvas>
<script src="setting.js"></script>
<script src="index.js"></script>
<script defer>
let kifData = [];
let recordIndex = 0;
let gameStarted = false;
const loadBtn = document.getElementById("load-kif-btn");
const kifInput = document.getElementById("kif-input");
// 再生速度制御
function setSpeed(v) {
speedMultiplier = v;
const el = document.getElementById("speed");
if (el) el.textContent = "x" + v;
}
// loadボタンで棋譜読み込み
loadBtn.onclick = () => {
try {
const data = JSON.parse(kifInput.value);
if (!Array.isArray(data)) throw "棋譜が配列ではありません";
kifData = data;
// 初期化
frame = 0;
second = 0;
cost = 10;
snakes.length = 0;
enemies.length = 0;
effects.length = 0;
costEffects.length = 0;
enemiesDefeated = 0;
gameOver = false;
recordIndex = 0;
gameStarted = true;
requestAnimationFrame(gameLoop);
} catch (e) {
alert("棋譜の読み込みに失敗しました: " + e);
}
};
// updateLogicを棋譜再生対応に上書き
const originalUpdateLogic = updateLogic;
updateLogic = function () {
if (gameOver) return;
frame++;
// ---------------------------
// 棋譜再生による蛇の配置・強化
// ---------------------------
if (gameStarted && kifData && recordIndex < kifData.length) {
while (recordIndex < kifData.length && kifData[recordIndex].frame <= frame) {
const act = kifData[recordIndex];
if (act.action === "placeSnake") {
snakes.push({ ...act, timer: 0 });
} else if (act.action === "upgradeSnake") {
const s = snakes.find(s => s.id === act.id);
if (s) s.level = act.level;
}
recordIndex++;
}
}
// ---------------------------
// 通常の時間処理
// ---------------------------
if (frame % FPS === 0) {
second++;
cost++;
}
// ---------------------------
// 敵の自動生成(index.js と同じロジック)
// ---------------------------
const spawnInterval = Math.max(120 - frame / 30, 50); // 出現間隔を徐々に短縮
if (frame % spawnInterval === 0) {
spawnEnemy(); // index.js と同じ仕様で生成
}
// ---------------------------
// 蛇の攻撃・生産・減速処理
// ---------------------------
snakes.forEach(s => {
s.timer++;
const t = getSnakeStats(s);
// 所持金生成
if (t.produceSec && s.timer % (t.produceSec * FPS) === 0) {
cost++;
costEffects.push({ x: s.x, y: s.y - 20, text: `+${t.produceAmmount}`, life: 30 });
}
// 攻撃
enemies.forEach(e => {
const d = Math.hypot(e.x - s.x, e.y - s.y);
if (d < t.range && t.rate && s.timer % t.rate === 0) {
e.hp -= t.dmg || 0;
if (t.slow) {
e.slow = t.slow;
e.slowTimer = t.slowTime;
}
if (t.dmg && t.dmg > 0) {
effects.push({ x: e.x, y: e.y, text: `-${t.dmg}`, life: 30 });
}
if (t.poison) e.poison += t.poison;
}
});
});
// ---------------------------
// 敵の移動・HP減少
// ---------------------------
enemies.forEach(e => {
if (e.slowTimer > 0) e.slowTimer--;
else e.slow = 1;
e.y += e.speed * e.slow;
e.hp -= e.poison;
if (e.y > defenseLine) gameOver = true;
});
// 倒れた敵削除
for (let i = enemies.length - 1; i >= 0; i--) {
if (enemies[i].hp <= 0) {
enemies.splice(i, 1);
enemiesDefeated++;
}
}
// ---------------------------
// エフェクト処理
// ---------------------------
for (let i = effects.length - 1; i >= 0; i--) {
effects[i].y -= 0.5;
effects[i].life--;
if (effects[i].life <= 0) effects.splice(i, 1);
}
// UI更新
const costEl = document.getElementById("cost");
if (costEl) costEl.textContent = cost;
const timeEl = document.getElementById("time");
if (timeEl) timeEl.textContent = second;
updateScoreUI();
};
// URLクエリパラメータから自動再生
const params = new URLSearchParams(window.location.search);
const kifParam = params.get("kif");
if (kifParam) {
try {
const decoded = decodeURIComponent(kifParam);
kifInput.value = decoded;
// 自動再生
loadBtn.click();
// 入力欄非表示
kifInput.style.display = "none";
loadBtn.style.display = "none";
} catch (e) {
console.error("棋譜自動読み込み失敗:", e);
}
}
</script>
</body>
</html>