summaryrefslogtreecommitdiffhomepage
path: root/app/ECS/components
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-05-18 04:49:47 -0400
committerrealtradam <[email protected]>2021-05-18 04:49:47 -0400
commit120b693ffd02bc5c7f41ff2b9657facc7117daae (patch)
tree59e9f982dc2ee994cbbb65411065b35445048502 /app/ECS/components
parent24524ad0b1c7a2aeea0bad28092e946cef8026fa (diff)
downloadtypemon-code-120b693ffd02bc5c7f41ff2b9657facc7117daae.tar.gz
typemon-code-120b693ffd02bc5c7f41ff2b9657facc7117daae.zip
.
Diffstat (limited to 'app/ECS/components')
-rw-r--r--app/ECS/components/00_renderable.rb35
-rw-r--r--app/ECS/components/01_sprite.rb81
-rw-r--r--app/ECS/components/02_label.rb47
-rw-r--r--app/ECS/components/03_player_control.rb36
4 files changed, 80 insertions, 119 deletions
diff --git a/app/ECS/components/00_renderable.rb b/app/ECS/components/00_renderable.rb
index bf944d0..18017cc 100644
--- a/app/ECS/components/00_renderable.rb
+++ b/app/ECS/components/00_renderable.rb
@@ -1,33 +1,10 @@
-class ECS
- class Components
- # If an entity can be rendered on screen
- class Renderable < ECS::BaseComponent
- def self.id
- @id ||= ECS::ID.renderable
- end
+class Components
+ # If an entity can be rendered on screen
+ class Renderable < BaseComponent
+ attr_accessor :z
- attr_accessor :z
-
- def initialize(z: 0)
- @z = z
- end
-=begin
- # 1. Create a serialize method that returns a hash with all of
- # the values you care about.
- def serialize
- { z: z }
- end
-
- # 2. Override the inspect method and return ~serialize.to_s~.
- def inspect
- serialize.to_s
- end
-
- # 3. Override to_s and return ~serialize.to_s~.
- def to_s
- serialize.to_s
- end
-=end
+ def initialize(z: 0)
+ @z = z
end
end
end
diff --git a/app/ECS/components/01_sprite.rb b/app/ECS/components/01_sprite.rb
index 8172ce5..5aa71ba 100644
--- a/app/ECS/components/01_sprite.rb
+++ b/app/ECS/components/01_sprite.rb
@@ -1,49 +1,44 @@
-class ECS
- class Components
- # If an entity can be rendered on screen
- class Sprite < ECS::BaseComponent
- def self.id
- @id ||= ECS::ID.sprite
- end
+class Components
+ # If an entity can be rendered on screen
+ class Sprite < 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
+ 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,
- @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]
- end
+ 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
+ def primative_marker
+ :sprite
end
end
end
diff --git a/app/ECS/components/02_label.rb b/app/ECS/components/02_label.rb
index c6b8b0b..2483d57 100644
--- a/app/ECS/components/02_label.rb
+++ b/app/ECS/components/02_label.rb
@@ -1,32 +1,27 @@
-class ECS
- class Components
- # If an entity can be rendered on screen
- class Label < ECS::BaseComponent
- def self.id
- @id ||= ECS::ID.label
- end
+class Components
+ # A dragonruby label wrapper
+ class Label < BaseComponent
- attr_accessor :x, :y, :text, :size_enum, :alignment_enum,
- :a, :r, :g, :b, :font, :vertical_alignment_enum
+ 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,
- @y = y,
- @text = text,
- @size_enum = size_enum,
- @alignment_enum = alignment_enum,
- @r = r,
- @g = g,
- @b = b,
- @a = a,
- @font = font,
- @vertical_alignment_enum = vertical_alignment_enum]
- end
+ 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,
+ @y = y,
+ @text = text,
+ @size_enum = size_enum,
+ @alignment_enum = alignment_enum,
+ @r = r,
+ @g = g,
+ @b = b,
+ @a = a,
+ @font = font,
+ @vertical_alignment_enum = vertical_alignment_enum]
+ end
- def primative_marker
- :label
- end
+ def primative_marker
+ :label
end
end
end
diff --git a/app/ECS/components/03_player_control.rb b/app/ECS/components/03_player_control.rb
index 1e4a348..22bc458 100644
--- a/app/ECS/components/03_player_control.rb
+++ b/app/ECS/components/03_player_control.rb
@@ -1,26 +1,20 @@
-class ECS
- class Components
- # If an entity can be rendered on screen
- class PlayerControl < ECS::BaseComponent
- def self.id
- @id ||= ECS::ID.player_control
- end
+class Components
+ # Gives control(keyboard or otherwise) over an object
+ class PlayerControl < BaseComponent
+ attr_accessor :north, :south, :east, :west
- attr_accessor :north, :south, :east, :west
-
- def initialize(north: 'w', south: 's', east: 'd', west: 'a')
- @north = north
- @south = south
- @east = east
- @west = west
- end
+ def initialize(north: 'w', south: 's', east: 'd', west: 'a')
+ @north = north
+ @south = south
+ @east = east
+ @west = west
+ end
- def set(north: 'w', south: 's', east: 'd', west: 'a')
- @north = north
- @south = south
- @east = east
- @west = west
- end
+ def set(north: 'w', south: 's', east: 'd', west: 'a')
+ @north = north
+ @south = south
+ @east = east
+ @west = west
end
end
end