jacius / rubygame

Flexible cross-platform game programming library for Ruby

This URL has Read+Write access

rubygame / samples / demo_sfont.rb
100755 53 lines (41 sloc) 1.407 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby
 
# This program is PUBLIC DOMAIN.
# It is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
require "rubygame"
require "rubygame/sfont"
include Rubygame
 
def main(*args)
  font_name = ""
 
if args.length < 1
    font_name = "term16.png"
puts <<EOF
You can pass the filename of a SFont-compatible font as the
first argument to try it, e.g.: ./demo_sfont.rb my_font.png
 
There are many sample fonts available online:
http://user.cs.tu-berlin.de/~karlb/sfont/fonts.html
EOF
  else
    font_name = args[0]
end
 
  screen = Screen.set_mode([700,400])
  queue = EventQueue.new()
  queue.ignore = [ActiveEvent,MouseMotionEvent,MouseUpEvent,MouseDownEvent]
 
 
  screen.title = "SFont Test (%s)"%font_name
  font = SFont.new(font_name)
  renders = []
  renders << font.render("This font is: %s"%font_name)
  renders << font.render("I say, \"I love pie!\"")
  renders << font.render("I could eat #{Math::PI} pies.")
  renders << font.render("0 1 2 3 4 5 6 7 8 9")
  renders << font.render("!@\#$%^&*()[]{}<>;:/\\+=-_'`\"")
  renders << font.render("abcdefghijklmnopqrstuvwxyz")
  renders << font.render("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
 
  (renders.length).times do |i|
    renders[i].blit(screen,[10,10+font.height*i])
  end
  screen.update()
 
queue.wait()
end
 
main(*ARGV)