Esempio n. 1
0
int main()
{
	initializeGraphics();	

	MouseType mouseObject = IDLE;

	int cursorXLocation = 10;
	int cursorYLocation = 10;

	// These control building & unit logic
	GameEntity* buildingsContainer = NULL;
	GameEntity* unitsContainer = NULL;

	uint16_t population = 0;		// This controls population count
	uint16_t frame = 0;				// This counts frames
	uint16_t unitSpawnDelay = 0;			// This controls the delay between unit spawns

	while (true)
	{
		FlipBuffers();																				// Flip buffers
		
		ClearScreen8(SAND_COLOR);																	// Clear screen

		render(buildingsContainer,unitsContainer);													// Render all buildings and units

		animatePowerPlant(frame);																	// Animate the power plant
		animateBarracks(frame);																		// Animate the barracks

		if(mouseObject!=IDLE)																		// If there has been some mouse action ...
		{
			if(isMovement(mouseObject))																	// ... and it is movement ...
			{
				move(cursorXLocation,cursorYLocation,mouseObject);											// ... movet the mouse.
			}
			 
			else if(isPlacement(mouseObject))															// ... if it is placement ...
			{
				place(cursorXLocation,cursorYLocation,mouseObject,buildingsContainer);						// ... attempt placement.
			}

			else if(isSpawning(mouseObject) && unitSpawnDelay==0 && population!=POP_CAP)				// ... if it is a unit and it's not to soon after the last unit was trained and population cap has not been reached  ...
			{														
				spawn(unitsContainer,buildingsContainer);													// place the unit
				population++;																				// increase population

				unitSpawnDelay = UNIT_SPAWN_COOLDOWN_PERIOD;												// start cooldown timer
			}
		}

		drawCursor(cursorXLocation,cursorYLocation);												// Draw the cursor

		mouseObject = updatedMouseType();															// Update the mouse

		WaitVSync();																				// Sync

		frame = (frame == 100) ? 0 : frame+1;														//	Reset frame count every 100 frames, else increase by one

		if(unitSpawnDelay!=0)																		// If there is a cooldown timer in action ...
			unitSpawnDelay--;																			// ... update it!

	}
	
	// We are environmentaly concious, so we clean after ourselves
	delete buildingsContainer;					
	delete unitsContainer;

	return 0;
}
Esempio n. 2
0
void Goblin_v2::moveAdvance(Mult::Mult_Object *obj, Gob_Object *gobDesc,
		int16 nextAct, int16 framesCount) {

	if (!obj->goblinStates)
		return;

	movePathFind(obj, 0, 0);
	playSounds(obj);

	Mult::Mult_AnimData *animData = obj->pAnimData;

	framesCount = _vm->_scenery->getAnimLayer(animData->animation, animData->layer)->framesCount;

	if (animData->isPaused == 0)
		animData->frame++;

	switch (animData->stateType) {
	case 0:
	case 1:
		animData->isPaused = 0;
		break;

	case 4:
		if (animData->frame == 0)
			animData->isPaused = 1;
		break;

	case 6:
		if (animData->frame >= framesCount)
			animData->isPaused = 1;
		break;
	}

	switch (animData->state) {
	case 0:
	case 1:
	case 7:
	case 13:
	case 16:
	case 23:
	case 40:
	case 41:
		animData->curLookDir = 0;
		break;

	case 2:
	case 15:
	case 18:
	case 21:
	case 26:
	case 38:
		animData->curLookDir = 2;
		break;

	case 3:
	case 4:
	case 5:
	case 12:
	case 19:
	case 22:
	case 42:
	case 43:
		animData->curLookDir = 4;
		break;

	case 6:
	case 14:
	case 17:
	case 20:
	case 27:
	case 39:
		animData->curLookDir = 6;
		break;

	case 8:
	case 9:
	case 28:
	case 29:
		if (animData->pathExistence == 4)
			animData->pathExistence = 5;
		break;
	}

	if ((animData->newState != -1) && (animData->frame == framesCount) &&
	    (animData->newState != animData->state)) {

		animData->nextState = animData->newState;
		animData->newState  = -1;
		animData->state     = animData->nextState;

		Scenery::AnimLayer *animLayer =
			_vm->_scenery->getAnimLayer(animData->animation, animData->layer);

		*obj->pPosX += animLayer->animDeltaX;
		*obj->pPosY += animLayer->animDeltaY;

		int16 animation = obj->goblinStates[animData->nextState][0].animation;
		int16 layer     = obj->goblinStates[animData->nextState][0].layer;

		animData->layer     = layer;
		animData->animation = animation;
		animData->frame     = 0;

		return;
	}

	if (isMovement(animData->state)) {
		int16 state = animData->nextState;

		if (animData->frame == ((framesCount + 1) / 2)) {
			int16 gobX = obj->goblinX;
			int16 gobY = obj->goblinY + 1;

			advMovement(obj, state);

			if (animData->state != state) {
				int16 animation = obj->goblinStates[state][0].animation;
				int16 layer     = obj->goblinStates[state][0].layer;

				animData->layer     = layer;
				animData->animation = animation;
				animData->frame     = 0;
				animData->state     = state;

				_vm->_scenery->updateAnim(layer, 0, animation, 0, *obj->pPosX, *obj->pPosY, 0);
				uint32 gobPosX =  gobX * _vm->_map->getTilesWidth();
				uint32 gobPosY = (gobY * _vm->_map->getTilesHeight()) -
				                 (_vm->_scenery->_animBottom - _vm->_scenery->_animTop);

				if (_vm->_map->hasBigTiles())
					gobPosY -= gobY / 2;

				*obj->pPosX = gobPosX;
				*obj->pPosY = gobPosY;
			}
		}
	}

	if (animData->frame < framesCount)
		return;

	int16 state     = animData->nextState;
	int16 animation = obj->goblinStates[state][0].animation;
	int16 layer     = obj->goblinStates[state][0].layer;

	animData->layer     = layer;
	animData->animation = animation;
	animData->frame     = 0;
	animData->state     = state;

	int16 gobX = obj->goblinX;
	int16 gobY = obj->goblinY + 1;

	advMovement(obj, state);

	_vm->_scenery->updateAnim(layer, 0, animation, 0, *obj->pPosX, *obj->pPosY, 0);
	uint32 gobPosX =  gobX * _vm->_map->getTilesWidth();
	uint32 gobPosY = (gobY * _vm->_map->getTilesHeight()) -
	                 (_vm->_scenery->_animBottom - _vm->_scenery->_animTop);

	if (_vm->_map->hasBigTiles())
		gobPosY -= gobY / 2;

	*obj->pPosX = gobPosX;
	*obj->pPosY = gobPosY;
}
/**
 * Fire off the position + velocitiy + movement direction topic.
 */
