diff options
| author | arngo <[email protected]> | 2022-01-29 00:21:25 -0500 |
|---|---|---|
| committer | arngo <[email protected]> | 2022-01-29 00:23:19 -0500 |
| commit | fe619e4f748ab38a128d80adaa013854d78e4a2f (patch) | |
| tree | 23f40811323aa92809c5e4ac5ac89670d461af4e /src | |
| parent | 99712a57accbb26fa6ad1b62deac035348b2818c (diff) | |
| download | orc-arena-of-time-fe619e4f748ab38a128d80adaa013854d78e4a2f.tar.gz orc-arena-of-time-fe619e4f748ab38a128d80adaa013854d78e4a2f.zip | |
main menu
Diffstat (limited to 'src')
| -rw-r--r-- | src/logic.rb | 51 | ||||
| -rw-r--r-- | src/menu.rb | 41 |
2 files changed, 90 insertions, 2 deletions
diff --git a/src/logic.rb b/src/logic.rb index a8b076b..8519e9f 100644 --- a/src/logic.rb +++ b/src/logic.rb @@ -209,8 +209,53 @@ Resetting = false ScissorPath = 10000 ScissorSize = 1 -FECS::Stg.add(FECS::Scn.new('Play')) +FECS::Scn.new('Menu') +FECS::Scn::Menu.add( + FECS::Sys.new('Button') do + FECS::Cmp::Button.each do |button| + ent = button.entity + sprite = ent.component[FECS::Cmp::Sprite] + hitbox = ent.component[FECS::Cmp::Hitbox] + if button.clicked + sprite.texture = button.pressed_texture + else + sprite.texture = button.unpressed_texture + end + if hitbox.rec.collide_with_point? Rl.mouse_position + if Rl.mouse_button_down? 0 + button.clicked = true + elsif Rl.mouse_button_up? 0 and button.clicked + button.clicked = false + FECS::Sys::DestroyTitleScreen.call + end + else + button.clicked = false + end + end + end, + FECS::Sys.new('RenderMenu') do + FECS::Cmp::Sprite.each do |sprite_cmp| + Rl.draw_texture_pro(texture: sprite_cmp.texture, + origin: Rl::Vector2.new(0,0), + source_rec: sprite_cmp.source_rec, + dest_rec: sprite_cmp.dest_rec) + end + end, + FECS::Sys.new('ApplyPositionToSprite') do + FECS::Cmp::Position.each do |position_cmp| + ent = position_cmp.entity + next if ent.components[FECS::Cmp::Sprite].nil? + sprite = ent.component[FECS::Cmp::Sprite] + hitbox = ent.component[FECS::Cmp::Hitbox] + sprite.dest_rec.x = position_cmp.x + sprite.dest_rec.y = position_cmp.y + hitbox.rec.x = position_cmp.x + hitbox.offset_x + hitbox.rec.y = position_cmp.y + hitbox.offset_y + end + end, +) +FECS::Scn.new('Play') FECS::Scn::Play.add( FECS::Sys.new('Music') do puts 'check web' @@ -877,7 +922,9 @@ FECS::Scn::Play.add( end ) -CurrentLevel.level = 0 +#CurrentLevel.level = 0 +FECS::Sys::ConstructTitleScreen.call +FECS::Stg.add(FECS::Scn::Menu) FelECS::Order.sort( FECS::Sys::PlayerInput, diff --git a/src/menu.rb b/src/menu.rb new file mode 100644 index 0000000..e822d50 --- /dev/null +++ b/src/menu.rb @@ -0,0 +1,41 @@ +FECS::Cmp.new('Button', + :unpressed_texture, + :pressed_texture, + clicked: false) + +FECS::Sys.new('ConstructTitleScreen') do + ent = FECS::Ent.new( + FECS::Cmp::Button.new( + unpressed_texture: Rl::Texture.new('./assets/start-button.png'), + pressed_texture: Rl::Texture.new('./assets/start-button-pressed.png') + ), + FECS::Cmp::Hitbox.new( + rec: Rl::Rectangle.new(0,0,204,42), + ), + FECS::Cmp::Sprite.new( + source_rec: Rl::Rectangle.new(0,0,102,21), + dest_rec: Rl::Rectangle.new(0,0,204,42), + ), + FECS::Cmp::Position.new(x: 450-102, y: 340) + ) + MapTexture.texture = Rl::Texture.new('./assets/menu-bg.png') + MapTexture.source_rec = Rl::Rectangle.new(0,0,125,125) + MapTexture.dest_rec = Rl::Rectangle.new(325,212,250,250) +end + +FECS::Sys.new('DestroyTitleScreen') do + FECS::Cmp::Button.reverse_each do |btn| + btn_ent = btn.entity + btn_ent.components.each do |mgr, arry| + arry.reverse_each do |cmp| + puts cmp + cmp.delete + end + end + btn_ent.delete + end + FECS::Stg.remove(FECS::Scn::Menu) + FECS::Stg.add(FECS::Scn::Play) + CurrentLevel.level = 0 +end + |
