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

📄 scourge.cpp

📁 S.C.O.U.R.G.E.是一款类似Rogue的游戏
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    }    break;	  case SDL_MOUSEBUTTONUP:	sdlHandler->applyMouseOffset(event->motion.x, event->motion.y, &mx, &my);    if(event->button.button) {	  processGameMouseClick(mx, my, event->button.button);	  if(teleporting && !exitConfirmationDialog->isVisible()) {		exitLabel->setText(Constants::getMessage(Constants::TELEPORT_TO_BASE_LABEL));		party->toggleRound(true);		exitConfirmationDialog->setVisible(true);	  } else if(changingStory && !exitConfirmationDialog->isVisible()) {		exitLabel->setText(Constants::getMessage(Constants::USE_GATE_LABEL));		party->toggleRound(true);		exitConfirmationDialog->setVisible(true);	  }    }    break;  }  switch(event->type) {  case SDL_KEYDOWN:  case SDL_KEYUP:	if(event->key.keysym.sym == SDLK_m) {	  missionCompleted();	  return false;	}	// this is here to test effects	if(event->key.keysym.sym == SDLK_f) {	  party->startEffect(Constants::EFFECT_FLAMES, (Constants::DAMAGE_DURATION * 4));	  return false;	}	if(event->key.keysym.sym == SDLK_t) {	  party->startEffect(Constants::EFFECT_TELEPORT, (Constants::DAMAGE_DURATION * 4));	  return false;	}	if(event->key.keysym.sym == SDLK_g) {	  party->startEffect(Constants::EFFECT_GLOW, (Constants::DAMAGE_DURATION * 4));	  return false;	}	if(event->key.keysym.sym == SDLK_h) {	  //party->startEffect(Constants::EFFECT_GREEN, (Constants::DAMAGE_DURATION * 4));    map->startEffect(party->getParty(0)->getX(), party->getParty(0)->getY(), 3,                      Constants::EFFECT_GREEN, (Constants::DAMAGE_DURATION * 4), 2, 2);	  return false;	}	if(event->key.keysym.sym == SDLK_j) {	  party->startEffect(Constants::EFFECT_EXPLOSION, (Constants::DAMAGE_DURATION * 4));	  return false;	}	if(event->key.keysym.sym == SDLK_k) {	  party->startEffect(Constants::EFFECT_SWIRL, (Constants::DAMAGE_DURATION * 4));	  return false;	}	if(event->key.keysym.sym == SDLK_l) {	  party->startEffect(Constants::EFFECT_CAST_SPELL, (Constants::DAMAGE_DURATION * 4));	  return false;	}	if(event->key.keysym.sym == SDLK_d) {    map->startEffect(party->getParty(0)->getX(), party->getParty(0)->getY(), 3,                      Constants::EFFECT_RING, (Constants::DAMAGE_DURATION * 4), 6, 6);	  return false;	}      if(event->type == SDL_KEYUP && event->key.keysym.sym == SDLK_ESCAPE){	  if(exitConfirmationDialog->isVisible()) {		exitConfirmationDialog->setVisible(false);	  } else {		party->toggleRound(true);		exitConfirmationDialog->setVisible(true);	  }	  	  return false;	}        // xxx_yyy_stop means : "do xxx_yyy action when the corresponding key is up"    ea = userConfiguration->getEngineAction(event);        if(ea == SET_MOVE_DOWN){        	  setMove(Constants::MOVE_DOWN);    }    else if(ea == SET_MOVE_UP){	  setMove(Constants::MOVE_UP);    }    else if(ea == SET_MOVE_RIGHT){	  setMove(Constants::MOVE_RIGHT);    }    else if(ea == SET_MOVE_LEFT){	  setMove(Constants::MOVE_LEFT);    }    else if(ea == SET_MOVE_DOWN_STOP){        	  map->setYRot(0.0f);	  map->setYRot(0);	  removeMove(Constants::MOVE_DOWN);    }    else if(ea == SET_MOVE_UP_STOP){	  map->setYRot(0.0f);	  map->setYRot(0);	  removeMove(Constants::MOVE_UP);    }    else if(ea == SET_MOVE_RIGHT_STOP){	  map->setYRot(0.0f);	  map->setZRot(0);	  removeMove(Constants::MOVE_RIGHT);    }    else if(ea == SET_MOVE_LEFT_STOP){	  map->setYRot(0.0f);	  map->setZRot(0);	  removeMove(Constants::MOVE_LEFT);    }                else if(ea == SET_PLAYER_0){	  party->setPlayer(0);    }    else if(ea == SET_PLAYER_1){	  party->setPlayer(1);    }    else if(ea == SET_PLAYER_2){	  party->setPlayer(2);    }    else if(ea == SET_PLAYER_3){	  party->setPlayer(3);    }    else if(ea == SET_PLAYER_ONLY){	  party->togglePlayerOnly();    }    	//    else if(ea == BLEND_A){    else if(event->type == SDL_KEYUP && event->key.keysym.sym == SDLK_6){        blendA++; if(blendA >= 11) blendA = 0;        fprintf(stderr, "blend: a=%d b=%d\n", blendA, blendB);    }	//    else if(ea == BLEND_B){        else if(event->type == SDL_KEYUP && event->key.keysym.sym == SDLK_7){            blendB++; if(blendB >= 11) blendB = 0;        fprintf(stderr, "blend: a=%d b=%d\n", blendA, blendB);    }    else if(ea == SHOW_INVENTORY){	  inventory->show(); 	      }    else if(ea == SHOW_OPTIONS_MENU){	  party->toggleRound(true);	  optionsMenu->show();    }    else if(ea == USE_ITEM_STOP){        useItem();            }    else if(ea == SET_NEXT_FORMATION_STOP){        if(party->getFormation() < Creature::FORMATION_COUNT - 1) party->setFormation(party->getFormation() + 1);	else party->setFormation(Constants::DIAMOND_FORMATION - Constants::DIAMOND_FORMATION);    }       else if(ea == SET_X_ROT_PLUS){                map->setXRot(5.0f);    }    else if(ea == SET_X_ROT_MINUS){        map->setXRot(-5.0f);    }    else if(ea == SET_Y_ROT_PLUS){        map->setYRot(5.0f);    }    else if(ea == SET_Y_ROT_MINUS){        map->setYRot(-5.0f);    }    else if(ea == SET_Z_ROT_PLUS){        map->setZRot(5.0f);    }    else if(ea == SET_Z_ROT_MINUS){        map->setZRot(-5.0f);    }        else if(ea == SET_X_ROT_PLUS_STOP){        map->setXRot(0.0f);    }    else if(ea == SET_X_ROT_MINUS_STOP){        map->setXRot(0.0f);    }    else if(ea == SET_Y_ROT_PLUS_STOP){        map->setYRot(0.0f);    }    else if(ea == SET_Y_ROT_MINUS_STOP){        map->setYRot(0.0f);    }    else if(ea == SET_Z_ROT_PLUS_STOP){        map->setZRot(0.0f);    }    else if(ea == SET_Z_ROT_MINUS_STOP){        map->setZRot(0.0f);    }        else if(ea == ADD_X_POS_PLUS){        map->addXPos(10.0f);    }    else if(ea == ADD_X_POS_MINUS){        map->addXPos(-10.0f);    }    else if(ea == ADD_Y_POS_PLUS){        map->addYPos(10.0f);    }    else if(ea == ADD_Y_POS_MINUS){        map->addYPos(-10.0f);    }    else if(ea == ADD_Z_POS_PLUS){        map->addZPos(10.0f);    }    else if(ea == ADD_Z_POS_MINUS){        map->addZPos(-10.0f);    }         else if(ea == MINIMAP_ZOOM_IN){        miniMap->zoomIn();    }    else if(ea == MINIMAP_ZOOM_OUT){        miniMap->zoomOut();    }    else if(ea == MINIMAP_TOGGLE){        miniMap->toggle();    }    else if(ea == SET_ZOOM_IN){        map->setZoomIn(true);    }    else if(ea == SET_ZOOM_OUT){        map->setZoomOut(true);    }    else if(ea == SET_ZOOM_IN_STOP){        map->setZoomIn(false);    }    else if(ea == SET_ZOOM_OUT_STOP){        map->setZoomOut(false);    }    else if(ea == TOGGLE_MAP_CENTER){        bool mc;        mc = userConfiguration->getAlwaysCenterMap();        userConfiguration->setAlwaysCenterMap(!mc);    }    else if(ea == INCREASE_GAME_SPEED){        addGameSpeed(-1);            }    else if(ea == DECREASE_GAME_SPEED){        addGameSpeed(1);            }    	else if(ea == START_ROUND) {	  party->toggleRound();	}    break;  default: break;  }  return false;  }void Scourge::processGameMouseMove(Uint16 x, Uint16 y) {  Uint16 mapx, mapy;  getMapXYAtScreenXY(x, y, &mapx, &mapy);  if(mapx < MAP_WIDTH) {	// find the drop target	Location *dropTarget = NULL;	if(movingItem) {	  Uint16 mapx, mapy, mapz;	  getMapXYZAtScreenXY(x, y, &mapx, &mapy, &mapz);	  if(mapx < MAP_WIDTH) {		dropTarget = map->getLocation(mapx, mapy, mapz);		if(!(dropTarget && 			 (dropTarget->creature || 			  (dropTarget->item && dropTarget->item->getRpgItem()->getType() == RpgItem::CONTAINER)) )) 		  dropTarget = NULL;	  }	}	map->setSelectedDropTarget(dropTarget);	map->handleMouseMove(mapx, mapy, 0);  }}void Scourge::processGameMouseDown(Uint16 x, Uint16 y, Uint8 button) {  Uint16 mapx, mapy, mapz;  if(button == SDL_BUTTON_LEFT) {	// click on an item	getMapXYZAtScreenXY(x, y, &mapx, &mapy, &mapz);	if(mapx > MAP_WIDTH) {	  getMapXYAtScreenXY(x, y, &mapx, &mapy);	  mapz = 0;	}	if(startItemDrag(mapx, mapy, mapz)) return;  }}void Scourge::processGameMouseClick(Uint16 x, Uint16 y, Uint8 button) {  char msg[80];  Uint16 mapx, mapy, mapz;  Creature *c = getTargetSelectionFor();  if(button == SDL_BUTTON_LEFT) {	getMapXYZAtScreenXY(x, y, &mapx, &mapy, &mapz);		// clicking on a creature	if(!movingItem && mapx < MAP_WIDTH) {	  Location *loc = map->getLocation(mapx, mapy, mapz);	  if(loc && loc->creature) {		if(getTargetSelectionFor()) {		  		  // make sure the selected action can target a creature		  if(c->getAction() == Constants::ACTION_CAST_SPELL &&			 c->getActionSpell() &&			 c->getActionSpell()->isCreatureTargetAllowed()) {						// assign this creature			c->setTargetCreature(loc->creature);			char msg[80];			sprintf(msg, "%s will target %s", c->getName(), c->getTargetCreature()->getName());			map->addDescription(msg);						  } else {			sprintf(msg, "%s cancelled a pending action.", c->getName());			map->addDescription(msg);		  }		  // turn off selection mode		  setTargetSelectionFor(NULL);		  return;		} else if(loc->creature->isMonster()) {		  // follow this creature		  party->setTargetCreature(loc->creature);		  return;		} else {		  // select player		  for(int i = 0; i < party->getPartySize(); i++) {			if(party->getParty(i) == loc->creature) {			  party->setPlayer(i);			  return;			}		  }		}	  }	}		// click on an item	if(mapx > MAP_WIDTH) {	  getMapXYAtScreenXY(x, y, &mapx, &mapy);	  mapz = 0;	}	if(useItem(mapx, mapy, mapz)) return;		// click on the map	getMapXYAtScreenXY(x, y, &mapx, &mapy);		// make sure the selected action can target a location	if(c) {	  if(c->getAction() == Constants::ACTION_CAST_SPELL &&		 c->getActionSpell() &&		 c->getActionSpell()->isLocationTargetAllowed()) {				// assign this creature		c->setTargetLocation(mapx, mapy, 0);		char msg[80];		sprintf(msg, "%s selected a target", c->getName());		map->addDescription(msg);					  } else {		sprintf(msg, "%s cancelled a pending action.", c->getName());		map->addDescription(msg);	  }	  // turn off selection mode	  setTargetSelectionFor(NULL);	  return;	}		/*	// cancel target selection mode	// FIXME: handle item selection. e.g.: open door from afar, etc.	if(getTargetSelectionFor()) {	Creature *c = getTargetSelectionFor();	c->setAction(-1);	setTargetSelectionFor(NULL);	sprintf(msg, "%s cancelled a pending action.", c->getName());	map->addDescription(msg);	}	*/		// FIXME: try to move to party.cpp	party->getPlayer()->setSelXY(mapx, mapy);	if(party->isPlayerOnly()) {	  party->getPlayer()->cancelTarget();	} else {	  for(int i = 0; i < party->getPartySize(); i++) {		if(!party->getParty(i)->getStateMod(Constants::dead)) {		  party->getParty(i)->cancelTarget();		  if(party->getParty(i) != party->getPlayer()) party->getParty(i)->follow(map);		}	  }	}	// end of FIXME		  } else if(button == SDL_BUTTON_RIGHT) {	getMapXYZAtScreenXY(x, y, &mapx, &mapy, &mapz);	// default click handling	map->handleMouseClick(mapx, mapy, mapz, button);		  }}void Scourge::getMapXYAtScreenXY(Uint16 x, Uint16 y,                                 Uint16 *mapx, Uint16 *mapy) {    glPushMatrix();    // Initialize the scene w/o y rotation.    //map->initMapView(false, true);    map->initMapView(true);    double obj_x, obj_y, obj_z;    double win_x = (double)x;

⌨️ 快捷键说明

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