Skip to content

Commit 5356b36

Browse files
author
MelonSpeedruns
committed
Gamepad Color Implementation
1 parent 248723d commit 5356b36

3 files changed

Lines changed: 112 additions & 0 deletions

File tree

include/d/actor/d_a_alink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4549,6 +4549,7 @@ class daAlink_c : public daPy_py_c {
45494549
/* 0x03850 */ daAlink_procFunc mpProcFunc;
45504550

45514551
#if TARGET_PC
4552+
void handleGamepadColor();
45524553
void handleWolfHowl();
45534554
void handleQuickTransform();
45544555
bool checkGyroAimItemContext();

src/d/actor/d_a_alink_dusk.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,113 @@
44
#include "d/d_meter2_draw.h"
55
#include "d/d_meter2_info.h"
66

7+
cXyz currentGamepadColor = {0, 0, 0};
8+
cXyz finalGamepadColor = {0, 0, 0};
9+
float lerpSpeed = 0.0f;
10+
const cXyz duskColor = {30, 30, -30};
11+
12+
const cXyz heartColor1 = {255, 0, 0};
13+
const cXyz heartColor2 = {155, 5, 5};
14+
const cXyz heartColor3 = {55, 5, 5};
15+
16+
float lerp(float a, float b, float t) {
17+
return a + t * (b - a);
18+
}
19+
20+
cXyz LerpColor(cXyz a, cXyz b, float t) {
21+
return {lerp(a.x, b.x, t), lerp(a.y, b.y, t), lerp(a.z, b.z, t)};
22+
}
23+
24+
void FadeLED(cXyz newColor, float speed) {
25+
finalGamepadColor = newColor;
26+
lerpSpeed = speed / 30.0f;
27+
}
28+
29+
void SetLED(cXyz newColor) {
30+
currentGamepadColor = newColor;
31+
finalGamepadColor = newColor;
32+
}
33+
34+
void AddGamepadCurrentColor(cXyz addColor) {
35+
finalGamepadColor.x += addColor.x;
36+
finalGamepadColor.y += addColor.y;
37+
finalGamepadColor.z += addColor.z;
38+
}
39+
40+
void daAlink_c::handleGamepadColor() {
41+
bool setColor = false;
42+
43+
fopAc_ac_c* zhint = dComIfGp_att_getZHint();
44+
if (zhint != NULL) {
45+
FadeLED({50, 50, 175}, 2.0f);
46+
setColor = true;
47+
}
48+
49+
u8 linkHp = Z2GetLink()->getLinkHp();
50+
if (linkHp <= 2) {
51+
FadeLED(heartColor1, 2.0f);
52+
setColor = true;
53+
} else if (linkHp <= 4) {
54+
FadeLED(heartColor2, 2.0f);
55+
setColor = true;
56+
} else if (linkHp <= 6) {
57+
FadeLED(heartColor3, 2.0f);
58+
setColor = true;
59+
}
60+
61+
if (!setColor) {
62+
if (checkWolf()) {
63+
FadeLED({115, 115, 75}, 5.0f);
64+
setColor = true;
65+
} else {
66+
switch (dComIfGs_getSelectEquipClothes()) {
67+
case dItemNo_WEAR_KOKIRI_e:
68+
FadeLED({0, 100, 0}, 5.0f);
69+
setColor = true;
70+
break;
71+
case dItemNo_WEAR_ZORA_e:
72+
FadeLED({0, 0, 100}, 5.0f);
73+
setColor = true;
74+
break;
75+
case dItemNo_ARMOR_e:
76+
if (checkMagicArmorHeavy()) {
77+
FadeLED({5, 100, 100}, 5.0f);
78+
} else {
79+
FadeLED({100, 0, 5}, 5.0f);
80+
}
81+
setColor = true;
82+
break;
83+
default:
84+
FadeLED({235, 230, 115}, 5.0f);
85+
setColor = true;
86+
break;
87+
}
88+
}
89+
}
90+
91+
if (dKy_darkworld_check()) {
92+
AddGamepadCurrentColor(duskColor);
93+
}
94+
95+
if (finalGamepadColor.x > 255)
96+
finalGamepadColor.x = 255;
97+
if (finalGamepadColor.x < 0)
98+
finalGamepadColor.x = 0;
99+
100+
if (finalGamepadColor.y > 255)
101+
finalGamepadColor.y = 255;
102+
if (finalGamepadColor.y < 0)
103+
finalGamepadColor.y = 0;
104+
105+
if (finalGamepadColor.z > 255)
106+
finalGamepadColor.z = 255;
107+
if (finalGamepadColor.z < 0)
108+
finalGamepadColor.z = 0;
109+
110+
currentGamepadColor = LerpColor(currentGamepadColor, finalGamepadColor, lerpSpeed);
111+
PADSetColor(PAD_1, (u8)currentGamepadColor.x, (u8)currentGamepadColor.y, (u8)currentGamepadColor.z);
112+
}
113+
7114
void daAlink_c::handleWolfHowl() {
8115
if (checkWolf()) {
9116
if (!dusk::getSettings().game.sunsSong) {

src/f_ap/f_ap_game.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ void fapGm_Execute() {
748748
#endif
749749

750750
#if TARGET_PC
751+
if (const auto link = g_dComIfG_gameInfo.play.getPlayer(0)) {
752+
dynamic_cast<daAlink_c*>(link)->handleGamepadColor();
753+
}
754+
751755
if (mDoCPd_c::getHoldR(PAD_1) && mDoCPd_c::getTrigX(PAD_1)) {
752756
if (const auto link = g_dComIfG_gameInfo.play.getPlayer(0)) {
753757
dynamic_cast<daAlink_c*>(link)->handleWolfHowl();

0 commit comments

Comments
 (0)