diff options
| author | tradam <git.tradam.fyi> | 2021-09-27 08:39:23 -0400 |
|---|---|---|
| committer | tradam <git.tradam.fyi> | 2021-09-27 08:39:23 -0400 |
| commit | 5f46f1f975bd621fbca9c7e173de78e83ad70e3a (patch) | |
| tree | eed828b369247c3d081ae1b3573bdb5119ff96a4 /example | |
| parent | c326eb2b27921f584ac46c484dab9be2cddb90f7 (diff) | |
| download | ruby2d-camera-5f46f1f975bd621fbca9c7e173de78e83ad70e3a.tar.gz ruby2d-camera-5f46f1f975bd621fbca9c7e173de78e83ad70e3a.zip | |
partially complete fixing code, found a strange bug with ruby2d
Diffstat (limited to 'example')
| -rw-r--r-- | example/old_example/README.mdown (renamed from example/README.mdown) | 0 | ||||
| -rw-r--r-- | example/old_example/assets/background.png (renamed from example/assets/background.png) | bin | 60142 -> 60142 bytes | |||
| -rw-r--r-- | example/old_example/assets/blobcoolthink.png (renamed from example/assets/blobcoolthink.png) | bin | 13066 -> 13066 bytes | |||
| -rw-r--r-- | example/old_example/assets/blobshadow.png (renamed from example/assets/blobshadow.png) | bin | 5679 -> 5679 bytes | |||
| -rw-r--r-- | example/old_example/assets/bricktexture.png (renamed from example/assets/bricktexture.png) | bin | 741798 -> 741798 bytes | |||
| -rw-r--r-- | example/old_example/assets/legacy_player.png (renamed from example/assets/legacy_player.png) | bin | 1044 -> 1044 bytes | |||
| -rw-r--r-- | example/old_example/assets/sprites/alienpls-56.png (renamed from example/assets/sprites/alienpls-56.png) | bin | 255710 -> 255710 bytes | |||
| -rw-r--r-- | example/old_example/assets/sprites/blobdance-128.png (renamed from example/assets/sprites/blobdance-128.png) | bin | 35825 -> 35825 bytes | |||
| -rw-r--r-- | example/old_example/assets/sprites/dance2-112.png (renamed from example/assets/sprites/dance2-112.png) | bin | 214857 -> 214857 bytes | |||
| -rw-r--r-- | example/old_example/assets/sprites/dancer-128.png (renamed from example/assets/sprites/dancer-128.png) | bin | 39270 -> 39270 bytes | |||
| -rw-r--r-- | example/old_example/assets/sprites/mainblob-128.png (renamed from example/assets/sprites/mainblob-128.png) | bin | 94731 -> 94731 bytes | |||
| -rw-r--r-- | example/old_example/house.rb (renamed from example/house.rb) | 0 | ||||
| -rw-r--r-- | example/old_example/room.rb (renamed from example/room.rb) | 0 | ||||
| -rw-r--r-- | example/old_example/run.rb (renamed from example/run.rb) | 2 | ||||
| -rw-r--r-- | example/test/assets/alienpls-56.png | bin | 0 -> 255710 bytes | |||
| -rw-r--r-- | example/test/assets/bricktexture-600.png | bin | 0 -> 741798 bytes | |||
| -rw-r--r-- | example/test/run.rb | 378 |
17 files changed, 379 insertions, 1 deletions
diff --git a/example/README.mdown b/example/old_example/README.mdown index 186f6e3..186f6e3 100644 --- a/example/README.mdown +++ b/example/old_example/README.mdown diff --git a/example/assets/background.png b/example/old_example/assets/background.png Binary files differindex f411e96..f411e96 100644 --- a/example/assets/background.png +++ b/example/old_example/assets/background.png diff --git a/example/assets/blobcoolthink.png b/example/old_example/assets/blobcoolthink.png Binary files differindex 7cdfcc8..7cdfcc8 100644 --- a/example/assets/blobcoolthink.png +++ b/example/old_example/assets/blobcoolthink.png diff --git a/example/assets/blobshadow.png b/example/old_example/assets/blobshadow.png Binary files differindex ff981cb..ff981cb 100644 --- a/example/assets/blobshadow.png +++ b/example/old_example/assets/blobshadow.png diff --git a/example/assets/bricktexture.png b/example/old_example/assets/bricktexture.png Binary files differindex 4ef86e0..4ef86e0 100644 --- a/example/assets/bricktexture.png +++ b/example/old_example/assets/bricktexture.png diff --git a/example/assets/legacy_player.png b/example/old_example/assets/legacy_player.png Binary files differindex 485e972..485e972 100644 --- a/example/assets/legacy_player.png +++ b/example/old_example/assets/legacy_player.png diff --git a/example/assets/sprites/alienpls-56.png b/example/old_example/assets/sprites/alienpls-56.png Binary files differindex af9452a..af9452a 100644 --- a/example/assets/sprites/alienpls-56.png +++ b/example/old_example/assets/sprites/alienpls-56.png diff --git a/example/assets/sprites/blobdance-128.png b/example/old_example/assets/sprites/blobdance-128.png Binary files differindex 6326ec0..6326ec0 100644 --- a/example/assets/sprites/blobdance-128.png +++ b/example/old_example/assets/sprites/blobdance-128.png diff --git a/example/assets/sprites/dance2-112.png b/example/old_example/assets/sprites/dance2-112.png Binary files differindex 2d69026..2d69026 100644 --- a/example/assets/sprites/dance2-112.png +++ b/example/old_example/assets/sprites/dance2-112.png diff --git a/example/assets/sprites/dancer-128.png b/example/old_example/assets/sprites/dancer-128.png Binary files differindex c3fdbc0..c3fdbc0 100644 --- a/example/assets/sprites/dancer-128.png +++ b/example/old_example/assets/sprites/dancer-128.png diff --git a/example/assets/sprites/mainblob-128.png b/example/old_example/assets/sprites/mainblob-128.png Binary files differindex ca78578..ca78578 100644 --- a/example/assets/sprites/mainblob-128.png +++ b/example/old_example/assets/sprites/mainblob-128.png diff --git a/example/house.rb b/example/old_example/house.rb index c6257ee..c6257ee 100644 --- a/example/house.rb +++ b/example/old_example/house.rb diff --git a/example/room.rb b/example/old_example/room.rb index 27c002d..27c002d 100644 --- a/example/room.rb +++ b/example/old_example/room.rb diff --git a/example/run.rb b/example/old_example/run.rb index 96ab9ab..2790f40 100644 --- a/example/run.rb +++ b/example/old_example/run.rb @@ -110,7 +110,7 @@ on :key do |event| 1 end elsif Camera.angle += if Camera.angle < 350 - 10 + 10 else 1 end diff --git a/example/test/assets/alienpls-56.png b/example/test/assets/alienpls-56.png Binary files differnew file mode 100644 index 0000000..af9452a --- /dev/null +++ b/example/test/assets/alienpls-56.png diff --git a/example/test/assets/bricktexture-600.png b/example/test/assets/bricktexture-600.png Binary files differnew file mode 100644 index 0000000..4ef86e0 --- /dev/null +++ b/example/test/assets/bricktexture-600.png diff --git a/example/test/run.rb b/example/test/run.rb new file mode 100644 index 0000000..14e9d5c --- /dev/null +++ b/example/test/run.rb @@ -0,0 +1,378 @@ +require 'ruby2d' +require 'ruby2d/camera' + +Window.set(width: 640, + height: 480) + +# ----- UI ----- +#Rectangle.new( +# width: 350, +# height: 135, +# color: 'navy', +# z: 100 +#) +@ui_pos_cam = Text.new( + 'pos: 0,0', + x: 10, + y: 10, + color: 'teal', + z: 101 +) +#@ui_pos_ply = Text.new( +# 'pos: 0,0', +# x: 10, +# y: 40, +# color: 'teal', +# z: 101 +#) +@ui_zoom = Text.new( + 'zoom: 0', + x: 10, + y: 35, + color: 'lime', + z: 101 +) +@ui_rotation = Text.new( + 'rotation: 0', + x: 10, + y: 60, + color: 'lime', + z: 101 +) +#Rectangle.new( +# x: (Window.width - 120), +# width: 80, +# height: 45, +# color: 'navy', +# opacity: 0.3, +# z: 100 +#) +@ui_fps = Text.new( + 'fps: 60.00', + x: (Window.width - 110), + y: 10, + color: 'teal', + z: 101 +) +@dancing_alien1 = Camera::Sprite.new('./assets/alienpls-56.png', + x: 520 + -28, + y: -28, + width: 56, + height: 56, + clip_width: 56, + loop: true, + time: 35, + z: 1) +@dancing_alien1.play +@dancing_alien2 = Camera::Sprite.new('./assets/alienpls-56.png', + x: -28, + y: 370 + -28, + width: 56, + height: 56, + clip_width: 56, + loop: true, + time: 35, + z: 1) +@dancing_alien2.play +@dancing_alien3 = Camera::Sprite.new('./assets/alienpls-56.png', + x: -520 + -28, + y: -28, + width: 56, + height: 56, + clip_width: 56, + loop: true, + time: 35, + z: 1) +@dancing_alien3.play +@dancing_alien4 = Camera::Sprite.new('./assets/alienpls-56.png', + x: -28, + y: -370 + -28, + width: 56, + height: 56, + clip_width: 56, + loop: true, + time: 35, + z: 1) +@dancing_alien4.play + +@caution_topleft = [] +@caution_topright = [] +@caution_botleft = [] +@caution_botright = [] + +@caution_topleft.push Camera::Triangle.new(color: 'yellow', + x1: -280, y1: -200, + x2: -260, y2: -220, + x3: -300, y3: -220 + ) +@caution_topleft.push Camera::Triangle.new(color: 'gray', + x1: -280, y1: -200, + x2: -300, y2: -180, + x3: -300, y3: -220 + ) +@caution_topleft.push Camera::Quad.new(color: 'yellow', + x1: -280, y1: -200, + x2: -300, y2: -180, + x3: -300, y3: -160, + x4: -280, y4: -180 + ) +@caution_topleft.push Camera::Quad.new(color: 'gray', + x1: -280, y1: -160, + x2: -300, y2: -140, + x3: -300, y3: -160, + x4: -280, y4: -180 + ) +@caution_topleft.push Camera::Quad.new(color: 'gray', + x1: -280, y1: -200, + x2: -260, y2: -220, + x3: -240, y3: -220, + x4: -260, y4: -200 + ) +@caution_topleft.push Camera::Quad.new(color: 'yellow', + x1: -240, y1: -200, + x2: -220, y2: -220, + x3: -240, y3: -220, + x4: -260, y4: -200 + ) + +@caution_topright.push Camera::Triangle.new(color: 'yellow', + x1: 280, y1: -200, + x2: 260, y2: -220, + x3: 300, y3: -220 + ) +@caution_topright.push Camera::Triangle.new(color: 'gray', + x1: 280, y1: -200, + x2: 300, y2: -180, + x3: 300, y3: -220 + ) +@caution_topright.push Camera::Quad.new(color: 'yellow', + x1: 280, y1: -200, + x2: 300, y2: -180, + x3: 300, y3: -160, + x4: 280, y4: -180 + ) +@caution_topright.push Camera::Quad.new(color: 'gray', + x1: 280, y1: -160, + x2: 300, y2: -140, + x3: 300, y3: -160, + x4: 280, y4: -180 + ) +@caution_topright.push Camera::Quad.new(color: 'gray', + x1: 280, y1: -200, + x2: 260, y2: -220, + x3: 240, y3: -220, + x4: 260, y4: -200 + ) +@caution_topright.push Camera::Quad.new(color: 'yellow', + x1: 240, y1: -200, + x2: 220, y2: -220, + x3: 240, y3: -220, + x4: 260, y4: -200 + ) + +@caution_botleft.push Camera::Triangle.new(color: 'yellow', + x1: -280, y1: 200, + x2: -260, y2: 220, + x3: -300, y3: 220 + ) +@caution_botleft.push Camera::Triangle.new(color: 'gray', + x1: -280, y1: 200, + x2: -300, y2: 180, + x3: -300, y3: 220 + ) +@caution_botleft.push Camera::Quad.new(color: 'yellow', + x1: -280, y1: 200, + x2: -300, y2: 180, + x3: -300, y3: 160, + x4: -280, y4: 180 + ) +@caution_botleft.push Camera::Quad.new(color: 'gray', + x1: -280, y1: 160, + x2: -300, y2: 140, + x3: -300, y3: 160, + x4: -280, y4: 180 + ) +@caution_botleft.push Camera::Quad.new(color: 'gray', + x1: -280, y1: 200, + x2: -260, y2: 220, + x3: -240, y3: 220, + x4: -260, y4: 200 + ) +@caution_botleft.push Camera::Quad.new(color: 'yellow', + x1: -240, y1: 200, + x2: -220, y2: 220, + x3: -240, y3: 220, + x4: -260, y4: 200 + ) + +@caution_botright.push Camera::Triangle.new(color: 'yellow', + x1: 280, y1: 200, + x2: 260, y2: 220, + x3: 300, y3: 220 + ) +@caution_botright.push Camera::Triangle.new(color: 'gray', + x1: 280, y1: 200, + x2: 300, y2: 180, + x3: 300, y3: 220 + ) +@caution_botright.push Camera::Quad.new(color: 'yellow', + x1: 280, y1: 200, + x2: 300, y2: 180, + x3: 300, y3: 160, + x4: 280, y4: 180 + ) +@caution_botright.push Camera::Quad.new(color: 'gray', + x1: 280, y1: 160, + x2: 300, y2: 140, + x3: 300, y3: 160, + x4: 280, y4: 180 + ) +@caution_botright.push Camera::Quad.new(color: 'gray', + x1: 280, y1: 200, + x2: 260, y2: 220, + x3: 240, y3: 220, + x4: 260, y4: 200 + ) +@caution_botright.push Camera::Quad.new(color: 'yellow', + x1: 240, y1: 200, + x2: 220, y2: 220, + x3: 240, y3: 220, + x4: 260, y4: 200 + ) + +@text = Camera::Text.new("Bigger circles should always be in front of smaller ones", + size: 30, + x: 0, y: 65) [email protected] = true + +@zindex_test = [] + +@zindex_test.push Camera::Circle.new(color: 'random', + x: 50 + -25, y: -25, + radius: 25) +@zindex_test.push Camera::Circle.new(color: 'random', + x: 25 + -25, y: -25, + radius: 25) +@zindex_test.push Camera::Circle.new(color: 'random', + x: 0 + -25, y: -25, + radius: 25) +@zindex_test.push Camera::Circle.new(color: 'random', + x: -25 + -25, y: -25, + radius: 25) +@zindex_test.push Camera::Circle.new(color: 'random', + x: -50 + -25, y: -25, + radius: 25) + +@speed = 5 +@one_degree_in_radians = 0.01745329 + +on :key do |event| + Camera.y -= (Math.cos(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'w' + Camera.y += (Math.cos(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 's' + Camera.x -= (Math.sin(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'w' + Camera.x += (Math.sin(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 's' + + Camera.x += (Math.cos(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'd' + Camera.x -= (Math.cos(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'a' + Camera.y -= (Math.sin(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'd' + Camera.y += (Math.sin(Camera.angle * @one_degree_in_radians) * @speed) if event.key == 'a' + + #@pressed_space = true if event.key == 'space' && !(@scene_transition_into || @scene_transition_out) + Camera.angle += 1.5 if event.key == 'q' + Camera.angle -= 1.5 if event.key == 'e' + Camera.zoom *= 1.01 if event.key == 'z' + Camera.zoom *= 0.99 if event.key == 'x' + if event.key == 'r'# && !(@scene_transition_into || @scene_transition_out || Camera.angle.zero?) + if Camera.zoom < 1.0 + Camera.zoom *= 1.03 + if Camera.zoom > 1.0 + Camera.zoom = 1.0 + end + elsif Camera.zoom > 1.0 + Camera.zoom /= 1.03 + if Camera.zoom < 1.0 + Camera.zoom = 1.0 + end + end + if Camera.angle <= 180 + Camera.angle -= if Camera.angle > 10 + 10 + elsif Camera.angle != 0 + 1 + else + 0 + end + elsif Camera.angle += if Camera.angle < 350 + 10 + elsif Camera.angle != 0 + 1 + else + 0 + end + if (Camera.angle > 359) || (Camera.angle < 1) + Camera.angle = 0 + end + end + end +end + +@frame = 0 +update do + @frame += 1 + + @a = (Math.sin(((@frame - 30) % 120) * (Math::PI / 60.0)) * 15 + 25) + @b = (Math.sin(((@frame - 15) % 120) * (Math::PI / 60.0)) * 15 + 25) + @c = (Math.sin((@frame % 120) * (Math::PI / 60.0)) * 15 + 25) + @d = (Math.sin(((@frame + 15) % 120) * (Math::PI / 60.0)) * 15 + 25) + @e = (Math.sin(((@frame + 30) % 120) * (Math::PI / 60.0)) * 15 + 25) + @zindex_test[0].z = @a + @zindex_test[0].radius = @a + @zindex_test[0].x = 50 + -@a + @zindex_test[0].y = -@a + @zindex_test[1].z = @b + @zindex_test[1].radius = @b + @zindex_test[1].x = 25 + -@b + @zindex_test[1].y = -@b + @zindex_test[2].z = @c + @zindex_test[2].radius = @c + @zindex_test[2].x = -@c + @zindex_test[2].y = -@c + @zindex_test[3].z = @d + @zindex_test[3].radius = @d + @zindex_test[3].x = -25 + -@d + @zindex_test[3].y = -@d + @zindex_test[4].z = @e + @zindex_test[4].radius = @e + @zindex_test[4].x = -50 + -@e + @zindex_test[4].y = -@e + + if (@frame % 120) < 30 + @dancing_alien1.add + @dancing_alien2.remove + @dancing_alien3.remove + @dancing_alien4.remove + elsif ((@frame + 30) % 120) < 30 + @dancing_alien1.remove + @dancing_alien2.add + @dancing_alien3.remove + @dancing_alien4.remove + elsif ((@frame + 60) % 120) < 30 + @dancing_alien1.remove + @dancing_alien2.remove + @dancing_alien3.add + @dancing_alien4.remove + elsif ((@frame + 90) % 120) < 30 + @dancing_alien1.remove + @dancing_alien2.remove + @dancing_alien3.remove + @dancing_alien4.add + end + + @ui_pos_cam.text = "Camera Position: #{Camera.x.round(1)}, #{Camera.y.round(1)}" + #@ui_pos_ply.text = "Player Position: #{@player.x.round(1)}, #{@player.y.round(1)}" + @ui_zoom.text = "Zoom: #{Camera.zoom.round(3)}" + @ui_fps.text = "FPS: #{Window.fps.round(2)}" + @ui_rotation.text = "Angle: #{Camera.angle}" +end + +show |
