Class: Rubygame::EventTriggers::AndTrigger

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygame/event_triggers.rb

Overview

AndTrigger is an event trigger which contains one or more other triggers, and fires when an event matches all of its triggers. You can use this to create more complex logic than is possible with a single trigger.

Contrast with OrTrigger.

Instance Method Summary collapse

Constructor Details

#initialize(*triggers) ⇒ AndTrigger

Initialize a new instance of AndTrigger, containing the given triggers.

*triggers

The triggers to contain. (Array of triggers, required)

Example:

gameover_trigger = InstanceOfTrigger.new( GameOver )
won_trigger = AttrTrigger.new( :won_game => true )

# Matches only an event which is BOTH:
#  1. an instance of class GameOver, AND
#  2. returns true when #won_game is called
AndTrigger.new( gameover_trigger, won_trigger )


110
111
112
# File 'lib/rubygame/event_triggers.rb', line 110

def initialize( *triggers )
	@triggers = triggers
end

Instance Method Details

#match?(event) ⇒ Boolean

Returns true if the event matches all the triggers that the AndTrigger contains.

Returns:

  • (Boolean)


117
118
119
# File 'lib/rubygame/event_triggers.rb', line 117

def match?( event )
	@triggers.all? { |trigger| trigger.match? event }
end