diff options
| author | _Tradam <[email protected]> | 2021-12-18 22:51:31 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-18 22:51:31 -0500 |
| commit | 55abb3c7534e57f8da270a7e77b16f3f06ca3712 (patch) | |
| tree | b40824f6d6588ebd5d7db2e7bfa6312d117ee419 /app | |
| parent | 43a07949acca8a11a3aee6ea915a9a3e00b373ab (diff) | |
| parent | 32a5e203e092dc22e7d1a34641b10692abe14702 (diff) | |
| download | SteelWings-55abb3c7534e57f8da270a7e77b16f3f06ca3712.tar.gz SteelWings-55abb3c7534e57f8da270a7e77b16f3f06ca3712.zip | |
Merge branch 'master' into menu-dev
Diffstat (limited to 'app')
| -rw-r--r-- | app/components/boid.rb | 9 | ||||
| -rw-r--r-- | app/components/camera.rb | 5 | ||||
| -rw-r--r-- | app/main.rb | 2 | ||||
| -rw-r--r-- | app/systems/camera.rb | 29 | ||||
| -rw-r--r-- | app/systems/debug/debug_render_vector_arrow.rb | 75 | ||||
| -rw-r--r-- | app/systems/update_boid_sprite.rb | 10 | ||||
| -rw-r--r-- | app/tick.rb | 75 |
7 files changed, 146 insertions, 59 deletions
diff --git a/app/components/boid.rb b/app/components/boid.rb index 060f9c3..3358559 100644 --- a/app/components/boid.rb +++ b/app/components/boid.rb @@ -1,5 +1,6 @@ FF::Cmp.new('Boid', - x: 0, y: 0, - vx: 0, vy: 0, - cx: 0, cy: 0, - angle: 0) + x: 0, y: 0, # position + vx: 0, vy: 0, # velocity + cx: 0, cy: 0, # change in velocity + w: 0, h: 0, # width and height + angle: 0) # angle of velocity diff --git a/app/components/camera.rb b/app/components/camera.rb new file mode 100644 index 0000000..dc61bae --- /dev/null +++ b/app/components/camera.rb @@ -0,0 +1,5 @@ +FF::Cmp.new('SingletonCamera', + :x, :y, + :zoom, :angle) + +FF::Cmp::SingletonCamera.new(x: 0.0, y: 0.0, zoom: 1.0, angle: 0.0) diff --git a/app/main.rb b/app/main.rb index 9a55c97..5c4797e 100644 --- a/app/main.rb +++ b/app/main.rb @@ -11,6 +11,7 @@ require 'app/components/rules/cohesion.rb' require 'app/components/rules/alignment.rb' require 'app/components/rules/separation.rb' require 'app/components/debug/debug_vector_arrow.rb' +require 'app/components/camera.rb' require 'app/systems/init_title_screen.rb' require 'app/systems/title_screen.rb' @@ -24,5 +25,6 @@ require 'app/systems/rules/alignment.rb' require 'app/systems/rules/separation.rb' require 'app/systems/rules/reset_change_vector.rb' require 'app/systems/debug/debug_render_vector_arrow.rb' +require 'app/systems/camera.rb' require 'app/tick.rb' diff --git a/app/systems/camera.rb b/app/systems/camera.rb new file mode 100644 index 0000000..db6e3fc --- /dev/null +++ b/app/systems/camera.rb @@ -0,0 +1,29 @@ +FF::Scn::Render.add( + # Update the position of the sprite according + # to camera values before the sprite is rendered + FF::Sys.new('Camera', priority: 97) do + camera = FF::Cmp::SingletonCamera[0] + camera.entities.each do |ent| + sprite = ent.components[FF::Cmp::Sprite][0].props + + angle = camera.angle * (Math::PI / 180) + half_width = $gtk.args.grid.w * 0.5 + half_height = $gtk.args.grid.h * 0.5 + offset_x = sprite[:x] + (sprite[:w] / 2) + offset_y = sprite[:y] + (sprite[:h] / 2) + temp_x = (((offset_x - camera.x) * Math.cos(angle)) - ((offset_y - camera.y) * Math.sin(angle))) \ + * camera.zoom + half_width - (sprite[:w] * camera.zoom / 2) + temp_y = (((offset_x - camera.x) * Math.sin(angle)) + ((offset_y - camera.y) * Math.cos(angle))) \ + * camera.zoom + half_height - (sprite[:h] * camera.zoom / 2) + temp_rotate = sprite[:angle] + camera.angle + temp_width = sprite[:w] * camera.zoom + temp_height = sprite[:h] * camera.zoom + + sprite[:x] = temp_x + sprite[:y] = temp_y + sprite[:w] = temp_width + sprite[:h] = temp_height + sprite[:angle] = temp_rotate + end + end +) diff --git a/app/systems/debug/debug_render_vector_arrow.rb b/app/systems/debug/debug_render_vector_arrow.rb index ebd7080..ae53d1c 100644 --- a/app/systems/debug/debug_render_vector_arrow.rb +++ b/app/systems/debug/debug_render_vector_arrow.rb @@ -1,35 +1,74 @@ FF::Sys.new('DebugRenderVectorArrow', priority: 100) do FF::Cmp::DebugVectorArrow[0].entities.each do |entity| boid = entity.components[FF::Cmp::Boid][0] + sprite = entity.components[FF::Cmp::Sprite][0] length = FF::Cmp::DebugVectorArrow[0].length #puts "vx: #{boid.vx}" #puts "cx: #{boid.cx}" - vxtip = boid.x + (boid.vx * length) - vytip = boid.y + (boid.vy * length) + boid_x = 0 + boid_y = 0 + boid_cx = 0 + boid_cy = 0 + boid_vx = 0 + boid_vy = 0 + vxtip = 0 + vytip = 0 + small_square = 15 + big_square = 25 + if !entity.components[FF::Cmp::SingletonCamera].nil? && !entity.components[FF::Cmp::SingletonCamera][0].nil? + camera = FF::Cmp::SingletonCamera[0] + vxtip = boid_x = sprite.props[:x] + vytip = boid_y = sprite.props[:y] + boid_vx = boid.vx * camera.zoom + boid_vy = boid.vy * camera.zoom + vxtip += ((Math.cos(camera.angle * (Math::PI / 180.0)) * boid_vx) * length) - ((Math.sin(camera.angle * (Math::PI / 180.0)) * boid_vy) * length) + vytip += ((Math.sin(camera.angle * (Math::PI / 180.0)) * boid_vx) * length) + ((Math.cos(camera.angle * (Math::PI / 180.0)) * boid_vy) * length) + boid_cx = (((Math.cos(camera.angle * (Math::PI / 180.0)) * boid.cx)) - ((Math.sin(camera.angle * (Math::PI / 180.0)) * boid.cy))) * camera.zoom + boid_cy = (((Math.sin(camera.angle * (Math::PI / 180.0)) * boid.cx)) + ((Math.cos(camera.angle * (Math::PI / 180.0)) * boid.cy))) * camera.zoom + half_height = sprite.props[:h] * 0.5 + half_width = sprite.props[:w] * 0.5 + vxtip += half_width + vytip += half_height + #boid_cx += half_width + #boid_cy += half_height + boid_x += half_width + boid_y += half_height + boid_vx += half_width + boid_vy += half_height + small_square *= camera.zoom + big_square *= camera.zoom + else + vxtip = boid_x = boid.x + vytip = boid_y = boid.y + boid_cx = boid.cx + boid_cy = boid.cy + vxtip += (boid.vx * length) + vytip += (boid.vy * length) + end # Velocity - $gtk.args.outputs.lines << [boid.x, boid.y, vxtip, vytip, 0, 255, 255, 255] - $gtk.args.outputs.lines << [boid.x+1, boid.y, vxtip+1, vytip, 0, 255, 255, 255] - $gtk.args.outputs.lines << [boid.x-1, boid.y, vxtip-1, vytip, 0, 255, 255, 255] - $gtk.args.outputs.lines << [boid.x, boid.y+1, vxtip, vytip+1, 0, 255, 255, 255] - $gtk.args.outputs.lines << [boid.x, boid.y-1, vxtip, vytip-1, 0, 255, 255, 255] + $gtk.args.outputs.lines << [boid_x, boid_y, vxtip, vytip, 0, 255, 255, 255] + $gtk.args.outputs.lines << [boid_x+1, boid_y, vxtip+1, vytip, 0, 255, 255, 255] + $gtk.args.outputs.lines << [boid_x-1, boid_y, vxtip-1, vytip, 0, 255, 255, 255] + $gtk.args.outputs.lines << [boid_x, boid_y+1, vxtip, vytip+1, 0, 255, 255, 255] + $gtk.args.outputs.lines << [boid_x, boid_y-1, vxtip, vytip-1, 0, 255, 255, 255] #$gtk.args.outputs.lines << [boid.x, boid.y, boid.x + (boid.cx * length * 10), boid.y + (boid.cy * length), 0, 255, 0, 255] # Change in Velocity - $gtk.args.outputs.lines << [vxtip, vytip, vxtip + (boid.cx * length * 10), vytip + (boid.cy * length * 10), 255, 0, 255, 255] - $gtk.args.outputs.lines << [vxtip+1, vytip, vxtip+1 + (boid.cx * length * 10), vytip + (boid.cy * length * 10), 255, 0, 255, 255] - $gtk.args.outputs.lines << [vxtip-1, vytip, vxtip-1 + (boid.cx * length * 10), vytip + (boid.cy * length * 10), 255, 0, 255, 255] - $gtk.args.outputs.lines << [vxtip, vytip+1, vxtip + (boid.cx * length * 10), vytip+1 + (boid.cy * length * 10), 255, 0, 255, 255] - $gtk.args.outputs.lines << [vxtip, vytip-1, vxtip + (boid.cx * length * 10), vytip-1 + (boid.cy * length * 10), 255, 0, 255, 255] + $gtk.args.outputs.lines << [vxtip, vytip, vxtip + (boid_cx * length * 10), vytip + (boid_cy * length * 10), 255, 0, 255, 255] + $gtk.args.outputs.lines << [vxtip+1, vytip, vxtip+1 + (boid_cx * length * 10), vytip + (boid_cy * length * 10), 255, 0, 255, 255] + $gtk.args.outputs.lines << [vxtip-1, vytip, vxtip-1 + (boid_cx * length * 10), vytip + (boid_cy * length * 10), 255, 0, 255, 255] + $gtk.args.outputs.lines << [vxtip, vytip+1, vxtip + (boid_cx * length * 10), vytip+1 + (boid_cy * length * 10), 255, 0, 255, 255] + $gtk.args.outputs.lines << [vxtip, vytip-1, vxtip + (boid_cx * length * 10), vytip-1 + (boid_cy * length * 10), 255, 0, 255, 255] # Square Velocity - $gtk.args.outputs.borders << [vxtip - 24, vytip - 24, 48, 48, 0, 255, 255] - $gtk.args.outputs.borders << [vxtip - 25, vytip - 26, 52, 52, 0, 255, 255] - $gtk.args.outputs.borders << [vxtip - 25, vytip - 25, 50, 50, 0, 255, 255] + $gtk.args.outputs.borders << [vxtip - (big_square - 1), vytip - (big_square - 1), (big_square - 1) * 2, (big_square - 1) * 2, 0, 255, 255] + $gtk.args.outputs.borders << [vxtip - big_square, vytip - big_square, (big_square) * 2, (big_square) * 2, 0, 255, 255] + $gtk.args.outputs.borders << [vxtip - (big_square + 1), vytip - (big_square + 1), (big_square + 1) * 2, (big_square + 1) * 2, 0, 255, 255] # Square Change in Velocity - $gtk.args.outputs.borders << [vxtip - 14 + (boid.cx * length * 10), vytip - 14 + (boid.cy * length * 10), 28, 28, 255, 0, 255, 255] - $gtk.args.outputs.borders << [vxtip - 15 + (boid.cx * length * 10), vytip - 15 + (boid.cy * length * 10), 30, 30, 255, 0, 255, 255] - $gtk.args.outputs.borders << [vxtip - 16 + (boid.cx * length * 10), vytip - 16 + (boid.cy * length * 10), 32, 32, 255, 0, 255, 255] + $gtk.args.outputs.borders << [vxtip - (small_square - 1) + (boid_cx * length * 10), vytip - (small_square - 1) + (boid_cy * length * 10), (small_square - 1) * 2, (small_square - 1) * 2, 255, 0, 255, 255] + $gtk.args.outputs.borders << [vxtip - small_square + (boid_cx * length * 10), vytip - small_square + (boid_cy * length * 10), (small_square) * 2, (small_square) * 2, 255, 0, 255, 255] + $gtk.args.outputs.borders << [vxtip - (small_square + 1) + (boid_cx * length * 10), vytip - (small_square + 1) + (boid_cy * length * 10), (small_square + 1) * 2, (small_square + 1) * 2, 255, 0, 255, 255] end end diff --git a/app/systems/update_boid_sprite.rb b/app/systems/update_boid_sprite.rb index b89579d..4f7dc76 100644 --- a/app/systems/update_boid_sprite.rb +++ b/app/systems/update_boid_sprite.rb @@ -1,13 +1,17 @@ FF::Scn::Render.add( - FF::Sys.new('UpdateBoidSprite', priority: 98) do + # Update the position of the boid sprite before + # the camera and before its rendered + FF::Sys.new('UpdateBoidSprite', priority: 95) do FF::Cmp::Boid.each do |boid| sprite = boid.entities[0].components[FF::Cmp::Sprite][0] - sprite.props[:x] = boid.x - sprite.props[:w] / 2 - sprite.props[:y] = boid.y - sprite.props[:h] / 2 + sprite.props[:x] = boid.x - boid.h / 2 + sprite.props[:y] = boid.y - boid.w / 2 diff_angle = (((Math.atan2(boid.vy, boid.vx) * 180.0) / Math::PI).round(3) - 90) - sprite.props[:angle] diff_angle = (diff_angle + 180) % 360 - 180 sprite.props[:angle] += diff_angle + sprite.props[:w] = boid.w + sprite.props[:h] = boid.h end end ) diff --git a/app/tick.rb b/app/tick.rb index 2a05891..c8c8f83 100644 --- a/app/tick.rb +++ b/app/tick.rb @@ -1,41 +1,48 @@ -#debug_arrow = FF::Cmp::DebugVectorArrow.new(length: 5) -#position = [ -# {x: 100, y: 100}, -# {x: 500, y: 500}, -# {x: 700, y: 200}, -# {x: 150, y: 250}, -#] -#position_range = (100..700).to_a -# -#25.times do |pos| -# sprite = FF::Cmp::Sprite.new -# sprite.props[:path] = 'sprites/kenny/Ships/ship_0011.png' -# FF::Ent.new( -# FF::Cmp::Boid.new(x: position_range.sample, y: position_range.sample, vx: 25, vy: 25), -# sprite, -# FF::Cmp::BoidBounds.new(strength: 1), -# FF::Cmp::BoidsAlignment.new(strength: 1), -# FF::Cmp::BoidsSeparation.new(distance: 150, strength: 0.01), -# FF::Cmp::BoidsCohesion.new(strength: 100), -# #debug_arrow, -# ) -#end -#FF::Ent.new( -# FF::Cmp::Sprite.new, -# FF::Cmp::Boid.new(x: 150, y: 250), -# FF::Cmp::BoidBounds.new, -#FF::Cmp::BoidsAlignment.new, -# FF::Cmp::BoidsSeparation.new(strength: 1.0), -# #FF::Cmp::BoidsCohesion.new, -# debug_arrow, -#) -#FF::Scn::Debug.add(FF::Sys::DebugRenderVectorArrow) -#@pause = true -#FF::Stg.remove FF::Scn::BoidRules + +#FF::Cmp::Boid.new(x: position_range.sample, y: position_range.sample, vx: 25, vy: 25, w: sprite.props[:w], h: sprite.props[:h]), +#FF::Cmp::SingletonCamera[0], + +#@pause = false +@camera = FF::Cmp::SingletonCamera[0] + FF::Sys::InitTitleScreen.call def tick args args.outputs.background_color = [0,0,0] FelFlame::Stage.call + + # Moving Camera + if args.inputs.keyboard.keys[:down_or_held].include?(:d) + @camera.x += (Math.cos([email protected] * (Math::PI / 180.0)) * 5) + @camera.y += (Math.sin([email protected] * (Math::PI / 180.0)) * 5) + end + if args.inputs.keyboard.keys[:down_or_held].include?(:a) + @camera.x += (Math.cos([email protected] * (Math::PI / 180.0)) * -5) + @camera.y += (Math.sin([email protected] * (Math::PI / 180.0)) * -5) + end + if args.inputs.keyboard.keys[:down_or_held].include?(:w) + #@camera.y += 5 + @camera.x -= (Math.sin([email protected] * (Math::PI / 180.0)) * 5) + @camera.y += (Math.cos([email protected] * (Math::PI / 180.0)) * 5) + end + if args.inputs.keyboard.keys[:down_or_held].include?(:s) + #@camera.y -= 5 + @camera.x -= (Math.sin([email protected] * (Math::PI / 180.0)) * -5) + @camera.y += (Math.cos([email protected] * (Math::PI / 180.0)) * -5) + end + if args.inputs.keyboard.keys[:down_or_held].include?(:q) + @camera.angle += 3 + end + if args.inputs.keyboard.keys[:down_or_held].include?(:e) + @camera.angle -= 3 + end + if args.inputs.keyboard.keys[:down_or_held].include?(:z) + @camera.zoom *= 1.05 + end + if args.inputs.keyboard.keys[:down_or_held].include?(:x) + @camera.zoom *= 0.95 + end + + # Pausing if args.inputs.keyboard.keys[:down].include?(:right) FF::Scn::BoidRules.call end |
