diff options
| author | realtradam <[email protected]> | 2021-08-09 10:32:45 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-08-09 10:32:45 -0400 |
| commit | c1eb3f4c18404d4921adc3d38dfa7438a47f4aa0 (patch) | |
| tree | e0150085494d014dfbcdc1e6e2314fde62c9af1c /run.rb | |
| parent | 501ec02e894865836f2960b0bbc16b3448e3707f (diff) | |
| download | ruboids-c1eb3f4c18404d4921adc3d38dfa7438a47f4aa0.tar.gz ruboids-c1eb3f4c18404d4921adc3d38dfa7438a47f4aa0.zip | |
initial piranha
Diffstat (limited to 'run.rb')
| -rw-r--r-- | run.rb | 93 |
1 files changed, 48 insertions, 45 deletions
@@ -1,40 +1,60 @@ require 'ruby2d' require 'ruby2d/camera' require 'felflame' -# If Camera should follow center mass -$follow = false -# Values that can tune strength of certain rules -# Lower is stronger -$cohesion = 3000.0 -$seperation = 75.0 -$seperation_distance = 125.0 -$alignment = 1000.0 -$target_strength = 2500.0 +# configuration for the simulation +# change values here to see a change in the simulation +FF::Cmp.new('SingletonConfig', + # Show vectors + debug: true, -# The velocity limit of a boid -# Set to negative to remove limit -$limit = 12.0 + # If the camera should follow the "center mass" + follow: false, -# These are changed later by mouse position -$x_target = 0.0 -$y_target = 0.0 + # The velocity limit of a boid + # Set to negative to disable + limit: 6.0, -FF::Cmp.new('SingletonConfig', - debug: false, - bounds_strength: 2.0, + # How strong the bounds should be + # Higher is stronger + bounds_strength: 1.0, + # What the bounds are xmax: 480.0, xmin: -580.0, - ymax: 250.0, ymin: -340.0) + ymax: 250.0, ymin: -340.0, + + # How much the boids try to pull together + # Smaller is stronger + cohesion: 6000.0, + + # How much the boids push away from eachother + # Smaller is stronger + seperation: 375.0, + # What the range of seperating should be + seperation_distance: 150.0, + + # How strong their vector alignment should be + # Smaller is stronger + alignment: 1000.0, + + # How much they try to follow their target(your mouse cursor) + # Smaller is stronger + target_strength: 2500.0, + + # These are later set by the mouse position + target_x: 0, target_y: 0) $config = FF::Cmp::SingletonConfig.new # Used by the Camera Library set(title: "Ruboids", width: 1164, height: 764, resizable: true) + + Dir[File.join(__dir__, 'lib/**', '*.rb')].sort.each { |file| require file } + # Comment out to remove a rule FF::Scn::BoidCalculations.add FF::Sys::Cohesion -FF::Scn::BoidCalculations.add FF::Sys::Alignment +#FF::Scn::BoidCalculations.add FF::Sys::Alignment FF::Scn::BoidCalculations.add FF::Sys::Seperation -FF::Scn::BoidCalculations.add FF::Sys::Target +#FF::Scn::BoidCalculations.add FF::Sys::Target FF::Scn::BoidCalculations.add FF::Sys::Bounds FF::Stg.add FF::Scn::BoidCalculations @@ -44,25 +64,11 @@ class GameWindow < Ruby2D::Window super Camera::Image.new('assets/Background.png', x: -get(:width)+57, y: -get(:height)+97, z: -99) randspot = ((-get(:height) / 2)..(get(:height)/2)).to_a - 6.times do - FF::Ent.new( - FF::Cmp::Boids.new(x: randspot.sample.to_f, y: randspot.sample.to_f), - FF::Cmp::BoidVisuals.new( - obj: Camera::Image.new( - 'assets/Guppy Large Normal.png', - width: 45, height: 46 - #obj: Camera::Circle.new( - # color: [0.86,0.57,0.96,1], - # radius: 7, - # sectors: 10 - ), - vect: Camera::Line.new( - width: 7, - color: [1.0,0,0,0.5], - z: -1 - ) - ) - ) + 7.times do + Fish.create(randspot.sample.to_f, randspot.sample.to_f) + end + 2.times do + Piranha.create(randspot.sample.to_f, randspot.sample.to_f) end unless $config.debug FF::Cmp::BoidVisuals.each do |boid| @@ -72,8 +78,8 @@ class GameWindow < Ruby2D::Window end def update - $x_target = Camera.coordinate_to_worldspace(get(:mouse_x), get(:mouse_y))[0] - $y_target = Camera.coordinate_to_worldspace(get(:mouse_y), get(:mouse_y))[1] + $config.target_x = Camera.coordinate_to_worldspace(get(:mouse_x), get(:mouse_y))[0] + $config.target_y = Camera.coordinate_to_worldspace(get(:mouse_y), get(:mouse_y))[1] FF::Stage.call Camera.y += 1 if key_held('s') Camera.y -= 1 if key_held('w') @@ -81,9 +87,6 @@ class GameWindow < Ruby2D::Window Camera.x -= 1 if key_held('a') Camera.zoom *= 1.1 if key_held('z') Camera.zoom /= 1.1 if key_held('x') - if key_held('space') - FF::Scn::BoidCalculations.call - end end def render |
