diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/helper.rb | 40 | ||||
| -rw-r--r-- | src/init.rb | 3 | ||||
| -rw-r--r-- | src/logic.rb | 41 |
3 files changed, 76 insertions, 8 deletions
diff --git a/src/helper.rb b/src/helper.rb index 020b2b9..1de57a5 100644 --- a/src/helper.rb +++ b/src/helper.rb @@ -59,3 +59,43 @@ module Helper end end end + +module Math + class <<self + # get a value in between two values + # percent is represented by a decimal + def interpolate(a, b, decimal_percent) + ((b - a) * decimal_percent) + a + end + + def midpoint(a, c) + (a + c) / 2 + end + + def extend(a, b) + (2 * b) - a + end + + def bezier(points, time) + result = 0 + points.each_with_index do |point, index| + result += self.choose(points.length - 1.0, index) * ((1.0 - time) ** (points.length - 1.0 - index)) * (time ** index) * point + end + result + end + + + def choose(n, r) + self.factorial(n).to_f / (self.factorial(r).to_f * self.factorial(n-r).to_f) + end + + def factorial(f) + if (@factorial ||= [1,1])[f].nil? + @factorial[f] = f * factorial(f-1) + else + @factorial[f] + end + end + + end +end diff --git a/src/init.rb b/src/init.rb index 606a596..77441ea 100644 --- a/src/init.rb +++ b/src/init.rb @@ -6,4 +6,5 @@ Rl.target_fps = 60 WHITE = Rl::Color.new(255,255,255,255) BLACK = Rl::Color.new(0,0,0,255) -BLUE = Rl::Color.new(0,0,255,255) +BLUE = Rl::Color.new(0, 121, 241, 255) +RED = Rl::Color.new(230, 41, 55, 255) diff --git a/src/logic.rb b/src/logic.rb index cfc7ca9..f943e44 100644 --- a/src/logic.rb +++ b/src/logic.rb @@ -35,14 +35,15 @@ FECS::Cmp.new('Input', ) FECS::Cmp.new('ScissorBox', :rec) + FECS::Cmp::ScissorBox.new(rec: Rl::Rectangle.new(200,200,250,250)) Input = FECS::Cmp::Input.new lancelot = Tileset.new(texture: Rl::Texture.new('./assets/lancelot_.png')) puts 'about to make rectangles' -8.times do |x| - lancelot.frames.push Rl::Rectangle.new((24 * x), 0, 24, 24) +4.times do |x| + lancelot.frames.push Rl::Rectangle.new((24 * x), 24*2, 24, 24) end puts 'finished making rectangles' @@ -241,7 +242,10 @@ FECS::Scn::Play.add( ent = position_cmp.entity sprite = ent.component[FECS::Cmp::Tileset] hitbox = ent.component[FECS::Cmp::Hitbox] - sprite.tileset.step(4 * Rl.frame_time) + y_vel = ent.component[FECS::Cmp::Velocity].y + x_vel = ent.component[FECS::Cmp::Velocity].x + velocity_mag = Math.sqrt((x_vel**2) + (y_vel**2)) + sprite.tileset.step((velocity_mag*0.04) * Rl.frame_time) if sprite sprite.dest_rec.x = position_cmp.x sprite.dest_rec.y = position_cmp.y @@ -269,6 +273,11 @@ FECS::Scn::Play.add( Rl.draw_text(text: "mouse y: #{Rl.mouse_y}", x: 10, y: 100, font_size: 30, color: BLACK) end, FECS::Sys.new('Render') do + #Rl.scissor_mode( + # x: Math.bezier([200, 200, 1183, 200],(Rl.time/8) % 1)-150, + # y: Math.bezier([200, 1183, 200, 200],(Rl.time/8) % 1)-150, + # width: 300, + # height: 300) do FECS::Cmp::Tileset.each do |sprite_cmp| Rl.draw_texture_pro(texture: sprite_cmp.tileset.texture, origin: sprite_cmp.origin, @@ -277,12 +286,30 @@ FECS::Scn::Play.add( tint: sprite_cmp.tint, rotation: sprite_cmp.rotation) end + # end end, FelECS::Sys.new('DebugRenderHitbox') do - FECS::Cmp::Hitbox.each do |hitbox| - #hitbox.rec.draw(color: BLACK) - hitbox.rec.draw_lines(line_thick: 2, color: BLUE) - end + Rl.scissor_mode( + x: Math.bezier([200, 200, 1183, 200],(Rl.time/8) % 1)-150, + y: Math.bezier([200, 1183, 200, 200],(Rl.time/8) % 1)-150, + width: 300, + height: 300) do + FECS::Cmp::Hitbox.each do |hitbox| + #hitbox.rec.draw(color: BLACK) + hitbox.rec.draw_lines(line_thick: 2, color: BLUE) + end + end + faded_blue = Rl::Color.new(0,121,241,30) + FECS::Cmp::Hitbox.each do |hitbox| + #hitbox.rec.draw(color: BLACK) + hitbox.rec.draw_lines(line_thick: 2, color: faded_blue) + end + + Rl::Rectangle.new( + Math.bezier([200, 200, 1183, 200],(Rl.time/8) % 1)-150, + Math.bezier([200, 1183, 200, 200],(Rl.time/8) % 1)-150, + 300, + 300).draw_lines(line_thick: 3, color: RED) end ) |
