mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
wip: Adding weapon class and usage
This commit is contained in:
parent
87c0a8a991
commit
b0ac26a7f6
13 changed files with 82 additions and 43 deletions
2
Makefile
2
Makefile
|
|
@ -11,11 +11,11 @@ IFLAGS = -I./mlx -I./libft
|
||||||
SOURCEFILES = \
|
SOURCEFILES = \
|
||||||
src/hud/load_texture.c \
|
src/hud/load_texture.c \
|
||||||
src/hud/hud.c \
|
src/hud/hud.c \
|
||||||
src/utils/inits.c \
|
|
||||||
src/utils/time.c \
|
src/utils/time.c \
|
||||||
src/utils/destroy_utils.c \
|
src/utils/destroy_utils.c \
|
||||||
src/draw/draw_map.c \
|
src/draw/draw_map.c \
|
||||||
src/draw/drawutils.c \
|
src/draw/drawutils.c \
|
||||||
|
src/utils/inits.c \
|
||||||
src/main.c \
|
src/main.c \
|
||||||
src/map/checkers.c \
|
src/map/checkers.c \
|
||||||
src/map/collision.c \
|
src/map/collision.c \
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/10 14:56:37 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 15:58:56 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,9 +16,9 @@
|
||||||
# include "map/mapdata.h"
|
# include "map/mapdata.h"
|
||||||
# include "draw/img_data.h"
|
# include "draw/img_data.h"
|
||||||
# include "sprites/sprite.h"
|
# include "sprites/sprite.h"
|
||||||
# include "player/player.h"
|
|
||||||
# include "utils/keypresses.h"
|
# include "utils/keypresses.h"
|
||||||
# include "consts.h"
|
# include "consts.h"
|
||||||
|
# include "player/player.h"
|
||||||
|
|
||||||
// the 4 static sprites are some of the perks and the mystery box
|
// the 4 static sprites are some of the perks and the mystery box
|
||||||
typedef struct s_cub3d_data
|
typedef struct s_cub3d_data
|
||||||
|
|
@ -35,7 +35,6 @@ typedef struct s_cub3d_data
|
||||||
t_img_data *perk_logos[3];
|
t_img_data *perk_logos[3];
|
||||||
t_img_data *tally_marks[5];
|
t_img_data *tally_marks[5];
|
||||||
t_img_data *round_figures[10];
|
t_img_data *round_figures[10];
|
||||||
t_img_data *gun;
|
|
||||||
t_mapdata *map;
|
t_mapdata *map;
|
||||||
t_player player;
|
t_player player;
|
||||||
t_keypresses keypresses;
|
t_keypresses keypresses;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/09/08 17:27:12 by tchampio #+# #+# */
|
/* Created: 2025/09/08 17:27:12 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/09/08 17:32:39 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 15:59:15 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -84,5 +84,5 @@ void create_hud(t_cub3d_data *data)
|
||||||
draw_points(data);
|
draw_points(data);
|
||||||
draw_perks(data);
|
draw_perks(data);
|
||||||
draw_round(data);
|
draw_round(data);
|
||||||
matrix_image_put(data, data->gun, WIDTH / 2, HEIGHT - 175);
|
matrix_image_put(data, data->player.weapon.texture, WIDTH / 2, HEIGHT - 175);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/10 14:56:33 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 15:59:34 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -114,5 +114,4 @@ void load_textures(t_cub3d_data *data)
|
||||||
load_points_textures(data);
|
load_points_textures(data);
|
||||||
load_perk_logos(data);
|
load_perk_logos(data);
|
||||||
load_round_indicators(data);
|
load_round_indicators(data);
|
||||||
data->gun = load_hud_texture(data, "ressources/weapon.xpm");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
src/main.c
12
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 17:30:24 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 15:34:15 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -34,6 +34,16 @@
|
||||||
#include "sprites/move_sprites.h"
|
#include "sprites/move_sprites.h"
|
||||||
#include "hud/hud.h"
|
#include "hud/hud.h"
|
||||||
|
|
||||||
|
void handle_shooting(t_cub3d_data *data)
|
||||||
|
{
|
||||||
|
if (!data->keypresses.is_space_pressed)
|
||||||
|
return ;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int game_loop(t_cub3d_data *data)
|
int game_loop(t_cub3d_data *data)
|
||||||
{
|
{
|
||||||
t_ray ray;
|
t_ray ray;
|
||||||
|
|
|
||||||
20
src/player/init_player.h
Normal file
20
src/player/init_player.h
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* init_player.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/10 15:55:37 by tchampio #+# #+# */
|
||||||
|
/* Updated: 2025/09/10 15:56:23 by tchampio ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef INIT_PLAYER_H
|
||||||
|
# define INIT_PLAYER_H
|
||||||
|
|
||||||
|
# include "../cub3d_data.h"
|
||||||
|
|
||||||
|
void init_player(t_cub3d_data *data, t_player *player, t_mapdata *map);
|
||||||
|
|
||||||
|
#endif // INIT_PLAYER_H
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/06 11:29:14 by kcolin #+# #+# */
|
/* Created: 2025/08/06 11:29:14 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/03 16:37:56 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 15:58:32 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include "../../libft/includes/libft.h"
|
#include "../../libft/includes/libft.h"
|
||||||
#include "../map/mapdata.h"
|
#include "../map/mapdata.h"
|
||||||
#include "../consts.h"
|
#include "../consts.h"
|
||||||
|
#include "../hud/load_texture.h"
|
||||||
|
|
||||||
// east west
|
// east west
|
||||||
void init_lon(t_player *player, char dir)
|
void init_lon(t_player *player, char dir)
|
||||||
|
|
@ -53,7 +54,7 @@ void init_lat(t_player *player, char dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_player(t_player *player, t_mapdata *map)
|
void init_player(t_cub3d_data *data, t_player *player, t_mapdata *map)
|
||||||
{
|
{
|
||||||
char dir;
|
char dir;
|
||||||
|
|
||||||
|
|
@ -63,6 +64,8 @@ void init_player(t_player *player, t_mapdata *map)
|
||||||
player->health = 100;
|
player->health = 100;
|
||||||
player->points = 500;
|
player->points = 500;
|
||||||
ft_bzero(player->perk_order, 3);
|
ft_bzero(player->perk_order, 3);
|
||||||
|
ft_bzero(&player->weapon, sizeof(t_weapon));
|
||||||
|
player->weapon.texture = load_hud_texture(data, "ressources/weapon.xpm");
|
||||||
if (dir == 'N' || dir == 'S')
|
if (dir == 'N' || dir == 'S')
|
||||||
init_lon(player, dir);
|
init_lon(player, dir);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
|
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/03 16:27:17 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 15:51:55 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
# define PLAYER_H
|
# define PLAYER_H
|
||||||
|
|
||||||
# include "../map/mapdata.h"
|
# include "../map/mapdata.h"
|
||||||
|
# include "../draw/img_data.h"
|
||||||
|
|
||||||
typedef struct s_vec2
|
typedef struct s_vec2
|
||||||
{
|
{
|
||||||
|
|
@ -29,23 +30,31 @@ typedef enum e_perks
|
||||||
DOUBLETAP
|
DOUBLETAP
|
||||||
} t_perks;
|
} t_perks;
|
||||||
|
|
||||||
|
typedef struct s_weapon
|
||||||
|
{
|
||||||
|
t_img_data *texture;
|
||||||
|
t_img_data *shoot_texture;
|
||||||
|
bool is_auto;
|
||||||
|
int clip;
|
||||||
|
int remaining_ammos;
|
||||||
|
} t_weapon;
|
||||||
|
|
||||||
typedef struct s_player
|
typedef struct s_player
|
||||||
{
|
{
|
||||||
double x;
|
double x;
|
||||||
double y;
|
double y;
|
||||||
double dir_x;
|
double dir_x;
|
||||||
double dir_y;
|
double dir_y;
|
||||||
double plane_x;
|
double plane_x;
|
||||||
double plane_y;
|
double plane_y;
|
||||||
int health;
|
int health;
|
||||||
int points;
|
int points;
|
||||||
bool has_revive;
|
bool has_revive;
|
||||||
bool has_juggernog;
|
bool has_juggernog;
|
||||||
bool has_doubletap;
|
bool has_doubletap;
|
||||||
t_perks perk_order[3];
|
t_perks perk_order[3];
|
||||||
t_vec2 movement;
|
t_vec2 movement;
|
||||||
|
t_weapon weapon;
|
||||||
} t_player;
|
} t_player;
|
||||||
|
|
||||||
void init_player(t_player *player, t_mapdata *map);
|
|
||||||
|
|
||||||
#endif // PLAYER_H
|
#endif // PLAYER_H
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */
|
/* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/10 15:18:58 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 16:00:47 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -65,23 +65,15 @@ void destroy_hud_textures(t_cub3d_data *data)
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < 10)
|
while (i < 10)
|
||||||
{
|
|
||||||
destroy_texture(data, data->point_figures[i++]);
|
destroy_texture(data, data->point_figures[i++]);
|
||||||
}
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < 10)
|
while (i < 10)
|
||||||
{
|
|
||||||
destroy_texture(data, data->round_figures[i++]);
|
destroy_texture(data, data->round_figures[i++]);
|
||||||
}
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < 5)
|
while (i < 5)
|
||||||
{
|
|
||||||
destroy_texture(data, data->tally_marks[i++]);
|
destroy_texture(data, data->tally_marks[i++]);
|
||||||
}
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < 3)
|
while (i < 3)
|
||||||
{
|
|
||||||
destroy_texture(data, data->perk_logos[i++]);
|
destroy_texture(data, data->perk_logos[i++]);
|
||||||
}
|
destroy_texture(data, data->player.weapon.texture);
|
||||||
destroy_texture(data, data->gun);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:22:57 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:22:57 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/03 17:54:36 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 15:33:38 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -37,6 +37,8 @@ int keypress_handler(int keycode, t_cub3d_data *data)
|
||||||
data->keypresses.is_left_pressed = true;
|
data->keypresses.is_left_pressed = true;
|
||||||
if (keycode == XK_Right)
|
if (keycode == XK_Right)
|
||||||
data->keypresses.is_right_pressed = true;
|
data->keypresses.is_right_pressed = true;
|
||||||
|
if (keycode == XK_space)
|
||||||
|
data->keypresses.is_space_pressed = true;
|
||||||
if (keycode == XK_p)
|
if (keycode == XK_p)
|
||||||
data->player.points += 500;
|
data->player.points += 500;
|
||||||
if (keycode == XK_u)
|
if (keycode == XK_u)
|
||||||
|
|
@ -60,5 +62,7 @@ int keyrelease_handler(int keycode, t_cub3d_data *data)
|
||||||
data->keypresses.is_left_pressed = false;
|
data->keypresses.is_left_pressed = false;
|
||||||
if (keycode == XK_Right)
|
if (keycode == XK_Right)
|
||||||
data->keypresses.is_right_pressed = false;
|
data->keypresses.is_right_pressed = false;
|
||||||
|
if (keycode == XK_space)
|
||||||
|
data->keypresses.is_space_pressed = false;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@
|
||||||
/* 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/08 17:26:11 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 15:56:38 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "inits.h"
|
||||||
#include "../cub3d_data.h"
|
#include "../cub3d_data.h"
|
||||||
#include "time.h"
|
#include "../player/init_player.h"
|
||||||
#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"
|
||||||
|
|
@ -90,7 +91,7 @@ void init_cub3d_data(t_cub3d_data *data, char **argv)
|
||||||
data->img_data->addr = mlx_get_data_addr(data->img_data->img,
|
data->img_data->addr = mlx_get_data_addr(data->img_data->img,
|
||||||
&data->img_data->bits_per_pixel, &data->img_data->line_length,
|
&data->img_data->bits_per_pixel, &data->img_data->line_length,
|
||||||
&data->img_data->endian);
|
&data->img_data->endian);
|
||||||
init_player(&data->player, data->map);
|
init_player(data, &data->player, data->map);
|
||||||
data->screen_matrix = ft_calloc(sizeof(int), WIDTH * HEIGHT);
|
data->screen_matrix = ft_calloc(sizeof(int), WIDTH * HEIGHT);
|
||||||
load_textures(data);
|
load_textures(data);
|
||||||
data->sprite_list = ft_calloc(sizeof(t_sprite *), MAX_SPRITES);
|
data->sprite_list = ft_calloc(sizeof(t_sprite *), MAX_SPRITES);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/31 13:28:47 by tchampio #+# #+# */
|
/* Created: 2025/07/31 13:28:47 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/08/06 14:14:11 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 15:51:42 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,5 +17,6 @@
|
||||||
|
|
||||||
void init_cub3d_data(t_cub3d_data *data, char **argv);
|
void init_cub3d_data(t_cub3d_data *data, char **argv);
|
||||||
t_img_data *load_single_texture(t_cub3d_data *data, char *path);
|
t_img_data *load_single_texture(t_cub3d_data *data, char *path);
|
||||||
|
void init_player(t_cub3d_data *data, t_player *player, t_mapdata *map);
|
||||||
|
|
||||||
#endif // INITS_H
|
#endif // INITS_H
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/29 13:42:39 by tchampio #+# #+# */
|
/* Created: 2025/07/29 13:42:39 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/08/13 15:22:54 by tchampio ### ########.fr */
|
/* Updated: 2025/09/10 15:32:51 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,6 +22,7 @@ typedef struct s_keypresses
|
||||||
bool is_left_pressed;
|
bool is_left_pressed;
|
||||||
bool is_right_pressed;
|
bool is_right_pressed;
|
||||||
bool is_f_pressed;
|
bool is_f_pressed;
|
||||||
|
bool is_space_pressed;
|
||||||
} t_keypresses;
|
} t_keypresses;
|
||||||
|
|
||||||
#endif // KEYPRESSES_H
|
#endif // KEYPRESSES_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue