Skip to content
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

Draft
wants to merge 5 commits into
base: prototype
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/oruguru.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
#include <raylib.h>
#include <raymath.h>

typedef struct Effect {
Copy link
Owner

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).

Copy link
Owner

Choose a reason for hiding this comment

The 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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, field names are a little meaningless atm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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?

I'll probably make more structs and think about how I should format it . It really depends what I want to add.
I'm thinking the Effect's fields should be just: vector (center coordinates), struct EffectType, bool exist.

Copy link
Owner

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

@dbcalitis dbcalitis Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Yeah, true... :v

If its a type, then you might wanna consider enum example from my repo.

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.

Copy link
Owner

@andwu137 andwu137 Dec 8, 2024

Choose a reason for hiding this comment

The 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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use <stdbool.h> and true | false.

} Effect;

void spawnEffect(Effect *e, Vector2 v) {
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Only for functions? Should we use another naming convention like camelCase for fields and other stuff? Or should we just make it all snakecase?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I currently have
Types: Pascal
Variables: Camel
Functions: Snake
Files: Snake
Constants: Caps
Macros: Snake or Caps

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;
Expand All @@ -10,15 +36,24 @@ int main(int argc, char *argv[]) {
SetTargetFPS(60);

while (!WindowShouldClose()) {
Vector2 v = {100, 100};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use field name initializers {.x = 100, .y = 100}.

Effect effect;
spawnEffect(&effect, v);
Copy link
Owner

Choose a reason for hiding this comment

The 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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't clear twice, as that does nothing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Copy link
Owner

Choose a reason for hiding this comment

The 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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use if (!effect.exist).

effect.exist = 1;
spawnEffect(&effect, v);
}
}

CloseWindow();
Expand Down