Commit Graph
43 Commits
Author SHA1 Message Date
pastilhas 2757d54dbb html5 canvas instead of DOM 2025-12-19 02:31:49 +00:00
pastilhas 41473f3b24 types 2025-12-19 02:17:51 +00:00
pastilhas 55970cc54e version 2025-11-02 19:15:52 +00:00
pastilhas c8218a9f16 feat(phase3): create gameInfo.ts with complete game documentation
- Create comprehensive gameInfo structure following vim-maze pattern
- Document controls: hjkl navigation, space/q/p game controls
- Document rules: movement, collisions, game flow, elements
- Document scoring: level-based points, speed progression
- Document configuration: all GameOptions with defaults and examples
- Add tips and objective for players
- Export gameInfo from main index.ts
2025-10-31 00:35:06 +00:00
pastilhas 2fcfd26429 feat: add initialSnakeSize and initialFoodCount to GameOptions
- New option: initialSnakeSize (defaults to 3)
- New option: initialFoodCount (defaults to 1)
- Snake spawns with configurable size
- Initial food count is configurable
- Example: useGame({ initialSnakeSize: 5, initialFoodCount: 2 })
2025-10-31 00:31:52 +00:00
pastilhas b82bef56e5 feat: add maxLevel to GameOptions with default of 25
- New option: maxLevel (defaults to 25)
- Once a player reaches maxLevel, levels no longer progress
- Prevents unlimited level scaling and FPS increases
- Example: useGame({ maxLevel: 10 })
2025-10-31 00:28:29 +00:00
pastilhas 520a640ea0 feat: add foodsPerLevel to GameOptions with default of 10
- New option: foodsPerLevel (defaults to 10)
- Controls how many foods must be eaten to level up
- Example: useGame({ foodsPerLevel: 5 })
2025-10-31 00:21:20 +00:00
pastilhas 5cbb2ee94c refactor: make all GameOptions optional with sensible defaults
- cols defaults to 30 (was required)
- rows defaults to 20 (was required)
- timeLimit and startingLevel remain optional
- Can now call useGame() with no arguments
- Example: useGame(), useGame({}), useGame({ startingLevel: 5 })
2025-10-31 00:19:43 +00:00
pastilhas ad82eaff7c refactor: enforce new GameOptions signature for useGame
- Remove old signature support (cols, rows, platformHook)
- useGame now requires GameOptions object only
- Update example app to use new signature
- Signature: useGame(options, platformHook?)
2025-10-31 00:17:36 +00:00
pastilhas 477bcdd9f3 feat: implement startingLevel option and remove INITIAL_FPS constant
- Remove INITIAL_FPS constant entirely - no longer exists
- Add startingLevel to GameOptions (defaults to 1)
- FPS now equals currentLevel (1:1 ratio)
- Points per food always equals currentLevel
- Game can start at any level with appropriate speed/scoring
2025-10-31 00:14:39 +00:00
pastilhas 58622c64d1 chore: change default initial FPS from 5 to 3 2025-10-31 00:06:31 +00:00
pastilhas 52cdbd81d5 feat(phase2.2): implement finalScore calculation
- finalScore equals current game score when gameStatus is 'game-over' or 'game-won'
- finalScore is null during active gameplay ('waiting' and 'started')
- Passed currentScore from gameManager to useScore hook
2025-10-30 23:57:23 +00:00
pastilhas 2a7162abf3 feat(phase2.1): track total keystrokes via keyLog length
- Expose keyLog.length as totalKeystrokes in ScoreManager
- Pass keyLog from useKeyBindings to useScore hook
- All game inputs (hjkl and platform keys) automatically counted
- Keystroke counter resets when keyLog is cleared (game restart)
2025-10-30 23:55:15 +00:00
pastilhas b59da4881d refactor(phase1.5): revert testing parameters to production values
- Reset initial snake size from 6 back to 3 segments
- Keep INITIAL_FPS at 5 (good starting speed)
- FOODS_PER_LEVEL = 2 (correct production value)
- Game now starts at normal difficulty
- Clean production-ready state
- Build and example app work correctly
2025-10-30 23:17:16 +00:00
pastilhas b60d17e2c8 refactor(phase1.4): clean up debug logging and finalize score calculation
- Remove all console.log debug statements
- Score calculation now working correctly:
  * Each food worth current level points
  * Level up happens AFTER food is eaten and scored
  * Example: food1(+1)=1pt, food2(+1, lvlup)=2pts, food3(+2)=4pts
- FOODS_PER_LEVEL = 2 (final production setting)
- Code is clean and production-ready
2025-10-30 23:12:51 +00:00
pastilhas f5886e5376 test: revert FOODS_PER_LEVEL back to 2 for final testing
- Change from 1 back to 2 for normal gameplay
- Now need 2 foods to level up instead of every food
- Score sequence should be: +1, +1, lvlup, +2, +2, lvlup, +3, +3, etc.
- Testing that score calculation works correctly with threshold of 2
2025-10-30 23:11:14 +00:00
pastilhas 804749ea53 fix(phase1.4): move level-up logic OUTSIDE setScore to prevent multiple triggers
- Call setLevel() BEFORE setScore(), not inside the callback
- This prevents setScore from being called multiple times per food
- Level up happens once, then score is updated with correct points
- Fixes: 1st food +1pt (lvl1), 2nd food +2pts (lvl2), 3rd food +3pts (lvl3)
- No more duplicate level ups on same food
2025-10-30 23:10:13 +00:00
pastilhas 1f654485ca fix(phase1.4): save current level BEFORE leveling up for score calculation
- Save pointsToAdd = levelRef.current at start of setScore
- Use saved value for scoring, not levelRef.current which gets changed
- This ensures 1st food adds 1 point at level 1, then level up to 2
- 2nd food adds 2 points at level 2, then level up to 3, etc.
- Correct sequence: +1, +2, +3, +4... with level ups after each
2025-10-30 23:07:51 +00:00
pastilhas c3ed497392 debug: revert speed to 5 FPS and add console.log for food/score tracking
- Reset INITIAL_FPS from 12 back to 5 for easier debugging
- Change FOODS_PER_LEVEL to 1 for easier threshold testing
- Add console.log to track foods eaten, level ups, and score changes
- Logs show: foods eaten, will level up flag, current level, score additions
- This will help debug the score calculation logic
2025-10-30 23:06:04 +00:00
pastilhas 01526b8cd8 fix(phase1.4): check level-up threshold BEFORE incrementing food counter
- Calculate willLevelUp BEFORE foodsEatenRef.current += 1
- This way the 2nd food that triggers level up is still worth 1 point
- Only AFTER eating it do we level up to 2
- Correct: eat food1(+1)=1pt, eat food2(+1, then lvlup)=2pts, eat food3(+2)=4pts
- Issue was checking >= threshold AFTER incrementing, causing wrong level calculation
2025-10-30 23:02:26 +00:00
pastilhas e5b18b814f fix(phase1.4): correct score calculation - food worth CURRENT level, level up AFTER
- Add points at CURRENT level FIRST
- THEN check if we should level up for NEXT food
- Food that triggers level up is worth old level points, not new
- Example: eat food 1 (+1), eat food 2 (+1, now level up), eat food 3 (+2)
- Correct scoring: 1 + 1 = 2 points at level 1, then 2 + 2 = 4 at level 2
2025-10-30 23:00:55 +00:00
pastilhas 07e3b2071c fix(phase1.4): fix level-up timing in score calculation
- Level up BEFORE adding points, not after
- When foodsEatenRef reaches threshold:
  1. Increment level first
  2. Reset food counter
  3. THEN add points at new level
