コード例 #1
0
ファイル: GameState.cpp プロジェクト: Decesso/Cat-walking
GameState::GameState(SDL_Window& window)
	: 
	IState(window),
	score_(0),
	retCause_(0)
{
	shotTime_=time(0);
	background_ = IMG_LoadTexture(ren_, "Sprites/background.png");
	if (background_ == 0) {
		throw std::runtime_error(SDL_GetError());
	}

	font_ = TTF_OpenFont("sample.ttf", 20);
	catChar_ = new Character(*ren_, "Sprites/catsheet.png");
	addNewEnemies();
}
コード例 #2
0
ファイル: GameState.cpp プロジェクト: Decesso/Cat-walking
void
GameState::moveItems()
{

	for (unsigned int i = 0; i < shotList_.size(); i++) {
		shotList_[i]->move();
		if(missileCollision(shotList_[i])) shotList_[i]->boom();
	}
	for (unsigned int i = 0; i < enemyList_.size(); i++) {
		SDL_Rect rect = catChar_->getDestination();
		if (enemyList_[i]->isCollide(rect)) {
			LOG("Game ended with score : " + std::to_string(score_));
			run_ = false;
		}
		enemyList_[i]->move();
	}
	catChar_->move();
	enemyList_.erase(std::remove_if(std::begin(enemyList_), std::end(enemyList_), isEnemyFinished), std::end(enemyList_));
	shotList_.erase(std::remove_if(std::begin(shotList_), std::end(shotList_), isMissileFinished), std::end(shotList_));
	
	addNewEnemies();
}
コード例 #3
0
ファイル: World.cpp プロジェクト: AlexDontsov2008/spacecrash
void World::update(sf::Time dt)
{
	// Scroll the world, reset player velocity
	mWorldView.move(0.f, mScrollSpeed * dt.asSeconds());	
	mPlayerSpaceship->setVelocity(0.f, 0.f);

	// Check for delete enemies
	destroyEntitiesOutsideView();


	// Forward commands to scene graph, adapt velocity (scrolling, diagonal correction)
	while (!mCommandQueue.isEmpty())
		mSceneGraph.onCommand(mCommandQueue.pop(), dt);
	adaptPlayerVelocity();
	// Handle our collision.
	handleCollisions();

	// Remove all destroyed entities, and create new.
	mSceneGraph.removeWrecks();
	// Templates for add new Enemies.
	addNewEnemies(dt);
	spawnEnemies();
	// Check, for edding new world texture.
	updateWorldBounds();


	// Regular update step, adapt position (correct if outside view)
	mSceneGraph.update(dt, mCommandQueue);
	adaptPlayerPosition();
	// Update Points and Health.
	updateText(dt);

	mBattlifieldBounds.setPosition(getBattlefieldBounds().left, getBattlefieldBounds().top);
	// Update ScrollSpeed
	mScrollSpeed -= ScrollSpeedAccelerate * dt.asSeconds();
}
コード例 #4
0
ファイル: program.c プロジェクト: ethanx94/space
void _entryPoint()
{
	struct Services services;
	
	/****************************>           Get Handles           <****************************/
	//Get a handle to coreinit.rpl
	OSDynLoad_Acquire("coreinit.rpl", &services.coreinit_handle);
	//Get a handle to vpad.rpl */
	unsigned int vpad_handle;
	OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
	/****************************>       External Prototypes       <****************************/
	//VPAD functions
	int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error);

	//OS functions
	void(*_Exit)();
	
	/****************************>             Exports             <****************************/
	//VPAD functions
	OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);

	// Draw functions
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenPutPixelEx", &services.OSScreenPutPixelEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "DCFlushRange", &services.DCFlushRange);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenFlipBuffersEx", &services.OSScreenFlipBuffersEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenGetBufferSizeEx", &services.OSScreenGetBufferSizeEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenPutFontEx", &services.OSScreenPutFontEx);
	OSDynLoad_FindExport(services.coreinit_handle, 0, "OSScreenClearBufferEx", &services.OSScreenClearBufferEx);
	//OS functions
	OSDynLoad_FindExport(services.coreinit_handle, 0, "_Exit", &_Exit);
	cleanSlate(&services);
	
	/****************************>             Globals             <****************************/
	struct SpaceGlobals mySpaceGlobals;
	//Flag for restarting the entire game.
	mySpaceGlobals.restart = 1;
	mySpaceGlobals.services = &services;

	// initial state is title screen
	mySpaceGlobals.state = 1;
	mySpaceGlobals.titleScreenRefresh = 1;

	//Flags for render states
	mySpaceGlobals.renderResetFlag = 0;
	mySpaceGlobals.menuChoice = 0; // 0 is play, 1 is password
	
	// setup the password list
	unsigned int pwSeed = 27;
	int x;
	for (x=0; x<100; x++)
		mySpaceGlobals.passwordList[x] = (int)(prand(&pwSeed)*100000);
	
	// set the starting time
	int64_t (*OSGetTime)();
    OSDynLoad_FindExport(services.coreinit_handle, 0, "OSGetTime", &OSGetTime);
	mySpaceGlobals.seed = OSGetTime();
	
	/****************************>            VPAD Loop            <****************************/
	int error;
	VPADData vpad_data;
	
	// decompress compressed things into their arrays, final argument is the transparent color in their palette
	decompress_sprite(3061, 200, 100, compressed_title, mySpaceGlobals.title, 39);
	decompress_sprite(511, 36, 36, compressed_ship, mySpaceGlobals.orig_ship, 14);
	decompress_sprite(206, 23, 23, compressed_enemy, mySpaceGlobals.enemy, 9);
	
	// setup palette and transparent index
	mySpaceGlobals.curPalette = ship_palette;
	mySpaceGlobals.transIndex = 14;
	
	// initialize starfield for this game
	initStars(&mySpaceGlobals);
	
	mySpaceGlobals.invalid = 1;
		
	while (1)
	{
		VPADRead(0, &vpad_data, 1, &error);
		
		//Get the status of the gamepad
		mySpaceGlobals.button = vpad_data.btn_hold;
		
		mySpaceGlobals.rstick = vpad_data.rstick;
		mySpaceGlobals.lstick = vpad_data.lstick;
		
		mySpaceGlobals.touched = vpad_data.tpdata.touched;
		if (mySpaceGlobals.touched == 1)
		{
			mySpaceGlobals.touchX = ((vpad_data.tpdata.x / 9) - 11);
			mySpaceGlobals.touchY = ((3930 - vpad_data.tpdata.y) / 16);
		}
		
		if (mySpaceGlobals.restart == 1)
		{
			reset(&mySpaceGlobals);
			mySpaceGlobals.restart = 0;
		}
		
		if (mySpaceGlobals.state == 1) // title screen
		{
			displayTitle(&mySpaceGlobals);
			doMenuAction(&mySpaceGlobals);
		}
		else if (mySpaceGlobals.state == 2) // password screen
		{
			displayPasswordScreen(&mySpaceGlobals);
			doPasswordMenuAction(&mySpaceGlobals);
		}
		else if (mySpaceGlobals.state == 3) // pause screen
		{
			displayPause(&mySpaceGlobals);
			doMenuAction(&mySpaceGlobals);
		}
		else if  (mySpaceGlobals.state == 4) // game over screen
		{
			displayGameOver(&mySpaceGlobals);
			doMenuAction(&mySpaceGlobals);
		}
		else 	// game play
		{
			//Update location of player1 and 2 paddles
			p1Move(&mySpaceGlobals);

			// perform any shooting
			p1Shoot(&mySpaceGlobals);
			
			// handle any collisions
			handleCollisions(&mySpaceGlobals);
			
			// do explosions
			handleExplosions(&mySpaceGlobals);
			
			// if we're out of lives, break
			if (mySpaceGlobals.lives <= 0 && mySpaceGlobals.state == 4)
				continue;
			
			// add any new enemies
			addNewEnemies(&mySpaceGlobals);
			
			//Render the scene
			render(&mySpaceGlobals);
			
			// check for pausing
			checkPause(&mySpaceGlobals);
		}
		//To exit the game
		if (mySpaceGlobals.button&BUTTON_HOME)
		{
			break;
		}

	}
	cleanSlate(mySpaceGlobals.services);
	_Exit();
}