mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
norme: fixed norme issues
This commit is contained in:
parent
f407f5b7ce
commit
a0f20b396c
6 changed files with 134 additions and 89 deletions
1
Makefile
1
Makefile
|
|
@ -10,6 +10,7 @@ IFLAGS = -I./mlx -I./libft
|
||||||
|
|
||||||
SOURCEFILES = \
|
SOURCEFILES = \
|
||||||
src/hud/load_texture.c \
|
src/hud/load_texture.c \
|
||||||
|
src/hud/hud.c \
|
||||||
src/utils/inits.c \
|
src/utils/inits.c \
|
||||||
src/utils/time.c \
|
src/utils/time.c \
|
||||||
src/utils/destroy_utils.c \
|
src/utils/destroy_utils.c \
|
||||||
|
|
|
||||||
88
src/hud/hud.c
Normal file
88
src/hud/hud.c
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* hud.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/08 17:27:12 by tchampio #+# #+# */
|
||||||
|
/* Updated: 2025/09/08 17:32:39 by tchampio ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../cub3d_data.h"
|
||||||
|
#include "../../libft/includes/libft.h"
|
||||||
|
#include "../renderer/render.h"
|
||||||
|
|
||||||
|
void draw_points(t_cub3d_data *data)
|
||||||
|
{
|
||||||
|
char points_str[11];
|
||||||
|
int i;
|
||||||
|
int horizontalpos;
|
||||||
|
|
||||||
|
ft_itoa_static(data->player.points, points_str, 11);
|
||||||
|
i = 0;
|
||||||
|
horizontalpos = 170;
|
||||||
|
while (i < (int)ft_strlen(points_str))
|
||||||
|
{
|
||||||
|
matrix_image_put(data, data->point_figures[points_str[i] - '0'],
|
||||||
|
WIDTH - horizontalpos, HEIGHT / 2);
|
||||||
|
horizontalpos -= 25;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_perks(t_cub3d_data *data)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int perk_pos;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
perk_pos = 50;
|
||||||
|
while (i < 3)
|
||||||
|
{
|
||||||
|
if (data->player.perk_order[i] != NONE)
|
||||||
|
{
|
||||||
|
if (data->player.perk_order[i] == REVIVE)
|
||||||
|
matrix_image_put(data, data->perk_logos[1], perk_pos, HEIGHT
|
||||||
|
- 200);
|
||||||
|
else if (data->player.perk_order[i] == JUGGERNOG)
|
||||||
|
matrix_image_put(data, data->perk_logos[0], perk_pos, HEIGHT
|
||||||
|
- 200);
|
||||||
|
else if (data->player.perk_order[i] == DOUBLETAP)
|
||||||
|
matrix_image_put(data, data->perk_logos[2], perk_pos, HEIGHT
|
||||||
|
- 200);
|
||||||
|
perk_pos += 50;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_round(t_cub3d_data *data)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int pos;
|
||||||
|
char round_str[5];
|
||||||
|
|
||||||
|
if (data->round <= 5)
|
||||||
|
return (matrix_image_put(data, data->tally_marks[data->round - 1], 20,
|
||||||
|
HEIGHT - 85));
|
||||||
|
pos = 20;
|
||||||
|
i = 0;
|
||||||
|
ft_itoa_static(data->round, round_str, 5);
|
||||||
|
while (round_str[i])
|
||||||
|
{
|
||||||
|
matrix_image_put(data, data->round_figures[round_str[i] - '0'], pos,
|
||||||
|
HEIGHT - 85);
|
||||||
|
pos += 50;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_hud(t_cub3d_data *data)
|
||||||
|
{
|
||||||
|
draw_points(data);
|
||||||
|
draw_perks(data);
|
||||||
|
draw_round(data);
|
||||||
|
matrix_image_put(data, data->gun, WIDTH / 2, HEIGHT - 175);
|
||||||
|
}
|
||||||
20
src/hud/hud.h
Normal file
20
src/hud/hud.h
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* hud.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/08 17:28:57 by tchampio #+# #+# */
|
||||||
|
/* Updated: 2025/09/08 17:29:54 by tchampio ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef HUD_H
|
||||||
|
# define HUD_H
|
||||||
|
|
||||||
|
# include "../cub3d_data.h"
|
||||||
|
|
||||||
|
void create_hud(t_cub3d_data *data);
|
||||||
|
|
||||||
|
#endif // HUD_H
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/09/03 17:02:08 by tchampio #+# #+# */
|
/* Created: 2025/09/03 17:02:08 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/09/05 20:26:20 by tchampio ### ########.fr */
|
/* Updated: 2025/09/08 17:25:53 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -71,16 +71,24 @@ void load_round_indicators(t_cub3d_data *data)
|
||||||
data->tally_marks[2] = load_hud_texture(data, "ressources/tally_three.xpm");
|
data->tally_marks[2] = load_hud_texture(data, "ressources/tally_three.xpm");
|
||||||
data->tally_marks[1] = load_hud_texture(data, "ressources/tally_two.xpm");
|
data->tally_marks[1] = load_hud_texture(data, "ressources/tally_two.xpm");
|
||||||
data->tally_marks[0] = load_hud_texture(data, "ressources/tally_one.xpm");
|
data->tally_marks[0] = load_hud_texture(data, "ressources/tally_one.xpm");
|
||||||
data->round_figures[0] = load_hud_texture(data, "ressources/round_zero.xpm");
|
data->round_figures[0] = load_hud_texture(data,
|
||||||
|
"ressources/round_zero.xpm");
|
||||||
data->round_figures[1] = load_hud_texture(data, "ressources/round_one.xpm");
|
data->round_figures[1] = load_hud_texture(data, "ressources/round_one.xpm");
|
||||||
data->round_figures[2] = load_hud_texture(data, "ressources/round_two.xpm");
|
data->round_figures[2] = load_hud_texture(data, "ressources/round_two.xpm");
|
||||||
data->round_figures[3] = load_hud_texture(data, "ressources/round_three.xpm");
|
data->round_figures[3] = load_hud_texture(data,
|
||||||
data->round_figures[4] = load_hud_texture(data, "ressources/round_four.xpm");
|
"ressources/round_three.xpm");
|
||||||
data->round_figures[5] = load_hud_texture(data, "ressources/round_five.xpm");
|
data->round_figures[4] = load_hud_texture(data,
|
||||||
data->round_figures[6] = load_hud_texture(data, "ressources/round_six.xpm");
|
"ressources/round_four.xpm");
|
||||||
data->round_figures[7] = load_hud_texture(data, "ressources/round_seven.xpm");
|
data->round_figures[5] = load_hud_texture(data,
|
||||||
data->round_figures[8] = load_hud_texture(data, "ressources/round_eight.xpm");
|
"ressources/round_five.xpm");
|
||||||
data->round_figures[9] = load_hud_texture(data, "ressources/round_nine.xpm");
|
data->round_figures[6] = load_hud_texture(data,
|
||||||
|
"ressources/round_six.xpm");
|
||||||
|
data->round_figures[7] = load_hud_texture(data,
|
||||||
|
"ressources/round_seven.xpm");
|
||||||
|
data->round_figures[8] = load_hud_texture(data,
|
||||||
|
"ressources/round_eight.xpm");
|
||||||
|
data->round_figures[9] = load_hud_texture(data,
|
||||||
|
"ressources/round_nine.xpm");
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_textures(t_cub3d_data *data)
|
void load_textures(t_cub3d_data *data)
|
||||||
|
|
|
||||||
76
src/main.c
76
src/main.c
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/08 13:56:27 by tchampio ### ########.fr */
|
/* Updated: 2025/09/08 17:30:24 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
#include "utils/frees.h"
|
#include "utils/frees.h"
|
||||||
#include "utils/hooks.h"
|
#include "utils/hooks.h"
|
||||||
#include "utils/inits.h"
|
#include "utils/inits.h"
|
||||||
#include "draw/drawutils.h"
|
|
||||||
#include <bits/types/struct_timeval.h>
|
#include <bits/types/struct_timeval.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
|
|
@ -33,78 +32,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include "utils/time.h"
|
#include "utils/time.h"
|
||||||
#include "sprites/move_sprites.h"
|
#include "sprites/move_sprites.h"
|
||||||
|
#include "hud/hud.h"
|
||||||
void draw_points(t_cub3d_data *data)
|
|
||||||
{
|
|
||||||
char points_str[11];
|
|
||||||
int i;
|
|
||||||
int horizontalpos;
|
|
||||||
|
|
||||||
ft_itoa_static(data->player.points, points_str, 11);
|
|
||||||
i = 0;
|
|
||||||
horizontalpos = 170;
|
|
||||||
while (i < (int)ft_strlen(points_str))
|
|
||||||
{
|
|
||||||
matrix_image_put(data, data->point_figures[points_str[i] - '0'], WIDTH - horizontalpos, HEIGHT / 2);
|
|
||||||
horizontalpos -= 25;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_perks(t_cub3d_data *data)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int perk_pos;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
perk_pos = 50;
|
|
||||||
while (i < 3)
|
|
||||||
{
|
|
||||||
if (data->player.perk_order[i] != NONE)
|
|
||||||
{
|
|
||||||
if (data->player.perk_order[i] == REVIVE)
|
|
||||||
matrix_image_put(data, data->perk_logos[1], perk_pos, HEIGHT - 200);
|
|
||||||
else if (data->player.perk_order[i] == JUGGERNOG)
|
|
||||||
matrix_image_put(data, data->perk_logos[0], perk_pos, HEIGHT - 200);
|
|
||||||
else if (data->player.perk_order[i] == DOUBLETAP)
|
|
||||||
matrix_image_put(data, data->perk_logos[2], perk_pos, HEIGHT - 200);
|
|
||||||
perk_pos += 50;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_round(t_cub3d_data *data)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int pos;
|
|
||||||
char round_str[5];
|
|
||||||
|
|
||||||
if (data->round <= 5)
|
|
||||||
return (matrix_image_put(data, data->tally_marks[data->round - 1], 20, HEIGHT - 85));
|
|
||||||
pos = 20;
|
|
||||||
i = 0;
|
|
||||||
ft_itoa_static(data->round, round_str, 5);
|
|
||||||
while (round_str[i])
|
|
||||||
{
|
|
||||||
matrix_image_put(data, data->round_figures[round_str[i] - '0'], pos, HEIGHT - 85);
|
|
||||||
pos += 50;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void create_hud(t_cub3d_data *data)
|
|
||||||
{
|
|
||||||
// draw points
|
|
||||||
draw_points(data);
|
|
||||||
// draw perks
|
|
||||||
draw_perks(data);
|
|
||||||
// draw round
|
|
||||||
draw_round(data);
|
|
||||||
// draw weapon
|
|
||||||
matrix_image_put(data, data->gun, WIDTH / 2, HEIGHT - 175);
|
|
||||||
// draw map
|
|
||||||
}
|
|
||||||
|
|
||||||
int game_loop(t_cub3d_data *data)
|
int game_loop(t_cub3d_data *data)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */
|
/* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/03 17:53:41 by tchampio ### ########.fr */
|
/* Updated: 2025/09/08 17:26:11 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -33,11 +33,11 @@ t_img_data *load_single_texture(t_cub3d_data *data, char *path)
|
||||||
ft_printf("Error: failed to open image at %s\n", path);
|
ft_printf("Error: failed to open image at %s\n", path);
|
||||||
destroy(data, 1);
|
destroy(data, 1);
|
||||||
}
|
}
|
||||||
// if (width != height || width != TEXTURE_SIZE)
|
if (width != height || width != TEXTURE_SIZE)
|
||||||
// {
|
{
|
||||||
// ft_printf("Error: textures are not the right size\n");
|
ft_printf("Error: textures are not the right size\n");
|
||||||
// destroy(data, 1);
|
destroy(data, 1);
|
||||||
// }
|
}
|
||||||
ft_printf("image: %p\n", img);
|
ft_printf("image: %p\n", img);
|
||||||
img_data = ft_calloc(sizeof(t_img_data), 1);
|
img_data = ft_calloc(sizeof(t_img_data), 1);
|
||||||
img_data->img = img;
|
img_data->img = img;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue