summaryrefslogtreecommitdiff
path: root/src/challengeStar.cpp
diff options
context:
space:
mode:
authorColin Noga <Tempus@chronometry.ca>2012-03-20 17:03:19 -0500
committerColin Noga <Tempus@chronometry.ca>2012-03-20 17:03:19 -0500
commita550f21ec661ddd8771a9c779f2b784209fee1f9 (patch)
treeb6afe90fa01765019f0aad4e8068970c2ec36ae8 /src/challengeStar.cpp
parent58b4ab236f6e4b0b5c4cf8384a3a8be299c86623 (diff)
downloadkamek-a550f21ec661ddd8771a9c779f2b784209fee1f9.tar.gz
kamek-a550f21ec661ddd8771a9c779f2b784209fee1f9.zip
Added challenge star, clown car junk, bowser improvements, some fixes here and there, and a roll your own model sprite for skawo.
Diffstat (limited to 'src/challengeStar.cpp')
-rw-r--r--src/challengeStar.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/challengeStar.cpp b/src/challengeStar.cpp
new file mode 100644
index 0000000..fc710d4
--- /dev/null
+++ b/src/challengeStar.cpp
@@ -0,0 +1,130 @@
+#include <common.h>
+#include <game.h>
+#include <g3dhax.h>
+#include <sfx.h>
+
+
+extern "C" void *PlaySound(dEn_c *, int soundID);
+extern "C" bool SpawnEffect(const char*, int, Vec*, S16Vec*, Vec*);
+
+extern int GlobalStarsCollected;
+
+struct EventTable_t { u64 events; };
+extern EventTable_t *EventTable;
+
+
+class dChallengeStar : public dEn_c {
+ int onCreate();
+ int onExecute();
+ int onDelete();
+ int onDraw();
+
+ mHeapAllocator_c allocator;
+ m3d::mdl_c bodyModel;
+
+ mEf::es2 effect;
+
+ u64 eventFlag;
+ s32 timer;
+
+ static dChallengeStar *build();
+
+ void updateModelMatrices();
+ void playerCollision(ActivePhysics *apThis, ActivePhysics *apOther);
+ void yoshiCollision(ActivePhysics *apThis, ActivePhysics *apOther);
+
+ void collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther);
+
+};
+
+
+void dChallengeStar::playerCollision(ActivePhysics *apThis, ActivePhysics *apOther) {
+ PlaySound(this, SE_OBJ_BROOM_KEY_SHOW);
+ SpawnEffect("Wm_ob_greencoinkira_a", 0, &this->pos, &(S16Vec){0,0,0}, &(Vec){0.8, 0.8, 0.8});
+
+ GlobalStarsCollected++;
+ if (GlobalStarsCollected == 50) {
+ GlobalStarsCollected = 0;
+ EventTable->events = EventTable->events | this->eventFlag;
+ }
+
+ this->Delete(this->_390);
+}
+
+void dChallengeStar::yoshiCollision(ActivePhysics *apThis, ActivePhysics *apOther) { this->playerCollision(apThis, apOther); }
+void dChallengeStar::collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther) { this->playerCollision(apThis, apOther); }
+
+
+dChallengeStar *dChallengeStar::build() {
+ void *buffer = AllocFromGameHeap1(sizeof(dChallengeStar));
+ return new(buffer) dChallengeStar;
+}
+
+
+int dChallengeStar::onCreate() {
+
+ OSReport("Creating a star collectable\n");
+ allocator.link(-1, GameHeaps[0], 0, 0x20);
+
+ nw4r::g3d::ResFile rf(getResource("I_star", "g3d/I_star.brres"));
+ bodyModel.setup(rf.GetResMdl("I_star"), &allocator, 0x224, 1, 0);
+ SetupTextures_Map(&bodyModel, 0);
+
+ allocator.unlink();
+
+ ActivePhysics::Info HitMeBaby;
+ HitMeBaby.xDistToCenter = 0.0;
+ HitMeBaby.yDistToCenter = -3.0;
+ HitMeBaby.xDistToEdge = 4.0;
+ HitMeBaby.yDistToEdge = 4.0;
+ HitMeBaby.category1 = 0x5;
+ HitMeBaby.category2 = 0x0;
+ HitMeBaby.bitfield1 = 0x4F;
+ HitMeBaby.bitfield2 = 0xFFFFFFFF;
+ HitMeBaby.unkShort1C = 0;
+ HitMeBaby.callback = &dEn_c::collisionCallback;
+
+ this->aPhysics.initWithStruct(this, &HitMeBaby);
+ this->aPhysics.addToList();
+
+ char eventNum = (this->settings >> 24) & 0xFF;
+ this->eventFlag = (u64)1 << (eventNum - 1);
+
+ this->scale.x = 0.5;
+ this->scale.y = 0.5;
+ this->scale.z = 0.5;
+
+ this->pos.z = 3300.0;
+
+ this->onExecute();
+ return true;
+}
+
+
+int dChallengeStar::onDelete() {
+ return true;
+}
+
+int dChallengeStar::onDraw() {
+ bodyModel.scheduleForDrawing();
+ return true;
+}
+
+
+void dChallengeStar::updateModelMatrices() {
+ matrix.translation(pos.x, pos.y, pos.z);
+ matrix.applyRotationYXZ(&rot.x, &rot.y, &rot.z);
+
+ bodyModel.setDrawMatrix(matrix);
+ bodyModel.setScale(&scale);
+ bodyModel.calcWorld(false);
+}
+
+int dChallengeStar::onExecute() {
+ updateModelMatrices();
+
+ effect.spawn("Wm_ob_keyget02_kira", 0, &this->pos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0});
+ this->rot.y += 0x200;
+ return true;
+}
+