diff options
| -rw-r--r-- | app/components/button.rb | 3 | ||||
| -rw-r--r-- | app/components/hitbox.rb | 3 | ||||
| -rw-r--r-- | app/main.rb | 5 | ||||
| -rw-r--r-- | app/scenes/scenes.rb | 5 | ||||
| -rw-r--r-- | app/systems/init_title_screen.rb | 22 | ||||
| -rw-r--r-- | app/systems/start_game.rb | 42 | ||||
| -rw-r--r-- | app/systems/title_screen.rb | 26 | ||||
| -rw-r--r-- | app/tick.rb | 40 | ||||
| -rw-r--r-- | sprites/title/start.png | bin | 0 -> 530 bytes |
9 files changed, 110 insertions, 36 deletions
diff --git a/app/components/button.rb b/app/components/button.rb new file mode 100644 index 0000000..8f9126f --- /dev/null +++ b/app/components/button.rb @@ -0,0 +1,3 @@ +FF::Cmp.new('Button', + :action, + clicked: false) diff --git a/app/components/hitbox.rb b/app/components/hitbox.rb new file mode 100644 index 0000000..2b842a3 --- /dev/null +++ b/app/components/hitbox.rb @@ -0,0 +1,3 @@ +FF::Cmp.new('Hitbox', + x: 0, y: 0, + w: 50, h: 50) diff --git a/app/main.rb b/app/main.rb index 00984e6..5c4797e 100644 --- a/app/main.rb +++ b/app/main.rb @@ -4,6 +4,8 @@ require 'app/scenes/scenes.rb' require 'app/components/sprite.rb' require 'app/components/boid.rb' +require 'app/components/button.rb' +require 'app/components/hitbox.rb' require 'app/components/rules/bounds.rb' require 'app/components/rules/cohesion.rb' require 'app/components/rules/alignment.rb' @@ -11,6 +13,9 @@ require 'app/components/rules/separation.rb' require 'app/components/debug/debug_vector_arrow.rb' require 'app/components/camera.rb' +require 'app/systems/init_title_screen.rb' +require 'app/systems/title_screen.rb' +require 'app/systems/start_game.rb' require 'app/systems/render.rb' require 'app/systems/update_boid_sprite.rb' require 'app/systems/update_boid_position.rb' diff --git a/app/scenes/scenes.rb b/app/scenes/scenes.rb index a414795..98e3632 100644 --- a/app/scenes/scenes.rb +++ b/app/scenes/scenes.rb @@ -1,5 +1,6 @@ +FF::Scn.new('BoidRules') +FF::Scn.new('Debug') FF::Stg.add( + FF::Scn.new('TitleScreen'), FF::Scn.new('Render'), - FF::Scn.new('BoidRules'), - FF::Scn.new('Debug') ) diff --git a/app/systems/init_title_screen.rb b/app/systems/init_title_screen.rb new file mode 100644 index 0000000..66873df --- /dev/null +++ b/app/systems/init_title_screen.rb @@ -0,0 +1,22 @@ +FF::Sys.new('InitTitleScreen', priority: 1) do + btn_w = 190 + btn_h = 49 + btn_x = 1280/2 - btn_w/2 + btn_y = 200 + + FF::Cmp.new('Title').new + #title_cmp = FF::Cmp::Title.new + sprite = FF::Cmp::Sprite.new + sprite.props[:x] = btn_x + sprite.props[:y] = btn_y + sprite.props[:w] = btn_w + sprite.props[:h] = btn_h + sprite.props[:path] = 'sprites/title/start.png' + # start button + FF::Ent.new( + FF::Cmp::Button.new(action: FF::Sys::StartGame), + FF::Cmp::Hitbox.new(x: btn_x, y: btn_y, w: btn_w, h: btn_h), + sprite, + FF::Cmp::Title[0] + ) +end diff --git a/app/systems/start_game.rb b/app/systems/start_game.rb new file mode 100644 index 0000000..2972209 --- /dev/null +++ b/app/systems/start_game.rb @@ -0,0 +1,42 @@ +FF::Sys.new('StartGame', priority: 50 ) do + FF::Cmp::Title[0].entities.each do |entity| + entity.components[FF::Cmp::Sprite][0].delete + entity.components[FF::Cmp::Button][0].delete + entity.components[FF::Cmp::Hitbox][0].delete + entity.delete + end + FF::Cmp::Title[0].delete + FF::Stg.remove FF::Scn::TitleScreen + + debug_arrow = FF::Cmp::DebugVectorArrow.new(length: 5) + 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::Stg.add( + FF::Scn::BoidRules, + FF::Scn::Debug, + ) + + FF::Scn::Debug.add(FF::Sys::DebugRenderVectorArrow) + @pause = false + #FF::Stg.remove FF::Scn::BoidRules +end diff --git a/app/systems/title_screen.rb b/app/systems/title_screen.rb new file mode 100644 index 0000000..0229720 --- /dev/null +++ b/app/systems/title_screen.rb @@ -0,0 +1,26 @@ +FF::Scn::TitleScreen.add( + FF::Sys.new('TitleScreen', priority: 50) do + FF::Cmp::Title[0].entities.each do |entity| + next unless entity.components.key?(FF::Cmp::Button) + + btn = entity.components[FF::Cmp::Button][0] + sprite = entity.components[FF::Cmp::Sprite][0] + hitbox = entity.components[FF::Cmp::Hitbox][0] + mouse = $gtk.args.inputs.mouse + + 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 + btn.clicked = false + #sprite.props[:path] = '' + end + if $gtk.args.inputs.mouse.click + btn.action.call + puts 'click' + end + end + end + end +) diff --git a/app/tick.rb b/app/tick.rb index 9cfaa30..c8c8f83 100644 --- a/app/tick.rb +++ b/app/tick.rb @@ -1,39 +1,11 @@ -debug_arrow = FF::Cmp::DebugVectorArrow.new(length: 5) -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, w: sprite.props[:w], h: sprite.props[:h]), - 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), - FF::Cmp::SingletonCamera[0], - 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 +#FF::Cmp::Boid.new(x: position_range.sample, y: position_range.sample, vx: 25, vy: 25, w: sprite.props[:w], h: sprite.props[:h]), +#FF::Cmp::SingletonCamera[0], + +#@pause = false @camera = FF::Cmp::SingletonCamera[0] + +FF::Sys::InitTitleScreen.call def tick args args.outputs.background_color = [0,0,0] FelFlame::Stage.call diff --git a/sprites/title/start.png b/sprites/title/start.png Binary files differnew file mode 100644 index 0000000..835f3a7 --- /dev/null +++ b/sprites/title/start.png |
