mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
feat(points): Finished point counter on the right of the screen
Some things are temporary, like the load single image function that still has comments. I'll make a function like this to restore the original code (almost). I'll also pass the pathes as constants for the sake of maintainabilty and try to avoid some of the magic values in the code for the same purpose.
This commit is contained in:
parent
242cbe3c7c
commit
761d126ba2
13 changed files with 444 additions and 122 deletions
|
|
@ -1,15 +1,45 @@
|
|||
/* XPM */
|
||||
static char * eight_xpm[] = {
|
||||
"7 10 2 1",
|
||||
"28 40 2 1",
|
||||
" c #FF00DC",
|
||||
". c #000001",
|
||||
" ",
|
||||
" ... ",
|
||||
" . . ",
|
||||
" . . ",
|
||||
" ... ",
|
||||
" . . ",
|
||||
" . . ",
|
||||
" . . ",
|
||||
" ... ",
|
||||
" "};
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,45 @@
|
|||
/* XPM */
|
||||
static char * five_xpm[] = {
|
||||
"7 10 2 1",
|
||||
"28 40 2 1",
|
||||
" c #FF00DC",
|
||||
". c #000001",
|
||||
" ",
|
||||
" ..... ",
|
||||
" . ",
|
||||
" . ",
|
||||
" .... ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . . ",
|
||||
" ... ",
|
||||
" "};
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" ................ ",
|
||||
" ................ ",
|
||||
" ................ ",
|
||||
" ................ ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,45 @@
|
|||
/* XPM */
|
||||
static char * four_xpm[] = {
|
||||
"7 10 2 1",
|
||||
"28 40 2 1",
|
||||
" c #FF00DC",
|
||||
". c #000001",
|
||||
" ",
|
||||
" . ",
|
||||
" . . ",
|
||||
" . . ",
|
||||
" . . ",
|
||||
" . . ",
|
||||
" ..... ",
|
||||
" . ",
|
||||
" . ",
|
||||
" "};
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,45 @@
|
|||
/* XPM */
|
||||
static char * nine_xpm[] = {
|
||||
"7 10 2 1",
|
||||
"28 40 2 1",
|
||||
" c #FF00DC",
|
||||
". c #000001",
|
||||
" ",
|
||||
" ... ",
|
||||
" . . ",
|
||||
" . . ",
|
||||
" .... ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" ... ",
|
||||
" "};
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" ................ ",
|
||||
" ................ ",
|
||||
" ................ ",
|
||||
" ................ ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,45 @@
|
|||
/* XPM */
|
||||
static char * one_xpm[] = {
|
||||
"7 10 2 1",
|
||||
"28 40 2 1",
|
||||
" c #FF00DC",
|
||||
". c #000001",
|
||||
" ",
|
||||
" . ",
|
||||
" .. ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" ... ",
|
||||
" "};
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" ........ ",
|
||||
" ........ ",
|
||||
" ........ ",
|
||||
" ........ ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,45 @@
|
|||
/* XPM */
|
||||
static char * seven_xpm[] = {
|
||||
"7 10 2 1",
|
||||
"28 40 2 1",
|
||||
" c #FF00DC",
|
||||
". c #000001",
|
||||
" ",
|
||||
" ..... ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" "};
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,45 @@
|
|||
/* XPM */
|
||||
static char * six_xpm[] = {
|
||||
"7 10 2 1",
|
||||
"28 40 2 1",
|
||||
" c #FF00DC",
|
||||
". c #000001",
|
||||
" ",
|
||||
" ... ",
|
||||
" . ",
|
||||
" . ",
|
||||
" .... ",
|
||||
" . . ",
|
||||
" . . ",
|
||||
" . . ",
|
||||
" ... ",
|
||||
" "};
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" ................ ",
|
||||
" ................ ",
|
||||
" ................ ",
|
||||
" ................ ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,45 @@
|
|||
/* XPM */
|
||||
static char * three_xpm[] = {
|
||||
"7 10 2 1",
|
||||
"28 40 2 1",
|
||||
" c #FF00DC",
|
||||
". c #000001",
|
||||
" ",
|
||||
" ... ",
|
||||
" . . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . . ",
|
||||
" ... ",
|
||||
" "};
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,45 @@
|
|||
/* XPM */
|
||||
static char * two_xpm[] = {
|
||||
"7 10 2 1",
|
||||
"28 40 2 1",
|
||||
" c #FF00DC",
|
||||
". c #000001",
|
||||
" ",
|
||||
" ... ",
|
||||
" . . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" . ",
|
||||
" ..... ",
|
||||
" "};
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .... ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" .................... ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,45 @@
|
|||
/* XPM */
|
||||
static char * zero_xpm[] = {
|
||||
"7 10 2 1",
|
||||
"28 40 2 1",
|
||||
" c #FF00DC",
|
||||
". c #000001",
|
||||
" ",
|
||||
" ... ",
|
||||
" . . ",
|
||||
" . .. ",
|
||||
" . . . ",
|
||||
" .. . ",
|
||||
" . . ",
|
||||
" . . ",
|
||||
" ... ",
|
||||
" "};
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... ........ ",
|
||||
" .... ........ ",
|
||||
" .... ........ ",
|
||||
" .... ........ ",
|
||||
" .... .... .... ",
|
||||
" .... .... .... ",
|
||||
" .... .... .... ",
|
||||
" .... .... .... ",
|
||||
" ........ .... ",
|
||||
" ........ .... ",
|
||||
" ........ .... ",
|
||||
" ........ .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" .... .... ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/20 16:08:56 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/08/20 16:10:45 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,6 +30,7 @@ typedef struct s_cub3d_data
|
|||
t_img_data *we_texture;
|
||||
t_img_data *ea_texture;
|
||||
t_img_data *img_data;
|
||||
t_img_data *point_figures[10];
|
||||
t_mapdata *map;
|
||||
t_player player;
|
||||
t_keypresses keypresses;
|
||||
|
|
|
|||
24
src/main.c
24
src/main.c
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/20 15:46:50 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/08/20 17:06:37 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -36,22 +36,28 @@
|
|||
|
||||
void draw_points(t_cub3d_data *data)
|
||||
{
|
||||
char points_str[10];
|
||||
char points_str[11];
|
||||
int i;
|
||||
int horizontalpos;
|
||||
|
||||
ft_itoa_static(data->player.points, points_str, 9);
|
||||
mlx_string_put(data->mlx, data->mlx_win, WIDTH - 20, HEIGHT / 2, 0x0000FF,
|
||||
points_str);
|
||||
ft_itoa_static(data->player.points, points_str, 11);
|
||||
i = 0;
|
||||
horizontalpos = 250;
|
||||
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 create_hud(t_cub3d_data *data)
|
||||
{
|
||||
mlx_string_put(data->mlx, data->mlx_win, 10, 10, 0x00FFFFFF, COMPILED_TEXT);
|
||||
// draw points
|
||||
draw_points(data);
|
||||
// draw perks
|
||||
// draw weapon
|
||||
// draw map
|
||||
draw_map(data->map, &data->player, data->img_data);
|
||||
}
|
||||
|
||||
int game_loop(t_cub3d_data *data)
|
||||
|
|
@ -66,10 +72,12 @@ int game_loop(t_cub3d_data *data)
|
|||
move_sprites(data);
|
||||
raycaster(data, &ray);
|
||||
sprite_caster(data);
|
||||
create_hud(data);
|
||||
matrix_to_image(data);
|
||||
mlx_put_image_to_window(data->mlx, data->mlx_win,
|
||||
data->img_data->img, 0, 0);
|
||||
create_hud(data);
|
||||
draw_map(data->map, &data->player, data->img_data);
|
||||
mlx_string_put(data->mlx, data->mlx_win, 10, 10, 0x00FFFFFF, COMPILED_TEXT);
|
||||
data->delta = (get_milliseconds() - data->last_tick);
|
||||
fps = 1000000.0 / data->delta;
|
||||
ft_itoa_static(fps, fps_string, 4);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/20 16:37:44 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/08/20 17:05:19 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,11 +21,12 @@
|
|||
|
||||
t_img_data *load_single_texture(t_cub3d_data *data, char *path)
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
void *img;
|
||||
t_img_data *img_data;
|
||||
|
||||
img = mlx_xpm_file_to_image(data->mlx, path, &img_data->width,
|
||||
&img_data->height);
|
||||
img = mlx_xpm_file_to_image(data->mlx, path, &width, &height);
|
||||
if (img == NULL)
|
||||
{
|
||||
ft_printf("Error: failed to open image at %s\n", path);
|
||||
|
|
@ -42,6 +43,8 @@ t_img_data *load_single_texture(t_cub3d_data *data, char *path)
|
|||
img_data->addr = mlx_get_data_addr(img_data->img,
|
||||
&img_data->bits_per_pixel, &img_data->line_length,
|
||||
&img_data->endian);
|
||||
img_data->height = height;
|
||||
img_data->width = width;
|
||||
return (img_data);
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +54,16 @@ void load_textures(t_cub3d_data *data)
|
|||
data->so_texture = load_single_texture(data, data->map->so_texture);
|
||||
data->we_texture = load_single_texture(data, data->map->we_texture);
|
||||
data->ea_texture = load_single_texture(data, data->map->ea_texture);
|
||||
data->point_figures[0] = load_single_texture(data, "ressources/zero.xpm");
|
||||
data->point_figures[1] = load_single_texture(data, "ressources/one.xpm");
|
||||
data->point_figures[2] = load_single_texture(data, "ressources/two.xpm");
|
||||
data->point_figures[3] = load_single_texture(data, "ressources/three.xpm");
|
||||
data->point_figures[4] = load_single_texture(data, "ressources/four.xpm");
|
||||
data->point_figures[5] = load_single_texture(data, "ressources/five.xpm");
|
||||
data->point_figures[6] = load_single_texture(data, "ressources/six.xpm");
|
||||
data->point_figures[7] = load_single_texture(data, "ressources/seven.xpm");
|
||||
data->point_figures[8] = load_single_texture(data, "ressources/eight.xpm");
|
||||
data->point_figures[9] = load_single_texture(data, "ressources/nine.xpm");
|
||||
}
|
||||
|
||||
void place_base_sprites(t_cub3d_data *data, char **map)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue