Ejemplo n.º 1
0
// Message passing routine, used to send and receive a typed message
// Useful for checking the packing and unpacking of message data.
void fakeMessagePassing(TypedMessage &send, TypedMessage &recv)
{
  const int tcpPort = TEST_PORT_BASE+401;
  char ipAddr[] = "127.0.0.1";

  TcpClient tcpClient;
  TcpServer tcpServer;
  SimpleMessage msgSend, msgRecv;

  send.toTopic(msgSend);

  // Construct server

  tcpServer.init(tcpPort);

  // Construct a client
  tcpClient.init(&ipAddr[0], tcpPort);
  tcpClient.makeConnect();  // make tcp client connection

  tcpServer.makeConnect();      // make tcp server connection

  tcpClient.sendMsg(msgSend);   // send message
  tcpServer.receiveMsg(msgRecv); // physically receive message
  recv.init(msgRecv); // copy received message into reference
}
Ejemplo n.º 2
0
void AntColony::ReceiveMessage(Message *m) {
    if(m->GetMessageName() == "SpawnAnt") {
        TypedMessage<std::string> *tmp = (TypedMessage<std::string> *) m;
        if(tmp != NULL && ((std::string) tmp->GetValue()) == this->name) {
            this->_spawning = false;
            this->SpawnAnt();
        }
    }
}
Ejemplo n.º 3
0
void MazeFinder::ReceiveMessage(Message *message)
{
	if (message->GetMessageName() == "MazeFinderPathPointReached")
	{
		if (_pathIndex < _pathPoints.size() - 1)
		{
			GetToNextPoint();
		}
	}
	else if (message->GetMessageName() == "MouseDown")
	{
		TypedMessage<Vec2i> *m = (TypedMessage<Vec2i>*)message;
		Vec2i screenCoordinates = m->GetValue();
		Vector2 worldCoordinates = MathUtil::ScreenToWorld(screenCoordinates);
		GoTo(worldCoordinates);
	}
}
Ejemplo n.º 4
0
void MagicTower::ReceiveMessage(Message *message) {
    if (message->GetMessageName() == "Tick") {
        ticks++;
        if (ticks == thePrefs.GetFloat("TowerSettings", "MagicTime")) {
            attack();
            ticks = 0;
        }
    }
    if (message->GetMessageName() == "MouseDown")
    {
        TypedMessage<Vec2i> *m = (TypedMessage<Vec2i>*)message;
        Vec2i screenCoordinates = m->GetValue();
        Vector2 click = MathUtil::ScreenToWorld(screenCoordinates);
        Vector2 position = GetPosition();
        Vector2 size = GetSize();
        if ((click.X < position.X + size.X/2.0) && (click.X > position.X - size.X/2.0) && (click.Y < position.Y + size.Y/2.0) && (click.Y > position.Y - size.Y/2.0)) {
            level_up();
        }
    }
}
Ejemplo n.º 5
0
void
Snake::handleCollision(Message* m)
{
    TypedMessage<std::set<Actor*> >* msg = static_cast<TypedMessage<std::set<Actor*> >* >(m);
    
    std::set<Actor*> collisions = msg->GetValue();
    
    std::set<Actor*>::iterator it = collisions.find(this);
    if(it != collisions.end())
    {
        /** Remove self from the set of collided objects. */
        collisions.erase(it);
        
        it = collisions.begin();
        for(; it != collisions.end(); ++it)
        {
            Consumable* consumable = dynamic_cast<Consumable*>(*it);
            
            /** Consume the object if it is a consumable. */
            if(consumable != NULL)
            {
                Consume(consumable);
            }
            /** If the object is not consumable we've hit an obstacle. */
            else
            {
                collide();
            }
        }
    }
    else
    {
        /** The snake is not part of this collision. */
        return;
    }
}
Ejemplo n.º 6
0
void Shape::ReceiveMessage(Message* message) {
  String messageName = message->GetMessageName();
  // sysLog.Log("Shape::ReceiveMessage: " + messageName);

  if ((messageName == "CollisionStartWith" + GetName()) || (messageName == "CollisionEndWith" + GetName())) {
    TypedMessage<b2Contact*>* contactMessage = (TypedMessage<b2Contact*>*)message;
    b2Contact* contact = contactMessage->GetValue();
    PhysicsActor* other = NULL;
    b2Fixture* fixture = NULL;
    if (contact->GetFixtureA()->GetUserData() == this) {
      // I hit something else
      other = (PhysicsActor*)contact->GetFixtureB()->GetBody()->GetUserData();
      fixture = contact->GetFixtureA();
    }
    else {
      // Something else hit me
      other = (PhysicsActor*)contact->GetFixtureA()->GetBody()->GetUserData();
      fixture = contact->GetFixtureB();
    }

    if (other == NULL) {
      return;
    }

    if (fixture == _footSensor) {
      if (messageName == "CollisionStartWith" + GetName()) {
        ProcessStompOn(other);
      }
      else {
        ProcessUnStompFrom(other);
      }
    }

    if (fixture == _headSensor) {
      if (messageName == "CollisionStartWith" + GetName()) {
        if (other->IsTagged("block")) {
          // if (theSound.IsPlaying(_jumpPlaying)) {
          //   theSound.StopSound(_jumpPlaying);
          // }
          // ((FloatingBlock*)other)->Bonk();
          // theSound.PlaySound(_bonkSound);

        }
      }
    }

    if ( (messageName == "CollisionStartWith" + GetName()) && (other->IsTagged("powerup")) ) {
      PowerMeUp();
      other->Destroy();
    }

    // Add orb to inventory
    if ( (messageName == "CollisionStartWith" + GetName()) && (other->IsTagged("orb")) ) {
      collectOrb(other);
      other->Destroy();
    }
  }
  else if (messageName == "Jump") {
    if (CanJump()) {
      Jump();
    }
  }
  else if (messageName == "PowerUpDone") {
    // LoadSpriteFrames("Resources/Images/dudette_01.png", GL_CLAMP, GL_NEAREST);
    // LoadSpriteFrames("Resources/Images/patch_powerup_01.png", GL_CLAMP, GL_NEAREST);
    float poweredJumpHeight = theTuning.GetFloat("BlockyPoweredJumpHeight");
    theTuning.SetFloat("BlockyJumpHeight", poweredJumpHeight);
    // theWorld.SetBackgroundColor(Color::FromInts(0, 191, 255));
    // SetColor(0.0f, 1.0f, 0.0f, 1.0f);
    // theWorld.ResumePhysics();
    _poweringUp = false;
  }
}
Ejemplo n.º 7
-1
void GameApp::ReceiveMessage(Message* message)
{
	if (message->GetMessageName() == "MouseDown")
    {
    	Castle* castle = (Castle*)Actor::GetNamed("Castle");
    	TypedMessage<Vec2i> *m = (TypedMessage<Vec2i>*)message;
        Vec2i screenCoordinates = m->GetValue();
        Vector2 click = MathUtil::ScreenToWorld(screenCoordinates);
        if(tower != 3){
	        ActorSet background = theTagList.GetObjectsTagged("grass");
			ActorSet::iterator it = background.begin();
	        while(it != background.end()){
	        	Vector2 position = (*it)->GetPosition();
	        	Vector2 size = (*it)->GetSize();
	        	if ((click.X < position.X + size.X/2.0) && (click.X > position.X - size.X/2.0) && (click.Y < position.Y + size.Y/2.0) && (click.Y > position.Y - size.Y/2.0)){
	        		if(!(castle->buy_tower(tower))) return;
	        		if(tower == 1){
	        			StandartTower* new_tower = (StandartTower*)Actor::Create("standart_tower");
	        			new_tower->SetPosition(click);
	        			theWorld.Add(new_tower, 2);
	        		}
	        		if(tower == 2){
	        			MagicTower* new_tower = (MagicTower*)Actor::Create("magic_tower");
	        			new_tower->SetPosition(click);
	        			theWorld.Add(new_tower, 2);
	        		}
	        		break;
	        	}
	        	it++;
	        }
	    }
	    else{
	    	ActorSet background = theTagList.GetObjectsTagged("road");
			ActorSet::iterator it = background.begin();
	        while(it != background.end()){
	        	Vector2 position = (*it)->GetPosition();
	        	Vector2 size = (*it)->GetSize();
	        	if ((click.X < position.X + size.X/2.0) && (click.X > position.X - size.X/2.0) && (click.Y < position.Y + size.Y/2.0) && (click.Y > position.Y - size.Y/2.0)){
	        		if(!(castle->buy_tower(tower))) return;
	        		Trap* new_trap = (Trap*)Actor::Create("trap");
	        		new_trap->SetPosition(click);
	        		theWorld.Add(new_trap, 1);
	        		break;
	        	}
	        	it++;
	        }
	    }
        theSwitchboard.UnsubscribeFrom(this, "MouseDown");
    }
}