From fe722a5982d6625ee58a164d8cfa576755d21aff Mon Sep 17 00:00:00 2001 From: realtradam Date: Sun, 8 Aug 2021 04:25:31 -0400 Subject: release --- README.md | 32 ----- README.mdown | 39 +++++++ assets/ruby2d-camera.png | Bin 0 -> 14837 bytes assets/ruby2d-camera.svg | 295 +++++++++++++++++++++++++++++++++++++++++++++++ ruby2d-camera.gemspec | 2 +- 5 files changed, 335 insertions(+), 33 deletions(-) delete mode 100644 README.md create mode 100644 README.mdown create mode 100644 assets/ruby2d-camera.png create mode 100644 assets/ruby2d-camera.svg diff --git a/README.md b/README.md deleted file mode 100644 index 359be3f..0000000 --- a/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# Ruby2D Camera Demo - -`ruby run.rb` to run the demo. - -## Controls: - -WASD to move character -Q/E to rotate camera -Hold R to reset the rotation -Space to enter doors - -## How it works: - -A single `Camera` module exists which keeps track of objects that you add to it. When you add an object to the camera it creates a wrapper for the object and 'monkey patches' it onto the object to work with the camera. - -Feel free to use any part of this code in your own projects, no credit required(but is appreciated [^; ) - -## How to use the camera in your own code: - -Copy the `lib/camera/` directory into your ruby project and then in your code simply ```require_relative 'camera/camera'``` at the top. In your `Update do` loop you must add ```Camera.redraw``` at the bottom(this is so that the camera applies any changes you tell it to do). Your camera is now ready to use! - -To add an object to the camera simply do ```Camera << @your_object``` and the camera will do its magic on your object. Only the various shape/image/text/line/sprite/etc. from Ruby2D are supported. -Whenever an object is wrapped by the camera it gets `x` and `y` methods if it does not already have them which you can use to move the object around in the camera. The text object also gets a `center` method which you can set to true if you wish the origin of text to be its center. Otherwise the origin of all objects is the top left corner. Other then these methods mentioned, object and their methods behave as expected within the context of the camera. - -When unloading an object, make sure to also remove it from the Camera or else it will attempt to update it when it is Nil. To do this use the following: `Camera.remove(@your_object)` - -To manipulate the camera there are 4 variables you can use: - -- `Camera.zoom` Default: 1. This is a multiplier for how much you want the camera to be zoomed in(e.g 2 is 2x zoom, 0.5 is 0.5x zoom) -- `Camera.x` and `Camera.y` Default: 0. This are the position of the camera in the "world" -- `Camera.angle` Default: 0. This is the angle of how much the camera is rotated(in degrees). It ranges from 0-359. Giving values outside of this range will automagically convert them to fit within the 0-359 range. - diff --git a/README.mdown b/README.mdown new file mode 100644 index 0000000..2a2e865 --- /dev/null +++ b/README.mdown @@ -0,0 +1,39 @@ +![ruby2d-camera logo](https://naked.catgirls.rodeo/images/ruby2d-camera.png) + +[![MIT License](https://img.shields.io/github/license/realtradam/FelFlame?label=license&style=flat)](https://github.com/realtradam/FelFlame/blob/master/LICENSE) +[![Ko-Fi](https://img.shields.io/static/v1?message=Buy%20me%20a%20coffee&logo=kofi&labelColor=ff5e5b&color=434B57&logoColor=white&label=%20)](https://ko-fi.com/tradam) + +# Ruby2D Camera Gem + +With this gem you can easily add camera functionality into your games built with Ruby2D. Install it using `gem install ruby2d-camera` and then add it into your project with `require ruby2d/camera` at the top of your code, just below the line `require ruby2d`. + +`ruby run.rb` to run the demo. + +## How to use the camera: + +Create your object as if you would create it in Ruby2D except you need to prefix it with `Camera::`. For example to create a square you do `Camera::Square.new`. Any objects you create this way can be controlled and manipulated the same way that you control and manipulate them in Ruby2D with a few small additions. Any objects that do not have an x/y variable to move it now do have this, so that you may move the objects in the camera. Text objects also have a boolean that you can change named `center` which allows you to set the origin to be the horizontal center of the text rather then the edge. + +### To manipulate the camera there are 4 variables: + +- `Camera.zoom` Default: 1. This is a multiplier for how much you want the camera to be zoomed in(e.g 2 is 2x zoom, 0.5 is 0.5x zoom) +- `Camera.x` and `Camera.y` Default: 0. This is the position the camera is centered on in the "world" +- `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. + +## How it works: + +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. + +## Demo: + +Under the `example` directory you can find a (poorly coded) demo using this gem. Simply `ruby run.rb` in the example directory to start the demo. + +### Controls: + +WASD to move character +Q/E to rotate camera +Hold R to reset the rotation +Space to enter doors + +## Known Issues: + +Unfortunately text cannot be resized due to current limitations of Ruby2D, this will fixed when possible. This means zooming with text will look strange, centering the text somewhat alleviates this issue. diff --git a/assets/ruby2d-camera.png b/assets/ruby2d-camera.png new file mode 100644 index 0000000..f2894ce Binary files /dev/null and b/assets/ruby2d-camera.png differ diff --git a/assets/ruby2d-camera.svg b/assets/ruby2d-camera.svg new file mode 100644 index 0000000..cac09d6 --- /dev/null +++ b/assets/ruby2d-camera.svg @@ -0,0 +1,295 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruby2d-camera.gemspec b/ruby2d-camera.gemspec index 507e8c0..e8146fa 100644 --- a/ruby2d-camera.gemspec +++ b/ruby2d-camera.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|assets|example)/}) } end spec.bindir = "exe" spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } -- cgit v1.2.3