示例#1
0
文件: QPF.cpp 项目: yukta/sdl
//closing SDL systems
void close()
{
	// cleaning up spaces occupied by different objects
	
	bkg.free();
	sprite.free();
	over.free();
	starting.free();
	obj.free();
	
	// destroying rendering context and original window
	
	SDL_DestroyRenderer( renderer );
	SDL_DestroyWindow( window );
	window = NULL;
	renderer = NULL;
	 Mix_FreeMusic( music ); 
	 music = NULL;
	 Mix_FreeMusic( go );
	 go=NULL;
	
	// closing up IMG and SDL system
	
	Mix_Quit();
	IMG_Quit();
	SDL_Quit();
	
}
示例#2
0
void SpriteTestApp::setup()
{
  addAssetDirectory( getAssetPath("") / ".." / ".." / "shared_assets" );
  mSpriteSheet = SpriteSheet::load( getAssetPath("sprite_sheet.json") );
  auto sprites = mSpriteSheet->getSpriteNames();

  for( const string &name : sprites )
  { // hold for equivalent of 2 frames at 24fps
    mSpriteAnimation.addFrame( mSpriteSheet->getSpriteData(name), 2.0f / 24.0f );
  }
  mSpriteAnimation.setFrameRate( 1.0f );

  Vec2f left_center = Vec2f{ 0.25f, 0.5f } * Vec2f{ getWindowSize() };
  mSpriteAnimation.getLocus().setLoc( left_center );
  mSprite = mSpriteSheet->getSprite("wood_cracked");
  mSprite.getLocus().setLoc( left_center + Vec2f{ 0, getWindowHeight() * 0.25f } );
  mSprite.setLayer( 5 );

//  mSimpleRenderer.add( &mSpriteAnimation );
  mSimpleRenderer.add( &mSprite );
  //
  mRenderer2dStrip.add( &mSprite );
  mLastUpdate = getElapsedSeconds();

  // sort by layer
  mSimpleRenderer.sort();
  mRenderer2dStrip.sort();
}
SpriteAnimation* SpriteAnimation::create(const std::string& plist, float delay)
{
    SpriteAnimation* ret = new SpriteAnimation();
    if (ret && ret->init(plist, delay))
    {
        ret->autorelease();
        return ret;
    }
    else
    {
        delete ret;
        return nullptr;
    }
}
示例#4
0
void SpriteTestApp::draw()
{
  // clear out the window with black
  gl::clear( Color( 0, 0, 0 ) );
  gl::disable( GL_TEXTURE_2D );
  gl::drawLine( Vec2f{ getWindowWidth() / 2, 0 }, Vec2f{ getWindowWidth() / 2, getWindowHeight() } );
  mSpriteSheet->enableAndBind();
  mSimpleRenderer.render();
  mSpriteAnimation.render();
  gl::pushModelView();
  gl::translate( Vec2f{ getWindowWidth() / 2, 0.0f } );
  mRenderer2dStrip.render();
  mSpriteAnimation.render();
  gl::popModelView();
}
示例#5
0
SpriteAnimation* SpriteAnimation::create(const char* plist, bool repeat)
{
    SpriteAnimation *pRet = new SpriteAnimation();
    if (pRet && pRet->init(plist, repeat))
    {
        pRet->autorelease();
        return pRet;
    }
    else
    {
        delete pRet;
        pRet = NULL;
        return NULL;
    }
}
示例#6
0
文件: QPF.cpp 项目: yukta/sdl
//regulating bkg speed
void bkgSpriteAnimation(int speed) // moving the background
{
		// scrolling offset of background
		SpriteAnimationoff-=speed;	
	
		// reinitialization
		if(SpriteAnimationoff< -bkg.getwidth())
		SpriteAnimationoff=0;
				
		SDL_RenderClear( renderer );
		// renders background from both sides so as to give a continuity
		
		// calling rendering function
		bkg.render(SpriteAnimationoff,0);
		bkg.render(SpriteAnimationoff + bkg.getwidth(), 0);
}
示例#7
0
SpriteAnimation *ScreenSprite::addAnimation(const String& name, const String& frames, Number speed) {
	SpriteAnimation *newAnimation = new SpriteAnimation();	
	
	
	newAnimation->numFramesX = texture->getWidth() / spriteWidth;	
	newAnimation->numFramesY = texture->getHeight() / spriteHeight;
	newAnimation->spriteUVWidth = spriteUVWidth;
	newAnimation->spriteUVHeight = spriteUVHeight;
	
	newAnimation->setOffsetsFromFrameString(frames);
			
	newAnimation->speed = speed;
	newAnimation->name = name;
	animations.push_back(newAnimation);
	return newAnimation;
}
示例#8
0
void GameObject::processSpriteAnimation(int state, float time, int startCol, int startRow, int endCol, int endRow, int repeatCount, bool oppDir)
{
	//SpriteAnimation *sa;
	//sa = dynamic_cast<SpriteAnimation*>(MeshBuilder::GenerateSpriteAnimation(name, numRow, numCol, 1.f));
	//sa->textureID[0] = LoadTGA(texture_path);
	SpriteAnimation *temp;
	temp = generateSpriteMesh();
	if(temp->name == "" || temp->textureID[0] == 0)
	{
		cout << "Sprite empty" << endl;
		delete temp;
		return;
	}
	temp->init(time, startCol, startRow, endCol, endRow, repeatCount, oppDir);
	animationList[state] = temp;
}
示例#9
0
void SpriteTestApp::update()
{
  float now = getElapsedSeconds();
  float deltaTime = now - mLastUpdate;
  mLastUpdate = now;
  mSpriteAnimation.step( deltaTime );
  mSprite.getLocus().setRotation( mSprite.getLocus().getRotation() + M_PI * 0.01f );
}
示例#10
0
文件: QPF.cpp 项目: yukta/sdl
//loadig individual images
bool load()
{	
	if(!bkg.loadpng("/home/lalit/Desktop/QPF-SAproject/data/ground.jpg")) // loads background image
	{
	IMG_GetError();
	return false;
	}
	if(!sprite.loadpng("/home/lalit/Desktop/QPF-SAproject/data/cat.png")) // loads cat image
	{
	IMG_GetError();
	return false;
	}
	
	if(!starting.loadpng("/home/lalit/Desktop/QPF-SAproject/data/strt.jpg")) // loads starting image
	{
	IMG_GetError();
	return false;
	}
	
	if(!obj.loadpng("/home/lalit/Desktop/QPF-SAproject/data/obj.png")) // loads collision object image
	{
	IMG_GetError();
	return false;
	}
	
	if(!over.loadpng("/home/lalit/Desktop/QPF-SAproject/data/over.gif")) // loads end image
	{
	IMG_GetError();
	return false;
	}
	
	 music = Mix_LoadMUS( "/home/lalit/Desktop/QPF-SAproject/data/music.mp3" );
	 go = Mix_LoadMUS( "/home/lalit/Desktop/QPF-SAproject/data/go.mp3" );
	  if( music == NULL || go == NULL )
	   { 
		   cout<<Mix_GetError();
		   return false;
	  } 
	
	return true;
}
示例#11
0
void MVC_Model::Update(double dt)
{
    m_fps = static_cast<float>(1.f / dt);
    m_camera->Update(dt);

    // Empties the render lists for this update
    if (m_renderList3D.size() > 0)
    {
        throw std::runtime_error("RenderList3D leak detected!");
    }

    if (m_renderList2D.size() > 0)
    {
        throw std::runtime_error("RenderList2D leak detected!");
    }

    // Update Sprite Animations in the Mesh List
    for (std::vector<Mesh*>::iterator it = meshList.begin(); it != meshList.end(); ++it)
    {
        SpriteAnimation* sa = dynamic_cast<SpriteAnimation*>((*it));
        if (sa != NULL)
        {
            sa->Update(dt);
        }
    }

    // Update FPS Counter
    static ostringstream oss;
    oss.str("");

    oss << "FPS: " << m_fps;

    m_fpsCount->SetText(oss.str());

    // Process input
    processKeyAction(dt);
    resetKeysPressed();
}
bool SpriteAnimation::operator==(const SpriteAnimation& anim) const
{
  const std::queue<sprite_animation_frame>& a = this->getFrameQueue();
  const std::queue<sprite_animation_frame>& b = anim.getFrameQueue();
  return ( &a == &b );
}
示例#13
0
文件: QPF.cpp 项目: yukta/sdl
int main() // the main function
{

	
	int level,speed,flag;  // defining levels and speeds for game
	flag=1;
	
	cout<<"           THe Quick Pink Fox                \n\n\n";
	cout<<"          Please choose a Level             \n";
	cout<<"                1 : Easy                     \n";
	cout<<"                2 : Medium                    \n";
	cout<<"                3 : Difficult                  \n";
	cin>>level; 
	
	if(level == 1)
	{
	speed = 8; // sets scrolling to 8
	}
	
	else if(level==2)
	{
	speed = 11; // sets scrolling to 11
	}
	
	else if(level==3)
	{
	speed=14; //sets scrolling to 14
	}
	
	else
	{
	cout<<"Wrong Input....";
	flag=0;
	}
	
	if(flag)
	{
	if(init()) // if init function returs true
	{
		if(load()) // if all surfaces have been loaded successfully
			{
				
				 if( Mix_PlayingMusic() == 0 )
				  {
					   //Play the music 
					   Mix_PlayMusic( music, -1 ); 
					}
				
				//loading the game image
				starting.GameLoads();	
					 
				sprite.classification(); // classification of the image sprite
				int ind=0; // the current index in within the catRect array
				
				
				bool gameover =false;
				SDL_Event e; // SDL Event
			
				while(!gameover)
				{
					while( SDL_PollEvent( &e ) != 0 )
				{
					
					//checks if the user gave a cross input
					if( e.type == SDL_QUIT)
					{
						gameover = true;
					}
					}// end of pollevent
	
	
	const Uint8 *keys = SDL_GetKeyboardState(NULL); // getting into pointers to the input key		
							
	// checking if shift is pressed
	if (keys[SDL_SCANCODE_LSHIFT] || keys[SDL_SCANCODE_RSHIFT]) 
	{
	//boosting up the speed
	bkgSpriteAnimation(speed + 5); // moves up the background
	size=5;
	obj.velocity=-(speed + 5);
	}
	
	else  
	{
	// normal speed
	bkgSpriteAnimation(speed);
	size=9;
	obj.velocity=-speed;
	}			
			
	obj.move(); // moving the hurdle 
	
	if(e.key.repeat == 0 && keys[SDL_SCANCODE_UP] )
    {		
				// if the pressed button is 'up'
				SDL_Rect* clip =&CatRect[0];
				
				// reducing the value of height
				sprite.catrender((w-550)/2 , (h)/2 , clip);
				
				//presenting the rendered context
				SDL_RenderPresent(renderer);

                ind=0;
                				
				// calling the CollDet function
				if(CollDet((h+50)/2))
				{ 
					
				SDL_Delay(1500);
				Mix_HaltMusic();
				
				if( Mix_PlayingMusic() == 0 )
   			    {
				   Mix_PlayMusic( go, -1 ); 
				}
				
				over.gameover();
				SDL_Delay(2000);
				Mix_HaltMusic();
				break;
				}
	   } 
	           
    
    else 
    {   
		 SDL_Rect* clip =&CatRect[ind/size];
	     sprite.catrender((w-550)/2 , (h+250)/2 , clip); 
	     SDL_RenderPresent(renderer);
		if(CollDet((h+250)/2))
		{
			SDL_Delay(2000);
			Mix_HaltMusic();
			
			if( Mix_PlayingMusic() == 0 )
   			    {
				   Mix_PlayMusic( go, -1 ); 
				}
				
			over.gameover();
			SDL_Delay(2000);
			Mix_HaltMusic();
			break;
		}
	}
				++ ind; // incrementing ind for next sprite 
			
				if(ind/size >=8 ) // bringing ind to start
				ind=0;	
			
				
				} // end of gameover 
			} // end of load
	}// end of init loop
	
	
	close();
	
	checkscore();
	} // end of if
	return 0; 
}