summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-10-30 18:39:57 +0100
committerCarlos Maiolino <[email protected]>2025-10-30 18:39:57 +0100
commitf497ea0100a28f8dffed57eebe52ec58c556e1e1 (patch)
tree714528abadda397a9695cb1b6def477b780998fc
parent005d4c349510d78ab10f1e7fa1c9f5f5f265d8e9 (diff)
Implement mouse tracking.
Make the object follow the mouse position Signed-off-by: Carlos Maiolino <[email protected]>
-rw-r--r--src/include/rb.h6
-rw-r--r--src/rb.c13
2 files changed, 15 insertions, 4 deletions
diff --git a/src/include/rb.h b/src/include/rb.h
index cc321e6..aba3488 100644
--- a/src/include/rb.h
+++ b/src/include/rb.h
@@ -3,9 +3,9 @@
#include <allegro5/allegro5.h>
-#define RB_WIDTH 1600
-#define RB_HEIGHT 900
-#define RB_FPS (1.0 / 30.0) /* 1 sec divided by 30 frames */
+#define RB_WIDTH 2240
+#define RB_HEIGHT 1400
+#define RB_FPS (1.0 / 80.0) /* 1 sec divided by 30 frames */
struct rb {
float width;
diff --git a/src/rb.c b/src/rb.c
index 7486d93..83a7f28 100644
--- a/src/rb.c
+++ b/src/rb.c
@@ -47,6 +47,9 @@ initialize_allegro(struct rb **p)
if (!al_install_keyboard())
goto err_alloc;
+ if (!al_install_mouse())
+ goto err_alloc;
+
rb->timer = al_create_timer(rb->fps);
if (!rb->timer)
goto err_alloc;
@@ -102,6 +105,9 @@ register_events(struct rb *rb)
al_get_display_event_source(rb->display));
al_register_event_source(rb->event_queue,
al_get_timer_event_source(rb->timer));
+ al_register_event_source(rb->event_queue,
+ al_get_mouse_event_source());
+ al_hide_mouse_cursor(rb->display);
}
void
@@ -145,6 +151,11 @@ start_game(struct rb *rb)
redraw = true;
break;
+ case ALLEGRO_EVENT_MOUSE_AXES:
+ x = event.mouse.x;
+ y = event.mouse.y;
+ break;
+
case ALLEGRO_EVENT_KEY_DOWN:
key[event.keyboard.keycode] = KEY_SEEN | KEY_DOWN;
break;
@@ -180,7 +191,7 @@ start_game(struct rb *rb)
al_draw_textf(rb->font, al_map_rgb(255, 255, 255),
0, 0, 0,
"X: %.1f Y: %.1f", x, y);
- al_draw_filled_rectangle(x, y, x+10, y+10,
+ al_draw_filled_rectangle(x, y, x+40, y+120,
al_map_rgb(255, 0, 0));
al_flip_display();