rework to context: now there's engine and user code copies, renaming of fields, most things that shouldn't be there are hidden
This commit is contained in:
@ -17,7 +17,7 @@ void handle_input(void)
|
||||
{
|
||||
State *state = ctx.udata;
|
||||
|
||||
if (ctx.mouse_window_position.y <= 60)
|
||||
if (ctx.mouse_position.y <= 60)
|
||||
return;
|
||||
|
||||
if (input_is_action_pressed("add_a_bit"))
|
||||
@ -27,10 +27,10 @@ void handle_input(void)
|
||||
if (state->bunniesCount < MAX_BUNNIES)
|
||||
{
|
||||
state->bunnies[state->bunniesCount].position = input_get_action_position("add_a_bit");
|
||||
state->bunnies[state->bunniesCount].speed.x = (float)(rand() % 500 - 250) / 60.0;
|
||||
state->bunnies[state->bunniesCount].speed.y = (float)(rand() % 500 - 250) / 60.0;
|
||||
state->bunnies[state->bunniesCount].speed.x = (float)(rand() % 500 - 250) / 60.0f;
|
||||
state->bunnies[state->bunniesCount].speed.y = (float)(rand() % 500 - 250) / 60.0f;
|
||||
state->bunnies[state->bunniesCount].color =
|
||||
(Color){rand() % 190 + 50, rand() % 160 + 80, rand() % 140 + 100, 255};
|
||||
(Color){(uint8_t)(rand() % 190 + 50), (uint8_t)(rand() % 160 + 80), (uint8_t)(rand() % 140 + 100), 255};
|
||||
state->bunniesCount++;
|
||||
}
|
||||
}
|
||||
@ -43,10 +43,10 @@ void handle_input(void)
|
||||
if (state->bunniesCount < MAX_BUNNIES)
|
||||
{
|
||||
state->bunnies[state->bunniesCount].position = input_get_action_position("add_a_lot");
|
||||
state->bunnies[state->bunniesCount].speed.x = (float)(rand() % 500 - 250) / 60.0;
|
||||
state->bunnies[state->bunniesCount].speed.y = (float)(rand() % 500 - 250) / 60.0;
|
||||
state->bunnies[state->bunniesCount].speed.x = (float)(rand() % 500 - 250) / 60.0f;
|
||||
state->bunnies[state->bunniesCount].speed.y = (float)(rand() % 500 - 250) / 60.0f;
|
||||
state->bunnies[state->bunniesCount].color =
|
||||
(Color){rand() % 190 + 50, rand() % 160 + 80, rand() % 140 + 100, 255};
|
||||
(Color){(uint8_t)(rand() % 190 + 50), (uint8_t)(rand() % 160 + 80), (uint8_t)(rand() % 140 + 100), 255};
|
||||
state->bunniesCount++;
|
||||
}
|
||||
}
|
||||
@ -73,32 +73,29 @@ void game_tick(void)
|
||||
|
||||
State *state = ctx.udata;
|
||||
|
||||
const double delta =
|
||||
(double)(ctx.delta_time) / 1000.0; // Receiving floating point delta value (diving by 1000 based on vibe)
|
||||
|
||||
for (int i = 0; i < state->bunniesCount; i++)
|
||||
{
|
||||
state->bunnies[i].position.x += state->bunnies[i].speed.x;
|
||||
state->bunnies[i].position.y += state->bunnies[i].speed.y;
|
||||
|
||||
if (((state->bunnies[i].position.x + BUNNY_W / 2) > ctx.base_draw_w) ||
|
||||
((state->bunnies[i].position.x + BUNNY_W / 2) < 0))
|
||||
if (((state->bunnies[i].position.x + (float)BUNNY_W / 2) > (float)ctx.resolution.x) ||
|
||||
((state->bunnies[i].position.x + (float)BUNNY_W / 2) < 0))
|
||||
state->bunnies[i].speed.x *= -1;
|
||||
if (((state->bunnies[i].position.y + BUNNY_H / 2) > ctx.base_draw_h) ||
|
||||
((state->bunnies[i].position.y + BUNNY_H / 2 - 60) < 0))
|
||||
if (((state->bunnies[i].position.y + (float)BUNNY_H / 2) > (float)ctx.resolution.y) ||
|
||||
((state->bunnies[i].position.y + (float)BUNNY_H / 2 - 60) < 0))
|
||||
state->bunnies[i].speed.y *= -1;
|
||||
}
|
||||
|
||||
handle_input();
|
||||
|
||||
// Clear window with Gray color (set the background color this way)
|
||||
draw_rectangle((Rect){0, 0, ctx.base_draw_w, ctx.base_draw_h}, GRAY);
|
||||
draw_rectangle((Rect){0, 0, (float)ctx.resolution.x, (float)ctx.resolution.y}, GRAY);
|
||||
|
||||
for (int i = 0; i < state->bunniesCount; i++)
|
||||
{ // Draw each bunny based on their position and color, also scale accordingly
|
||||
m_sprite(m_set(path, "wabbit_alpha.png"),
|
||||
m_set(rect, ((Rect){.x = (int)state->bunnies[i].position.x,
|
||||
.y = (int)state->bunnies[i].position.y,
|
||||
m_set(rect, ((Rect){.x = state->bunnies[i].position.x,
|
||||
.y = state->bunnies[i].position.y,
|
||||
.w = BUNNY_W * SPRITE_SCALE,
|
||||
.h = BUNNY_H * SPRITE_SCALE})),
|
||||
m_opt(color, (state->bunnies[i].color)), m_opt(stretch, true), );
|
||||
|
Reference in New Issue
Block a user