diff options
| author | arngo <[email protected]> | 2021-12-23 01:04:59 -0500 |
|---|---|---|
| committer | arngo <[email protected]> | 2021-12-23 01:04:59 -0500 |
| commit | 8116ce1f56aaf5344596ca16177c7abff11b1496 (patch) | |
| tree | ac0b5e048f6b056129b01439fb20b89861efeee5 | |
| parent | b567c7ceb887a8da73a8e2c1015a7638ca1f8fad (diff) | |
| download | SteelWings-8116ce1f56aaf5344596ca16177c7abff11b1496.tar.gz SteelWings-8116ce1f56aaf5344596ca16177c7abff11b1496.zip | |
implement ai components/systems
| -rw-r--r-- | app/components/singleton_title.rb | 2 | ||||
| -rw-r--r-- | app/factories/ships/osprey.rb | 7 | ||||
| -rw-r--r-- | app/main.rb | 3 | ||||
| -rw-r--r-- | app/systems/ai/rejoin.rb | 14 | ||||
| -rw-r--r-- | app/systems/ai/scatter.rb | 18 | ||||
| -rw-r--r-- | app/systems/ai/target_player.rb | 11 | ||||
| -rw-r--r-- | app/systems/start_game.rb | 4 | ||||
| -rw-r--r-- | app/tick.rb | 22 |
8 files changed, 74 insertions, 7 deletions
diff --git a/app/components/singleton_title.rb b/app/components/singleton_title.rb index c2fd410..5ebe400 100644 --- a/app/components/singleton_title.rb +++ b/app/components/singleton_title.rb @@ -1,2 +1,2 @@ -FF::Cmp.new('SingletonTitle', singleton: true) +FF::Cmp.new('SingletonTitle', singleton: true, title_screen: true) FF::Cmp::SingletonTitle.new diff --git a/app/factories/ships/osprey.rb b/app/factories/ships/osprey.rb index 1e76b17..e371e60 100644 --- a/app/factories/ships/osprey.rb +++ b/app/factories/ships/osprey.rb @@ -16,15 +16,16 @@ class Factory FF::Cmp::Boid.new(x: x, y: y, vx: -3, vy: -3, w: 32, h: 32), sprite, FF::Cmp::BoidBounds.new(strength: 0.6), - FF::Cmp::BoidsAlignment.new(strength: 1), + FF::Cmp::BoidsAlignment.new(strength: 10), FF::Cmp::BoidsSeparation.new(distance: 150, strength: 0.001), - FF::Cmp::BoidsCohesion.new(strength: 10000), + FF::Cmp::BoidsCohesion.new(strength: 1000), FF::Cmp::Hp.new(health: 100), FF::Cmp::CollisionDamage.new(damage: 100), FF::Cmp::Hitcircle.new(r: 12), FF::Cmp::BoidMinimumSpeed.new(speed: 3), + FF::Cmp::DecaySpeed.new(strength: 0.9), FF::Cmp::Team.new, - FF::Cmp::SingletonDebugVectorArrow[0], + #FF::Cmp::SingletonDebugVectorArrow[0], FF::Cmp::SingletonCamera[0], ) end diff --git a/app/main.rb b/app/main.rb index 20d0e8c..5a172c5 100644 --- a/app/main.rb +++ b/app/main.rb @@ -47,6 +47,9 @@ require 'app/systems/player_weapon.rb' require 'app/systems/move_camera.rb' require 'app/systems/rules/minimum_speed.rb' require 'app/systems/cleanup_bullets.rb' +require 'app/systems/ai/scatter.rb' +require 'app/systems/ai/rejoin.rb' +require 'app/systems/ai/target_player.rb' require 'app/factories/bullet.rb' require 'app/factories/ships/osprey.rb' diff --git a/app/systems/ai/rejoin.rb b/app/systems/ai/rejoin.rb new file mode 100644 index 0000000..51137f9 --- /dev/null +++ b/app/systems/ai/rejoin.rb @@ -0,0 +1,14 @@ +FF::Sys.new("Rejoin", priority: 40) do + FF::Cmp::BoidsSeparation.each do |sep| + puts 'add align/cohesion'.upcase + sep.distance = 150 + alignment_mgr = sep.entities[0].components[FF::Cmp::BoidsAlignment] + cohesion_mgr = sep.entities[0].components[FF::Cmp::BoidsCohesion] + if alignment_mgr.nil? || alignment_mgr.empty? + sep.entities[0].add FF::Cmp::BoidsAlignment.new(strength: 10) + end + if cohesion_mgr.nil? || cohesion_mgr.empty? + sep.entities[0].add FF::Cmp::BoidsCohesion.new(strength: 1000) + end + end +end diff --git a/app/systems/ai/scatter.rb b/app/systems/ai/scatter.rb new file mode 100644 index 0000000..9b93c73 --- /dev/null +++ b/app/systems/ai/scatter.rb @@ -0,0 +1,18 @@ +FF::Sys.new("Scatter", priority: 40) do + FF::Cmp::BoidsSeparation.each do |sep| + sep.distance = 200 + puts 'remove align/cohesion/follow'.upcase + alignment_mgr = sep.entities[0].components[FF::Cmp::BoidsAlignment] + cohesion_mgr = sep.entities[0].components[FF::Cmp::BoidsCohesion] + follow_mgr = sep.entities[0].components[FF::Cmp::Follow] + unless follow_mgr.nil? || follow_mgr.empty? + follow_mgr[0].delete + end + unless alignment_mgr.nil? || alignment_mgr.empty? + alignment_mgr[0].delete + end + unless cohesion_mgr.nil? || cohesion_mgr.empty? + cohesion_mgr[0].delete + end + end +end diff --git a/app/systems/ai/target_player.rb b/app/systems/ai/target_player.rb new file mode 100644 index 0000000..c72ffb4 --- /dev/null +++ b/app/systems/ai/target_player.rb @@ -0,0 +1,11 @@ +FF::Sys.new("TargetPlayer", priority: 40) do + FF::Cmp::BoidsSeparation.each do |sep| + puts 'target player'.upcase + sep.distance = 200 + follow_mgr = sep.entities[0].components[FF::Cmp::Follow] + player_boid = FF::Cmp::SingletonPlayer[0].entities[0].components[FF::Cmp::Boid][0] + if follow_mgr.nil? || follow_mgr.empty? + sep.entities[0].add FF::Cmp::Follow.new(target: player_boid, strength: 500) + end + end +end diff --git a/app/systems/start_game.rb b/app/systems/start_game.rb index fd45a14..d6546df 100644 --- a/app/systems/start_game.rb +++ b/app/systems/start_game.rb @@ -9,7 +9,7 @@ FF::Sys.new('StartGame', priority: 50 ) do entity.delete end - FF::Cmp::SingletonTitle[0].delete + FF::Cmp::SingletonTitle[0].title_screen = false FF::Stg.remove FF::Scn::TitleScreen debug_arrow = FF::Cmp::SingletonDebugVectorArrow.new(length: 5) @@ -28,7 +28,7 @@ FF::Sys.new('StartGame', priority: 50 ) do FF::Cmp::SingletonCamera[0], FF::Cmp::Boid.new(h: 1920 * 2, w: 1920 * 2) ) - 5.times do |pos| + 15.times do |pos| Factory::Osprey.new(x: position_range.sample, y: position_range.sample) end diff --git a/app/tick.rb b/app/tick.rb index f994d5a..901a538 100644 --- a/app/tick.rb +++ b/app/tick.rb @@ -4,9 +4,29 @@ #@pause = false @camera = FF::Cmp::SingletonCamera[0] - +@scatter = false +@target = true +@timer = 0 FF::Sys::InitTitleScreen.call def tick args + #puts @timer + @timer += 1 + if @timer >= 100 && !FF::Cmp::SingletonTitle[0].title_screen + @timer -= 100 + puts "scatter: #{@scatter}" + puts "target: #{@target}" + @scatter = !@scatter + if @scatter + FF::Sys::Scatter.call + elsif @target + @target = false + FF::Sys::Rejoin.call + else + @target = true + FF::Sys::TargetPlayer.call + end + end + args.outputs.background_color = [0,0,0] args.outputs.solids << [-10_000, -10_000, 20_000, 20_000, 223, 246, 245] |
