ehb_game_lib 0.0.5 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/lib/ehb_game_lib.rb +5 -20
  3. data/lib/ehb_game_lib/base_state.rb +6 -0
  4. data/lib/ehb_game_lib/canvas.rb +20 -0
  5. data/lib/ehb_game_lib/gfx.rb +2 -0
  6. data/lib/ehb_game_lib/globals.rb +2 -0
  7. data/lib/ehb_game_lib/math.rb +9 -0
  8. data/lib/ehb_game_lib/math/circle.rb +2 -0
  9. data/lib/ehb_game_lib/math/intersection/circle_line.rb +2 -0
  10. data/lib/ehb_game_lib/math/intersection/circle_line_segment.rb +2 -0
  11. data/lib/ehb_game_lib/math/line.rb +2 -0
  12. data/lib/ehb_game_lib/math/line_segment.rb +2 -0
  13. data/lib/ehb_game_lib/math/quadratic_equation.rb +4 -1
  14. data/lib/ehb_game_lib/math/rectable_object.rb +2 -0
  15. data/lib/ehb_game_lib/math/vector.rb +2 -0
  16. data/lib/ehb_game_lib/nes.rb +9 -0
  17. data/lib/ehb_game_lib/nes/all_colors_palette.rb +2 -0
  18. data/lib/ehb_game_lib/nes/color.rb +2 -0
  19. data/lib/ehb_game_lib/nes/palette.rb +2 -0
  20. data/lib/ehb_game_lib/patches/chingu/basic_game_object.rb +2 -0
  21. data/lib/ehb_game_lib/patches/gosu/font.rb +2 -0
  22. data/lib/ehb_game_lib/text.rb +9 -0
  23. data/lib/ehb_game_lib/text/bitmap_font.rb +18 -0
  24. data/lib/ehb_game_lib/text/bitmap_text.rb +8 -0
  25. data/lib/ehb_game_lib/traits/bounding_line_segment.rb +4 -0
  26. data/lib/ehb_game_lib/utils.rb +9 -0
  27. data/lib/ehb_game_lib/utils/cursor.rb +3 -1
  28. data/lib/ehb_game_lib/version.rb +3 -1
  29. data/lib/ehb_game_lib/window.rb +72 -0
  30. data/lib/ehb_game_lib/window/gl_read_pixels_image.rb +26 -0
  31. data/test/lib/ehb_game_lib/math/circle_test.rb +2 -0
  32. data/test/lib/ehb_game_lib/math/intersection/circle_line_segment_test.rb +5 -0
  33. data/test/lib/ehb_game_lib/math/intersection/circle_line_test.rb +2 -0
  34. data/test/lib/ehb_game_lib/math/line_segment_test.rb +2 -0
  35. data/test/lib/ehb_game_lib/math/line_test.rb +2 -0
  36. data/test/lib/ehb_game_lib/math/quadratic_equation_test.rb +2 -0
  37. data/test/lib/ehb_game_lib/math/rectable_object_test.rb +2 -0
  38. data/test/test_helper.rb +2 -0
  39. metadata +48 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e2dd328f0f04eb106f0d5583057e3327c7e2ed15
4
- data.tar.gz: 635f13624ba391b24b80a9403ae987db25d53d80
2
+ SHA256:
3
+ metadata.gz: 9acd1ac23a1acd8cdafc3382002cca990d79c0eebdba0f681c9a5e499876fd05
4
+ data.tar.gz: 54c26e41e8a034f231445bb0105a072ff1be27dd5e27c08df921c8ee63b23dae
5
5
  SHA512:
