Skip to content

Commit 7cb1b60

Browse files
committed
add DPad
1 parent b96e19f commit 7cb1b60

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/firefly.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,38 @@ Angle degrees(float a)
2121
return r;
2222
};
2323

24+
/// @brief Time in the number of samples.
2425
AudioTime samples(int32_t s)
2526
{
2627
struct AudioTime t = {s};
2728
return t;
2829
}
2930

31+
/// @brief Time in seconds.
3032
AudioTime seconds(int32_t s)
3133
{
3234
struct AudioTime t = {s * SAMPLE_RATE};
3335
return t;
3436
}
3537

38+
/// @brief Time in miliseconds.
3639
AudioTime miliseconds(int32_t s)
3740
{
3841
struct AudioTime t = {s * SAMPLE_RATE / 1000};
3942
return t;
4043
}
4144

45+
/// @brief Convert Pad to DPad.
46+
DPad pad_to_dpad(Pad pad)
47+
{
48+
DPad dpad = {
49+
.left = pad.x <= -100,
50+
.right = pad.x >= 100,
51+
.up = pad.y <= -100,
52+
.down = pad.y >= 100};
53+
return dpad;
54+
}
55+
4256
// -- GRAPHICS -- //
4357

4458
/// @brief Fill the whole frame with the given color.

src/firefly.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,20 @@ struct Pad
174174
};
175175
typedef struct Pad Pad;
176176

177+
/// @brief A classic 4-button representation of the Pad.
178+
struct DPad
179+
{
180+
/// @brief If the left segment of the Pad is pressed.
181+
bool left;
182+
/// @brief If the right segment of the Pad is pressed.
183+
bool right;
184+
/// @brief If the upper segment of the Pad is pressed.
185+
bool up;
186+
/// @brief If the lower segment of the Pad is pressed.
187+
bool down;
188+
};
189+
typedef struct DPad DPad;
190+
177191
/// @brief State of the buttons. True is pressed, false is released.
178192
struct Buttons
179193
{
@@ -316,6 +330,7 @@ Angle degrees(float a);
316330
AudioTime samples(int32_t s);
317331
AudioTime seconds(int32_t s);
318332
AudioTime miliseconds(int32_t s);
333+
DPad pad_to_dpad(Pad pad);
319334

320335
void clear_screen(Color c);
321336
void set_color(Color c, RGB v);

0 commit comments

Comments
 (0)