-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(drawing): Create the display system #3
base: prototype
Are you sure you want to change the base?
Changes from 1 commit
676af58
e9b8951
1a9e264
e3179e0
981fd49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,32 @@ | ||
#include <raylib.h> | ||
#include <raymath.h> | ||
|
||
typedef struct Effect { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Effect struct is not very generalized in comparison to its name. Any plans for an effect system? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, field names are a little meaningless atm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'll probably make more structs and think about how I should format it . It really depends what I want to add. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If its a type, then you might wanna consider enum example from my repo. Also, idk if center or top left is better. Cause for most elements other than circle, they normally go top left? But, the circle can just use the same vector struct as the center? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, true... :v
I'll use a struct instead bc I have to keep track of other stuff as well like innerRadius and outerRadius for the one i have right now to animate it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does something like this work for you, or is this not flexible enough? (tagged unions) struct Effect {
enum {
EFFECT_RING,
EFFECT_TRANSLATE,
} type;
double completion; /* range: [0, 1] */
union {
struct {
int startInnerRadius;
int startOuterRadius;
int endInnerRadius;
int endOuterRadius;
} ring;
struct {
Vector2 startPosition;
Vector2 endPosition;
} translate;
} data;
}; If you dont like duplication? union EffectData {
struct {
int innerRadius;
int outerRadius;
} ring;
struct {
Vector2 position;
} translate;
};
struct Effect {
enum {
EFFECT_RING,
EFFECT_TRANSLATE,
} type;
double completion; /* range: [0, 1] */
union EffectData startData;
union EffectData endData;
}; |
||
Vector2 vector; | ||
int innerRadius; | ||
int outerRadius; | ||
char exist; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use |
||
} Effect; | ||
|
||
void spawnEffect(Effect *e, Vector2 v) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am currently using snakecase for my functions, we need a consensus on that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Only for functions? Should we use another naming convention like camelCase for fields and other stuff? Or should we just make it all snakecase? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I currently have |
||
e->vector = v; | ||
e->innerRadius = 5; | ||
e->outerRadius = 10; | ||
e->exist = 1; | ||
} | ||
|
||
void drawEffect(Effect *e) { | ||
if (e->exist) { | ||
DrawRing(e->vector, e->innerRadius, e->outerRadius, 0, 360, 0, YELLOW); | ||
} | ||
e->innerRadius += 5; | ||
e->outerRadius += 4; | ||
|
||
if (e->innerRadius >= e->outerRadius) { | ||
e->exist = 0; | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
const int screenWidth = 800; | ||
const int screenHeight = 450; | ||
|
@@ -10,15 +36,24 @@ int main(int argc, char *argv[]) { | |
SetTargetFPS(60); | ||
|
||
while (!WindowShouldClose()) { | ||
Vector2 v = {100, 100}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use field name initializers |
||
Effect effect; | ||
spawnEffect(&effect, v); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are tabbed incorrectly; also in the finished product, we should try to keep variable declarations above the block they are used in. |
||
// Update | ||
|
||
// Draw | ||
BeginDrawing(); | ||
{ | ||
ClearBackground(RAYWHITE); | ||
ClearBackground(DARKGRAY); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't clear twice, as that does nothing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why the RAYWHITE one is still there. I don't have it on my end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe u forgot to push your second commit? |
||
DrawText("oruguru", 190, 200, 20, LIGHTGRAY); | ||
drawEffect(&effect); | ||
} | ||
EndDrawing(); | ||
if (effect.exist == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use |
||
effect.exist = 1; | ||
spawnEffect(&effect, v); | ||
} | ||
} | ||
|
||
CloseWindow(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer not to use typedef, makes it less confusing which type you have (struct vs union vs enum vs ptr).