// // Génération des couloirs entre les pièces // void Level::generateBspCorridor() { Room* lastRoom = nullptr; int lastX = 0; int lastY = 0; int currentX = 0; int currentY = 0; int i = 0; for (Room* room: rooms_) { //centre de la room currentX = room->x + (room->width / 2); currentY = room->y + (room->height / 2); if (i > 0) { //centre de la lastRoom lastX = lastRoom->x + (lastRoom->width / 2); lastY = lastRoom->y + (lastRoom->height / 2); digRectangle(currentX, currentY, lastX, currentY); digRectangle(currentX, currentY, currentX, lastY); createDoor(currentX, currentY); } lastRoom = room; i++; } }
void Level03::setBG() { m_worldMap = Node::create(); Sprite* bg[4]; for (int i = 0; i < 4; i++) { bg[i] = Sprite::create("img/caveBackground.png"); // position the sprite on the center of the screen bg[i]->setScale(m_visibleSize.width / m_visibleSize.height); bg[i]->setPosition(Point((m_visibleSize.width) * i+1, m_visibleSize.height / 2)); // add the sprite as a child to this layer m_worldMap->addChild(bg[i]); } m_doorList[2] = createDoor(m_visibleSize.width * 2.7); m_doorList[0] = createDoor(m_visibleSize.width * 2.2); m_doorList[1] = createDoor(m_visibleSize.width * 3.4); this->addChild(m_worldMap); }
level initializeFromFile(const char* path, int *nbPersos, int *nbPlatforms, int *nbDoors, carre **squares, carre **platforms, carre **doors){ level l ; l.scale = 1; FILE *file = NULL; file = fopen(path, "r"); if (file == NULL) { printf("Le fichier de niveau n'a pas pu être ouvert\n"); exit(1); } int i = 0; int w, h, r, v, b, x, y, dec, shadow, type, toLvl, beginPlatform, finalPlatform, doorPlatform; float jump_power, level_scale; if(fscanf(file, "%*s : %f", &level_scale)==1){ l.scale = level_scale; } else printf("Failed to assign the right inputs.\n"); if(fscanf(file, "%*s : %d", nbPlatforms)==1){ *platforms = (carre *) malloc(*nbPlatforms * sizeof(carre)); if (platforms == NULL) { printf("NOT ENOUGH MEMORY"); exit(1); } } else printf("Failed to assign the right inputs.\n"); for (i = 0; i < *nbPlatforms; ++i) { if(fscanf(file, "%d %d %d %d %d %d", &w, &h, &x, &y, &shadow, &type)==6){ (*platforms)[i] = createPlatform(w, h, x, y, shadow, type); } else printf("Failed to assign the right inputs.\n"); } if(fscanf(file, "%*s : %d", nbDoors)==1){ *doors = (carre *) malloc(*nbDoors * sizeof(carre)); if (doors == NULL) { printf("NOT ENOUGH MEMORY"); exit(1); } } else printf("Failed to assign the right inputs.\n"); for (i = 0; i < *nbDoors; ++i) { if(fscanf(file, "%d %d %d %d %d %d", &w, &h, &x, &doorPlatform, &shadow, &toLvl)==6){ (*doors)[i] = createDoor(w, h, x, (*platforms)[doorPlatform].y + (*platforms)[doorPlatform].height, shadow, toLvl); } else printf("Failed to assign the right inputs D .\n"); } //printf("Number of platforms : %d\n", *nbPlatforms); if(fscanf(file, "%*s : %d", nbPersos)==1){ *squares = (carre*) malloc(*nbPersos * sizeof(carre)); if (squares == NULL) { printf("NOT ENOUGH MEMORY"); exit(1); } } else printf("Failed to assign the right inputs.\n"); //printf("Number of characters : %d\n", *nbPersos); for (i = 0; i < *nbPersos; ++i) { if(fscanf(file, "%d %d %d %d %d %d %f %d %d %d", &w, &h, &x, &beginPlatform, &finalPlatform, &dec, &jump_power, &r, &v, &b)==10){ (*squares)[i] = createCarre(w, h, x, (*platforms)[beginPlatform].y + (*platforms)[beginPlatform].height, (*platforms)[finalPlatform].x + dec, (*platforms)[finalPlatform].y + (*platforms)[finalPlatform].height, jump_power, r, v, b); printf("%d\n", (*squares)[i].height); } else printf("Failed to assign the right inputs.\n"); } fclose(file); return l; }
Door* PropFactory::createDoor(){ return createDoor(100); }
void Level01::setBG() { m_worldMap = Node::create(); if (UserDefault::getInstance()->getBoolForKey("light")) { m_collision = m_visibleSize.width*0.3; } else { m_collision = -m_visibleSize.width*0.7; } Sprite* bg[3]; for (int i = 0; i < 3; i++) { bg[i] = Sprite::create("img/background.png"); // position the sprite on the center of the screen bg[i]->setScale(m_visibleSize.width / m_visibleSize.height); bg[i]->setPosition(Point((m_visibleSize.width) * i+1, m_visibleSize.height / 2)); // add the sprite as a child to this layer m_worldMap->addChild(bg[i]); } createObjectOnFloor(bg[1]->getBoundingBox().getMidX()- 200, "img/chair.png"); createObjectOnFloor(bg[1]->getBoundingBox().getMidX(), "img/chair.png"); createObjectOnFloor(bg[1]->getBoundingBox().getMidX(), "img/table.png"); createObjectOnFloor(bg[0]->getBoundingBox().getMidX(), "img/chair.png"); auto drawing2 = Sprite::create("img/drawing01.png"); drawing2->setScale(2); drawing2->setPosition(Vec2(m_visibleSize.width * 1.3, m_visibleSize.height / 1.4)); //m_worldMap->addChild(drawing2); //m_doorList[2] = createDoor(m_visibleSize.width * 2.7); m_doorList[0] = createDoor(convertToNodeSpace(sprite->getPosition()).x); //m_doorList[1] = createDoor(m_visibleSize.width * 3.4); auto sadman = Sprite::create("img/sadman01.png"); sadman->setScale(1.8); sadman->setPosition(Vec2(m_visibleSize.width * 1.2 + 55, m_floorPoint + sadman->getBoundingBox().getMaxY())); m_worldMap->addChild(sadman); if (UserDefault::getInstance()->getBoolForKey("light")) { sadman->setVisible(true); } else { sadman->setVisible(false); } auto sadmanAnim = Animation::create(); sadmanAnim->addSpriteFrameWithFileName("img/sadman01.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman01.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman02.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman01.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman02.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman03.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman02.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman03.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman02.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman03.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman02.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman03.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman04.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman04.png"); sadmanAnim->addSpriteFrameWithFileName("img/sadman04.png"); sadmanAnim->setLoops(-1); sadmanAnim->setDelayPerUnit(0.3f); sadmanAnim->setRestoreOriginalFrame(true); auto sadmanAnimate = Animate::create(sadmanAnim); sadman->runAction(RepeatForever::create(sadmanAnimate)); m_doorList[1] = sadman; this->addChild(m_worldMap); }