⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 party.cpp

📁 S.C.O.U.R.G.E.是一款类似Rogue的游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  pc[0]->addInventory(scourge->newItem(RpgItem::getItemByName("Potion of IQ")));  pc[0]->addInventory(scourge->newItem(RpgItem::getItemByName("Potion of Leadership")));  pc[0]->addInventory(scourge->newItem(RpgItem::getItemByName("Potion of Luck")));  pc[0]->addInventory(scourge->newItem(RpgItem::getItemByName("Potion of Piety")));  pc[0]->addInventory(scourge->newItem(RpgItem::getItemByName("Potion of Lore")));  pc[0]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor magic potion")));    pc[0]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor magic potion")));    pc[1]->addInventory(scourge->newItem(RpgItem::getItemByName("Smallbow")));  pc[1]->addInventory(scourge->newItem(RpgItem::getItemByName("Apple")));  pc[1]->addInventory(scourge->newItem(RpgItem::getItemByName("Bread")));  pc[1]->addInventory(scourge->newItem(RpgItem::getItemByName("Mushroom")));  pc[1]->addInventory(scourge->newItem(RpgItem::getItemByName("Big egg")));  pc[1]->addInventory(scourge->newItem(RpgItem::getItemByName("Mutton meat")));  pc[1]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor health potion")));    pc[1]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor magic potion")));    pc[1]->addInventory(scourge->newItem(RpgItem::getItemByName("Liquid armor")));    pc[2]->addInventory(scourge->newItem(RpgItem::getItemByName("Dagger")));  pc[2]->addInventory(scourge->newItem(RpgItem::getItemByName("Smallbow")));  pc[2]->addInventory(scourge->newItem(RpgItem::getItemByName("Long sword")));  pc[2]->addInventory(scourge->newItem(RpgItem::getItemByName("Wine barrel")));  pc[2]->addInventory(scourge->newItem(RpgItem::getItemByName("Mutton meat")));  pc[2]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor health potion")));    pc[2]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor health potion")));    pc[2]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor magic potion")));    pc[2]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor magic potion")));    pc[2]->addInventory(scourge->newItem(RpgItem::getItemByName("Liquid armor")));     // add some scrolls  for(int i = 0; i < 10; i++) {    Spell *spell = MagicSchool::getRandomSpell(1);    if(spell) {      Item *scroll = scourge->newItem(RpgItem::getItemByName("Scroll"));      scroll->setSpell(spell);      pc[2]->addInventory(scroll);      }  }  pc[2]->setMp(50);  pc[3]->addInventory(scourge->newItem(RpgItem::getItemByName("Dagger")));  pc[3]->addInventory(scourge->newItem(RpgItem::getItemByName("Great sword")));  pc[3]->addInventory(scourge->newItem(RpgItem::getItemByName("Battleaxe")));  pc[3]->addInventory(scourge->newItem(RpgItem::getItemByName("Throwing axe")));    pc[3]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor health potion")));    pc[3]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor health potion")));    pc[3]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor health potion")));    pc[3]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor magic potion")));    pc[3]->addInventory(scourge->newItem(RpgItem::getItemByName("Minor magic potion")));    pc[3]->addInventory(scourge->newItem(RpgItem::getItemByName("Liquid armor")));      // equip weapons  pc[0]->equipInventory(0);  pc[0]->equipInventory(1);  pc[1]->equipInventory(0);  pc[2]->equipInventory(0);  pc[2]->equipInventory(1);  pc[3]->equipInventory(0);  // add some spells  pc[2]->addSpell(Spell::getSpellByName("Flame of Azun"));  pc[2]->addSpell(Spell::getSpellByName("Ole Taffy's purty colors"));  pc[2]->addSpell(Spell::getSpellByName("Silent knives"));  pc[2]->addSpell(Spell::getSpellByName("Stinging light"));  pc[2]->addSpell(Spell::getSpellByName("Burning stare"));  pc[3]->addSpell(Spell::getSpellByName("Lesser healing touch"));  pc[3]->addSpell(Spell::getSpellByName("Body of stone"));				    return pc;}void Party::createUI() {  sprintf(version, "S.C.O.U.R.G.E. version %7.2f", SCOURGE_VERSION);  sprintf(min_version, "S.C.O.U.R.G.E.");  mainWin = new Window( scourge->getSDLHandler(),						scourge->getSDLHandler()->getScreen()->w - GUI_WIDTH, 						scourge->getSDLHandler()->getScreen()->h - GUI_HEIGHT, 						GUI_WIDTH, GUI_HEIGHT, 						version, 						scourge->getShapePalette()->getGuiTexture(), false );  cards = new CardContainer(mainWin);    inventoryButton = cards->createButton( 0, 0, 120, 25, strdup("Party Info"), MAX_SIZE );  optionsButton = cards->createButton( 0, 25,  60, 50, strdup("Options"), MAX_SIZE );  quitButton = cards->createButton( 60, 25,  120, 50, strdup("Quit"), MAX_SIZE );  roundButton = cards->createButton( 0, 50,  120, 75, strdup("Real-Time"), MAX_SIZE );  roundButton->setToggle(true);  roundButton->setSelected(true);    int lowerRowHeight = 20;  diamondButton = cards->createButton( 0, 75,  20, 75 + lowerRowHeight, strdup("f1"), MAX_SIZE );  diamondButton->setToggle(true);  staggeredButton = cards->createButton( 20, 75,  40, 75 + lowerRowHeight, strdup("f2"), MAX_SIZE );  staggeredButton->setToggle(true);  squareButton = cards->createButton( 40, 75,  60, 75 + lowerRowHeight, strdup("f3"), MAX_SIZE );  squareButton->setToggle(true);  rowButton = cards->createButton( 60, 75,  80, 75 + lowerRowHeight, strdup("f4"), MAX_SIZE );  rowButton->setToggle(true);  scoutButton = cards->createButton( 80, 75, 100, 75 + lowerRowHeight, strdup("f5"), MAX_SIZE );  scoutButton->setToggle(true);  crossButton = cards->createButton( 100, 75,  120, 75 + lowerRowHeight, strdup("f6"), MAX_SIZE );  crossButton->setToggle(true);  groupButton = cards->createButton( 0, 75 + lowerRowHeight,  20, 75 + (lowerRowHeight * 2), strdup("G"), MAX_SIZE );  groupButton->setToggle(true);  groupButton->setSelected(true);  calendarButton = cards->createButton( 20, 75 + lowerRowHeight, 120, 75 + (lowerRowHeight * 2), 							   strdup(calendar->getCurrentDate().getDateString()), MAX_SIZE);        //calendarButton->setLabelPosition(Button::CENTER);  minButton = cards->createButton( 0, 75 + (lowerRowHeight * 2), 20, 75 + (lowerRowHeight * 3), strdup("-"), MAX_SIZE );  maxButton = cards->createButton( 0, 75 + (lowerRowHeight * 2), 20, 75 + (lowerRowHeight * 3), strdup("+"), MIN_SIZE );  int playerButtonWidth = (GUI_WIDTH - 120) / 4;  int playerButtonHeight = 20;    player1Button = cards->createButton( 120 + playerButtonWidth * 0, 0,  									   120 + playerButtonWidth * 1, playerButtonHeight, NULL, MAX_SIZE );  player1Button->setToggle(true);  player2Button = cards->createButton( 120 + playerButtonWidth * 1, 0,  									   120 + playerButtonWidth * 2, playerButtonHeight, NULL, MAX_SIZE );  player2Button->setToggle(true);  player3Button = cards->createButton( 120 + playerButtonWidth * 2, 0, 									   120 + playerButtonWidth * 3, playerButtonHeight, NULL, MAX_SIZE );  player3Button->setToggle(true);  player4Button = cards->createButton( 120 + playerButtonWidth * 3, 0,  									   120 + playerButtonWidth * 4, playerButtonHeight, NULL, MAX_SIZE );  player4Button->setToggle(true);  for(int i = 0; i < getPartySize(); i++) {	playerInfo[i] = new Canvas( 120 + playerButtonWidth * i, playerButtonHeight,  								120 + playerButtonWidth * (i + 1), GUI_HEIGHT - 25, 								this );	cards->addWidget( playerInfo[i], MAX_SIZE );  }  minPartyInfo = new Canvas( 0, 0, MIN_GUI_WIDTH, 75 + (lowerRowHeight * 2), this );  cards->addWidget( minPartyInfo, MIN_SIZE );  cards->setActiveCard( MAX_SIZE );   }void Party::drawWidget(Widget *w) {  char msg[80];  if(w == minPartyInfo) {	for(int i = 0; i < getPartySize(); i++) {	  	  // hp	  if(getParty(i) == getPlayer()) {		w->applyBorderColor();		glBegin( GL_QUADS );		glVertex3f( MIN_GUI_WIDTH, (i * 20), 0 );		glVertex3f( 0, (i * 20), 0 );		glVertex3f( 0, 20 + (i * 20), 0 );		glVertex3f( MIN_GUI_WIDTH, 20 + (i * 20), 0 );		glEnd();	  }	  //	  w->applyColor();	  glColor4f( 0.8f, 0.2f, 0.0f, 1.0f );	  sprintf(msg, "%c:", getParty(i)->getName()[0]);	  scourge->getSDLHandler()->texPrint(0, 13 + (i * 20), msg);	  Util::drawBar(15, 8 + (i * 20), MIN_GUI_WIDTH - 20,  					(float)getParty(i)->getHp(), (float)getParty(i)->getMaxHp());	  Util::drawBar(15, 14 + (i * 20), MIN_GUI_WIDTH - 20,  					(float)getParty(i)->getMp(), (float)getParty(i)->getMaxMp(),					0.45f, 0.65f, 1.0f, false);	}  } else {	int selectedPlayerIndex = -1;	for(int i = 0; i < getPartySize(); i++) {	  if(playerInfo[i] == w) {		selectedPlayerIndex = i;		break;	  }	}	if(selectedPlayerIndex == -1) {	  cerr << "Warning: Unknown widget in Party::drawWidget." << endl;	  return;	}	Creature *p = getParty(selectedPlayerIndex);		// hp	w->applyColor();	sprintf(msg, "%d/%d", p->getHp(), p->getMaxHp());	scourge->getSDLHandler()->texPrint(3, 10, msg);	glColor4f( 0.8f, 0.2f, 0.0f, 1.0f );	sprintf(msg, "hp:");	scourge->getSDLHandler()->texPrint(3, 20, msg);	Util::drawBar(22, 18, ((GUI_WIDTH - 120) / 4) - 24,  				  (float)p->getHp(), (float)p->getMaxHp());		// mp	w->applyColor();	sprintf(msg, "%d/%d", p->getMp(), p->getMaxMp());	scourge->getSDLHandler()->texPrint(3, 35, msg);	glColor4f( 0.8f, 0.2f, 0.0f, 1.0f );	sprintf(msg, "mp:");	scourge->getSDLHandler()->texPrint(3, 45, msg);	Util::drawBar(22, 43, ((GUI_WIDTH - 120) / 4) - 24,  				  (float)p->getMp(), (float)p->getMaxMp(),				  0.45f, 0.65f, 1.0f, false);	/*	// ac	w->applyColor();	sprintf(msg, "%d/%d", p->getSkillModifiedArmor(), p->getArmor());	scourge->getSDLHandler()->texPrint(3, 35, msg);	glColor4f( 0.8f, 0.2f, 0.0f, 1.0f );	sprintf(msg, "ac:");	scourge->getSDLHandler()->texPrint(3, 45, msg);	Util::drawBar(22, 43, ((GUI_WIDTH - 120) / 4) - 24,  	(float)p->getSkillModifiedArmor(), (float)p->getArmor());	*/		// exp	w->applyColor();	sprintf(msg, "%d (%d)", p->getExp(), p->getLevel());	scourge->getSDLHandler()->texPrint(3, 60, msg);	glColor4f( 0.8f, 0.2f, 0.0f, 1.0f );	sprintf(msg, "ex:");	scourge->getSDLHandler()->texPrint(3, 70, msg);	Util::drawBar(22, 68, ((GUI_WIDTH - 120) / 4) - 24,  				  (float)p->getExp(), (float)p->getExpOfNextLevel(),				  1.0f, 0.65f, 1.0f, false);		// show stat mods	glEnable(GL_TEXTURE_2D);	int xp = 0;	int yp = 0;	float n = 12;	int row = 5;	int left = 5;	int bottom = w->getHeight() - ((int)(3 * n + 1) + 4);	for(int i = 0; i < Constants::STATE_MOD_COUNT; i++) {	  GLuint icon = scourge->getShapePalette()->getStatModIcon(i);	  if(p->getStateMod(i)) {		glColor4f( 1.0f, 1.0f, 0.5f, 0.5f );		if(icon) {		  glBindTexture( GL_TEXTURE_2D, icon );		}	  } else {		w->applyBorderColor();		icon = 0;	  }	  	  glPushMatrix();	  glTranslatef( left + xp * (n + 1), bottom + (yp * (n + 1)), 0 );	  glBegin( GL_QUADS );	  glNormal3f( 0, 0, 1 );	  if(icon) glTexCoord2f( 0, 0 );	  glVertex3f( 0, 0, 0 );	  if(icon) glTexCoord2f( 0, 1 );	  glVertex3f( 0, n, 0 );	  if(icon) glTexCoord2f( 1, 1 );	  glVertex3f( n, n, 0 );	  if(icon) glTexCoord2f( 1, 0 );	  glVertex3f( n, 0, 0 );	  glEnd();	  glPopMatrix();	  	  xp++;	  if(xp >= row) {		xp = 0;		yp++;	  }	}	glDisable(GL_TEXTURE_2D);  }}void Party::drawView() {  // update current date variables and see if scheduled events have occured    if(calendar->update(scourge->getUserConfiguration()->getGameSpeedLevel())){	calendarButton->getLabel()->setTextCopy(calendar->getCurrentDate().getDateString());          }  // refresh map if any party member's effect is on  bool effectOn = false;  for(int i = 0; i < getPartySize(); i++) {	if(!party[i]->getStateMod(Constants::dead) && party[i]->isEffectOn()) {	  effectOn = true;	  break;	}  }  if(effectOn != lastEffectOn) {	lastEffectOn = effectOn;	scourge->getMap()->refresh();  }}bool Party::handleEvent(Widget *widget, SDL_Event *event) {  if(widget == inventoryButton) {	scourge->toggleInventoryWindow();  } else if(widget == optionsButton) {	scourge->toggleOptionsWindow();  } else if(widget == quitButton) {	scourge->showExitConfirmationDialog();  } else if(widget == diamondButton) {	setFormation(Constants::DIAMOND_FORMATION - Constants::DIAMOND_FORMATION);  } else if(widget == staggeredButton) {	setFormation(Constants::STAGGERED_FORMATION - Constants::DIAMOND_FORMATION);  } else if(widget == squareButton) {	setFormation(Constants::SQUARE_FORMATION - Constants::DIAMOND_FORMATION);  } else if(widget == rowButton) {	setFormation(Constants::ROW_FORMATION - Constants::DIAMOND_FORMATION);  } else if(widget == scoutButton) {	setFormation(Constants::SCOUT_FORMATION - Constants::DIAMOND_FORMATION);  } else if(widget == crossButton) {	setFormation(Constants::CROSS_FORMATION - Constants::DIAMOND_FORMATION);  } else if(widget == player1Button) {	setPlayer(Constants::PLAYER_1 - Constants::PLAYER_1);  } else if(widget == player2Button) {	setPlayer(Constants::PLAYER_2 - Constants::PLAYER_1);  } else if(widget == player3Button) {	setPlayer(Constants::PLAYER_3 - Constants::PLAYER_1);  } else if(widget == player4Button) {	setPlayer(Constants::PLAYER_4 - Constants::PLAYER_1);  } else if(widget == groupButton) {	togglePlayerOnly();  } else if(widget == roundButton) {	toggleRound();  } else if(widget == minButton) {	cards->setActiveCard( MIN_SIZE );	mainWin->resize( MIN_GUI_WIDTH, GUI_HEIGHT );	oldX = mainWin->getX();	mainWin->move( (oldX < (scourge->getSDLHandler()->getScreen()->w / 2) - (GUI_WIDTH / 2) ? 					0 : 					scourge->getSDLHandler()->getScreen()->w - MIN_GUI_WIDTH), mainWin->getY() );	mainWin->setTitle( min_version );  } else if(widget == maxButton) {	cards->setActiveCard( MAX_SIZE );	mainWin->move( oldX, mainWin->getY() );	mainWin->resize( GUI_WIDTH, GUI_HEIGHT );	mainWin->setTitle( version );  }  return false;}/** 	Return the closest live player within the given radius or null if none can be found.*/Creature *Party::getClosestPlayer(int x, int y, int w, int h, int radius) {  float minDist = 0;  Creature *p = NULL;  for(int i = 0; i < getPartySize(); i++) {	if(!party[i]->getStateMod(Constants::dead)) {	  float dist = Constants::distance(x, y, w, h,									   party[i]->getX(),									   party[i]->getY(),									   party[i]->getShape()->getWidth(),									   party[i]->getShape()->getDepth());	  if(dist <= (float)radius &&		 (!p || dist < minDist)) {		p = party[i];		minDist = dist;	  }	}  }  return p;}void Party::startEffect(int effect_type, int duration) {  for(int i = 0; i < getPartySize(); i++) {	if(!party[i]->getStateMod(Constants::dead)) {	  party[i]->startEffect(effect_type, duration);	}  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -