예제 #1
0
void GameController::tryPlayerMove (Direction direction) {
    if (isFinished ()) {
        return;
    }

    Coords playerCoords = level.getObjectCoords (player);

    Coords playerDestination = playerCoords + direction;

    if (level.isValidCoord (playerDestination)) {

        if (!level.isEmpty (playerDestination)) {
            ObjectRef targetObject = level.getObject (playerDestination);

            auto interaction = targetObject->getGameClass ().interactionFunction;

            GameCommands commands (*this, targetObject);

            interaction (commands);
        } else {
            level.setObject (playerDestination, player);
            level.clear (playerCoords);
        }
    }

    displayFunction (data, level);
}
예제 #2
0
/**
 * Affichage de la scène OpenGL.
 */
void gu_display() {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  glPushMatrix();
  displayFunction();
  glPopMatrix();
  
  SDL_GL_SwapBuffers();

  GLenum erreur;
  if ((erreur = glGetError()) != GL_NO_ERROR) {
    fprintf(stderr, "Erreur OpenGL dans display : %s\n", gluErrorString(erreur));
  }
}
예제 #3
0
void W_LABEL::display(int xOffset, int yOffset)
{
	if (displayFunction != NULL)
	{
		displayFunction(this, xOffset, yOffset);
		return;
	}

	iV_SetFont(FontID);
	iV_SetTextColour(fontColour);

	QByteArray text = aText.toUtf8();
	int fx;
	if (style & WLAB_ALIGNCENTRE)
	{
		int fw = iV_GetTextWidth(text.constData());
		fx = xOffset + x() + (width() - fw) / 2;
	}
	else if (style & WLAB_ALIGNRIGHT)
	{
		int fw = iV_GetTextWidth(text.constData());
		fx = xOffset + x() + width() - fw;
	}
	else
	{
		fx = xOffset + x();
	}
	int fy;
	if ((style & WLAB_ALIGNTOPLEFT) != 0)  // Align top
	{
		fy = yOffset + y() - iV_GetTextAboveBase();
	}
	else if ((style & WLAB_ALIGNBOTTOMLEFT) != 0)  // Align bottom
	{
		fy = yOffset + y() - iV_GetTextAboveBase() + (height() - iV_GetTextLineSize());
	}
	else
	{
		fy = yOffset + y() - iV_GetTextAboveBase() + (height() - iV_GetTextLineSize())/2;
	}
	iV_DrawText(text.constData(), fx, fy);
}
예제 #4
0
파일: pick.c 프로젝트: canvural/CG-Project
/**
 * pick.c
 *
 * Handles the picking an object.
 */
int handlePicking()
{
	renderMode = GL_SELECT; 
	glRenderMode(renderMode);
	glInitNames(); 
	glPushName(-1);
	displayFunction();
	renderMode = GL_RENDER; 
	hits = glRenderMode(renderMode);
	fprintf(stdout, "# pick hits = %d\n", hits);
	
	if(hits > 0)
    {
        int choose = pickBuffer[3];
        int depth = pickBuffer[1];
		int loop;

        for (loop = 1; loop < hits; loop++) {
			// select the closest object
			if (pickBuffer[loop*4+1] < (GLuint)depth)
			{
				choose = pickBuffer[loop*4+3];
				depth = pickBuffer[loop*4+1];
			}
        }
        printf("Selected item id => %d\n\n", choose);
	    object *selectedObject = getObjectById(choose);
	    if(selectedObject->data->selected) {
			selectedObject->data->selected = 0;
			selectedObjectId = 0;
	    }
	    else {
			selectedObject->data->selected = 1;
			selectedObjectId = choose;
		}
	  
		return 0;
    }
	
	return 1;
}