summaryrefslogtreecommitdiffhomepage
path: root/run.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-08-09 09:15:38 -0400
committerrealtradam <[email protected]>2021-08-09 09:15:38 -0400
commit501ec02e894865836f2960b0bbc16b3448e3707f (patch)
treead2c1124e5ab5807dea1b11002cc5bf2df1226d9 /run.rb
parent4e909c6b44794b76ef3a98c032ea90204b673f85 (diff)
downloadruboids-501ec02e894865836f2960b0bbc16b3448e3707f.tar.gz
ruboids-501ec02e894865836f2960b0bbc16b3448e3707f.zip
ruboids!
Diffstat (limited to 'run.rb')
-rw-r--r--run.rb98
1 files changed, 60 insertions, 38 deletions
diff --git a/run.rb b/run.rb
index bfce180..e21f723 100644
--- a/run.rb
+++ b/run.rb
@@ -1,65 +1,88 @@
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
+
+# The velocity limit of a boid
+# Set to negative to remove limit
+$limit = 12.0
+
+# These are changed later by mouse position
+$x_target = 0.0
+$y_target = 0.0
+
+FF::Cmp.new('SingletonConfig',
+ debug: false,
+ bounds_strength: 2.0,
+ xmax: 480.0, xmin: -580.0,
+ ymax: 250.0, ymin: -340.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 }
-#FF::Scn::BoidCalculations.remove FF::Sys::Cohesion
-FF::Stg.remove FF::Scn::BoidCalculations
+# 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::Seperation
+FF::Scn::BoidCalculations.add FF::Sys::Target
+FF::Scn::BoidCalculations.add FF::Sys::Bounds
+
+FF::Stg.add FF::Scn::BoidCalculations
class GameWindow < Ruby2D::Window
def initialize
super
- #Camera.x = 10
- #Camera.y = 10
- randspot = ((-720 / 2)..(720/2)).to_a
- @ent = FF::Ent.new(
- FF::Cmp::Boids.new(x: randspot.sample, y:randspot.sample),
- FF::Cmp::BoidVisuals.new(
- obj: Camera::Circle.new(
- color: [0.86,1.0,0.96,1],
- radius: 7,
- sectors: 10
- ),
- vect: Camera::Line.new(
- width: 7,
- color: 'red',
- z: -1
- )
- )
- )
- 5.times do
+ 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, y:randspot.sample),
+ FF::Cmp::Boids.new(x: randspot.sample.to_f, y: randspot.sample.to_f),
FF::Cmp::BoidVisuals.new(
- obj: Camera::Circle.new(
- color: [0.86,0.57,0.96,1],
- radius: 7,
- sectors: 10
+ 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: 'red',
+ color: [1.0,0,0,0.5],
z: -1
)
)
)
end
+ unless $config.debug
+ FF::Cmp::BoidVisuals.each do |boid|
+ boid.vect.remove
+ end
+ end
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]
FF::Stage.call
- Camera.y += 5 if key_held('s')
- Camera.y -= 5 if key_held('w')
- Camera.x += 5 if key_held('d')
- Camera.x -= 5 if key_held('a')
+ Camera.y += 1 if key_held('s')
+ Camera.y -= 1 if key_held('w')
+ Camera.x += 1 if key_held('d')
+ 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 #if key_held('space')
- puts "X: #{@ent.components[FF::Cmp::Boids].first.x}"
- puts "Y: #{@ent.components[FF::Cmp::Boids].first.y}"
- puts "VX:#{@ent.components[FF::Cmp::Boids].first.vx}"
- puts "VY:#{@ent.components[FF::Cmp::Boids].first.vy}"
+ FF::Scn::BoidCalculations.call
end
end
@@ -69,6 +92,5 @@ end
gamewindow = GameWindow.new
-set(title: "Ruboids", width: 1280, height: 720, resizable: true)
-gamewindow.set(title: "Ruboids", width: 1280, height: 720, resizable: true)
+gamewindow.set(title: get(:title), width: get(:width), height: get(:height), resizable: get(:resizable))
gamewindow.show