Scheme .动态改变大爆炸中的时钟滴答声频率

Scheme .动态改变大爆炸中的时钟滴答声频率,scheme,racket,Scheme,Racket,on tick子句包括更改时钟滴答频率的选项。我已经包含了根据世界状态值动态更改值的代码。代码不起作用,我不明白为什么。另一个问题-如何调试世界程序?“步骤”选项不起作用 ; physical constants (define HEIGHT 300) (define WIDTH 100) (define YDELTA 3) ; graphical constants (define BACKG (empty-scene WIDTH HEIGHT)) (define ROCKET

on tick子句包括更改时钟滴答频率的选项。我已经包含了根据世界状态值动态更改值的代码。代码不起作用,我不明白为什么。另一个问题-如何调试世界程序?“步骤”选项不起作用

; physical constants 

(define HEIGHT 300)
(define WIDTH  100)

(define YDELTA 3)

; graphical constants 
(define BACKG  (empty-scene WIDTH HEIGHT))
(define ROCKET (rectangle 5 30 "solid" "red"))
(define ROCKET-CENTER (/ (image-height ROCKET) 2))
(define ROCKET-XPOS 10)

; LRCD -> LRCD
(define (main1 s)
  (big-bang s
    [to-draw show]
    [on-key launch]
    [on-tick fly (clock-rate s)]))

; LRCD -> Image
; renders the state as a resting or flying rocket
(define (show x)
  (cond
    [(string? x) (rocket-ht HEIGHT)]
    [(<= -3 x -1)
     (place-image (text (number->string x) 20 "red")
                  ROCKET-XPOS (* 3/4 WIDTH)
                  (rocket-ht HEIGHT))]
    [(>= x 0)
     (rocket-ht x)]))

; LRCD -> image
; positions the rocket at correct height
(define (rocket-ht ht)
  (place-image ROCKET ROCKET-XPOS (- ht ROCKET-CENTER) BACKG))

; LRCD KeyEvent -> LRCD
; starts the count-down when space bar is pressed, 
; if the rocket is still resting 
(define (launch x ke)
  (cond
    [(string? x) (if (string=? ke " ") -3 x)]
    [else x]))

; LRCD -> LRCD
; raises the rocket by YDELTA,
;  if it is moving already 
(define (fly x)
  (cond
    [(string? x) x]
    [(<= -3 x -1) (if (= x -1) HEIGHT (add1 x))]
    [else (- x YDELTA)]))

(define (clock-rate s)
  (cond
    [(number? s) (if (< s 0) 1 1/28)]
    [else 1/28]))
;物理常数
(定义高度300)
(定义宽度100)
(定义YDELTA 3)
; 图形常数
(定义背景(空场景宽度高度))
(定义火箭(矩形5 30“实心”“红色”))
(定义火箭中心(/(火箭图像高度)2))
(定义ROCKET-XPOS 10)
; LRCD->LRCD
(定义(main1s)
(大爆炸)
[画展]
[关键发布时]
[实时(时钟速率)])
; LRCD->图像
; 将状态渲染为静止或飞行的火箭
(定义(显示x)
(续)
[(字符串?x)(火箭高度)]
[(字符串x)20“红色”)
火箭-XPOS(*3/4宽)
(火箭高度)]
[(>=x0)
(火箭ht x)])
; LRCD->图像
; 将火箭定位在正确的高度
(定义(火箭ht)
(将图像放在火箭-XPOS(-ht火箭-中心)背面)
; LRCD键事件->LRCD
; 按下空格键时开始倒计时,
; 如果火箭还在静止
(定义(启动x ke)
(续)
[(字符串?x)(如果(字符串=?ke“”)-3 x)]
[else x]))
; LRCD->LRCD
; 伊德尔塔举起火箭,
;  如果它已经在移动
(定义(飞行x)
(续)
[(字符串?x)x]

[(
(时钟频率s)
在调用
大爆炸
时只计算一次。为什么要动态更改计时速率?游戏通常以恒定速率运行。如果要计算秒数,可以根据计时速率计算秒数,并在世界状态中存储计时器。因为在“如何设计程序"版本2要求如下:练习58。定义main2,这样你就可以发射火箭并观看它升空。阅读on tick子句以确定一个tick的长度以及如何更改它。这并不意味着动态更改它。如果你不指定它,它将有一个默认值。你可以按照molbdnilo在他的c中指出的那样更改它奥蒙特。