diff options
| author | arngo <[email protected]> | 2021-12-18 22:10:28 -0500 |
|---|---|---|
| committer | arngo <[email protected]> | 2021-12-18 22:10:28 -0500 |
| commit | 43a07949acca8a11a3aee6ea915a9a3e00b373ab (patch) | |
| tree | 8f6e1bba2e025dd11bffda46bd46b29535580be9 /app | |
| parent | b04f361c9430a3a3c29ef63a43884db0d168a808 (diff) | |
| download | SteelWings-43a07949acca8a11a3aee6ea915a9a3e00b373ab.tar.gz SteelWings-43a07949acca8a11a3aee6ea915a9a3e00b373ab.zip | |
implement button components and title screen
Diffstat (limited to 'app')
| -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 | 51 |
8 files changed, 130 insertions, 27 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 6b3abe6..9a55c97 100644 --- a/app/main.rb +++ b/app/main.rb @@ -4,12 +4,17 @@ 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' require 'app/components/rules/separation.rb' require 'app/components/debug/debug_vector_arrow.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 11a47a5..2a05891 100644 --- a/app/tick.rb +++ b/app/tick.rb @@ -1,25 +1,25 @@ -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 +#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::Ent.new( # FF::Cmp::Sprite.new, # FF::Cmp::Boid.new(x: 150, y: 250), @@ -29,9 +29,10 @@ end # #FF::Cmp::BoidsCohesion.new, # debug_arrow, #) -FF::Scn::Debug.add(FF::Sys::DebugRenderVectorArrow) -@pause = true -FF::Stg.remove FF::Scn::BoidRules +#FF::Scn::Debug.add(FF::Sys::DebugRenderVectorArrow) +#@pause = true +#FF::Stg.remove FF::Scn::BoidRules +FF::Sys::InitTitleScreen.call def tick args args.outputs.background_color = [0,0,0] FelFlame::Stage.call |
