void WarpTile::reopen() { holePixmap.setVisible(true); holeOpen = true; if(position().x() < MAPW/2) { MapTile *mt = playfield->tileAt(position() + QPoint(1,0)); if(mt->walls() & MT_W) mt->setWalls(mt->walls() - MT_W); } else { if(walls() & MT_W) setWalls(walls() - MT_W); } }
static void cylinder() { glPushMatrix(); glTranslated(-300,-20,-250); glScaled(200,200,200); walls(); glPopMatrix(); glPushMatrix(); glTranslated(300,-20,-250); glScaled(200,200,200); walls(); glPopMatrix(); }
std::vector<WallSpec> RoundConfig::allWalls() const { const auto& appParams = BleepoutParameters::get(); std::vector<WallSpec> walls(_walls); buildAllSpecs(*this, _curvedWallSets, &walls); buildAllSpecs(*this, _wallRings, &walls); return walls; }
void Scene::BuildCornellBoxScene(std::vector<Shape*> &objects) { camera = new Camera( Point(-260, 0, 90), Point(-199, 0, 90) ); float lightEnergy = 35e8; lights.push_back(new SphereLight(Point(0, 0, 160), 3, Color(lightEnergy,lightEnergy,lightEnergy),1)); Color walls(0.1f,0.1f,0.1f); Material* white = new Material(Ambient(0.3,0.3,0.3),Diffuse(0.9, 0.9, 0.9),walls); AddObject("files\\cornell_box\\cornell_box_floor.3ds", new Material(Color(0.3,0.3,0.3),Color(0.9,0.9,0.9),walls, Reflect(0.2, 0.2, 0.2)), objects); AddObject("files\\cornell_box\\cornell_box_ceil.3ds", white, objects); AddObject("files\\cornell_box\\cornell_box_right_wall.3ds", new Material(Color(0.,0.1,0.),Color(0.4,1,0.4),walls), objects); AddObject("files\\cornell_box\\cornell_box_back.3ds", white, objects); AddObject("files\\cornell_box\\cornell_box_left_wall.3ds", new Material(Color(0.1,0.,0.),Color(1,0.4,0.4),walls), objects); AddObject("files\\cornell_box\\cornell_box_box1.3ds", white, objects); AddObject("files\\cornell_box\\cornell_box_box2.3ds", white, objects); objects.push_back(new Sphere(Point(-35,-45,20),15,new Material(Ambient(0,0,0),Diffuse(0,0,0),Specular(0,0,0), Reflect(0,0,0), Refract(1,1,1), 1.51, 1), Shape::GetUniqueID())); objects.push_back(new Sphere(Point(-50,50,15),15,new Material(Ambient(0,0,0),Diffuse(0,0,0),Specular(0,0,0), Reflect(1,1,1)), Shape::GetUniqueID() )); }
void Boid::update(std::vector<Boid *> &otherBoids, ofVec3f &min, ofVec3f &max) { velocity += separationWeight*separation(otherBoids); velocity += cohesionWeight*cohesion(otherBoids); velocity += alignmentWeight*alignment(otherBoids); walls(min, max); position += velocity; }
Entity create_walls(const unsigned int width, const unsigned int height) { Entity walls(Walls::create(width, height), nullptr, // input nullptr, // physics nullptr, // light nullptr); // audio return walls; }
void Pursued::update() { if(!hasDestination) setRandomDestination();/// FOR NO OTHER TARGETS changeDirection(); walls(); if(hasDestination) move(); move(); hasDestination = false; }
QPointF WarpTile::warpTo() { if(!holeOpen) return pos(); Q_ASSERT(targetTile); holePixmap.setVisible(false); holeOpen = false; closedTimer.start(5000); targetTile->warpTo(); if(position().x() < MAPW/2) { MapTile *mt = playfield->tileAt(position() + QPoint(1,0)); mt->setWalls(mt->walls() | MT_W); } else { setWalls(walls() | MT_W); } return targetTile->pos(); }
int main(){ int cases,count=0; scanf("%d",&cases); while (cases--) { int num_walls,hj(0),lj(0); scanf("%d",&num_walls); std::vector<int> walls(num_walls); for (auto i = 0u; i != num_walls; ++i) scanf("%d",&walls[i]); for (auto j = 1u; j != walls.size(); ++j) { if(walls[j-1]>walls[j]) lj++; else if(walls[j-1]<walls[j]) hj++; } count++; printf("Case %d: %d %d\n",count,hj,lj); } }
int main() { sf::RenderWindow window(sf::VideoMode(800, 600), "Movement"); sf::Texture characterTexture; characterTexture.loadFromFile(resourcePath() + "Images/alien.jpg"); sf::Sprite characterSprite; characterSprite.setTexture(characterTexture); characterSprite.setPosition(400, 300); sf::Texture wall1Texture; wall1Texture.loadFromFile(resourcePath() + "Images/wall1.png"); sf::Sprite wall1; wall1.setTexture(wall1Texture); while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } window.clear(); window.draw(characterSprite); movement(characterSprite, window); walls(wall1); window.display(); } return 0; }
/* ************************************************************************* */ bool SimPolygon2D::contains(const Point2& c) const { vector<SimWall2D> edges = walls(); bool initialized = false; bool lastSide = false; BOOST_FOREACH(const SimWall2D& ab, edges) { // compute cross product of ab and ac Point2 dab = ab.b() - ab.a(); Point2 dac = c - ab.a(); double cross = dab.x() * dac.y() - dab.y() * dac.x(); if (fabs(cross) < 1e-6) // check for on one of the edges return true; bool side = cross > 0; // save the first side found if (!initialized) { lastSide = side; initialized = true; continue; } // to be inside the polygon, point must be on the same side of all lines if (lastSide != side) return false; }
//-------------------------------------------------------------- void testApp::update(){ walls(); apply_physics(); }
sf::VertexArray Map::getOutline() const { sf::VertexArray walls(sf::Quads); for (int i = 1; i < _bools.size() - 1; i++) { for (int j = 1; j < _bools[i].size() - 1; j++) { //Si il s'agit d'une zone traversable if (!_bools[i][j]) { //Mur vertical gauche if (_bools[i - 1][j]) { //Point en haut à gauche if (!_bools[i - 1][j - 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness - _width, j*_width - _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness - _width, j*_width - _width - _thickness), _lineColor)); //Point en bas à gauche if (!_bools[i - 1][j + 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness - _width, j*_width + _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness - _width, j*_width + _width + _thickness), _lineColor)); //Point en bas à droite if (!_bools[i - 1][j + 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness - _width, j*_width + _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness - _width, j*_width + _width + _thickness), _lineColor)); //Point en haut à droite if (!_bools[i - 1][j - 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness - _width, j*_width - _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness - _width, j*_width - _width - _thickness), _lineColor)); } //Mur vertical droit if (_bools[i + 1][j]) { //Point en haut¸à gauche if (!_bools[i + 1][j - 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width + _width - _thickness, j*_width - _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width + _width - _thickness, j*_width - _width - _thickness), _lineColor)); //Point en bas à gauche if (!_bools[i + 1][j + 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width + _width - _thickness, j*_width + _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width + _width - _thickness, j*_width + _width + _thickness), _lineColor)); //Point en bas à droite if (!_bools[i + 1][j + 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width + _width + _thickness, j*_width + _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width + _width + _thickness, j*_width + _width + _thickness), _lineColor)); //Point en haut¸à droite if (!_bools[i + 1][j - 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width + _width + _thickness, j*_width - _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width + _width + _thickness, j*_width - _thickness - _width), _lineColor)); } //Mur horizontal haut if (_bools[i][j - 1]) { //Point en haut à gauche if (!_bools[i - 1][j - 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness, j*_width - _width - _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness - _width, j*_width - _width - _thickness), _lineColor)); //Point en haut à droite if (!_bools[i + 1][j - 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness, j*_width - _width - _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness + _width, j*_width - _width - _thickness), _lineColor)); //Point en bas à droite if (!_bools[i + 1][j - 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness, j*_width - _width + _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness + _width, j*_width - _width + _thickness), _lineColor)); //Point en bas à gauche if (!_bools[i - 1][j - 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness, j*_width - _width + _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness - _width, j*_width - _width + _thickness), _lineColor)); } //Mur horizontal bas if (_bools[i][j + 1]) { //Point en haut à gauche if (!_bools[i - 1][j + 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness, j*_width + _width - _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness - _width, j*_width + _width - _thickness), _lineColor)); //Point en haut à droite if (!_bools[i + 1][j + 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness, j*_width + _width - _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness + _width, j*_width + _width - _thickness), _lineColor)); //Point en bas à droite if (!_bools[i + 1][j + 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness, j*_width + _width + _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width + _thickness + _width, j*_width + _width + _thickness), _lineColor)); //Point en bas à gauche if (!_bools[i - 1][j + 1]) walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness, j*_width + _width + _thickness), _lineColor)); else walls.append(sf::Vertex(sf::Vector2f(i*_width - _thickness - _width, j*_width + _width + _thickness), _lineColor)); } } } } return walls; }
void Maze::loadTiles() { const unsigned int spaceSize = 10; const unsigned int totalSize = tileSize + spaceSize; //Load the textures auto getIntRect = [totalSize](unsigned int row, unsigned int col) { return sf::IntRect(static_cast<int>(col*totalSize), static_cast<int>(row*totalSize), static_cast<int>(tileSize), static_cast<int>(tileSize)); }; //Corner tiles tileTextureById_[TileId::DownRightCorner] = getIntRect(4, 0); tileTextureById_[TileId::DownLeftCorner] = getIntRect(4, 1); tileTextureById_[TileId::UpRightCorner] = getIntRect(5, 0); tileTextureById_[TileId::UpLeftCorner] = getIntRect(5, 1); //Corridor tiles tileTextureById_[TileId::LeftRightCorridor] = getIntRect(4, 2); tileTextureById_[TileId::UpDownCorridor] = getIntRect(5, 2); //TShape tiles tileTextureById_[TileId::DownTShape] = getIntRect(4, 3); tileTextureById_[TileId::UpTShape] = getIntRect(4, 4); tileTextureById_[TileId::RightTShape] = getIntRect(5, 3); tileTextureById_[TileId::LeftTShape] = getIntRect(5, 4); //DeadEnd tiles tileTextureById_[TileId::RightDeadEnd] = getIntRect(4, 5); tileTextureById_[TileId::DownDeadEnd] = getIntRect(4, 6); tileTextureById_[TileId::UpDeadEnd] = getIntRect(5, 5); tileTextureById_[TileId::LeftDeadEnd] = getIntRect(5, 6); //Center tiles tileTextureById_[TileId::Center] = getIntRect(6, 7); //Close tiles tileTextureById_[TileId::Close] = getIntRect(7, 6); //Load the walls' hitBoxes enum class WallStyle { TopBar, BotBar, LeftBar, RightBar, TopRightCorner, TopLeftCorner, BotLeftCorner, BotRightCorner }; float ts = static_cast<float>(tileSize); float ws = static_cast<float>(wallSize); std::vector<WallStyle> walls(4); auto getFloatRect = [ts, ws](std::vector<WallStyle>& wallStyles) { std::vector<sf::FloatRect> vec(wallStyles.size()); float sws = ws - 1.f; for(WallStyle w: wallStyles) switch(w) { case WallStyle::TopBar: vec.emplace_back(0.f, 0.f, ts, ws); break; case WallStyle::BotBar: vec.emplace_back(0.f, ts - ws, ts, ws); break; case WallStyle::LeftBar: vec.emplace_back(0.f, 0.f, ws, ts); break; case WallStyle::RightBar: vec.emplace_back(ts - ws, 0.f, ws, ts); break; case WallStyle::TopLeftCorner: { vec.emplace_back(0.f, 1.f, ws, sws); vec.emplace_back(1.f, 0.f, sws, ws); } break; case WallStyle::TopRightCorner: { vec.emplace_back(ts - ws, 1.f, ws, sws); vec.emplace_back(ts - ws, 0.f, sws, ws); } break; case WallStyle::BotLeftCorner: { vec.emplace_back(0.f, ts - ws, ws, sws); vec.emplace_back(1.f, ts - ws, sws, ws); } break; case WallStyle::BotRightCorner: { vec.emplace_back(ts - ws, ts - ws, ws, sws); vec.emplace_back(ts - ws, ts - ws, sws, ws); } break; default: assert(0); break; } wallStyles.clear(); return std::move(vec); }; //Corner tiles walls = {WallStyle::TopBar, WallStyle::LeftBar, WallStyle::BotRightCorner}; tileHitBoxesById_[TileId::DownRightCorner] = getFloatRect(walls); walls = {WallStyle::TopBar, WallStyle::RightBar, WallStyle::BotLeftCorner}; tileHitBoxesById_[TileId::DownLeftCorner] = getFloatRect(walls); walls = {WallStyle::BotBar, WallStyle::LeftBar, WallStyle::TopRightCorner}; tileHitBoxesById_[TileId::UpRightCorner] = getFloatRect(walls); walls = {WallStyle::BotBar, WallStyle::RightBar, WallStyle::TopLeftCorner}; tileHitBoxesById_[TileId::UpLeftCorner] = getFloatRect(walls); //Corridor tiles walls = {WallStyle::TopBar, WallStyle::BotBar}; tileHitBoxesById_[TileId::LeftRightCorridor] = getFloatRect(walls); walls = {WallStyle::RightBar, WallStyle::LeftBar}; tileHitBoxesById_[TileId::UpDownCorridor] = getFloatRect(walls); //TShape tiles walls = {WallStyle::TopBar, WallStyle::BotLeftCorner, WallStyle::BotRightCorner}; tileHitBoxesById_[TileId::DownTShape] = getFloatRect(walls); walls = {WallStyle::BotBar, WallStyle::TopLeftCorner, WallStyle::TopRightCorner}; tileHitBoxesById_[TileId::UpTShape] = getFloatRect(walls); walls = {WallStyle::LeftBar, WallStyle::TopRightCorner, WallStyle::BotRightCorner}; tileHitBoxesById_[TileId::RightTShape] = getFloatRect(walls); walls = {WallStyle::RightBar, WallStyle::TopLeftCorner, WallStyle::BotLeftCorner}; tileHitBoxesById_[TileId::LeftTShape] = getFloatRect(walls); //DeadEnd tiles walls = {WallStyle::TopBar, WallStyle::BotBar, WallStyle::RightBar}; tileHitBoxesById_[TileId::RightDeadEnd] = getFloatRect(walls); walls = {WallStyle::BotBar, WallStyle::LeftBar, WallStyle::RightBar}; tileHitBoxesById_[TileId::DownDeadEnd] = getFloatRect(walls); walls = {WallStyle::TopBar, WallStyle::LeftBar, WallStyle::RightBar}; tileHitBoxesById_[TileId::UpDeadEnd] = getFloatRect(walls); walls = {WallStyle::TopBar, WallStyle::BotBar, WallStyle::LeftBar}; tileHitBoxesById_[TileId::LeftDeadEnd] = getFloatRect(walls); //Center tiles walls = {WallStyle::TopLeftCorner, WallStyle::TopRightCorner, WallStyle::BotLeftCorner, WallStyle::BotRightCorner}; tileHitBoxesById_[TileId::Center] = getFloatRect(walls); //Close tiles walls = {WallStyle::TopBar, WallStyle::BotBar, WallStyle::LeftBar, WallStyle::RightBar}; tileHitBoxesById_[TileId::Close] = getFloatRect(walls); }
/* Funcion principal del programa */ int main (int argc, char * argv[]) { player_t * player1; player_t * player2; int finishp; int p[2][2]; int opt; const char * progname1; const char * progname2; while ((opt = getopt(argc, argv, "bd:n:w:")) != -1) { switch (opt) { /* Establece el retraso entre movimiento y movimiento */ case 'd': delay = atoi (optarg); break; /* No usa SDL, solo recolecta estadisticsa. */ case 'b': graphicsp = 0; break; /* Numero de partidas para simular. */ case 'n': plays = atoi (optarg); break; /* Numero de particulas de muro */ case 'w': nwalls = atoi (optarg); break; default: /* '?' */ usage(); } } if (argc-optind < 2) usage(); progname1 = argv[optind++]; progname2 = argv[optind++]; if(graphicsp) { SDL_Init (SDL_INIT_VIDEO); SDL_WM_SetCaption ("AI Tron", NULL); screen = SDL_SetVideoMode(N * POINTSIZE, N * POINTSIZE, 32, SDL_HWSURFACE); if (screen == NULL) { fprintf (stderr, "El sistema no soporta esta resolucion.\n"); exit (-1); } } initialize_random(); player1 = create_player (progname1); player2 = create_player (progname2); for(current_play=0; current_play<plays; current_play++) { memset (map, 0, sizeof(map)); if (graphicsp) SDL_FillRect( screen, NULL, 0 ); random_position (&p[0][0], &p[0][1]); random_position (&p[1][0], &p[1][1]); prepare_player (player1, p[0][0], p[0][1]); prepare_player (player2, p[1][0], p[1][1]); write_cords (player1, p[1][0], p[1][1]); write_cords (player2, p[0][0], p[0][1]); walls(nwalls, player1, player2); /* Bucle principal */ finishp=0; while(!finishp) { SDL_Event event; draw_point (player1->i, player1->j, 255); draw_point (player2->i, player2->j, 65025); /* Lee los siguientes movimientos de cada bot */ read_cords (player1, &p[0][0], &p[0][1]); read_cords (player2, &p[1][0], &p[1][1]); /* Comprueba si alguien ha perdido */ finishp |= lossp (player1, p[0][0], p[0][1]); finishp |= lossp (player2, p[1][0], p[1][1]); if (!finishp && p[0][0]==p[1][0] && p[0][1]==p[1][1]) { player1->loses++; player2->loses++; finishp = 1; } /* Actualiza el mapa con los movimientos */ move (player1, p[0][0], p[0][1]); move (player2, p[1][0], p[1][1]); turns++; /* Informa del ultimo movimiento de cada bot al otro */ write_cords (player1, p[1][0], p[1][1]); write_cords (player2, p[0][0], p[0][1]); if (graphicsp) { /* Elimina procesos de la cola, y termina en caso de que el usuario lo haya solicitado. */ while( SDL_PollEvent( &event ) ){ if (event.type == SDL_QUIT) { plays = current_play; finishp = 1; } } SDL_Flip (screen); SDL_Delay (delay); } } finish_player (player1); finish_player (player2); } printf ("Resumen:\n"); printf (" %s: %d/%d\n", player1->name, plays - player1->loses, plays); printf (" %s: %d/%d\n", player2->name, plays - player2->loses, plays); printf ("\n"); printf ("Un total de %d turnos, %f turnos de media por partida.\n", turns, (float)turns/plays); close_player (player1); close_player (player2); finalize_random(); if (graphicsp) SDL_Quit (); return 0; }
void box(int x, int y, int z_start, int height, CubeType tile) { walls(x,y,z_start,height,tile); map_gen::floor(x,y,z_start, 1, tile); map_gen::floor(x,y,z_start+height, 1, tile); }