summaryrefslogtreecommitdiff
path: root/src/init.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-05-29 13:11:19 +0200
committerGitHub2024-05-29 13:11:19 +0200
commit7b230503231e154c5400413b4f9b87dd6fcd8304 (patch)
treeaaa06976a569ad3f3452121800e6bf33fc8d14ac /src/init.c
parentcb6f98a5fa7bb2ed361abe68b3000f2e3f578ea7 (diff)
parent3ad8aa9e66f7e159b175a9a52e5ad00bbfd90734 (diff)
downloadso_long-7b230503231e154c5400413b4f9b87dd6fcd8304.tar.gz
so_long-7b230503231e154c5400413b4f9b87dd6fcd8304.zip
Merge collectibles-and-exit into master
Collectibles and exit
Diffstat (limited to 'src/init.c')
-rw-r--r--src/init.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/init.c b/src/init.c
index e7fedf2..40f15f1 100644
--- a/src/init.c
+++ b/src/init.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 14:50:09 by dkaiser #+# #+# */
-/* Updated: 2024/05/15 15:09:44 by dkaiser ### ########.fr */
+/* Updated: 2024/05/20 18:31:33 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,15 +14,16 @@
#include "so_long.h"
static void init_hooks(t_game *game);
-static void init_actor(t_game *game);
+static void init_player(t_game *game);
int init(t_game *game)
{
game->mlx = mlx_init(1920, 1080, "so_long", false);
// TODO: make size and title dynamic
game->input_direction = ZERO;
+ game->map.tile_size = (t_ivector){48, 48};
init_hooks(game);
- init_actor(game);
+ init_player(game);
return (0);
}
@@ -32,19 +33,17 @@ static void init_hooks(t_game *game)
mlx_key_hook(game->mlx, on_key_input, game);
}
-static void init_actor(t_game *game)
+static void init_player(t_game *game)
{
mlx_texture_t *texture;
t_actor *player;
player = &game->player;
texture = mlx_load_png("textures/player.png");
- player->position.x = game->map.player_start_tile.x * game->map.grid_size.x;
- player->position.y = game->map.player_start_tile.y * game->map.grid_size.y;
- player->velocity.x = 0;
- player->velocity.y = 0;
- player->size.x = 44;
- player->size.y = 44;
+ player->position = grid_to_screen_pos(game->map.player_start_tile,
+ game->map.tile_size);
+ player->velocity = (t_vector){0, 0};
+ player->size = (t_ivector){44, 44};
player->img = mlx_texture_to_image(game->mlx, texture);
mlx_resize_image(player->img, player->size.x, player->size.y);
mlx_image_to_window(game->mlx, player->img, player->position.x,