Skip to content

Commit

Permalink
Merge pull request #49 from FreddyMSchubert/46-inventory
Browse files Browse the repository at this point in the history
46 inventory
  • Loading branch information
Reptudn authored Jun 28, 2024
2 parents eb4fdb4 + df58f4d commit 890db0b
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/cub3d",
"args": ["./assets/maps/garden.cub"],
"args": ["./assets/maps/valid/42.cub"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ endif

HEADERS := -I ./include -I $(LIBMLX)/include -I $(LIBFT)/include -I $(GNL)/include -I $(GLFW_PATH)/include
LIBS := $(LIBMLX)/build/libmlx42.a -ldl -lm -L$(GLFW_PATH)/lib -lglfw $(LIBFT)/libft.a $(GNL)/libftgnl.a
CFLAGS := -Wall -Werror -Wextra -Wunreachable-code -fsanitize=address
CFLAGS := -Wall -Werror -Wextra -Wunreachable-code

$(NAME): setup $(OBJ) $(LIBMLX)/build/libmlx42.a $(LIBFT)/libft.a $(GNL)/libftgnl.a
cc $(OBJ) $(LIBS) $(HEADERS) -o $(NAME) -g -fsanitize=address
cc $(OBJ) $(LIBS) $(HEADERS) -o $(NAME)

$(OBJ_DIR)/%.o: ./src/%.c
@mkdir -p $(OBJ_DIR)
Expand Down
8 changes: 6 additions & 2 deletions include/cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 08:37:47 by jkauker #+# #+# */
/* Updated: 2024/06/27 20:56:22 by freddy ### ########.fr */
/* Updated: 2024/06/28 13:07:20 by jkauker ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -157,6 +157,10 @@ void draw_crosshair(void);
void draw_square(int x, int y, int size, int color);
void draw_square_hud(int x, int y, int size, int color);
void draw_square_world(int x, int y, int size, int color);
void draw_inventory(void);
mlx_image_t **get_amount_text_by_index(int index);
void texture_draw(mlx_texture_t *texture, t_scale pos, t_scale size);
void cycle_inventory(int direction, bool direct);
// minimap
void hud_draw_minimap(void);
void hud_toogle_worldmap(bool change_state);
Expand Down
23 changes: 16 additions & 7 deletions include/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* structs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fschuber <fschuber@student.42.fr> +#+ +:+ +#+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 08:37:38 by jkauker #+# #+# */
/* Updated: 2024/06/28 10:38:18 by fschuber ### ########.fr */
/* Updated: 2024/06/28 12:58:43 by jkauker ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -138,11 +138,20 @@ typedef struct s_persistent_data

typedef struct s_inventory
{
int keys;
int water_orbs;
int fire_orbs;
int earth_orbs;
int air_orbs;
int num_available_items;
int current_index;

int keys;
int water_orbs;
int fire_orbs;
int earth_orbs;
int air_orbs;

mlx_image_t *text_amount_key;
mlx_image_t *text_amount_water;
mlx_image_t *text_amount_fire;
mlx_image_t *text_amount_earth;
mlx_image_t *text_amount_air;
} t_inventory;

typedef struct s_player
Expand Down
10 changes: 8 additions & 2 deletions src/2_setup/player_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* player_setup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fschuber <fschuber@student.42.fr> +#+ +:+ +#+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 08:28:05 by freddy #+# #+# */
/* Updated: 2024/06/26 14:05:00 by fschuber ### ########.fr */
/* Updated: 2024/06/28 12:58:45 by jkauker ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -23,4 +23,10 @@ void setup_player(void)
player()->inv.fire_orbs = 0;
player()->inv.earth_orbs = 0;
player()->inv.air_orbs = 0;
player()->inv.num_available_items = 5;
player()->inv.current_index = 0;
player()->inv.text_amount_earth = NULL;
player()->inv.text_amount_fire = NULL;
player()->inv.text_amount_water = NULL;
player()->inv.text_amount_air = NULL;
}
4 changes: 2 additions & 2 deletions src/2_setup/setup_mlx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* setup_mlx.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
/* By: jkauker <jkauker@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 08:41:35 by freddy #+# #+# */
/* Updated: 2024/06/27 15:23:44 by freddy ### ########.fr */
/* Updated: 2024/06/26 15:26:46 by jkauker ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
2 changes: 1 addition & 1 deletion src/3_game_loop/a_game_logic/entities/projectile_entity.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* PROJECTILE_NTTntity.c :+: :+: :+: */
/* PROJECTILE_NTTntity.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: freddy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
Expand Down
21 changes: 17 additions & 4 deletions src/3_game_loop/a_game_logic/hooks/key_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@
/* ::: :::::::: */
/* key_hook.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fschuber <fschuber@student.42.fr> +#+ +:+ +#+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 10:23:50 by freddy #+# #+# */
/* Updated: 2024/06/28 10:09:36 by fschuber ### ########.fr */
/* Updated: 2024/06/28 12:32:55 by jkauker ### ########.fr */
/* */
/* ************************************************************************** */

#include "../../../../include/cub3d.h"
#include <stdio.h>

static inline void inventory_press(mlx_key_data_t keydata)
{
if (keydata.key >= MLX_KEY_1 && keydata.key <= MLX_KEY_9 && keydata.action == MLX_PRESS)
{
if ((unsigned int)(player()->inv.num_available_items) > keydata.key - MLX_KEY_1)
{
player()->inv.current_index = keydata.key - MLX_KEY_1;
game()->dirty = true;
}
}
}

void key_hook(mlx_key_data_t keydata, void *param)
{
Expand All @@ -22,7 +35,7 @@ void key_hook(mlx_key_data_t keydata, void *param)
turn (TURN_SPEED_ARROWS_DEG);
else if (keydata.key == MLX_KEY_R && keydata.action == MLX_PRESS)
setup_player();
// else if (keydata.key == MLX_KEY_M && keydata.action == MLX_PRESS)
// hud_toogle_worldmap(true);
inventory_press(keydata);
game()->dirty = true;
(void) param;
}
29 changes: 19 additions & 10 deletions src/3_game_loop/a_game_logic/hooks/mouse_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
/* ::: :::::::: */
/* mouse_hook.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/11 15:50:17 by freddy #+# #+# */
/* Updated: 2024/06/27 22:12:30 by freddy ### ########.fr */
/* Updated: 2024/06/28 13:07:40 by jkauker ### ########.fr */
/* */
/* ************************************************************************** */

#include "../../../../include/cub3d.h"
#include <stdint.h>

int *get_amount_of_item(int index);

void handle_mouse_mv(void)
{
Expand Down Expand Up @@ -39,23 +42,29 @@ void scroll_hook(double xdelta, double ydelta, void *param)
if (ydelta != 0)
{
if (ydelta > 0)
game()->minimap_size += 1;
cycle_inventory(-1, false);
else
game()->minimap_size -= 1;
if (game()->minimap_size < 2)
game()->minimap_size = 2;
if (game()->minimap_size > 6)
game()->minimap_size = 6;
cycle_inventory(1, false);
game()->dirty = true;
}
}

void mouse_click_hook(mouse_key_t button, action_t action, modifier_key_t mods, void* param)
{
int *amount;
mlx_image_t **amount_text;

(void)param;
(void)mods;
if (button == MLX_MOUSE_BUTTON_LEFT && action == MLX_PRESS && player()->inv.air_orbs > 0)
amount = get_amount_of_item(player()->inv.current_index);
if (button == MLX_MOUSE_BUTTON_LEFT && action == MLX_PRESS
&& *amount)
{
shooooot(player()->transform, TYPE_WATER);
amount_text = get_amount_text_by_index(player()->inv.current_index);
shooooot(player()->transform, player()->inv.current_index - 1);
(*amount)--;
mlx_delete_image(game()->mlx, *amount_text);
*amount_text = NULL;
logger(LOGGER_ACTION, "Shot projectile!");
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/3_game_loop/b_rendering/draw_walls/3_draw_walls.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* 3_draw_walls.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkauker <jkauker@student.42heilbronn.de +#+ +:+ +#+ */
/* By: jkauker <jkauker@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 13:58:47 by freddy #+# #+# */
/* Updated: 2024/06/26 12:52:21 by jkauker ### ########.fr */
/* Updated: 2024/06/28 10:23:47 by jkauker ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,7 +19,7 @@ void set_pixel_color(mlx_image_t *img, int x, int y, int col)
mlx_put_pixel(img, x, y, col);
}

static inline int get_tex_color_at(mlx_texture_t *tex, int x, int y)
int get_tex_color_at(mlx_texture_t *tex, int x, int y)
{
int index;

Expand Down
Loading

0 comments on commit 890db0b

Please sign in to comment.