#include "koopatlas/player.h" #include "koopatlas/subplayer.h" daWMPlayer_c *daWMPlayer_c::instance; int daWMPlayer_c::onCreate() { this->modelHandler = new dPlayerModelHandler_c(0); // loadModel(u8 player_id, int powerup_id, int unk); this->modelHandler->loadModel(0, 3, 2); this->modelHandler->mdlClass->startAnimation(0, 1.2, 10.0, 0.0); this->modelHandler->setSRT((Vec){0.0,100.0,-100.0}, (S16Vec){0,0,0}, (Vec){2.0,2.0,2.0}); this->modelHandler->draw(); hammerSuit.setup(this->modelHandler); pos = (Vec){0.0f,0.0f,3000.0f}; rot = (S16Vec){0x1800,0,0}; scale = (Vec){1.6f,1.6f,1.6f}; hasEffect = false; hasSound = false; step = false; effectName = ""; soundName = 0; timer = 0; jumpOffset = 0.0; return true; } int daWMPlayer_c::onDelete() { delete modelHandler; return true; } int daWMPlayer_c::onExecute() { if (!dScKoopatlas_c::instance->mapIsRunning()) return true; 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; myMatrix.scale(scale.x, scale.y, scale.z); myMatrix.applyTranslation(pos.x, pos.y + jumpOffset, pos.z); myMatrix.applyRotationX(&rot.x); myMatrix.applyRotationY(&rot.y); // Z is unused for now modelHandler->setMatrix(myMatrix); if (hasEffect) { Vec effPos = {pos.x, pos.y, 3300.0f}; effect.spawn(effectName, 0, &effPos, &rot, &scale); } if (hasSound) { timer++; if (timer == 12) { if (step) { MapSoundPlayer(SoundRelatedClass, soundName, 1); step = false; } else { MapSoundPlayer(SoundRelatedClass, soundName+1, 1); step = true; } timer = 0; } 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; } int daWMPlayer_c::onDraw() { if (!visible) return true; this->modelHandler->draw(); hammerSuit.draw(); return true; } void daWMPlayer_c::startAnimation(int id, float frame, float unk, float updateRate) { if (id == currentAnim && frame == currentFrame && unk == currentUnk && updateRate == currentUpdateRate) return; currentAnim = id; currentFrame = frame; currentUnk = unk; currentUpdateRate = updateRate; this->modelHandler->mdlClass->startAnimation(id, frame, unk, updateRate); } daWMPlayer_c *daWMPlayer_c::build() { void *buffer = AllocFromGameHeap1(sizeof(daWMPlayer_c)); daWMPlayer_c *c = new(buffer) daWMPlayer_c; instance = c; return c; }