orange_zest 0.1.0 → 0.2.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: 86f58491ecd24a1b7bc7f00fdf6ef8ededee32319660e83b4c97816a5a2d6263
4
- data.tar.gz: fd151abcfe7ecbeac7fe08459d5bb12eda93d1f05f5044c50ee354212e8a1bf8
3
+ metadata.gz: 27e386f30a8dc3f44d62bc4883bc8f08466ab9238a79c0027eaec2845cc9073e
4
+ data.tar.gz: c1e22e77a3cc554a03e253e732c37efb42ddda52dbbe39a1e9d07e009ae0d4d8
5
5
  SHA512:
6
- metadata.gz: 733200a7e3ffd918dd961e90dc6a6185a5be1aa2fcb45a8a1c608c146955d8fd315411a3550edafe38a41954961733b5570653bc7f1cfabc12da9971eb201b44
7
- data.tar.gz: 7110079d1c76dfc8de9a05b5c50d02c8d85798d3ab0652191ad8aabf549fa60b8f84de526360ead66a6163f489ff6005c679ee0d16ea91980d6afeeda73a91bb
6
+ metadata.gz: 33e6b35b126fc62d9b6b1f2627b6afc37144d921ec95434e7ca338a1c63c1fe10d3217e1613cb6bb64b9bf4fa8de4cc19463e68ab3c4c69493d9398ba6e60960
7
+ data.tar.gz: 77b3ed115ae9d72f2de69f73efb82ac3f3c951edbaa145a1e30882f0a064e92c605dd49304ea216e111daed01b723f7f2d1a4fb7a5f59ccf6d1e93abfa0056fd
@@ -7,6 +7,8 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  steps:
9
9
  - uses: actions/checkout@v2
10
+ - name: Install Gosu dependencies
11
+ run: sudo apt install build-essential libsdl2-dev libgl1-mesa-dev libopenal-dev libgmp-dev libfontconfig1-dev
10
12
  - name: Set up Ruby
11
13
  uses: ruby/setup-ruby@v1
12
14
  with:
data/CHANGELOG.md CHANGED
@@ -1,4 +1,18 @@
1
- ## [Unreleased]
1
+ ## [0.2.0] - 2023-05-18
2
+
3
+ ### Added
4
+
5
+ - Add `Component#anon` for creating one-off components
6
+ - Add `Box#centre` for getting the centre point of a bounding box
7
+ - Add `Point#line_to` for sampling points on a line between two points
8
+ - Alias `Point#[]` to `Point#new`
9
+ - Override `Point#to_s` and `Point#inspect` to be more concise
10
+ - Scalars can now be added or subtracted with a `Point` to equivalently affect all of its elements
11
+ - Add `Animation#placeholder` for creating a static, solid-colour animation
12
+
13
+ ### Fixed
14
+
15
+ - `Entity#bounding_box` now reflects scaling in its width and height
2
16
 
3
17
  ## [0.1.0] - 2022-08-27
4
18
 
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  diff-lcs (1.5.0)
11
- gosu (9.9.9)
11
+ gosu (1.4.5)
12
12
  rake (13.0.6)
13
13
  rspec (3.11.0)
14
14
  rspec-core (~> 3.11.0)
@@ -26,6 +26,7 @@ GEM
26
26
 
27
27
  PLATFORMS
28
28
  arm64-darwin-21
29
+ x86_64-linux
29
30
 
30
31
  DEPENDENCIES
31
32
  orange_zest!
@@ -23,6 +23,19 @@ module OrangeZest
23
23
  new([image], -1)
24
24
  end
25
25
 
26
+ # A helper method to create a placeholder animation, with a single frame of static colour in a
27
+ # chosen size.
28
+ # @param [Numeric] width
29
+ # @param [Numeric] height
30
+ # @param [Gosu::Color] colour
31
+ # @return [Animation]
32
+ def self.placeholder(width, height, colour)
33
+ image = Gosu.render(width, height) do
34
+ Gosu.draw_rect(0, 0, width, height, colour)
35
+ end
36
+ Animation.static(image)
37
+ end
38
+
26
39
  # Resets this animation to its first frame.
27
40
  def reset
28
41
  @ticks = 0
@@ -18,9 +18,17 @@ module OrangeZest
18
18
  end
19
19
 
20
20
  # Returns true if a point is inside this box.
21
+ # @return [Boolean]
21
22
  def point_inside?(point)
22
23
  point.x >= origin.x && point.x <= origin.x + width \
23
24
  && point.y >= origin.y && point.y <= origin.y + height
24
- end
25
- end
25
+ end
26
+
27
+ # Returns the point at the centre of this box.
28
+ # @return [Point]
29
+ def centre
30
+ origin + Point.new(width / 2, height / 2)
31
+ end
32
+ alias center centre
33
+ end
26
34
  end
@@ -28,5 +28,30 @@ module OrangeZest
28
28
  raise 'tried to unregister component which is not registered' unless group
29
29
  group.remove(self)
30
30
  end
31
+
32
+ # A helper method to easily instantiate a new `Component` without creating a named subclass.
33
+ # Useful for components which will be instantiated exactly once and never need to be referred
34
+ # to again.
35
+ #
36
+ # @param [#call, nil] update
37
+ # @param [#call, nil] draw
38
+ # @return [Component]
39
+ def self.anon(update: nil, draw: nil)
40
+ _update = update || ->{}
41
+ _draw = draw || ->{}
42
+
43
+ Class.new(Component) do
44
+ @@update = _update
45
+ @@draw = _draw
46
+
47
+ def update
48
+ @@update.()
49
+ end
50
+
51
+ def draw
52
+ @@draw.()
53
+ end
54
+ end.new
55
+ end
31
56
  end
32
57
  end
@@ -82,7 +82,7 @@ module OrangeZest
82
82
  # Returns a bounding box for this entity, starting at its position and spanning the size of its
83
83
  # current frame.
84
84
  def bounding_box
85
- Box.new(position, image.width, image.height)
85
+ Box.new(position, image.width * scaling, image.height * scaling)
86
86
  end
87
87
  end
88
88
  end
@@ -9,9 +9,19 @@ module OrangeZest
9
9
  @z = z
10
10
  end
11
11
 
12
+ def self.[](*args)
13
+ new(*args)
14
+ end
15
+
12
16
  def +(other)
13
- raise "can't add point to #{other}" unless other.is_a?(Point)
14
- Point.new(x + other.x, y + other.y, z + other.z)
17
+ case other
18
+ when Point
19
+ Point.new(x + other.x, y + other.y, z + other.z)
20
+ when Numeric
21
+ Point.new(x + other, y + other, z + other)
22
+ else
23
+ raise TypeError, "can't add point to #{other}"
24
+ end
15
25
  end
16
26
 
17
27
  def -@
@@ -33,11 +43,57 @@ module OrangeZest
33
43
  [x, y, z].hash
34
44
  end
35
45
 
46
+ def to_s
47
+ "#<Point: #{x}, #{y}, #{z}>"
48
+ end
49
+ alias inspect to_s
50
+
36
51
  # Computes the distance between this point and another.
37
52
  def distance(other)
38
53
  x_dist = (x - other.x)
39
54
  y_dist = (y - other.y)
40
55
  Math.sqrt(x_dist**2 + y_dist**2)
41
56
  end
57
+
58
+ # Return all points in a line from one point to another.
59
+ #
60
+ # This is a 2D operation - Z is ignored. Floating point components of either point are rounded
61
+ # to integers.
62
+ #
63
+ # @param [Point] other
64
+ # @return [<Point>]
65
+ def line_to(other)
66
+ # `supercover_line` from: https://www.redblobgames.com/grids/line-drawing.html
67
+ dx = other.x.round - self.x.round
68
+ dy = other.y.round - self.y.round
69
+ nx = dx.abs
70
+ ny = dy.abs
71
+ sign_x = dx <=> 0
72
+ sign_y = dy <=> 0
73
+
74
+ p = self.clone
75
+ points = [p.clone]
76
+
77
+ ix = 0
78
+ iy = 0
79
+ while ix < nx || iy < ny
80
+ decision = (1 + 2*ix) * ny - (1 + 2*iy) * nx
81
+ if decision == 0
82
+ p.x += sign_x
83
+ p.y += sign_y
84
+ ix += 1
85
+ iy += 1
86
+ elsif decision < 0
87
+ p.x += sign_x
88
+ ix += 1
89
+ else
90
+ p.y += sign_y
91
+ iy += 1
92
+ end
93
+ points << p.clone
94
+ end
95
+
96
+ points
97
+ end
42
98
  end
43
99
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OrangeZest
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orange_zest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Christiansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-30 00:00:00.000000000 Z
11
+ date: 2023-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu