bestguigui_lab 0.6.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d6f1ccaf5c79158aa6dc51cbbf2c9596c9365136e7d11846051de723adab104
4
- data.tar.gz: 581bc3c963fee75bbf61b56cc6cce393ce0fb23abe50065ef176c3ac70298642
3
+ metadata.gz: 5b673ef4e8872e5d7caf22b1ff79292179b2218c4cc7b52c2caafba484d6b268
4
+ data.tar.gz: beb55c5d96030f481f50400880e4fe03fab15c7a84b176d289d2697947ba38c7
5
5
  SHA512:
6
- metadata.gz: edeedc5450b235ac9db1612d388c85dc11ac12524d79e4c1c5eb24cbc34a31bf0119d3008ea083ea1a2b070846a86a139cf85456ffa1d9e4ce580bec6efa0583
7
- data.tar.gz: 6f65e74172370444eca7515ad98a595d41f1cccec471c3b089e1136b08f35dcd5605fa53b07c053ac3af0db5122b4421c3528e4dadfdc85e5e19702456c38576
6
+ metadata.gz: e84c4e95875f7dec3e34190e852c50bf61fe909799507cf0f6b47f98d50b780b561a93fd6fc95616019fb41a40f71ce9ac4d4a98f46aba29d79a64edbd4c678a
7
+ data.tar.gz: 2d5c2e7de99e3025b7e1b97cadd48c8881bdf79bcf568dec299a9ae4a135a6e1eced058c1d508c5567c26a7df39cdd6e6420321905eae7a185ae11794d5c48aa
@@ -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
- # Monkey patch de Gosu::Image pour lire/ecrire un pixel individuel.
4
- class Gosu::Image
5
- def get_pixel(x, y)
6
- return nil if x < 0 || x >= width || y < 0 || y >= height
7
-
8
- r, g, b, a = to_blob[((y * width) + x) * 4, 4].unpack('C4')
9
- Gosu::Color.new(a, r, g, b)
10
- end
11
-
12
- def set_pixel(x, y, color)
13
- blob = [color.red, color.green, color.blue, color.alpha].pack('C4')
14
- pixel = Gosu::Image.from_blob(1, 1, blob)
15
- insert(pixel, x, y)
16
- end
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
@@ -125,6 +125,10 @@ module Bestguigui
125
125
  HOLD = 1.2
126
126
  FADE_OUT = 0.6
127
127
 
128
+ JINGLE_PATH = File.join(__dir__, 'assets', 'splash_jingle.wav')
129
+
130
+ def self.jingle = @jingle ||= Gosu::Sample.new(JINGLE_PATH)
131
+
128
132
  def initialize(window, title:, next_scene:)
129
133
  super(window)
130
134
  @title = title
@@ -134,6 +138,7 @@ module Bestguigui
134
138
  @subtitle_font = Assets.font(size: 24)
135
139
  @gosu_font = Assets.font(size: 36)
136
140
  @elapsed = 0.0
141
+ self.class.jingle.play
137
142
  end
138
143
 
139
144
  def update(dt)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bestguigui
4
- VERSION = '0.6.0'
4
+ VERSION = '0.8.0'
5
5
  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.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bestguigui
@@ -42,7 +42,9 @@ 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
47
+ - lib/bestguigui_lab/assets/splash_jingle.wav
46
48
  - lib/bestguigui_lab/gl_texture.rb
47
49
  - lib/bestguigui_lab/helpers.rb
48
50
  - lib/bestguigui_lab/image_pixels.rb