6
- metadata.gz: 95094355b73f2229f9c976314f12b2ae364f9640e05e32e289bf05731b2bd736382ed508af0876be125d9953dc4eead42e4b3ffda5f2ea503474a682e536334c
7
- data.tar.gz: 763dd1a5d99ee835996d3faf697c7668c0bb95fbf6b612794116aa7e0dd5673a0f1907ac44fdb2ca0222896ac130a3a3f36ee88b7745ece671c1f4091ea21d13
6
+ metadata.gz: 16e379f2da9c3bda6e0aabeb25b3dd76160d01ffd255bb01c154dd66788c19efc53980694ef45bdd2528b145bed0da9b73570be39205d417ff4730cacea35367
7
+ data.tar.gz: 82e9484c27ead60e992b2069a0d2ba66480bd4f8b2aecbffcf33c4a9a447e233c92c10719c758716a079b40629d8865d1427c519776f97138eb761e0e06c830c
@@ -1,24 +1,9 @@
1
- require 'active_support'
2
- require 'active_support/core_ext'
1
+ # frozen_string_literal: true
2
+
3
3
  require 'chingu'
4
- require 'ehb_game_lib/version'
5
- require 'ehb_game_lib/globals'
6
- require 'ehb_game_lib/gfx'
7
- require 'ehb_game_lib/math/circle'
8
- require 'ehb_game_lib/math/line'
9
- require 'ehb_game_lib/math/line_segment'
10
- require 'ehb_game_lib/math/quadratic_equation'
11
- require 'ehb_game_lib/math/rectable_object'
12
- require 'ehb_game_lib/math/vector'
13
- require 'ehb_game_lib/math/intersection/circle_line'
14
- require 'ehb_game_lib/math/intersection/circle_line_segment'
15
- require 'ehb_game_lib/nes/all_colors_palette'
16
- require 'ehb_game_lib/nes/color'
17
- require 'ehb_game_lib/nes/palette'
18
- require 'ehb_game_lib/patches/chingu/basic_game_object'
19
- require 'ehb_game_lib/patches/gosu/font'
20
- require 'ehb_game_lib/traits/bounding_line_segment'
21
- require 'ehb_game_lib/utils/cursor'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'opengl'
22
6
 
23
7
  module EhbGameLib
8
+ require_sub __FILE__
24
9
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EhbGameLib
4
+ class BaseState < ::Chingu::GameState
5
+ end
6
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehb_game_lib/math/rectable_object'
5
+
6
+ module EhbGameLib
7
+ class Canvas
8
+ include ::EhbGameLib::Math::RectableObject
9
+
10
+ common_constructor :width, :height
11
+
12
+ def x
13
+ 0
14
+ end
15
+
16
+ def y
17
+ 0
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  class Gfx
3
5
  class << self
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  # No-global variables bridge to Chingu global variables.
3
5
  class Globals
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbGameLib
6
+ module Math
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Math
3
5
  class Circle
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Math
3
5
  module Intersection
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Math
3
5
  module Intersection
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Math
3
5
  class Line
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Math
3
5
  class LineSegment
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Math
3
5
  class QuadraticEquation
@@ -12,6 +14,7 @@ module EhbGameLib
12
14
  def roots
13
15
  return [root(1), root(-1)] if delta > 0.0
14
16
  return [root(1)] if delta == 0.0
17
+
15
18
  []
16
19
  end
17
20
 
@@ -20,7 +23,7 @@ module EhbGameLib
20
23
  end
21
24
 
22
25
  def root(signal)
23
- signal = signal < 0 ? -1 : 1
26
+ signal = signal.negative? ? -1 : 1
24
27
  (-b + signal * ::Math.sqrt(delta)) / (2 * a)
25
28
  end
26
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Math
3
5
  module RectableObject
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Math
3
5
  class Vector
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbGameLib
6
+ module Nes
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Nes
3
5
  class AllColorsPalette
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Nes
3
5
  class Color
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Nes
3
5
  class Palette
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Patches
3
5
  module Chingu
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Patches
3
5
  module Gosu
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbGameLib
6
+ module Text
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EhbGameLib
4
+ module Text
5
+ class BitmapFont
6
+ attr_reader :name, :line_height
7
+
8
+ def initialize(name, line_height)
9
+ @name = name
10
+ @line_height = line_height
11
+ end
12
+
13
+ def image(text)
14
+ ::Gosu::Image.from_text(text, line_height, retro: true, font: name)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EhbGameLib
4
+ module Text
5
+ class BitmapText
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Traits
3
5
  # Interface required:
@@ -5,10 +7,12 @@ module EhbGameLib
5
7
  module BoundingLineSegment
6
8
  def nearest_circle_collision(klasses)
7
9
  return [nil, nil] unless line_segment?
10
+
8
11
  min_obj = min_p = min_dist = nil
9
12
  each_circle_collision(klasses) do |object, p|
10
13
  dist = Gosu.distance(last_x, last_y, p.x, p.y)
11
14
  next unless min_dist.nil? || dist < min_dist
15
+
12
16
  min_dist = dist
13
17
  min_obj = object
14
18
  min_p = p
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbGameLib
6
+ module Utils
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
4
  module Utils
3
5
  class Cursor
@@ -38,7 +40,7 @@ module EhbGameLib
38
40
  @index = 0
39
41
  elsif @index >= @set.count
40
42
  @index = @set.count - 1
41
- elsif @index < 0
43
+ elsif @index.negative?
42
44
  @index = 0
43
45
  end
44
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EhbGameLib
2
- VERSION = '0.0.5'.freeze
4
+ VERSION = '0.2.2'
3
5
  end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/require_sub'
5
+ require 'ehb_game_lib/canvas'
6
+ ::EacRubyUtils.require_sub(__FILE__)
7
+
8
+ module EhbGameLib
9
+ class Window < ::Chingu::Window
10
+ attr_accessor :fit_canvas_to_window, :draw_retro
11
+ attr_reader :canvas, :canvas_factor
12
+
13
+ def initialize(canvas_width, canvas_height)
14
+ @canvas = ::EhbGameLib::Canvas.new(canvas_width, canvas_height)
15
+ @canvas_factor = 1
16
+ self.fit_canvas_to_window = true
17
+ self.draw_retro = true
18
+ super calculated_width, calculated_height
19
+ dimensions_reset
20
+ end
21
+
22
+ def calculated_width
23
+ canvas.width * canvas_factor
24
+ end
25
+
26
+ def calculated_height
27
+ canvas.height * canvas_factor
28
+ end
29
+
30
+ def canvas_factor=(factor)
31
+ @canvas_factor = factor
32
+ dimensions_reset
33
+ end
34
+
35
+ def fullscreen=(value)
36
+ super(value)
37
+ dimensions_reset
38
+ end
39
+
40
+ def draw
41
+ super if ::EhbGameLib::Globals.window
42
+ draw_resized
43
+ end
44
+
45
+ private
46
+
47
+ def dimensions_reset
48
+ if fullscreen?
49
+ self.width = canvas.width
50
+ self.height = canvas.height
51
+ else
52
+ self.width = calculated_width
53
+ self.height = calculated_height
54
+ end
55
+ end
56
+
57
+ def draw_resized
58
+ return unless fit_canvas_to_window && !fullscreen?
59
+
60
+ ::Gosu::Image.new(canvas_image_source, retro: draw_retro)
61
+ .draw(0, 0, 100, canvas_factor, canvas_factor)
62
+ end
63
+
64
+ def canvas_image_source
65
+ image_source(0, height - canvas.height, canvas.width, canvas.height)
66
+ end
67
+
68
+ def image_source(x, y, w, h)
69
+ GlReadPixelsImage.new(x, y, w, h)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'chingu'
4
+
5
+ module EhbGameLib
6
+ class Window < ::Chingu::Window
7
+ class GlReadPixelsImage
8
+ attr_reader :columns, :rows
9
+
10
+ DEPTH = 4
11
+
12
+ def initialize(x, y, width, height)
13
+ @columns = width
14
+ @rows = height
15
+ Gosu.flush
16
+ Gosu.gl do
17
+ @blob = ::Gl.glReadPixels(x, y, width, height, Gl::GL_RGBA, Gl::GL_UNSIGNED_BYTE)
18
+ end
19
+ end
20
+
21
+ def to_blob
22
+ @blob.force_encoding('binary').scan(/.{#{columns * 4}}/m).reverse.join
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module EhbGameLib
@@ -1,3 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehb_game_lib/math/circle'
4
+ require 'ehb_game_lib/math/intersection/circle_line'
5
+ require 'ehb_game_lib/math/intersection/circle_line_segment'
1
6
  require 'test_helper'
2
7
 
3
8
  module EhbGameLib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module EhbGameLib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module EhbGameLib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module EhbGameLib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module EhbGameLib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module EhbGameLib
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ehb_game_lib'
2
4
  require 'test/unit'
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehb_game_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-27 00:00:00.000000000 Z
11
+ date: 2021-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: chingu
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0
19
+ version: 0.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.0
26
+ version: 0.8.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: chingu
28
+ name: eac_ruby_utils
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.1
33
+ version: '0.57'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.8.1
40
+ version: '0.57'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gosu
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,13 +53,13 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.13.1
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: opengl
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :development
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -67,19 +67,39 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rubocop
70
+ name: eac_ruby_gem_support
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '='
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ - - ">="
74
77
  - !ruby/object:Gem::Version
75
- version: 0.42.0
78
+ version: 0.1.2
76
79
  type: :development
77
80
  prerelease: false
78
81
  version_requirements: !ruby/object:Gem::Requirement
79
82
  requirements:
80
- - - '='
83
+ - - "~>"
81
84
  - !ruby/object:Gem::Version
82
- version: 0.42.0
85
+ version: '0.1'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 0.1.2
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
83
103
  - !ruby/object:Gem::Dependency
84
104
  name: test-unit
85
105
  requirement: !ruby/object:Gem::Requirement
@@ -102,8 +122,11 @@ extensions: []
102
122
  extra_rdoc_files: []
103
123
  files:
104
124
  - lib/ehb_game_lib.rb
125
+ - lib/ehb_game_lib/base_state.rb
126
+ - lib/ehb_game_lib/canvas.rb
105
127
  - lib/ehb_game_lib/gfx.rb
106
128
  - lib/ehb_game_lib/globals.rb
129
+ - lib/ehb_game_lib/math.rb
107
130
  - lib/ehb_game_lib/math/circle.rb
108
131
  - lib/ehb_game_lib/math/intersection/circle_line.rb
109
132
  - lib/ehb_game_lib/math/intersection/circle_line_segment.rb
@@ -112,14 +135,21 @@ files:
112
135
  - lib/ehb_game_lib/math/quadratic_equation.rb
113
136
  - lib/ehb_game_lib/math/rectable_object.rb
114
137
  - lib/ehb_game_lib/math/vector.rb
138
+ - lib/ehb_game_lib/nes.rb
115
139
  - lib/ehb_game_lib/nes/all_colors_palette.rb
116
140
  - lib/ehb_game_lib/nes/color.rb
117
141
  - lib/ehb_game_lib/nes/palette.rb
118
142
  - lib/ehb_game_lib/patches/chingu/basic_game_object.rb
119
143
  - lib/ehb_game_lib/patches/gosu/font.rb
144
+ - lib/ehb_game_lib/text.rb
145
+ - lib/ehb_game_lib/text/bitmap_font.rb
146
+ - lib/ehb_game_lib/text/bitmap_text.rb
120
147
  - lib/ehb_game_lib/traits/bounding_line_segment.rb
148
+ - lib/ehb_game_lib/utils.rb
121
149
  - lib/ehb_game_lib/utils/cursor.rb
122
150
  - lib/ehb_game_lib/version.rb
151
+ - lib/ehb_game_lib/window.rb
152
+ - lib/ehb_game_lib/window/gl_read_pixels_image.rb
123
153
  - test/lib/ehb_game_lib/math/circle_test.rb
124
154
  - test/lib/ehb_game_lib/math/intersection/circle_line_segment_test.rb
125
155
  - test/lib/ehb_game_lib/math/intersection/circle_line_test.rb
@@ -146,8 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
176
  - !ruby/object:Gem::Version
147
177
  version: '0'
148
178
  requirements: []
149
- rubyforge_project:
150
- rubygems_version: 2.6.14
179
+ rubygems_version: 3.0.8
151
180
  signing_key:
152
181
  specification_version: 4
153
182
  summary: EHB's game library for Ruby