Compare commits

..

No commits in common. "37bb56733e8b4f10dd6fa74b9d1fe1612df560fe" and "5da35830772774b36ba8bd71c9e5c5223da32562" have entirely different histories.

13 changed files with 28 additions and 110 deletions

View file

@ -32,7 +32,6 @@ SOURCEFILES = \
src/raycast/barricades.c \
src/raycast/ray.c \
src/raycast/walls.c \
src/raycast/zombie_checker.c \
src/renderer/render.c \
src/sprites/create_sprite.c \
src/sprites/move_sprites.c \

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/08 17:27:12 by tchampio #+# #+# */
/* Updated: 2025/09/15 13:06:07 by tchampio ### ########.fr */
/* Updated: 2025/09/10 15:59:15 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -84,6 +84,5 @@ void create_hud(t_cub3d_data *data)
draw_points(data);
draw_perks(data);
draw_round(data);
matrix_image_put(data, data->player.weapon.texture,
WIDTH / 2, HEIGHT - 175);
matrix_image_put(data, data->player.weapon.texture, WIDTH / 2, HEIGHT - 175);
}

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/09/15 15:45:27 by tchampio ### ########.fr */
/* Updated: 2025/09/14 16:41:00 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,29 +34,12 @@
#include "sprites/move_sprites.h"
#include "hud/hud.h"
void kill_zombie(t_cub3d_data *data, t_sprite *zombie_ptr)
{
mlx_destroy_image(data->mlx, zombie_ptr->image->img);
free(zombie_ptr->image);
zombie_ptr->sprite_type = DEAD_ZOMBIE;
}
void handle_shooting(t_cub3d_data *data)
{
if (data->keypresses.is_space_pressed)
{
if (!data->player.weapon.is_auto)
data->keypresses.is_space_pressed = false;
if (data->player.aimed_zombie)
{
data->player.aimed_zombie->health -= 10;
ft_printf("Shooting %p, now at %d HP\n", data->player.aimed_zombie,
data->player.aimed_zombie->health);
if (data->player.aimed_zombie->health <= 0)
kill_zombie(data, data->player.aimed_zombie);
}
else
ft_printf("Shoot!\n");
}
}
@ -71,7 +54,6 @@ int game_loop(t_cub3d_data *data)
move_player(data);
handle_shooting(data);
move_sprites(data);
data->player.aimed_zombie = NULL;
raycaster(data, &ray);
sprite_caster(data);
create_hud(data);

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
/* Updated: 2025/09/15 13:18:49 by tchampio ### ########.fr */
/* Updated: 2025/09/10 15:51:55 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,6 @@
# include "../map/mapdata.h"
# include "../draw/img_data.h"
# include "../sprites/sprite.h"
typedef struct s_vec2
{
@ -56,7 +55,6 @@ typedef struct s_player
t_perks perk_order[3];
t_vec2 movement;
t_weapon weapon;
t_sprite *aimed_zombie;
} t_player;
#endif // PLAYER_H

View file

@ -6,12 +6,11 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */
/* Updated: 2025/09/15 14:08:27 by tchampio ### ########.fr */
/* Updated: 2025/09/14 17:40:53 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "ray.h"
#include "zombie_checker.h"
#include "barricades.h"
#include "raycaster.h"
#include "../player/player.h"
@ -19,8 +18,8 @@
#include "../cub3d_data.h"
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include "../map/collision.h"
#include "../../libft/includes/libft.h"
void init_ray(t_ray *ray, int pos_x, t_player *player)
{
@ -59,10 +58,21 @@ void ray_calculate_step(t_ray *ray, t_player *player)
void calculate_wall_dist(t_ray *ray, int x, t_cub3d_data *data)
{
int i;
while (true)
{
if (x == WIDTH / 2)
check_for_zombies(ray, data);
{
i = 0;
while (i < data->sprite_counter)
{
if (data->sprite_list[i]->sprite_type == ZOMBIE && ray->map_x == (int)data->sprite_list[i]->x && ray->map_y == (int)data->sprite_list[i]->y)
{
ft_printf("Zombie found\n");
}
i++;
}
}
if (ray->side_dist_x < ray->side_dist_y)
{
ray->side_dist_x += ray->delta_dist_x;

View file

@ -1,37 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* zombie_checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/15 13:08:48 by tchampio #+# #+# */
/* Updated: 2025/09/15 14:10:17 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "ray.h"
#include "../cub3d_data.h"
#include <stdlib.h>
void check_for_zombies(t_ray *ray, t_cub3d_data *data)
{
int i;
i = 0;
while (i < data->sprite_counter)
{
if (ray->map_x == (int)data->sprite_list[i]->x
&& ray->map_y == (int)data->sprite_list[i]->y)
{
if (data->sprite_list[i]->sprite_type == ZOMBIE)
{
data->player.aimed_zombie = data->sprite_list[i];
break ;
}
else
data->player.aimed_zombie = NULL;
}
i++;
}
}

View file

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* zombie_checker.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/15 13:09:54 by tchampio #+# #+# */
/* Updated: 2025/09/15 13:10:44 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ZOMBIE_CHECKER_H
# define ZOMBIE_CHECKER_H
# include "ray.h"
# include "../cub3d_data.h"
void check_for_zombies(t_ray *ray, t_cub3d_data *data);
#endif // ZOMBIE_CHECKER_H

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:52:23 by kcolin #+# #+# */
/* Updated: 2025/09/15 14:36:47 by tchampio ### ########.fr */
/* Updated: 2025/09/09 14:08:10 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,7 +37,6 @@ void create_zombie(t_cub3d_data *data, double x, double y)
data->sprite_list[data->sprite_counter] = create_sprite(data,
"ressources/zombie.xpm", x, y);
data->sprite_list[data->sprite_counter]->sprite_type = ZOMBIE;
data->sprite_list[data->sprite_counter]->health = 250;
data->sprite_counter++;
}
@ -60,7 +59,6 @@ t_sprite *place_right_sprite(t_cub3d_data *data, char c, double x, double y)
{
sprite = create_sprite(data, ZOMBIE_TEX, x + 0.5, y + 0.5);
sprite->sprite_type = ZOMBIE;
sprite->health = 250;
}
if (c == 'D' || c == 'Q' || c == 'J')
sprite->sprite_type = PERK;

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:22:50 by kcolin #+# #+# */
/* Updated: 2025/09/15 15:25:39 by tchampio ### ########.fr */
/* Updated: 2025/08/20 12:38:53 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,6 @@
#include "../map/collision.h"
#include "sprite.h"
#include <math.h>
#include <stdlib.h>
void make_move(t_cub3d_data *data, t_sprite *sprite)
{

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/05 12:59:44 by tchampio #+# #+# */
/* Updated: 2025/09/15 15:26:56 by tchampio ### ########.fr */
/* Updated: 2025/08/13 14:44:02 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,6 @@
typedef enum e_sprite_type
{
ZOMBIE,
DEAD_ZOMBIE,
PERK,
BOX,
OTHER
@ -63,7 +62,6 @@ typedef struct s_sprite
int sprite_draw_start_x;
int sprite_draw_end_x;
t_sprite_type sprite_type;
int health;
} t_sprite;
#endif // SPRITE_H

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/05 15:51:01 by tchampio #+# #+# */
/* Updated: 2025/09/15 15:41:09 by tchampio ### ########.fr */
/* Updated: 2025/09/01 15:55:41 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,6 @@
#include "sort_sprites.h"
#include <math.h>
#include "../../libft/includes/libft.h"
#include "sprite.h"
static void calculate_pos_and_transform(t_cub3d_data *data, t_sprite *sprite,
int i)
@ -129,8 +128,6 @@ void sprite_caster(t_cub3d_data *data)
while (data->sprite_list[i] && i < MAX_SPRITES)
{
sprite_calculate_pos_and_dist(data, i);
if (data->sprite_list[data->sprite_order[i]]->sprite_type
!= DEAD_ZOMBIE)
render_sprites(data, i);
i++;
}

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */
/* Updated: 2025/09/15 15:39:44 by tchampio ### ########.fr */
/* Updated: 2025/09/10 16:00:47 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,7 +26,6 @@ void destroy_texture(t_cub3d_data *data, t_img_data *data_img)
void destroy_textures(t_cub3d_data *data)
{
int i;
if (data->no_texture)
mlx_destroy_image(data->mlx, data->no_texture->img);
free(data->no_texture);
@ -52,12 +51,9 @@ void destroy_sprites(t_cub3d_data *data)
if (data->sprite_list == NULL)
return ;
while (data->sprite_list[sprite] && sprite < MAX_SPRITES)
{
if (data->sprite_list[sprite]->sprite_type != DEAD_ZOMBIE)
{
mlx_destroy_image(data->mlx, data->sprite_list[sprite]->image->img);
free(data->sprite_list[sprite]->image);
}
free(data->sprite_list[sprite]);
sprite++;
}

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 13:28:47 by tchampio #+# #+# */
/* Updated: 2025/09/15 13:05:14 by tchampio ### ########.fr */
/* Updated: 2025/09/10 15:51:42 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */