diff options
author | Henrique Alves <henrique.alves@itsjungle.xyz> | 2024-04-28 22:20:26 +0300 |
---|---|---|
committer | Henrique Alves <henrique.alves@itsjungle.xyz> | 2024-04-28 22:20:26 +0300 |
commit | 94e1881676e39bd8b8e6a8ee98e541102b380549 (patch) | |
tree | ca5165f60b60359b7b0e6fe55af1105a8ab81d23 | |
parent | f6e3396a5a653c3ae124afcd74bac5c9c7e50ae1 (diff) | |
download | gamejam-slgj-2024-94e1881676e39bd8b8e6a8ee98e541102b380549.tar.gz gamejam-slgj-2024-94e1881676e39bd8b8e6a8ee98e541102b380549.tar.bz2 gamejam-slgj-2024-94e1881676e39bd8b8e6a8ee98e541102b380549.zip |
prototyping runtime code evaluation
-rw-r--r-- | scripts/keys.scm | 2 | ||||
-rw-r--r-- | scripts/main.scm | 41 | ||||
-rw-r--r-- | sources/core.h | 6 |
3 files changed, 39 insertions, 10 deletions
diff --git a/scripts/keys.scm b/scripts/keys.scm index 963fb41..1ed31bf 100644 --- a/scripts/keys.scm +++ b/scripts/keys.scm @@ -1,3 +1,5 @@ +(define KEY_ENTER 257) +(define KEY_BACKSPACE 259) (define KEY_RIGHT 262) (define KEY_LEFT 263) (define KEY_DOWN 264) diff --git a/scripts/main.scm b/scripts/main.scm index 0e98e7a..048c7eb 100644 --- a/scripts/main.scm +++ b/scripts/main.scm @@ -7,27 +7,48 @@ (define text-box (make-rect 30 180 250 80)) (define mouse-on-text #f) +(define prompt-text "") (define (update) -;; (cond ((rl-is-key-down KEY_RIGHT) (set! b (rl-load-texture))) ;; right -;; ((rl-is-key-down KEY_LEFT) (set! a (+ a 1))) ;; left -;; ((rl-is-key-down KEY_DOWN) (gc)) ;; down -;; ) -;; (display (rl-get-mouse-position)) -;; (newline) + ;; (cond ((rl-is-key-down KEY_RIGHT) (set! b (rl-load-texture))) ;; right + ;; ((rl-is-key-down KEY_LEFT) (set! a (+ a 1))) ;; left + ;; ((rl-is-key-down KEY_DOWN) (gc)) ;; down + ;; ) + ;; (display (rl-get-mouse-position)) + ;; (newline) (define mouse-pos (rl-get-mouse-position)) (define mouse-pos-point (make-point (mouse-pos 0) (mouse-pos 1))) (set! mouse-on-text (is-point-inside-rect? mouse-pos-point text-box)) - + (if mouse-on-text + (let ((key (rl-get-char-pressed))) + (cond ((and (>= key 32) (<= key 125)) + (set! prompt-text + (string-append prompt-text (string (integer->char key))))) + ) + )) + + (if (rl-is-key-down KEY_ENTER) + (begin + (eval-string prompt-text))) + #f ) (define (draw) - (rl-draw-rectangle (rect-x text-box) (rect-y text-box) (rect-width text-box) (rect-height text-box) (make-color 190 100 255)) + (rl-draw-rectangle + (rect-x text-box) + (rect-y text-box) + (rect-width text-box) + (rect-height text-box) + (make-color 190 100 255)) - (rl-draw-text (format #f "~A" mouse-on-text) 100 100 30 (make-color 100 100 100)) - #f + (rl-draw-text + (format #f "~A" mouse-on-text) 100 100 30 (make-color 100 100 100)) + + (rl-draw-text prompt-text 30 180 20 (make-color 0 0 0)) ) + + diff --git a/sources/core.h b/sources/core.h index 70a7d81..3717a60 100644 --- a/sources/core.h +++ b/sources/core.h @@ -17,7 +17,13 @@ static s7_pointer rl_is_key_down(s7_scheme *s7, s7_pointer args) { return(s7_make_boolean(s7, isKey)); } +static s7_pointer rl_get_char_pressed(s7_scheme *s7, s7_pointer args) { + int key = GetCharPressed(); + return(s7_make_integer(s7, key)); +} + static void rl_core_define_methods(s7_scheme *s7) { s7_define_function(s7, "rl-is-key-down", rl_is_key_down, 1, 0, false, "(rl-is-key-down KEY)"); s7_define_function(s7, "rl-get-mouse-position", rl_get_mouse_position, 0, 0, false, "(rl-get-mouse-position)"); + s7_define_function(s7, "rl-get-char-pressed", rl_get_char_pressed, 0, 0, false, "(rl-get-char-pressed)"); } |