diff options
| author | realtradam <[email protected]> | 2021-12-18 02:03:57 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-12-18 02:03:57 -0500 |
| commit | 509f53c9bca30de88af6f12c371ca637a9a4f9a3 (patch) | |
| tree | fff0eb4fcea193a1c1acb383817bdf61c67458e9 | |
| parent | 264b2f9e92a475db75904f72cad2bc8131b39dda (diff) | |
| download | SteelWings-509f53c9bca30de88af6f12c371ca637a9a4f9a3.tar.gz SteelWings-509f53c9bca30de88af6f12c371ca637a9a4f9a3.zip | |
fixed separation defaults, centering sprites
| -rw-r--r-- | app/components/boid.rb | 3 | ||||
| -rw-r--r-- | app/components/rules/separation.rb | 4 | ||||
| -rw-r--r-- | app/components/sprite.rb | 2 | ||||
| -rw-r--r-- | app/systems/rules/separation.rb | 8 | ||||
| -rw-r--r-- | app/systems/update_boid_position.rb | 2 | ||||
| -rw-r--r-- | app/systems/update_boid_sprite.rb | 4 | ||||
| -rw-r--r-- | app/tick.rb | 66 |
7 files changed, 44 insertions, 45 deletions
diff --git a/app/components/boid.rb b/app/components/boid.rb index 99701df..060f9c3 100644 --- a/app/components/boid.rb +++ b/app/components/boid.rb @@ -1,4 +1,5 @@ FF::Cmp.new('Boid', x: 0, y: 0, vx: 0, vy: 0, - cx: 0, cy: 0) + cx: 0, cy: 0, + angle: 0) diff --git a/app/components/rules/separation.rb b/app/components/rules/separation.rb index 00fee32..5298623 100644 --- a/app/components/rules/separation.rb +++ b/app/components/rules/separation.rb @@ -1,3 +1,3 @@ FF::Cmp.new('BoidsSeparation', - strength: 100, - distance: 100) + :strength, + distance: 500) diff --git a/app/components/sprite.rb b/app/components/sprite.rb index 3af016d..01602c5 100644 --- a/app/components/sprite.rb +++ b/app/components/sprite.rb @@ -16,6 +16,6 @@ FF::Cmp.new("Sprite", props: { flip_vertically: false, flip_horizontally: false, angle_anchor_x: 0.5, - angle_anchor_y: 1.0, + angle_anchor_y: 0.5, blendmode_enum: 1 }) diff --git a/app/systems/rules/separation.rb b/app/systems/rules/separation.rb index 4a20193..9e223d2 100644 --- a/app/systems/rules/separation.rb +++ b/app/systems/rules/separation.rb @@ -6,9 +6,9 @@ FF::Scn::BoidRules.add( FF::Cmp::Boid.each do |boid_check| next if boid_check == boid_update - + if Math.sqrt(((-boid_check.x + boid_update.x)**2) + ((-boid_check.y + boid_update.y)**2)).abs < separation.distance - #if (boid_check.x - boid_update.x).abs < separation.distance and (boid_check.y - boid_update.y).abs < separation.distance + #if (boid_check.x - boid_update.x).abs < separation.distance and (boid_check.y - boid_update.y).abs < separation.distance newvec[0] -= boid_check.x - boid_update.x newvec[1] -= boid_check.y - boid_update.y end @@ -19,8 +19,8 @@ FF::Scn::BoidRules.add( # puts "cx: #{boid_update.cx} cy: #{boid_update.cy}" # puts "vx: #{boid_update.vx} vy: #{boid_update.vy}" #end - boid_update.cx += newvec[0].to_f * separation.strength - boid_update.cy += newvec[1].to_f * separation.strength + boid_update.cx += (newvec[0].to_f * separation.strength.to_f) + boid_update.cy += (newvec[1].to_f * separation.strength.to_f) end end ) diff --git a/app/systems/update_boid_position.rb b/app/systems/update_boid_position.rb index 50ab9a7..81d053e 100644 --- a/app/systems/update_boid_position.rb +++ b/app/systems/update_boid_position.rb @@ -5,7 +5,7 @@ FF::Scn::BoidRules.add( boid.vy += boid.cy boid.x += boid.vx boid.y += boid.vy - # TODO: based on direction of the vector, needs to update the rotation of sprite too + end end ) diff --git a/app/systems/update_boid_sprite.rb b/app/systems/update_boid_sprite.rb index 3a4f25e..b89579d 100644 --- a/app/systems/update_boid_sprite.rb +++ b/app/systems/update_boid_sprite.rb @@ -4,6 +4,10 @@ FF::Scn::Render.add( 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 + + 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 end end ) diff --git a/app/tick.rb b/app/tick.rb index 60ffbd5..7539405 100644 --- a/app/tick.rb +++ b/app/tick.rb @@ -1,40 +1,34 @@ debug_arrow = FF::Cmp::DebugVectorArrow.new(length: 5) -FF::Ent.new( - FF::Cmp::Sprite.new, - FF::Cmp::Boid.new(x: 10, y: 10), - FF::Cmp::BoidBounds.new, - #FF::Cmp::BoidsAlignment.new, - FF::Cmp::BoidsSeparation.new, - #FF::Cmp::BoidsCohesion.new, - debug_arrow, -) -FF::Ent.new( - FF::Cmp::Sprite.new, - FF::Cmp::Boid.new(x: 50, y: 50), - FF::Cmp::BoidBounds.new, - #FF::Cmp::BoidsAlignment.new, - FF::Cmp::BoidsSeparation.new, - #FF::Cmp::BoidsCohesion.new, - debug_arrow, -) -FF::Ent.new( - FF::Cmp::Sprite.new, - FF::Cmp::Boid.new(x: 70, y: 20), - FF::Cmp::BoidBounds.new, - #FF::Cmp::BoidsAlignment.new, - FF::Cmp::BoidsSeparation.new, - #FF::Cmp::BoidsCohesion.new, - debug_arrow, -) -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, - #FF::Cmp::BoidsCohesion.new, - debug_arrow, -) +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 |
