/* 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 */
/* */
/* ************************************************************************** */
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);
}
/* 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)
/* 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 */
/* */
/* ************************************************************************** */
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);
}