本文整理汇总了C++中Stage::getHeight方法的典型用法代码示例。如果您正苦于以下问题:C++ Stage::getHeight方法的具体用法?C++ Stage::getHeight怎么用?C++ Stage::getHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stage
的用法示例。
在下文中一共展示了Stage::getHeight方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runNewMatch
void GuiManager::runNewMatch(const char *stageName, char **teamNames,
int numUserTeams) {
tpsFactor_ = 0.5;
nextDrawTime_ = 1;
showedResults_ = false;
sf::RenderWindow *window;
bool maintainWindowScale = false;
double prevScale = 1.0;
double backingScale = getBackingScaleFactor();
int screenWidth =
backingScale * sf::VideoMode::getDesktopMode().width;
int screenHeight =
backingScale * sf::VideoMode::getDesktopMode().height;
int dockSize = backingScale * DOCK_SIZE;
if (window_ != 0) {
if (restarting_) {
prevScale = ((double) (window_->getSize().x - dockSize)) / viewWidth_;
maintainWindowScale = true;
}
}
// On Mac OS X, we need to init SFML before the wxWidgets stuff below or we
// hit some unexplainable crashes when we delete an SFML window. I don't know
// why, I've merely devised a work-around. Judging from some SFML forum
// threads, it sounds likely to be an issue with nightmare-ish video drivers.
if (window_ == 0) {
window = initMainWindow(backingScale * screenWidth,
backingScale * (screenHeight - 75));
} else {
window = window_;
}
if (!restarting_) {
saveCurrentMatchSettings(stageName, teamNames, numUserTeams);
}
if (engine_ != 0) {
delete engine_;
engine_ = 0;
}
if (restarting_) {
stageConsole_->clear();
guiPrintHandler_->restartMode();
} else {
destroyStageConsole();
stageConsole_ = new OutputConsole(stageName, CONSOLE_SHIP_STAGE,
menuBarMaker_);
stageConsole_->Hide();
if (guiPrintHandler_ != 0) {
delete guiPrintHandler_;
guiPrintHandler_ = 0;
}
guiPrintHandler_ = new GuiPrintHandler(stageConsole_, 0, menuBarMaker_);
}
engine_ = new BerryBotsEngine(guiPrintHandler_, fileManager_,
resourcePath().c_str());
Stage *stage = engine_->getStage();
if (restarting_) {
stage->setGfxEnabled(stageConsole_->isChecked());
}
stageConsole_->setListener(new StageConsoleListener(stage));
try {
engine_->initStage(getStagesDir().c_str(), stageName,
getCacheDir().c_str());
engine_->initShips(getShipsDir().c_str(), teamNames, numUserTeams,
getCacheDir().c_str());
teamConsoles_ = guiPrintHandler_->getTeamConsoles();
} catch (EngineException *e) {
errorConsole_->print(stageName);
errorConsole_->print(": ");
errorConsole_->println(e->what());
wxMessageDialog errorMessage(NULL, e->what(),
"BerryBots engine init failed", wxOK | wxICON_EXCLAMATION);
errorMessage.ShowModal();
delete engine_;
engine_ = 0;
restarting_ = false;
newMatchDialog_->Show();
delete e;
return;
}
viewWidth_ = stage->getWidth() + (STAGE_MARGIN * 2);
viewHeight_ = stage->getHeight() + (STAGE_MARGIN * 2);
double windowScale;
if (restarting_ && maintainWindowScale) {
windowScale = prevScale;
} else {
windowScale =
std::min(backingScale, std::min(
((double) screenWidth - dockSize) / viewWidth_,
((double) screenHeight) / viewHeight_));
}
unsigned int targetWidth = round(windowScale * viewWidth_) + dockSize;
unsigned int targetHeight = round(windowScale * viewHeight_);
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
delete stageName;
int firstTeam = (2 + optArgsOffset);
int numTeams = argc - firstTeam;
char **teams = new char*[numTeams];
for (int x = 0; x < numTeams; x++) {
char *teamAbsName = fileManager->getAbsFilePath(argv[x + firstTeam]);
char *teamName =
fileManager->parseRelativeFilePath(shipsBaseDir, teamAbsName);
if (teamName == 0) {
std::cout << "Ship must be located under " << SHIPS_SUBDIR
<< "/ subdirectory: " << argv[x + firstTeam] << std::endl;
return 0;
}
teams[x] = teamName;
delete teamAbsName;
}
printHandler->setNumTeams(numTeams);
try {
engine->initShips(shipsBaseDir, teams, numTeams, CACHE_SUBDIR);
} catch (EngineException *e) {
std::cout << "BerryBots initialization failed:" << std::endl;
std::cout << " " << e->what() << std::endl;
delete e;
return 0;
}
printHandler->updateTeams(engine->getTeams());
GfxManager *gfxManager;
sf::RenderWindow *window = 0;
GfxEventHandler *gfxHandler = 0;
unsigned int viewWidth = stage->getWidth() + (STAGE_MARGIN * 2);
unsigned int viewHeight = stage->getHeight() + (STAGE_MARGIN * 2);
if (!nodisplay) {
gfxHandler = new GfxEventHandler();
stage->addEventHandler((EventHandler*) gfxHandler);
unsigned int screenWidth = sf::VideoMode::getDesktopMode().width;
unsigned int screenHeight = sf::VideoMode::getDesktopMode().height;
double windowScale = std::min(1.0,
std::min(((double) screenWidth) / viewWidth,
((double) screenHeight) / viewHeight));
unsigned int targetWidth = round(windowScale * viewWidth);
unsigned int targetHeight = round(windowScale * viewHeight);
gfxManager = new GfxManager(false);
window = new sf::RenderWindow(sf::VideoMode(targetWidth, targetHeight),
"BerryBots", sf::Style::Default, sf::ContextSettings(0, 0, 16, 2, 0));
gfxManager->initViews(window, viewWidth, viewHeight);
gfxManager->initBbGfx(window, viewHeight, stage, engine->getTeams(),
engine->getNumTeams(), engine->getShips(), engine->getNumShips(),
resourcePath());
window->clear();
gfxManager->drawGame(window, stage, engine->getShips(),
engine->getNumShips(), engine->getGameTime(), gfxHandler, false, false,
0);
window->display();
}
time_t realTime1;
time_t realTime2;
time(&realTime1);
int realSeconds = 0;
try {
示例3: savePreviewImage
char* StagePreview::savePreviewImage(sf::RenderWindow *window,
BerryBotsEngine *engine, unsigned int &targetWidth,
unsigned int &targetHeight) {
Stage *stage = engine->getStage();
double backingScale = getBackingScaleFactor();
unsigned int viewWidth = stage->getWidth() + (2 * STAGE_MARGIN);
unsigned int viewHeight = stage->getHeight() + (2 * STAGE_MARGIN);
unsigned int screenWidth = backingScale * MAX_PREVIEW_WIDTH;
unsigned int screenHeight = backingScale * MAX_PREVIEW_HEIGHT;
double windowScale =
std::min(backingScale, std::min(((double) screenWidth) / viewWidth,
((double) screenHeight) / viewHeight));
targetWidth = round(windowScale * viewWidth);
targetHeight = round(windowScale * viewHeight);
#ifdef __WXGTK__
// Since setSize() doesn't work reliably, we create it inline on Linux.
window = new sf::RenderWindow(
sf::VideoMode(targetWidth, targetHeight), "Preview",
sf::Style::None,
sf::ContextSettings(0, 0, (isAaDisabled() ? 0 : 4), 2, 0));
window->setVisible(false);
#else
window->setSize(sf::Vector2u(targetWidth, targetHeight));
#endif
Team **teams = new Team*[1];
teams[0] = new Team;
strcpy(teams[0]->name, "PreviewTeam");
teams[0]->numRectangles = 0;
teams[0]->numLines = 0;
teams[0]->numCircles = 0;
teams[0]->numTexts = 0;
Ship **ships = new Ship*[1];
Ship *ship = new Ship;
ShipProperties *properties = new ShipProperties;
properties->shipR = properties->shipG = properties->shipB = 255;
properties->laserR = properties->laserB = 0;
properties->laserG = 255;
properties->thrusterR = 255;
properties->thrusterG = properties->thrusterB = 0;
strcpy(properties->name, "PreviewShip");
ship->properties = properties;
ship->thrusterAngle = ship->thrusterForce = 0;
Point2D *start = stage->getStart();
ship->x = start->getX();
ship->y = start->getY();
ship->alive = true;
ship->showName = ship->energyEnabled = false;
ships[0] = ship;
teams[0]->numTexts = 0;
stage->setTeamsAndShips(teams, 1, ships, 1);
previewGfxManager_->initBbGfx(window, backingScale, viewHeight, stage, teams,
1, ships, 1);
previewGfxManager_->initViews(window, viewWidth, viewHeight);
GfxEventHandler *gfxHandler = new GfxEventHandler();
window->clear();
previewGfxManager_->drawGame(window, stage, ships, 1, 0, gfxHandler, false,
false, 0);
std::stringstream filenameStream;
filenameStream << (rand() % 10000000) << ".png";
char *filename = fileManager_->getFilePath(getTmpDir().c_str(),
filenameStream.str().c_str());
char *absFilename = fileManager_->getAbsFilePath(filename);
delete filename;
sf::Image previewImage = window->capture();
fileManager_->createDirectoryIfNecessary(getTmpDir().c_str());
previewImage.saveToFile(absFilename);
#ifdef __WXGTK__
delete window;
#endif
previewGfxManager_->destroyBbGfx();
delete gfxHandler;
delete properties;
delete teams[0];
delete teams;
return absFilename;
}
示例4: create
GameGUI* GameGUIBuilder::create() {
FILE_LOG(logDEBUG) << "CONFIGURATION INITIALIZED";
GameGUI *gameGUI = GameGUI::getInstance();
Json::Value root;
Json::Reader reader;
ifstream gameConfig(this->configFilePath.c_str(), std::ifstream::binary);
if (!gameConfig.good()) {
MessageError fileNotFound(ERROR_FILE_NOT_FOUND, FILE_CONFIG_NOT_FOUND, LOG_LEVEL_ERROR);
Log<Output2FILE>::logMsgError(fileNotFound);
return createDefault();
}
bool parsingSuccessful = reader.parse(gameConfig, root, false);
if (!parsingSuccessful) {
MessageError parseException(ERROR_PARSER_JSON, reader.getFormattedErrorMessages(), LOG_LEVEL_ERROR);
Log<Output2FILE>::logMsgError(parseException);
return createDefault();
}
try {
const Json::Value value1 = root.get(JSON_KEY_PERSONAJES, 0);
const Json::Value value2 = root.get(JSON_KEY_CAPAS,0);
Json::Value value3 = root[JSON_KEY_ESCENARIO];
Json::Value value14 = root[JSON_KEY_VENTANA];
Json::Value value5 = root[JSON_KEY_PELEA];
Json::Value value6 = root[JSON_KEY_JOYSTICKS];
Json::Value value7 = root[JSON_KEY_SECUENCES];
} catch(std::exception const & e) {
FILE_LOG(logDEBUG) << "Corrupt JSON File. Exception: "<<e.what();
return createDefault(); //TODO: Validate create default
}
Window* window = jsonGetWindow(root);
Stage* stage = jsonGetStage(root,window->width);
gameGUI->setWindow(window);
gameGUI->setStage(stage);
float ratioX = getRatio(window->widthPx, window->width,"X");
float ratioY = getRatio(window->heightPx, stage->getHeight(),"Y");
TextureManager::Instance()->ratioHeight = ratioY;
TextureManager::Instance()->ratioWidth = ratioX;
vector<Layer*> layers = jsonGetLayers(root, ratioX, ratioY, window, stage);
if (layers.size()==0) {
layers = buildLayersByDefault(ratioX, ratioY,window,stage);
}
vector<Character*> characters = jsonGetCharacters(root, ratioX, ratioY, stage);
gameGUI->setCharacters(characters);
//The fight is now being triggered by the MENU
/*Fight* fight = jsonGetFight(root);
gameGUI->setFight(fight);
if (fight->getFighterOne()->getName() == fight->getFighterTwo()->getName()) {
fight->getFighterTwo()->setIsAlternativePlayer(true);
}
fight->getFighterOne()->setIsRightOriented(true);
MKGame::Instance()->getObjectList().push_back(fight->getFighterOne());
MKGame::Instance()->getObjectList().push_back(fight->getFighterTwo());*/
gameGUI->setLayers(layers);
//The fight is now being triggered by the MENU
//vector<Character*> fightingCharacters;
//fightingCharacters.push_back(fight->getFighterOne());
//fightingCharacters.push_back(fight->getFighterTwo());
/*gameGUI->setCharacters(fightingCharacters);
createGameInfo(window, fightingCharacters, ratioX, ratioY);
createThrowableObject(fightingCharacters, window, ratioX, ratioY);*/
jsonGetJoysticks(root);
jsonGetSecuences(root);
vector<VisualEffect*> visualEffects = createVisualEffects(ratioX, ratioY, window, stage);
gameGUI->setVisualEffects(visualEffects);
FILE_LOG(logDEBUG) << "CONFIGURATION FINISHED";
return gameGUI;
}
示例5: showPreview
void StagePreview::showPreview(sf::RenderWindow *window, const char *stageName,
int x, int y) {
if (stageName_ != 0) {
delete stageName_;
}
stageName_ = new char[strlen(stageName) + 1];
strcpy(stageName_, stageName);
SetPosition(wxPoint(x, y));
infoSizer_->Clear(true);
descSizer_->Clear(true);
BerryBotsEngine *engine = new BerryBotsEngine(0, fileManager_, 0);
Stage *stage = engine->getStage();
try {
engine->initStage(getStagesDir().c_str(), stageName, getCacheDir().c_str());
} catch (EngineException *e) {
wxMessageDialog errorMessage(NULL, e->what(), "Preview failure",
wxOK | wxICON_EXCLAMATION);
errorMessage.ShowModal();
delete engine;
delete e;
return;
}
SetTitle(wxString::Format(wxT("%s"), stage->getName()));
unsigned int targetWidth;
unsigned int targetHeight;
char *previewFilename =
savePreviewImage(window, engine, targetWidth, targetHeight);
wxImage previewImage(previewFilename);
delete previewFilename;
double backingScale = getBackingScaleFactor();
if (backingScale > 1) {
targetWidth /= backingScale;
targetHeight /= backingScale;
}
visualPreview_->SetMinSize(wxSize(targetWidth, targetHeight));
visualPreview_->SetMaxSize(wxSize(targetWidth, targetHeight));
#ifdef __WXOSX__
int padding = 4;
#else
int padding = 8;
#endif
wxSizer *infoGrid = new wxFlexGridSizer(2, 0, padding);
addInfo(infoGrid, "Name:", stage->getName());
addInfo(infoGrid, "Size:",
wxString::Format(wxT("%i x %i"), stage->getWidth(), stage->getHeight()));
if (engine->getTeamSize() > 1) {
addInfo(infoGrid, "Team size:", engine->getTeamSize());
}
addInfo(infoGrid, "Walls:", (stage->getWallCount() - 4));
addInfo(infoGrid, "Zones:", stage->getZoneCount());
addInfo(infoGrid, "Starts:", stage->getStartCount());
int numStageShips = stage->getStageShipCount();
if (numStageShips > 0) {
char **stageShips = stage->getStageShips();
for (int x = 0; x < numStageShips; x++) {
const char *shipName = stageShips[x];
if (shipName != 0) {
int count = 1;
for (int y = x + 1; y < numStageShips; y++) {
const char *shipName2 = stageShips[y];
if (shipName2 != 0 && strcmp(shipName, shipName2) == 0) {
count++;
stageShips[y] = 0;
}
}
wxString wxShipName = (count == 1) ? wxString(stageShips[x])
: wxString::Format(wxT("%s x%i"), shipName, count);
addInfo(infoGrid, (x == 0 ? "Ships:" : ""), wxShipName);
}
}
}
infoSizer_->Add(infoGrid);
char *description = fileManager_->getStageDescription(
getStagesDir().c_str(), stageName, getCacheDir().c_str());
if (description == 0) {
std::string descstr("<No description>");
description = new char[descstr.length() + 1];
strcpy(description, descstr.c_str());
}
wxStaticText *descCtrl = new wxStaticText(mainPanel_, wxID_ANY, description);
descSizer_->Add(descCtrl);
delete description;
mainPanel_->GetSizer()->SetSizeHints(mainPanel_);
mainPanel_->Layout();
Fit();
mainPanel_->SetFocus();
wxBitmap bitmap;
#ifdef __WINDOWS__
bitmap = wxBitmap(previewImage);
#else
bitmap.CreateScaled(targetWidth, targetHeight, wxBITMAP_SCREEN_DEPTH,
//.........这里部分代码省略.........