Add start-game word, make foo-attributes words when GAME: foo is defined, don't lose the loop object after the game is over

db4
Doug Coleman 2010-06-08 18:05:28 -05:00
parent 4997489980
commit 46ad6b63e6
1 changed files with 12 additions and 4 deletions

View File

@ -1,7 +1,8 @@
! (c)2009 Joe Groff bsd license ! (c)2009 Joe Groff bsd license
USING: accessors combinators fry game.input game.loop generic kernel math USING: accessors audio.engine combinators destructors fry
parser sequences ui ui.gadgets ui.gadgets.worlds ui.gestures threads game.input game.loop generic kernel math parser sequences
words audio.engine destructors ; threads ui ui.gadgets ui.gadgets.worlds ui.gestures words
words.constant ;
IN: game.worlds IN: game.worlds
TUPLE: game-world < world TUPLE: game-world < world
@ -48,7 +49,7 @@ M: game-world begin-world
[ >>game-loop begin-game-world ] keep start-loop ; [ >>game-loop begin-game-world ] keep start-loop ;
M: game-world end-world M: game-world end-world
[ [ stop-loop ] when* f ] change-game-loop dup game-loop>> [ stop-loop ] when*
[ end-game-world ] [ end-game-world ]
[ audio-engine>> [ dispose ] when* ] [ audio-engine>> [ dispose ] when* ]
[ use-game-input?>> [ close-game-input ] when ] tri ; [ use-game-input?>> [ close-game-input ] when ] tri ;
@ -70,8 +71,15 @@ M: game-world apply-world-attributes
[ call-next-method ] [ call-next-method ]
} cleave ; } cleave ;
: start-game ( attributes -- game-world )
f swap open-window* ;
: define-attributes-word ( word tuple -- )
[ name>> "-attributes" append create-in ] dip define-constant ;
SYNTAX: GAME: SYNTAX: GAME:
CREATE CREATE
game-attributes parse-main-window-attributes game-attributes parse-main-window-attributes
2dup define-attributes-word
parse-definition parse-definition
define-main-window ; define-main-window ;