From 44e96e43a8d98b6f4acc146b25e75a3795c10309 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 19 Apr 2021 23:08:57 -0400 Subject: Update game code. --- game.scm | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 172 insertions(+), 36 deletions(-) diff --git a/game.scm b/game.scm index 7277322..edf43fc 100644 --- a/game.scm +++ b/game.scm @@ -7,11 +7,13 @@ #:use-module (chickadee scripting) #:use-module (ice-9 match) #:use-module (oop goops) + #:use-module (srfi srfi-1) #:use-module (starling asset) #:use-module (starling gui) #:use-module (starling kernel) #:use-module (starling node) #:use-module (starling node-2d) + #:use-module (starling ring-buffer) #:use-module (starling scene) #:duplicates (merge-generics) #:export (launch-game)) @@ -35,7 +37,9 @@ (define-asset dialog-box-texture (load-image "assets/images/dialog-box.png")) (define-asset darkness (load-image "assets/images/darkness.png")) (define-asset room-background (load-image "assets/images/room.png")) -(define-asset scanner-texture (load-image "assets/images/scanner.png")) +(define-asset door-lock-texture (load-image "assets/images/door-lock.png")) +(define-asset terminal-texture (load-image "assets/images/terminal.png")) +(define-asset terminal-background (load-image "assets/images/terminal-background.png")) (define-asset monogram-font (load-font "assets/fonts/monogram_extended.ttf" 12)) (define-asset monogram-font-big (load-font "assets/fonts/monogram_extended.ttf" 24)) @@ -75,13 +79,24 @@ ;;; Device ;;; +(define %device-hover-tint (rgb #xff7777)) + ;; An object you can interact with by clicking. (define-class () (texture #:accessor texture #:init-keyword #:texture #:init-value null-texture #:watch? #t)) +(define-method (refresh-hover-state (device )) + ;; A crude way of showing the user something is clickable. + (set! (tint (& device sprite)) + (if (hover? device) + %device-hover-tint + white))) + (define-method (on-change (device ) slot-name old new) (case slot-name + ((hover?) + (refresh-hover-state device)) ((texture) (let ((sprite (& device sprite))) (when sprite @@ -94,7 +109,9 @@ (replace device (make #:name 'sprite - #:texture (texture device)))) + #:rank 1 + #:texture (texture device))) + (refresh-hover-state device)) ;;; @@ -111,11 +128,29 @@ (state #:accessor state #:init-value #f) (friendship #:accessor friendship #:init-value 0) (dialog-container #:accessor dialog-container) - (click-channel #:getter click-channel #:init-thunk make-channel)) + (click-channel #:accessor click-channel #:init-thunk make-channel) + (terminal-locked? #:accessor terminal-locked? #:init-value #t) + (terminal-channel #:accessor terminal-channel #:init-thunk make-channel) + (terminal-lines #:accessor terminal-lines #:init-form (make-ring-buffer 17))) + +(define-method (reboot (game )) + (set! (click-channel game) (make-channel)) + (set! (terminal-locked? game) #t) + (set! (terminal-channel game) (make-channel)) + (set! (terminal-lines game) (make-ring-buffer 17)) + (next-method)) (define-method (detach-all (game )) (for-each detach (children game))) +(define (run-on-left-click node proc) + (lambda (widget button) + (if (eq? button 'left) + (begin + (run-script node (proc)) + #t) + #f))) + (define-method (dialog (game ) name line) (let ((old-state (state game)) (c (dialog-container game))) @@ -153,12 +188,9 @@ #:height 32.0 #:text (number->string n) #:listeners - `((click . ,(lambda (widget button) - (if (eq? button 'left) - (begin - (input n) - #t) - #f))))))) + `((click . ,(run-on-left-click game + (lambda () + (input n)))))))) (define (input n) (let ((pin (& game pin-pad display pin))) (when (< (string-length (text pin)) 6) @@ -172,7 +204,7 @@ (set! (state game) 'pin-entry) (parameterize ((current-theme gui-theme)) (attach-to game - ;; Hack to block clicks on devices in the room. + ;; Hack to block clicks on devices in the room. Not working! (make #:name 'blocker #:rank 98 @@ -223,12 +255,7 @@ #:width 64.0 #:height 32.0 #:listeners - `((click . ,(lambda (widget button) - (if (eq? button 'left) - (begin - (clear) - #t) - #f)))))) + `((click . ,(run-on-left-click game clear))))) (margin (make