mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
dev: improved sprites by creating a create_sprite function
This commit is contained in:
parent
09ff569a31
commit
00e8a73d14
4 changed files with 60 additions and 31 deletions
1
Makefile
1
Makefile
|
|
@ -32,6 +32,7 @@ SOURCEFILES = \
|
||||||
src/renderer/render.c \
|
src/renderer/render.c \
|
||||||
src/sprites/sort_sprites.c \
|
src/sprites/sort_sprites.c \
|
||||||
src/sprites/sprite_caster.c \
|
src/sprites/sprite_caster.c \
|
||||||
|
src/sprites/create_sprite.c \
|
||||||
|
|
||||||
OBJECTS = $(SOURCEFILES:.c=.o)
|
OBJECTS = $(SOURCEFILES:.c=.o)
|
||||||
NAME = cub3d
|
NAME = cub3d
|
||||||
|
|
|
||||||
30
src/sprites/create_sprite.c
Normal file
30
src/sprites/create_sprite.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* create_sprite.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/08/12 15:43:19 by tchampio #+# #+# */
|
||||||
|
/* Updated: 2025/08/12 15:53:05 by tchampio ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "../../libft/includes/libft.h"
|
||||||
|
#include "../cub3d_data.h"
|
||||||
|
#include "../utils/inits.h"
|
||||||
|
|
||||||
|
t_sprite *create_sprite(t_cub3d_data *data, char *texture,
|
||||||
|
double x, double y)
|
||||||
|
{
|
||||||
|
t_sprite *sprite;
|
||||||
|
|
||||||
|
sprite = ft_calloc(sizeof(t_sprite), 1);
|
||||||
|
if (!sprite)
|
||||||
|
return (NULL);
|
||||||
|
sprite->x = x;
|
||||||
|
sprite->y = y;
|
||||||
|
sprite->image = load_single_texture(data, texture);
|
||||||
|
return (sprite);
|
||||||
|
}
|
||||||
21
src/sprites/create_sprite.h
Normal file
21
src/sprites/create_sprite.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* create_sprite.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/08/12 15:49:25 by tchampio #+# #+# */
|
||||||
|
/* Updated: 2025/08/12 15:53:12 by tchampio ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef CREATE_SPRITE_H
|
||||||
|
# define CREATE_SPRITE_H
|
||||||
|
|
||||||
|
# include "../cub3d_data.h"
|
||||||
|
|
||||||
|
t_sprite *create_sprite(t_cub3d_data *data,
|
||||||
|
char *filename, double x, double y);
|
||||||
|
|
||||||
|
#endif // CREATE_SPRITE_H
|
||||||
|
|
@ -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/08/12 15:21:00 by tchampio ### ########.fr */
|
/* Updated: 2025/08/12 15:55:51 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include "../../libft/includes/libft.h"
|
#include "../../libft/includes/libft.h"
|
||||||
#include "../../mlx/mlx.h"
|
#include "../../mlx/mlx.h"
|
||||||
#include "../map/map_checker.h"
|
#include "../map/map_checker.h"
|
||||||
|
#include "../sprites/create_sprite.h"
|
||||||
#include "frees.h"
|
#include "frees.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
@ -57,47 +58,23 @@ void place_base_sprites(t_cub3d_data *data, char **map)
|
||||||
{
|
{
|
||||||
int y;
|
int y;
|
||||||
int x;
|
int x;
|
||||||
int currentsprite;
|
int c;
|
||||||
|
|
||||||
y = 0;
|
y = 0;
|
||||||
currentsprite = 0;
|
c = 0;
|
||||||
while (y < data->map->mapheight)
|
while (y < data->map->mapheight)
|
||||||
{
|
{
|
||||||
x = 0;
|
x = 0;
|
||||||
while (x < (int)ft_strlen(map[y]))
|
while (x < (int)ft_strlen(map[y]))
|
||||||
{
|
{
|
||||||
if (map[y][x] == 'M')
|
if (map[y][x] == 'M')
|
||||||
{
|
data->sprite_list[c++] = create_sprite(data, "ressources/box.xpm", x + 0.5, y + 0.5);
|
||||||
data->sprite_list[currentsprite] = ft_calloc(sizeof(t_sprite), 1);
|
|
||||||
data->sprite_list[currentsprite]->image = load_single_texture(data, "ressources/box.xpm");
|
|
||||||
data->sprite_list[currentsprite]->x = x + 0.5;
|
|
||||||
data->sprite_list[currentsprite]->y = y + 0.5;
|
|
||||||
currentsprite++;
|
|
||||||
}
|
|
||||||
if (map[y][x] == 'Q')
|
if (map[y][x] == 'Q')
|
||||||
{
|
data->sprite_list[c++] = create_sprite(data, "ressources/revive.xpm", x + 0.5, y + 0.5);
|
||||||
data->sprite_list[currentsprite] = ft_calloc(sizeof(t_sprite), 1);
|
|
||||||
data->sprite_list[currentsprite]->image = load_single_texture(data, "ressources/revive.xpm");
|
|
||||||
data->sprite_list[currentsprite]->x = x + 0.5;
|
|
||||||
data->sprite_list[currentsprite]->y = y + 0.5;
|
|
||||||
currentsprite++;
|
|
||||||
}
|
|
||||||
if (map[y][x] == 'J')
|
if (map[y][x] == 'J')
|
||||||
{
|
data->sprite_list[c++] = create_sprite(data, "ressources/juggernog.xpm", x + 0.5, y + 0.5);
|
||||||
data->sprite_list[currentsprite] = ft_calloc(sizeof(t_sprite), 1);
|
|
||||||
data->sprite_list[currentsprite]->image = load_single_texture(data, "ressources/juggernog.xpm");
|
|
||||||
data->sprite_list[currentsprite]->x = x + 0.5;
|
|
||||||
data->sprite_list[currentsprite]->y = y + 0.5;
|
|
||||||
currentsprite++;
|
|
||||||
}
|
|
||||||
if (map[y][x] == 'D')
|
if (map[y][x] == 'D')
|
||||||
{
|
data->sprite_list[c++] = create_sprite(data, "ressources/doubletap.xpm", x + 0.5, y + 0.5);
|
||||||
data->sprite_list[currentsprite] = ft_calloc(sizeof(t_sprite), 1);
|
|
||||||
data->sprite_list[currentsprite]->image = load_single_texture(data, "ressources/doubletap.xpm");
|
|
||||||
data->sprite_list[currentsprite]->x = x + 0.5;
|
|
||||||
data->sprite_list[currentsprite]->y = y + 0.5;
|
|
||||||
currentsprite++;
|
|
||||||
}
|
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
y++;
|
y++;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue