void NewPosition(MazewarInstance::Ptr m) //void NewPosition(MazewarInstance *m) { Loc newX(0); Loc newY(0); Direction dir(0); /* start on occupied square */ while (M->maze_[newX.value()][newY.value()]) { /* MAZE[XY]MAX is a power of 2 */ newX = Loc(random() & (MAZEXMAX - 1)); newY = Loc(random() & (MAZEYMAX - 1)); /* In real game, also check that square is unoccupied by another rat */ } /* prevent a blank wall at first glimpse */ if (!m->maze_[(newX.value())+1][(newY.value())]) dir = Direction(NORTH); if (!m->maze_[(newX.value())-1][(newY.value())]) dir = Direction(SOUTH); if (!m->maze_[(newX.value())][(newY.value())+1]) dir = Direction(EAST); if (!m->maze_[(newX.value())][(newY.value())-1]) dir = Direction(WEST); m->xlocIs(newX); m->ylocIs(newY); m->dirIs(dir); }
int main() { Adjacency v; ID id; Map map(0); cin >> id; Feature * r1 = new MockFeature( id ); r1->addToMap( &map ); cin >> id; Feature * r2 = new MockFeature( id ); r2->addToMap( &map ); cin >> id; Feature * r3 = new MockFeature( id ); r3->addToMap( &map ); std::cout << "******* ADJACENCY TESTS ***********\n"; std::cout << "Input and save test. Expected output same as last " << "line of input plus tag\n"; v.input( std::cin, &map ); v.save( std::cout ); std::cout << '\n'; std::cout << "\nPretty-printed output (should list only exits " << "that are valid above)\n"; v.printDescription( std::cout ); std::cout << "\nDirection checks: Should be similar to above\n"; printExit( v, Direction("north") ); printExit( v, Direction("east") ); printExit( v, Direction("south") ); printExit( v, Direction("west") ); return 0; }
void CellularAutomata::handleMouse(bool isPressed, bool isDown, const Ray & mouseRay, const Vector2 & mousePos) { m_transientPlayhead.position = Vector2int16(-5, -5); if (m_paused) { Point2int16 selectedPosition(-1,-1); for (int x = 0; x < m_width; ++x) { for (int y = 0; y < m_height; ++y) { Vector2 normalizedCoord = Vector2(x,y) * Vector2(1.0f / (m_width - 1.0f), 1.0f / (m_height - 1.0f)); const Point3& p = normCoordTo3DPoint(normalizedCoord); if (intersects(mouseRay, p, collisionRadius())) { selectedPosition = Vector2int16(x, y); } } } if (selectedPosition.x >= 0) { m_transientPlayhead.position = selectedPosition; m_transientPlayhead.direction = Direction::DOWN; // Super hackish way to select the direction to point in based on mouse position // from the center (should work on in either mode, but only tested on 2D) // This is the first thing due for a cleanup float minDistance = 10.0f; // Basically infinity... Vector2 normalizedCoord = Vector2(selectedPosition) * Vector2(1.0f / (m_width - 1.0f), 1.0f / (m_height - 1.0f)); const Point3& center = normCoordTo3DPoint(normalizedCoord); float t = mouseRay.intersectionTime(Sphere(center, collisionRadius())); Point3 intersectionPoint = mouseRay.origin() + mouseRay.direction() * t; for (int i = 0; i < 4; ++i) { Vector2 npos = normalizedCoord + Vector2(vecFromDir(Direction(i)))*0.001f; const Point3& p = normCoordTo3DPoint(npos); if ((intersectionPoint - p).length() < minDistance) { minDistance = (intersectionPoint - p).length(); m_transientPlayhead.direction = Direction(i); } } if (isPressed) { bool removed = false; for (int i = m_playhead.size() - 1; i >= 0; --i) { if (selectedPosition == m_playhead[i].position) { m_playhead.remove(i); removed = true; break; } } if (!removed) { m_playhead.append(m_transientPlayhead); } } } } }
void Player::event(const sf::Event &event) { if (event.type == sf::Event::KeyPressed) { switch (event.key.code) { case sf::Keyboard::Left: if (next != RIGHT) next = LEFT; break; case sf::Keyboard::Right: if (next != LEFT) next = RIGHT; break; case sf::Keyboard::Up: if (next != DOWN) next = UP; break; case sf::Keyboard::Down: if (next != UP) next = DOWN; break; default: next = Direction(0, 0); break; } } else if (event.type == sf::Event::KeyReleased) next = Direction(0, 0); }
std::vector<PlanetData> initializePlanetData() { std::srand(std::time(NULL)); std::vector<PlanetData> data(Planet::TypeCount); data[Planet::Earth].speed = 45.f; data[Planet::Earth].texutre = Textures::Earth; data[Planet::Earth].directions.push_back(Direction(20, 1000.f)); data[Planet::Pluton].speed = 50.f; data[Planet::Pluton].texutre = Textures::Pluton; data[Planet::Pluton].directions.push_back(Direction(0.f, 1000.f)); data[Planet::AsteroidGreate].speed = 70.f; data[Planet::AsteroidGreate].texutre = Textures::AsteroidGreate; data[Planet::AsteroidGreate].directions.push_back(Direction((rand() % 15) * 1.f, 1000.f)); data[Planet::AsteroidAverage].speed = 90.f; data[Planet::AsteroidAverage].texutre = Textures::AsteroidAverage; data[Planet::AsteroidAverage].directions.push_back(Direction(-15, 1000.f)); data[Planet::AsteroidLittle].speed = 110.f; data[Planet::AsteroidLittle].texutre = Textures::AsteroidLittle; data[Planet::AsteroidLittle].directions.push_back(Direction(10.f, 1000.f)); return data; }
TEST (Direction, MazeSetDirection_ReturnSetValue) { location_t loc = {3, 4}; direction_t dir = EAST; EXPECT_EQ (INVALID, Direction (loc)); SetDirection (loc, dir); EXPECT_EQ (dir, Direction (loc)); }
void RandomModel::treesProduce() { /* double y = this->length / 10; double ty = y; double ry = 9 * y; Point tp0(- this->width / 2, ty, TREE_HEIGHT); Point tp1(this->width / 2, ty, TREE_HEIGHT); Point tp2(- this->width / 2, ry, TREE_HEIGHT); Point tp3(this->width / 2, ry, TREE_HEIGHT); Tree t0(tp0); Tree t1(tp1); Tree t2(tp2); Tree t3(tp3); */ double x = this->width / 2; double y = this->length / 10; double z = 0; TreeConfig *tConfig0 = new TreeConfig(3, Point(x, y, z)); Geometry *crown = NULL; ///crown = new Ball(Point(x, y, z+5), 8); //crown = new BallPart(Point(x, y, z+5), 8, Point(x, y, z+3)); //crown = new Cylinder(Point(x, y, z+15), Point(x, y, z+5), 7); //crown = new Cone(Point(x, y, z+25), Point(x, y, z+5), 10); //crown = new Ellipse(Point(x, y, z+13), Point(x, y, z+1), 10, 8); //crown = new EllipsePart(Point(x, y, z+13), Point(x, y, z+1), 10, 8, Point(x, y, z+8), true); crown = new Cuboid(Direction(12,0,0), Direction(0,12,0), Direction(0,0,12), Point(x-3, y-4, z+5)); tConfig0->setCrown(crown); /* TreeConfig *tConfig1 = new TreeConfig(3, Point(-x, y, z)); TreeConfig *tConfig2 = new TreeConfig(3, Point(x,this->length - y, z)); TreeConfig *tConfig3 = new TreeConfig(3, Point(-x, this->length - y, z)); */ Tree t0(tConfig0); t0.generate(); t0.generateLeavesList(); /* Tree t1(tConfig1); t1.generate(); t1.generateLeavesList(); Tree t2(tConfig2); t2.generate(); t2.generateLeavesList(); Tree t3(tConfig3); t3.generate(); t3.generateLeavesList(); */ this->trees.push_back(t0); /* this->trees.push_back(t1); this->trees.push_back(t2); this->trees.push_back(t3); */ }
CircleGroup Field::GetSameColoredCircles( const Coordinate& startCoordinate )const { Direction dirs[ 4 ] = { Direction( 0, 1 ), // <- WEST Direction( 1, 1 ), // _\| NORD_WEST Direction( 1, 0 ), // _|_ NORD Direction( 1, -1 ) // _|/_ NORD_EAST }; Coordinate firstCircle; CircleGroup result; result.isErase = false; int count = 0; int row = 0, col = 0; int i = 0; for( i = 0; i < 4; i ++ ) { firstCircle = GetFirstCircle( startCoordinate, dirs[ i ] ); row = firstCircle.row ; col = firstCircle.col ; count = 0; while( field[ firstCircle.row ][ firstCircle.col ].color == field[ row ][ col ].color && row >= 0 && row <= NUMSQUARES && col >= 0 && col < NUMSQUARES && ( field[ row ][ col ].isFilled == true ) ) { row += dirs[ i ].plusToRow; col += dirs[ i ].plusToCol; count ++; } if( count >= 5 ) break; } result.countOfCircles = count; result.firstCircle = firstCircle; result.isErase = ( count >= 5 ) ? true : false; result.moveDir = dirs[ i ]; return result; }
String DumbDirectionSolver::mergeCommands(Point bomb, Direction direction) const { if (direction == Direction(LL("STOP"))) { bomb.setNull(true); } StringStream ss; if (!bomb.isNull()) { ss << Direction(LL("ACT")).toString(); if (direction != Direction(LL("NULL"))) { ss << LL(","); } } ss << direction.toString(); return ss.str(); }
Spiral::Direction Spiral::getIdealDirection(Direction current) { if(rotation == Clockwise) { return Direction((current + 1) % Count); } else { if(current == Up) return Left; return Direction(current - 1); } }
std::vector<AircraftData> initializeAircraftData(){ std::vector<AircraftData> data(Aircraft::TypeCount); data[Aircraft::EAGLE].hitpoints = 100; data[Aircraft::EAGLE].speed = 200.f; data[Aircraft::EAGLE].texture = Resources::Textures::Entities; data[Aircraft::EAGLE].textureRect = sf::IntRect(0, 0, 48, 64); data[Aircraft::EAGLE].hasRollAnimation = true; data[Aircraft::RAPTOR].hitpoints = 20; data[Aircraft::RAPTOR].speed = 80; data[Aircraft::RAPTOR].texture = Resources::Textures::Entities; data[Aircraft::RAPTOR].textureRect = sf::IntRect(144, 0, 84, 64); data[Aircraft::RAPTOR].hasRollAnimation = false; data[Aircraft::RAPTOR].directions.push_back(Direction(+45, 80)); data[Aircraft::RAPTOR].directions.push_back(Direction(-45, 160)); data[Aircraft::RAPTOR].directions.push_back(Direction(+45, 80)); data[Aircraft::AVENGER].hitpoints = 40; data[Aircraft::AVENGER].speed = 50.f; data[Aircraft::AVENGER].texture = Resources::Textures::Entities; data[Aircraft::AVENGER].textureRect = sf::IntRect(228, 0, 60, 59); data[Aircraft::AVENGER].hasRollAnimation = false; data[Aircraft::AVENGER].directions.push_back(Direction(+45, 50)); data[Aircraft::AVENGER].directions.push_back(Direction(0, 50)); data[Aircraft::AVENGER].directions.push_back(Direction(-45, 100)); data[Aircraft::AVENGER].directions.push_back(Direction(0, 50)); data[Aircraft::AVENGER].directions.push_back(Direction(+45, 50)); return data; }
Direction BallAIFunction(QbertModel* /*model*/) { srand( (unsigned)time(NULL) ); if (LastBox->IsOnPerimeter()) return IntoBox; if (MovingDirection == OutOfBox) return Direction(rand() % 4); if (MovingDirection == Left) return ((rand() % 2) ? Right: Up); if (MovingDirection == Right) return ((rand() % 2) ? Left: Up); return Direction(rand() % 3); }
/// Creates a slaw that fully describes a Hand found by the Leap Slaw ToSlaw (Leap::Hand const& h) const { Leap::Vector phys_origin = Point (h . palmPosition ()), phys_through = phys_origin + Direction (h . direction ()); return Slaw::Map ("id", h . id (), "dir", ToSlaw (Direction (h . direction ())), "plmnrm", ToSlaw (Direction (h . palmNormal ())), "plmpos", ToSlaw (phys_origin), "plmvel", ToSlaw (h . palmVelocity ()), "center", ToSlaw (Direction (h . sphereCenter ())), "radius", h . sphereRadius (), "orig", ToSlaw (phys_origin), "thru", ToSlaw (phys_through)); }
void Game::areDelayHandleEvent(const SDL_Event &event) { if (event.type == SDL_KEYUP){ SDLKey sym = event.key.keysym.sym; if (sym == playerData->moveLeft){ dropStatus = NORMAL; } else if (sym == playerData->moveRight){ dropStatus = NORMAL; } } if (event.type == SDL_KEYDOWN){ SDLKey sym = event.key.keysym.sym; if (sym == playerData->moveLeft){ dropStatus = ARRLEFT; } else if (sym == playerData->moveRight){ dropStatus = ARRRIGHT; } else if (sym == playerData->rotateLeft){ direction = Direction( direction == 3? 0: direction + 1); } else if (sym == playerData->rotateRight){ direction = Direction( direction == 0? 3: direction - 1); } else if (sym == playerData->hardDrop){ pos = getLockPos(); ResourceData::sound->playChunk(Sound::HARDDROP); if (!checkBlock(pos, direction)){ gameOver(); } else{ fillMap(); gameStatus = START; } } else if (sym == playerData->hold){ if (holdStatus == PREPAREHOLD){ ResourceData::sound->playChunk(Sound::HOLD); holdStatus = HOLD; gameStatus = START; } else{ ResourceData::sound->playChunk(Sound::HOLDFAIL); } } } }
/* \brief 二分查找法,求多边形上方向是u的极点,设凸多边形是逆时针顺序的。 */ int ExtremePoint_BinarySearch( const Point2D* p, int n, const Vector2D& u) { int a = 0, b = n, m; int upA = Direction(p[1] - p[0],u) , upM; if( upA<=0 && !IsAbove(p[n-1],p[0],u) ) return 0; while(true) { m = (a + b) / 2; upM = Direction(p[(m+1)%n] - p[m],u); if( upM<=0 && !IsAbove(p[m-1],p[m],u) ) return m; if( upA>0 ) { if( upM<0 ) { //选择[a,m] b = m; } else if( IsAbove(p[a],p[m],u) ) { //选择[a,m] b = m; } else { //选择[m,b] a = m; upA = upM; } } else { if( upM>0 ) { //选择[m,b] a = m; upA = upM; } else if( IsBelow(p[a],p[m],u) ) { //选择[a,m] b = m; } else { //选择[m,b] a = m; upA = upM; } } } return 0; }
/* readonly attribute unsigned long direction; */ NS_IMETHODIMP nsDOMSimpleGestureEvent::GetDirection(uint32_t *aDirection) { NS_ENSURE_ARG_POINTER(aDirection); *aDirection = Direction(); return NS_OK; }
//--------------------------------------------------------- // valueChanged //--------------------------------------------------------- void EditDrumset::valueChanged() { if(!pitchList->currentItem()) return; int pitch = pitchList->currentItem()->data(Column::PITCH, Qt::UserRole).toInt(); nDrumset.drum(pitch).name = name->text(); if (customGbox->isChecked() || noteHead->currentIndex() == noteHead->findData(int(NoteHead::Group::HEAD_CUSTOM))) { fillCustomNoteheadsDataFromComboboxes(pitch); setCustomNoteheadsGUIEnabled(true); } else { nDrumset.drum(pitch).notehead = NoteHead::Group(noteHead->currentData().toInt()); fillNoteheadsComboboxes(false, pitch); setCustomNoteheadsGUIEnabled(false); } nDrumset.drum(pitch).line = staffLine->value(); nDrumset.drum(pitch).voice = voice->currentIndex(); nDrumset.drum(pitch).stemDirection = Direction(stemDirection->currentIndex()); if (QString(QChar(nDrumset.drum(pitch).shortcut)) != shortcut->currentText()) { if (shortcut->currentText().isEmpty()) nDrumset.drum(pitch).shortcut = 0; else nDrumset.drum(pitch).shortcut = shortcut->currentText().at(0).toLatin1(); } updateExample(); }
Color PointLight::Illuminate(const Point3& p, const Point3& N) const { Color returnColor = Color(0.0f); if (size > 0) { CircleSampler randomCircleSampler = CircleSampler(SHADOW_SAMPLE_COUNT, SHADOW_SAMPLE_COUNT, size, p, position); randomCircleSampler.generateSamples(); Point3 randomVectorW; Point3 vectorU = Point3(0.0f, 0.0f, 0.0f); Point3 vectorV = Point3(0.0f, 0.0f, 0.0f); Point3 lightDir; lightDir = -1 * Direction(p); Ray sampleRay; Point3 offset; Point3 samplePosition; getOrthoNormalBasisVector(lightDir, vectorU, vectorV); for (int i = 0; i < randomCircleSampler.getCurrentSampleCount(); ++i) { offset = randomCircleSampler.getSample(i).getOffset(); samplePosition = position + offset.x*vectorU + offset.y*vectorV; sampleRay.dir = samplePosition + lightDir /*Direction(samplePosition)*/; sampleRay.p = p; randomCircleSampler.setSampleColor(i, Shadow(sampleRay)* intensity); randomCircleSampler.setIsSampleHit(i, true); } returnColor = randomCircleSampler.getAveragedSampleListColor(); } else returnColor = Shadow(Ray(p,position-p),1) * intensity; //delete randomCircleSampler; return returnColor; }
void GameStateManager::reactToBlockDestruction(const WorldCoords & wc) { // Clear the block alerts. The only alerts that can possibly be // stored with a solid block are of the type that we process here, // so we clear the entire range. auto interesting_blocks = m_map.blockAlerts().equal_range(wc); m_map.blockAlerts().erase(interesting_blocks.first, interesting_blocks.second); // Remove attached torches. WorldCoords wn; for (size_t k = 1; k < 6; ++k) { const WorldCoords wn = wc + Direction(k); if (!m_map.haveChunk(getChunkCoords(wn))) continue; unsigned char & block = m_map.chunk(getChunkCoords(wn)).blockType(getLocalCoords(wn)); if (block == BLOCK_Torch) { sendToAll(MAKE_CALLBACK(packetSCBlockChange, wn, BLOCK_Air, 0)); block = BLOCK_Air; m_map.chunk(getChunkCoords(wn)).taint(); reactToSuccessfulDig(wn, EBlockItem(block)); } } }
RNRgb R3DirectionalLight:: Reflection(const R3Brdf& brdf, const R3Point& eye, const R3Point& point, const R3Vector& normal) const { // Check if light is active if (!IsActive()) return RNblack_rgb; // Get material properties const RNRgb& Dc = brdf.Diffuse(); const RNRgb& Sc = brdf.Specular(); RNScalar s = brdf.Shininess(); // Get light properties RNScalar I = Intensity(); R3Vector L = -(Direction()); const RNRgb& Ic = Color(); // Compute geometric stuff RNScalar NL = normal.Dot(L); if (RNIsNegativeOrZero(NL)) return RNblack_rgb; R3Vector R = (2.0 * NL) * normal - L; R3Vector V = eye - point; V.Normalize(); RNScalar VR = V.Dot(R); // Compute diffuse reflection RNRgb rgb = (I * NL) * Dc * Ic; // Compute specular reflection if (RNIsPositive(VR)) rgb += (I * pow(VR,s)) * Sc * Ic; // Return total reflection return rgb; }
bool Articulation::setProperty(P_ID propertyId, const QVariant& v) { score()->addRefresh(canvasBoundingRect()); switch (propertyId) { case P_DIRECTION: setDirection(Direction(v.toInt())); break; case P_ARTICULATION_ANCHOR: anchorStyle = PropertyStyle::UNSTYLED; setAnchor(ArticulationAnchor(v.toInt())); break; case P_TIME_STRETCH: setTimeStretch(v.toDouble()); score()->fixTicks(); break; default: return Element::setProperty(propertyId, v); } score()->addRefresh(canvasBoundingRect()); // layout: if (chordRest()) chordRest()->layoutArticulations(); else if (parent() && parent()->type() == BAR_LINE) static_cast<BarLine*>(parent())->layout(); score()->addRefresh(canvasBoundingRect()); score()->setLayoutAll(false); //DEBUG return true; }
/** * <param name="gameTime"></param> * <param name="horizontalAxis_"> value between -1.0 and 1.0 </param> * <param name="verticalAxis_"> value between -1.0 and 1.0 </param> * <param name="rollAxis_"> value between -1.0 and 1.0 </param> * <param name="zoom"> zoom value </param> */ void ArcBallCameraController::HandleControls(const GameTime& gameTime_, float rightAxis_, float upAxis_, float forwardAxis_, float horizontalOrbit_, float verticalOrbit_, float /*rollOrbit_*/, float zoom_) { float r = rightAxis_ * gameTime_.FrameTime() * m_fInputDisplacementRate; float u = upAxis_ * gameTime_.FrameTime() * m_fInputDisplacementRate; float f = forwardAxis_ * gameTime_.FrameTime() * m_fInputDisplacementRate; float dH = horizontalOrbit_ * gameTime_.FrameTime() * m_fInputTurnRate; float dV = verticalOrbit_ * gameTime_.FrameTime() * m_fInputTurnRate; //float dR = rollOrbit_ * gameTime_.FrameTime() * m_fInputTurnRate; if ( dH != 0.0f ) RotateTargetRight(dH);//OrbitUp( dH ); if ( dV != 0.0f ) RotateTargetUp(dV); //OrbitRight( dV ); //if ( dR != 0.0f ) RotateClockwise( dR ); //decrease distance to target m_fDistance += zoom_ * gameTime_.FrameTime() * m_fInputDistanceRate; if ( m_fDistance < 0.001f ) m_fDistance = 0.001f; if ( r != 0.0f || u != 0.0f || f != 0.0f ) { Vector3F pos = Target() + (Right() * r) + (Up() * u) + (Direction() * f); Target(pos); /*Vector3F target = pos; target.Normalize(); target *= m_fDistance; target += pos; SetCamera(pos, target, Up());*/ } }
void CellularAutomata::init(int width, int height, int numPlayHeads, int bpm, int sampleRate) { m_sampleRate = sampleRate; m_bpm = bpm; m_currentTime = 0.0f; m_width = width; m_height = height; m_paused = true; m_playhead.fastClear(); Random& rnd = Random::common(); for (int i = 0; i < numPlayHeads; ++i) { int x = rnd.integer(1, width-2); int y = rnd.integer(1, height-2); Direction d = Direction(rnd.integer(0,3)); m_playhead.append(PlayHead(x,y, d)); } m_soundBank.fastClear(); Array<double> frequencies; Array<PianoKey> keys; keys.append(PianoKey::C, PianoKey::D, PianoKey::E, PianoKey::G, PianoKey::A); for (int i = 1; i <keys.size(); ++i) { frequencies.append(getFrequencyFromKey(keys[i], 3)); } for (int i = 0; i <keys.size(); ++i) { frequencies.append(getFrequencyFromKey(keys[i], 4)); } for (double frequency : frequencies) { float duration = 0.3f; float fadeOutProportion = 0.2f; m_soundBank.append(AudioSample::createSine(m_sampleRate, frequency, int(duration * m_sampleRate), fadeOutProportion)); } }
int NeighborDirection::getOpposite(int d) { switch (Direction(d)) { case Front: return Back; break; case Back: return Front; break; case Left: return Right; break; case Right: return Left; break; case Top: return Bottom; break; case Bottom: return Top; break; default: return -1; break; } }
Ref FollowCam::GetRef() { Point3D Direction(m_Vehicle->MyRef.Speed); Direction.z() = 0; if (Direction.normalize() == 0) Direction = m_Vehicle->MyRef.GetDirection(); return Ref(Direction*(-8.f) + m_Vehicle->MyRef.Position + Z*3.f,Direction,Up); }
// Handle mouse movement void _Camera::HandleMouse(float UpdateX, float UpdateY) { Yaw += glm::radians(UpdateX) * Sensitivity[0]; if(Yaw > DOUBLE_PI) Yaw -= DOUBLE_PI; if(Yaw < 0) Yaw += DOUBLE_PI; Pitch += glm::radians(UpdateY) * Sensitivity[1]; if(Pitch > PitchLimit) Pitch = PitchLimit; else if(Pitch < -PitchLimit) Pitch = -PitchLimit; float AdjustedYaw = Yaw - HALF_PI; float AdjustedPitch = Pitch + HALF_PI; float CosPitch = cosf(AdjustedPitch); float SinPitch = sinf(AdjustedPitch); float CosYaw = cosf(AdjustedYaw); float SinYaw = sinf(AdjustedYaw); glm::vec3 Direction(SinPitch * CosYaw, CosPitch, SinPitch * SinYaw); switch(Type) { case FREEMOVE: { } break; case THIRD_PERSON: { Position = Direction * -Distance; } break; } }
int NeighborDirection::getOpposite(int d) { switch (Direction(d)) { case BottomLeft: return TopRight; break; case Left: return Right; break; case TopLeft: return BottomRight; break; case BottomRight: return TopLeft; break; case Right: return Left; break; case TopRight: return BottomLeft; break; default: ERRPUT << "*** ERROR *** : unknown face" << endl; return -1; break; } }
const noFlag* GameWorldBase::GetRoadFlag(MapPoint pt, Direction& dir, unsigned prevDir) const { unsigned i = 0; while(true) { // suchen, wo der Weg weitergeht for(i = 0; i < Direction::COUNT; ++i) { if(i != prevDir && GetPointRoad(pt, Direction::fromInt(i))) break; } if(i == 6) return nullptr; pt = GetNeighbour(pt, Direction::fromInt(i)); // endlich am Ende des Weges und an einer Flagge angekommen? if(GetNO(pt)->GetType() == NOP_FLAG) { dir = Direction(i + 3); return GetSpecObj<noFlag>(pt); } prevDir = (i + 3) % 6; } }
bool nofAttacker::AttackFlag(nofDefender* /*defender*/) { // Zur Flagge laufen, findet er einen Weg? unsigned char tmp_dir = gwg->FindHumanPath(pos, attacked_goal->GetFlag()->GetPos(), 3, true); if(tmp_dir != 0xFF) { // Hat er drumrum gewartet? bool waiting_around_building = (state == STATE_ATTACKING_WAITINGAROUNDBUILDING); // Ja er hat einen Weg gefunden, also hinlaufen // Wenn er steht, muss er loslaufen if(waiting_around_building) StartWalking(Direction(tmp_dir)); state = STATE_ATTACKING_ATTACKINGFLAG; // Hatte er ums Gebäude gewartet? if(waiting_around_building) { // evtl. Nachrücker senden attacked_goal->SendSuccessor(pos, radius); } return true; } return false; }
/// Creates a slaw that fully describes a Leap Pointing gesture Slaw ToSlaw (Leap::Pointable const& p) const { Leap::Vector phys_origin = Point (p . tipPosition ()), phys_through = phys_origin + p . length () * Direction (p . direction ()); return Slaw::Map ("id", p . id (), "dir", ToSlaw (Direction (p . direction ())), "hand", p . hand () . id (), "isfngr", p . isFinger (), "istool", p . isTool (), "length", p . length ()) . MapMerge (Slaw::Map ("t-pos", ToSlaw (phys_origin), "t-vel", ToSlaw (p . tipVelocity ()), "width", p . width (), "orig", ToSlaw (phys_origin), "thru", ToSlaw (phys_through))); }