Map::Map(WINDOW* win) : _bossMode(false), _score(0), _window(win) { srand(time(NULL)); for (int i = 0; i < NB_ENEMIES; ++i) { _resetPosition(_entities_list[i]); } for (int i = 0; i < NB_WALLS; ++i) { _resetPosition(_walls[i]); } for (int i = 0; i < NB_BLAST; ++i) { _blast_list[i] = NULL; } }
bool PerformanceTest::init() { if (!LayerColor::initWithColor(cocos2d::Color4B(105, 105, 105, 255))) { return false; } _text = cocos2d::Label::create(); _text->setPosition(cocos2d::Director::getInstance()->getVisibleSize().width * 0.5f, 60.f); _text->setAlignment(cocos2d::TextHAlignment::CENTER); this->addChild(_text); _addingArmature = false; _removingArmature = false; _dragonBonesData = _factory.loadDragonBonesData("DragonBoy/DragonBoy.json"); if (_dragonBonesData) { _factory.loadTextureAtlasData("DragonBoy/DragonBoy_texture_1.json"); cocos2d::Director::getInstance()->getScheduler()->schedule( [&](float passedTime) { if (_addingArmature) { _addArmature(); _addArmature(); _addArmature(); _addArmature(); _addArmature(); _addArmature(); _addArmature(); _addArmature(); _addArmature(); _addArmature(); _resetPosition(); } if (_removingArmature) { _removeArmature(); _removeArmature(); _removeArmature(); _removeArmature(); _removeArmature(); _removeArmature(); _removeArmature(); _removeArmature(); _removeArmature(); _removeArmature(); _resetPosition(); } dragonBones::WorldClock::clock.advanceTime(passedTime); }, this, 0.f, false, "clock" ); const auto listener = cocos2d::EventListenerTouchOneByOne::create(); listener->onTouchBegan = CC_CALLBACK_2(PerformanceTest::_touchBeganHandler, this); listener->onTouchEnded = CC_CALLBACK_2(PerformanceTest::_touchEndedHandler, this); this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); // for (std::size_t i = 0; i < 100; ++i) { _addArmature(); } _resetPosition(); } else { assert(false); } return true; }
void Map::_computeEntities() { if (_bossMode) { _boss.moveY(_boss.vy()); // _boss.moveX(_boss.vx()); if (_boss.y() <= 1 || _boss.y() + _boss.height() >= 30) { _boss.set_vy(_boss.vy() * -1); } // _boss.set_vx(_boss.vx() * -1); for (int j = 0; j < NB_BLAST; j++) { if (!_blast_list[j]) { Blast* shot = _boss.attack(); _blast_list[j] = shot; break ; } } for (int j = 0; j < NB_BLAST; j++) { if (!_blast_list[j]) { Blast* shot = _boss.attack2(); _blast_list[j] = shot; break ; } } for (int i = 0; i < NB_BLAST; ++i) { // BLAST if (_blast_list[i]) { int oldx = _blast_list[i]->x(); _blast_list[i]->moveX(_blast_list[i]->vx()); int x = _blast_list[i]->x(); (void)x, (void)oldx; if (x >= _boss.x() && x <= _boss.x() + _boss.width() && _blast_list[i]->y() >= _boss.y() && _blast_list[i]->y() <= _boss.y() + _boss.height()) { _boss.takeDamage(1); delete _blast_list[i]; _blast_list[i] = NULL; } // FEATURE AMMOS if (_blast_list[i]) { if (_blast_list[i]->x() >= 137 || _blast_list[i]->x() <= 0) { delete _blast_list[i]; _blast_list[i] = NULL; } } if (_blast_list[i] // est-ce que le missile ennemie va nous toucher ? && x <= _player.x() + _player.width() && oldx >= _player.x() && _blast_list[i]->y() >= _player.y() && _blast_list[i]->y() < _player.y() + _player.height()) { delete _blast_list[i]; _blast_list[i] = NULL; _player.takeDamage(1); } if (_blast_list[i]) { // si toujours en vie _renderEntity(*_blast_list[i]); } } } if (_boss.hp() <= 0 || _player.x() + _player.width() >= _boss.x()) { _score += 42000; _player.takeDamage(42); } } else { for (int i = 0; i < NB_ENEMIES; ++i) { // ENEMIES { int oldx = _entities_list[i].x(); _entities_list[i].moveX(_entities_list[i].vx()); int x = _entities_list[i].x(); //if (x <= _player.x() && oldx >= _player.x() // && _entities_list[i].y() == _player.y()) { // collision if (x <= _player.x() + _player.width() && oldx >= _player.x() && _entities_list[i].y() >= _player.y() && _entities_list[i].y() < _player.y() + _player.height()) { // collision _player.takeDamage(1); _resetPosition(_entities_list[i]); } else if (_entities_list[i].x() <= 1) { _resetPosition(_entities_list[i]); } if (_entities_list[i].x() <= 136 // si toujours sur la map, possibilitee de tirer && _entities_list[i].y() == _player.y() && rand() % 9 == 3) { for (int j = 0; j < NB_BLAST; j++) { if (!_blast_list[j]) { Blast* shot = _entities_list[i].attack(); _blast_list[j] = shot; break ; } } } } } // ASTEROIDS for (int i = 0; i < NB_WALLS; i++) { { int oldx = _walls[i].x(); _walls[i].moveX(_walls[i].vx()); int x = _walls[i].x(); if (x <= _player.x() + _player.width() && oldx >= _player.x() && _walls[i].y() >= _player.y() && _walls[i].y() < _player.y() + _player.height()) { // collision _player.takeDamage(1); _resetPosition(_walls[i]); } else if (_walls[i].x() <= 1) { _resetPosition(_walls[i]); } } } for (int i = 0; i < NB_BLAST; ++i) { // BLAST if (_blast_list[i]) { int oldx = _blast_list[i]->x(); _blast_list[i]->moveX(_blast_list[i]->vx()); int x = _blast_list[i]->x(); for (int j = 0; j < NB_ENEMIES; j++) { if (x >= _entities_list[j].x() && oldx <= _entities_list[j].x() && _blast_list[i]->y() == _entities_list[j].y()) { _resetPosition(_entities_list[j]); delete _blast_list[i]; _blast_list[i] = NULL; _score += 42; break ; } } if (_blast_list[i]) { for (int j = 0; j < NB_WALLS; j++) { if (x >= _walls[j].x() && oldx <= _walls[j].x() && _blast_list[i]->y() == _walls[j].y()) { delete _blast_list[i]; _blast_list[i] = NULL; break ; } } } if (_blast_list[i] // est-ce que le missile ennemie va nous toucher ? && x <= _player.x() + _player.width() && oldx >= _player.x() && _blast_list[i]->y() >= _player.y() && _blast_list[i]->y() < _player.y() + _player.height()) { delete _blast_list[i]; _blast_list[i] = NULL; _player.takeDamage(1); } // FEATURE AMMOS if (_blast_list[i]) { if (_blast_list[i]->x() >= 137 || _blast_list[i]->x() <= 0) { delete _blast_list[i]; _blast_list[i] = NULL; } } if (_blast_list[i]) { // si toujours en vie _renderEntity(*_blast_list[i]); } } } } /* t_ent_lst* tmp = _blast_lst; t_ent_lst* prev = tmp; int x, oldx; bool collision = false; while (tmp) { oldx = tmp->ent->x(); tmp->ent->moveX(tmp->ent->vx()); x = tmp->ent->x(); for (int i = 0; i < 142; i++) { if (x >= _entities_list[i].x() && oldx <= _entities_list[i].x() && tmp->ent->y() == _entities_list[i].y() && !collision) { _entities_list[i].set_x(rand() % 135 + 135); _entities_list[i].set_y(rand() % 31); collision = true; } } if (!collision) { _renderEntity(*tmp->ent); prev = tmp; tmp = tmp->next; } else { if (prev != _blast_lst) { prev->next = tmp->next; //delete tmp->ent; //delete tmp; tmp = prev->next; } else { tmp = tmp->next; delete _blast_lst->ent; delete _blast_lst; _blast_lst = tmp; prev = tmp; } } } */ }