Пример #1
0
/**
* \fn void updateGameWorms(Jeu* jeu, Worms** wormsTab, SDL_Texture* pTextureDisplay, SDL_Rect* pCamera)
* \brief Update worms display, manages overlay and physics for all worms.
*
* \returns void
*/
void updateGameWorms(Jeu* jeu, Worms** wormsTab, SDL_Texture* pTextureDisplay, SDL_Rect* pCamera)
{
	int indexWorms;

	updateTeamLife(jeu->equipes);
	isGameEnd(jeu);

	if (!globalVar.gameEnd && !globalInput->menu && !globalInput->weaponTab)
	{
		if (wormsTab[globalVar.indexWormsTab]->vie <= 0)
		{
			callNextWorms(wormsTab);
		}
		globalInput->deplacement = 0;
		for (indexWorms = 0; indexWorms < globalVar.nbWormsTotal; indexWorms++)
		{
			if (indexWorms == globalVar.indexWormsTab || wormsTab[indexWorms]->wormsObject->reactToBomb == 1
				|| !testGround(jeu->pMapTerrain->collisionMapSurface, wormsTab[indexWorms]->wormsObject->objectSurface, 1))
			{
				if (wormsTab[indexWorms]->vie > 0
					|| (wormsTab[indexWorms]->vie == 0 && !testGround(jeu->pMapTerrain->collisionMapSurface, wormsTab[indexWorms]->wormsObject->objectSurface, 2)))
				{
					KaamWormsMotionManagement(wormsTab[indexWorms], jeu->pMapTerrain->collisionMapSurface);
				}
				if (deathByLimitMap(wormsTab[indexWorms], jeu->pMapTerrain->collisionMapSurface))
					resetInputs();
			}
			if (globalInput->deplacement || globalInput->raffraichissement)
			{
				updateTextSurfaceWormsTab(wormsTab);	//MAJ de la position du texte + Surface Vie	
				displayWorms(wormsTab[indexWorms], 1);
				if (globalVar.nbWormsTotal > 1)
					wormsOverlay(wormsTab);
				globalInput->raffraichissement = 1;
			}
			/*if (wormsTab[indexWorms]->vie > 0 && (!wormsTab[indexWorms]->wormsObject->startMotion || !wormsTab[indexWorms]->wormsObject->falling))
			randomAnimationWorms(wormsTab[indexWorms], jeu->pMapTerrain->collisionMapSurface);*/
		}
		updateHUD(wormsTab);
		if (wormsTab[globalVar.indexWormsTab]->vie > 0 && !globalInput->grenade)
			weaponManagement(jeu->pMapTerrain, pTextureDisplay, wormsTab, globalInput->weaponIndex, pCamera);
		if (globalInput->grenade && !globalInput->arme)
			grenadeManagement(jeu->pMapTerrain, pTextureDisplay, wormsTab, pCamera);
	}
}
Пример #2
0
int main(int argc, char *argv[]) 
{
	RGS_Init(256,240,0,0, RGS_NTSC);
	titleMenuOffset = 0;
	
	srand(SDL_GetTicks());
	
	// sounds
	
	jumpSound = RGS_LoadSFS(CONTENT_PATH"jump.sfs");
	hitSound = RGS_LoadSFS(CONTENT_PATH"hit.sfs");
	selectSound = RGS_LoadSFS(CONTENT_PATH"select.sfs");
	chooseSound = RGS_LoadSFS(CONTENT_PATH"select2.sfs");
	illegalSound = RGS_LoadSFS(CONTENT_PATH"illegal.sfs");
	bustedSound = RGS_LoadSFS(CONTENT_PATH"busted.sfs");
	sellSound = RGS_LoadSFS(CONTENT_PATH"sell.sfs");
	
	gameScreen = RGS_CreateScreen();
	gameScreen->visible = 0;
	titleScreen = RGS_CreateScreen();
	titleScreen->visible = 0;

	hiscoreScreen = RGS_CreateScreen();
	hiscoreScreen->visible = 0;
	
	RGS_CreateShape(hiscoreScreen, RGS_SHAPE_RECT, 0x000000, 0,0,256, 240);
	RGS_CreateLabel(hiscoreScreen, "*** HIGH SCORES ***", RGS_FONT_BIG, 65, 20, 0xffffff);

	int k;
	for(k=0;k<10;k++) {
		hsLabels[k] = RGS_CreateLabel(hiscoreScreen, "000000", RGS_FONT_BIG, 102, 50+(12*k), 0xffffff);
	}

	RGS_CreateLabel(hiscoreScreen, "PRESS ANY KEY", RGS_FONT_BIG, 85, 200, 0xffffff);
	
	RGS_Surface *titleSurface = RGS_LoadSurface(CONTENT_PATH"title.sur");
	RGS_CreateSurfaceImage(titleScreen, titleSurface, 0,0);
	RGS_CreateLabel(titleScreen, "NEW GAME", RGS_FONT_BIG, 160,125, 0xffffff);
	RGS_CreateLabel(titleScreen, "HIGH SCORES", RGS_FONT_BIG, 138,137, 0xffffff);
	RGS_CreateLabel(titleScreen, "EXIT", RGS_FONT_BIG, 190,149, 0xffffff);
	
	RGS_Surface *canearrowSurface = RGS_LoadSurface(CONTENT_PATH"canearrow.sur");
	caneArrow = RGS_CreateSurfaceImage(titleScreen, canearrowSurface, 220, 126);	
	
	aboutScreen = RGS_CreateScreen();
	aboutScreen->visible = 1;
	
	RGS_CreateShape(aboutScreen, RGS_SHAPE_RECT, 0x000000, 0,0,256, 240);
	RGS_CreateLabel(aboutScreen, "COPYRIGHT IVAN SAFRIN 2008", RGS_FONT_BIG, 40, 50, 0xffffff);
	RGS_CreateLabel(aboutScreen, "LICENSED BY TIGSOURCE OF AMERICA", RGS_FONT_BIG, 20, 65, 0xffffff);

	RGS_CreateLabel(aboutScreen, "VGNG IS A REGISTERED TRADEMARK OF", RGS_FONT_BIG, 15, 145, 0xffffff);
	RGS_CreateLabel(aboutScreen, "THE TIGSOURCE CORPORATION", RGS_FONT_BIG, 35, 160, 0xffffff);
	RGS_CreateLabel(aboutScreen, "MUSIC COPYRIGHT 50 CENT", RGS_FONT_BIG, 47, 185, 0xffffff);
	RGS_CreateLabel(aboutScreen, "EVERYTHING ELSE BY IVAN SAFRIN", RGS_FONT_BIG, 28, 200, 0xffffff);
	
	RGS_RegisterEntity(ENTITY_DEALER, gameScreen, CONTENT_PATH"dealer.spr", Dealer_Init, Dealer_Update, NULL, 0, NULL);
	RGS_RegisterEntity(ENTITY_CITIZEN, gameScreen, CONTENT_PATH"citizen2.spr", Citizen_Init, Citizen_Update, NULL, 0, NULL);
	RGS_RegisterEntity(ENTITY_COP, gameScreen, CONTENT_PATH"cop.spr", Cop_Init, Cop_Update, NULL, 0, NULL);
	RGS_RegisterEntity(ENTITY_HO, gameScreen, CONTENT_PATH"ho.spr", Ho_Init, Ho_Update, NULL, 0, NULL);
	
	testLevel = RGS_CreateTilemap(gameScreen, 256, 240, CONTENT_PATH"level1.map", CONTENT_PATH"level1.sur");
	int i;
	for(i =0;i < MAX_CITIZENS;i++) {
		RGS_CreateEntitySpriteByCode(testLevel, ENTITY_CITIZEN, rand() % testLevel->mapWidth, 40);
	}
	
	for(i =0;i < MAX_COPS;i++) {
		RGS_CreateEntitySpriteByCode(testLevel, ENTITY_COP, rand() % testLevel->mapWidth, 40);
	}

	for(i =0;i < MAX_HOS;i++) {
		RGS_CreateEntitySpriteByCode(testLevel, ENTITY_HO, rand() % testLevel->mapWidth, 40);
	}
	
	pimp.pimpSprite = RGS_CreateEntitySprite(gameScreen, testLevel, CONTENT_PATH"pimp2.spr");

	initPimp();

	RGS_PlaySpriteAnimation(pimp.pimpSprite->sprite, "idle",0);
	RGS_TilemapFollowEntity(testLevel, pimp.pimpSprite->entity, 0, -50);
	
	RGS_CreateShape(gameScreen, RGS_SHAPE_RECT, 0x000000, 0,0,256, 27);
	cashCounter = RGS_CreateLabel(gameScreen, "", RGS_FONT_BIG, 2,2, 0xffffff);
	methCounter = RGS_CreateLabel(gameScreen, "", RGS_FONT_BIG, 105,2, 0xffffff);
	cokeCounter = RGS_CreateLabel(gameScreen, "", RGS_FONT_BIG, 180,2, 0xffffff);
	
	moralCounter = RGS_CreateLabel(gameScreen, "", RGS_FONT_BIG, 2,14, 0x808080);
	hoCounter = RGS_CreateLabel(gameScreen, "", RGS_FONT_BIG, 105,14, 0x808080);
	timeCounter = RGS_CreateLabel(gameScreen, "", RGS_FONT_BIG, 180,14, 0x808080);
	
	dealingScreen = RGS_CreateScreen();
	RGS_CreateShape(dealingScreen, RGS_SHAPE_RECT, 0x000000, 15, 40, 160, 75);
	dealingScreen->visible = 0;
	dealerNameLabel = RGS_CreateLabel(dealingScreen, "", RGS_FONT_BIG, 20,45, 0x808080);
	dealerCokeLabel = RGS_CreateLabel(dealingScreen, "", RGS_FONT_BIG, 40,79, 0xffffff);
	dealermethLabel = RGS_CreateLabel(dealingScreen, "", RGS_FONT_BIG, 40,67, 0xffffff);
	RGS_CreateLabel(dealingScreen, "CANCEL", RGS_FONT_BIG, 40,91, 0xffffff);
	RGS_Surface *arrowSurface = RGS_LoadSurface(CONTENT_PATH"arrow.sur");
	dealArrow = RGS_CreateSurfaceImage(dealingScreen, arrowSurface, 30, 68);
	
	RGS_ResetTimer(&timeBlinkTimer);
	RGS_ResetTimer(&secondCounter);
	
	RGS_SetKeyCallback(onKeyPress);

	gameoverScreen = RGS_CreateScreen();
	gameoverScreen->visible = 0;
	
	
	RGS_CreateShape(gameoverScreen, RGS_SHAPE_RECT, 0x000000, 0, 0, 256, 240);
	moralLabel = RGS_CreateLabel(gameoverScreen, "YOU MONSTER! THOSE POOR WOMEN!", RGS_FONT_BIG, 22,45, 0xffffff);
	timeUpLabel = RGS_CreateLabel(gameoverScreen, "TIME'S UP! LETS SEE HOW YOU DID!", RGS_FONT_BIG, 22,45, 0xffffff);
	RGS_CreateLabel(gameoverScreen, "YOUR FINAL SCORE", RGS_FONT_BIG, 70,75, 0xffffff);
	finalScoreLabel = RGS_CreateLabel(gameoverScreen, "99999", RGS_FONT_BIG, 70,95, 0xffffff);
	hiScoreLabel = RGS_CreateLabel(gameoverScreen, "YOU GOT A HIGHSCORE!", RGS_FONT_BIG, 70,115, 0xffffff);
	RGS_CreateLabel(gameoverScreen, "PRESS ANY KEY", RGS_FONT_BIG, 85, 200, 0xffffff);
	
	wantedLabel = RGS_CreateLabel(gameScreen, "WANTED!!!", RGS_FONT_BIG, 100, 40, 0xe40060);
	fineLabel = RGS_CreateLabel(gameScreen, "THE COPS TOOK ALL YOUR DRUGS.", RGS_FONT_BIG, 20, 40, 0xffffff);
	fineLabel->object.visible = 0;
	
	helpScreen = RGS_CreateScreen();
	helpScreen->visible = 0;
	
	RGS_CreateShape(helpScreen, RGS_SHAPE_RECT, 0x000000, 0, 0, 256, 240);
	RGS_CreateLabel(helpScreen, "*** TINY PIMPING 101 *** ", RGS_FONT_BIG, 60,10, 0xffffff);	
	RGS_CreateLabel(helpScreen, "* PRESS UP TO BUY FROM DEALERS", RGS_FONT_BIG, 5,30, 0x808080);	
	RGS_CreateLabel(helpScreen, "* PRESS UP TO SELL METH TO METH HEADS", RGS_FONT_BIG, 5,45, 0xffffff);	
	RGS_CreateLabel(helpScreen, "* PRESS UP TO GIVE COKE TO THE HOS", RGS_FONT_BIG, 5,60, 0x808080);	
	RGS_CreateLabel(helpScreen, "* WITHOUT THE COKE THEY WONT MAKE $$$", RGS_FONT_BIG, 5,75, 0xffffff);	
	RGS_CreateLabel(helpScreen, "* PRESS Z TO JUMP", RGS_FONT_BIG, 5,90, 0x808080);	
	RGS_CreateLabel(helpScreen, "* PRESS X TO SMACK HOS FOR MONEY", RGS_FONT_BIG, 5,105, 0xffffff);	
	RGS_CreateLabel(helpScreen, "* WATCH YOUR MORAL INTEGRITY", RGS_FONT_BIG, 5,120, 0x808080);	
	RGS_CreateLabel(helpScreen, "* IF COPS SEE YOU DO ANYTHING ILLEGAL", RGS_FONT_BIG, 5,135, 0xffffff);	
	RGS_CreateLabel(helpScreen, "    YOU WILL BECOME WANTED", RGS_FONT_BIG, 5,150, 0xffffff);	
	RGS_CreateLabel(helpScreen, "* OTHERWISE THEY WONT TOUCH YOU, PIMP", RGS_FONT_BIG, 5,165, 0x808080);
	RGS_CreateLabel(helpScreen, "* HOW MUCH MONEY CAN YOU MAKE IN 5 MIN?", RGS_FONT_BIG, 5,180, 0xffffff);
	RGS_CreateLabel(helpScreen, "PRESS ANY KEY", RGS_FONT_BIG, 85, 210, 0xffffff);
	
	RGS_ResetTimer(&introTimer);
	RGS_ResetTimer(&moralTimer);
	
	while(RGS_Update() != 0) {
		if((minutesLeft < 0 || pimp.moralint < 0) && gameover == 0) {
			gameOver();
		}

		if(gameoverScreen->visible == 1 && gameoverkeylock == 1) {
			RGS_UpdateTimer(&gameoverTimer);
			if(RGS_TimerHasElapsed(&gameoverTimer, 3000) == 1) {
				gameoverkeylock = 0;
			}
	
		}

		if(pimp.isDealing == 0)
			dealingScreen->visible = 0;
			
		if(smacking == 1){
				RGS_UpdateTimer(&smackingTimer);
				if(RGS_TimerHasElapsed(&smackingTimer, 200) == 1) {
					smacking = 0;
				}
		}	
			
		RGS_UpdateTimer(&moralTimer);
		if(RGS_TimerHasElapsed(&moralTimer, 20) == 1)  {
			if(pimp.moralint < 999) {
				pimp.moralint++;
			}
		}
		
		RGS_UpdateTimer(&wantedTimer);
		if(RGS_TimerHasElapsed(&wantedTimer, 10000) == 1)
			stopWanted();
		
		dealArrow->object.y = 68 + (12*dealMenuOffset);
		caneArrow->object.y = 126 + (12*titleMenuOffset);
		

		if(showingIntro == 1) {
			RGS_UpdateTimer(&introTimer);
			if(RGS_TimerHasElapsed(&introTimer, 5000) == 1)
				hideIntro();
		}
		
		
		if(fineLabel->object.visible == 1) {
			RGS_UpdateTimer(&fineLabelTimer);
			if(RGS_TimerHasElapsed(&fineLabelTimer, 2000) == 1) {
				fineLabel->object.visible = 0;
			}
		}
		
		updateHUD();
		
		if(pimp.isDealing == 1)
			doIllegal();
		
		if(pimp.pimpSprite->entity->isTouchingGround == 1)
			jumping = 0;
		
		if(RGS_KeyDown(RGS_LEFT) == 1 && pimp.isDealing == 0){
			pimp.pimpSprite->entity->xVelocity = 100;
			pimp.pimpSprite->entity->xDirection = -1;
			if(jumping == 0 && smacking == 0)
				RGS_PlaySpriteAnimation(pimp.pimpSprite->sprite, "walk",0);
			pimp.pimpSprite->sprite->flipX = 1;
		} else if(RGS_KeyDown(RGS_RIGHT) == 1 && pimp.isDealing == 0){
			pimp.pimpSprite->entity->xVelocity = 100;
			pimp.pimpSprite->entity->xDirection = 1;	
			pimp.pimpSprite->sprite->flipX = 0;
			if(jumping == 0 && smacking == 0)
				RGS_PlaySpriteAnimation(pimp.pimpSprite->sprite, "walk",0);
		} else {
			if(jumping == 0 && smacking == 0)
				RGS_PlaySpriteAnimation(pimp.pimpSprite->sprite, "idle",0);	
		}
	}
	return 1;
}
Пример #3
0
void GameManager::tick()
{
	capTimer.start();

	// Calcuclate delta time
	auto lastFrame = currentFrame;
	currentFrame = hr_clock::now();
	auto timeSpan = currentFrame - lastFrame;
	deltaTime = static_cast<float>(timeSpan.count()) / 1000000000.0f;

	//Calculate and correct fps
	auto avgFPS = countedFrames / (fpsTimer.getTicks() / 1000.f);

	if (avgFPS > 2000000) {

		avgFPS = 0;
	}

	/***************
	* Movement
	****************/

	paddle.move(deltaTime);
	ball.move(paddle, deltaTime);

	SDL_Rect ballRect;
	ballRect.x = ball.getPosX();
	ballRect.y = ball.getPosY();
	ballRect.w = ball.mCollider.w;
	ballRect.h = ball.mCollider.h;

	// Check collision with the pieces
	for (auto & piece : pieces)
	{
		if (piece.isVisible)
		{
			auto hit = piece.hitByBall(&ball, ballRect);
			// We do not want to have more than 1 collision per frame
			if (hit) {
				totalBlocksDestroyed++;
				score.addScore();
				break;
			}
		}
	}

	// Advance to the next level
	if (totalBlocksDestroyed == PIECES)
	{
		level++;
		nextLevel(level);
	}

	// Game over
	if (ball.getLivesLeft() == 0)
	{
		restart();
	}

	int frameTicks = capTimer.getTicks();
	if (frameTicks < SCREEN_TICKS_PER_FRAME)
	{
		// wait the remaining time
		SDL_Delay(SCREEN_TICKS_PER_FRAME - frameTicks);
	}

	// Update game HUD every 10 ticks
	if(frameTicks < 10)
	{
		updateHUD();
	}

}
Пример #4
0
// Run by GLUT every [tickspeed] miliseconds
void tick(int in)
{
	
	// Local handles to objects
	Level *currentLevel = levelController->getCurrentLevel();
	Ball *ball = currentLevel->getBall();
	Physics *physics = ball->getPhysics();

	Tile* currentTile = currentLevel->getTile(ball->getCurrentTileID());
    vector<int> borderIDs = currentTile->getNeighborIDs();
    vector<Shape*> borderShapes = currentTile->getBorders()->getInwardShapes();

    vec3 ballPosition = physics->getPosition();

	// Debug -- Highlight current tile
	if (DEBUG_TILE_PAINT)
	{
		currentTile->getShapes()[0]->changeColor(TILE_HIGHLIGHT_COLOR);
		currentTile->getShapes()[0]->reload();
	}

    // Collision with cup
    glm::vec3 ballPos = physics->getPosition();
    glm::vec3 cupPos = currentLevel->getCup()->getPhysics()->getPosition();
    float cupPlaneDist = sqrt(((ballPos.x - cupPos.x)*(ballPos.x - cupPos.x)) + ((ballPos.z - cupPos.z)*(ballPos.z - cupPos.z)));

    if(cupPlaneDist < (CUP_RADIUS - (0.8 * BALL_RADIUS)) && abs(cupPos.y - ballPos.y) <= 1.1*BALL_OFFSET){ // allow for slight error
		//Play SFX for falling in hole
		sound->getEngine()->play2D("sfx/retro_cup.wav");
        //----------------CHANGE TO NEXT HOLE----------------//
        nextHole();
    }

    // Physics and collision calculations
	vec3 newDirection = physics->getDirection(); // used for tile transitions
    if(ballMoving)
	{
		// Check for collision
		if(detectCollisions(currentTile, physics, sound)){
			newDirection = physics->getDirection();
		}

        // Update ball direction
        newDirection = updateBallDirection(levelController, sound);

        // Update current tile
        currentTile = currentLevel->getTile(ball->getCurrentTileID());

        // Update ball speed
        double ballSpeed = physics->getSpeed();
        if(currentTile->getShapes().at(0)->normals()[0] == glm::vec3(0.0,1.0,0.0)){ // flat tile
            if(ballSpeed > 0.01){
                physics->setSpeed(ballSpeed - TILE_DEFAULT_FRICTION);
		        ballSpeed = physics->getSpeed();
            }
            else{
                physics->setSpeed(0.0);
                ballStopped();
            }
        }
        else if(newDirection.y > 0){ // going up hill
            //cout << endl << "UP";
            //cout << "Direction y-value: " << newDirection.y << endl;
            if(ballSpeed > 0.01){
                physics->setSpeed(ballSpeed - (TILE_DEFAULT_FRICTION + (2.0*currentTile->getSlope()*TILE_DEFAULT_FRICTION)));
		        ballSpeed = physics->getSpeed();
            }
        }
        else{ // going down hill
            //cout << endl << "DOWN";
            //cout << "Direction y-value: " << newDirection.y << endl;
            if(ballSpeed <= (100.0/100.1)){
                physics->setSpeed(ballSpeed + TILE_DEFAULT_FRICTION);
            }
            else{ // clmap speed
                ballSpeed = (100.0/100.1);
            }
        }

		// Update ballPosition
		physics->updatePosition();

		// Update shape using velocity
		Shape* ballShape = ball->getShapes().at(0);
		ballShape->translate(physics->getVelocity());

		// Update ball direction
		physics->setDirection(newDirection);

        // Snap ball to correct y value -- hacky
        if(currentTile->getShapes().at(0)->normals()[0] == glm::vec3(0.0,1.0,0.0)){ // flat tile
            if(physics->getPosition().y != (currentTile->getPhysics()->getPosition().y + BALL_OFFSET)){
                // Snap ball shape
                ball->getShapes()[0]->translate(vec3(0.0, -(physics->getPosition().y), 0.0));
                ball->getShapes()[0]->translate(vec3(0.0, (currentTile->getPhysics()->getPosition().y + BALL_OFFSET), 0.0));
                // Update ball physics
                physics->setPosition(vec3(physics->getPosition().x, (currentTile->getPhysics()->getPosition().y + BALL_OFFSET), physics->getPosition().z));
            }
        }
		else{// sloped tile
			float correctY = currentTile->getShapes()[0]->yValueAtPoint(physics->getPosition().x, physics->getPosition().z);
			if(physics->getPosition().y != correctY){
				// Snap ball shape
                ball->getShapes()[0]->translate(vec3(0.0, -(physics->getPosition().y), 0.0));
                ball->getShapes()[0]->translate(vec3(0.0, correctY, 0.0));
                // Update ball physics
				physics->setPositionY(correctY);
			}
		}

        // Reload shape
        ballShape->reload();

    }   
    
	// Update HUD
	currentLevel = levelController->getCurrentLevel();
    updateHUD(currentLevel->getLevelName(), fileIO->getNumHoles(), currentHoleScore, currentLevel->getPar());

	//If controls are enabled (ball not yet launched), then make ball direction equal to launchVector
	if (angleSpinner->enabled)
	{
		float launchAngleRadians = launchAngle * (PI/180);
		launchVector = normalize(vec3(sin(launchAngleRadians), 0.0, cos(launchAngleRadians)));
        updateCamera(physics->getPosition(), launchVector, false);
	}
	else
	{
		updateCamera(physics->getPosition(), physics->getDirection(), true);
	}

	glutTimerFunc(tickSpeed, tick, 0);
}
void CharacterEntity::setHealthPoints(const int healthPoints_) {
    healthPoints = healthPoints_;
    updateHUD();
}