void ControllerSimpleMove::moveOneStep() { Sprite* sprite = m_entity->getSprite();//初始化时,将调用simplemove的entity传入,m_entity=entity if(sprite != NULL) { Point entityPos = m_entity->getPosition(); Point curDestPos = m_curDestPos->getPos();//这里为什么用getpos,都没有定义? /* 取得下一个移动坐标点 */ entityPos = getNextPos(entityPos, curDestPos); /* 移动实体 */ m_entity->setPosition(entityPos); /* 到达当前目的地,开始下一个目的地 */ if(entityPos.x == curDestPos.x && entityPos.y == curDestPos.y) { if(m_movePosList.size() > 0) { nextMovePos(); } else { /* 移动结束 */ if (m_moveEndFunc) { m_moveEndFunc(); m_moveEndFunc = nullptr; } } } } }
void moveZombies(){ int i; for(i=1;i<MAX_ENTITIES;i++){ float maxZombieSpeed=.10; allEntities[i].prevYpos = allEntities[i].curYpos; allEntities[i].prevXpos = allEntities[i].curXpos; if(allEntities[i].isAlive){ if(((float)(clock() - allEntities[i].lastMoveClock)/CLOCKS_PER_SEC) > allEntities[i].speed ){ getNextPos(allEntities[i].curYpos,allEntities[i].curXpos,allEntities[0].curYpos,allEntities[0].curXpos); struct CollisionEvent collisionEvent = collisionDetect(nextPos.y,nextPos.x); if(collisionEvent.collidedWithBoundary || collisionEvent.collidedWithUnPassableChar || collisionEvent.collidedWithItem || collisionEvent.collidedWithEntity){ if(collisionEvent.collidedWithEntity){ if(collisionEvent.collidedWithEntity->type,"zombie"){ } } } else{ allEntities[i].curYpos = nextPos.y; allEntities[i].curXpos = nextPos.x; } allEntities[i].lastMoveClock=clock(); } } } }
/* * TrackServerMsg - update the coversations tracking window */ void TrackServerMsg( MONCBSTRUCT *info ) { char *inst; DDETrackInfo *listinfo; ServerInfo **entry; ServerInfo *cur; inst = HSZToString( info->hsz2 ); listinfo = (DDETrackInfo *)GetWindowLong( Tracking[DDEMENU_TRK_SERVER - DDE_TRK_FIRST].hwnd, 0 ); entry = findServer( inst, listinfo ); if( info->wType == XTYP_REGISTER ) { if( entry == NULL ) { entry = getNextPos( listinfo ); cur = MemAlloc( sizeof( ServerInfo ) ); *entry = cur; cur->instname = inst; cur->server = HSZToString( info->hsz1 ); } else { MemFree( inst ); } } else if( info->wType == XTYP_UNREGISTER ) { if( entry != NULL ) { cur = *entry; MemFree( cur->instname ); MemFree( cur->server ); *entry = NULL; } else { MemFree( inst ); } } displayServers( listinfo ); } /* TrackServerMsg */
void ControllerSimpleMove::moveOneStep() { CCSprite* sprite = m_entity->getSprite(); if(sprite != NULL) { CCPoint entityPos = m_entity->getPosition(); CCPoint curDestPos = m_curDestPos->getPos(); /* 取得下一个移动坐标点 */ entityPos = getNextPos(entityPos, curDestPos); /* 移动实体 */ m_entity->setPosition(entityPos); /* 到达当前目的地,开始下一个目的地 */ if(entityPos.x == curDestPos.x && entityPos.y == curDestPos.y) { if(m_movePosList->count() > 0) { nextMovePos(); } else { /* 移动结束 */ m_isMoving = false; if(m_moveEnd != NULL) { m_moveEnd->moveEnd(); } } } } }
VectorFloat TCBSpline::getPos(float curTime) { VectorFloat pos(0.0f,0.0f,0.0f); int i = findKey((int)curTime, 0, numKeys-1); if (i != -1) { /*for (int i = 0; i < numKeys-1; i++) { // okay "i" must be the current key if (curTime >= keys[i].ti && curTime < keys[i+1].ti) {*/ float deltai = (float)(keys[i+1].ti - keys[i].ti); float t = (float)(curTime - keys[i].ti); float v = t/deltai; VectorFloat curPos = keys[i].v; VectorFloat nextPos = getNextPos(i); VectorFloat lastPos = getLastPos(i); // incoming tangent vector for the current point VectorFloat Ti = calcTi(i); // outgoing tangent vector for the current point VectorFloat To = calcTo(i); // incoming tangent vector for the next point VectorFloat Ti1 = calcTi(i+1); // outgoing tangent vector for the next point VectorFloat To1 = calcTo(i+1); VectorFloat Ai = curPos; VectorFloat Bi = deltai * To; VectorFloat Ci = (3.0f * (nextPos - curPos)) - (deltai * ((2.0f * To) + Ti1)); VectorFloat Di = (-2.0f * (nextPos - curPos)) + (deltai * (To + Ti1)); float v2 = v*v; float v3 = v2*v; pos = Ai + (v*Bi) + (v2*Ci) + (v3*Di); /* break; } }*/ } return pos; }
VectorFloat TCBSpline::calcTo(int i) { //return 0.5f * (getNextPos(keys, i, numKeys) - getLastPos(keys, i, numKeys)); float coeff1 = ((1.0f - keys[i].t) * (1.0f - keys[i].c) * (1.0f - keys[i].b))*0.5f; float coeff2 = ((1.0f - keys[i].t) * (1.0f + keys[i].c) * (1.0f + keys[i].b))*0.5f; return (coeff1 * (getNextPos(i) - keys[i].v)) + (coeff2 * (keys[i].v - getLastPos(i))); }
void solve(vector<vector<char>>& grid) { if(grid.empty()) return; rowSize = grid.size(); colSize = grid[0].size(); // cout << "Grid size: " << rowSize << " x " << colSize << "\n"; vector<vector<bool>> visited(rowSize, vector<bool>(colSize, false)); queue<px> zeros; bool isRegion; vector<px> mark; for(int i = 0; i < rowSize; i++) { for(int j = 0; j < colSize; j++) { if(visited[i][j]) continue; visited[i][j] = true; isRegion = true; if(grid[i][j] == 'O') { zeros.push({i, j}); mark.push_back({i, j}); // cout << "pushing " << "(" << i << ", " << j << ")\n"; while(!zeros.empty()) { px curr, next; curr = zeros.front(); zeros.pop(); // cout << "CURRENT: (" << curr.row << ", " << curr.col << ")\n"; for(int k = 0; k < 4; k++) { if(getNextPos(curr, next, k)) { if(!visited[next.row][next.col] && grid[next.row][next.col] == 'O') { zeros.push(next); mark.push_back(next); } visited[next.row][next.col] = true; } else { // on the boarder isRegion = false; } } } if(!isRegion) mark.clear(); else { for(auto x :mark) { // cout << x.row << ", " << x.col << "\n"; grid[x.row][x.col] = 'X'; } } } mark.clear(); } } }
/* * TrackLinkMsg - update the links tracking window */ void TrackLinkMsg( MONLINKSTRUCT *info ) { DDETrackInfo *listinfo; LinkInfo *item; LinkInfo **itempos; listinfo = (DDETrackInfo *)GetWindowLong( Tracking[DDEMENU_TRK_LINK - DDE_TRK_FIRST].hwnd, 0 ); itempos = findLinkInfo( listinfo, info ); if( info->fEstablished ) { if( itempos != NULL ) { return; } itempos = getNextPos( listinfo ); item = MemAlloc( sizeof( LinkInfo ) ); *itempos = item; item->service = HSZToString( info->hszSvc ); item->topic = HSZToString( info->hszTopic ); item->item = HSZToString( info->hszItem ); item->format = MemAlloc( 20 ); GetFmtStr( info->wFmt, item->format ); if( info->fNoData ) { item->type = AllocRCString( STR_WARM ); } else { item->type = AllocRCString( STR_HOT ); } item->client = info->hConvClient; item->server = info->hConvServer; if( strlen( item->service ) > MAX_TRK_STR ) { item->service[MAX_TRK_STR] = '\0'; } if( strlen( item->topic ) > MAX_TRK_STR ) { item->topic[MAX_TRK_STR] = '\0'; } if( strlen( item->item ) > MAX_TRK_STR ) { item->item[MAX_TRK_STR] = '\0'; } } else { if( itempos != NULL ) { FreeLinkInfo( *itempos ); *itempos = NULL; } } redispLinkTrk( listinfo, TRUE ); } /* TrackLinkMsg */
// call this regularly in loop() void ServoEaser::update() { if( ((millis() - lastMillis) < frameMillis) || !running ) { // time yet? return; } lastMillis = millis(); currPos = easingFunc( tick, startPos, changePos, tickCount ); debug_update(); if( !arrived ) tick++; if( tick == tickCount ) { // time for new position getNextPos(); } float p = (flipped) ? 180.0 - currPos : currPos; if( useMicros ) { servo.writeMicroseconds( angleToMicros(p) ); } else { servo.write( p ); } }
/* * TrackConvMsg - update the coversations tracking window */ void TrackConvMsg( MONCONVSTRUCT *info ) { LinkInfo *item; LinkInfo **itempos; DDETrackInfo *listinfo; listinfo = (DDETrackInfo *)GetWindowLong( Tracking[DDEMENU_TRK_CONV - DDE_TRK_FIRST].hwnd, 0 ); itempos = findConvInfo( listinfo, info ); if( info->fConnect ) { if( itempos != NULL ) { return; } itempos = getNextPos( listinfo ); item = MemAlloc( sizeof( LinkInfo ) ); *itempos = item; item->service = HSZToString( info->hszSvc ); item->topic = HSZToString( info->hszTopic ); item->client = info->hConvClient; item->server = info->hConvServer; item->type = NULL; item->item = NULL; item->format = NULL; if( strlen( item->service ) > MAX_TRK_STR ) { item->service[MAX_TRK_STR] = '\0'; } if( strlen( item->topic ) > MAX_TRK_STR ) { item->topic[MAX_TRK_STR] = '\0'; } } else { if( itempos != NULL ) { FreeLinkInfo( *itempos ); *itempos = NULL; } } redispLinkTrk( listinfo, FALSE ); } /* TrackConvMsg */
/* * addStringInfo - add information about a new string to the list of * strings displayed in the string tracking window */ static StringInfo *addStringInfo( MONHSZSTRUCT *info, DDETrackInfo *listinfo ) { StringInfo **str; StringInfo *ret; #ifdef __NT__ WORD *ptr; DWORD len; DWORD ver; #endif str = getNextPos( listinfo ); ret = MemAlloc( sizeof( StringInfo ) ); *str = ret; ret->hsz = info->hsz; ret->cnt = 1; ret->str = NULL; #ifdef __NT__ /* In NT 3.1, ret->str is a Unicode string. Otherwise it is ASCII. */ ver = GetVersion(); if( (ver & 0xFF) == 3 && (ver & 0xFF00) <= 0x0A00 ) { len = 0; ptr = (WORD *)info->str; while( *ptr != 0 ) { ptr++; len++; } ret->str = MemAlloc( len + 1 ); wsprintf( ret->str, "%ls", info->str ); } #endif if( ret->str == NULL ) { ret->str = MemAlloc( strlen( info->str ) + 1 ); strcpy( ret->str, info->str ); } return( ret ); } /* addStringInfo */