Add script scheduler and pre/post visual effects system.
This commit is contained in:
parent
67c25d93cb
commit
98ae464ab9
6 changed files with 260 additions and 10 deletions
37
game.scm
37
game.scm
|
@ -27,11 +27,13 @@
|
|||
(dom window)
|
||||
(game actors)
|
||||
(game audio)
|
||||
(game effects)
|
||||
(game level)
|
||||
(game levels level-1)
|
||||
(game levels level-2)
|
||||
(game levels level-3)
|
||||
(game levels level-4)
|
||||
(game scripts)
|
||||
(game tileset)
|
||||
(goblins core)
|
||||
(hoot bytevectors)
|
||||
|
@ -172,7 +174,11 @@
|
|||
(if (< idx (vector-length levels))
|
||||
(begin
|
||||
(save-game!)
|
||||
(load-level! idx))
|
||||
(run-script
|
||||
(lambda ()
|
||||
(show-effect! (make-fade-out+in-effect 1.0))
|
||||
(wait 30) ; ~half the effect time
|
||||
(load-level! idx))))
|
||||
(set! *state* 'win))))
|
||||
|
||||
;; Auto-save/load to local storage.
|
||||
|
@ -232,8 +238,11 @@
|
|||
(set! *gems* (cons *level-idx* *gems*)))
|
||||
(('emit x y)
|
||||
(play-sound-effect audio:emit))
|
||||
((or ('gate-open x y) ('gate-close x y))
|
||||
(('gate-open x y)
|
||||
(play-sound-effect audio:gate))
|
||||
(('gate-close x y)
|
||||
(play-sound-effect audio:gate)
|
||||
(show-effect! (make-screen-shake-effect 0.05)))
|
||||
((or ('floor-switch-on x y) ('floor-switch-off x y))
|
||||
(play-sound-effect audio:floor-switch))
|
||||
(('electric-switch-on x y)
|
||||
|
@ -252,13 +261,24 @@
|
|||
|
||||
(define dt (/ 1000.0 60.0)) ; aim for updating at 60Hz
|
||||
(define (update)
|
||||
;; TODO: what kind of work do we need to do each frame?
|
||||
(scheduler-tick! (current-scheduler))
|
||||
(timeout update-callback dt))
|
||||
(define update-callback (procedure->external update))
|
||||
|
||||
;; Render loop
|
||||
(define *current-effect* #f)
|
||||
(define (show-effect! effect)
|
||||
(set! *current-effect* effect)
|
||||
(effect-start! effect))
|
||||
(define (draw-current-effect type)
|
||||
(when (and *current-effect*
|
||||
(eq? type (effect-type *current-effect*)))
|
||||
(draw-effect context *current-effect*)
|
||||
(unless (effect-started? *current-effect*)
|
||||
(set! *current-effect* #f))))
|
||||
|
||||
(define number->string*
|
||||
(let ((cache (make-eq-hashtable))) ; assuming fixnums only
|
||||
(let ((cache (make-eq-hashtable))) ; assuming fixnums only
|
||||
(lambda (x)
|
||||
(or (hashtable-ref cache x)
|
||||
(let ((str (number->string x)))
|
||||
|
@ -362,6 +382,9 @@
|
|||
(set-text-align! context "center")
|
||||
(fill-text context "OUCH... x_x" (/ game-width 2.0) (/ game-height 2.0)))))
|
||||
|
||||
(define (draw-interstitial)
|
||||
(draw-level))
|
||||
|
||||
(define (draw-win)
|
||||
(set-fill-color! context "#000000")
|
||||
(set-text-align! context "left")
|
||||
|
@ -370,10 +393,12 @@
|
|||
(define (draw prev-time)
|
||||
(clear-rect context 0.0 0.0 *canvas-width* *canvas-height*)
|
||||
(set-transform! context 1.0 0.0 0.0 1.0 0.0 0.0)
|
||||
(set-scale! context *canvas-scale* *canvas-scale*)
|
||||
(scale! context *canvas-scale* *canvas-scale*)
|
||||
(draw-current-effect 'pre)
|
||||
(match *state*
|
||||
('play (draw-level))
|
||||
((or 'play 'interstitial) (draw-level))
|
||||
('win (draw-win)))
|
||||
(draw-current-effect 'post)
|
||||
(request-animation-frame draw-callback))
|
||||
(define draw-callback (procedure->external draw))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue