ruby2d-camera 1.0.0 → 1.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: fb4d1852c5d26e98334d2d1dff3f480c0ee51b0f3a0e0acfcd55f21bbb494d9b
4
- data.tar.gz: c4829a8ece2fcc5b342e82ea1b21e4af317e59691a376ec61724a52ee233cfd2
3
+ metadata.gz: 06037a9f51eba2e45da347b87365f4a58a62aa5c08408aab3a782cdcf377bb77
4
+ data.tar.gz: 692821b9a6bbc5a1635d480abd8260359bd8cc5df8bb6dd534235b62c3892ab4
5
5
  SHA512:
6
- metadata.gz: ef598ebfb03a65bb732ffd2c257ff8e685f44f5838b92c2d866d0492a678b66c39649caf9703262669f7bdef7d514492bada4de1d146ebb84b310a90abd4b109
7
- data.tar.gz: 5c65aab04d7c23de753f603114bd96e9352e8bf6fbe9f26fd37d5346d111322c6fd08b31a736aa1a0ceff414941b1068fe1a7a6aaf55e0ea9205376bff42d324
6
+ metadata.gz: a36731f90ce30ac654a70e047d978c9db839e642d4d0b13a17d6c33b2d92c296dd4e4627f64777c2beaf48ade923d742e931e8b90c353abdc8d0480e8fa18cf2
7
+ data.tar.gz: 867f0ddcc5147a7e58abf89f600c3dd7e5a38d2b0829d63ac6527b24f0a4cfc3c047082a200887db3164cc4d562d1bb9201b90c5c7a733ec1f214dbc61618221
data/CHANGELOG.mdown CHANGED
@@ -6,6 +6,10 @@
6
6
  ![Deprecated](https://img.shields.io/badge/-Deprecated-orange)
7
7
  ![Removed](https://img.shields.io/badge/-Removed-red)
8
8
 
9
+ ## [1.1.0](https://github.com/realtradam/ruby2d-camera/releases/tag/1.1.0) - 2021-08-09
10
+ ![Added](https://img.shields.io/badge/-Added-brightgreen)
11
+ - Added Camera functions `Camera.coordinate_to_screenspace` and `Camera.coordinate_to_worldspace`
12
+
9
13
  ## [1.0.0](https://github.com/realtradam/ruby2d-camera/releases/tag/1.0.0) - 2021-08-08
10
14
  ![Added](https://img.shields.io/badge/-Added-brightgreen)
11
15
  - Initial release
data/README.mdown CHANGED
@@ -19,6 +19,11 @@ Create your object as if you would create it in Ruby2D except you need to prefix
19
19
  - `Camera.x` and `Camera.y` Default: 0. This is the position the camera is centered on in the "world"
20
20
  - `Camera.angle` Default: 0. This is the angle of how much the camera is rotated(in degrees). It ranges from 0-360. Giving values outside of this range will automagically convert them to fit within the 0-360 range.
21
21
 
22
+ ### There are also 2 helpful functions:
23
+
24
+ - `Camera.coordinate_to_worldspace(x,y)` You pass coordinates on the screen(for example where a player clicked in the window) and it will return the coordinates(in a 2d array) what the coordinates are in the world
25
+ - `Camera.coordinate_to_screenspace(x,y)` You pass in a coordinate in the world(for example an enemy in your game) and it will give you the coordinates(in a 2d array) of where on the screen this character appears. Note this function may return values that are outside of the screen if the object is not in view of the camera
26
+
22
27
  ## How it works:
23
28
 
24
29
  A single `Camera` module exists which keeps track of objects created with it. When you create an object with the camera it creates a special object that inherits the original object from Ruby2D and then adds additional functions. The Camera module then uses these functions to draw the various objects on the screen each frame, using the parameters you gave it.
data/lib/ruby2d/camera.rb CHANGED
@@ -94,6 +94,23 @@ module Ruby2D
94
94
  angle %= 360
95
95
  @angle = angle
96
96
  end
97
+
98
+ # Convert screenspace coordinates into worldspace camera ones
99
+ def self.coordinate_to_worldspace(x, y)
100
+ angle = Camera.angle * (Math::PI / 180)
101
+ half_width = Window.width * 0.5
102
+ half_height = Window.height * 0.5
103
+
104
+ [(((x - half_width) / zoom) * Math.cos(-angle)) - (((y - half_height) / zoom) * Math.sin(-angle)) + self.x,
105
+ (((x - half_width) / zoom) * Math.sin(-angle)) + (((y - half_height) / zoom) * Math.cos(-angle)) + self.y]
106
+ end
107
+
108
+ # Convert worldspace camera coordinates into screenspace ones
109
+ def self.coordinate_to_screenspace(x, y)
110
+ angle = Camera.angle * (Math::PI / 180)
111
+ [(((x - Camera.x) * Math.cos(angle)) - ((y - Camera.y) * Math.sin(angle))) * Camera.zoom + (Window.width * 0.5),
112
+ (((x - Camera.x) * Math.sin(angle)) + ((y - Camera.y) * Math.cos(angle))) * Camera.zoom + (Window.height * 0.5)]
113
+ end
97
114
  end
98
115
  end
99
116
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ruby2d
4
4
  module Camera
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby2d-camera
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tradam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-08 00:00:00.000000000 Z
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby2d