void Topics::posvelmov() {
  ros::Publisher posPub, velPub, pmovPub, nmovPub;
  posPub = node.advertise<std_msgs::Float64MultiArray>("pos", 1000);
  velPub = node.advertise<std_msgs::Float64MultiArray>("vel", 1000);
  pmovPub = node.advertise<std_msgs::Float64MultiArray>("pmov", 1000);
  nmovPub = node.advertise<std_msgs::Float64MultiArray>("nmov", 1000);

  std_msgs::Float64MultiArray posMsg;
  std_msgs::Float64MultiArray velMsg;
  std_msgs::Float64MultiArray pmovMsg;
  std_msgs::Float64MultiArray nmovMsg;

  uima::ANIterator jsIter = gateway.getANIterator("JointState");
  uima::Feature jsnF = gateway.getFeature("JointState", "jointNames");
  uima::Feature jtpF = gateway.getFeature("JointState", "jointTrajectoryPoint");
  uima::Feature posF = gateway.getFeature("JointTrajectoryPoint", "positions");
  uima::Feature velF = gateway.getFeature("JointTrajectoryPoint", "velocities");

  uima::ANIterator pmovIter = gateway.getANIterator("PositiveMovement");
  uima::ANIterator nmovIter = gateway.getANIterator("NegativeMovement");
  uima::Feature pmovnF = gateway.getFeature("PositiveMovement", "jointName");
  uima::Feature nmovnF = gateway.getFeature("NegativeMovement", "jointName");

  uima::AnnotationFS js, pmov, nmov;
  uima::FeatureStructure jtp;
  uima::StringArrayFS names;
  uima::DoubleArrayFS positions, velocities;

  std::vector<int>::const_iterator it;
  std::size_t i;

  while (node.ok() && (jsIter.isValid() || loop)) {
    if (!jsIter.isValid()) {
      jsIter = gateway.getANIterator("JointState");
    }

    js = jsIter.get();
    names = js.getStringArrayFSValue(jsnF);
    jtp = js.getFSValue(jtpF);
    positions = jtp.getDoubleArrayFSValue(posF);
    velocities = jtp.getDoubleArrayFSValue(velF);

    // Gene fresh message.
    posMsg.data.clear();
    velMsg.data.clear();
    pmovMsg.data.clear();
    nmovMsg.data.clear();
    posMsg.data.resize(joints.size());
    velMsg.data.resize(joints.size());
    pmovMsg.data.resize(joints.size());
    nmovMsg.data.resize(joints.size());
    for (it = joints.begin(), i = 0; it != joints.end(); it++, i++) {
      posMsg.data[i] = positions.get(*it);
      velMsg.data[i] = velocities.get(*it);

      if (isMovement(pmovIter, pmovnF, names.get(*it), js.getBeginPosition())) {
        pmovMsg.data[i] = positions.get(*it);
      }

      if (isMovement(nmovIter, nmovnF, names.get(*it), js.getBeginPosition())) {
        nmovMsg.data[i] = positions.get(*it);
      }
    }

    // Print current message data.
    if (echo) {
      std::puts(utils::join(posMsg.data, " | ").c_str());
      std::puts(utils::join(velMsg.data, " | ").c_str());
      std::puts(utils::join(pmovMsg.data, " | ").c_str());
      std::puts(utils::join(nmovMsg.data, " | ").c_str());
      std::puts("\n");
    }

    posPub.publish(posMsg);
    velPub.publish(velMsg);
    pmovPub.publish(pmovMsg);
    nmovPub.publish(nmovMsg);

    jsIter.moveToNext();
    ros::spinOnce();
    rate.sleep();
  }
}