Skip to content

fix: clamp sprite wall collisions - #28

Open
saurabhhhcodes wants to merge 1 commit into
dishu4u:mainfrom
saurabhhhcodes:fix/collision-resolution-6
Open

fix: clamp sprite wall collisions#28
saurabhhhcodes wants to merge 1 commit into
dishu4u:mainfrom
saurabhhhcodes:fix/collision-resolution-6

Conversation

@saurabhhhcodes

Copy link
Copy Markdown

Summary

  • snap Pac-Man and ghosts flush to wall edges after collision
  • stop processing additional wall collisions after a direction probe is rejected
  • clamp ghosts at horizontal board boundaries before choosing a new direction

Root Cause

The movement code handled wall collisions by subtracting the current velocity. That works for perfectly step-aligned movement, but if a sprite is already partially overlapping a wall, the rollback can leave it embedded or jittering against the obstacle.

Changes Made

  • added a shared wall-collision resolver that clamps the moving block to the contacted wall edge based on travel direction
  • reused the resolver for Pac-Man movement, ghost movement, and direction-change probes
  • separated ghost wall collision handling from board-boundary handling so only one movement correction is applied per frame

Testing

  • git -c core.whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol diff --check
  • javac pacman-java/App.java pacman-java/PacMan.java could not run because this macOS environment has Java command shims but no installed Java runtime

Impact

Player and ghost movement no longer relies on simple velocity rollback, reducing wall clipping and inconsistent ghost collision behavior while preserving the existing tile speed and direction choices.

Fixes #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Collision Detection Bugs

1 participant