]> git.dkaiser.de - 42/so_long.git/commitdiff
Setup basic structure and add basic input handling
authorDominik Kaiser <dkaiser@1-C-7.42heilbronn.de>
Thu, 9 May 2024 14:19:29 +0000 (16:19 +0200)
committerDominik Kaiser <dkaiser@1-C-7.42heilbronn.de>
Thu, 9 May 2024 14:19:29 +0000 (16:19 +0200)
Makefile
include/so_long.h
src/init.c [new file with mode: 0644]
src/loop.c [new file with mode: 0644]
src/main.c

index 145fc8a7f333b32a17244153ea8e72aeb7438bcf..6315601c415da6e5467f65c0ad345aa93519fc2e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ LIBS    =       -Llibft -lft -lm -Lmlx -lmlx
 FRMWRKS        =       -framework OpenGL -framework AppKit
 
 VPATH  :=      src
-SRC            =       main.c
+SRC            =       main.c init.c loop.c input.c
 
 OBJ_DIR        :=      obj
 OBJ            :=      $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o))
index c1c966b78ab9d04a34222eeeb968e75d123a9ce5..98b47117326de67147efd7d3ccf14ab2d25bda36 100644 (file)
@@ -6,13 +6,25 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/05/08 14:14:02 by dkaiser           #+#    #+#             */
-/*   Updated: 2024/05/09 12:01:41 by dkaiser          ###   ########.fr       */
+/*   Updated: 2024/05/09 16:13:43 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #ifndef SO_LONG_H
-#define SO_LONG_H
+# define SO_LONG_H
 
-#include "mlx.h"
+# include "libft.h"
+# include "mlx.h"
+
+typedef struct s_game
+{
+       void    *mlx;
+       void    *window;
+}                      t_game;
+
+int                    init(t_game *game);
+int                    loop(t_game *game);
+int    on_key_down(int key, t_game *game);
+int on_key_up(int keycode, t_game *game);
 
 #endif // SO_LONG_H
diff --git a/src/init.c b/src/init.c
new file mode 100644 (file)
index 0000000..569bed8
--- /dev/null
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   init.c                                             :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/05/09 14:50:09 by dkaiser           #+#    #+#             */
+/*   Updated: 2024/05/09 16:13:22 by dkaiser          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "mlx.h"
+#include "so_long.h"
+
+static void    init_hooks(t_game *game)
+{
+       mlx_loop_hook(game->mlx, loop, game);
+       /* mlx_key_hook(game->mlx, on_key_down, game); */
+       mlx_hook(game->window, 2, 0, on_key_down, game);
+       mlx_hook(game->window, 3, 0, on_key_up, game);
+}
+
+int    init(t_game *game)
+{
+       game->mlx = mlx_init();
+       game->window = mlx_new_window(game->mlx, 1920, 1080, "so_long");
+       // TODO: make size and title dynamic
+       init_hooks(game);
+       return (0);
+}
diff --git a/src/loop.c b/src/loop.c
new file mode 100644 (file)
index 0000000..506dad1
--- /dev/null
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   loop.c                                             :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/05/09 15:09:24 by dkaiser           #+#    #+#             */
+/*   Updated: 2024/05/09 15:10:15 by dkaiser          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "so_long.h"
+
+int    loop(t_game *game)
+{
+       return (0);
+}
index e76703f6670c549823d0e38671e4a2cbdfe971ea..db6b5247b887d3fa71f54d67d4bb2cc84751c316 100644 (file)
@@ -6,13 +6,17 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/05/08 14:14:13 by dkaiser           #+#    #+#             */
-/*   Updated: 2024/05/08 15:56:23 by dkaiser          ###   ########.fr       */
+/*   Updated: 2024/05/09 15:15:29 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
+#include "mlx.h"
 #include "so_long.h"
 
-int main(void) {
+int    main(void)
+{
+       t_game  game;
 
-    return 0;
+       init(&game);
+       mlx_loop(game.mlx);
 }