racket - how to save the state of a game scheme -


for example have game:

this game move bird on keyboard or mouse

(define-struct estado (ancho alto vel tiempo mov punto))  (define mapa (bitmap "mapa.png")) (define projo (bitmap "projo.png")) (define mario (bitmap "mario.png"))  (define (crear-mundo estado)    (big-bang estado   [to-draw pintar]   [on-tick tiempo-nuevo]   [on-mouse click]   [on-key cambiar-al-nuevo-mundo-teclado]   [stop-when fin-juego]))   (define (pintar nuevo-mundo)   (cond     [(colisiĆ³n nuevo-mundo area)      (place-image projo                   (posn-x (estado-punto nuevo-mundo))                   (posn-y (estado-punto nuevo-mundo))                   (place-image (text (string-append "tiempo: " (number->string (quotient (estado-tiempo nuevo-mundo) 28))) 12 "red") 40 20 mapa)                   )]     [else (place-image projo                        (posn-x (estado-punto nuevo-mundo))                        (posn-y (estado-punto nuevo-mundo))                        ;(place-image mario 750 500 (empty-scene 800 600))                        ;(place-image mario 750 500 mapa)                        (place-image (text (string-append "tiempo: " (number->string (quotient (estado-tiempo nuevo-mundo) 28))) 12 "green") 40 20 mapa)                        )]     )   ) 

create new state of game make-posn position of bird

(crear-mundo (make-estado 800 600 10 0 0 (make-posn 100 100))) 

how can save state of play position of bird when game run , position changes

the simplest use standard write , read:

#!racket  (define file "file.rc")  (define (save config)   (with-output-to-file file       (lambda () (write config))       #:mode 'text       #:exists 'truncate)   config)  (define (read)    (with-input-from-file file       (lambda () (read))))            

so imagine have loop somewhere pass new state next iteration. wrapping in (save state) save new file on last. (read) read file, perhaps when start up.

you might need check if exists need read/store state.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -