diff --git a/src/game/constants.js b/src/game/constants.js index 9d1a6d1..7b53952 100644 --- a/src/game/constants.js +++ b/src/game/constants.js @@ -10,7 +10,7 @@ export const HEIGHTS = { // Constantes de gameplay export const GAMEPLAY = { - BASE_GAME_SPEED: 0.7, // Velocidade base inicial (70% da velocidade) + BASE_GAME_SPEED: 1.5, // Velocidade base inicial (100% da velocidade) SPEED_INCREASE: 0.02, // Aumento de velocidade por milestone SPEED_MILESTONE: 100, // A cada quantos pontos aumenta a velocidade BUG_SPEED: 2, // Velocidade dos bugs @@ -21,4 +21,9 @@ export const GAMEPLAY = { BUG_SPACING_MAX: 2000, // Espaçamento máximo entre bugs INITIAL_BUG_DISTANCE: 600, // Distância inicial dos bugs INITIAL_BUG_SPACING: 600, // Espaçamento inicial entre bugs - reduzido + TARGET_FPS: 60, // FPS alvo para normalização (60fps padrão) +}; + +export const getDeltaMultiplier = (delta) => { + return delta / (1000 / GAMEPLAY.TARGET_FPS); }; diff --git a/src/game/gameobjects/Beetle.ts b/src/game/gameobjects/Beetle.ts index 14cab3a..8392604 100644 --- a/src/game/gameobjects/Beetle.ts +++ b/src/game/gameobjects/Beetle.ts @@ -33,8 +33,8 @@ export default class Beetle extends Phaser.GameObjects.Image { this.move(); } - updateWithSpeed(gameSpeed: number) { - this.moveWithSpeed(gameSpeed); + updateWithSpeed(gameSpeed: number, deltaMultiplier: number = 1) { + this.moveWithSpeed(gameSpeed, deltaMultiplier); } recycleBug() { @@ -51,7 +51,7 @@ export default class Beetle extends Phaser.GameObjects.Image { this.x -= this.speed * GAMEPLAY.BASE_GAME_SPEED; } - moveWithSpeed(gameSpeed: number) { - this.x -= this.speed * gameSpeed; + moveWithSpeed(gameSpeed: number, deltaMultiplier: number = 1) { + this.x -= this.speed * gameSpeed * deltaMultiplier; } } diff --git a/src/game/gameobjects/Cloud.js b/src/game/gameobjects/Cloud.js index 7179507..803a975 100644 --- a/src/game/gameobjects/Cloud.js +++ b/src/game/gameobjects/Cloud.js @@ -23,8 +23,8 @@ export default class Cloud extends Phaser.GameObjects.Image { } } - updateWithSpeed(gameSpeed) { - this.moveWithSpeed(gameSpeed); + updateWithSpeed(gameSpeed, deltaMultiplier = 1) { + this.moveWithSpeed(gameSpeed, deltaMultiplier); if (this.x < -this.width) { this.recycleCloud(); @@ -42,7 +42,7 @@ export default class Cloud extends Phaser.GameObjects.Image { this.x -= this.speed * GAMEPLAY.BASE_GAME_SPEED; } - moveWithSpeed(gameSpeed) { - this.x -= this.speed * gameSpeed; + moveWithSpeed(gameSpeed, deltaMultiplier = 1) { + this.x -= this.speed * gameSpeed * deltaMultiplier; } } diff --git a/src/game/gameobjects/Cockroach.ts b/src/game/gameobjects/Cockroach.ts index 9f90083..617e885 100644 --- a/src/game/gameobjects/Cockroach.ts +++ b/src/game/gameobjects/Cockroach.ts @@ -33,8 +33,8 @@ export default class Cockroach extends Phaser.GameObjects.Image { this.move(); } - updateWithSpeed(gameSpeed: number) { - this.moveWithSpeed(gameSpeed); + updateWithSpeed(gameSpeed: number, deltaMultiplier: number = 1) { + this.moveWithSpeed(gameSpeed, deltaMultiplier); } recycleBug() { @@ -51,7 +51,7 @@ export default class Cockroach extends Phaser.GameObjects.Image { this.x -= this.speed * GAMEPLAY.BASE_GAME_SPEED; // Usa velocidade base } - moveWithSpeed(gameSpeed: number) { - this.x -= this.speed * gameSpeed; + moveWithSpeed(gameSpeed: number, deltaMultiplier: number = 1) { + this.x -= this.speed * gameSpeed * deltaMultiplier; } } diff --git a/src/game/gameobjects/Duck.js b/src/game/gameobjects/Duck.js index fe3ef9c..b963a6b 100644 --- a/src/game/gameobjects/Duck.js +++ b/src/game/gameobjects/Duck.js @@ -22,16 +22,16 @@ export default class Duck extends Phaser.GameObjects.Image { this.move(); } - updateWithSpeed(gameSpeed) { - this.moveWithSpeed(gameSpeed); + updateWithSpeed(gameSpeed, deltaMultiplier = 1) { + this.moveWithSpeed(gameSpeed, deltaMultiplier); } move() { this.x -= this.speed * GAMEPLAY.BASE_GAME_SPEED; } - moveWithSpeed(gameSpeed) { - this.x -= this.speed * gameSpeed; + moveWithSpeed(gameSpeed, deltaMultiplier = 1) { + this.x -= this.speed * gameSpeed * deltaMultiplier; } collect() { diff --git a/src/game/gameobjects/LadyBug.ts b/src/game/gameobjects/LadyBug.ts index 0731602..336bd5f 100644 --- a/src/game/gameobjects/LadyBug.ts +++ b/src/game/gameobjects/LadyBug.ts @@ -35,8 +35,8 @@ export default class LadyBug extends Phaser.GameObjects.Image { // Remoção controlada pela cena Game } - updateWithSpeed(gameSpeed: number) { - this.moveWithSpeed(gameSpeed); + updateWithSpeed(gameSpeed: number, deltaMultiplier: number = 1) { + this.moveWithSpeed(gameSpeed, deltaMultiplier); } recycleBug() { @@ -53,7 +53,7 @@ export default class LadyBug extends Phaser.GameObjects.Image { this.x -= this.speed * GAMEPLAY.BASE_GAME_SPEED; // Usa velocidade base } - moveWithSpeed(gameSpeed: number) { - this.x -= this.speed * gameSpeed; + moveWithSpeed(gameSpeed: number, deltaMultiplier: number = 1) { + this.x -= this.speed * gameSpeed * deltaMultiplier; } } diff --git a/src/game/gameobjects/Moth.ts b/src/game/gameobjects/Moth.ts index 46b3a35..3146bf9 100644 --- a/src/game/gameobjects/Moth.ts +++ b/src/game/gameobjects/Moth.ts @@ -36,8 +36,8 @@ export default class Moth extends Phaser.GameObjects.Sprite { this.move(); } - updateWithSpeed(gameSpeed: number) { - this.moveWithSpeed(gameSpeed); + updateWithSpeed(gameSpeed: number, deltaMultiplier: number = 1) { + this.moveWithSpeed(gameSpeed, deltaMultiplier); } recycleBug() { @@ -54,7 +54,7 @@ export default class Moth extends Phaser.GameObjects.Sprite { this.x -= this.speed * GAMEPLAY.BASE_GAME_SPEED; // Usa velocidade base } - moveWithSpeed(gameSpeed: number) { - this.x -= this.speed * gameSpeed; + moveWithSpeed(gameSpeed: number, deltaMultiplier: number = 1) { + this.x -= this.speed * gameSpeed * deltaMultiplier; } } diff --git a/src/game/gameobjects/Player.js b/src/game/gameobjects/Player.js index e686d47..f4dc529 100644 --- a/src/game/gameobjects/Player.js +++ b/src/game/gameobjects/Player.js @@ -153,7 +153,7 @@ export default class Player extends Phaser.Physics.Arcade.Sprite { } } - update() { + update(delta, deltaMultiplier) { if (this.isHit) { // Após 1 segundo de hit, muda para animação de morto const hitElapsed = this.scene.time.now - this.hitTimer; diff --git a/src/game/main.ts b/src/game/main.ts index a8cb2a6..482a94a 100644 --- a/src/game/main.ts +++ b/src/game/main.ts @@ -13,6 +13,10 @@ const config: Phaser.Types.Core.GameConfig = { height: 500, parent: "game-container", backgroundColor: "#000000", + fps: { + target: 60, + forceSetTimeOut: false, + }, physics: { default: "arcade", arcade: { diff --git a/src/game/scenes/Game.js b/src/game/scenes/Game.js index 12b2d5c..8f45fc7 100644 --- a/src/game/scenes/Game.js +++ b/src/game/scenes/Game.js @@ -1,7 +1,7 @@ import { Scene } from "phaser"; import { EventBus } from "./../EventBus"; -import { HEIGHTS, GAMEPLAY } from "./../constants"; +import { HEIGHTS, GAMEPLAY, getDeltaMultiplier } from "./../constants"; import Player from "./../gameobjects/Player"; import Cloud from "./../gameobjects/Cloud"; @@ -365,15 +365,17 @@ export class Game extends Scene { } update(time, delta) { + const deltaMultiplier = getDeltaMultiplier(delta); + // Se o player foi atingido, para tudo if (!this.playerHit) { this.clouds.forEach((cloud) => - cloud.updateWithSpeed(this.getCurrentGameSpeed()) + cloud.updateWithSpeed(this.getCurrentGameSpeed(), deltaMultiplier) ); // Atualizar bugs e reciclar quando saem da tela this.bugs.forEach((bug) => { - bug.updateWithSpeed(this.getCurrentGameSpeed()); + bug.updateWithSpeed(this.getCurrentGameSpeed(), deltaMultiplier); if (bug.x < -50) { this.recycleBug(bug); } @@ -381,7 +383,7 @@ export class Game extends Scene { // Atualizar patos e remover quando saem da tela this.ducks.forEach((duck, index) => { - duck.updateWithSpeed(this.getCurrentGameSpeed()); + duck.updateWithSpeed(this.getCurrentGameSpeed(), deltaMultiplier); if (duck.x < -50) { duck.destroy(); this.ducks.splice(index, 1); @@ -390,7 +392,7 @@ export class Game extends Scene { if (this.roadSprite) { this.roadSprite.tilePositionX += - GAMEPLAY.BACKGROUND_SPEED * this.getCurrentGameSpeed(); // Aplica velocidade dinâmica + GAMEPLAY.BACKGROUND_SPEED * this.getCurrentGameSpeed() * deltaMultiplier; // Aplica velocidade dinâmica normalizada } // Pontuação por passos (a cada 100ms = 1 ponto) @@ -410,7 +412,7 @@ export class Game extends Scene { } if (this.player) { - this.player.update(); + this.player.update(delta, deltaMultiplier); // Atualiza framerate da animação de corrida baseado na velocidade this.player.updateRunningSpeed(this.getCurrentGameSpeed()); }