cutechicken commited on
Commit
8e54d52
Β·
verified Β·
1 Parent(s): ea91682

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +33 -17
index.html CHANGED
@@ -194,10 +194,11 @@
194
  const weaponInfo = document.getElementById('weaponInfo');
195
  const countdownEl = document.getElementById('countdown');
196
  const bossButton = document.getElementById('bossButton');
197
- // κ²Œμž„ μƒνƒœ λ³€μˆ˜λ“€ λ°”λ‘œ μ•„λž˜μ— μΆ”κ°€
198
- const FPS = 60; // λͺ©ν‘œ FPS
199
- const frameDelay = 1000 / FPS; // ν”„λ ˆμž„λ‹Ή μ‹œκ°„ (μ•½ 16.67ms)
200
- let lastFrameTime = 0; // λ§ˆμ§€λ§‰ ν”„λ ˆμž„μ˜ μ‹œκ°„μ„ μ €μž₯
 
201
  canvas.width = window.innerWidth;
202
  canvas.height = window.innerHeight;
203
 
@@ -1265,23 +1266,38 @@ function updateBF109Damage() {
1265
  }
1266
  function gameLoop(timestamp) {
1267
  if (!gameOver && gameStarted) {
1268
- // ν˜„μž¬ ν”„λ ˆμž„κ³Ό 이전 ν”„λ ˆμž„μ˜ μ‹œκ°„ 차이 계산
1269
- const elapsed = timestamp - lastFrameTime;
1270
-
1271
- // frameDelay(16.67ms)보닀 더 λ§Žμ€ μ‹œκ°„μ΄ μ§€λ‚¬λŠ”μ§€ 확인
1272
- if (elapsed > frameDelay) {
1273
- // λ§ˆμ§€λ§‰ ν”„λ ˆμž„ μ‹œκ°„ μ—…λ°μ΄νŠΈ
1274
- lastFrameTime = timestamp - (elapsed % frameDelay);
1275
-
1276
- // κ²Œμž„ μ—…λ°μ΄νŠΈ 및 그리기
1277
- updateGame();
1278
- drawGame();
 
 
 
 
 
 
 
 
1279
  }
1280
 
1281
- // λ‹€μŒ ν”„λ ˆμž„ μš”μ²­
1282
- requestAnimationFrame(gameLoop);
 
 
 
1283
  }
 
 
 
1284
  }
 
1285
  class Enemy {
1286
  constructor(isBoss = false) {
1287
  this.x = Math.random() * canvas.width;
 
194
  const weaponInfo = document.getElementById('weaponInfo');
195
  const countdownEl = document.getElementById('countdown');
196
  const bossButton = document.getElementById('bossButton');
197
+ // κ²Œμž„μ˜ κΈ°λ³Έ μƒνƒœ λ³€μˆ˜λ“€ κ·Όμ²˜μ— μΆ”κ°€
198
+ let lastFrameTime = 0; // λ§ˆμ§€λ§‰ ν”„λ ˆμž„μ΄ μ‹€ν–‰λœ μ‹œκ°„
199
+ const FPS = 60; // λͺ©ν‘œ FPS
200
+ const frameDelay = 1000 / FPS; // ν”„λ ˆμž„ μ‚¬μ΄μ˜ 간격 (16.67ms)
201
+ let deltaTime = 0; // ν”„λ ˆμž„ κ°„μ˜ μ‹œκ°„ 차이
202
  canvas.width = window.innerWidth;
203
  canvas.height = window.innerHeight;
204
 
 
1266
  }
1267
  function gameLoop(timestamp) {
1268
  if (!gameOver && gameStarted) {
1269
+ // 첫 ν”„λ ˆμž„μΌ 경우 μ‹œκ°„ μ΄ˆκΈ°ν™”
1270
+ if (!lastFrameTime) {
1271
+ lastFrameTime = timestamp;
1272
+ }
1273
+
1274
+ // ν˜„μž¬ ν”„λ ˆμž„κ³Ό 이전 ν”„λ ˆμž„μ˜ μ‹œκ°„ 차이 계산
1275
+ deltaTime = timestamp - lastFrameTime;
1276
+
1277
+ // 16.67ms(60FPS)κ°€ μ§€λ‚¬λŠ”μ§€ 확인
1278
+ if (deltaTime >= frameDelay) {
1279
+ // μ—…λ°μ΄νŠΈν•  ν”„λ ˆμž„ 수 계산
1280
+ const numUpdates = Math.floor(deltaTime / frameDelay);
1281
+
1282
+ // ν•œλ²ˆμ— λ„ˆλ¬΄ λ§Žμ€ μ—…λ°μ΄νŠΈ 방지 (μ΅œλŒ€ 3ν”„λ ˆμž„)
1283
+ const maxUpdates = 3;
1284
+
1285
+ // κ²Œμž„ μƒνƒœ μ—…λ°μ΄νŠΈ
1286
+ for (let i = 0; i < Math.min(numUpdates, maxUpdates); i++) {
1287
+ updateGame(frameDelay / 1000);
1288
  }
1289
 
1290
+ // ν™”λ©΄ 그리기
1291
+ drawGame();
1292
+
1293
+ // λ§ˆμ§€λ§‰ ν”„λ ˆμž„ μ‹œκ°„ μ—…λ°μ΄νŠΈ
1294
+ lastFrameTime = timestamp - (deltaTime % frameDelay);
1295
  }
1296
+
1297
+ // λ‹€μŒ ν”„λ ˆμž„ μš”μ²­
1298
+ requestAnimationFrame(gameLoop);
1299
  }
1300
+ }
1301
  class Enemy {
1302
  constructor(isBoss = false) {
1303
  this.x = Math.random() * canvas.width;