ruby2d 0.9.2 → 0.10.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.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/assets/README.md +7 -8
  3. data/assets/Rakefile +85 -0
  4. data/assets/include/SDL2/SDL.h +4 -1
  5. data/assets/include/SDL2/SDL_assert.h +3 -1
  6. data/assets/include/SDL2/SDL_atomic.h +20 -2
  7. data/assets/include/SDL2/SDL_audio.h +47 -14
  8. data/assets/include/SDL2/SDL_bits.h +10 -1
  9. data/assets/include/SDL2/SDL_blendmode.h +10 -7
  10. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  11. data/assets/include/SDL2/SDL_config.h +24 -390
  12. data/assets/include/SDL2/SDL_config_android.h +182 -0
  13. data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
  14. data/assets/include/SDL2/SDL_config_macosx.h +266 -0
  15. data/assets/include/SDL2/SDL_config_minimal.h +85 -0
  16. data/assets/include/SDL2/SDL_config_os2.h +188 -0
  17. data/assets/include/SDL2/SDL_config_pandora.h +135 -0
  18. data/assets/include/SDL2/SDL_config_psp.h +165 -0
  19. data/assets/include/SDL2/SDL_config_windows.h +288 -0
  20. data/assets/include/SDL2/SDL_config_winrt.h +243 -0
  21. data/assets/include/SDL2/SDL_config_wiz.h +149 -0
  22. data/assets/include/SDL2/SDL_copying.h +20 -0
  23. data/assets/include/SDL2/SDL_cpuinfo.h +119 -8
  24. data/assets/include/SDL2/SDL_egl.h +4 -1
  25. data/assets/include/SDL2/SDL_endian.h +6 -3
  26. data/assets/include/SDL2/SDL_error.h +38 -2
  27. data/assets/include/SDL2/SDL_events.h +67 -28
  28. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  29. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  30. data/assets/include/SDL2/SDL_gesture.h +1 -1
  31. data/assets/include/SDL2/SDL_haptic.h +10 -1
  32. data/assets/include/SDL2/SDL_hints.h +460 -17
  33. data/assets/include/SDL2/SDL_image.h +2 -2
  34. data/assets/include/SDL2/SDL_joystick.h +115 -24
  35. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  36. data/assets/include/SDL2/SDL_keycode.h +11 -9
  37. data/assets/include/SDL2/SDL_loadso.h +1 -1
  38. data/assets/include/SDL2/SDL_locale.h +101 -0
  39. data/assets/include/SDL2/SDL_log.h +3 -3
  40. data/assets/include/SDL2/SDL_main.h +28 -16
  41. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  42. data/assets/include/SDL2/SDL_metal.h +117 -0
  43. data/assets/include/SDL2/SDL_misc.h +75 -0
  44. data/assets/include/SDL2/SDL_mouse.h +1 -1
  45. data/assets/include/SDL2/SDL_mutex.h +1 -1
  46. data/assets/include/SDL2/SDL_name.h +1 -1
  47. data/assets/include/SDL2/SDL_opengl.h +1 -1
  48. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  49. data/assets/include/SDL2/SDL_opengles.h +1 -1
  50. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  51. data/assets/include/SDL2/SDL_pixels.h +27 -18
  52. data/assets/include/SDL2/SDL_platform.h +1 -1
  53. data/assets/include/SDL2/SDL_power.h +1 -1
  54. data/assets/include/SDL2/SDL_quit.h +1 -1
  55. data/assets/include/SDL2/SDL_rect.h +29 -3
  56. data/assets/include/SDL2/SDL_render.h +230 -3
  57. data/assets/include/SDL2/SDL_revision.h +2 -2
  58. data/assets/include/SDL2/SDL_rwops.h +51 -22
  59. data/assets/include/SDL2/SDL_scancode.h +2 -2
  60. data/assets/include/SDL2/SDL_sensor.h +28 -12
  61. data/assets/include/SDL2/SDL_shape.h +1 -1
  62. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  63. data/assets/include/SDL2/SDL_surface.h +12 -2
  64. data/assets/include/SDL2/SDL_system.h +50 -4
  65. data/assets/include/SDL2/SDL_syswm.h +39 -9
  66. data/assets/include/SDL2/SDL_test.h +1 -1
  67. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  68. data/assets/include/SDL2/SDL_test_common.h +32 -2
  69. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  70. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  71. data/assets/include/SDL2/SDL_test_font.h +1 -1
  72. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  73. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  74. data/assets/include/SDL2/SDL_test_images.h +1 -1
  75. data/assets/include/SDL2/SDL_test_log.h +1 -1
  76. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  77. data/assets/include/SDL2/SDL_test_memory.h +3 -3
  78. data/assets/include/SDL2/SDL_test_random.h +1 -1
  79. data/assets/include/SDL2/SDL_thread.h +34 -11
  80. data/assets/include/SDL2/SDL_timer.h +1 -1
  81. data/assets/include/SDL2/SDL_touch.h +17 -1
  82. data/assets/include/SDL2/SDL_types.h +1 -1
  83. data/assets/include/SDL2/SDL_version.h +2 -2
  84. data/assets/include/SDL2/SDL_video.h +11 -5
  85. data/assets/include/SDL2/SDL_vulkan.h +9 -11
  86. data/assets/include/SDL2/begin_code.h +8 -9
  87. data/assets/include/SDL2/close_code.h +4 -1
  88. data/assets/macos/lib/libFLAC.a +0 -0
  89. data/assets/macos/lib/libSDL2.a +0 -0
  90. data/assets/macos/lib/libSDL2_image.a +0 -0
  91. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  92. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  93. data/assets/macos/lib/libfreetype.a +0 -0
  94. data/assets/macos/lib/libjpeg.a +0 -0
  95. data/assets/macos/lib/libmpg123.a +0 -0
  96. data/assets/macos/lib/libogg.a +0 -0
  97. data/assets/macos/lib/libpng16.a +0 -0
  98. data/assets/macos/lib/libtiff.a +0 -0
  99. data/assets/macos/lib/libvorbis.a +0 -0
  100. data/assets/macos/lib/libvorbisfile.a +0 -0
  101. data/assets/macos/lib/libwebp.a +0 -0
  102. data/assets/mingw/bin/SDL2.dll +0 -0
  103. data/assets/mingw/bin/SDL2_image.dll +0 -0
  104. data/assets/mingw/bin/libpng16-16.dll +0 -0
  105. data/assets/mingw/bin/libtiff-5.dll +0 -0
  106. data/assets/mingw/bin/libwebp-7.dll +0 -0
  107. data/assets/mingw/lib/libSDL2.a +0 -0
  108. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  109. data/assets/mingw/lib/libSDL2_image.a +0 -0
  110. data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
  111. data/assets/mingw/lib/libSDL2_test.a +0 -0
  112. data/assets/mingw/lib/libSDL2main.a +0 -0
  113. data/bin/ruby2d +2 -1
  114. data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
  115. data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
  116. data/ext/ruby2d/extconf.rb +6 -36
  117. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +106 -85
  118. data/{assets/linux/simple2d/src → ext/ruby2d}/gl2.c +35 -20
  119. data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +146 -58
  120. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +41 -26
  121. data/{assets/linux/simple2d/src → ext/ruby2d}/image.c +16 -16
  122. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  123. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  124. data/ext/ruby2d/ruby2d.c +427 -290
  125. data/ext/ruby2d/ruby2d.h +789 -0
  126. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  127. data/ext/ruby2d/sound.c +118 -0
  128. data/{assets/linux/simple2d/src → ext/ruby2d}/sprite.c +16 -16
  129. data/{assets/linux/simple2d/src → ext/ruby2d}/text.c +22 -22
  130. data/ext/ruby2d/tileset.c +30 -0
  131. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +71 -60
  132. data/lib/ruby2d.rb +5 -2
  133. data/lib/ruby2d/circle.rb +18 -2
  134. data/lib/ruby2d/cli/build.rb +3 -8
  135. data/lib/ruby2d/cli/colorize.rb +10 -0
  136. data/lib/ruby2d/dsl.rb +16 -9
  137. data/lib/ruby2d/entity.rb +17 -0
  138. data/lib/ruby2d/font.rb +4 -3
  139. data/lib/ruby2d/image.rb +24 -1
  140. data/lib/ruby2d/line.rb +20 -0
  141. data/lib/ruby2d/music.rb +5 -0
  142. data/lib/ruby2d/pixel.rb +17 -0
  143. data/lib/ruby2d/quad.rb +18 -0
  144. data/lib/ruby2d/rectangle.rb +11 -2
  145. data/lib/ruby2d/renderable.rb +4 -8
  146. data/lib/ruby2d/sound.rb +5 -0
  147. data/lib/ruby2d/sprite.rb +35 -3
  148. data/lib/ruby2d/square.rb +9 -0
  149. data/lib/ruby2d/text.rb +22 -1
  150. data/lib/ruby2d/tileset.rb +69 -0
  151. data/lib/ruby2d/triangle.rb +16 -0
  152. data/lib/ruby2d/version.rb +1 -1
  153. data/lib/ruby2d/window.rb +249 -22
  154. metadata +41 -27
  155. data/assets/include/simple2d.h +0 -735
  156. data/assets/linux/simple2d/Makefile +0 -250
  157. data/assets/linux/simple2d/bin/simple2d.sh +0 -1249
  158. data/assets/linux/simple2d/include/simple2d.h +0 -735
  159. data/assets/linux/simple2d/src/sound.c +0 -56
  160. data/assets/macos/lib/libsimple2d.a +0 -0
  161. data/assets/mingw/lib/libsimple2d.a +0 -0
  162. data/lib/ruby2d/colorize.rb +0 -10
@@ -0,0 +1,10 @@
1
+ # String#ruby2d_colorize
2
+
3
+ # Extend `String` to include some fancy colors
4
+ class String
5
+ def ruby2d_colorize(c); "\e[#{c}m#{self}\e[0m" end
6
+ def bold; ruby2d_colorize('1') end
7
+ def info; ruby2d_colorize('1;34') end
8
+ def warn; ruby2d_colorize('1;33') end
9
+ def error; ruby2d_colorize('1;31') end
10
+ end
data/lib/ruby2d/dsl.rb CHANGED
@@ -2,38 +2,45 @@
2
2
 
3
3
  module Ruby2D::DSL
4
4
 
5
- Ruby2D::Window.new
5
+ @window = Ruby2D::Window.new
6
+
7
+ def self.window; @window end
8
+ def self.window=(w); @window = w end
6
9
 
7
10
  def get(sym, opts = nil)
8
- Window.get(sym, opts)
11
+ DSL.window.get(sym, opts)
9
12
  end
10
13
 
11
14
  def set(opts)
12
- Window.set(opts)
15
+ DSL.window.set(opts)
13
16
  end
14
17
 
15
18
  def on(event, &proc)
16
- Window.on(event, &proc)
19
+ DSL.window.on(event, &proc)
17
20
  end
