Skip to content

Commit

Permalink
Resolvendo as hitbox do cano e simples menu antes de iniciar o game
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcardosoy committed Nov 17, 2023
1 parent 7a53027 commit 2563529
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
Binary file modified MarioRun_win64.exe
Binary file not shown.
15 changes: 11 additions & 4 deletions src/lib/character.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,17 @@ void character_get_colision(Character character, int* x1, int* x2, int* y1, int*
int render_y = character->is_crouched ? character->y * 1.085 : character->y;
int render_x = character->is_crouched ? character->x * 1.25 : character->x;

*x1 = render_x;
*x2 = render_x + render_width;
*y1 = render_y;
*y2 = render_y + render_height;
if (!character->is_crouched) {
*x1 = render_x + render_width * 0.6;
*x2 = render_x + render_width;
*y1 = render_y;
*y2 = render_y + render_height;
} else {
*x1 = render_x;
*x2 = render_x + render_width;
*y1 = render_y;
*y2 = render_y + render_height;
}
}

int character_get_position_y(Character character)
Expand Down
33 changes: 24 additions & 9 deletions src/lib/mario_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,32 @@ void game_init(Game* game)

bool game_menu(Game game, bool is_dead)
{
// not implemented yet
bool quit = false;
SDL_Event event;

while (!quit) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
quit = true;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_SPACE:
case SDLK_ESCAPE:
case SDLK_UP:
quit = true;
break;
}
}
}
}

return quit;
}

void game_animate(Game game)
{

game_events(game);
if (character_can_jump(game->character))
character_set_falling(game->character, false);

Expand Down Expand Up @@ -191,12 +210,12 @@ void game_pause(Game game)

void game_run(Game game, bool* quit)
{
game_animate(game);
game_menu(game, false);

Mix_PlayMusic(game->main_song, -1);
Mix_VolumeMusic(MIX_MAX_VOLUME / 2);

game_menu(game, false);

while (!*quit) {
game_frame(game, quit);
}
Expand Down Expand Up @@ -224,9 +243,7 @@ void game_frame(Game game, bool* quit)
game_animate(game);
}

game_pause(game);
*quit = game_menu(game, true);
game_reset(game);
}

frame_time = SDL_GetTicks() - startLoop;
Expand All @@ -238,8 +255,6 @@ void game_frame(Game game, bool* quit)
void game_reset(Game game)
{
// Não sei se essa implementação funciona, deixar provisioriamente até futuros testes.
game_destroy(&game);
game_init(&game);
}

bool are_colliding(Character character, Obstacle obstacle)
Expand Down
18 changes: 14 additions & 4 deletions src/lib/obstacle.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,20 @@ int obstacle_get_width(Obstacle obstacle)

void obstacle_get_colision(Obstacle obstacle, int* x1, int* x2, int* y1, int* y2)
{
*x1 = obstacle->x;
*x2 = obstacle->x + obstacle->width;
*y1 = obstacle->y;
*y2 = obstacle->y + obstacle->height;
if (obstacle->type != 3)
{
*x1 = obstacle->x;
*x2 = obstacle->x + obstacle->width;
*y1 = obstacle->y;
*y2 = obstacle->y + obstacle->height;
} else {
*x1 = obstacle->x;
*x2 = obstacle->x + obstacle->width;
*y1 = obstacle->y + (obstacle->height * 0.19);
*y2 = obstacle->y + obstacle->height;
}


}

void obstacle_destroy(Obstacle* obstacle)
Expand Down

0 comments on commit 2563529

Please sign in to comment.