5Fermer7
boulifbLe 10/08/2006 à 19:13
à la demande de Godzil, voici le bout de code illustrant la technique utilisée (très simple) wink

	int							nWidth=SCREEN_WIDTH/SCALE, nHeight=SCREEN_HEIGHT/SCALE;
	int							nXPos=0, nYPos=0, nScrollSpeed=0, dir=-1;

	...
	dir=rand() % 4;
	bShake=(*pEnvironment)->toki.sprite.state == TOKISTATE_GHOSTTRAPDOWN;

	...
	
	// calculate the correct position X of the camera depending on toki's position in the map
	nXPos=(*pEnvironment)->toki.sprite.location.x-(nWidth/2);

	if (bShake && dir == 0)
		nXPos--;

	if (nXPos < 0)
		nXPos=0;
		
	 if (bShake && dir == 1)
		nXPos++;
	
	 if (nXPos > ((*pEnvironment)->level->size.cx*TILE_WIDTH)-nWidth)
		nXPos=(((*pEnvironment)->level->size.cx*TILE_WIDTH)-nWidth);
	
	// calculate the correct position Y of the camera depending on toki's position in the map
	nYPos=(*pEnvironment)->toki.sprite.location.y-(nHeight/2);
	
	 if (bShake && dir == 2)
		nYPos--;

	 if (nYPos < 0)
		nYPos=0;
		
	 if (bShake && dir == 3)
		nYPos++;

	 if (nYPos > ((*pEnvironment)->level->size.cy*TILE_HEIGHT)-nHeight)
		nYPos=(((*pEnvironment)->level->size.cy*TILE_HEIGHT)-nHeight);
	...


Ce qui donne bien l'effet visuel escompté:
[URL=http://imageshack.us][IMG]http://img144.imageshack.us/img144/8787/totogtvn7.gif[/IMG][/URL]

Voilà smile