18
21
 
19
22
  def off(event_descriptor)
20
- Window.off(event_descriptor)
23
+ DSL.window.off(event_descriptor)
21
24
  end
22
25
 
23
26
  def update(&proc)
24
- Window.update(&proc)
27
+ DSL.window.update(&proc)
28
+ end
29
+
30
+ def render(&proc)
31
+ DSL.window.render(&proc)
25
32
  end
26
33
 
27
34
  def clear
28
- Window.clear
35
+ DSL.window.clear
29
36
  end
30
37
 
31
38
  def show
32
- Window.show
39
+ DSL.window.show
33
40
  end
34
41
 
35
42
  def close
36
- Window.close
43
+ DSL.window.close
37
44
  end
38
45
 
39
46
  end
@@ -0,0 +1,17 @@
1
+ # Ruby2D::Entity
2
+
3
+ module Ruby2D
4
+ class Entity
5
+
6
+ # Add the entity to the window
7
+ def add
8
+ Window.add(self)
9
+ end
10
+
11
+ # Remove the entity from the window
12
+ def remove
13
+ Window.remove(self)
14
+ end
15
+
16
+ end
17
+ end
data/lib/ruby2d/font.rb CHANGED
@@ -63,11 +63,12 @@ module Ruby2D
63
63
  end
64
64
  # If MRuby
65
65
  else
66
- if `uname`.include? 'Darwin' # macOS
66
+ uname = `uname`
67
+ if uname.include? 'Darwin' # macOS
67
68
  macos_font_path
68
- elsif `uname`.include? 'Linux'
69
+ elsif uname.include? 'Linux'
69
70
  linux_font_path
70
- elsif `uname`.include? 'MINGW'
71
+ elsif uname.include? 'MINGW'
71
72
  windows_font_path
72
73
  end
73
74
  end
data/lib/ruby2d/image.rb CHANGED
@@ -23,7 +23,30 @@ module Ruby2D
23
23
  unless ext_init(@path)
24
24
  raise Error, "Image `#{@path}` cannot be created"
25
25
  end
26
- add
26
+ unless opts[:show] == false then add end
27
+ end
28
+
29
+ def draw(opts = {})
30
+ opts[:width] = opts[:width] || @width
31
+ opts[:height] = opts[:height] || @height
32
+ opts[:rotate] = opts[:rotate] || @rotate
33
+ unless opts[:color]
34
+ opts[:color] = [1.0, 1.0, 1.0, 1.0]
35
+ end
36
+
37
+ self.class.ext_draw([
38
+ self, opts[:x], opts[:y], opts[:width], opts[:height], opts[:rotate],
39
+ opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
40
+ ])
41
+ end
42
+
43
+ private
44
+
45
+ def render
46
+ self.class.ext_draw([
47
+ self, @x, @y, @width, @height, @rotate,
48
+ @color.r, @color.g, @color.b, @color.a
49
+ ])
27
50
  end
28
51
 
29
52
  end
data/lib/ruby2d/line.rb CHANGED
@@ -38,8 +38,28 @@ module Ruby2D
38
38
  (((@y2 - @y1) * x - (@x2 - @x1) * y + @x2 * @y1 - @y2 * @x1).abs / length) <= 0.5 * @width
39
39
  end
40
40
 
41
+ def self.draw(opts = {})
42
+ ext_draw([
43
+ opts[:x1], opts[:y1], opts[:x2], opts[:y2], opts[:width],
44
+ opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
45
+ opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
46
+ opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
47
+ opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
48
+ ])
49
+ end
50
+
41
51
  private
42
52
 
53
+ def render
54
+ self.class.ext_draw([
55
+ @x1, @y1, @x2, @y2, @width,
56
+ @c1.r, @c1.g, @c1.b, @c1.a,
57
+ @c2.r, @c2.g, @c2.b, @c2.a,
58
+ @c3.r, @c3.g, @c3.b, @c3.a,
59
+ @c4.r, @c4.g, @c4.b, @c4.a
60
+ ])
61
+ end
62
+
43
63
  # Calculate the distance between two points
44
64
  def points_distance(x1, y1, x2, y2)
45
65
  Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
data/lib/ruby2d/music.rb CHANGED
@@ -58,5 +58,10 @@ module Ruby2D
58
58
  ext_fadeout(ms)
59
59
  end
60
60
 
61
+ # Returns the length in seconds
62
+ def length
63
+ ext_length
64
+ end
65
+
61
66
  end
62
67
  end
@@ -0,0 +1,17 @@
1
+ # Ruby2D::Pixel
2
+
3
+ module Ruby2D
4
+ class Pixel
5
+
6
+ def self.draw(opts = {})
7
+ ext_draw([
8
+ opts[:x] , opts[:y],
9
+ opts[:x] + opts[:size], opts[:y],
10
+ opts[:x] + opts[:size], opts[:y] + opts[:size],
11
+ opts[:x] , opts[:y] + opts[:size],
12
+ opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
13
+ ])
14
+ end
15
+
16
+ end
17
+ end
data/lib/ruby2d/quad.rb CHANGED
@@ -48,8 +48,26 @@ module Ruby2D
48
48
  questioned_area <= self_area
49
49
  end
50
50
 
51
+ def self.draw(opts = {})
52
+ ext_draw([
53
+ opts[:x1], opts[:y1], opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
54
+ opts[:x2], opts[:y2], opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
55
+ opts[:x3], opts[:y3], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
56
+ opts[:x4], opts[:y4], opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
57
+ ])
58
+ end
59
+
51
60
  private
52
61
 
62
+ def render
63
+ self.class.ext_draw([
64
+ @x1, @y1, @c1.r, @c1.g, @c1.b, @c1.a,
65
+ @x2, @y2, @c2.r, @c2.g, @c2.b, @c2.a,
66
+ @x3, @y3, @c3.r, @c3.g, @c3.b, @c3.a,
67
+ @x4, @y4, @c4.r, @c4.g, @c4.b, @c4.a
68
+ ])
69
+ end
70
+
53
71
  def triangle_area(x1, y1, x2, y2, x3, y3)
54
72
  (x1*y2 + x2*y3 + x3*y1 - x3*y2 - x1*y3 - x2*y1).abs / 2
55
73
  end
@@ -39,6 +39,15 @@ module Ruby2D
39
39
  update_coords(@x, @y, @width, h)
40
40
  end
41
41
 
42
+ def self.draw(opts = {})
43
+ ext_draw([
44
+ opts[:x] , opts[:y] , opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
45
+ opts[:x] + opts[:width], opts[:y] , opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
46
+ opts[:x] + opts[:width], opts[:y] + opts[:height], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
47
+ opts[:x] , opts[:y] + opts[:height], opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
48
+ ])
49
+ end
50
+
42
51
  private
43
52
 
44
53
  def update_coords(x, y, w, h)
@@ -46,10 +55,10 @@ module Ruby2D
46
55
  @y1 = y
47
56
  @x2 = x + w
48
57
  @y2 = y
49
- @x4 = x
50
- @y4 = y + h
51
58
  @x3 = x + w
52
59
  @y3 = y + h
60
+ @x4 = x
61
+ @y4 = y + h
53
62
  end
54
63
 
55
64
  end
@@ -14,16 +14,12 @@ module Ruby2D
14
14
 
15
15
  # Add the object to the window
16
16
  def add
17
- if Module.const_defined? :DSL
18
- Window.add(self)
19
- end
17
+ Window.add(self)
20
18
  end
21
19
 
22
20
  # Remove the object from the window
23
21
  def remove
24
- if Module.const_defined? :DSL
25
- Window.remove(self)
26
- end
22
+ Window.remove(self)
27
23
  end
28
24
 
29
25
  # Set the color value
@@ -32,8 +28,8 @@ module Ruby2D
32
28
  end
33
29
 
34
30
  # Allow British English spelling of color
35
- def colour; self.color end
36
- def colour=(c); self.color = c end
31
+ alias_method :colour, :color
32
+ alias_method :colour=, :color=
37
33
 
38
34
  # Allow shortcuts for setting color values
39
35
  def r; self.color.r end
data/lib/ruby2d/sound.rb CHANGED
@@ -21,5 +21,10 @@ module Ruby2D
21
21
  ext_play
22
22
  end
23
23
 
24
+ # Returns the length in seconds
25
+ def length
26
+ ext_length
27
+ end
28
+
24
29
  end
25
30
  end
data/lib/ruby2d/sprite.rb CHANGED
@@ -42,7 +42,7 @@ module Ruby2D
42
42
  @last_frame = 0
43
43
  @done_proc = nil
44
44
 
45
- # The sprite image size set by the native extension `ext_init()`
45
+ # The sprite image size set by the native extension `ext_init`
46
46
  @img_width = nil; @img_height = nil
47
47
 
48
48
  # Initialize the sprite
@@ -72,7 +72,7 @@ module Ruby2D
72
72
  }
73
73
 
74
74
  # Add the sprite to the window
75
- add
75
+ unless opts[:show] == false then add end
76
76
  end
77
77
 
78
78
  # Set the x coordinate
@@ -141,6 +141,7 @@ module Ruby2D
141
141
  set_frame
142
142
  restart_time
143
143
  end
144
+ self
144
145
  end
145
146
 
146
147
  # Stop the current animation and set to the default frame
@@ -221,7 +222,7 @@ module Ruby2D
221
222
  @start_time = Time.now.to_f
222
223
  end
223
224
 
224
- # Update the sprite animation, called by `Sprite#ext_render`
225
+ # Update the sprite animation, called by `render`
225
226
  def update
226
227
  if @playing
227
228
 
@@ -246,5 +247,36 @@ module Ruby2D
246
247
  end
247
248
  end
248
249
 
250
+ def draw(opts = {})
251
+ opts[:width] = opts[:width] || @flip_width
252
+ opts[:height] = opts[:height] || @flip_height
253
+ opts[:rotate] = opts[:rotate] || @rotate
254
+ opts[:clip_x] = opts[:clip_x] || @clip_x
255
+ opts[:clip_y] = opts[:clip_y] || @clip_y
256
+ opts[:clip_width] = opts[:clip_width] || @clip_width
257
+ opts[:clip_height] = opts[:clip_height] || @clip_height
258
+ unless opts[:color]
259
+ opts[:color] = [1.0, 1.0, 1.0, 1.0]
260
+ end
261
+
262
+ self.class.ext_draw([
263
+ self, opts[:x], opts[:y], opts[:width], opts[:height], opts[:rotate],
264
+ opts[:clip_x], opts[:clip_y], opts[:clip_width], opts[:clip_height],
265
+ opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
266
+ ])
267
+ end
268
+
269
+ private
270
+
271
+ def render
272
+ update
273
+ self.class.ext_draw([
274
+ self, @flip_x, @flip_y, @flip_width, @flip_height, @rotate,
275
+ @clip_x, @clip_y, @clip_width, @clip_height,
276
+ @color.r, @color.g, @color.b, @color.a
277
+ ])
278
+ end
279
+
280
+
249
281
  end
