diff options
| author | realtradam <[email protected]> | 2021-01-29 00:31:00 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-01-29 00:31:00 -0500 |
| commit | bee6e8aa782895acefc6b40b2559f4d618a9466d (patch) | |
| tree | 8d842ce28317bc23bd3bd56a0df07bd27a2e54ff /run.rb | |
| parent | 7c87aec3da8f502bc5401264fc68dcefde25caf0 (diff) | |
| download | ruby2d-camera-bee6e8aa782895acefc6b40b2559f4d618a9466d.tar.gz ruby2d-camera-bee6e8aa782895acefc6b40b2559f4d618a9466d.zip | |
small progress
Diffstat (limited to 'run.rb')
| -rw-r--r-- | run.rb | 89 |
1 files changed, 67 insertions, 22 deletions
@@ -7,9 +7,9 @@ require_relative 'animator' @background = Image.new('assets/background.png') #@player = Image.new('assets/player.png') @player = Quad.new(x1: 0, y1: 0, - x2: 20, y2: 0, - x3: 20, y3: 20, - x4: 0, y4: 20) + x2: 20, y2: 0, + x3: 20, y3: 20, + x4: 0, y4: 20) @squares = [] # Use this to add a few extra methods to an Image @@ -39,12 +39,27 @@ Camera.elasticity = 10 # If you want to use a camera, you need all elements in the world to be known to it # Exeptions would be things such as UI elements where you want them statically placed on the screen 25.times do - @squares << AnimatedSquare.new(x: (0..1920).to_a.sample, - y: (0..1080).to_a.sample, - size: (10..50).to_a.sample, - color: 'random') - Camera << @squares.last + tempx = (0..1920).to_a.sample + tempy = (0..1080).to_a.sample + tempsize = (25..100).to_a.sample + Camera << Quad.new(x1: tempx, + y1: tempy, + x2: tempx, + y2: tempy + tempsize, + x3: tempx + tempsize, + y3: tempy + tempsize, + x4: tempx + tempsize, + y4: tempy, + size: (10..50).to_a.sample, + color: 'random') end +#25.times do +# @squares << AnimatedSquare.new(x: (0..1920).to_a.sample, +# y: (0..1080).to_a.sample, +# size: (10..50).to_a.sample, +# color: 'random') +# Camera << @squares.last +#end # An example of static elements on the screen that # do not follow the camera movement @@ -99,16 +114,20 @@ Rectangle.new( on :key do |event| if event.key == 'a' - @x_move -= @speed + @y_move += Math.sin(Math::PI * (180 + @player.rotation_degrees) / 180) * @speed + @x_move += Math.cos(Math::PI * (180 + @player.rotation_degrees) / 180) * @speed end if event.key == 'd' - @x_move += @speed + @y_move += Math.sin(Math::PI * @player.rotation_degrees / 180) * @speed + @x_move += Math.cos(Math::PI * @player.rotation_degrees / 180) * @speed end if event.key == 'w' - @y_move -= @speed + @y_move += Math.sin(Math::PI * (-90 + @player.rotation_degrees) / 180) * @speed + @x_move += Math.cos(Math::PI * (-90 + @player.rotation_degrees) / 180) * @speed end if event.key == 's' - @y_move += @speed + @y_move += Math.sin(Math::PI * (90 + @player.rotation_degrees) / 180) * @speed + @x_move += Math.cos(Math::PI * (90 + @player.rotation_degrees) / 180) * @speed end if event.key == 'j' @cam_x_move -= @speed @@ -132,14 +151,36 @@ on :key do |event| end on :key do |event| + if event.key == 'z' + @zoom_by = 1.015 + end + if event.key == 'x' + @zoom_by = 0.985 + end + if event.key == 'c' + Camera.zoom_to 1 + end + if event.key == 'm' + Camera.move_to(-10,-10) + end + if event.key == 'q' - @zoom_by = 1.05 + temp_cam = Camera.camera_position + Camera.rotate_by(-1) + Camera.move_to(@player.lazy_center[0] - (Window.width / 2), + @player.lazy_center[1] - (Window.height / 2)) end if event.key == 'e' - @zoom_by = 0.95 + Camera.rotate_by(1) + Camera.move_to(@player.lazy_center[0] - (Window.width / 2), + @player.lazy_center[1] - (Window.height / 2)) end if event.key == 'r' - Camera.zoom_to 1 + unless Camera.rotation_degrees.zero? + Camera.rotate_by(-Camera.rotation_degrees) + Camera.move_to(@player.lazy_center[0] - (Window.width / 2), + @player.lazy_center[1] - (Window.height / 2)) + end end end @quad = Quad.new(x1: 0, y1: 0, @@ -148,6 +189,9 @@ end x4: 0, y4: 20) Camera << @quad @frame = 0 + @player.rotate_relative([email protected], + -12) update do @frame += 1 @frame %= 60 @@ -167,18 +211,19 @@ update do end @quad.rotate_relative(50 - @quad.x,50 - @quad.y,1) @quad.color = 'random' if @frame.zero? - puts @quad.rotation_degrees + #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 - puts Math.cos(Math::PI * @player.rotation_degrees.to_f / 180) - @player.rotate_relative(Math.cos(Math::PI * (@player.rotation_degrees + 1 * 180 / 4) / 180) * (10 * 1.41421356237), - Math.cos(Math::PI * (@player.rotation_degrees - 1 * 180 / 4) / 180) * (10 * 1.41421356237), - 2) - + puts @player.x1_debug + #Camera.rotate_by(2) + #puts Math.cos(Math::PI * @player.rotation_degrees.to_f / 180) + #@player.rotate_relative(Math.cos(Math::PI * (@player.rotation_degrees + 1 * 180 / 4) / 180) * (10 * 1.41421356237), + # Math.cos(Math::PI * (@player.rotation_degrees - 1 * 180 / 4) / 180) * (10 * 1.41421356237), + # 2) # This function will teleport the camera directory to those coordinates # It is used by Camera.follow but you can use it yourself too! #Camera.move_to(50,50) @@ -187,7 +232,7 @@ update do @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)}" - @ui_rotation.text = "Angle: #{@player.rotation_degrees.round(-1)}" + @ui_rotation.text = "Angle: #{Camera.rotation_degrees}" end show |
