Game Development Reference
In-Depth Information
23 end
24
25 def draw
26 returnif done?
27
image = current_frame
image . draw(
28
@x - image . width / 2 + 3 ,
29
@y - image . height / 2 - 35 ,
30
20 )
31
32 end
33
34 def done?
35 @done ||= @current_frame == animation . size
36 end
37
38
private
39
40 def current_frame
41 animation [ @current_frame % animation . size ]
42 end
43
44 def frame_expired?
45 now = Gosu . milliseconds
46 @last_frame ||= now
47 if (now - @last_frame ) > FRAME_DELAY
48 @last_frame = now
49 end
50 end
51 end
There is nothing fancy about this implementation. Most of it is taken from “Images And
Animation” chapter.
Running The Prototype
We have walked through all the code. You can get it at GitHub .
Now it's time to give it a spin. There is a video of me playing it available on YouTube, but
it's always best to experience it firsthand. Run main.rb to start the game:
$ ruby 03-prototype/main.rb
Hit N to start new game.
Search WWH ::




Custom Search