summaryrefslogtreecommitdiff
path: root/src/koopatlas/player.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/koopatlas/player.cpp71
1 files changed, 69 insertions, 2 deletions
diff --git a/src/koopatlas/player.cpp b/src/koopatlas/player.cpp
index a3e484a..3a736b4 100644
--- a/src/koopatlas/player.cpp
+++ b/src/koopatlas/player.cpp
@@ -1,4 +1,5 @@
#include "koopatlas/player.h"
+#include "koopatlas/subplayer.h"
daWMPlayer_c *daWMPlayer_c::instance;
@@ -17,8 +18,6 @@ int daWMPlayer_c::onCreate() {
rot = (S16Vec){0x1800,0,0};
scale = (Vec){1.6f,1.6f,1.6f};
- current_param = 0;
-
hasEffect = false;
hasSound = false;
step = false;
@@ -43,6 +42,38 @@ int daWMPlayer_c::onExecute() {
dScKoopatlas_c::instance->pathManager.execute();
+ // work out the Z positions first of all
+ struct ySortThing_s {
+ float y; int id;
+ };
+ ySortThing_s sorts[4];
+ sorts[0].y = pos.y;
+ sorts[0].id = 0;
+ for (int i = 1; i < 4; i++) {
+ sorts[i].y = stateHistory[i * SUBPLAYER_DISTANCE].pos.y;
+ sorts[i].id = i;
+ }
+
+ // bubble sort it with an algorithm from wikipedia
+ bool swapped;
+ do {
+ swapped = false;
+ for (int i = 1; i < 4; i++) {
+ if (sorts[i-1].y > sorts[i].y) {
+ ySortThing_s forSwap = sorts[i-1];
+ sorts[i-1] = sorts[i];
+ sorts[i] = forSwap;
+ swapped = true;
+ }
+ }
+ } while (swapped);
+
+ // then put together the positions
+ float chosenZPositions[4];
+ for (int i = 0; i < 4; i++)
+ chosenZPositions[sorts[i].id] = 3100.0f - (i * 25.0f);
+ pos.z = chosenZPositions[0];
+
this->modelHandler->update();
mMtx myMatrix;
@@ -70,6 +101,42 @@ int daWMPlayer_c::onExecute() {
if (timer > 12) { timer = 0; }
}
+ if (stateHistoryBuilt) {
+ for (int i = STATE_COUNT - 1; i >= 1; i--)
+ stateHistory[i] = stateHistory[i - 1];
+ }
+
+ state_s *st = &stateHistory[0];
+ st->pos = pos;
+ st->scale = scale;
+ st->rot = rot;
+ st->repeatedEffect = (hasEffect ? effectName : 0);
+ st->nowEffect = nextNowEffect;
+ st->repeatedSound = (hasSound ? soundName : 0);
+ st->nowSound = nextNowSound;
+ st->jumpOffset = jumpOffset;
+ st->anim = currentAnim;
+ st->animFrame = currentFrame;
+ st->animUnk = currentUnk;
+ st->animUpdateRate = currentUpdateRate;
+
+ if (!stateHistoryBuilt) {
+ for (int i = 1; i < STATE_COUNT; i++)
+ stateHistory[i] = stateHistory[0];
+ stateHistoryBuilt = true;
+ }
+
+ nextNowEffect = 0;
+ nextNowSound = 0;
+
+ for (int i = 0; i < 3; i++) {
+ daWMSubPlayer_c *sp = dScKoopatlas_c::instance->subPlayer[i];
+
+ state_s *st = &stateHistory[(i+1) * SUBPLAYER_DISTANCE];
+ st->pos.z = chosenZPositions[i+1];
+ sp->update(st);
+ }
+
return true;
}