Exemple #1
0
int Emitter::eventHandler( const df::Event *event ) {
	if ( event->getType( ) == df::STEP_EVENT ) {
		df::Position pos = this->getPosition( );
		switch ( this->getDirection( ) ) {
		case UP:
			pos.setY( pos.getY( ) - 1 );
			break;
		case DOWN:
			pos.setY( pos.getY( ) + 1 );
			break;
		case LEFT:
			pos.setX( pos.getX( ) - 1 );
			break;
		case RIGHT:
			pos.setX( pos.getX( ) + 1 );
			break;
		default:
			break;
		}
		Laser* laser = new Laser( this->getColor( ), this->getDirection( ) );
		laser->setPosition( pos );
		return 1;
	}
	return Component::eventHandler( event );
}
Exemple #2
0
int Lens::eventHandler( const df::Event* evt ) {
  // Reset the output color on step
  if (evt->getType() == df::STEP_EVENT) {
    if (this->color != laser::BLACK) {
      Laser* laser = new Laser(this->color, getDirection());
      laser->setPosition(getPosition());
      this->color = laser::BLACK;
    }
    return 1;
  }
  return Component::eventHandler(evt);
}