From f97a9ca95e464e728bba9337b579bc380c33bc7d Mon Sep 17 00:00:00 2001 From: realtradam Date: Thu, 20 May 2021 05:04:21 -0400 Subject: implemented hitboxes --- app/lib/components/00_renderable.rb | 16 ++++++++++++ app/lib/components/01_sprite.rb | 44 +++++++++++++++++++++++++++++++++ app/lib/components/02_label.rb | 27 ++++++++++++++++++++ app/lib/components/03_player_control.rb | 21 ++++++++++++++++ app/lib/components/04_map.rb | 21 ++++++++++++++++ app/lib/components/05_interactable.rb | 16 ++++++++++++ app/lib/components/06_collidable.rb | 22 +++++++++++++++++ app/lib/components/07_battle.rb | 4 +++ app/lib/components/07_indoor.rb | 4 +++ app/lib/components/07_overworld.rb | 16 ++++++++++++ app/lib/components/debug_singleton.rb | 13 ++++++++++ 11 files changed, 204 insertions(+) create mode 100644 app/lib/components/00_renderable.rb create mode 100644 app/lib/components/01_sprite.rb create mode 100644 app/lib/components/02_label.rb create mode 100644 app/lib/components/03_player_control.rb create mode 100644 app/lib/components/04_map.rb create mode 100644 app/lib/components/05_interactable.rb create mode 100644 app/lib/components/06_collidable.rb create mode 100644 app/lib/components/07_battle.rb create mode 100644 app/lib/components/07_indoor.rb create mode 100644 app/lib/components/07_overworld.rb create mode 100644 app/lib/components/debug_singleton.rb (limited to 'app/lib/components') diff --git a/app/lib/components/00_renderable.rb b/app/lib/components/00_renderable.rb new file mode 100644 index 0000000..3971c8c --- /dev/null +++ b/app/lib/components/00_renderable.rb @@ -0,0 +1,16 @@ +class Components + # If an entity can be rendered on screen + class Renderable < Helper::BaseComponent + attr_accessor :z + + def initialize + @z = 0 + end + + def set(**opts) + opts.each do |key, value| + self.send "#{key}=", value + end + end + end +end diff --git a/app/lib/components/01_sprite.rb b/app/lib/components/01_sprite.rb new file mode 100644 index 0000000..8d30cdf --- /dev/null +++ b/app/lib/components/01_sprite.rb @@ -0,0 +1,44 @@ +class Components + # If an entity can be rendered on screen + class Sprite < Helper::BaseComponent + + attr_accessor :x, :y, :w, :h, :path, :angle, :a, :r, :g, :b, + :source_x, :source_y, :source_w, :source_h, + :tile_x, :tile_y, :tile_w, :tile_h, + :flip_horizontally, :flip_vertically, + :angle_anchor_x, :angle_anchor_y + + def set(x: @x, y: @y, w: @w, h: @h, path: @path, angle: @angle, a: @a, r: @r, g: @g, b: @b, + source_x: @source_x, source_y: @source_y, source_w: @source_w, source_h: @source_h, + tile_x: @tile_x, tile_y: @tile_y, tile_w: @tile_w, tile_h: @tile_h, + flip_horizontally: @flip_horizontally, flip_vertically: @flip_vertically, + angle_anchor_x: @angle_anchor_x, angle_anchor_y: @angle_anchor_y) + {x: @x = x, + y: @y = y, + w: @w = w, + h: @h = h, + path: @path = path, + angle: @angle = angle, + a: @a = a, + r: @r = r, + g: @g = g, + b: @b = b, + source_x: @source_x = source_x, + source_y: @source_y = source_y, + source_w: @source_w = source_w, + source_h: @source_h = source_h, + tile_x: @tile_x = tile_x, + tile_y: @tile_y = tile_y, + tile_w: @tile_w = tile_w, + tile_h: @tile_h = tile_h, + flip_horizontally: @flip_horizontally = flip_horizontally, + flip_vertically: @flip_vertically = flip_vertically, + angle_anchor_x: @angle_anchor_x = angle_anchor_x, + angle_anchor_y: @angle_anchor_y = angle_anchor_y} + end + + def primative_marker + :sprite + end + end +end diff --git a/app/lib/components/02_label.rb b/app/lib/components/02_label.rb new file mode 100644 index 0000000..13544b7 --- /dev/null +++ b/app/lib/components/02_label.rb @@ -0,0 +1,27 @@ +class Components + # A dragonruby label wrapper + class Label < Helper::BaseComponent + + attr_accessor :x, :y, :text, :size_enum, :alignment_enum, + :a, :r, :g, :b, :font, :vertical_alignment_enum + + def set(x: @x, y: @y, text: @text, size_enum: @size_enum, alignment_enum: @alignment_enum, + a: @a, r: @r, g: @g, b: @b, font: @font, vertical_alignment_enum: @vertical_alignment_enum) + {x: @x = x, + y: @y = y, + text: @text = text, + size_enum: @size_enum = size_enum, + alignment_enum: @alignment_enum = alignment_enum, + r: @r = r, + g: @g = g, + b: @b = b, + a: @a = a, + font: @font = font, + vertical_alignment_enum: @vertical_alignment_enum = vertical_alignment_enum } + end + + def primative_marker + :label + end + end +end diff --git a/app/lib/components/03_player_control.rb b/app/lib/components/03_player_control.rb new file mode 100644 index 0000000..d5d8f7a --- /dev/null +++ b/app/lib/components/03_player_control.rb @@ -0,0 +1,21 @@ +class Components + # Gives control(keyboard or otherwise) over an object + class PlayerControl < Helper::BaseComponent + attr_accessor :north, :south, :east, :west, :interact, :menu + + def initialize + @north = 'up' + @south = 'down' + @east = 'right' + @west = 'left' + @interact = 'space' + @menu = 'enter' + end + + def set(**opts) + opts.each do |key, value| + send "#{key}=", value + end + end + end +end diff --git a/app/lib/components/04_map.rb b/app/lib/components/04_map.rb new file mode 100644 index 0000000..7700e9f --- /dev/null +++ b/app/lib/components/04_map.rb @@ -0,0 +1,21 @@ +class Components + # dragonruby label wrapper + class Map < Helper::BaseComponent + + attr_accessor :json_name, :json, :x, :y, :tilewidth, :tileheight, :a, :r, :g, :b + + def set(json_name: @json_name, x: @x, y: @y, tilewidth: @tilewidth, + tileheight: @tileheight, a: @a, r: @r, g: @g, b: @b) + { json_name: @json_name = json_name, + json: @json = Helper.get_json_tiles(json_name), + x: @x = x, + y: @y = y, + tilewidth: @tilewidth = tilewidth, + tileheight: @tileheight = tileheight, + r: @r = r, + g: @g = g, + b: @b = b, + a: @a = a } + end + end +end diff --git a/app/lib/components/05_interactable.rb b/app/lib/components/05_interactable.rb new file mode 100644 index 0000000..636a216 --- /dev/null +++ b/app/lib/components/05_interactable.rb @@ -0,0 +1,16 @@ +class Components + # If an entity can be rendered on screen + class Interactable < Helper::BaseComponent + attr_accessor :z + + def initialize + @z = z + end + + def set(**opts) + opts.each do |key, value| + self.send "#{key}=", value + end + end + end +end diff --git a/app/lib/components/06_collidable.rb b/app/lib/components/06_collidable.rb new file mode 100644 index 0000000..76ce51e --- /dev/null +++ b/app/lib/components/06_collidable.rb @@ -0,0 +1,22 @@ +class Components + # If an entity can be rendered on screen + class Collidable < Helper::BaseComponent + class <