예제 #1
0
void GameDrawer::drawCrabsAndPoles(bool isReflected) {
	if (crabModel != NULL) {
		glEnable(GL_NORMALIZE);
		for(int i = 0; i < 4; i++) {
			Crab* crab = game->crabs()[i];
			
			//Translate and rotate to the appropriate side of the board
			glPushMatrix();
			switch(i) {
				case 1:
					glTranslatef(0, 0, 1);
					glRotatef(90, 0, 1, 0);
					break;
				case 2:
					glTranslatef(1, 0, 1);
					glRotatef(180, 0, 1, 0);
					break;
				case 3:
					glTranslatef(1, 0, 0);
					glRotatef(270, 0, 1, 0);
					break;
			}
			
			if (crab != NULL || crabFadeAmounts[i] > 0) {
				//Draw the crab
				glPushMatrix();
				
				float crabPos;
				if (crab != NULL) {
					crabPos = crab->pos();
				}
				else {
					crabPos = oldCrabPos[i];
				}
				glTranslatef(crabPos, 0.055f, CRAB_OFFSET);
				if (crab == NULL) {
					//Used for the shrinking effect, whereby crabs shrink
					//until they disappear when they are eliminated from play
					glTranslatef(0, -0.055f * (1 - crabFadeAmounts[i]), 0);
					glScalef(crabFadeAmounts[i],
							 crabFadeAmounts[i],
							 crabFadeAmounts[i]);
				}
				
				glRotatef(-90, 0, 1, 0);
				glRotatef(-90, 1, 0, 0);
				glScalef(0.05f, 0.05f, 0.05f);
				
				if (crab == NULL || crab->dir() == 0) {
					crabModel->setAnimation("stand");
				}
				else {
                    crabModel->setAnimation("run");
				}
				
				glColor3f(1, 1, 1);
				crabModel->draw(i, animTimes[i]);
				glPopMatrix();
			}
			
			if (crab == NULL) {
				//Draw the pole
				if (isReflected) {
					glDisable(GL_NORMALIZE);
				}
				glCallList(poleDisplayListId);
				if (isReflected) {
					glEnable(GL_NORMALIZE);
				}
			}
			
			glPopMatrix();
		}
	}
}
예제 #2
0
void GameDrawer::step() {
	//Advance the game
	game->advance(STEP_TIME);
	
	//Advance the water
	waterTextureOffset += STEP_TIME / WATER_TEXTURE_TIME;
	while (waterTextureOffset > WATER_TEXTURE_SIZE) {
		waterTextureOffset -= WATER_TEXTURE_SIZE;
	}
	
	//Update animTimes, crabFadeAmounts, and isGameOver0
	bool opponentAlive = false;
	for(int i = 0; i < 4; i++) {
		Crab* crab = game->crabs()[i];
		
		if (crab != NULL) {
			oldCrabPos[i] = crab->pos();
		}
		
		//Update animation time
		if (crab != NULL || crabFadeAmounts[i] > 0) {
			if (crab != NULL && crab->dir() != 0) {
				if (crab->dir() > 0) {
					animTimes[i] += STEP_TIME / WALK_ANIM_TIME;
				}
				else {
					animTimes[i] -= STEP_TIME / WALK_ANIM_TIME;
				}
			}
			else {
				animTimes[i] += STEP_TIME / STAND_ANIM_TIME;
			}
			
			while (animTimes[i] > 1) {
				animTimes[i] -= 1;
			}
			while (animTimes[i] < 0) {
				animTimes[i] += 1;
			}
		}
		
		//Update fade amount
		if (crab == NULL) {
			crabFadeAmounts[i] -= STEP_TIME / CRAB_FADE_OUT_TIME;
			if (crabFadeAmounts[i] < 0) {
				if (i == 0) {
					isGameOver0 = true;
				}
				crabFadeAmounts[i] = 0;
			}
			else if (i != 0) {
				opponentAlive = true;
			}
		}
		else if (i != 0) {
			opponentAlive = true;
		}
	}
	
	if (!opponentAlive) {
		isGameOver0 = true;
	}
}