diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/components/button.rb | 2 | ||||
| -rw-r--r-- | app/components/rules/follow.rb | 3 | ||||
| -rw-r--r-- | app/main.rb | 2 | ||||
| -rw-r--r-- | app/systems/init_title_screen.rb | 4 | ||||
| -rw-r--r-- | app/systems/rules/follow.rb | 27 | ||||
| -rw-r--r-- | app/systems/start_game.rb | 10 | ||||
| -rw-r--r-- | app/systems/title_screen.rb | 12 |
7 files changed, 52 insertions, 8 deletions
diff --git a/app/components/button.rb b/app/components/button.rb index 8f9126f..097ca51 100644 --- a/app/components/button.rb +++ b/app/components/button.rb @@ -1,3 +1,5 @@ FF::Cmp.new('Button', :action, + :pressed_sprite_path, + :unpressed_sprite_path, clicked: false) diff --git a/app/components/rules/follow.rb b/app/components/rules/follow.rb new file mode 100644 index 0000000..868d44f --- /dev/null +++ b/app/components/rules/follow.rb @@ -0,0 +1,3 @@ +FF::Cmp.new('Follow', + :target, + strength: 100) diff --git a/app/main.rb b/app/main.rb index 4c2a54e..f5cc908 100644 --- a/app/main.rb +++ b/app/main.rb @@ -10,6 +10,7 @@ require 'app/components/rules/bounds.rb' require 'app/components/rules/cohesion.rb' require 'app/components/rules/alignment.rb' require 'app/components/rules/separation.rb' +require 'app/components/rules/follow.rb' require 'app/components/debug/debug_vector_arrow.rb' require 'app/components/camera.rb' require 'app/components/stats/collision_damage.rb' @@ -27,6 +28,7 @@ require 'app/systems/rules/cohesion.rb' require 'app/systems/rules/alignment.rb' require 'app/systems/rules/separation.rb' require 'app/systems/rules/reset_change_vector.rb' +require 'app/systems/rules/follow.rb' require 'app/systems/debug/debug_render_vector_arrow.rb' require 'app/systems/camera.rb' require 'app/systems/collision_damage.rb' diff --git a/app/systems/init_title_screen.rb b/app/systems/init_title_screen.rb index 66873df..04c4978 100644 --- a/app/systems/init_title_screen.rb +++ b/app/systems/init_title_screen.rb @@ -11,10 +11,10 @@ FF::Sys.new('InitTitleScreen', priority: 1) do sprite.props[:y] = btn_y sprite.props[:w] = btn_w sprite.props[:h] = btn_h - sprite.props[:path] = 'sprites/title/start.png' + #sprite.props[:path] = 'sprites/title/start.png' # start button FF::Ent.new( - FF::Cmp::Button.new(action: FF::Sys::StartGame), + FF::Cmp::Button.new(action: FF::Sys::StartGame, pressed_sprite_path: 'sprites/title/start_pressed.png', unpressed_sprite_path: 'sprites/title/start.png'), FF::Cmp::Hitbox.new(x: btn_x, y: btn_y, w: btn_w, h: btn_h), sprite, FF::Cmp::Title[0] diff --git a/app/systems/rules/follow.rb b/app/systems/rules/follow.rb new file mode 100644 index 0000000..0b5045e --- /dev/null +++ b/app/systems/rules/follow.rb @@ -0,0 +1,27 @@ +FF::Scn::BoidRules.add( + FF::Sys.new('Follow', priority: 70) do + FF::Cmp::Follow.each do |follow| + boid = follow.entities[0].components[FF::Cmp::Boid][0] + target_coords = [0.0, 0.0] + case follow.target + when FF::Cmp::Boid + target_coords[0] = follow.target.x + target_coords[1] = follow.target.y + when Array + target_coords[0] = follow.target[0] + target_coords[1] = follow.target[1] + when :mouse + camera = FF::Cmp::SingletonCamera[0] + angle = camera.angle * (Math::PI / 180) + mouse = $gtk.args.inputs.mouse + half_width = $gtk.args.grid.w * 0.5 + half_height = $gtk.args.grid.h * 0.5 + target_coords[0] = (((mouse.x - half_width) / camera.zoom) * Math.cos(-angle)) - (((mouse.y - half_height) / camera.zoom) * Math.sin(-angle)) + camera.x + target_coords[1] = (((mouse.x - half_width) / camera.zoom) * Math.sin(-angle)) + (((mouse.y - half_height) / camera.zoom) * Math.cos(-angle)) + camera.y + end + + boid.cx += (target_coords[0] - boid.x) / follow.strength.to_f + boid.cy += (target_coords[1] - boid.y) / follow.strength.to_f + end + end +) diff --git a/app/systems/start_game.rb b/app/systems/start_game.rb index b5a832b..39cc63c 100644 --- a/app/systems/start_game.rb +++ b/app/systems/start_game.rb @@ -21,6 +21,16 @@ FF::Sys.new('StartGame', priority: 50 ) do Factory::Osprey.new(x: position_range.sample, y: position_range.sample) end + 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, w: sprite.props[:w], h: sprite.props[:h]), + sprite, + debug_arrow, + FF::Cmp::SingletonCamera[0], + FF::Cmp::Follow.new(target: :mouse, strength: 500) + ) + FF::Stg.add( FF::Scn::BoidRules, FF::Scn::Debug, diff --git a/app/systems/title_screen.rb b/app/systems/title_screen.rb index 0229720..0fa0a81 100644 --- a/app/systems/title_screen.rb +++ b/app/systems/title_screen.rb @@ -11,15 +11,15 @@ FF::Scn::TitleScreen.add( if mouse.x > hitbox.x and mouse.x < hitbox.x + hitbox.w and mouse.y > hitbox.y and mouse.y < hitbox.y + hitbox.h if $gtk.args.inputs.mouse.down btn.clicked = true - #sprite.props[:path] = '' - else + sprite.props[:path] = btn.pressed_sprite_path + elsif $gtk.args.inputs.mouse.up and btn.clicked btn.clicked = false - #sprite.props[:path] = '' - end - if $gtk.args.inputs.mouse.click + sprite.props[:path] = btn.unpressed_sprite_path btn.action.call - puts 'click' end + else + btn.clicked = false + sprite.props[:path] = btn.unpressed_sprite_path end end end |
