Skip to content

Commit

Permalink
Changed how the new mouse movement works, so that one click starts mo…
Browse files Browse the repository at this point in the history
…vement, the next one stops it.
  • Loading branch information
lanceewing committed Mar 9, 2024
1 parent 20079eb commit f9ad3e9
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions core/src/main/java/com/agifans/agile/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ private void updateObjectDirections() {
}
}

/**
* For AGI games that do not use the AGI Mouse hack, AGILE provides a way to
* control ego via mouse clicks, where clicking starts moving in the direction
* of the click, and then clicking again stops movement. That is unless it is
* hold.key mode, in which case it simply follows where the mouse is while the
* button is down.
*
* @param holdKeyMode true if hold.key mode is active.
*
* @return
*/
private byte getMouseClickDirection(boolean holdKeyMode) {
byte direction = 0;

Expand All @@ -231,6 +242,13 @@ private byte getMouseClickDirection(boolean holdKeyMode) {
// If is not in hold.key mode, then we only continue if mouse button
// wasn't previously down.
if (holdKeyMode || (state.getOldMouseButton() == 0)) {

if (!holdKeyMode && (state.getVar(Defines.EGODIR) != 0)) {
// If ego is already moving, and it isn't hold key mode, then
// clicking will stop ego.
return (byte)state.getVar(Defines.EGODIR);
}

int mouseY = (state.getMouseY() - (state.pictureRow * 8));
int egoX = (state.ego.x + (state.ego.xSize() / 2));
int xDiff = (((state.getMouseX() - egoX) * 3) / 2);
Expand All @@ -240,24 +258,6 @@ private byte getMouseClickDirection(boolean holdKeyMode) {

if (distance > 3) {
// Convert heading to an AGI direction.
// LEFT: 3.14159
// -2.7488936
// LEFT/UP: -2.35619
// -1.9634954
// UP: -1.5707963267948966
// -1.178097
// RIGHT/UP: -0.785398
// -0.3926991
// RIGHT: 0.0
// 0.3926991
// RIGHT/DOWN: 0.785398
// 1.178097
// DOWN: 1.5707963267948966
// 1.9634954
// LEFT/DOWN: 2.35619
// 2.7488936
// LEFT: 3.14159

if (heading == 0) {
// Right
direction = 3;
Expand Down Expand Up @@ -309,15 +309,6 @@ else if (heading > -2.7488936) {
}
}
}

System.out.println(
"ego.x: " + egoX + ", " +
"ego.y: " + state.ego.y + ", " +
"mouseX: " + state.getMouseX() + ", " +
"mouseY: " + mouseY + ", " +
"heading: " + heading + ", " +
"distance: " + distance + ", " +
"direction: " + direction);
}
}

Expand Down

0 comments on commit f9ad3e9

Please sign in to comment.