diff options
| -rw-r--r-- | assets/lancelot_.png | bin | 0 -> 4251 bytes | |||
| -rw-r--r-- | main.rb | 30 | ||||
| -rw-r--r-- | src/components/player.rb | 21 | ||||
| -rw-r--r-- | src/systems/systems.rb | 47 |
4 files changed, 98 insertions, 0 deletions
diff --git a/assets/lancelot_.png b/assets/lancelot_.png Binary files differnew file mode 100644 index 0000000..f00e9d4 --- /dev/null +++ b/assets/lancelot_.png @@ -0,0 +1,30 @@ +#Rl.init_window(900, 506, 'Da Game') +puts 'before window' +Rl.init_window(900, 675, 'Da Game') + +puts 'before require' +require './src/components/player.rb' +require './src/systems/systems.rb' +puts 'after require' + +#WHITE = Rl::Color.new(255,255,255,255) +#BLACK = Rl::Color.new(0,0,0,255) +#Lautrec = Rl::Texture.new('./assets/lancelot_.png') +#Lautrec_Source = Rl::Rectangle.new(0,0,24,24) +#Position = Rl::Rectangle.new(0,0,48,48) +#Origin = Rl::Vector2.new(0,0) + +#Rl.init_audio_device if Rl.platform == 'web' + +Rl.while_window_open do + + Rl.draw(clear_color: WHITE) do + #Rl.draw_texture_pro(texture: Lautrec, origin: Origin, source: Lautrec_Source, dest: Position) + #draw_texture_pro(texture:, source:, dest:, origin: Rl::Vector.new(0,0), rotation: 0, tint: Rl::Color.new(255,255,255,255)) + puts 'start stage' + FECS::Stage.call + puts 'end stage' + end +end + + diff --git a/src/components/player.rb b/src/components/player.rb new file mode 100644 index 0000000..1a6e9b6 --- /dev/null +++ b/src/components/player.rb @@ -0,0 +1,21 @@ +FECS::Cmp.new('Player') +FECS::Cmp.new('Velocity', x: 0, y: 0) +FECS::Cmp.new('Position', x: 0, y: 0) +FECS::Cmp.new('Sprite', + :texture, + :origin, + :source_rect, + :dest_rect, + :rotation) +FECS::Cmp.new('Hp', value: 0) + +@player = FECS::Ent.new(FECS::Cmp::Player.new, + FECS::Cmp::Position.new, + FECS::Cmp::Velocity.new, + FECS::Cmp::Sprite.new( + texture: Rl::Texture.new('./assets/lancelot_.png'), + source_rect: Rl::Rectangle.new(0,0,24,24), + dest_rect: Rl::Rectangle.new(0,0,48,48))) + + + diff --git a/src/systems/systems.rb b/src/systems/systems.rb new file mode 100644 index 0000000..6bcffa9 --- /dev/null +++ b/src/systems/systems.rb @@ -0,0 +1,47 @@ +FECS::Stg.add(FECS::Scn.new('Play')) + +FECS::Scn::Play.add( + FECS::Sys.new('PlayerInput') do + puts 'start player input' + ent = FECS::Cmp::Player.first.entity + velocity_component = ent.component[FECS::Cmp::Velocity] + velocity_component.x = 0 + velocity_component.y = 0 + velocity_component.y -= 10 if Rl.key_down? 87 + velocity_component.y += 10 if Rl.key_down? 83 + velocity_component.x -= 10 if Rl.key_down? 65 + velocity_component.x += 10 if Rl.key_down? 68 + puts 'end player input' + end, + FECS::Sys.new('Movement') do + FECS::Cmp::Velocity.each do |velocity_component| + position_component = velocity_component.entity.component[FECS::Cmp::Position] + position_component.x += velocity_component.x + position_component.y += velocity_component.y + end + end, + FECS::Sys.new('TakePosition') do + FECS::Cmp::Position.each do |position_cmp| + sprite = position_cmp.entity.component[FECS::Cmp::Sprite] + if sprite + sprite.dest_rect.x = position_cmp.x + sprite.dest_rect.y = position_cmp.y + end + end + end, + FECS::Sys.new('Render') do + FECS::Cmp::Sprite.each do |sprite_cmp| + #Rl.draw_texture_pro(texture: sprite_cmp.texture, + # origin: sprite_cmp.origin_rect, + # source_rect: sprite_cmp.source_rect, + # dest_rect: sprite_cmp.dest_rect) + end + end, +) + +FelECS::Order.sort( + FECS::Sys::PlayerInput, + FECS::Sys::Movement, + FECS::Sys::TakePosition, + FECS::Sys::Render, +) |
