File: joy.rb

package info (click to toggle)
libsdl-ruby 0.7-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 408 kB
  • ctags: 360
  • sloc: ansic: 2,714; ruby: 781; makefile: 120
file content (37 lines) | stat: -rw-r--r-- 796 bytes parent folder | download
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
require 'sdl'

SDL.init( SDL::INIT_VIDEO|SDL::INIT_JOYSTICK )
screen = SDL::setVideoMode(640,480,16,SDL::SWSURFACE)

if SDL::Joystick.num == 0 then
  raise "joystick not found"
end

print SDL::Joystick.name(0),"\n"
joy=SDL::Joystick.open(0)

event=SDL::Event.new

while true 
  if  event.poll != 0 then
    if event.type==SDL::Event::QUIT then
      break
    end
    if event.type==SDL::Event::KEYDOWN then
      exit
    end
  end
  SDL::Joystick.updateAll
  screen.fillRect(0,0,640,480,0)
  screen.drawFilledCircle( joy.axis(0)/500+320, joy.axis(1)/500+200,10,0xff)
  for i in 0..joy.numButtons-1
    if joy.button(i) then
      screen.drawFilledCircle( i*30+30,50,10,0xff )
    else
      screen.drawCircle( i*30+30,50,10,0xff )
    end
  end
  screen.updateRect(0,0,0,0)
end

print "exit\n"