void Swan::move(Floor& floor){ location deltaPos, current, next; int input; current = getPos(); do{ deltaPos.r = 0; deltaPos.c = 0; next = current; input = rand()%4; if(input == 0){ deltaPos.r--; } else if(input == 1){ deltaPos.c--; } else if(input == 2){ deltaPos.r++; } else if(input == 3){ deltaPos.c++; } next.r += deltaPos.r; next.c += deltaPos.c; }while(invalidMove(next, floor)); floor.setTile(current.r, current.c, getTileBelow()); if(getTileBelow() == 'P') floor.setTile(current.r, current.c, ' '); setTileBelow(floor.getTile(next.r, next.c)); setPos(next); floor.setTile(next.r, next.c, 'S'); }
void Person::RequestFloor(Environment &env) { Floor *next = path_.front(); if (!next) { std::ostringstream oss("Invalid operation: no next floor in path ", std::ostringstream::ate); oss << "ID of person: <" << GetId(); oss << ", this error should never occur."; throw std::runtime_error(oss.str()); } for (int i = 0; i < elevator_->GetInterfaceCount(); ++i) { Interface *interf = elevator_->GetInterface(i); Floor *floor = static_cast<Floor*>(interf->GetLoadable(0)); if (floor == next) { action_ = env.SendEvent("Interface::Interact", 3, this, elevator_->GetInterface(i)); return; } } std::ostringstream oss("Invalid operation: ", std::ostringstream::ate); oss << elevator_->GetName() << " can not go to Floor " << next->GetId(); oss << ", this error should never occur."; throw std::runtime_error(oss.str()); }
void Person::RequestElevator(Environment &env, int time) { if (current_ == final_) return; Floor *next = path_.front(); if (!next) { std::ostringstream oss("Invalid operation: no next floor in path ", std::ostringstream::ate); oss << "ID of person: <" << GetId(); oss << ", this error should never occur."; throw std::runtime_error(oss.str()); } for (int i = 0; i < current_->GetInterfaceCount(); ++i) { Interface *interf = current_->GetInterface(i); Elevator *ele = static_cast<Elevator*>(interf->GetLoadable(0)); if (ele->HasFloor(next)) { requested_ = current_->GetInterface(i); env.SendEvent("Interface::Interact", time - env.GetClock(), this, requested_); return; } } std::ostringstream oss("Invalid operation: no elevator available to go from Floor ", std::ostringstream::ate); oss << current_->GetId() << " to Floor " << next->GetId(); oss << ", this error should never occur."; throw std::runtime_error(oss.str()); }
Surface* Building::extrude_lod3(double hFloor, double lenHasWin, double lenUnit) const { Surface* bldg = extrude_envelope(); for(int i=0;i<bldg->getNumChildren();++i) { if(bldg->getChild(i)->getType()==SurfaceType::Wall) { Wall* wall = (Wall*)(bldg->getChild(i)); wall->splitFloor(hFloor); double lWall = wall->getLength(); if(lWall>lenHasWin || std::abs(lWall-lenHasWin)<0.001) { for(int j=0;j<wall->getNumChildren();++j) { Floor* floor = (Floor*)(wall->getChild(j)); floor->splitUnit(lenUnit); for(int k=0;k<floor->getNumChildren();++k) { Unit* unit = (Unit*)(floor->getChild(k)); if(j==0 && k%5 == 0 && unit->getLength()>3) { unit->insertDoor(unit->getLength()/3,unit->getHeight()*2/3); continue; } if(unit->getLength()>1) unit->insertWindow(unit->getLength()/3,unit->getHeight()/3); } } } } } return bldg; }
void onKeyPress(unsigned char key, int x, int y) { switch (key) { //exit case 27: exit(0); break; //fullscreen case 'f': { if (fullscreen = !fullscreen) glutFullScreen(); else { glutReshapeWindow(400, 455); glutPositionWindow(50, 50); } break; } //light - night case 'n': lights.switchLight(); break; //pause case 'p': paused = !paused; break; //reset case 'r': maze = Maze(); break; //cam1 case '1': cams.enable(CAM_FLAT); break; case '2': cams.enable(CAM_1); break; case '3': cams.enable(CAM_2); break; case '4': cams.enable(CAM_FOLLOW); break; case '5': cams.enable(CAM_FOLLOW2); break; case '6': cams.enable(CAM_FOLLOW2_NEAR); break; case '7': cams.enable(CAM_BILU); break; case '8': cams.enable(CAM_MOVE); break; case 'z': mazeFloor.switchFloor(mazeFloor.getactiveFloor()); break; } cams.onKeyPress(key); }
void FloorFace::onAllLoaded() { Object::onAllLoaded(); Floor *floor = Object::cast<Floor>(_parent); for (uint i = 0; i < ARRAYSIZE(_indices); i++) { _vertices[i] = floor->getVertex(_indices[i]); } }
void GameScene::initFloorsAndCoins() { int num = 0;//用来作为数组下标 int count = 0;//用来控制山体的X坐标 isFrontBlank = false; //创建20个山体和金币,放入数组中 for (int i=0; i<floorCount; i++) { Floor *floor = Floor::createFloor(); floor->setScale(scaleFix); this->addChild(floor); floorArray.pushBack(floor); Coin *coin = Coin::createCoin(); this->addChild(coin); coinArray.pushBack(coin); } //循环遍历修改山体和金币的位置 while (num<floorCount) { count++; if (num<floorCount/2) { //前10个山体和金币单独处理,count用来控制位置,根据player的初始化位置设置地面的位置 floorArray.at(num)->setPosition(Point(count*35,winSize.height/2 -100)); Floor *floortemp = floorArray.at(num); //金币放在山体上方一定距离 coinArray.at(num)->setPosition(Point(count*35,floortemp->getPositionY()+80)); num++; }else{ //后10个山体和金币的处理 randomNum = this->getRandomNumber(0, 2); //0~2的随机数 if (randomNum == 0) { isFrontBlank = true; continue; } if (isFrontBlank) { //山体高度设置为100到320-220即100之间的随机数 floorArray.at(num)->setPosition(Point(count*35, this->getRandomNumber(winSize.height/2 -100, 180))); //金币高度设置为山体以上30到100的高度 float y = floorArray.at(num)->getPositionY() + this->getRandomNumber(50, 150); coinArray.at(num)->setPosition(Point(count*35, y)); isFrontBlank = false; }else{ //设置山体的高度为前一个山体的高度 floorArray.at(num)->setPosition(Point(count*35, floorArray.at(num -1)->getPositionY())); //金币的高度为山体以上30到100的高度 float y = floorArray.at(num)->getPositionY() + this->getRandomNumber(50, 150); coinArray.at(num)->setPosition(Point(count*35, y)); } num++; } } }
void WorldGenerator::AddFloor( float _x, float _y ) { Floor* floor = new Floor(); floor->mPosition = D3DXVECTOR3( _x, -100, _y ); floor->mModel = mResources->getModel( 801 ); floor->Initialize( md3dManager ); mGFS->mFloor.push_back( floor ); }
Command *Command::opEnableFloorField(const ResourceReference &floorFieldRef, bool enable) { FloorField *floorField = floorFieldRef.resolve<FloorField>(); Layer *layer = floorField->findParent<Layer>(); Floor *floor = layer->findChild<Floor>(); floor->enableFloorField(floorField, enable); return nextCommand(); }
void GameScene::updateFloorsAndCoins() { //改变山体的位置 for (int i =0; i<floorArray.size(); i++) { Floor *floor = floorArray.at(i); //forceX=300,speedFix = 0.01 floor->setPosition(Point(floor->getPositionX()-forceX * speedFix, floor->getPositionY())); } //改变金币的位置 for (int i = 0; i<coinArray.size(); i++) { Coin *coin = coinArray.at(i); coin->setPosition(Point(coin->getPositionX()-forceX * speedFix, coin->getPositionY())); } //当第一个山体移出屏幕 if (floorArray.at(0)->getPositionX() <-50) { int num = floorArray.size()-1;//数组中最后一个元素下标 float posx = floorArray.at(num)->getPositionX();//获取最后一个山体的X坐标 //将第一个山体再加入数组中,这样它就成为最后一个元素 floorArray.pushBack(floorArray.at(0)); //删除数组中第一个元素,这样就完成了第一个山体移动到数组中最后的位置 floorArray.eraseObject(floorArray.at(0)); coinArray.pushBack(coinArray.at(0)); coinArray.eraseObject(coinArray.at(0)); //获取0~2的随机数 randomNum = this->getRandomNumber(0, 2); if (randomNum == 0) { isFrontBlank = true; randomNum = this->getRandomNumber(1, 4); } Coin *coin = coinArray.at(num); //数组中最后一个元素,即原来的第一个元素移动到最后位置,再获取最后一个 coin->setVisible(true); if (isFrontBlank) { //posx为数组中倒数第二个元素的X坐标,高度为随机数100~150之间 //设置新的最后一个元素的位置 floorArray.at(num)->setPosition(Point(posx + randomNum*35 + 35, this->getRandomNumber(winSize.height/2 -100,170))); coinArray.at(num)->setPosition(Point(posx + randomNum*35 + 35, floorArray.at(num)->getPositionY() + this->getRandomNumber(50, 150))); isFrontBlank = false; }else{ //X轴坐标后移,高度同前一个山体 floorArray.at(num)->setPosition(Point(posx + 35 , floorArray.at(num - 1)->getPositionY())); coinArray.at(num)->setPosition(Point(posx + 35, floorArray.at(num)->getPositionY() + this->getRandomNumber(50, 150))); } randomNum = this ->getRandomNumber(0, 2); if (randomNum == 0) { coin->setVisible(false); } } }
CCArray *Building::getTransferFloors(){ CCArray *transferFloors = CCArray::create(); for(int i = 0; i < this->arrayFloors->count(); i++){ Floor *floor = (Floor *)this->arrayFloors->objectAtIndex(i); if(floor->getTransferLeft() || floor->getTransferRight()){ transferFloors->addObject(floor); } } return transferFloors; }
Floor *Floor::create(int ID, CCString *name, int floorNumber, bool transferRight, bool transferLeft){ Floor *f = new Floor(ID, name, floorNumber, transferRight, transferLeft); f->autorelease(); if(!arrayFloors){ arrayFloors = CCDictionary::create(); arrayFloors->retain(); } arrayFloors->setObject(f, ID); return f; }
Floor *Building::getFloor(int floorNumber){ if (this->arrayFloors != NULL) { for(int i = 0; i < this->arrayFloors->count(); i++){ Floor *floor = (Floor *)this->arrayFloors->objectAtIndex(i); if(floor->getFloorNumber() == floorNumber){ return floor; } } } return NULL; }
// person walks onto a floor void Person::stepOntoFloor( Floor& floor ) { // notify floor a person is coming cout << "person " << ID << " steps onto floor " << floor.getNumber() << endl; floor.personArrives( this ); // press button on the floor cout << "person " << ID << " presses floor button on floor " << floor.getNumber() << endl; floor.floorButton.pressButton(); }
int main(int argc, char** argv) { srand(lastUpdate); glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(400, 455); glutInitWindowPosition(-1, -1); glutCreateWindow("Pac-Man"); glutDisplayFunc(onDisplay); glutReshapeFunc(onReshape); glutSpecialFunc(onSpecialKeyPress); //glutSpecialUpFunc(onSpecialKeyUp); glutKeyboardFunc(onKeyPress); glutIdleFunc(onIdle); //glutIgnoreKeyRepeat(true); glEnable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT, GL_FILL); mazeFloor.load(); glutMainLoop(); return 0; }
Elevator::Elevator(Floor &flr1, Floor &flr2) : currentFloor(flr1.getNumber()), destFloor(flr1.getNumber()), floor1(flr1), floor2(flr2), personPtr(0), moving(false), doors(), bell(), currentTime(0), arrivalTime(0), movingDirection(NO), elevatorbutton(*this) { cout << "Elevator was created." << endl; }
// person exits elevator void Person::exitElevator( const Floor &floor, Elevator &elevator ) const { cout << "person " << ID << " exits elevator on floor " << floor.getNumber() << endl; elevator.passengerExits(); }
void Ghost::locateGhost(Floor Level) { for (int i = 0; i< 20; i++) { for (int j = 0; j < 30 ; j++) { if (Level.getGrid(i,j) == 'G') { y = i; x = j; } } } }
Elevator::Elevator(const int cap, const int s, const Floor& tFloor) : ID(elevatorID++), capacity(cap), speed(s), toFloor(0) // initialize const data members { location = tFloor.getLocation(); direction = IDLE; doorOpen = true; } // end Elevator class constructor
// arrive at a particular floor void Elevator::arriveAtFloor( Floor& arrivalFloor ) { moving = false; // reset state cout << "elevator resets its button" << endl; elevatorButton.resetButton(); bell.ringBell(); // notify floor that elevator has arrived Person *floorPersonPtr = arrivalFloor.elevatorArrived(); door.openDoor( passengerPtr, floorPersonPtr, arrivalFloor, *this ); // this floor needs service? bool currentFloorNeedsService = currentFloor == Floor::FLOOR1 ? floor1NeedsService : floor2NeedsService; // other floor needs service? bool otherFloorNeedsService = currentFloor == Floor::FLOOR1 ? floor2NeedsService : floor1NeedsService; // if this floor does not need service // prepare to leave for the other floor if ( !currentFloorNeedsService ) prepareToLeave( otherFloorNeedsService ); else // otherwise, reset service flag currentFloor == Floor::FLOOR1 ? floor1NeedsService = false: floor2NeedsService = false; } // end function arriveAtFloor
std::vector<std::vector<bool>> Graph<Room>::generateCorridors(Floor &floor) const { auto arr = floor.toArray(); int minX = floor.MinX(), maxX = floor.MaxX(), minY = floor.MinY(), maxY = floor.MaxY(); for (const auto & node : nodes) { const Room & room = *node.content, & next = *node.neighbors[0]->content; const int room_x = room.middle().x, room_y = room.middle().y, next_x = next.middle().x, next_y = next.middle().y, dx = next_x - minX, dy = maxY - next_y; int x = room_x - minX, y = maxY - room_y; //Horizontal part of corridor if (room_x < next_x) for (; x < dx; ++x) arr[y][x] = true; else for (; x > dx; --x) arr[y][x] = true; //Vertical part of corridor if (room_y < next_y) for (; y > dy; --y) arr[y][x] = true; else for (; y < dy; ++y) arr[y][x] = true; } return arr; }
Elevator::Elevator(const int cap, const int spd, const Floor& startFloor) : ID(Elevator::elevatorID), capacity(cap), speed(spd), toFloor(0) { elevatorID++; location = startFloor.getLocation(); direction = IDLE; doorOpen = true; }
Floor* Tower::getFloor(int floorId) { Floor* floor = _floors.at(floorId); // 楼层缓存初始化 if(floor == nullptr) { ValueMap model; model["url"] = _floorUrls[cocos2d::Value(floorId).asString()]; model["id"] = floorId; model["name"] = StringUtils::format("floor%d", floorId); model["towerId"] = getId(); floor = Floor::create(model); _floors.insert(floorId, floor); floor->setTower(this); } return floor; }
bool Swan::invalidMove(location next, Floor floor){ location floorSize = floor.getSize(); char nextTile = floor.getTile(next.r, next.c); if(nextTile == '#'){ return true; } if(nextTile == 'D'){ return true; } if(nextTile == 'E'){ return true; } if(next.r<0 || next.c<0 || next.r>floorSize.r || next.c>floorSize.c){ return true; } return false; }
Floor *Building::findNearestTransferLeftFloor(int actualFloorNumber){ CCArray *transferFloors = this->getTransferFloors(); Floor *actualFloor = NULL; int actualDiff = 99; for(int i = 0; i < transferFloors->count(); i++){ Floor *floor = (Floor *)transferFloors->objectAtIndex(i); if(floor->getTransferLeft()){ int floorNumber = floor->getFloorNumber(); int diff = abs(actualFloorNumber - floorNumber); if(diff < actualDiff){ actualDiff = diff; actualFloor = floor; } } } return actualFloor; }
void KServer::recv_landscape( vce::VSint32 floorID, vce::VSint32 x1,vce::VSint32 y1,vce::VSint32 x2,vce::VSint32 y2) { if( !m_authenticationSuccess )return; if( !m_pc )return; Floor *fl = World::getFloor(floorID); if(!fl)return; TileType data[4000]; int ind = 0; for(int y=y1; y < y2; y++ ){ for(int x=x1; x < x2; x++){ data[ind++] = fl->getTile(Coord(x,y)).typeID; if( ind == ARRAYLEN(data)) break; } if( ind == ARRAYLEN(data)) break; } send_landscapeResult( floorID, x1,y1,x2,y2, data, ind ); }
bool Dungeon::change_floor_down() { clear_event_queue(); if (floors.size() <= active_floor+1) { Floor *f = new Floor(); f->spawn_pc(PC::instance()); f->place_at_stairs(true); s_instance->floors.push_back(f); s_instance->active_floor++; s_instance->generate_monsters(); s_instance->generate_objects(); s_instance->active_floor--; } s_instance->floors.at(active_floor)->reset_current_vision(); s_instance->active_floor++; queue_monster_turns(); PC::instance()->update_vision(floors.at(active_floor)); return true; }
// person enters elevator void Person::enterElevator( Elevator &elevator, Floor &floor ) { floor.personBoardingElevator(); // person leaves floor elevator.passengerEnters( this ); // person enters elevator // press button on elevator cout << "person " << ID << " presses elevator button" << endl; elevator.elevatorButton.pressButton(); }
/********************************************************************* ** Function: cleanFloor ** Description: Random AI to clean the floor ** Parameters: Floor &floor ** Pre-Conditions: None ** Post-Conditions: None *********************************************************************/ void randomAI::cleanFloor(Floor &floor) { srand(time(NULL)); while (battery > 0) { floor.clean(); int x = rand() % 4 + 1; if (x == 1) { floor.up(); } else if (x == 2) { floor.down(); } else if (x == 3) { floor.right(); } else if (x == 4) { floor.left(); } update(floor); } }
Math::Vector3d Command::getObjectPosition(const ResourceReference &targetRef, int32 *floorFace) { Object *target = targetRef.resolve<Object>(); Floor *floor = StarkGlobal->getCurrent()->getFloor(); Math::Vector3d position; switch (target->getType().get()) { case Type::kBookmark: { Bookmark *bookmark = Object::cast<Bookmark>(target); position = bookmark->getPosition(); if (floorFace) { *floorFace = floor->findFaceContainingPoint(position); } break; } case Type::kItem: { FloorPositionedItem *item = Object::cast<FloorPositionedItem>(target); position = item->getPosition3D(); if (floorFace) { *floorFace = item->getFloorFaceIndex(); } break; } case Type::kPath: { assert(target->getSubType() == Path::kPath3D); Path3D *path = Object::cast<Path3D>(target); position = path->getVertexPosition3D(0, floorFace); break; } default: warning("Unimplemented getObjectPosition target type %s", target->getType().getName()); } return position; }