r2d-takaokouji 0.0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/r2d +35 -0
- data/lib/console.rb +55 -0
- data/lib/r2d.rb +19 -0
- data/lib/r2d/adapters.rb +45 -0
- data/lib/r2d/adapters/gosu.rb +158 -0
- data/lib/r2d/circle.rb +35 -0
- data/lib/r2d/color.rb +48 -0
- data/lib/r2d/exceptions.rb +12 -0
- data/lib/r2d/helpers.rb +48 -0
- data/lib/r2d/image.rb +39 -0
- data/lib/r2d/line.rb +77 -0
- data/lib/r2d/quad.rb +42 -0
- data/lib/r2d/rectangle.rb +95 -0
- data/lib/r2d/song.rb +37 -0
- data/lib/r2d/sound.rb +37 -0
- data/lib/r2d/square.rb +20 -0
- data/lib/r2d/text.rb +42 -0
- data/lib/r2d/triangle.rb +41 -0
- data/lib/r2d/version.rb +5 -0
- data/lib/r2d/window.rb +92 -0
- metadata +82 -0
    
        data/bin/r2d
    ADDED
    
    | @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'r2d'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            case ARGV[0]
         | 
| 6 | 
            +
            when 'console'
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              require 'io/wait'
         | 
| 9 | 
            +
              require 'open3'
         | 
| 10 | 
            +
              require 'readline'
         | 
| 11 | 
            +
              
         | 
| 12 | 
            +
              path = __dir__.sub(' ', '\ ') << "/../lib/console.rb"
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              stdin, stdout, stderr, wait_thr = Open3.popen3("ruby #{path}")
         | 
| 15 | 
            +
              
         | 
| 16 | 
            +
              loop do
         | 
| 17 | 
            +
                str = Readline.readline(">> ", true)
         | 
| 18 | 
            +
                
         | 
| 19 | 
            +
                if str == "exit"
         | 
| 20 | 
            +
                  Process.kill 'INT', wait_thr.pid
         | 
| 21 | 
            +
                  wait_thr.value
         | 
| 22 | 
            +
                  exit
         | 
| 23 | 
            +
                else
         | 
| 24 | 
            +
                  stdin.puts str
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
                
         | 
| 27 | 
            +
                puts stdout.gets
         | 
| 28 | 
            +
                while stdout.ready? do
         | 
| 29 | 
            +
                  puts stdout.gets
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
                
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            else
         | 
| 34 | 
            +
              puts "`r2d console` is the only available command"
         | 
| 35 | 
            +
            end
         | 
    
        data/lib/console.rb
    ADDED
    
    | @@ -0,0 +1,55 @@ | |
| 1 | 
            +
            require 'io/wait'
         | 
| 2 | 
            +
            require 'r2d'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class String
         | 
| 5 | 
            +
              def error
         | 
| 6 | 
            +
                # red => \e[0;31
         | 
| 7 | 
            +
                # red/bold => \e[1;31m
         | 
| 8 | 
            +
                "\e[0;31m#{self}\e[0m"
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
              def task
         | 
| 11 | 
            +
                "\e[1;34m#{self}\e[0m"
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
              def success
         | 
| 14 | 
            +
                "\e[0;32m#{self}\e[0m"
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            window width: 640, height: 480
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            _activity = Square.new(630, 470, 10, 'white')
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            _c = 0
         | 
| 23 | 
            +
            _switch = true
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            update do
         | 
| 26 | 
            +
              
         | 
| 27 | 
            +
              if _switch
         | 
| 28 | 
            +
                _c += 2
         | 
| 29 | 
            +
                if _c > 255
         | 
| 30 | 
            +
                  _switch = false
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              else 
         | 
| 33 | 
            +
                _c -= 2
         | 
| 34 | 
            +
                if _c < 0
         | 
| 35 | 
            +
                  _switch = true
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
              
         | 
| 39 | 
            +
              _activity.color = [255, 255, 255, _c]
         | 
| 40 | 
            +
              
         | 
| 41 | 
            +
              if STDIN.ready?
         | 
| 42 | 
            +
                str = STDIN.gets
         | 
| 43 | 
            +
                begin
         | 
| 44 | 
            +
                  r = eval(str, TOPLEVEL_BINDING)
         | 
| 45 | 
            +
                  STDOUT.puts r.to_s
         | 
| 46 | 
            +
                  STDOUT.flush
         | 
| 47 | 
            +
                rescue Exception => e
         | 
| 48 | 
            +
                  STDOUT.puts e.to_s.error
         | 
| 49 | 
            +
                  STDOUT.flush
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
              
         | 
| 53 | 
            +
            end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            window :show
         | 
    
        data/lib/r2d.rb
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            # r2d.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'r2d/version'
         | 
| 4 | 
            +
            require 'r2d/adapters'
         | 
| 5 | 
            +
            require 'r2d/adapters/gosu'
         | 
| 6 | 
            +
            require 'r2d/window'
         | 
| 7 | 
            +
            require 'r2d/color'
         | 
| 8 | 
            +
            require 'r2d/quad'
         | 
| 9 | 
            +
            require 'r2d/rectangle'
         | 
| 10 | 
            +
            require 'r2d/square'
         | 
| 11 | 
            +
            require 'r2d/line'
         | 
| 12 | 
            +
            require 'r2d/triangle'
         | 
| 13 | 
            +
            require 'r2d/circle'
         | 
| 14 | 
            +
            require 'r2d/text'
         | 
| 15 | 
            +
            require 'r2d/image'
         | 
| 16 | 
            +
            require 'r2d/song'
         | 
| 17 | 
            +
            require 'r2d/sound'
         | 
| 18 | 
            +
            require 'r2d/exceptions'
         | 
| 19 | 
            +
            require 'r2d/helpers'
         | 
    
        data/lib/r2d/adapters.rb
    ADDED
    
    | @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            # adapters.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module R2D
         | 
| 4 | 
            +
              module Adapters
         | 
| 5 | 
            +
                
         | 
| 6 | 
            +
                @active = nil
         | 
| 7 | 
            +
                
         | 
| 8 | 
            +
                def self.create(window, kind)
         | 
| 9 | 
            +
                  if !@active
         | 
| 10 | 
            +
                    case kind
         | 
| 11 | 
            +
                    when :gosu
         | 
| 12 | 
            +
                      @active = Gosu
         | 
| 13 | 
            +
                      @active.create_window(window)
         | 
| 14 | 
            +
                    end
         | 
| 15 | 
            +
                    true
         | 
| 16 | 
            +
                  else
         | 
| 17 | 
            +
                    false
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
                
         | 
| 21 | 
            +
                def self.show
         | 
| 22 | 
            +
                  @active.show_window
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
                
         | 
| 25 | 
            +
                def self.key_lookup(key); Gosu.key_id(key) end
         | 
| 26 | 
            +
                
         | 
| 27 | 
            +
                def self.get_color(r, g, b, a); Gosu.get_color(r, g, b, a) end
         | 
| 28 | 
            +
                
         | 
| 29 | 
            +
                def self.mouse_x; Gosu.mouse_x end
         | 
| 30 | 
            +
                def self.mouse_y; Gosu.mouse_y end
         | 
| 31 | 
            +
                
         | 
| 32 | 
            +
                # Fix these:
         | 
| 33 | 
            +
                
         | 
| 34 | 
            +
                def self.song(path); @active.song(path) end
         | 
| 35 | 
            +
                
         | 
| 36 | 
            +
                def self.current_song; @active.current_song end
         | 
| 37 | 
            +
                
         | 
| 38 | 
            +
                def self.sound(path); @active.sound(path) end
         | 
| 39 | 
            +
                
         | 
| 40 | 
            +
                def self.image(path); @active.image(path) end
         | 
| 41 | 
            +
                
         | 
| 42 | 
            +
                def self.text(h=20, font='default'); @active.text(h, font) end
         | 
| 43 | 
            +
                
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| @@ -0,0 +1,158 @@ | |
| 1 | 
            +
            # gosu.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'gosu'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module R2D
         | 
| 6 | 
            +
              module Adapters
         | 
| 7 | 
            +
                module Gosu
         | 
| 8 | 
            +
                  
         | 
| 9 | 
            +
                  @gosu_window = nil
         | 
| 10 | 
            +
                  
         | 
| 11 | 
            +
                  def self.create_window(window)
         | 
| 12 | 
            +
                    @gosu_window = GosuWindow.new(window)
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
                  
         | 
| 15 | 
            +
                  def self.show_window
         | 
| 16 | 
            +
                    @gosu_window.show
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                  
         | 
| 19 | 
            +
                  def self.mouse_x; @gosu_window.mouse_x end
         | 
| 20 | 
            +
                  def self.mouse_y; @gosu_window.mouse_y end
         | 
| 21 | 
            +
                  
         | 
| 22 | 
            +
                  def self.get_color(r, g, b, a); ::Gosu::Color.argb(a, r, g, b) end
         | 
| 23 | 
            +
                  
         | 
| 24 | 
            +
                  def self.song(path); ::Gosu::Song.new(@gosu_window, path) end
         | 
| 25 | 
            +
                  
         | 
| 26 | 
            +
                  def self.current_song; ::Gosu::Song.current_song end
         | 
| 27 | 
            +
                  
         | 
| 28 | 
            +
                  def self.sound(path); ::Gosu::Sample.new(@gosu_window, path) end
         | 
| 29 | 
            +
                  
         | 
| 30 | 
            +
                  def self.image(path); ::Gosu::Image.new(@gosu_window, path, true) end
         | 
| 31 | 
            +
                  
         | 
| 32 | 
            +
                  def self.text(h, font)
         | 
| 33 | 
            +
                    if font == 'default' then font = ::Gosu::default_font_name end
         | 
| 34 | 
            +
                    ::Gosu::Font.new(@gosu_window, font, h)
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                  
         | 
| 37 | 
            +
                  def self.key_id(key)
         | 
| 38 | 
            +
                    case key
         | 
| 39 | 
            +
                    when 'up'
         | 
| 40 | 
            +
                      id = ::Gosu::KbUp
         | 
| 41 | 
            +
                    when 'down'
         | 
| 42 | 
            +
                      id = ::Gosu::KbDown
         | 
| 43 | 
            +
                    when 'left'
         | 
| 44 | 
            +
                      id = ::Gosu::KbLeft
         | 
| 45 | 
            +
                    when 'right'
         | 
| 46 | 
            +
                      id = ::Gosu::KbRight
         | 
| 47 | 
            +
                      
         | 
| 48 | 
            +
                    when 'left_alt'
         | 
| 49 | 
            +
                      id = ::Gosu::KbLeftAlt
         | 
| 50 | 
            +
                    when 'right_alt'
         | 
| 51 | 
            +
                      id = ::Gosu::KbRightAlt
         | 
| 52 | 
            +
                    when 'left_control'
         | 
| 53 | 
            +
                      id = ::Gosu::KbLeftControl
         | 
| 54 | 
            +
                    when 'right_control'
         | 
| 55 | 
            +
                      id = ::Gosu::KbRightControl
         | 
| 56 | 
            +
                    when 'left_shift'
         | 
| 57 | 
            +
                      id = ::Gosu::KbLeftShift
         | 
| 58 | 
            +
                    when 'right_shift'
         | 
| 59 | 
            +
                      id = ::Gosu::KbRightShift
         | 
| 60 | 
            +
                      
         | 
| 61 | 
            +
                    when 'backspace'
         | 
| 62 | 
            +
                      id = ::Gosu::KbBackspace
         | 
| 63 | 
            +
                    when 'delete'
         | 
| 64 | 
            +
                      id = ::Gosu::KbDelete
         | 
| 65 | 
            +
                    when 'space'
         | 
| 66 | 
            +
                      id = ::Gosu::KbSpace
         | 
| 67 | 
            +
                    when 'tab'
         | 
| 68 | 
            +
                      id = ::Gosu::KbTab
         | 
| 69 | 
            +
                    when 'return'
         | 
| 70 | 
            +
                      id = ::Gosu::KbReturn
         | 
| 71 | 
            +
                      
         | 
| 72 | 
            +
                    when 'mouse_left'
         | 
| 73 | 
            +
                      id = ::Gosu::MsLeft
         | 
| 74 | 
            +
                    when 'mouse_right'
         | 
| 75 | 
            +
                      id = ::Gosu::MsRight
         | 
| 76 | 
            +
                      
         | 
| 77 | 
            +
                    when ('a'..'z') || ('A'..'Z') || ('0'..'9')
         | 
| 78 | 
            +
                      id = @gosu_window.char_to_button_id(key)
         | 
| 79 | 
            +
                    else
         | 
| 80 | 
            +
                      raise Error, "The key '#{key}' is not valid!"
         | 
| 81 | 
            +
                    end
         | 
| 82 | 
            +
                  end
         | 
| 83 | 
            +
                  
         | 
| 84 | 
            +
                  class GosuWindow < ::Gosu::Window
         | 
| 85 | 
            +
                    
         | 
| 86 | 
            +
                    attr_accessor :window
         | 
| 87 | 
            +
                    
         | 
| 88 | 
            +
                    def initialize(window)
         | 
| 89 | 
            +
                      # super 800, 600, false
         | 
| 90 | 
            +
                      super window.w, window.h, window.fs
         | 
| 91 | 
            +
                      
         | 
| 92 | 
            +
                      self.caption = window.title
         | 
| 93 | 
            +
                      @cursor = window.cursor
         | 
| 94 | 
            +
                      @window = window
         | 
| 95 | 
            +
                    end
         | 
| 96 | 
            +
                    
         | 
| 97 | 
            +
                    # Gosu Methods
         | 
| 98 | 
            +
                    
         | 
| 99 | 
            +
                    def needs_cursor?; @cursor end
         | 
| 100 | 
            +
                    
         | 
| 101 | 
            +
                    def button_down(id)
         | 
| 102 | 
            +
                      if id == ::Gosu::KbEscape
         | 
| 103 | 
            +
                        close
         | 
| 104 | 
            +
                      elsif @window.on_keys.has_key? id
         | 
| 105 | 
            +
                        @window.on_keys[id].call
         | 
| 106 | 
            +
                      end
         | 
| 107 | 
            +
                    end
         | 
| 108 | 
            +
                    
         | 
| 109 | 
            +
                    def update
         | 
| 110 | 
            +
                      @window.update_proc.call
         | 
| 111 | 
            +
                      
         | 
| 112 | 
            +
                      @window.keys_down.each_key do |id|
         | 
| 113 | 
            +
                        if button_down? id
         | 
| 114 | 
            +
                          @window.keys_down[id].call
         | 
| 115 | 
            +
                        end
         | 
| 116 | 
            +
                      end
         | 
| 117 | 
            +
                    end
         | 
| 118 | 
            +
                    
         | 
| 119 | 
            +
                    def draw
         | 
| 120 | 
            +
                      @window.objects.each do |o|
         | 
| 121 | 
            +
                        case o
         | 
| 122 | 
            +
                        when Line
         | 
| 123 | 
            +
                          draw_quad(
         | 
| 124 | 
            +
                            o.qx1, o.qy1, o.c1.adapter,
         | 
| 125 | 
            +
                            o.qx2, o.qy2, o.c2.adapter,
         | 
| 126 | 
            +
                            o.qx3, o.qy3, o.c3.adapter,
         | 
| 127 | 
            +
                            o.qx4, o.qy4, o.c4.adapter
         | 
| 128 | 
            +
                          )
         | 
| 129 | 
            +
                        when Triangle
         | 
| 130 | 
            +
                          draw_triangle(
         | 
| 131 | 
            +
                            o.x1, o.y1, o.c1.adapter,
         | 
| 132 | 
            +
                            o.x2, o.y2, o.c2.adapter,
         | 
| 133 | 
            +
                            o.x3, o.y3, o.c3.adapter
         | 
| 134 | 
            +
                          )
         | 
| 135 | 
            +
                        when Quad
         | 
| 136 | 
            +
                          draw_quad(
         | 
| 137 | 
            +
                            o.x1, o.y1, o.c1.adapter,
         | 
| 138 | 
            +
                            o.x2, o.y2, o.c2.adapter,
         | 
| 139 | 
            +
                            o.x3, o.y3, o.c3.adapter,
         | 
| 140 | 
            +
                            o.x4, o.y4, o.c4.adapter
         | 
| 141 | 
            +
                          )
         | 
| 142 | 
            +
                        when Image
         | 
| 143 | 
            +
                          # .draw(x, y, z, factor_x=1, factor_y=1, color=0xffffffff, mode=:default)
         | 
| 144 | 
            +
                          o.adapter.draw(o.x, o.y, 0, o.f_x, o.f_y)
         | 
| 145 | 
            +
                        when Text
         | 
| 146 | 
            +
                          # .draw(text, x, y, z, factor_x=1, factor_y=1, color=0xffffffff, mode=:default)
         | 
| 147 | 
            +
                          o.adapter.draw(o.content, o.x, o.y, 0, 1, 1, o.c.adapter)
         | 
| 148 | 
            +
                        else
         | 
| 149 | 
            +
                          raise Error, "Cannot draw type '#{o.class}'"
         | 
| 150 | 
            +
                        end
         | 
| 151 | 
            +
                      end
         | 
| 152 | 
            +
                    end
         | 
| 153 | 
            +
                    
         | 
| 154 | 
            +
                  end
         | 
| 155 | 
            +
                  
         | 
| 156 | 
            +
                end
         | 
| 157 | 
            +
              end
         | 
| 158 | 
            +
            end
         | 
    
        data/lib/r2d/circle.rb
    ADDED
    
    | @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            # circle.rb
         | 
| 2 | 
            +
            # https://gist.github.com/661266
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class Circle
         | 
| 5 | 
            +
              attr_reader :columns, :rows
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              def initialize radius
         | 
| 8 | 
            +
                @columns = @rows = radius * 2
         | 
| 9 | 
            +
                lower_half = (0...radius).map do |y|
         | 
| 10 | 
            +
                  x = Math.sqrt(radius**2 - y**2).round
         | 
| 11 | 
            +
                  right_half = "#{"\xff" * x}#{"\x00" * (radius - x)}"
         | 
| 12 | 
            +
                  "#{right_half.reverse}#{right_half}"
         | 
| 13 | 
            +
                end.join
         | 
| 14 | 
            +
                @blob = lower_half.reverse + lower_half
         | 
| 15 | 
            +
                @blob.gsub!(/./) { |alpha| "\xff\xff\xff#{alpha}"}
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def to_blob
         | 
| 19 | 
            +
                @blob
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            # class TestWin < Gosu::Window
         | 
| 24 | 
            +
            #   def initialize
         | 
| 25 | 
            +
            #     super 400, 400, false
         | 
| 26 | 
            +
            #
         | 
| 27 | 
            +
            #     @img = Gosu::Image.new(self, Circle.new(200), false)
         | 
| 28 | 
            +
            #   end
         | 
| 29 | 
            +
            #
         | 
| 30 | 
            +
            #   def draw
         | 
| 31 | 
            +
            #     @img.draw 0, 0, 0
         | 
| 32 | 
            +
            #   end
         | 
| 33 | 
            +
            # end
         | 
| 34 | 
            +
            #
         | 
| 35 | 
            +
            # TestWin.new.show
         | 
    
        data/lib/r2d/color.rb
    ADDED
    
    | @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            # color.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module R2D
         | 
| 4 | 
            +
              class Color
         | 
| 5 | 
            +
                
         | 
| 6 | 
            +
                attr_reader :r, :g, :b, :a, :adapter
         | 
| 7 | 
            +
                
         | 
| 8 | 
            +
                def initialize(c)
         | 
| 9 | 
            +
                  case c
         | 
| 10 | 
            +
                  when "red"
         | 
| 11 | 
            +
                    @r, @g, @b, @a = 255, 0, 0, 255
         | 
| 12 | 
            +
                  when "green"
         | 
| 13 | 
            +
                    @r, @g, @b, @a = 0, 255, 0, 255
         | 
| 14 | 
            +
                  when "blue"
         | 
| 15 | 
            +
                    @r, @g, @b, @a = 0, 0, 255, 255
         | 
| 16 | 
            +
                  when "black"
         | 
| 17 | 
            +
                    @r, @g, @b, @a = 0, 0, 0, 255
         | 
| 18 | 
            +
                  when "white"
         | 
| 19 | 
            +
                    @r, @g, @b, @a = 255, 255, 255, 255
         | 
| 20 | 
            +
                  when "yellow"
         | 
| 21 | 
            +
                    @r, @g, @b, @a = 255, 255, 0, 255
         | 
| 22 | 
            +
                  when "orange"
         | 
| 23 | 
            +
                    @r, @g, @b, @a = 255, 150, 0, 255
         | 
| 24 | 
            +
                  when "purple"
         | 
| 25 | 
            +
                    @r, @g, @b, @a = 150, 30, 150, 255
         | 
| 26 | 
            +
                  when "random"
         | 
| 27 | 
            +
                    @r, @g, @b, @a = rand(0..255), rand(0..255), rand(0..255), 255
         | 
| 28 | 
            +
                  when Array
         | 
| 29 | 
            +
                    @r, @g = to_val(c[0]), to_val(c[1])
         | 
| 30 | 
            +
                    @b, @a = to_val(c[2]), to_val(c[3])
         | 
| 31 | 
            +
                  else
         | 
| 32 | 
            +
                    raise Error, "Color does not exist!"
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                  
         | 
| 35 | 
            +
                  @adapter = R2D::Adapters.get_color(r, g, b, a)
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
                
         | 
| 38 | 
            +
                private
         | 
| 39 | 
            +
                
         | 
| 40 | 
            +
                def to_val(n)
         | 
| 41 | 
            +
                  if n.class == Fixnum
         | 
| 42 | 
            +
                    return n
         | 
| 43 | 
            +
                  elsif n.class == Float
         | 
| 44 | 
            +
                    return (n * 255).to_i
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
            end
         | 
    
        data/lib/r2d/helpers.rb
    ADDED
    
    | @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            # helpers.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module R2D
         | 
| 4 | 
            +
              module Helpers
         | 
| 5 | 
            +
                
         | 
| 6 | 
            +
                def mouse_x
         | 
| 7 | 
            +
                  Adapters.mouse_x
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
                
         | 
| 10 | 
            +
                def mouse_y
         | 
| 11 | 
            +
                  Adapters.mouse_y
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
                
         | 
| 14 | 
            +
                def on_key(key, &block)
         | 
| 15 | 
            +
                  @current.on_key(key, block)
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
                
         | 
| 18 | 
            +
                def key_down?(key)
         | 
| 19 | 
            +
                  @current.key_down?(key)
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
                
         | 
| 22 | 
            +
                def key_down(key, &block)
         | 
| 23 | 
            +
                  @current.add_key_down(key, block)
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
                
         | 
| 26 | 
            +
                def update(&block)
         | 
| 27 | 
            +
                  @current.update(block)
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
                
         | 
| 30 | 
            +
                def window(opts={})
         | 
| 31 | 
            +
                  case opts
         | 
| 32 | 
            +
                  when :show
         | 
| 33 | 
            +
                    @current.show
         | 
| 34 | 
            +
                  when :clear
         | 
| 35 | 
            +
                    @current.clear
         | 
| 36 | 
            +
                  else
         | 
| 37 | 
            +
                    @current = Window.new(
         | 
| 38 | 
            +
                      w: opts[:width] || 640,
         | 
| 39 | 
            +
                      h: opts[:height] || 480,
         | 
| 40 | 
            +
                      bg: opts[:background],
         | 
| 41 | 
            +
                      fs: opts[:fullscreen] || false
         | 
| 42 | 
            +
                    )
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
            end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            include R2D::Helpers
         | 
    
        data/lib/r2d/image.rb
    ADDED
    
    | @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            # image.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Image
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              attr_accessor :x, :y
         | 
| 6 | 
            +
              attr_reader :width, :height, :f_x, :f_y
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              def initialize(x, y, path, visible=true)
         | 
| 9 | 
            +
                @x, @y, @path = x, y, path
         | 
| 10 | 
            +
                @f_x, @f_y = 1, 1
         | 
| 11 | 
            +
                @image = R2D::Adapters.image(path)
         | 
| 12 | 
            +
                @o_w, @o_h = @image.width, @image.height
         | 
| 13 | 
            +
                @width, @height = @o_w, @o_h
         | 
| 14 | 
            +
                if visible then add end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
              
         | 
| 17 | 
            +
              def width=(w)
         | 
| 18 | 
            +
                @f_x = w / @o_w.to_f
         | 
| 19 | 
            +
                @width = w
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
              
         | 
| 22 | 
            +
              def height=(h)
         | 
