err_t MapManager :: createMap(uint32_t aUID, GameMap::Info** aInfo) { ASSERT_ERR(aInfo != nullptr && *aInfo != nullptr, ERROR_INVALID_POINTER); err_t err = ERROR_SUCCESS; if (mGameMaps.find(aUID) == mGameMaps.end()) { map<uint16_t, MapData*>::const_iterator it; if ((it = mMaps.find((*aInfo)->DocID)) != mMaps.end()) { GameMap* gameMap = new GameMap(aUID, aInfo, *it->second); ASSERT(gameMap != nullptr); mGameMaps[aUID] = gameMap; LOG(INFO, "Created game map %d with data of %u.", gameMap->getUID(), gameMap->getDocID()); } else { LOG(ERROR, "Missing map data for doc ID %u. The map %d won't be created.", (*aInfo)->DocID, aUID); err = ERROR_NOT_FOUND; } } else { LOG(ERROR, "Duplicated map %d.", aUID); err = ERROR_CANNOT_CREATE; } return err; }
void Client::TakeMapShot(){ try{ std::string name = MapShotPath(); { std::unique_ptr<IStream> stream(FileManager::OpenForWriting(name.c_str())); try{ GameMap *map = GetWorld()->GetMap(); if(map == nullptr){ SPRaise("No map loaded"); } map->Save(stream.get()); }catch(...){ throw; } } std::string msg; msg = _Tr("Client", "Map saved: {0}", name); ShowAlert(msg, AlertType::Notice); }catch(const Exception& ex){ std::string msg; msg = _Tr("Client", "Saving map failed: "); msg += ex.GetShortMessage(); ShowAlert(msg, AlertType::Error); SPLog("Saving map failed: %s", ex.what()); }catch(const std::exception& ex){ std::string msg; msg = _Tr("Client", "Saving map failed: "); msg += ex.what(); ShowAlert(msg, AlertType::Error); SPLog("Saving map failed: %s", ex.what()); } }
void Explosion::clearExplosion(GameMap &map, int pow) { int xpos = getPosX(); int zpos = getPosZ(); int i; // right if (map.getCoordType(zpos, xpos) == 7) map.setTypeAtPos(xpos, zpos, 0); for (i = 1; i < pow; ++i) if (map.getCoordType(zpos, xpos + i) == 7) map.setTypeAtPos(xpos + i, zpos, 0); // left for (i = -1; i > -pow; --i) { if (map.getCoordType(zpos, xpos + i) == 7) map.setTypeAtPos(xpos + i, zpos, 0); } // up for (i = 1; i < pow; ++i) { if (map.getCoordType(zpos + i, xpos) == 7) map.setTypeAtPos(xpos, zpos + i, 0); } // down for (i = -1; i > -pow; --i) { if (map.getCoordType(zpos + i, xpos) == 7) map.setTypeAtPos(xpos, zpos + i, 0); } }
void Player :: enterMap() { static const MapManager& mgr = MapManager::getInstance(); GameMap* map = mgr.getMap(mMapId); if (map != nullptr) { // SendLight(); // int nKeepSecs = 0; // keep light Msg* msg = nullptr; msg = new MsgAction(this, map->getLight(), MsgAction::ACTION_MAP_ARGB); send(msg); SAFE_DELETE(msg); map->enterRoom(*this); // pMap->SendRegionInfo(this); map->sendMapInfo(*this); updateBroadcastSet(true); // if (pMap && pMap->IsBoothEnable()) // DetachStatus((IRole*)this, STATUS_XPFULL); // CRole::AttachStatus(this->QueryRole(), STATUS_PK_PROTECT, 0, CHGMAP_LOCK_SECS); } else { // invalid map... mClient.disconnect(); return; } }
void GameStart::over() { //make adventurer WorldManager &wm = WorldManager::getInstance(); Adventurer *a = new Adventurer; wm.addObject(a); //read in curses CurseList::getInstance().readCurses("curse_list.txt"); //make room map GameMap* gm = new GameMap(); int status = gm->generateMap(); if(status < 0) { LogManager::getInstance().WRITELOG("generateMap failed."); } else { gm->getCurrentRoom()->makeActive(); //make messager new Messager; //new message EventMessage em("You enter the vault."); wm.broadcastEvent(&em); } WorldManager::getInstance().markForDelete(this); }
void loadIsland() { float x, z; for(int i = 0; i < game_map.getStageMap().size(); i++) { for(int j = 0; j < game_map.getStageMap().at(i).size(); j++) { A_RGB rgb = game_map.getStageMap().at(i).at(j); if(rgb.isBlack()) { Ground hole = Ground(i,j); hole.getPosition().convert_to_xz(&x, &z); glPushMatrix(); glTranslatef(x,-0.5f,z); glScalef(0.5f,0.5f,0.5f); glmDraw(cube_hole, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE); glPopMatrix(); } else if(rgb.isGreen()) { Ground floor = Ground(i,j); floor.getPosition().convert_to_xz(&x, &z); glPushMatrix(); glTranslatef(x,-0.5f,z); glScalef(0.5f,0.5f,0.5f); glmDraw(cube, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE); glPopMatrix(); } else if(rgb.isRed()) { Ground crack = Ground(i,j); crack.getPosition().convert_to_xz(&x, &z); A_RGB east = game_map.getStageMap().at(i).at(j+1); A_RGB west = game_map.getStageMap().at(i).at(j-1); if(east.isRed() || west.isRed()) { glPushMatrix(); glTranslatef(x,-0.5f,z); glRotatef(90.0f, 0.0f, 1.0f, 0.0f); glScalef(0.5f,0.5f,0.5f); glmDraw(cube_crack, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE); glPopMatrix(); } else { glPushMatrix(); glTranslatef(x,-0.5f,z); glScalef(0.5f,0.5f,0.5f); glmDraw(cube_crack, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE); glPopMatrix(); } } } } }
/* call-seq: new new(tilesets) new(tile, tile2, tile3, tileset, ...) Creates a new map, either from an array containing tilesets' name, or from arguments being either a tileset's name or tiles. */ VALUE GameMap_initialize(int argc, VALUE *argv, VALUE self) { GameMap *ptr = getPtr<GameMap>(self); if (argc >= 1) { if (TYPE(argv[0]) == T_ARRAY) { int size = RARRAY_LEN(argv[0]); for (int i = 0; i < size; ++i) { VALUE val = rb_ary_entry(argv[0], i); ptr->addTileset(StringValuePtr(val)); } } else { for (int i = 0; i < argc; ++i) { argv[i] = rb_obj_as_string(argv[i]); ptr->addTileset(StringValuePtr(argv[i])); } } } return Qnil; }
bool OnGS2C_LookInfoDynamicTransferDoor(GS2C_LookInfoDynamicTransferDoor *value) { // add dynamicTransferDoor to m_doors GameMap* pMap = gGameLayer->getCurrMap(); if (!pMap->getRegionManager()->addDynamicTransferDoorIfNotExist(value->id,value->x,value->y,value->cx,value->cy)) { //gMap->addEffect(1001001,value->x+value->cx/2,value->y+value->cy/2,false); } return true; }
GameMap* GameMap::create( int mainLevel, int viceLevel ) { GameMap* ret = new GameMapRecrusive(); if (ret->initWithLevel(mainLevel, viceLevel)) { ret->autorelease(); return ret; } CC_SAFE_DELETE(ret); return nullptr; }
GameMap* GameMap::createGameMap(char* mapName){ GameMap* gameMap = GameMap::create(); auto map = GameMap::loadMap(mapName); map->setPosition(gameMap->getContentSize() / 2 - map->getContentSize() / 2);//设置居中 gameMap->_map = map; gameMap->registerInspectObjects(); gameMap->addChild(map); return gameMap; }
bool ResMap::load() { GameMap* pMap = gGameLayer->getCurrMap(); CCLOG("ResMap =============load start============"); if ( pMap->loadMap(m_nMapID) ) { CCLOG("ResMap =============load succ============"); return true; } CCLOG("ResMap =============load fail============"); return false; }
BlockMap::BlockMap(GameMap &map) : height( map.getHeight() ), length( map.getLength() ) { blockmap = (Block**) malloc( sizeof( Block* ) * height * length); // copy values in for (uint32_t i = 0; i < length; i++) for (uint32_t j = 0; j < height; j++) addBlockAt(i, j, map.getValue(i, j)); }
Player :: ~Player() { static const MapManager& mgr = MapManager::getInstance(); GameMap* map = mgr.getMap(mMapId); if (map != nullptr) map->leaveRoom(*this); deleteAllItem(); deleteAllWeaponSkill(); deleteAllMagicSkill(); }
GameMap* GameMap::gameMapWithTMXFile(const char *tmxFile) { GameMap *pRet = new GameMap(); if (pRet->initWithTMXFile(tmxFile)) { pRet->extraInit(); pRet->autorelease(); return pRet; } CC_SAFE_DELETE(pRet); return NULL; }
void Player :: leaveMap() { static const MapManager& mgr = MapManager::getInstance(); GameMap* map = mgr.getMap(mMapId); if (map != nullptr) map->leaveRoom(*this); MsgAction msg(this, 0, MsgAction::ACTION_LEAVE_MAP); broadcastRoomMsg(&msg, false); clearBroadcastSet(); }
GameMap* GameMap::gameMapWithTMXFile(const char *tmxFile) { //new一个对象 GameMap *pRet = new GameMap(); //调用init方法 if (pRet->initWithTMXFile(tmxFile)) { //将实例放入autorelease池,统一由引擎控制对象的生命周期 pRet->autorelease(); return pRet; } CC_SAFE_DELETE(pRet); return NULL; }
bool Player :: move(uint16_t aX, uint16_t aY, uint8_t aDir) { static const MapManager& mgr = MapManager::getInstance(); GameMap* map = mgr.getMap(mMapId); if (map != nullptr) { if (!map->isValidPoint(aX, aY) || !map->isStandEnable(aX, aY)) { sendSysMsg(STR_INVALID_COORDINATE); kickBack(); return false; } // the maximum elevation difference (between the character's initial // position and the check tile's position) is 210 if (map->getFloorAlt(aX, aY) - map->getFloorAlt(mPosX, mPosY) > 210) { // TODO ? Jail with wall jump hack ? kickBack(); return false; } // TODO detach status STATUS_HIDDEN // StandRestart() // map->ChangeRegion() mPrevX = mPosX; mPrevY = mPosY; mPosX = aX; mPosY = aY; mDirection = aDir; mPose = POSE_STANDBY; updateBroadcastSet(); // IsInBattle = false, MagicIntone = false, Mining = false // ProcessAfterMove() return true; } return false; }
void graphicsRenderGameOverlayChatWorker( void* Params) { std::string UpdMsg = *((std::string*)Params); GameMap* MainMap = gRGOCW_MainMap; MainMap->LockMemory(); if (UpdMsg.length() > 0) { UpdMsg = "[" + GameConfig.PlayerName + "] " + UpdMsg; if (MainMap->IsHost) chatInsertMessage(UpdMsg); NetmgrPostMessage(UpdMsg); } MainMap->UnlockMemory(); PhEngine::PhEngineState = PhEngine::Running; return ; }
void charTyped(unsigned int c) { switch(c) { case 'l': for (Room& room:gamemap.rooms) room.begin(); break; case 'r': gamemap.rooms[gamemap.curroom].reset(); break; case '+': case '=': gamemap.setRoom(gamemap.curroom+1,true); break; case '-': case '_': gamemap.setRoom(gamemap.curroom-1,true); break; } }
void ResMap::onLoadComplete(ResTask* pTask) { ResBase::onLoadComplete(pTask); GameMap* pMap = gGameLayer->getCurrMap(); // ´´½¨Ä£ºý±³¾° Sprite* pBg = Sprite::create(pMap->getMapBgFileName()); if ( pBg ) { float scaleX = (float)pMap->getMapWidth()/pBg->getContentSize().width; float scaleY = (float)pMap->getMapHeight()/pBg->getContentSize().height; pBg->setScaleX(scaleX); pBg->setScaleY(scaleY); pBg->setAnchorPoint(Point::ZERO); pMap->addChild(pBg,-9999); } else { LOGE("can't find map file[%s]",pMap->getMapBgFileName()); } gGameLayer->addChild(pMap); gHero->EnterMap(pMap,m_nCX,m_nCY); gLoadingUI->SetPercent(100.f, 4.f); LOGD("========ResMap::onLoadComplete========="); gNetDispatcher->Unlock(); }
void DataMap::load_map(ThreeDManager& threeDManager) { GameMap myGameMap; myGameMap.generateMap((unsigned int)this->width - 2, (unsigned int)this->height - 2); for (int y = 0; y < (int)this->height; y++) { char *info = new char[32]; if (y == 0 || y == (int)this->height - 1) { for (int i = 0; i < (int)this->width; i++) info[i] = 'w'; } else { for (int x = 0; x < (int)this->width; x++) { if (x == 0 || x == (int)this->width - 1) info[x] = 'w'; else { if (myGameMap.getCase(x - 1, y - 1) == MAP_CASE_EMPTY) info[x] = ' '; else if (myGameMap.getCase(x - 1, y - 1) == MAP_CASE_WALL) info[x] = 'w'; else if (myGameMap.getCase(x - 1, y - 1) == MAP_CASE_CRATE) info[x] = 'g'; } } } mapinfo[y].assign(info); delete []info; } this->load3DObjects(threeDManager); }
/* call-seq: new new(tilesets) new(tile, tile2, tile3, tileset, ...) Creates a new map, either from an array containing tilesets' name, or from arguments being either a tileset's name or tiles. */ VALUE wrap<GameMap>(int argc, VALUE *argv, VALUE info) { GameMap *ptr = new GameMap; if (argc >= 1) { if (TYPE(argv[0]) == T_ARRAY) { int size = RARRAY_LEN(argv[0]); for (int i = 0; i < size; ++i) { VALUE val = rb_ary_entry(argv[0], i); ptr->addTileset(StringValuePtr(val)); } } else { for (int i = 0; i < argc; ++i) ptr->addTileset(StringValuePtr(argv[i])); } } VALUE tdata = Data_Wrap_Struct(info, 0, wrapped_free<GameMap>, ptr); return tdata; }
void Entity::GetFOV(GameMap &CurrentMap) { vector<Tile>::iterator it; //reset all to invis for(it = CurrentMap.TileMap.begin(); it != CurrentMap.TileMap.end(); it++) { (*it).Visible = false; } Circle.clear(); GetCircle(CurrentMap); vector<int>::iterator nit; for(nit = Circle.begin(); nit != Circle.end(); nit++) { CurrentMap.Bresenham(y, x, CurrentMap.TileMap[(*nit)].y, CurrentMap.TileMap[(*nit)].x); } }
void Monster::GetFOVNPC(GameMap &CurrentMap) { vector<int> ReturnedTiles; vector<Tile>::iterator it; Circle.clear(); VisTiles.clear(); GetCircle(CurrentMap); vector<int>::iterator nit; for(nit = Circle.begin(); nit != Circle.end(); nit++) { ReturnedTiles.clear(); ReturnedTiles = CurrentMap.BresenhamNPC(y, x, CurrentMap.TileMap[(*nit)].y, CurrentMap.TileMap[(*nit)].x); for(int i = 0; i < ReturnedTiles.size(); i++) VisTiles.push_back(ReturnedTiles[i]); } }
GameMap* GameMap::create(int mapWidth, int mapHeight) { GameMap* ret = new GameMap(); if (ret && !ret->init()) { delete ret; return NULL; } ret->setMapWidth(mapWidth); ret->setMapHeight(mapHeight); ret->initMap(); ret->autorelease(); return ret; }
void Entity::GetCircle(GameMap &CurrentMap) { int radius = 5; int xPos = 0; int yPos = 0; for(int i = 0; i < 130; i++) { xPos = x + radius * cos((3/10.f)*i); yPos = y + radius * sin((3/10.f)*i); if(xPos < 12) xPos = 12; if(xPos > 77) xPos = 77; if(yPos < 0) yPos = 0; if(yPos >21) yPos = 21; Circle.push_back(CurrentMap.ScanTileByCoord(yPos, xPos)); } }
void loadEnemies() { float x, z; for(int i = 0; i < game_map.getScythers().size(); i++) { Scyther schyther = game_map.getScythers().at(i); schyther.getPosition().convert_to_xz(&x, &z); glPushMatrix(); glTranslatef(x,0.5f,z); glRotatef(schyther.getYRotation(),0.0f,1.0f,0.0f); glmDraw(scytherModel, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE); glPopMatrix(); } for(int i = 0; i < game_map.getSharpedos().size(); i++) { Sharpedo sharpedo = game_map.getSharpedos().at(i); sharpedo.getPosition().convert_to_xz(&x, &z); glPushMatrix(); glTranslatef(x,-0.5f,z); glRotatef(sharpedo.getYRotation(),0.0f,1.0f,0.0f); glmDraw(sharpedoModel, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE); glPopMatrix(); } for(int i = 0; i < game_map.getSnorlaxs().size(); i++) { Snorlax snorlax = game_map.getSnorlaxs().at(i); snorlax.getPosition().convert_to_xz(&x, &z); glPushMatrix(); glTranslatef(x,0.2f,z); glRotatef(snorlax.getYRotation(),0.0f,1.0f,0.0f); glRotatef(270.0f,1.0f,0.0f,0.0f); glmDraw(snorlaxModel, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE); glPopMatrix(); } }
void MapView::Draw(){ World *world = client->GetWorld(); if(!world) return; Player *player = world->GetLocalPlayer(); if(client->IsFollowing()){ player = world->GetPlayer(client->followingPlayerId); } if(!player) return; if(largeMap) if(zoomState < .0001f) return; GameMap *map = world->GetMap(); Vector2 mapSize = MakeVector2(map->Width(), map->Height()); Vector3 pos = player->GetPosition();; if(player->GetTeamId() >= 2){ pos = client->followPos; } Vector2 center = {pos.x, pos.y}; float cfgMapSize = cg_minimapSize; if(cfgMapSize < 32) cfgMapSize = 32; if(cfgMapSize > 256) cfgMapSize = 256; Vector2 mapWndSize = {cfgMapSize, cfgMapSize}; float scale = actualScale; center = Mix(center, mapSize * .5f, zoomState); Vector2 zoomedSize = {512, 512}; if(renderer->ScreenWidth() < 512.f || renderer->ScreenHeight() < 512.f) zoomedSize = MakeVector2(256, 256); if(largeMap){ float per = zoomState; per = 1.f - per; per *= per; per = 1.f - per; per = Mix(.7f, 1.f, per); zoomedSize = Mix(MakeVector2(0, 0), zoomedSize, per); mapWndSize = zoomedSize; } Vector2 inRange = mapWndSize * .5f * scale; AABB2 inRect(center - inRange, center + inRange); if(largeMap){ inRect.min = MakeVector2(0, 0); inRect.max = mapSize; }else{ if(inRect.GetMinX() < 0.f) inRect = inRect.Translated(-inRect.GetMinX(), 0.f); if(inRect.GetMinY() < 0.f) inRect = inRect.Translated(0, -inRect.GetMinY()); if(inRect.GetMaxX() > mapSize.x) inRect = inRect.Translated(mapSize.x - inRect.GetMaxX(), 0.f); if(inRect.GetMaxY() > mapSize.y) inRect = inRect.Translated(0, mapSize.y - inRect.GetMaxY()); } AABB2 outRect(renderer->ScreenWidth() - mapWndSize.x - 16.f, 16.f, mapWndSize.x, mapWndSize.y); if(largeMap){ outRect.min = MakeVector2((renderer->ScreenWidth() - zoomedSize.x) * .5f, (renderer->ScreenHeight() - zoomedSize.y) * .5f); outRect.max =MakeVector2((renderer->ScreenWidth() + zoomedSize.x) * .5f, (renderer->ScreenHeight() + zoomedSize.y) * .5f); } float alpha = 1.f; if(largeMap){ alpha = zoomState; } // fades bg if(largeMap) { Handle<IImage> bg = renderer->RegisterImage("Gfx/MapBg.png"); Vector2 scrSize = {renderer->ScreenWidth(), renderer->ScreenHeight()}; float size = std::max(scrSize.x, scrSize.y); renderer->SetColorAlphaPremultiplied(MakeVector4(0, 0, 0,alpha * .5f)); renderer->DrawImage(bg, AABB2((scrSize.x - size) * .5f, (scrSize.y - size) * .5f, size, size)); } // draw border Handle<IImage> border; float borderWidth; AABB2 borderRect = outRect; if(largeMap) { border = renderer->RegisterImage("Gfx/MapBorder.png"); borderWidth = 3.f * outRect.GetHeight() / zoomedSize.y; }else{ border = renderer->RegisterImage("Gfx/MinimapBorder.png"); borderWidth = 2.f; } borderRect = borderRect.Inflate(borderWidth - 8.f); renderer->SetColorAlphaPremultiplied(MakeVector4(alpha,alpha,alpha,alpha)); renderer->DrawImage(border, AABB2(borderRect.GetMinX()-16, borderRect.GetMinY()-16, 16, 16), AABB2(0, 0, 16, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMaxX(), borderRect.GetMinY()-16, 16, 16), AABB2(16, 0, 16, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMinX()-16, borderRect.GetMaxY(), 16, 16), AABB2(0, 16, 16, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMaxX(), borderRect.GetMaxY(), 16, 16), AABB2(16, 16, 16, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMinX(), borderRect.GetMinY()-16, borderRect.GetWidth(), 16), AABB2(16, 0, 0, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMinX(), borderRect.GetMaxY(), borderRect.GetWidth(), 16), AABB2(16, 16, 0, 16)); renderer->DrawImage(border, AABB2(borderRect.GetMinX()-16, borderRect.GetMinY(), 16, borderRect.GetHeight()), AABB2(0, 16, 16, 0)); renderer->DrawImage(border, AABB2(borderRect.GetMaxX(), borderRect.GetMinY(), 16, borderRect.GetHeight()), AABB2(16, 16, 16, 0)); // draw map renderer->SetColorAlphaPremultiplied(MakeVector4(alpha,alpha,alpha,alpha)); renderer->DrawFlatGameMap(outRect, inRect); this->inRect = inRect; this->outRect = outRect; // draw grid renderer->SetColorAlphaPremultiplied(MakeVector4(0,0,0,0.8f*alpha)); Handle<IImage> dashLine = renderer->RegisterImage("Gfx/DashLine.tga"); for(float x = 64.f; x < map->Width(); x += 64.f){ float wx = (x - inRect.GetMinX()) / inRect.GetWidth(); if(wx < 0.f || wx >= 1.f) continue; wx = (wx * outRect.GetWidth()) + outRect.GetMinX(); wx = roundf(wx); renderer->DrawImage(dashLine, MakeVector2(wx, outRect.GetMinY()), AABB2(0, 0, 1.f, outRect.GetHeight())); } for(float y = 64.f; y < map->Height(); y += 64.f){ float wy = (y - inRect.GetMinY()) / inRect.GetHeight(); if(wy < 0.f || wy >= 1.f) continue; wy = (wy * outRect.GetHeight()) + outRect.GetMinY(); wy = roundf(wy); renderer->DrawImage(dashLine, MakeVector2(outRect.GetMinX(), wy), AABB2(0, 0, outRect.GetWidth(), 1.f)); } // draw grid label renderer->SetColorAlphaPremultiplied(MakeVector4(1,1,1,1)*(0.8f*alpha)); Handle<IImage> mapFont = renderer->RegisterImage("Gfx/Fonts/MapFont.tga"); for(int i = 0; i < 8; i++){ float startX = (float)i * 64.f; float endX = startX + 64.f; if(startX > inRect.GetMaxX() || endX < inRect.GetMinX()) continue; float fade = std::min((std::min(endX, inRect.GetMaxX()) - std::max(startX, inRect.GetMinX())) / (endX - startX) * 2.f, 1.f); renderer->SetColorAlphaPremultiplied(MakeVector4(1,1,1,1)*(fade * .8f * alpha)); float center = std::max(startX, inRect.GetMinX()); center = .5f * (center + std::min(endX, inRect.GetMaxX())); float wx = (center - inRect.GetMinX()) / inRect.GetWidth(); wx = (wx * outRect.GetWidth()) + outRect.GetMinX(); wx = roundf(wx); float fntX = static_cast<float>((i & 3) * 8); float fntY = static_cast<float>((i >> 2) * 8); renderer->DrawImage(mapFont, MakeVector2(wx - 4.f, outRect.GetMinY() + 4), AABB2(fntX, fntY, 8, 8)); } for(int i = 0; i < 8; i++){ float startY = (float)i * 64.f; float endY = startY + 64.f; if(startY > inRect.GetMaxY() || endY < inRect.GetMinY()) continue; float fade = std::min((std::min(endY, inRect.GetMaxY()) - std::max(startY, inRect.GetMinY())) / (endY - startY) * 2.f, 1.f); renderer->SetColorAlphaPremultiplied(MakeVector4(1,1,1,1)*(fade * .8f * alpha)); float center = std::max(startY, inRect.GetMinY()); center = .5f * (center + std::min(endY, inRect.GetMaxY())); float wy = (center - inRect.GetMinY()) / inRect.GetHeight(); wy = (wy * outRect.GetHeight()) + outRect.GetMinY(); wy = roundf(wy); int fntX = (i & 3) * 8; int fntY = (i >> 2) * 8 + 16; renderer->DrawImage(mapFont, MakeVector2(outRect.GetMinX() + 4, wy - 4.f), AABB2(fntX, fntY, 8, 8)); } //draw objects std::string iconmode = cg_Minimap_Player_Icon;//import variable from configuration file std::string colormode = cg_Minimap_Player_Color;//import variable from configuration file Handle<IImage> playerSMG = renderer->RegisterImage("Gfx/Map/SMG.png"); Handle<IImage> playerRifle = renderer->RegisterImage("Gfx/Map/Rifle.png"); Handle<IImage> playerShotgun = renderer->RegisterImage("Gfx/Map/Shotgun.png"); Handle<IImage> playerIcon = renderer->RegisterImage("Gfx/Map/Player.png"); { IntVector3 teamColor = world->GetLocalPlayer()->GetTeamId() >= 2 ? IntVector3::Make(200, 200, 200) : world->GetTeam(world->GetLocalPlayer()->GetTeamId()).color; Vector4 teamColorF = ModifyColor(teamColor); teamColorF *= alpha; // draw local player's view { Player *p = player; Handle<IImage> viewIcon = renderer->RegisterImage("Gfx/Map/View.png"); if(p->IsAlive()) { Vector3 front = p->GetFront2D(); float ang = atan2(front.x, -front.y); if(player->GetTeamId() >= 2){ ang = client->followYaw - static_cast<float>(M_PI) * .5f; } renderer->SetColorAlphaPremultiplied(teamColorF * 0.9f); DrawIcon(player->GetTeamId() >= 2 ? client->followPos : p->GetPosition(), viewIcon, ang); } } // draw player's icon for(int i = 0; i < world->GetNumPlayerSlots(); i++){ Player * p = world->GetPlayer(i); if(p == nullptr || p->GetTeamId() != world->GetLocalPlayer()->GetTeamId() || !p->IsAlive()) continue; Vector3 front = p->GetFront2D(); float ang = atan2(front.x, -front.y); if(player->GetTeamId() >= 2){ ang = client->followYaw - static_cast<float>(M_PI) * .5f; } //use a spec color for each player if ( colormode=="1"){ IntVector3 Colorplayer=IntVector3::Make(palette[i][0],palette[i][1],palette[i][2]); Vector4 ColorplayerF = ModifyColor(Colorplayer); ColorplayerF *=1.0f; renderer->SetColorAlphaPremultiplied(ColorplayerF); } else { renderer->SetColorAlphaPremultiplied(teamColorF); } //use a different icon in minimap according to weapon of player if( iconmode=="1"){ WeaponType weapon=world->GetPlayer(i)->GetWeaponType(); if (weapon == WeaponType::SMG_WEAPON){ DrawIcon(player->GetTeamId() >= 2 ? client->followPos : p->GetPosition(),playerSMG , ang); } else if (weapon == WeaponType::RIFLE_WEAPON){ DrawIcon(player->GetTeamId() >= 2 ? client->followPos : p->GetPosition(), playerRifle, ang); } else if (weapon == WeaponType::SHOTGUN_WEAPON){ DrawIcon(player->GetTeamId() >= 2 ? client->followPos : p->GetPosition(), playerShotgun, ang); } } else{//draw normal color DrawIcon(player->GetTeamId() >= 2 ? client->followPos : p->GetPosition(), playerIcon, ang); } } } IGameMode* mode = world->GetMode(); if( mode && IGameMode::m_CTF == mode->ModeType() ) { CTFGameMode *ctf = static_cast<CTFGameMode *>(mode); Handle<IImage> intelIcon = renderer->RegisterImage("Gfx/Map/Intel.png"); Handle<IImage> baseIcon = renderer->RegisterImage("Gfx/Map/CommandPost.png"); for(int tId = 0; tId < 2; tId++){ CTFGameMode::Team& team = ctf->GetTeam(tId); IntVector3 teamColor = world->GetTeam(tId).color; Vector4 teamColorF = ModifyColor(teamColor); teamColorF *= alpha; // draw base renderer->SetColorAlphaPremultiplied(teamColorF); DrawIcon(team.basePos, baseIcon, 0.f); // draw flag if(!ctf->GetTeam(1-tId).hasIntel){ renderer->SetColorAlphaPremultiplied(teamColorF); DrawIcon(team.flagPos, intelIcon, 0.f); }else if(world->GetLocalPlayer()->GetTeamId() == 1-tId){ // local player's team is carrying int cId = ctf->GetTeam(1-tId).carrier; // in some game modes, carrier becomes invalid if(cId < world->GetNumPlayerSlots()){ Player * carrier= world->GetPlayer(cId); if(carrier && carrier->GetTeamId() == world->GetLocalPlayer()->GetTeamId()){ Vector4 col = teamColorF; col *= fabsf(sinf(world->GetTime() * 4.f)); renderer->SetColorAlphaPremultiplied(col); DrawIcon(carrier->GetPosition(), intelIcon, 0.f); } } } } } else if( mode && IGameMode::m_TC == mode->ModeType() ) { TCGameMode *tc = static_cast<TCGameMode *>(mode); Handle<IImage> icon = renderer->RegisterImage("Gfx/Map/CommandPost.png"); int cnt = tc->GetNumTerritories(); for(int i = 0; i < cnt; i++){ TCGameMode::Territory *t = tc->GetTerritory(i); IntVector3 teamColor = {128,128,128}; if(t->ownerTeamId < 2){ teamColor = world->GetTeam(t->ownerTeamId).color; } Vector4 teamColorF = ModifyColor(teamColor); teamColorF *= alpha; // draw base renderer->SetColorAlphaPremultiplied(teamColorF); DrawIcon(t->pos, icon, 0.f); } } }
void Player::FireWeapon() { SPADES_MARK_FUNCTION(); Vector3 muzzle = GetEye(); muzzle += GetFront() * 0.01f; // for hit-test debugging std::map<int, HitTestDebugger::PlayerHit> playerHits; std::vector<Vector3> bulletVectors; //Vector3 right = GetRight(); //Vector3 up = GetUp(); int pellets = weapon->GetPelletSize(); float spread = weapon->GetSpread(); GameMap *map = world->GetMap(); // pyspades takes destroying more than one block as a // speed hack (shotgun does this) bool blockDestroyed = false; Vector3 dir2 = GetFront(); for(int i =0 ; i < pellets; i++){ // AoS 0.75's way (dir2 shouldn't be normalized!) dir2.x += (GetRandom() - GetRandom()) * spread; dir2.y += (GetRandom() - GetRandom()) * spread; dir2.z += (GetRandom() - GetRandom()) * spread; Vector3 dir = dir2.Normalize(); bulletVectors.push_back(dir); // first do map raycast GameMap::RayCastResult mapResult; mapResult = map->CastRay2(muzzle, dir, 500); Player *hitPlayer = NULL; float hitPlayerDistance = 0.f; HitBodyPart hitPart = HitBodyPart::None; for(int i = 0; i < world->GetNumPlayerSlots(); i++){ Player *other = world->GetPlayer(i); if(other == this || other == NULL) continue; if(other == this || !other->IsAlive() || other->GetTeamId() >= 2) continue; // quickly reject players unlikely to be hit if(!other->RayCastApprox(muzzle, dir)) continue; HitBoxes hb = other->GetHitBoxes(); Vector3 hitPos; if(hb.head.RayCast(muzzle, dir, &hitPos)) { float dist = (hitPos - muzzle).GetLength(); if(hitPlayer == NULL || dist < hitPlayerDistance){ hitPlayer = other; hitPlayerDistance = dist; hitPart = HitBodyPart::Head; } } if(hb.torso.RayCast(muzzle, dir, &hitPos)) { float dist = (hitPos - muzzle).GetLength(); if(hitPlayer == NULL || dist < hitPlayerDistance){ hitPlayer = other; hitPlayerDistance = dist; hitPart = HitBodyPart::Torso; } } for(int j = 0; j < 3 ;j++){ if(hb.limbs[j].RayCast(muzzle, dir, &hitPos)) { float dist = (hitPos - muzzle).GetLength(); if(hitPlayer == NULL || dist < hitPlayerDistance){ hitPlayer = other; hitPlayerDistance = dist; switch(j) { case 0: hitPart = HitBodyPart::Limb1; break; case 1: hitPart = HitBodyPart::Limb2; break; case 2: hitPart = HitBodyPart::Arms; break; } } } } } Vector3 finalHitPos; finalHitPos = muzzle + dir * 128.f; if(hitPlayer == nullptr && !mapResult.hit) { // might hit water surface. } if(mapResult.hit && (mapResult.hitPos - muzzle).GetLength() < 128.f && (hitPlayer == NULL || (mapResult.hitPos - muzzle).GetLength() < hitPlayerDistance)){ IntVector3 outBlockCoord = mapResult.hitBlock; // TODO: set correct ray distance // FIXME: why ray casting twice? finalHitPos = mapResult.hitPos; if(outBlockCoord.x >= 0 && outBlockCoord.y >= 0 && outBlockCoord.z >= 0 && outBlockCoord.x < map->Width() && outBlockCoord.y < map->Height() && outBlockCoord.z < map->Depth()){ if(outBlockCoord.z == 63) { if(world->GetListener()) world->GetListener()->BulletHitBlock(mapResult.hitPos, mapResult.hitBlock, mapResult.normal); }else if(outBlockCoord.z == 62) { // blocks at this level cannot be damaged if(world->GetListener()) world->GetListener()->BulletHitBlock(mapResult.hitPos, mapResult.hitBlock, mapResult.normal); }else{ int x = outBlockCoord.x; int y = outBlockCoord.y; int z = outBlockCoord.z; SPAssert(map->IsSolid(x, y, z)); Vector3 blockF = {x + .5f, y + .5f, z + .5f}; float distance = (blockF - muzzle).GetLength(); uint32_t color = map->GetColor(x, y, z); int health = color >> 24; health -= weapon->GetDamage(HitTypeBlock, distance); if(health <= 0 && !blockDestroyed){ health = 0; blockDestroyed = true; //send destroy cmd if(world->GetListener() && world->GetLocalPlayer() == this) world->GetListener()->LocalPlayerBlockAction (outBlockCoord, BlockActionTool); } color = (color & 0xffffff) | ((uint32_t)health << 24); if(map->IsSolid(x, y, z)) map->Set(x, y, z, true, color); if(world->GetListener()) world->GetListener()->BulletHitBlock(mapResult.hitPos, mapResult.hitBlock, mapResult.normal); } } }else if(hitPlayer != NULL){
bool Entity::Move(string direction, GameMap &CurrentMap) { if(direction == "up") { switch(CurrentMap.CheckCollision(CurrentMap.ScanTileByCoord(y - 1, x))) { case true://Collision returned true return false;//Deny any move break; case false: //remove NPC flag from previous tile and update flag for current tile int Temp_new = CurrentMap.LastTileScanned; int Temp_old = CurrentMap.ScanTileByCoord(y, x); CurrentMap.TileMap[Temp_old].HasNPC = false; CurrentMap.TileMap[Temp_new].HasNPC = true; y--; PrevTile = CurrentTile; CurrentTile = CurrentMap.LastTileScanned; HasMoved = true; return true; break; } } else if(direction == "down") { switch(CurrentMap.CheckCollision(CurrentMap.ScanTileByCoord(y + 1, x))) { case true: return false; break; case false: //remove NPC flag from previous tile and update flag for current tile int Temp_new = CurrentMap.LastTileScanned; int Temp_old = CurrentMap.ScanTileByCoord(y, x); CurrentMap.TileMap[Temp_old].HasNPC = false; CurrentMap.TileMap[Temp_new].HasNPC = true; y++; PrevTile = CurrentTile; CurrentTile = CurrentMap.LastTileScanned; HasMoved = true; return true; break; } } else if(direction == "left") { switch(CurrentMap.CheckCollision(CurrentMap.ScanTileByCoord(y, x - 1))) { case true: return false; break; case false: //remove NPC flag from previous tile and update flag for current tile int Temp_new = CurrentMap.LastTileScanned; int Temp_old = CurrentMap.ScanTileByCoord(y, x); CurrentMap.TileMap[Temp_old].HasNPC = false; CurrentMap.TileMap[Temp_new].HasNPC = true; x--; PrevTile = CurrentTile; CurrentTile = CurrentMap.LastTileScanned; HasMoved = true; return true; break; } } else if(direction == "right") { switch(CurrentMap.CheckCollision(CurrentMap.ScanTileByCoord(y, x + 1))) { case true: return false; break; case false: //remove NPC flag from previous tile and update flag for current tile int Temp_new = CurrentMap.LastTileScanned; int Temp_old = CurrentMap.ScanTileByCoord(y, x); CurrentMap.TileMap[Temp_old].HasNPC = false; CurrentMap.TileMap[Temp_new].HasNPC = true; x++; PrevTile = CurrentTile; CurrentTile = CurrentMap.LastTileScanned; HasMoved = true; return true; break; } } }