summaryrefslogtreecommitdiff
path: root/src/koopatlas
diff options
context:
space:
mode:
Diffstat (limited to 'src/koopatlas')
-rw-r--r--src/koopatlas/pathmanager.cpp125
-rw-r--r--src/koopatlas/pathmanager.h4
2 files changed, 92 insertions, 37 deletions
diff --git a/src/koopatlas/pathmanager.cpp b/src/koopatlas/pathmanager.cpp
index 0238cc7..acf8995 100644
--- a/src/koopatlas/pathmanager.cpp
+++ b/src/koopatlas/pathmanager.cpp
@@ -272,7 +272,7 @@ void dWMPathManager_c::unlockPaths() {
// now set all node alphas
for (int i = 0; i < pathLayer->nodeCount; i++) {
dKPNode_s *node = pathLayer->nodes[i];
-
+
node->setLayerAlpha((node->isUnlocked() & !node->isNew) ? 255 : 0);
}
@@ -341,6 +341,9 @@ bool dWMPathManager_c::doingThings() {
(countdownToFadeIn > 0))
return true;
+ if (isMoving)
+ return true;
+
return false;
}
@@ -380,7 +383,7 @@ void dWMPathManager_c::execute() {
for (int i = 0; i < pathLayer->nodeCount; i++) {
dKPNode_s *node = pathLayer->nodes[i];
-
+
if (node->isNew)
node->setLayerAlpha(unlockingAlpha);
}
@@ -444,19 +447,18 @@ void dWMPathManager_c::execute() {
int nowPressed = Remocon_GetPressed(GetActiveRemocon());
+ // Left, right, up, down
+ int pressedDir = -1;
+ if (nowPressed & WPAD_LEFT) pressedDir = 0;
+ else if (nowPressed & WPAD_RIGHT) pressedDir = 1;
+ else if (nowPressed & WPAD_UP) pressedDir = 2;
+ else if (nowPressed & WPAD_DOWN) pressedDir = 3;
+
if (isMoving) {
- moveThroughPath();
+ moveThroughPath(pressedDir);
} else {
- // Left, right, up, down
- int pressedDir = -1;
- if (nowPressed & WPAD_LEFT) pressedDir = 0;
- else if (nowPressed & WPAD_RIGHT) pressedDir = 1;
- else if (nowPressed & WPAD_UP) pressedDir = 2;
- else if (nowPressed & WPAD_DOWN) pressedDir = 3;
- else if (nowPressed & WPAD_TWO)
- activatePoint();
-
if (pressedDir >= 0) {
+ // Use an exit if possible
if (canUseExit(currentNode->exits[pressedDir])) {
startMovementTo(currentNode->exits[pressedDir]);
} else {
@@ -464,6 +466,8 @@ void dWMPathManager_c::execute() {
static u16 directions[] = {-0x4000,0x4000,-0x7FFF,0};
daWMPlayer_c::instance->rot.y = directions[pressedDir];
}
+ } else if (nowPressed & WPAD_TWO) {
+ activatePoint();
}
}
}
@@ -494,7 +498,7 @@ void dWMPathManager_c::startMovementTo(dKPPath_s *path) {
SpammyReport("e\n");
if (reverseThroughPath) {
- SpammyReport("e2\n");
+ SpammyReport("e2\n");
direction += 0x8000;
}
@@ -564,6 +568,7 @@ void dWMPathManager_c::startMovementTo(dKPPath_s *path) {
if (path->animation == dKPPath_s::ENTER_CAVE_UP) {
scaleAnimProgress = 60;
// what direction does this path go in?
+ static u16 directions[] = {-0x4000,0x4000,-0x7FFF,0};
isScalingUp = (deltaY < 0) ^ reverseThroughPath;
if (!isScalingUp)
@@ -577,7 +582,13 @@ void dWMPathManager_c::startMovementTo(dKPPath_s *path) {
player->startAnimation(Animations[id].anim, Animations[id].animParam1, Animations[id].animParam2, 0.0f);
- player->rot.y = (Animations[id].forceRotation != -1) ? Animations[id].forceRotation : direction;
+ if (Animations[id].forceRotation != -1) {
+ forcedRotation = true;
+ player->rot.y = Animations[id].forceRotation;
+ } else {
+ forcedRotation = false;
+ player->rot.y = direction;
+ }
moveSpeed = (Animations[id].forceSpeed >= 0.0f) ? Animations[id].forceSpeed : 3.0f;
moveSpeed = path->speed * moveSpeed;
@@ -611,7 +622,7 @@ void dWMPathManager_c::startMovementTo(dKPPath_s *path) {
}
}
-void dWMPathManager_c::moveThroughPath() {
+void dWMPathManager_c::moveThroughPath(int pressedDir) {
dKPNode_s *from, *to;
from = reverseThroughPath ? currentPath->end : currentPath->start;
@@ -619,6 +630,48 @@ void dWMPathManager_c::moveThroughPath() {
daWMPlayer_c *player = daWMPlayer_c::instance;
+ if (pressedDir >= 0) {
+ int whatDirDegrees = ((int)(atan2(to->x-from->x, to->y-from->y) / ((M_PI * 2) / 360.0)) + 360) % 360;
+ // dirs are: left, right, up, down
+ int whatDir;
+ if (whatDirDegrees >= 225 && whatDirDegrees <= 315)
+ whatDir = 1; // moving Left, so reversing requires Right
+ else if (whatDirDegrees >= 45 && whatDirDegrees <= 135)
+ whatDir = 0; // moving Right, so reversing requires Left
+ else if (whatDirDegrees > 135 && whatDirDegrees < 225)
+ whatDir = 3; // moving Up, so reversing requires Down
+ else if (whatDirDegrees > 315 || whatDirDegrees < 45)
+ whatDir = 2; // moving Down, so reversing requires Up
+ OSReport("Delta: %d, %d; Degrees: %d (Atan result is %f); Calced dir is %d; Pressed dir is %d\n", to->x-from->x, to->y-from->y, whatDirDegrees, atan2(to->x-from->x,to->y-from->y), whatDir, pressedDir);
+
+ if (whatDir == pressedDir) {
+ // are we using a forbidden animation?
+ static const dKPPath_s::Animation forbidden[] = {
+ dKPPath_s::JUMP, dKPPath_s::JUMP_SAND,
+ dKPPath_s::JUMP_SNOW, dKPPath_s::JUMP_WATER,
+ dKPPath_s::PIPE, dKPPath_s::DOOR,
+ dKPPath_s::ENTER_CAVE_UP,
+ dKPPath_s::MAX_ANIM
+ };
+ bool allowed = true;
+ for (int i = 0;;i++) {
+ if (forbidden[i] == dKPPath_s::MAX_ANIM)
+ break;
+ if (forbidden[i] == currentPath->animation)
+ allowed = false;
+ }
+
+ if (allowed) {
+ reverseThroughPath = !reverseThroughPath;
+ if (!forcedRotation)
+ player->rot.y += 0x8000;
+ // start over with the reversed path!
+ moveThroughPath(-1);
+ return;
+ }
+ }
+ }
+
if (scaleAnimProgress >= 0) {
float soFar = scaleAnimProgress * (1.6f / 60.0f);
@@ -670,29 +723,29 @@ void dWMPathManager_c::moveThroughPath() {
// Check if we've reached the end yet
if (
(((move.x > 0) ? (player->pos.x >= to->x) : (player->pos.x <= to->x)) &&
- ((move.y > 0) ? (-player->pos.y >= to->y) : (-player->pos.y <= to->y)))
+ ((move.y > 0) ? (-player->pos.y >= to->y) : (-player->pos.y <= to->y)))
||
(from->x == to->x && from->y == to->y)
) {
- currentNode = to;
- player->pos.x = to->x;
- player->pos.y = -to->y;
+ currentNode = to;
+ player->pos.x = to->x;
+ player->pos.y = -to->y;
- isJumping = false;
- timer = 0.0;
+ isJumping = false;
+ timer = 0.0;
- SpammyReport("reached path end (%p) with type %d\n", to, to->type);
+ SpammyReport("reached path end (%p) with type %d\n", to, to->type);
- bool reallyStop = false;
+ bool reallyStop = false;
- if (to->type == dKPNode_s::LEVEL) {
- // Always stop on levels
- reallyStop = true;
- } else if (to->type == dKPNode_s::CHANGE || to->type == dKPNode_s::WORLD_CHANGE) {
+ if (to->type == dKPNode_s::LEVEL) {
+ // Always stop on levels
+ reallyStop = true;
+ } else if (to->type == dKPNode_s::CHANGE || to->type == dKPNode_s::WORLD_CHANGE) {
// Never stop on entrances or on world changes
reallyStop = false;
- } else if (to->type == dKPNode_s::PASS_THROUGH) {
+ } else if (to->type == dKPNode_s::PASS_THROUGH) {
// If there's only one exit here, then stop even though
// it's a passthrough node
reallyStop = (to->getAvailableExitCount() == 1);
@@ -701,7 +754,7 @@ void dWMPathManager_c::moveThroughPath() {
// If it's a junction with more than two exits, but only two are open,
// take the opposite open one
if (to->getExitCount() > 2 && to->getAvailableExitCount() == 2)
- reallyStop = false;
+ reallyStop = false;
else
reallyStop = true;
}
@@ -778,14 +831,14 @@ void dWMPathManager_c::moveThroughPath() {
DoSceneChange(WORLD_MAP, 0x10000000 | (to->foreignID << 20), 0);
} else if (reallyStop) {
- // Stop here
- player->startAnimation(0, 1.2, 10.0, 0.0);
- player->hasEffect = false;
- player->hasSound = false;
+ // Stop here
+ player->startAnimation(0, 1.2, 10.0, 0.0);
+ player->hasEffect = false;
+ player->hasSound = false;
- SpammyReport("stopping here\n");
+ SpammyReport("stopping here\n");
- isMoving = false;
+ isMoving = false;
SaveBlock *save = GetSaveFile()->GetBlock(-1);
save->current_path_node = pathLayer->findNodeID(to);
@@ -893,7 +946,7 @@ void dWMPathManager_c::unlockAllPaths(char type) {
// dKPNode_s *node = pathLayer->nodes[i];
// node->setupNodeExtra();
// }
-
+
}
diff --git a/src/koopatlas/pathmanager.h b/src/koopatlas/pathmanager.h
index 2a7ce46..18a08c9 100644
--- a/src/koopatlas/pathmanager.h
+++ b/src/koopatlas/pathmanager.h
@@ -28,7 +28,7 @@ class dWMPathManager_c {
}
void startMovementTo(dKPPath_s *path);
- void moveThroughPath();
+ void moveThroughPath(int pressedDir);
void activatePoint();
void unlockAllPaths(char type);
@@ -43,6 +43,8 @@ class dWMPathManager_c {
bool isJumping;
float moveSpeed;
+ bool forcedRotation;
+
int scaleAnimProgress;
bool isScalingUp;