Skip to content

Commit 3e72b10

Browse files
committed
added the collectible animations
1 parent dc7df5e commit 3e72b10

14 files changed

+796
-23
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ BONUS = bonus/ft_comp_checker_bonus.c \
3737
bonus/ft_map_free_bonus.c \
3838
bonus/so_long_bonus.c \
3939
bonus/ft_check_path_bonus.c \
40-
bonus/ft_enemy_hooks.c
40+
bonus/ft_enemy_hooks.c \
41+
bonus/ft_collectible_animation.c \
42+
bonus/ft_both.c
4143

4244
SUPERLIB_DIR = ./superlib
4345
SUPERLIB = ./superlib/superlib.a

bonus/ft_both.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_both.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/02/07 18:12:49 by amait-ou #+# #+# */
9+
/* Updated: 2023/02/07 19:27:09 by amait-ou ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "so_long_bonus.h"
14+
15+
int ft_both(t_game *game)
16+
{
17+
ft_enemytextures(game);
18+
ft_collectible_animation(game);
19+
return (1);
20+
}

bonus/ft_collectible_animation.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_collectible_animation.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/02/07 17:14:47 by amait-ou #+# #+# */
9+
/* Updated: 2023/02/08 09:36:46 by amait-ou ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "so_long_bonus.h"
14+
15+
void ft_textures4(t_game *game)
16+
{
17+
int x;
18+
int y;
19+
20+
x = game->img.w * 50;
21+
y = game->img.h * 50;
22+
game->tex.co1 = mlx_xpm_file_to_image(
23+
game->mlx.mlx,
24+
"./textures/collectible_1.xpm", &x, &y);
25+
game->tex.co2 = mlx_xpm_file_to_image(
26+
game->mlx.mlx,
27+
"./textures/collectible_2.xpm", &x, &y);
28+
game->tex.co3 = mlx_xpm_file_to_image(
29+
game->mlx.mlx,
30+
"./textures/collectible_3.xpm", &x, &y);
31+
game->tex.co4 = mlx_xpm_file_to_image(
32+
game->mlx.mlx,
33+
"./textures/collectible_4.xpm", &x, &y);
34+
}
35+
36+
void ft_enemy_animation(t_game *game, int j, int i)
37+
{
38+
if (game->col.c == 1)
39+
{
40+
ft_texture_helper(game, game->tex.bgd, j, i);
41+
ft_texture_helper(game, game->tex.co1, j, i);
42+
}
43+
if (game->col.c == 6)
44+
{
45+
ft_texture_helper(game, game->tex.bgd, j, i);
46+
ft_texture_helper(game, game->tex.co2, j, i);
47+
}
48+
if (game->col.c == 11)
49+
{
50+
ft_texture_helper(game, game->tex.bgd, j, i);
51+
ft_texture_helper(game, game->tex.co3, j, i);
52+
}
53+
if (game->col.c == 16)
54+
{
55+
ft_texture_helper(game, game->tex.bgd, j, i);
56+
ft_texture_helper(game, game->tex.co4, j, i);
57+
}
58+
}
59+
60+
int ft_collectible_animation(t_game *game)
61+
{
62+
if (game->col.c == 16)
63+
game->col.c -= 16;
64+
game->col.c++;
65+
return (1);
66+
}

bonus/ft_game_render_bonus.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/01/30 01:33:55 by amait-ou #+# #+# */
9-
/* Updated: 2023/02/07 11:14:28 by amait-ou ### ########.fr */
9+
/* Updated: 2023/02/07 17:55:42 by amait-ou ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -20,6 +20,7 @@ void ft_game_render(t_game *game)
2020
i = 0;
2121
ft_textures1(game);
2222
ft_textures2(game);
23+
ft_textures4(game);
2324
while (i < game->len)
2425
{
2526
j = 0;

bonus/ft_player_moves_bonus.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/01/29 00:03:36 by amait-ou #+# #+# */
9-
/* Updated: 2023/02/07 15:38:55 by amait-ou ### ########.fr */
9+
/* Updated: 2023/02/07 19:12:37 by amait-ou ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -26,7 +26,7 @@ void ft_move_right(t_game *game)
2626
if (game->map[y][x + 1] == 'C')
2727
game->cols--;
2828
ft_player_editer(game, y, x, 'r');
29-
ft_printf("%s[+]%s Move -> %s%d%s\n", B, W, B, game->moves++, W);
29+
game->moves++;
3030
}
3131
else if (game->map[y][x + 1] == 'E')
3232
{
@@ -55,7 +55,7 @@ void ft_move_left(t_game *game)
5555
if (game->map[y][x - 1] == 'C')
5656
game->cols--;
5757
ft_player_editer(game, y, x, 'l');
58-
ft_printf("%s[+]%s Move -> %s%d%s\n", B, W, B, game->moves++, W);
58+
game->moves++;
5959
}
6060
else if (game->map[y][x - 1] == 'E')
6161
{
@@ -83,7 +83,7 @@ void ft_move_up(t_game *game)
8383
if (game->map[y - 1][x] == 'C')
8484
game->cols--;
8585
ft_player_editer(game, y, x, 'u');
86-
ft_printf("%s[+]%s Move -> %s%d%s\n", B, W, B, game->moves++, W);
86+
game->moves++;
8787
}
8888
else if (game->map[y - 1][x] == 'E')
8989
{
@@ -111,7 +111,7 @@ void ft_move_down(t_game *game)
111111
if (game->map[y + 1][x] == 'C')
112112
game->cols -= 1;
113113
ft_player_editer(game, y, x, 'd');
114-
ft_printf("%s[+]%s Move -> %s%d%s\n", B, W, B, game->moves++, W);
114+
game->moves++;
115115
}
116116
else if (game->map[y + 1][x] == 'E')
117117
{

bonus/ft_put_textures_bonus.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/01/22 17:16:59 by amait-ou #+# #+# */
9-
/* Updated: 2023/02/07 11:52:46 by amait-ou ### ########.fr */
9+
/* Updated: 2023/02/08 09:38:19 by amait-ou ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -19,9 +19,6 @@ void ft_textures1(t_game *game)
1919

2020
x = game->img.w * 50;
2121
y = game->img.h * 50;
22-
game->tex.col = mlx_xpm_file_to_image(
23-
game->mlx.mlx,
24-
"./textures/collectible.xpm", &x, &y);
2522
game->tex.wal = mlx_xpm_file_to_image(
2623
game->mlx.mlx,
2724
"./textures/wall.xpm", &x, &y);
@@ -79,9 +76,9 @@ void ft_put_textures(t_game *game, int i, int j)
7976
{
8077
while (game->map[i][j])
8178
{
82-
if (game->map[i][j] == '1' || game->map[i][j] == 'C' ||
83-
game->map[i][j] == 'P' || game->map[i][j] == 'E' ||
84-
game->map[i][j] == '1' || game->map[i][j] == 'M')
79+
if (game->map[i][j] == '1' || game->map[i][j] == 'P'
80+
|| game->map[i][j] == 'E' || game->map[i][j] == '1'
81+
|| game->map[i][j] == 'M')
8582
ft_texture_helper(game, game->tex.bgd, j, i);
8683
if (game->map[i][j] == '1')
8784
ft_texture_helper(game, game->tex.wal, j, i);
@@ -92,9 +89,11 @@ void ft_put_textures(t_game *game, int i, int j)
9289
if (game->map[i][j] == 'E')
9390
ft_texture_helper(game, game->tex.ext, j, i);
9491
if (game->map[i][j] == 'C')
95-
ft_texture_helper(game, game->tex.col, j, i);
92+
ft_enemy_animation(game, j, i);
9693
if (game->map[i][j] == 'M')
9794
ft_texture_helper(game, game->tex.ene, j, i);
9895
++j;
9996
}
97+
mlx_string_put(game->mlx.mlx, game->mlx.win, 0 * 50, 0 * 50,
98+
0xFF00FFFF, ft_itoa(game->moves));
10099
}

bonus/ft_vars_init_bonus.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/01/26 15:15:43 by amait-ou #+# #+# */
9-
/* Updated: 2023/02/07 16:06:38 by amait-ou ### ########.fr */
9+
/* Updated: 2023/02/08 09:08:02 by amait-ou ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -24,8 +24,9 @@ void ft_vars_init(t_game *game)
2424
game->cols = 0;
2525
game->plrs = 0;
2626
game->exts = 0;
27-
game->moves = 1;
27+
game->moves = 0;
2828
game->enes = 0;
2929
game->ene.x = 0;
3030
game->ene.y = 0;
31+
game->col.c = 1;
3132
}

bonus/so_long_bonus.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/01/25 16:29:24 by amait-ou #+# #+# */
9-
/* Updated: 2023/02/07 13:56:29 by amait-ou ### ########.fr */
9+
/* Updated: 2023/02/07 18:13:41 by amait-ou ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -24,7 +24,7 @@ int main(int ac, char **ag)
2424
{
2525
ft_mlx_init(&game);
2626
ft_game_render(&game);
27-
mlx_loop_hook(game.mlx.mlx, ft_enemytextures, &game);
27+
mlx_loop_hook(game.mlx.mlx, ft_both, &game);
2828
mlx_hook(game.mlx.win, 2, 0, ft_key_hook, &game);
2929
mlx_hook(game.mlx.win, 17, 0, ft_game_exit, &game);
3030
mlx_loop(game.mlx.mlx);

bonus/so_long_bonus.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/01/16 10:38:07 by amait-ou #+# #+# */
9-
/* Updated: 2023/02/07 16:03:55 by amait-ou ### ########.fr */
9+
/* Updated: 2023/02/08 09:37:34 by amait-ou ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -37,7 +37,10 @@
3737

3838
typedef struct s_textures
3939
{
40-
void *col;
40+
void *co1;
41+
void *co2;
42+
void *co3;
43+
void *co4;
4144
void *wal;
4245
void *pl1;
4346
void *pl2;
@@ -74,6 +77,11 @@ typedef struct s_enemy
7477
int x;
7578
} t_ene;
7679

80+
typedef struct s_collectible
81+
{
82+
int c;
83+
} t_col;
84+
7785
typedef struct s_mlx
7886
{
7987
void *mlx;
@@ -95,6 +103,7 @@ typedef struct s_game
95103
t_plr plr;
96104
t_ext ext;
97105
t_ene ene;
106+
t_col col;
98107
t_mlx mlx;
99108
} t_game;
100109

@@ -125,6 +134,7 @@ void ft_textures1(t_game *game);
125134
void ft_textures2(t_game *game);
126135
void ft_texture_helper(t_game *game, void *img, int j, int i);
127136
void ft_textures3(t_game *game, int j, int i);
137+
void ft_textures4(t_game *game);
128138
void ft_put_textures(t_game *game, int i, int j);
129139
void ft_player_coordonates(t_game *game, char c);
130140
void ft_player_editer(t_game *game, int y, int x, char c);
@@ -148,4 +158,11 @@ void ft_map_free(t_game *game);
148158
// Game Banner
149159
void ft_game_banner(void);
150160

161+
// Collectible Animation
162+
int ft_collectible_animation(t_game *game);
163+
void ft_enemy_animation(t_game *game, int j, int i);
164+
165+
// MLx Hook
166+
int ft_both(t_game *game);
167+
151168
#endif

mandatory/ft_put_textures.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/01/22 17:16:59 by amait-ou #+# #+# */
9-
/* Updated: 2023/02/07 06:27:24 by amait-ou ### ########.fr */
9+
/* Updated: 2023/02/07 17:13:25 by amait-ou ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -21,7 +21,7 @@ void ft_textures1(t_game *game)
2121
y = game->img.h * 50;
2222
game->tex.col = mlx_xpm_file_to_image(
2323
game->mlx.mlx,
24-
"./textures/collectible.xpm", &x, &y);
24+
"./textures/collectible_1.xpm", &x, &y);
2525
game->tex.wal = mlx_xpm_file_to_image(
2626
game->mlx.mlx,
2727
"./textures/wall.xpm", &x, &y);

0 commit comments

Comments
 (0)