diff options
author | elioat <elioat@tilde.institute> | 2024-12-27 08:10:16 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2024-12-27 08:10:16 -0500 |
commit | cbec006c83cbd51a8586ec8b4360b3e197e5d634 (patch) | |
tree | cef3d7a594fa7854cfa98d74c1ae424f9cc32181 /html/rogue | |
parent | ea50f9ee0875b9230174996af0f92922f747b974 (diff) | |
download | tour-cbec006c83cbd51a8586ec8b4360b3e197e5d634.tar.gz |
*
Diffstat (limited to 'html/rogue')
-rw-r--r-- | html/rogue/js/camera.js | 4 | ||||
-rw-r--r-- | html/rogue/js/config.js | 27 | ||||
-rw-r--r-- | html/rogue/js/game.js | 2 | ||||
-rw-r--r-- | html/rogue/js/hexGrid.js | 9 | ||||
-rw-r--r-- | html/rogue/js/player.js | 4 |
5 files changed, 36 insertions, 10 deletions
diff --git a/html/rogue/js/camera.js b/html/rogue/js/camera.js index e7b2475..a5aae47 100644 --- a/html/rogue/js/camera.js +++ b/html/rogue/js/camera.js @@ -13,7 +13,7 @@ const Camera = { const targetX = targetPixel.x - state.canvas.width / 2; const targetY = targetPixel.y - state.canvas.height / 2; - this.x += (targetX - this.x) * 0.1; - this.y += (targetY - this.y) * 0.1; + this.x += (targetX - this.x) * Config.camera.FOLLOW_SPEED; + this.y += (targetY - this.y) * Config.camera.FOLLOW_SPEED; } }; \ No newline at end of file diff --git a/html/rogue/js/config.js b/html/rogue/js/config.js index aea067f..284ad89 100644 --- a/html/rogue/js/config.js +++ b/html/rogue/js/config.js @@ -4,5 +4,32 @@ const Config = { GRID: '#333333', // Off-black for grid lines PLAYER: 'red', // Player color HEX_FILL: '#ffffff' // White fill for passable hexes + }, + + hex: { + SIZE: 40, // Base size of hexagons + GRID_SIZE: 10, // Number of hexes in grid (width/height) + get WIDTH() { // Computed hex width + return this.SIZE * 2; + }, + get HEIGHT() { // Computed hex height + return Math.sqrt(3) * this.SIZE; + } + }, + + game: { + FPS: 60, // Target frame rate + get FRAME_TIME() { // Computed frame duration + return 1000 / this.FPS; + } + }, + + player: { + MOVE_SPEED: 0.1, // Player movement speed + SIZE_RATIO: 1/3 // Player size relative to hex size + }, + + camera: { + FOLLOW_SPEED: 0.1 // Camera smoothing factor } }; \ No newline at end of file diff --git a/html/rogue/js/game.js b/html/rogue/js/game.js index 40c8826..e0010b7 100644 --- a/html/rogue/js/game.js +++ b/html/rogue/js/game.js @@ -65,7 +65,7 @@ function drawHex(ctx, x, y, hex) { } function gameLoop(currentTime) { - if (currentTime - lastFrameTime < FRAME_TIME) { + if (currentTime - lastFrameTime < Config.game.FRAME_TIME) { requestAnimationFrame(gameLoop); return; } diff --git a/html/rogue/js/hexGrid.js b/html/rogue/js/hexGrid.js index c45c981..0d4d81f 100644 --- a/html/rogue/js/hexGrid.js +++ b/html/rogue/js/hexGrid.js @@ -1,13 +1,12 @@ // Hex grid utilities and calculations const HexGrid = { - SIZE: 40, + get SIZE() { return Config.hex.SIZE }, + get WIDTH() { return Config.hex.WIDTH }, + get HEIGHT() { return Config.hex.HEIGHT }, + get GRID_SIZE() { return Config.hex.GRID_SIZE }, COLOR: Config.colors.GRID, - GRID_SIZE: 10, IMPASSABLE_COLOR: Config.colors.BACKGROUND, - get WIDTH() { return this.SIZE * 2 }, - get HEIGHT() { return Math.sqrt(3) * this.SIZE }, - // Convert hex coordinates to pixel coordinates toPixel(hex) { const x = this.SIZE * (3/2 * hex.q); diff --git a/html/rogue/js/player.js b/html/rogue/js/player.js index 9a25715..803a6b7 100644 --- a/html/rogue/js/player.js +++ b/html/rogue/js/player.js @@ -4,7 +4,7 @@ const player = { target: null, // Target hex to move to path: [], // Array of hex coordinates to follow movementProgress: 0, // Progress of current movement (0 to 1) - moveSpeed: 0.1, // Movement speed (0 to 1 per frame) + moveSpeed: Config.player.MOVE_SPEED, // Movement speed (0 to 1 per frame) // Initialize player init() { @@ -135,7 +135,7 @@ const player = { ctx.fillStyle = Config.colors.PLAYER; ctx.beginPath(); - ctx.arc(screenX, screenY, HEX_SIZE/3, 0, Math.PI * 2); + ctx.arc(screenX, screenY, HEX_SIZE * Config.player.SIZE_RATIO, 0, Math.PI * 2); ctx.fill(); // Optionally, draw the remaining path |