- Correct flow: eat 2 foods at level 1 (+1,+1=2pts), level up, next food worth +2pts
- Was: eat at level 1, level up happens, get 2pts (wrong level)
- Now: eat at level 1, eat at level 1, level up, next food gets 2pts (correct)
2025-10-30 23:00:06 +00:00
pastilhas 6926a080f6 fix(phase1.4): fix score calculation - remove wrong decrement on level up
- Remove the buggy 'newScore--' line that was penalizing level ups
- Score now correctly accumulates: each food = (+1 * current_level) points
- Level 1: 1 food = +1 point
- Level 2: 1 food = +2 points
- Level 3: 1 food = +3 points, etc.
- No penalty on leveling up, just speed increase
- Score calculation now makes intuitive sense
2025-10-30 22:54:34 +00:00
pastilhas b671c7452c refactor(phase1.3): remove old duplicate hook files
- Delete src/useGame/useSnake.ts (replaced by src/useCursor/useCursor.ts)
- Delete src/useGame/useRenderer.ts (replaced by src/useBoard/useBoard.ts)
- Delete src/useGame/useGameStatus.ts (replaced by src/useGameStatus/useGameStatus.ts)
- Update useFood.ts to import from useBoard instead of useRenderer
- Fix TypeScript type annotations in useFood.ts
- Cleaner codebase with no duplicate implementations
- Build and example app still work correctly
2025-10-30 22:52:40 +00:00
pastilhas c5bd51d96b test: increase initial snake size to 6 for easier testing
- Change initial snake length from 3 to 6 segments
- Makes it easier to test turning mechanics and buffering
- Better visibility of snake movement patterns
- Can be reverted once testing is complete
2025-10-30 22:48:42 +00:00
pastilhas a3c9f201be test: increase initial game speed to 12 FPS for easier testing
- Change INITIAL_FPS from 5 to 12 for faster gameplay
- Makes it easier to test key buffering at higher speeds
- Can be reverted once testing is complete
2025-10-30 22:47:49 +00:00
pastilhas c803df242a fix(phase1.2b): apply buffered direction BEFORE movement, not after
- Move applyBufferedDirection() to execute before moveSnake()
- This ensures buffered input is used for the current frame's movement
- Allows multi-frame 180° turns (down then left, for example)
- Snake can turn in any valid direction across frames
- Fixes the 180° reversal restriction issue
2025-10-30 22:46:20 +00:00
pastilhas 4b0e386691 fix(phase1.2b): adjust key buffer logic to allow 180° reversals
- Change buffer validation from lastMovedDirection to currentDirection
- This allows 180° reversals across frames (they're safe if you have space)
- Only blocks immediate 180° within same frame (would cause self-collision)
- Removes overly restrictive direction blocking
- Player can now freely turn in any direction between moves
- Should fix the 'impossible to turn' and 'immediate death' issues
2025-10-30 22:41:52 +00:00
pastilhas 762bc86878 feat(phase1.2b): implement Nokia-style key buffering system
- Add nextDirectionRef to buffer player input
- Update changeDirection() to queue input instead of immediate execution
- Add applyBufferedDirection() to safely apply buffered input
- Buffer prevents 180° reversals for safe turns
- Call applyBufferedDirection() after each successful move in game loop
- Remove collision grace period - no longer needed with key buffering
- Remove collisionGracePeriodRef and related logic
- Clean up all console.log statements from useGameStatus
- Game now feels responsive at high speeds
- Allows pre-emptive turning on board edges (Nokia Snake style)
- Build and example app work correctly
2025-10-30 22:39:21 +00:00
pastilhas 5c398b556f feat(phase1.2): fix GameManager interface to match Unified API
- Create comprehensive types.ts with all required manager interfaces
- Define GameManager with proper Unified API compliance
- Implement CursorManager interface in useCursor with VIM motions
- Add SnakeCursorManager type with snake-specific extensions
- Update useGame to return proper GameManager interface
- Support both old (cols, rows) and new (options) signatures
- Add quitGame alias for stopGame in useGameStatus
- Wrap renderBoard to match Unified API signature (no parameters)
- Add placeholder for totalKeystrokes and finalScore in ScoreManager
- All TypeScript builds successfully
- Example app builds without errors
2025-10-30 22:22:03 +00:00
pastilhas dcaa93ea08 feat(phase1.1): create hook module structure with proper exports
- Create new hook modules: useBoard, useCursor, useGameStatus
- Move/copy hook implementations to their own directories
- Create index.ts files for clean module exports
- Update all imports to use new module locations
- Rename useSnake -> useCursor for Unified API alignment
- Rename useRenderer -> useBoard for clarity
- Update main src/index.ts to export from all hook modules
- All TypeScript builds successfully
- Example app remains functional
2025-10-30 22:16:13 +00:00
pastilhas 2b3a55df37 before Unified API 2025-10-30 22:14:04 +00:00
pastilhas 4a416ade41 32px cells 2025-10-16 17:56:01 +01:00
pastilhas 835f68de72 food score 2025-10-16 17:50:53 +01:00
pastilhas d02a8e9618 working on levels 2025-10-16 17:18:31 +01:00
pastilhas e4f5be1a56 food! 2025-10-16 16:22:09 +01:00
pastilhas fede770c61 snake personality... 2025-10-16 13:49:22 +01:00
pastilhas cbb8cce833 snake personality... 2025-10-16 13:39:35 +01:00
pastilhas f37605d8d2 snake moving, changing directions, wall collision working 2025-10-16 13:30:26 +01:00
pastilhas 20ac6b9349 proper keybindings 2025-10-16 13:21:22 +01:00
pastilhas 6a3cfad409 game start/stop, snake rendered on board 2025-10-16 12:56:15 +01:00
pastilhas 39dde6e5e6 prepared for publish 0.1.0 2025-10-16 12:32:35 +01:00
pastilhas 892e85ecf5 board consumed in example 2025-10-16 12:25:52 +01:00