summaryrefslogtreecommitdiffhomepage
path: root/app/ECS/components
diff options
context:
space:
mode:
Diffstat (limited to 'app/ECS/components')
-rw-r--r--app/ECS/components/00_renderable.rb33
-rw-r--r--app/ECS/components/00_test_component.rb16
-rw-r--r--app/ECS/components/01_based.rb16
-rw-r--r--app/ECS/components/01_sprite.rb49
-rw-r--r--app/ECS/components/02_label.rb32
-rw-r--r--app/ECS/components/03_player_control.rb26
6 files changed, 140 insertions, 32 deletions
diff --git a/app/ECS/components/00_renderable.rb b/app/ECS/components/00_renderable.rb
new file mode 100644
index 0000000..bf944d0
--- /dev/null
+++ b/app/ECS/components/00_renderable.rb
@@ -0,0 +1,33 @@
+class ECS
+ class Components
+ # If an entity can be rendered on screen
+ class Renderable < ECS::BaseComponent
+ def self.id
+ @id ||= ECS::ID.renderable
+ end
+
+ 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
+ end
+ end
+end
diff --git a/app/ECS/components/00_test_component.rb b/app/ECS/components/00_test_component.rb
deleted file mode 100644
index 0906fc8..0000000
--- a/app/ECS/components/00_test_component.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-class ECS
- class Components
- class TestComponent < ECS::BaseComponent
- def self.id
- @id = '0001'.to_i(2)
- end
-
- attr_accessor :x, :y
-
- def initialize(x: 0, y: 0)
- @x = x
- @y = y
- end
- end
- end
-end
diff --git a/app/ECS/components/01_based.rb b/app/ECS/components/01_based.rb
deleted file mode 100644
index fe564ca..0000000
--- a/app/ECS/components/01_based.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-class ECS
- class Components
- class Based < ECS::BaseComponent
- def self.id
- @id = '0010'.to_i(2)
- end
-
- attr_accessor :x, :y
-
- def initialize(x: 0, y:0)
- @x = x
- @y = y
- end
- end
- end
-end
diff --git a/app/ECS/components/01_sprite.rb b/app/ECS/components/01_sprite.rb
new file mode 100644
index 0000000..8172ce5
--- /dev/null
+++ b/app/ECS/components/01_sprite.rb
@@ -0,0 +1,49 @@
+class ECS
+ class Components
+ # If an entity can be rendered on screen
+ class Sprite < ECS::BaseComponent
+ def self.id
+ @id ||= ECS::ID.sprite
+ end
+
+ 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 primative_marker
+ :sprite
+ end
+ end
+ end
+end
diff --git a/app/ECS/components/02_label.rb b/app/ECS/components/02_label.rb
new file mode 100644
index 0000000..c6b8b0b
--- /dev/null
+++ b/app/ECS/components/02_label.rb
@@ -0,0 +1,32 @@
+class ECS
+ class Components
+ # If an entity can be rendered on screen
+ class Label < ECS::BaseComponent
+ def self.id
+ @id ||= ECS::ID.label
+ end
+
+ 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 primative_marker
+ :label
+ end
+ end
+ end
+end
diff --git a/app/ECS/components/03_player_control.rb b/app/ECS/components/03_player_control.rb
new file mode 100644
index 0000000..1e4a348
--- /dev/null
+++ b/app/ECS/components/03_player_control.rb
@@ -0,0 +1,26 @@
+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
+
+ 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 set(north: 'w', south: 's', east: 'd', west: 'a')
+ @north = north
+ @south = south
+ @east = east
+ @west = west
+ end
+ end
+ end
+end