diff options
Diffstat (limited to 'snek.scm')
| -rw-r--r-- | snek.scm | 39 |
1 files changed, 30 insertions, 9 deletions
@@ -1,3 +1,9 @@ +(cond-expand ((and (compilation-target (_)) + (not raylib)) + (import (raylib)) + (define-cond-expand-feature raylib)) + (else #t)) + (define-syntax with-drawing (syntax-rules () ((with-drawing body ...) @@ -9,6 +15,7 @@ (define BLACK (raylib#make-color 0 0 0 255)) (define WHITE (raylib#make-color 255 255 255 255)) (define RED (raylib#make-color 255 0 0 255)) +(define GREEN (raylib#make-color 0 255 0 255)) (define KEY_ESC 256) (define KEY_RIGHT 262) @@ -152,15 +159,29 @@ 0 'right)) +(define (run-game) + (dynamic-wind + (lambda () (begin + (raylib#set-target-fps 60) + (raylib#init-window VP_WIDTH VP_HEIGHT "snek") + (raylib#set-exit-key KEY_ESC) + (set! game-running #t) + (display "GAME ON!"))) + (lambda () (let ((state (init))) + (place-apple! state) + (main-loop state))) + (lambda () (raylib#close-window)))) + +(define (run-game-bg) + (thread-start! (make-thread (lambda () (run-game)) "game-loop"))) + (define (main arg) - (raylib#set-target-fps 60) - (raylib#init-window VP_WIDTH VP_HEIGHT "snek") - (raylib#set-exit-key KEY_ESC) - (set! game-running #t) - (display "GAME ON!") - (let ((state (init))) - (place-apple! state) - (main-loop state)) - (raylib#close-window)) + ;; compilation-target (_) denotes the interpreter ! + (cond-expand ((compilation-target (_)) + (display "BG-RUN") + (run-game-bg)) + (else + (display "FG-RUN") + (run-game)))) (main '()) |
