Class: LZRTag::Player::Effects

Inherits:
Hardware show all
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

Life

Instance Attribute Summary collapse

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

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

#heartbeatObject

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

#markedObject

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_topicsObject



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.

Parameters:

  • hitLength (Numeric, nil) (defaults to: nil)

    Length (in s) of the hit.



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.

Parameters:

  • duration (Numeric) (defaults to: 0.5)

    Length in seconds

  • frequency (Numeric) (defaults to: 440)

    Frequency of the note

  • volume (Numeric) (defaults to: 0.5)

    Volume (0..1) of the note



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

Parameters:

  • duration (Numeric)

    Number (in s) to vibrate for.

Raises:

  • (ArgumentError)


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