summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/init.c9
-rw-r--r--src/input.c8
-rw-r--r--src/loop.c14
3 files changed, 16 insertions, 15 deletions
diff --git a/src/init.c b/src/init.c
index d72f486..bd6b48f 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 12:11:01 by dkaiser ### ########.fr */
+/* Updated: 2024/05/10 12:13:33 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,15 +17,18 @@ static void init_player(t_player *player, int x, int y);
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
- mlx_texture_t *texture = mlx_load_png("textures/player.png");
+ texture = mlx_load_png("textures/player.png");
game->player.img = mlx_texture_to_image(game->mlx, texture);
- mlx_image_to_window(game->mlx, game->player.img, game->player.position.x, game->player.position.y);
+ mlx_image_to_window(game->mlx, game->player.img, game->player.position.x,
+ game->player.position.y);
return (0);
}
diff --git a/src/input.c b/src/input.c
index 40c5670..a6cb8d4 100644
--- a/src/input.c
+++ b/src/input.c
@@ -6,17 +6,17 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 15:37:40 by dkaiser #+# #+# */
-/* Updated: 2024/05/10 12:11:48 by dkaiser ### ########.fr */
+/* Updated: 2024/05/10 12:13:22 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
-void on_key_input(mlx_key_data_t event, void *params)
+void on_key_input(mlx_key_data_t event, void *params)
{
- t_game *game;
+ t_game *game;
- game = (t_game *) params;
+ game = (t_game *)params;
if (event.action == MLX_PRESS)
{
if (event.key == MLX_KEY_W || event.key == MLX_KEY_UP)
diff --git a/src/loop.c b/src/loop.c
index e994bc0..6162935 100644
--- a/src/loop.c
+++ b/src/loop.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 15:09:24 by dkaiser #+# #+# */
-/* Updated: 2024/05/10 11:17:33 by dkaiser ### ########.fr */
+/* Updated: 2024/05/10 12:17:03 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,16 +15,14 @@
void loop(void *params)
{
- t_game *game;
+ t_game *game;
- game = (t_game *) params;
+ game = (t_game *)params;
game->player.direction.x = ((game->input_direction & RIGHT) != 0)
- ((game->input_direction & LEFT) != 0);
game->player.direction.y = ((game->input_direction & DOWN) != 0)
- ((game->input_direction & UP) != 0);
-
- game->player.position.x += game->player.direction.x * PLAYER_MOVE_SPEED;
- game->player.position.y += game->player.direction.y * PLAYER_MOVE_SPEED;
-
- draw(game);
+ game->player.position.x += game->player.direction.x * PLAYER_MOVE_SPEED;
+ game->player.position.y += game->player.direction.y * PLAYER_MOVE_SPEED;
+ draw(game);
}