250
282
  end
data/lib/ruby2d/square.rb CHANGED
@@ -21,6 +21,15 @@ module Ruby2D
21
21
  self.width = self.height = @size = s
22
22
  end
23
23
 
24
+ def self.draw(opts = {})
25
+ ext_draw([
26
+ opts[:x] , opts[:y] , opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
27
+ opts[:x] + opts[:size], opts[:y] , opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
28
+ opts[:x] + opts[:size], opts[:y] + opts[:size], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
29
+ opts[:x] , opts[:y] + opts[:size], opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
30
+ ])
31
+ end
32
+
24
33
  # Make the inherited width and height attribute accessors private
25
34
  private :width=, :height=
26
35
 
data/lib/ruby2d/text.rb CHANGED
@@ -23,7 +23,7 @@ module Ruby2D
23
23
  unless ext_init
24
24
  raise Error, "Text `#{@text}` cannot be created"
25
25
  end
26
- add
26
+ unless opts[:show] == false then add end
27
27
  end
28
28
 
29
29
  def text=(msg)
@@ -31,5 +31,26 @@ module Ruby2D
31
31
  ext_set(@text)
32
32
  end
33
33
 
34
+ def draw(opts = {})
35
+ opts[:rotate] = opts[:rotate] || @rotate
36
+ unless opts[:color]
37
+ opts[:color] = [1.0, 1.0, 1.0, 1.0]
38
+ end
39
+
40
+ self.class.ext_draw([
41
+ self, opts[:x], opts[:y], opts[:rotate],
42
+ opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
43
+ ])
44
+ end
45
+
46
+ private
47
+
48
+ def render
49
+ self.class.ext_draw([
50
+ self, @x, @y, @rotate,
51
+ @color.r, @color.g, @color.b, @color.a
52
+ ])
53
+ end
54
+
34
55
  end
35
56
  end
@@ -0,0 +1,69 @@
1
+ # Ruby2D::Tileset
2
+
3
+ module Ruby2D
4
+ class Tileset
5
+ include Renderable
6
+
7
+ def initialize(path, opts = {})
8
+ unless File.exist? path
9
+ raise Error, "Cannot find tileset image file `#{path}`"
10
+ end
11
+ @path = path
12
+ @tiles = []
13
+ @defined_tiles = {}
14
+ @padding = opts[:padding] || 0
15
+ @spacing = opts[:spacing] || 0
16
+ @tile_width = opts[:tile_width]
17
+ @tile_height = opts[:tile_height]
18
+
19
+ unless ext_init(@path)
20
+ raise Error, "Tileset `#{@path}` cannot be created"
21
+ end
22
+
23
+ unless opts[:show] == false then add end
24
+ end
25
+
26
+ def define_tile(name, x, y)
27
+ @defined_tiles[name] = { x: x, y: y }
28
+ end
29
+
30
+ def set_tile(name, coordinates)
31
+ tile = @defined_tiles.fetch(name)
32
+
33
+ coordinates.each do |coordinate|
34
+ @tiles.push({
35
+ tile_x: tile.fetch(:x),
36
+ tile_y: tile.fetch(:y),
37
+ x: coordinate.fetch(:x),
38
+ y: coordinate.fetch(:y)
39
+ })
40
+ end
41
+ end
42
+
43
+ def clear_tiles
44
+ @tiles = []
45
+ end
46
+ end
47
+
48
+ def draw(opts = {})
49
+ render(opts)
50
+ end
51
+
52
+ private
53
+
54
+ def render(opts = {})
55
+ opts[:tile_width] = opts[:tile_width] || @tile_width
56
+ opts[:tile_height] = opts[:tile_height] || @tile_height
57
+ opts[:padding] = opts[:padding] || @padding
58
+ opts[:spacing] = opts[:spacing] || @spacing
59
+
60
+ @tiles.each do |tile|
61
+ self.class.ext_draw(
62
+ [
63
+ self, opts[:tile_width], opts[:tile_height], opts[:padding], opts[:spacing],
64
+ tile.fetch(:tile_x), tile.fetch(:tile_y), tile.fetch(:x),
65
+ tile.fetch(:y)
66
+ ])
67
+ end
68
+ end
69
+ end