| 23 | 
            +
                @f_y = h / @o_h.to_f
         | 
| 24 | 
            +
                @height = h
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
              
         | 
| 27 | 
            +
              def add
         | 
| 28 | 
            +
                R2D::Window.add(self)
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
              
         | 
| 31 | 
            +
              def remove
         | 
| 32 | 
            +
                R2D::Window.remove(self)
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
              
         | 
| 35 | 
            +
              def adapter
         | 
| 36 | 
            +
                @image
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
              
         | 
| 39 | 
            +
            end
         | 
    
        data/lib/r2d/line.rb
    ADDED
    
    | @@ -0,0 +1,77 @@ | |
| 1 | 
            +
            # line.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Line
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              attr_reader :x1, :y1, :x2, :y2, :w, :color,
         | 
| 6 | 
            +
                          :qx1, :qy1, :qx2, :qy2, :qx3, :qy3, :qx4, :qy4,
         | 
| 7 | 
            +
                          :c1, :c2, :c3, :c4
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              def initialize(x1, y1, x2, y2, w, c="white", visible=true)
         | 
| 10 | 
            +
                @x1, @y1, @x2, @y2, @w, @color = x1, y1, x2, y2, w, c
         | 
| 11 | 
            +
                update_coords(x1, y1, x2, y2, w)
         | 
| 12 | 
            +
                update_color(c)
         | 
| 13 | 
            +
                if visible then add end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
              
         | 
| 16 | 
            +
              def x1=(x1)
         | 
| 17 | 
            +
                @x1 = x1
         | 
| 18 | 
            +
                update_coords(x1, @y1, @x2, @y2, @w)
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
              def y1=(y1)
         | 
| 22 | 
            +
                @y1 = y1
         | 
| 23 | 
            +
                update_coords(@x1, y1, @x2, @y2, @w)
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
              
         | 
| 26 | 
            +
              def x2=(x2)
         | 
| 27 | 
            +
                @x2 = x2
         | 
| 28 | 
            +
                update_coords(@x1, @y1, x2, @y2, @w)
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
              
         | 
| 31 | 
            +
              def y2=(y2)
         | 
| 32 | 
            +
                @y2 = y2
         | 
| 33 | 
            +
                update_coords(@x1, @y1, @x2, y2, @w)
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
              
         | 
| 36 | 
            +
              def w=(w)
         | 
| 37 | 
            +
                @w = w
         | 
| 38 | 
            +
                update_coords(@x1, @y1, @x2, @y2, w)
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
              
         | 
| 41 | 
            +
              def color=(c)
         | 
| 42 | 
            +
                @color = c
         | 
| 43 | 
            +
                update_color(c)
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
              
         | 
| 46 | 
            +
              def add
         | 
| 47 | 
            +
                R2D::Window.add(self)
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
              
         | 
| 50 | 
            +
              def remove
         | 
| 51 | 
            +
                R2D::Window.remove(self)
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
              
         | 
| 54 | 
            +
              def show; add end
         | 
| 55 | 
            +
              def hide; remove end
         | 
| 56 | 
            +
              
         | 
| 57 | 
            +
              private
         | 
| 58 | 
            +
              
         | 
| 59 | 
            +
              def update_coords(x1, y1, x2, y2, w)
         | 
| 60 | 
            +
                @qx1 = x1
         | 
| 61 | 
            +
                @qy1 = y1 - w/2
         | 
| 62 | 
            +
                @qx2 = x2
         | 
| 63 | 
            +
                @qy2 = y2 - w/2
         | 
| 64 | 
            +
                @qx3 = x1
         | 
| 65 | 
            +
                @qy3 = y1 + w/2
         | 
| 66 | 
            +
                @qx4 = x2
         | 
| 67 | 
            +
                @qy4 = y2 + w/2
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
              
         | 
| 70 | 
            +
              def update_color(c)
         | 
| 71 | 
            +
                @c1 = R2D::Color.new(c)
         | 
| 72 | 
            +
                @c2 = R2D::Color.new(c)
         | 
| 73 | 
            +
                @c3 = R2D::Color.new(c)
         | 
| 74 | 
            +
                @c4 = R2D::Color.new(c)
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
              
         | 
| 77 | 
            +
            end
         | 
    
        data/lib/r2d/quad.rb
    ADDED
    
    | @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            # quad.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Quad
         | 
| 4 | 
            +
              # x1,y1 == top left
         | 
| 5 | 
            +
              # x2,y2 == top right
         | 
| 6 | 
            +
              # x3,y3 == bottom left
         | 
| 7 | 
            +
              # x4,y4 == bottom right
         | 
| 8 | 
            +
              attr_reader :color,
         | 
| 9 | 
            +
                          :x1, :y1, :c1,
         | 
| 10 | 
            +
                          :x2, :y2, :c2,
         | 
| 11 | 
            +
                          :x3, :y3, :c3,
         | 
| 12 | 
            +
                          :x4, :y4, :c4
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              def initialize(x1, y1, x2, y2, x3, y3, x4, y4, c="white", visible=true)
         | 
| 15 | 
            +
                @x1, @y1, @x2, @y2, @x3, @y3, @x4, @y4 = x1, y1, x2, y2, x3, y3, x4, y4
         | 
| 16 | 
            +
                @color = c
         | 
| 17 | 
            +
                update_color(c)
         | 
| 18 | 
            +
                if visible then add end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
              def color=(c)
         | 
| 22 | 
            +
                @color = c
         | 
| 23 | 
            +
                update_color(c)
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
              
         | 
| 26 | 
            +
              def add
         | 
| 27 | 
            +
                R2D::Window.add(self)
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
              
         | 
| 30 | 
            +
              def remove
         | 
| 31 | 
            +
                R2D::Window.remove(self)
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
              
         | 
| 34 | 
            +
              private
         | 
| 35 | 
            +
              
         | 
| 36 | 
            +
              def update_color(c)
         | 
| 37 | 
            +
                @c1 = R2D::Color.new(c)
         | 
| 38 | 
            +
                @c2 = R2D::Color.new(c)
         | 
| 39 | 
            +
                @c3 = R2D::Color.new(c)
         | 
| 40 | 
            +
                @c4 = R2D::Color.new(c)
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
            end
         | 
| @@ -0,0 +1,95 @@ | |
| 1 | 
            +
            # rectangle.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Rectangle < Quad
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              attr_reader :x, :y, :width, :height
         | 
