Class: LZRTag::Player::Effects
- Defined in:
- lib/lzrtag/player/effects_player.rb
Overview
This class extends the pure hardware class, adding various hooks that can be used to send effects and other events to the weapon. These do not change the game itself, but instead just look and feel good!
Direct Known Subclasses
Instance Attribute Summary collapse
-
#heartbeat ⇒ Object
Heartbeat status of the player The “heartbeat” is a regular vibration pattern on the weapon, which can be used to indicate things like low life or other tense events.
-
#marked ⇒ Object
Mark a player in a given color This function can be used to “mark” a player, sending flashes of light across their LEDs in a given color.
Attributes inherited from Hardware
#ammo, #battery, #brightness, #dead, #deathChangeTime, #gunNo, #gyroPose, #heap, #maxAmmo, #ping, #team
Attributes inherited from Base
#DeviceID, #handler, #hitIDTimetable, #id, #name, #status
Instance Method Summary collapse
- #clear_all_topics ⇒ Object
-
#hit(hitLength = nil) ⇒ Object
Make the weapon display a hit.
-
#initialize(*data) ⇒ Effects
constructor
A new instance of Effects.
-
#noise(duration: 0.5, frequency: 440, volume: 0.5) ⇒ Object
Make the weapon play a given note.
-
#sound(sName) ⇒ Object
Play a given sound file.
-
#vibrate(duration) ⇒ Object
Vibrate the weapon for a number of seconds.
Methods inherited from Hardware
#_set_dead, getBrightnessKeys, #gunDamage, #kill_by, #on_mqtt_data, #revive_by
Methods inherited from Base
#connected?, #inspect, #on_mqtt_data
Constructor Details
#initialize(*data) ⇒ Effects
Returns a new instance of Effects.
23 24 25 26 27 |
# File 'lib/lzrtag/player/effects_player.rb', line 23 def initialize(*data) super(*data); @marked = false; end |
Instance Attribute Details
#heartbeat ⇒ Object
Heartbeat status of the player The “heartbeat” is a regular vibration pattern on the weapon, which can be used to indicate things like low life or other tense events. Set it to true/false.
14 15 16 |
# File 'lib/lzrtag/player/effects_player.rb', line 14 def heartbeat @heartbeat end |
#marked ⇒ Object
Mark a player in a given color This function can be used to “mark” a player, sending flashes of light across their LEDs in a given color. This can either be false, to turn the marking off, or 0..7 to set it to a team color. Alternatively, any RGB Number (0x?? ?? ??) can be used for arbitrary marking color
21 22 23 |
# File 'lib/lzrtag/player/effects_player.rb', line 21 def marked @marked end |
Instance Method Details
#clear_all_topics ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/lzrtag/player/effects_player.rb', line 87 def clear_all_topics() super(); ["CFG/Heartbeat", "CFG/Marked"].each do |t| _pub_to(t, "", retain: true) end end |
#hit(hitLength = nil) ⇒ Object
Make the weapon display a hit. When a weapon is hit, it will flash bright white and vibrate for a short moment. The length can be specified.
82 83 84 |
# File 'lib/lzrtag/player/effects_player.rb', line 82 def hit(hitLength = nil) _pub_to("CFG/Hit", hitLength || 0.7) end |
#noise(duration: 0.5, frequency: 440, volume: 0.5) ⇒ Object
Make the weapon play a given note. This function can make the set play a note of given frequency, volume and duration.
60 61 62 63 |
# File 'lib/lzrtag/player/effects_player.rb', line 60 def noise(duration: 0.5, frequency: 440, volume: 0.5) return false unless duration.is_a? Numeric and frequency.is_a? Integer _pub_to("Sound/Note", [frequency, volume*20000, duration*1000].pack("L3")) end |
#sound(sName) ⇒ Object
Play a given sound file. Depending on the weapon, various sounds are available to be played, such as:
-
“GAME START”
-
“HIT”
-
“OWN DEATH”
-
“KILL SCORE”
etc. This list may be expanded in the future
74 75 76 |
# File 'lib/lzrtag/player/effects_player.rb', line 74 def sound(sName) _pub_to("Sound/File", sName); end |
#vibrate(duration) ⇒ Object
Vibrate the weapon for a number of seconds
31 32 33 34 |
# File 'lib/lzrtag/player/effects_player.rb', line 31 def vibrate(duration) raise ArgumentError, "Vibration-duration out of range (between 0 and 65.536)" unless duration.is_a? Numeric and duration <= 65.536 and duration >= 0 _pub_to("CFG/Vibrate", duration); end |