Exemplo n.º 1
0
void MissionController::onStepEvent(CCObject* sender)
{
//    if (!m_gameWorld->isEndStep()) {
    
        //还没有到达终点,继续前进。不需要检查,会在移动完成处理
        
        unsigned int step=Game::getInstance()->getRandom()->NextUInt(1,6);
        
        moveStep(step);
    
    
        //显示投出的数字,现在使用文字。TODO,使用筛子动画
    CCSize contentSize=getPreferredContentSize();
    CCLabelTTF* tipLable=CCLabelTTF::create(CCString::createWithFormat("%d",step)->getCString(), "Arial", 40);
    
    float offsetY=80;
    
    tipLable->setPosition(ccp(contentSize.width/2,(contentSize.height-offsetY)/2));
    m_view->addChild(tipLable);
    
    tipLable->runAction(CCSequence::createWithTwoActions(CCMoveBy::create(0.5f, ccp(0, offsetY)), CCRemoveSelf::create()));
    
//    }else{
//        doMissionFinish();
//    }
    
}
Exemplo n.º 2
0
void Scanner_Worker::runScan(int steps, int accuracy)
{
    ScanRunning = true;
    for(int i = 0; i <= steps; i++)
    {
        if(ScanRunning == false)
            break;
        Data->mutex.lock();
        if(Data->number >= accuracy)
        {
            qDebug() << "Current emitted data: Step: " << i << " and counts: " << Data->counts << " and current pos: " << ((qreal)i)/((qreal)steps)*100;
            emit currentData(qMakePair(i, Data->counts));
            emit moveStep();
            emit currentPosition(((qreal)i)/((qreal)steps)*100);
            Data->counts = 0;
            Data->number = 0;
            Data->mutex.unlock();
        }
        else
        {
            Data->WaitCond.wait(&(Data->mutex));
            Data->mutex.unlock();
            i--;
        }

    }
    emit ScanFinished();
}
void BoardActor::generateMovePath(std::vector<Coordinate3D<int>> path){
	move_path.clear();
	if(path.size() > 1){
		destination = path[0];
		move_path.push_back(Util::coordToScreen(destination));
	}

	for(int i = 0; i < ((int)path.size())-1; i++){
		generateMovePath(path[i+1], path[i]);
	}
	moveStep();
}
Exemplo n.º 4
0
void MissionController::viewDidLoad()
{
    CCSize visibleSize =  this->getPreferredContentSize();//CCSizeMake(480,240);//
    
    MissionService* missionService=ServiceFactory::getInstance()->getMissionService();
    
    int mapId=missionService->getCurrentMap();
    
    m_gameWorld=new StepGameWorldController();
    m_gameWorld->init(missionService->getCurrentZone(), mapId);
    m_gameWorld->setTouchable(false);
    m_gameWorld->setPreferredContentSize(visibleSize);
    m_gameWorld->setStepIndex(ServiceFactory::getInstance()->getMissionService()->getLastMapStepIndex());
    
    m_view->addChild(m_gameWorld->getView());
    
    //create test button
    CCMenuItemLabel *stepBtn=CCMenuItemLabel::create(CCLabelTTF::create("step", "Arial", 40),
                                                     this,
                                                     menu_selector(MissionController::onStepEvent));
    
    CCMenu* menu=CCMenu::create(stepBtn,NULL);
    menu->alignItemsHorizontally();
    menu->setPosition(ccp(visibleSize.width-60,40));
    
    m_view->addChild(menu);
    
    
    //地图事件
    //取得地图的事件信息
    CCDictionary* stepEvents=missionService->getMapStepEvents(mapId);
    if (!stepEvents) {
       stepEvents=missionService->generateMapStepEvents(mapId, m_gameWorld->getWalkPaths(), m_gameWorld->getMapColumn());
    }
    
    setStepEvents(stepEvents);
    showStepEvent();
    
    //检查是否被断下来
    if (missionService->getMoveLeftStep()) {
        //继续移动
        moveStep(missionService->getMoveLeftStep());
    }
    
}
bool BoardActor::update(){
	BoardPiece::update();
	moveStep();
	return true;
}
Exemplo n.º 6
0
list* doMovement(int mode, int dt) {
  int i;
  float fs;
  Data *data;
  list *l = NULL;
  GameEvent *e;

  for(i = 0; i < game->players; i++) {
    data = game->player[i].data;
    if(data->speed > 0) { /* still alive */

#define FREQ 1200
#define FACTOR 0.09
      fs = 1.0 - FACTOR + FACTOR * 
	cos(i * M_PI / 4.0 + 
	    (float)(game2->time.current % FREQ) * 2.0 * M_PI / (float)FREQ);
#undef FREQ
#undef FACTOR

      data->t += dt / 100.0 * data->speed * fs;
      while(data->t >= 1) {
	moveStep(data);
	data->t--;
	if(getCol(data->iposx, data->iposy) && mode) {
	  e = (GameEvent*) malloc(sizeof(GameEvent));
	  e->type = EVENT_CRASH;
	  e->player = i;
	  e->x = data->iposx;
	  e->y = data->iposy;
	  e->timestamp = game2->time.current;
	  addList(&l, e);
	  break;
	} else {
	  writePosition(i);
	}
      }
      data->posx = data->iposx + data->t * dirsX[data->dir];
      data->posy = data->iposy + data->t * dirsY[data->dir];
    } else { /* already crashed */
      if(game2->rules.eraseCrashed == 1 && data->trail_height > 0)
	data->trail_height -= (float)(dt * TRAIL_HEIGHT) / 1000;
      if(data->exp_radius < EXP_RADIUS_MAX)
	data->exp_radius += (float)dt * EXP_RADIUS_DELTA;
      else if (data->speed == SPEED_CRASHED) {
	int winner = -1;

	data->speed = SPEED_GONE;
	game->running--;
	if(game->running <= 1) { /* all dead, find survivor */
	  int i, maxSpeed = SPEED_GONE;
	  /* create winner event */
	  for(i = 0; i < game->players; i++) {
	    if(game->player[i].data->speed >= maxSpeed) {
	      winner = i;
	      maxSpeed = game->player[i].data->speed;
	    }
	  }
	  if(mode) {
	    e = (GameEvent*) malloc(sizeof(GameEvent));
	    e->type = EVENT_STOP;
	    e->player = winner;
	    e->timestamp = game2->time.current;
	    e->x = 0; e->y = 0;
	    addList(&l, e);
	    /* a stop event is the last event that happens */
	    return l;
	  }
	}
      }
    }      
  }
  return l;
}
Exemplo n.º 7
0
//		MAIN FUNCTION TO TRAVERSE *****************************
void traverse ( char * * maze, int * currentLocation, char facing, int w, int h, char move )
{	
	//	MOVE TO NEW LOCATION
	if ( !moveStep( maze, currentLocation, move, w, h ) )
	{
		//	Can't Move further in the direction
		
		return;
	}
	else
	{
		printf( "%c 1\n", facing );
		maze[ currentLocation[0] ][ currentLocation[1] ] = '*';
	}
	//print_loc ( maze, w, h, currentLocation );
	//printf("\n");
	
	//-------------------------
	int numWays = 0;
	int LastRecursiveLocation [2];
	int i = 0;
	char * dir = { "WESN" };
	int j = 0;
	int tempLocation [2];
	int x,y;
	
	numWays = numWaysToGo ( maze, w, h, currentLocation, facing );
	
	//	p 	RECURSIVE CASE
	if ( numWays > 1 )
	{
		x = currentLocation[0];
		y = currentLocation[1];
		//printf ( "RECURSIVE CASE!!\n\n");
		setLocation ( LastRecursiveLocation, currentLocation[0], currentLocation[1] );
		setLocation ( tempLocation, currentLocation[0], currentLocation[1] );
		while ( i < numWays && j < 4 )
		{
			//	Go in all possible directions and come back!!
			if ( dir[j] != oppositeDir( facing ) && moveStep( maze, tempLocation, dir[j], w, h ) )
			{
				traverse( maze, currentLocation, dir[j], w, h, dir[j] );	// 		TRAVERSE!!
				setLocation( currentLocation, x, y );
				setLocation ( tempLocation, currentLocation[0], currentLocation[1] );
				i++;
			}
			j++;
		}
		
	}
	//	************************************************************
	
	//		NORMAL CASE 
	else if ( numWays == 1 )
	{
		//		Keep Going
		setLocation ( tempLocation, currentLocation[0], currentLocation[1] );
		if ( moveStep ( maze, tempLocation, facing , w, h ) )
		{
			traverse( maze, currentLocation, facing, w, h, facing );		// TRAVERSE!!
		}
		else if ( !moveStep ( maze, tempLocation, facing , w, h ) )
		{
			while ( j < 4 )
			{
				if (dir[j] != oppositeDir( facing ) && moveStep ( maze, tempLocation, dir[j], w, h ) )
				{
					traverse( maze, currentLocation, dir[j], w, h, dir[j] );		// TRAVERSE!!
					j = 4;
				}
				j++;
			}
		}
	}
	//	***************************************************************
	
	//		BASE CASE
	else if ( numWays == 0 )
	{
		//printf ( "BASE CASE!!\n\n" );
		//	GO BACK!!
	}
	
	printf("%c 1\n", oppositeDir(facing));
}
Exemplo n.º 8
0
chassis_id PhysicsRegion::moveStepRelative(chassis_id id,
		vector2F offset, float step, SlideMoveStyle slide,flag_plane src, flag_plane collision) {
	return moveStep(id,getChassisCoord(id)+offset,step,slide,src,collision);
}
bool MovingEffect::update(){
	Effect::update();
	return moveStep();
}