/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/08 14:14:02 by dkaiser #+# #+# */
-/* Updated: 2024/05/15 14:04:06 by dkaiser ### ########.fr */
+/* Updated: 2024/05/15 14:48:10 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
int y;
} t_ivector;
-typedef struct s_player
+typedef struct s_actor
{
t_vector position;
t_vector direction;
t_vector velocity;
t_ivector size;
mlx_image_t *img;
-} t_player;
+} t_actor;
typedef struct s_tilemap
{
{
mlx_t *mlx;
void *window;
- t_player player;
+ t_actor player;
int input_direction;
t_tilemap map;
} t_game;
t_vector b_pos, t_ivector b_size);
int check_wall_collision(t_vector a_pos, t_ivector a_size,
t_tilemap *map);
-void move_and_slide(t_player *player, t_tilemap *map,
+void move_and_slide(t_actor *actor, t_tilemap *map,
double delta_time);
int is_on_floor(t_vector pos, t_ivector size, t_tilemap *map);
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/14 11:48:59 by dkaiser #+# #+# */
-/* Updated: 2024/05/15 13:20:29 by dkaiser ### ########.fr */
+/* Updated: 2024/05/15 14:47:26 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
return (0);
}
-void move_and_slide(t_player *player, t_tilemap *map, double delta_time)
+void move_and_slide(t_actor *actor, t_tilemap *map, double delta_time)
{
t_vector move_pos;
- move_pos.x = player->position.x + (player->velocity.x * delta_time);
- move_pos.y = player->position.y;
+ move_pos.x = actor->position.x + (actor->velocity.x * delta_time);
+ move_pos.y = actor->position.y;
- if ((check_wall_collision(move_pos, player->size, map) & (RIGHT | LEFT)) == 0)
- player->position.x = move_pos.x;
+ if ((check_wall_collision(move_pos, actor->size, map) & (RIGHT | LEFT)) == 0)
+ actor->position.x = move_pos.x;
else
- player->velocity.x = 0;
+ actor->velocity.x = 0;
- move_pos.x = player->position.x;
- move_pos.y = player->position.y + (player->velocity.y * delta_time);
- if ((check_wall_collision(move_pos, player->size, map) & (UP | DOWN)) == 0)
- player->position.y = move_pos.y;
+ move_pos.x = actor->position.x;
+ move_pos.y = actor->position.y + (actor->velocity.y * delta_time);
+ if ((check_wall_collision(move_pos, actor->size, map) & (UP | DOWN)) == 0)
+ actor->position.y = move_pos.y;
else
- player->velocity.y = 0;
+ actor->velocity.y = 0;
}
int is_on_floor(t_vector pos, t_ivector size, t_tilemap *map)
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 14:50:09 by dkaiser #+# #+# */
-/* Updated: 2024/05/15 12:13:03 by dkaiser ### ########.fr */
+/* Updated: 2024/05/15 14:46:09 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
static void init_hooks(t_game *game);
-static void init_player(t_game *game);
+static void init_actor(t_game *game);
int init(t_game *game)
{
// TODO: make size and title dynamic
game->input_direction = ZERO;
init_hooks(game);
- init_player(game);
+ init_actor(game);
return (0);
}
mlx_key_hook(game->mlx, on_key_input, game);
}
-static void init_player(t_game *game)
+static void init_actor(t_game *game)
{
mlx_texture_t *texture;
- t_player *player;
+ t_actor *player;
player = &game->player;
texture = mlx_load_png("textures/player.png");
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/14 12:40:05 by dkaiser #+# #+# */
-/* Updated: 2024/05/15 13:53:01 by dkaiser ### ########.fr */
+/* Updated: 2024/05/15 14:46:26 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
void player_process(t_game *game)
{
- t_player *player;
+ t_actor *player;
player = &game->player;
player->direction = get_direction_from_input(game);