summaryrefslogtreecommitdiff
path: root/src/init.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-05-11 16:26:51 +0200
committerDominik Kaiser2024-05-11 16:26:51 +0200
commitf199b13df1350aa864a9104616f0d9b82606b4ed (patch)
treee4b79a06bb668a91b360807ab182eab6ce210957 /src/init.c
parent24a6825a00bf4ac319f57ed12e76afc8f1c9f401 (diff)
downloadso_long-f199b13df1350aa864a9104616f0d9b82606b4ed.tar.gz
so_long-f199b13df1350aa864a9104616f0d9b82606b4ed.zip
Finish map input
Diffstat (limited to 'src/init.c')
-rw-r--r--src/init.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/init.c b/src/init.c
index 3c15791..5277b5c 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/10 13:05:13 by dkaiser ### ########.fr */
+/* Updated: 2024/05/11 16:23:54 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,23 +14,16 @@
#include "so_long.h"
static void init_hooks(t_game *game);
-static void init_player(t_player *player, int x, int y);
+static void init_player(t_game *game);
int init(t_game *game)
{
- mlx_texture_t *texture;
game->mlx = mlx_init(1920, 1080, "so_long", false);
// TODO: make size and title dynamic
game->input_direction = ZERO;
init_hooks(game);
- init_player(&game->player, 960, 540);
- // TODO: make player spawn point dynamic
- texture = mlx_load_png("textures/player.png");
- game->player.img = mlx_texture_to_image(game->mlx, texture);
- mlx_resize_image(game->player.img, 48, 48);
- mlx_image_to_window(game->mlx, game->player.img, game->player.position.x,
- game->player.position.y);
+ init_player(game);
return (0);
}
@@ -40,10 +33,19 @@ static void init_hooks(t_game *game)
mlx_key_hook(game->mlx, on_key_input, game);
}
-static void init_player(t_player *player, int x, int y)
+static void init_player(t_game *game)
{
- player->position.x = x;
- player->position.y = y;
+ mlx_texture_t *texture;
+ t_player *player;
+
+ player = &game->player;
+ texture = mlx_load_png("textures/player.png");
+ player->position.x = game->map.player_start_tile.x * 48;
+ player->position.y = game->map.player_start_tile.y * 48;
player->velocity.x = 0;
player->velocity.y = 0;
+ player->img = mlx_texture_to_image(game->mlx, texture);
+ mlx_resize_image(player->img, 48, 48);
+ mlx_image_to_window(game->mlx, player->img, player->position.x,
+ player->position.y);
}