I’m building an Anime Desktop Mascot program for Windows and need some help with rewriting some code.
This code tracks cursor movement so I can calculate its speed, so I need to track X & Y movement.
Do you see any way I can merge the two blocks? Also, is there a better practice for declaring many variables at once?
bool calculateNewSpeedX = true; bool calculateNewSpeedY = true; int cursorSpeedTimerX; int cursorSpeedTimerY; int initialCursorPosX; int initialCursorPosY; int lastCursorPosX; int lastCursorPosY; int curCursorPosX; int curCursorPosY; private void TrackCursorMovement() { curCursorPosX = Cursor.Position.X; curCursorPosY = Cursor.Position.Y; cursorSpeedTimerX++; cursorSpeedTimerY++; // X Axis if (calculateNewSpeedX) { calculateNewSpeedX = false; initialCursorPosX = curCursorPosX; cursorSpeedTimerX = 1; } else { if (curCursorPosX != lastCursorPosX) { lastCursorPosX = curCursorPosX; } else { calculateNewSpeedX = true; } } // Y-AXIS if (calculateNewSpeedY) { calculateNewSpeedY = false; initialCursorPosY = curCursorPosY; cursorSpeedTimerY = 1; } else { if (curCursorPosY != lastCursorPosY) { lastCursorPosY = curCursorPosY; } else { calculateNewSpeedY = true; } } }