ehb_game_lib 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d643f13e6d8b07eaa4619f06e90dc4560ad05cecb7fa87bda94d1ddb929ac608
4
- data.tar.gz: fecab868437c73851309abed83e4baa9090c6b8e460c9e96e9e3722af0c690aa
3
+ metadata.gz: 29657e3bdfde37d33d26b4ab32ed8048421d48a82f2cd823e005878f438e3c78
4
+ data.tar.gz: 252deae3be739fb8b83917bd3e4f7e914701b76132f02338dbf489e5957a04b8
5
5
  SHA512:
6
- metadata.gz: 2860f3c38dbce468873ea6c2802c4175c69af94f245c5a3c151ca52863e7f5320cb5c1bed61a94c5a0a7a6d5dc8031e3ba034a1a2fe6c50b8f7bfe86aecdb52e
7
- data.tar.gz: 03e53f34ec987f63960fc5e046d364603df4c3ccaec23482ac1e5aaebaa9db3e4c09214c44a9e96262a10a06fdf982a2b7bf5d6fd9a9953f644c8c44390bc4ae
6
+ metadata.gz: e31e685a986caae81bd127bf9cabdf6ca59a767f08b72e64c50b7df2ffd98bd7383cab432d230b8e18e3ec44629cc962a8bf7740253685cde557cd71620f4d98
7
+ data.tar.gz: cf7d3da8e1ff2f29c86852f1c265d15e8984a3fa8e07bd57c07ae667d82eb05a1ed9cda7fb468aadfb0827861fdd5f6ad1c859c119967041b43da5c6ac503816
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EhbGameLib
4
+ class BaseState < ::Chingu::GameState
5
+ def draw
6
+ super
7
+ ::EhbGameLib::Globals.window.draw_resized
8
+ end
9
+ end
10
+ 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,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbGameLib
4
- VERSION = '0.0.6'
4
+ VERSION = '0.1.0'
5
5
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EhbGameLib
4
+ class Window < ::Chingu::Window
5
+ attr_accessor :fit_canvas_to_window, :draw_retro
6
+ attr_reader :canvas_width, :canvas_height, :canvas_factor
7
+
8
+ def initialize(canvas_width, canvas_height)
9
+ @canvas_width = canvas_width
10
+ @canvas_height = canvas_height
11
+ @canvas_factor = 1
12
+ self.fit_canvas_to_window = true
13
+ self.draw_retro = true
14
+ super calculated_width, calculated_height
15
+ end
16
+
17
+ def calculated_width
18
+ canvas_width * canvas_factor
19
+ end
20
+
21
+ def calculated_height
22
+ canvas_height * canvas_factor
23
+ end
24
+
25
+ def canvas_factor=(factor)
26
+ @canvas_factor = factor
27
+ self.width = calculated_width
28
+ self.height = calculated_height
29
+ end
30
+
31
+ def draw
32
+ super if ::EhbGameLib::Globals.window
33
+ end
34
+
35
+ def draw_resized
36
+ return unless fit_canvas_to_window
37
+
38
+ ::Gosu::Image.new(canvas_image_source, retro: draw_retro)
39
+ .draw(0, 0, 100, canvas_factor, canvas_factor)
40
+ end
41
+
42
+ private
43
+
44
+ def canvas_image_source
45
+ image_source(0, height - canvas_height, canvas_width, canvas_height)
46
+ end
47
+
48
+ def image_source(x, y, w, h)
49
+ GlReadPixelsImage.new(x, y, w, h)
50
+ end
51
+
52
+ class GlReadPixelsImage
53
+ attr_reader :columns, :rows
54
+
55
+ DEPTH = 4
56
+
57
+ def initialize(x, y, width, height)
58
+ @columns = width
59
+ @rows = height
60
+ Gosu.flush
61
+ Gosu.gl do
62
+ @blob = ::Gl.glReadPixels(x, y, width, height, Gl::GL_RGBA, Gl::GL_UNSIGNED_BYTE)
63
+ end
64
+ end
65
+
66
+ def to_blob
67
+ @blob.force_encoding('binary').scan(/.{#{columns * 4}}/m).reverse.join
68
+ end
69
+ end
70
+ end
71
+ end
data/lib/ehb_game_lib.rb CHANGED
@@ -3,7 +3,9 @@
3
3
  require 'active_support'
4
4
  require 'active_support/core_ext'
5
5
  require 'chingu'
6
+ require 'opengl'
6
7
  require 'ehb_game_lib/version'
8
+ require 'ehb_game_lib/base_state'
7
9
  require 'ehb_game_lib/globals'
8
10
  require 'ehb_game_lib/gfx'
9
11
  require 'ehb_game_lib/math/circle'
@@ -20,7 +22,10 @@ require 'ehb_game_lib/nes/palette'
20
22
  require 'ehb_game_lib/patches/chingu/basic_game_object'
21
23
  require 'ehb_game_lib/patches/gosu/font'
22
24
  require 'ehb_game_lib/traits/bounding_line_segment'
25
+ require 'ehb_game_lib/text/bitmap_font'
26
+ require 'ehb_game_lib/text/bitmap_text'
23
27
  require 'ehb_game_lib/utils/cursor'
28
+ require 'ehb_game_lib/window'
24
29
 
25
30
  module EhbGameLib
26
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehb_game_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
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: 2020-01-29 00:00:00.000000000 Z
11
+ date: 2020-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0
19
+ version: 4.0.0
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: 4.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: chingu
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.13.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: opengl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +116,7 @@ extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
118
  - lib/ehb_game_lib.rb
119
+ - lib/ehb_game_lib/base_state.rb
105
120
  - lib/ehb_game_lib/gfx.rb
106
121
  - lib/ehb_game_lib/globals.rb
107
122
  - lib/ehb_game_lib/math/circle.rb
@@ -117,9 +132,12 @@ files:
117
132
  - lib/ehb_game_lib/nes/palette.rb
118
133
  - lib/ehb_game_lib/patches/chingu/basic_game_object.rb
119
134
  - lib/ehb_game_lib/patches/gosu/font.rb
135
+ - lib/ehb_game_lib/text/bitmap_font.rb
136
+ - lib/ehb_game_lib/text/bitmap_text.rb
120
137
  - lib/ehb_game_lib/traits/bounding_line_segment.rb
121
138
  - lib/ehb_game_lib/utils/cursor.rb
122
139
  - lib/ehb_game_lib/version.rb
140
+ - lib/ehb_game_lib/window.rb
123
141
  - test/lib/ehb_game_lib/math/circle_test.rb
124
142
  - test/lib/ehb_game_lib/math/intersection/circle_line_segment_test.rb
125
143
  - test/lib/ehb_game_lib/math/intersection/circle_line_test.rb