-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarChip.cpp
More file actions
136 lines (111 loc) · 2.63 KB
/
StarChip.cpp
File metadata and controls
136 lines (111 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "StarChip.h"
#include "LaunchStar.h"
#include "MOM_IDs.h"
constexpr Fix12i RADIUS = 0x64000_f;
constexpr Fix12i HEIGHT = 0x64000_f;
constexpr short int ROT_SPEED = 0x300;
constexpr short int ACTOR_ID = 0x191;
constexpr short int OBJECT_ID = 0x191;
constinit SharedFilePtr StarChip::modelFile;
constinit SpawnInfo StarChip::spawnData =
{
[]() -> ActorBase* { return new StarChip; },
0x0030,
0x0100,
0x00000002,
0x00064'000_f,
0x000c8'000_f,
Fix12i::max,
Fix12i::max
};
void StarChip::UpdateModelTransform()
{
model.mat4x3 = Matrix4x3::RotationY(ang.y);
model.mat4x3.c3 = pos >> 3;
DropShadowRadHeight(shadow, model.mat4x3, 0x50000_f, 0x137000_f, 0xc);
}
int& StarChip::GetChipCounter()
{
static constinit std::array<int, 3> counters;
if (LEVEL_ID == 40)
return counters[eventID - 1];
else
return counters[0];
}
int StarChip::InitResources()
{
model.SetFile(modelFile.LoadBMD(), 1, -1);
shadow.InitCylinder();
UpdateModelTransform();
UpdateClsnPosAndRot();
shadowMat = model.mat4x3;
shadowMat.c3.y -= 20._f >> 3;
cylClsn.Init(this, RADIUS, HEIGHT, 0x00100002, 0x8000);
eventID = param1 & 0xff;
GetChipCounter() = 0;
colorID = (1 <= eventID && eventID <= 3) ? eventID + 1 : 0;
const LaunchStar::Color& color = LaunchStar::colors[colorID];
model.data.materials[0].difAmb = color.difAmb;
model.data.materials[0].speEmi = color.speEmi;
// enable light 1 and disable light 0 in the final boss level
if (LEVEL_ID == 40) (model.data.materials[0].polygonAttr &= ~1) |= 2;
return 1;
}
int StarChip::CleanupResources()
{
modelFile.Release();
return 1;
}
int StarChip::Behavior()
{
ang.y += ROT_SPEED;
UpdateModelTransform();
HandleClsn();
cylClsn.Clear();
cylClsn.Update();
return 1;
}
int StarChip::Render()
{
if (!(flags & Actor::IN_YOSHI_MOUTH))
model.Render(nullptr);
return 1;
}
void StarChip::HandleClsn() {
Actor* other = Actor::FindWithID(cylClsn.otherObjID);
if(!other)
return;
if(other->actorID != 0x00bf)
return;
unsigned hitFlags = cylClsn.hitFlags;
if ((hitFlags & 0x8000) == 0 && killable) {
Kill();
} else {
killable = false;
}
}
void StarChip::OnTurnIntoEgg(Player& player)
{
Kill();
MarkForDestruction();
}
unsigned StarChip::OnYoshiTryEat()
{
return Actor::YE_SWALLOW;
}
void StarChip::Kill()
{
int& chipCounter = GetChipCounter();
chipCounter++;
Particle::System::NewSimple(0xD2, pos.x, pos.y + 0x28000_f, pos.z);
pos.y += 180._f;
SpawnNumber(pos, chipCounter | std::max<unsigned>(colorID, 1) << 8, false, 0);
Sound::Play(4, 3, camSpacePos);
if (chipCounter >= 5)
{
Event::SetBit(eventID);
chipCounter = 0;
}
KillAndTrackInDeathTable();
UntrackInDeathTable();
}