Racket's Big Bang framework - making a game go faster using tick rate?

蹲街弑〆低调 提交于 2019-12-11 01:53:35

问题


So in the Big Bang framework you can specify a tick rate:

(on-tick tick-handler tick-rate)

This tick-rate value is evaluated only once I believe (there is a similar question on here where this is stated as so).

If that's the case, how would one go about writing a game (such as Tetris) where you want the shape to drop down at a quicker rate as time goes by? I've got the shape-drop occurring on the tick-handler at present. If the tick-rate changed, the drop would occur more frequently. As it is, I can't figure out how to make this happen without that feature. Any clues?


回答1:


Set the tickrate to the fastest rate you need. Make a tick counter. In you tick-handler have something like:

 (define rate 4)
 (cond
   [(= (remainder tick-counter rate) 0)   do-the-same-as-before]
   [else                                  do-nothing-but-increment-counter])

When rate is 4, you will only activate your tick handler for every fourth tick. If you change rate to, say 2, you the speed is twice as fast. And when rate is 1, you will get the fastest speed.



来源:https://stackoverflow.com/questions/44356735/rackets-big-bang-framework-making-a-game-go-faster-using-tick-rate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!