Class: Quake::Entity
- Inherits:
-
Object
- Object
- Quake::Entity
- Defined in:
- lib/quake/entity.rb
Overview
Represents a parsed entity from the BSP entities lump. All Quake entities (players, monsters, items, triggers, brush models) are defined as key-value property bags in the BSP entity string.
Instance Attribute Summary collapse
-
#angle ⇒ Object
Returns the value of attribute angle.
-
#angles ⇒ Object
Returns the value of attribute angles.
-
#classname ⇒ Object
Returns the value of attribute classname.
-
#health ⇒ Object
Returns the value of attribute health.
-
#lip ⇒ Object
Returns the value of attribute lip.
-
#message ⇒ Object
Returns the value of attribute message.
-
#model_index ⇒ Object
Returns the value of attribute model_index.
-
#move_dir ⇒ Object
Returns the value of attribute move_dir.
-
#position ⇒ Object
Returns the value of attribute position.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#sounds ⇒ Object
Returns the value of attribute sounds.
-
#speed ⇒ Object
Returns the value of attribute speed.
-
#state ⇒ Object
Returns the value of attribute state.
-
#target ⇒ Object
Returns the value of attribute target.
-
#targetname ⇒ Object
Returns the value of attribute targetname.
-
#think_time ⇒ Object
Returns the value of attribute think_time.
-
#wait ⇒ Object
Returns the value of attribute wait.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #brush_entity? ⇒ Boolean
-
#forward_vector ⇒ Object
Direction vector from the “angle” field (Quake convention).
-
#initialize(properties = {}) ⇒ Entity
constructor
A new instance of Entity.
Constructor Details
#initialize(properties = {}) ⇒ Entity
Returns a new instance of Entity.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/quake/entity.rb', line 13 def initialize(properties = {}) @properties = properties @classname = properties["classname"] || "" # Parse common fields @position = parse_vec3(properties["origin"]) || Math::Vec3::ORIGIN @angle = (properties["angle"] || "0").to_f @angles = parse_vec3(properties["angles"]) || Math::Vec3::ORIGIN # Brush model reference: "*1", "*2", etc. @model_index = nil if (model_str = properties["model"]) @model_index = model_str[1..].to_i if model_str.start_with?("*") end # Targeting @target = properties["target"] @targetname = properties["targetname"] # Movement/behavior @speed = (properties["speed"] || default_speed).to_f @wait = (properties["wait"] || "3").to_f @lip = (properties["lip"] || "8").to_f @health = (properties["health"] || "0").to_f @sounds = (properties["sounds"] || "0").to_i @message = properties["message"] # Runtime state @state = :idle @think_time = 0.0 @move_dir = Math::Vec3::ORIGIN end |
Instance Attribute Details
#angle ⇒ Object
Returns the value of attribute angle.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def angle @angle end |
#angles ⇒ Object
Returns the value of attribute angles.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def angles @angles end |
#classname ⇒ Object
Returns the value of attribute classname.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def classname @classname end |
#health ⇒ Object
Returns the value of attribute health.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def health @health end |
#lip ⇒ Object
Returns the value of attribute lip.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def lip @lip end |
#message ⇒ Object
Returns the value of attribute message.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def @message end |
#model_index ⇒ Object
Returns the value of attribute model_index.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def model_index @model_index end |
#move_dir ⇒ Object
Returns the value of attribute move_dir.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def move_dir @move_dir end |
#position ⇒ Object
Returns the value of attribute position.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def position @position end |
#properties ⇒ Object
Returns the value of attribute properties.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def properties @properties end |
#sounds ⇒ Object
Returns the value of attribute sounds.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def sounds @sounds end |
#speed ⇒ Object
Returns the value of attribute speed.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def speed @speed end |
#state ⇒ Object
Returns the value of attribute state.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def state @state end |
#target ⇒ Object
Returns the value of attribute target.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def target @target end |
#targetname ⇒ Object
Returns the value of attribute targetname.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def targetname @targetname end |
#think_time ⇒ Object
Returns the value of attribute think_time.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def think_time @think_time end |
#wait ⇒ Object
Returns the value of attribute wait.
8 9 10 |
# File 'lib/quake/entity.rb', line 8 def wait @wait end |
Instance Method Details
#[](key) ⇒ Object
46 |
# File 'lib/quake/entity.rb', line 46 def [](key) = @properties[key] |
#brush_entity? ⇒ Boolean
48 |
# File 'lib/quake/entity.rb', line 48 def brush_entity? = !@model_index.nil? |
#forward_vector ⇒ Object
Direction vector from the “angle” field (Quake convention)
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/quake/entity.rb', line 51 def forward_vector case @angle.to_i when -1 # UP Math::Vec3.new(0.0, 0.0, 1.0) when -2 # DOWN Math::Vec3.new(0.0, 0.0, -1.0) else rad = @angle * ::Math::PI / 180.0 Math::Vec3.new(::Math.cos(rad), ::Math.sin(rad), 0.0) end end |