Allow any actor to push an event to the UI.
This commit is contained in:
parent
bcb235bd82
commit
a24d737bc7
4 changed files with 99 additions and 74 deletions
80
game.scm
80
game.scm
|
@ -67,6 +67,8 @@
|
|||
(define audio:exit (load-sound-effect "exit"))
|
||||
(define audio:pickup (load-sound-effect "pickup"))
|
||||
(define audio:die (load-sound-effect "die"))
|
||||
(define audio:electric-switch-on (load-sound-effect "electric-switch-on"))
|
||||
(define audio:electric-switch-off (load-sound-effect "electric-switch-off"))
|
||||
|
||||
;; Game state
|
||||
(define *state* #f)
|
||||
|
@ -196,45 +198,45 @@
|
|||
|
||||
;; Update loop
|
||||
(define (move-player dir)
|
||||
(define (do-move)
|
||||
(with-goblins
|
||||
(let ((player (level-player *level*)))
|
||||
(if ($ player 'alive?)
|
||||
(begin
|
||||
($ player 'move dir)
|
||||
($ (level-actor *level*) 'tick)
|
||||
;; TODO: Need a better way to receive events to play sounds
|
||||
;; and emit particles and stuff so any actor can trigger
|
||||
;; events.
|
||||
(let ((result
|
||||
(match ($ player 'event)
|
||||
(('bump)
|
||||
(play-sound-effect audio:bump)
|
||||
#f)
|
||||
(('push)
|
||||
(play-sound-effect audio:push)
|
||||
#f)
|
||||
(('exit)
|
||||
(play-sound-effect audio:exit)
|
||||
'next-level)
|
||||
(('die)
|
||||
(play-sound-effect audio:die)
|
||||
#f)
|
||||
(('gem)
|
||||
(play-sound-effect audio:pickup)
|
||||
;; TODO: Maybe show a little achievement popup when all gems
|
||||
;; are collected?
|
||||
(set! *gems* (cons *level-idx* *gems*))
|
||||
#f)
|
||||
(_ #f))))
|
||||
(update-objects!)
|
||||
(save-snapshot!)
|
||||
result))
|
||||
(begin
|
||||
(play-sound-effect audio:no)
|
||||
#f)))))
|
||||
(when (eq? (do-move) 'next-level)
|
||||
(next-level!)))
|
||||
(define level-complete? #f)
|
||||
(with-goblins
|
||||
(let ((player (level-player *level*))
|
||||
(level (level-actor *level*)))
|
||||
(cond
|
||||
(($ player 'alive?)
|
||||
(begin
|
||||
($ player 'move dir)
|
||||
($ level 'tick)
|
||||
(let lp ((events ($ level 'flush-events)))
|
||||
(match events
|
||||
(() (values))
|
||||
((event . rest)
|
||||
(match (pk 'event event)
|
||||
(('bump x y)
|
||||
(play-sound-effect audio:bump))
|
||||
(('push x y)
|
||||
(play-sound-effect audio:push))
|
||||
(('exit x y)
|
||||
(play-sound-effect audio:exit)
|
||||
(set! level-complete? #t))
|
||||
(('player-death x y)
|
||||
(play-sound-effect audio:die))
|
||||
(('pickup x y)
|
||||
(play-sound-effect audio:pickup)
|
||||
;; TODO: Maybe show a little achievement popup when all gems
|
||||
;; are collected?
|
||||
(set! *gems* (cons *level-idx* *gems*)))
|
||||
(('electric-switch-on x y)
|
||||
(play-sound-effect audio:electric-switch-on))
|
||||
(('electric-switch-off x y)
|
||||
(play-sound-effect audio:electric-switch-off))
|
||||
(_ (values)))
|
||||
(lp rest))))
|
||||
(update-objects!)
|
||||
(save-snapshot!)))
|
||||
(else
|
||||
(play-sound-effect audio:no)))))
|
||||
(when level-complete? (next-level!)))
|
||||
|
||||
(define dt (/ 1000.0 60.0)) ; aim for updating at 60Hz
|
||||
(define (update)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue