feat: add interval update
This commit is contained in:
parent
493991ef8f
commit
fb117e328a
1 changed files with 33 additions and 0 deletions
33
game.scm
33
game.scm
|
@ -22,9 +22,12 @@
|
||||||
(dom document)
|
(dom document)
|
||||||
(dom element)
|
(dom element)
|
||||||
(dom event)
|
(dom event)
|
||||||
|
(dom window)
|
||||||
(math vector)
|
(math vector)
|
||||||
(hoot ffi)
|
(hoot ffi)
|
||||||
|
(hoot debug)
|
||||||
(hoot hashtables)
|
(hoot hashtables)
|
||||||
|
(srfi srfi-9)
|
||||||
(ice-9 match))
|
(ice-9 match))
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,4 +148,34 @@
|
||||||
|
|
||||||
;; Main
|
;; Main
|
||||||
(set! *template* template-task)
|
(set! *template* template-task)
|
||||||
|
|
||||||
|
(define *update-list* '())
|
||||||
|
(define dt (/ 1000.0 60.0))
|
||||||
|
|
||||||
|
(define-record-type <timeout-function>
|
||||||
|
(make-timeout-function interval countdown func)
|
||||||
|
timeout-function?
|
||||||
|
(interval timeout-function-interval set-timeout-function-interval!)
|
||||||
|
(countdown timeout-function-countdown set-timeout-function-countdown!)
|
||||||
|
(func timeout-function-func))
|
||||||
|
|
||||||
|
(define (plus-clicks)
|
||||||
|
(set! *clicks* (+ *clicks* 1)))
|
||||||
|
|
||||||
|
(set! *update-list* (append *update-list* (list (make-timeout-function 60 60 plus-clicks))))
|
||||||
|
|
||||||
|
(define (update)
|
||||||
|
(for-each (lambda (i)
|
||||||
|
(dprint "countdown" (timeout-function-countdown i))
|
||||||
|
(if (= (timeout-function-countdown i) 0)
|
||||||
|
(begin
|
||||||
|
((timeout-function-func i))
|
||||||
|
(set-timeout-function-countdown! i (timeout-function-interval i))
|
||||||
|
(render))
|
||||||
|
(set-timeout-function-countdown! i (- (timeout-function-countdown i) 1))))
|
||||||
|
*update-list*)
|
||||||
|
(timeout update-callback dt))
|
||||||
|
|
||||||
|
(define update-callback (procedure->external update))
|
||||||
(render)
|
(render)
|
||||||
|
(timeout update-callback dt)
|
||||||
|
|
Loading…
Reference in a new issue