| 6 | 
            +
              
         | 
| 7 | 
            +
              def initialize(x, y, w, h, c="white", visible=true)
         | 
| 8 | 
            +
                @x, @y, @width, @height, @color = x, y, w, h, c
         | 
| 9 | 
            +
                update_coords(x, y, w, h)
         | 
| 10 | 
            +
                update_color(c)
         | 
| 11 | 
            +
                if visible then add end
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              def x=(x)
         | 
| 15 | 
            +
                @x = @x1 = x
         | 
| 16 | 
            +
                @x2 = x + @width
         | 
| 17 | 
            +
                @x3 = x
         | 
| 18 | 
            +
                @x4 = x + @width
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
              def y=(y)
         | 
| 22 | 
            +
                @y = @y1 = y
         | 
| 23 | 
            +
                @y2 = y
         | 
| 24 | 
            +
                @y3 = y + @height
         | 
| 25 | 
            +
                @y4 = y + @height
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
              
         | 
| 28 | 
            +
              def width=(w)
         | 
| 29 | 
            +
                @width = w
         | 
| 30 | 
            +
                update_coords(@x, @y, w, @height)
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
              
         | 
| 33 | 
            +
              def height=(h)
         | 
| 34 | 
            +
                @height = h
         | 
| 35 | 
            +
                update_coords(@x, @y, @width, h)
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
              
         | 
| 38 | 
            +
              def gradient=(g)
         | 
| 39 | 
            +
                if g[:top]
         | 
| 40 | 
            +
                  # r, g, b, a = R2D::Color.rgba(g[:top])
         | 
| 41 | 
            +
                  # @c1 = @c2 = R2D::Window.get_color(r, g, b, a)
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
                
         | 
| 44 | 
            +
                p g.class
         | 
| 45 | 
            +
                
         | 
| 46 | 
            +
                # if g[:bottom]
         | 
| 47 | 
            +
                #   r, g, b, a = R2D::Color.rgba(g[:bottom])
         | 
| 48 | 
            +
                #   @c3 = @c4 = R2D::Window.get_color(r, g, b, a)
         | 
| 49 | 
            +
                # end
         | 
| 50 | 
            +
                
         | 
| 51 | 
            +
                # if g[:left]
         | 
| 52 | 
            +
                #   r, g, b, a = R2D::Color.rgba(g[:left])
         | 
| 53 | 
            +
                #   @c1 = @c3 = R2D::Window.get_color(r, g, b, a)
         | 
| 54 | 
            +
                # end
         | 
| 55 | 
            +
                
         | 
| 56 | 
            +
                # if g[:right]
         | 
| 57 | 
            +
                #   r, g, b, a = R2D::Color.rgba(g[:right])
         | 
| 58 | 
            +
                #   @c2 = @c4 = R2D::Window.get_color(r, g, b, a)
         | 
| 59 | 
            +
                # end
         | 
| 60 | 
            +
                
         | 
| 61 | 
            +
                # if g[:top_left]
         | 
| 62 | 
            +
                #   r, g, b, a = R2D::Color.rgba(g[:top_left])
         | 
| 63 | 
            +
                #   @c1 = R2D::Window.get_color(r, g, b, a)
         | 
| 64 | 
            +
                # end
         | 
| 65 | 
            +
                
         | 
| 66 | 
            +
                # if g[:top_right]
         | 
| 67 | 
            +
                #   r, g, b, a = R2D::Color.rgba(g[:top_right])
         | 
| 68 | 
            +
                #   @c2 = R2D::Window.get_color(r, g, b, a)
         | 
| 69 | 
            +
                # end
         | 
| 70 | 
            +
                
         | 
| 71 | 
            +
                # if g[:bottom_left]
         | 
| 72 | 
            +
                #   r, g, b, a = R2D::Color.rgba(g[:bottom_left])
         | 
| 73 | 
            +
                #   @c3 = R2D::Window.get_color(r, g, b, a)
         | 
| 74 | 
            +
                # end
         | 
| 75 | 
            +
                
         | 
| 76 | 
            +
                # if g[:bottom_right]
         | 
| 77 | 
            +
                #   r, g, b, a = R2D::Color.rgba(g[:bottom_right])
         | 
| 78 | 
            +
                #   @c4 = R2D::Window.get_color(r, g, b, a)
         | 
| 79 | 
            +
                # end
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
              
         | 
| 82 | 
            +
              private
         | 
| 83 | 
            +
              
         | 
| 84 | 
            +
              def update_coords(x, y, w, h)
         | 
| 85 | 
            +
                @x1 = x
         | 
| 86 | 
            +
                @y1 = y
         | 
| 87 | 
            +
                @x2 = x + w
         | 
| 88 | 
            +
                @y2 = y
         | 
| 89 | 
            +
                @x3 = x
         | 
| 90 | 
            +
                @y3 = y + h
         | 
| 91 | 
            +
                @x4 = x + w
         | 
| 92 | 
            +
                @y4 = y + h
         | 
| 93 | 
            +
              end
         | 
| 94 | 
            +
              
         | 
| 95 | 
            +
            end
         | 
    
        data/lib/r2d/song.rb
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            # song.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Song
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              def initialize(path)
         | 
| 6 | 
            +
                @song = R2D::Adapters.song(path)
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              def play
         | 
| 10 | 
            +
                @song.play
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
              
         | 
| 13 | 
            +
              def loop
         | 
| 14 | 
            +
                @song.play(true)
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
              
         | 
| 17 | 
            +
              def pause
         | 
| 18 | 
            +
                @song.pause
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
              def playing?
         | 
| 22 | 
            +
                @song.playing?
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
              
         | 
| 25 | 
            +
              def paused?
         | 
| 26 | 
            +
                @song.paused?
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
              
         | 
| 29 | 
            +
              def stop
         | 
| 30 | 
            +
                @song.stop
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
              
         | 
| 33 | 
            +
              def volume
         | 
| 34 | 
            +
                @song.volume
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
              
         | 
| 37 | 
            +
            end
         | 
    
        data/lib/r2d/sound.rb
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            # sound.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Sound
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              def initialize(path)
         | 
| 6 | 
            +
                @sound = R2D::Adapters.sound(path)
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              def play
         | 
| 10 | 
            +
                @sound.play
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
              
         | 
| 13 | 
            +
              def play_loop
         | 
| 14 | 
            +
                @sound.play(true)
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
              
         | 
| 17 | 
            +
              def pause
         | 
| 18 | 
            +
                @sound.pause
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
              def playing?
         | 
| 22 | 
            +
                @sound.playing?
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
              
         | 
| 25 | 
            +
              def paused?
         | 
| 26 | 
            +
                @sound.paused?
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
              
         | 
| 29 | 
            +
              def stop
         | 
| 30 | 
            +
                @sound.stop
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
              
         | 
| 33 | 
            +
              def volume
         | 
| 34 | 
            +
                @sound.volume
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
              
         | 
| 37 | 
            +
            end
         | 
    
        data/lib/r2d/square.rb
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            # square.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Square < Rectangle
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              attr_reader :size
         | 
| 6 | 
            +
              
         | 
| 7 | 
            +
              def initialize(x=0, y=0, s=100, c="white", visible=true)
         | 
| 8 | 
            +
                @x, @y, @color = x, y, c
         | 
| 9 | 
            +
                @width = @height = @size = s
         | 
| 10 | 
            +
                update_coords(x, y, s, s)
         | 
| 11 | 
            +
                update_color(c)
         | 
| 12 | 
            +
                if visible then add end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
              
         | 
| 15 | 
            +
              def size=(s)
         | 
| 16 | 
            +
                self.width = self.height = @size = s
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
              
         | 
| 19 | 
            +
              private :width=, :height=
         | 
| 20 | 
            +
            end
         | 
    
        data/lib/r2d/text.rb
    ADDED
    
    | @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            # text.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Text
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              attr_accessor :x, :y
         | 
| 6 | 
            +
              attr_reader :h, :content, :color, :c
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              def initialize(x=0, y=0, h=50, content="Hello World!", c="white", visible=true)
         | 
| 9 | 
            +
                @x, @y, @h, @content, @color = x, y, h, content, c
         | 
| 10 | 
            +
                update_color(c)
         | 
| 11 | 
            +
                @text = R2D::Adapters.text(h)
         | 
| 12 | 
            +
                if visible then add end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
              
         | 
| 15 | 
            +
              def color=(c)
         | 
| 16 | 
            +
                @color = c
         | 
| 17 | 
            +
                update_color(c)
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
              
         | 
| 20 | 
            +
              def content=(c)
         | 
| 21 | 
            +
                @content = c
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
              
         | 
| 24 | 
            +
              def add
         | 
| 25 | 
            +
                R2D::Window.add(self)
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
              
         | 
| 28 | 
            +
              def remove
         | 
| 29 | 
            +
                R2D::Window.remove(self)
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
              
         | 
| 32 | 
            +
              def adapter
         | 
| 33 | 
            +
                @text
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
              
         | 
| 36 | 
            +
              private
         | 
| 37 | 
            +
              
         | 
| 38 | 
            +
              def update_color(c)
         | 
| 39 | 
            +
                @c = R2D::Color.new(c)
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
              
         | 
| 42 | 
            +
            end
         | 
    
        data/lib/r2d/triangle.rb
    ADDED
    
    | @@ -0,0 +1,41 @@ | |
| 1 | 
            +
            # triangle.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Triangle
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              attr_accessor :x1, :y1, :c1,
         | 
| 6 | 
            +
                            :x2, :y2, :c2,
         | 
| 7 | 
            +
                            :x3, :y3, :c3
         | 
| 8 | 
            +
              attr_reader :color
         | 
| 9 | 
            +
              
         | 
| 10 | 
            +
              def initialize(x1, y1, x2, y2, x3, y3, c="white", visible=true)
         | 
| 11 | 
            +
                @x1, @y1 = x1, y1
         | 
| 12 | 
            +
                @x2, @y2 = x2, y2
         | 
| 13 | 
            +
                @x3, @y3 = x3, y3
         | 
| 14 | 
            +
                @color = c
         | 
| 15 | 
            +
                update_color(c)
         | 
| 16 | 
            +
                if visible then add end
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
              
         | 
| 19 | 
            +
              def color=(c)
         | 
| 20 | 
            +
                update_color(c)
         | 
| 21 | 
            +
                @color = c
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
              
         | 
| 24 | 
            +
              def add
         | 
| 25 | 
            +
                R2D::Window.add(self)
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
              
         | 
| 28 | 
            +
              def remove
         | 
| 29 | 
            +
                R2D::Window.remove(self)
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
              
         | 
| 32 | 
            +
              private
         | 
| 33 | 
            +
              
         | 
| 34 | 
            +
              def update_color(c)
         | 
| 35 | 
            +
                @c1 = R2D::Color.new(c)
         | 
| 36 | 
            +
                @c2 = R2D::Color.new(c)
         | 
| 37 | 
            +
                @c3 = R2D::Color.new(c)
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
              
         | 
| 40 | 
            +
            end
         | 
| 41 | 
            +
             | 
    
        data/lib/r2d/version.rb
    ADDED
    
    
    
        data/lib/r2d/window.rb
    ADDED
    
    | @@ -0,0 +1,92 @@ | |
| 1 | 
            +
            # window.rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module R2D
         | 
| 4 | 
            +
              class Window
         | 
| 5 | 
            +
                
         | 
| 6 | 
            +
                attr_accessor :w, :h, :title, :bg, :cursor, :fs
         | 
| 7 | 
            +
                attr_reader :objects, :on_keys, :keys_down, :update_proc
         | 
| 8 | 
            +
                
         | 
| 9 | 
            +
                def initialize(options = {})
         | 
| 10 | 
            +
                  options = options.merge({w: 640, h: 480, title: "R2D", bg: nil, cursor: true, fs: false})
         | 
| 11 | 
            +
                  @w, @h, @title, @bg, @cursor, @fs, =
         | 
| 12 | 
            +
                    options[:w], options[:h], options[:title], options[:bg], options[:cursor], options[:fs]
         | 
| 13 | 
            +
                  
         | 
| 14 | 
            +
                  @objects = []
         | 
| 15 | 
            +
                  @on_keys = {}
         | 
| 16 | 
            +
                  @keys_down = {}
         | 
| 17 | 
            +
                  @update_proc = Proc.new {}
         | 
| 18 | 
            +
                  
         | 
| 19 | 
            +
                  Adapters.create(self, :gosu)
         | 
| 20 | 
            +
                  
         | 
| 21 | 
            +
                  @@current = self
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
                
         | 
| 24 | 
            +
                def self.add(o)
         | 
| 25 | 
            +
                  @@current.add(o)
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
                
         | 
| 28 | 
            +
                def self.remove(o)
         | 
| 29 | 
            +
                  @@current.remove(o)
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
                
         | 
| 32 | 
            +
                def add(o)
         | 
| 33 | 
            +
                  if !@objects.include?(o)
         | 
| 34 | 
            +
                    @objects.push(o)
         | 
| 35 | 
            +
                    true
         | 
| 36 | 
            +
                  else
         | 
| 37 | 
            +
                    false
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
                
         | 
| 41 | 
            +
                def remove(o)
         | 
| 42 | 
            +
                  if i = @objects.index(o)
         | 
| 43 | 
            +
                    @objects.slice!(i)
         | 
| 44 | 
            +
                    true
         | 
| 45 | 
            +
                  else
         | 
| 46 | 
            +
                    false
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
                
         | 
| 50 | 
            +
                def clear
         | 
| 51 | 
            +
                  @objects.clear
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
                
         | 
| 54 | 
            +
                def add_on_key(key, proc)
         | 
| 55 | 
            +
                  @on_keys[Adapters.key_lookup(key)] = proc
         | 
| 56 | 
            +
                  true
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
                
         | 
| 59 | 
            +
                def key_down?(key)
         | 
| 60 | 
            +
                  button_down?(Adapters.key_lookup(key))
         | 
| 61 | 
            +
                  true
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
                
         | 
| 64 | 
            +
                def add_key_down(key, proc)
         | 
| 65 | 
            +
                  @keys_down[Adapters.key_lookup(key)] = proc
         | 
| 66 | 
            +
                  true
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
                
         | 
| 69 | 
            +
                def update(block)
         | 
| 70 | 
            +
                  @update_proc = block
         | 
| 71 | 
            +
                  true
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
                
         | 
| 74 | 
            +
                def on_key(key, block)
         | 
| 75 | 
            +
                  add_on_key(key, block)
         | 
| 76 | 
            +
                  true
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
                
         | 
| 79 | 
            +
                def mouse_x
         | 
| 80 | 
            +
                  Adapters.mouse_x
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
                
         | 
| 83 | 
            +
                def mouse_y
         | 
| 84 | 
            +
                  Adapters.mouse_y
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
                
         | 
| 87 | 
            +
                def show
         | 
| 88 | 
            +
                  Adapters.show
         | 
| 89 | 
            +
                end
         | 
| 90 | 
            +
                
         | 
| 91 | 
            +
              end
         | 
| 92 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,82 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: r2d-takaokouji
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.0.0
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
            platform: ruby
         | 
| 7 | 
            +
            authors:
         | 
| 8 | 
            +
            - Kouji Takao
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2013-07-25 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: gosu
         | 
| 16 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - ~>
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: 0.7.47.1
         | 
| 22 | 
            +
              type: :runtime
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - ~>
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: 0.7.47.1
         | 
| 30 | 
            +
            description: ! 'R2D original: https://github.com/blacktm/r2d. This is temporary gem.'
         | 
| 31 | 
            +
            email: kouji.takao@gmail.com
         | 
| 32 | 
            +
            executables:
         | 
| 33 | 
            +
            - r2d
         | 
| 34 | 
            +
            extensions: []
         | 
| 35 | 
            +
            extra_rdoc_files: []
         | 
| 36 | 
            +
            files:
         | 
| 37 | 
            +
            - lib/console.rb
         | 
| 38 | 
            +
            - lib/r2d/adapters/gosu.rb
         | 
| 39 | 
            +
            - lib/r2d/adapters.rb
         | 
| 40 | 
            +
            - lib/r2d/circle.rb
         | 
| 41 | 
            +
            - lib/r2d/color.rb
         | 
| 42 | 
            +
            - lib/r2d/exceptions.rb
         | 
| 43 | 
            +
            - lib/r2d/helpers.rb
         | 
| 44 | 
            +
            - lib/r2d/image.rb
         | 
| 45 | 
            +
            - lib/r2d/line.rb
         | 
| 46 | 
            +
            - lib/r2d/quad.rb
         | 
| 47 | 
            +
            - lib/r2d/rectangle.rb
         | 
| 48 | 
            +
            - lib/r2d/song.rb
         | 
| 49 | 
            +
            - lib/r2d/sound.rb
         | 
| 50 | 
            +
            - lib/r2d/square.rb
         | 
| 51 | 
            +
            - lib/r2d/text.rb
         | 
| 52 | 
            +
            - lib/r2d/triangle.rb
         | 
| 53 | 
            +
            - lib/r2d/version.rb
         | 
| 54 | 
            +
            - lib/r2d/window.rb
         | 
| 55 | 
            +
            - lib/r2d.rb
         | 
| 56 | 
            +
            - bin/r2d
         | 
| 57 | 
            +
            homepage: https://github.com/takaokouji/r2d
         | 
| 58 | 
            +
            licenses:
         | 
| 59 | 
            +
            - MIT
         | 
| 60 | 
            +
            post_install_message: 
         | 
| 61 | 
            +
            rdoc_options: []
         | 
| 62 | 
            +
            require_paths:
         | 
| 63 | 
            +
            - lib
         | 
| 64 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
              none: false
         | 
| 66 | 
            +
              requirements:
         | 
| 67 | 
            +
              - - ! '>='
         | 
| 68 | 
            +
                - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                  version: 1.9.3
         | 
| 70 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 71 | 
            +
              none: false
         | 
| 72 | 
            +
              requirements:
         | 
| 73 | 
            +
              - - ! '>='
         | 
| 74 | 
            +
                - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                  version: '0'
         | 
| 76 | 
            +
            requirements: []
         | 
| 77 | 
            +
            rubyforge_project: 
         | 
| 78 | 
            +
            rubygems_version: 1.8.24
         | 
| 79 | 
            +
            signing_key: 
         | 
| 80 | 
            +
            specification_version: 3
         | 
| 81 | 
            +
            summary: R2D by Kouji Takao
         | 
| 82 | 
            +
            test_files: []
         |