diff options
| author | realtradam <[email protected]> | 2021-01-26 01:48:57 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-01-26 01:48:57 -0500 |
| commit | e66aa3520badc5b2641088ff5f9e903d13e2c98e (patch) | |
| tree | 276c398e35839788375c0227968cfb1c3029cb8f | |
| parent | f0d46fb2f12a8da8425330779863884d2bff79db (diff) | |
| download | ruby2d-camera-old-e66aa3520badc5b2641088ff5f9e903d13e2c98e.tar.gz ruby2d-camera-old-e66aa3520badc5b2641088ff5f9e903d13e2c98e.zip | |
minor tests
| -rw-r--r-- | quad_camera_tracker.rb | 5 | ||||
| -rw-r--r-- | run.rb | 27 |
2 files changed, 29 insertions, 3 deletions
diff --git a/quad_camera_tracker.rb b/quad_camera_tracker.rb index 16473b8..25c6071 100644 --- a/quad_camera_tracker.rb +++ b/quad_camera_tracker.rb @@ -35,6 +35,7 @@ module QuadCameraTracker def height [@y1, @y2, @y3, @y4].max - [@y1, @y2, @y3, @y4].min end + def x @x ||= @x1 / Camera.zoom_level + Camera.camera_position[0] end @@ -75,6 +76,8 @@ module QuadCameraTracker # undo rotation/translation/zoom end + # Should modify the x1 methods so they move everything else isntead + # this is so that x1 is always the "origin" aka 0,0 of the shape def x1=(x1) @x1 = ((x1 + x) - Camera.camera_position[0]) * Camera.zoom_level # add rotation level @@ -177,6 +180,7 @@ module QuadCameraTracker x_shifted4 = self.x4 - x_pivot y_shifted4 = self.y4 - y_pivot + # Used to update x and y later in the code x1_old = self.x1 y1_old = self.y1 @@ -192,6 +196,7 @@ module QuadCameraTracker self.x4 = x_pivot + (x_shifted4 * Math.cos(@angle) - y_shifted4 * Math.sin(@angle)) self.y4 = y_pivot + (x_shifted4 * Math.sin(@angle) + y_shifted4 * Math.cos(@angle)) + # Updates x and y to be on the origin correctly @x += -x1_old + self.x1 @y += -y1_old + self.y1 end @@ -50,7 +50,7 @@ end # do not follow the camera movement Rectangle.new( width: 350, - height: 70, + height: 105, color: 'navy' ) @ui_pos = Text.new( @@ -65,6 +65,25 @@ Rectangle.new( y: 40, color: 'lime' ) +@ui_rotation = Text.new( + 'rotation: 0', + x: 10, + y: 70, + color: 'lime' +) +Rectangle.new( + x: (Window.width - 120), + width: 120, + height: 45, + color: 'navy' +) +@ui_fps = Text.new( + 'fps: 60.00', + x: (Window.width - 110), + y: 10, + color: 'teal' +) + # How fast the player can move @@ -146,15 +165,16 @@ update do @squares.each do |square| square.update(Camera.camera_position, Camera.zoom_level) end - @quad.rotate(50 - @quad.x,50 - @quad.y,5) + @quad.rotate(50 - @quad.x,50 - @quad.y,30) if @frame.zero? @quad.color = 'random' if @frame.zero? + puts @quad.rotation_degrees # Alternating between follow and manual control if @is_follow Camera.follow @player else Camera.move_by(@cam_x_move, @cam_y_move) end - @player.rotate(@player.x1, @player.y1, 5) + @player.rotate(0, 0, 5) # This function will teleport the camera directory to those coordinates # It is used by Camera.follow but you can use it yourself too! @@ -163,6 +183,7 @@ update do @cam_y_move = 0 @ui_pos.text = "Camera Position: #{Camera.camera_position[0].round(1)}, #{Camera.camera_position[1].round(1)}" @ui_zoom.text = "Zoom: #{Camera.zoom_level.round(3)}" + @ui_fps.text = "FPS: #{Window.fps.round(2)}" end show |
