bestguigui_lab 0.6.0 → 0.7.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.
- checksums.yaml +4 -4
- data/lib/bestguigui_lab/animation.rb +48 -0
- data/lib/bestguigui_lab/assets.rb +2 -0
- data/lib/bestguigui_lab/image_pixels.rb +19 -17
- data/lib/bestguigui_lab/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d7feac3a249d87251ad58de5f8c57710a2145397f3e89ca1403a01b3d8d60448
|
|
4
|
+
data.tar.gz: be7f8c50bd86ba6ec526ff14918ff5e95a496b8abc42c4cdee7b726f2b49e6ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a1bf4728a5e383ffb1d042ebfac95e5bc939d1e8b08774cc5179323584b3ff2bd88c3d91dec9c683cd23ab7bd8e441aa809616b7664bc32b2f699496ab4d20a2
|
|
7
|
+
data.tar.gz: d833d0f6452eda6520a63be8bf9d9c69bf7b44bdf1e3b13970a400571e52985d5850b6c52760050011d52aba1c914ca4e460cfee365f4302d25ef1a5e61bda68
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bestguigui
|
|
4
|
+
# Anime les frames d'un spritesheet selon un cycle d'indices donne
|
|
5
|
+
# (ex. cycle: [0, 1, 2, 1] pour un aller-retour). Sans cycle, joue
|
|
6
|
+
# les frames dans l'ordre du sheet.
|
|
7
|
+
#
|
|
8
|
+
# walk = Bestguigui::Animation.new('hero.png', 32, 32, cycle: [0, 1, 2, 1], frame_duration: 120)
|
|
9
|
+
# walk.update(dt)
|
|
10
|
+
# walk.draw(x, y)
|
|
11
|
+
class Animation
|
|
12
|
+
# rubocop:disable Metrics/ParameterLists -- reprend la signature de Gosu::Image#draw
|
|
13
|
+
def initialize(path, frame_width, frame_height, frame_duration:, cycle: nil, loop: true)
|
|
14
|
+
@frames = Assets.frames(path, frame_width, frame_height)
|
|
15
|
+
@cycle = cycle || (0...@frames.size).to_a
|
|
16
|
+
@frame_duration = frame_duration
|
|
17
|
+
@loop = loop
|
|
18
|
+
@elapsed = 0
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def update(dt)
|
|
22
|
+
@elapsed += dt unless finished?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def frame = @frames[@cycle[current_step]]
|
|
26
|
+
|
|
27
|
+
def draw(x, y, z = 0, scale_x = 1, scale_y = 1, color = Gosu::Color::WHITE, mode = :default)
|
|
28
|
+
frame.draw(x, y, z, scale_x, scale_y, color, mode)
|
|
29
|
+
end
|
|
30
|
+
# rubocop:enable Metrics/ParameterLists
|
|
31
|
+
|
|
32
|
+
def finished? = !@loop && raw_step >= @cycle.size
|
|
33
|
+
|
|
34
|
+
def reset
|
|
35
|
+
@elapsed = 0
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def raw_step = (@elapsed / @frame_duration).to_i
|
|
41
|
+
|
|
42
|
+
def current_step
|
|
43
|
+
return raw_step % @cycle.size if @loop
|
|
44
|
+
|
|
45
|
+
[raw_step, @cycle.size - 1].min
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -11,6 +11,7 @@ module Bestguigui
|
|
|
11
11
|
@fonts = Hash.new { |cache, key| cache[key] = Gosu::Font.new(key[1], name: key[0]) }
|
|
12
12
|
@models = Hash.new { |cache, path| cache[path] = ObjModel.new(path) }
|
|
13
13
|
@textures = Hash.new { |cache, path| cache[path] = GLTexture.new(path) }
|
|
14
|
+
@frames = Hash.new { |cache, key| cache[key] = Gosu::Image.load_tiles(key[0], key[1], key[2], retro: true) }
|
|
14
15
|
|
|
15
16
|
def self.resolve(name) = File.expand_path(name, @root)
|
|
16
17
|
def self.image(name) = @images[resolve(name)]
|
|
@@ -24,5 +25,6 @@ module Bestguigui
|
|
|
24
25
|
|
|
25
26
|
def self.model(name) = @models[resolve(name)]
|
|
26
27
|
def self.texture(name) = @textures[resolve(name)]
|
|
28
|
+
def self.frames(name, tile_width, tile_height) = @frames[[resolve(name), tile_width, tile_height]]
|
|
27
29
|
end
|
|
28
30
|
end
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Gosu
|
|
4
|
+
# Monkey patch de Gosu::Image pour lire/ecrire un pixel individuel.
|
|
5
|
+
class Image
|
|
6
|
+
def get_pixel(x, y)
|
|
7
|
+
return nil if x.negative? || x >= width || y.negative? || y >= height
|
|
8
|
+
|
|
9
|
+
r, g, b, a = to_blob[((y * width) + x) * 4, 4].unpack('C4')
|
|
10
|
+
Gosu::Color.new(a, r, g, b)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def set_pixel(x, y, color)
|
|
14
|
+
blob = [color.red, color.green, color.blue, color.alpha].pack('C4')
|
|
15
|
+
pixel = Gosu::Image.from_blob(1, 1, blob)
|
|
16
|
+
insert(pixel, x, y)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bestguigui_lab
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bestguigui
|
|
@@ -42,6 +42,7 @@ extensions: []
|
|
|
42
42
|
extra_rdoc_files: []
|
|
43
43
|
files:
|
|
44
44
|
- lib/bestguigui_lab.rb
|
|
45
|
+
- lib/bestguigui_lab/animation.rb
|
|
45
46
|
- lib/bestguigui_lab/assets.rb
|
|
46
47
|
- lib/bestguigui_lab/gl_texture.rb
|
|
47
48
|
- lib/bestguigui_lab/helpers.rb
|