Closed vlazic closed 11 months ago
Please update movement mapping so when two keys are pressed the plane is shown diagonally as it exists currently.
Please update movement mapping so when two keys are pressed the plane is shown diagonally as it exists currently.
Done :)
I removed DIAGONAL_SPEED_MULTIPLIER and the movement from diagonals because it was stacking on top of the movement already being made.
Summary of Changes:
Introduced Constants for Keys: Moved hardcoded keys to a constant dictionary
KEYS
for better readability and easier future modifications.Centralized Movement and Rotation: Implemented a unified
moveAndRotate
function to handle both movement and rotation, reducing repetition and improving code clarity.Optimized Key Event Handlers:
registerKeyPress
andderegisterKeyPress
) for better organization.formatKey
function to streamline the key formatting process, ensuring uniformity.Mapped Keys to Movements: Created a
movementMapping
dictionary to associate keys with their corresponding movement functions, enabling easier modifications and additions in the future.Enhanced Game Loop:
needsRedraw
flag in the game loop, ensuring the canvas redraws only when there's a change.By implementing these changes, the
Controls.js
file is now more structured, efficient, and easily extensible for future updates.