//---------------------------------------------------------------------
    void
    BackgroundFileSerializer::removeBuggySprites( SpriteList &sprites )
    {
        auto it = sprites.begin();
        while (it != sprites.end())
        {
            const SpriteData &sprite = (*it);

            if (std::abs(sprite.dst.x) > SPRITE_DST_MAX
                    || std::abs(sprite.dst.y) > SPRITE_DST_MAX)
            {
                it = sprites.erase(it);
            }
            else
            {
                ++it;
            }
        }
    }
Beispiel #2
0
void SpriteHolder::DrawSprites(){
	SpriteList * result = new SpriteList();
	for (int i = 0; i <= spritetype_t::UI; i++){
		
		GetSprites((spritetype_t)i, result);
		for (std::list<Sprite *>::iterator it = result->begin(); it != result->end(); ++it){
			Sprite * s = (*it);
			spritestate_t state = s->GetState();

			if (state == spritestate_t::ALIVE){
				s->Draw();
			}
			else if (state == spritestate_t::DEAD) {
				if (s->GetType() != spritetype_t::PLAYER) LatelyDestroyable::Add(s);
				s->SetState(spritestate_t::WAIT);
			}
		}
	}
	delete result;
}
Beispiel #3
0
	void NewNugget(int num = 1)
	{
		for (int i=0; i<num; ++i)
		{
			int gx = rand() % 500 + 100;
			int gy = rand() % 300 + 100;

			Sprite &gspr = sprite_list.GetSprite("gold");
			Object * nug = new GoldObject(gx, gy, gspr);

			world.AddObject(nug);
		}
	}
Beispiel #4
0
void Sprite::getScaledSpriteBuffer(SpriteList &spriteList, uint spriteNumber, int scale, int &width, int &height, int &xAlign, int &yAlign, const byte *&buffer) {
	SpriteInfo *spriteInfo;

	if (spriteList.size() <= spriteNumber) {
		// this can occur in IHNM while loading a saved game from chapter 1-5 when being in the end chapter
		warning("spriteList.size() <= spriteNumber");
		return;
	}

	spriteInfo = &spriteList[spriteNumber];

	if (scale < 256) {
		xAlign = (spriteInfo->xAlign * scale) >> 8; //TODO: do we need to take in account sprite x&y aligns ?
		yAlign = (spriteInfo->yAlign * scale) >> 8; // ????
		height = (spriteInfo->height * scale + 0x7f) >> 8;
		width = (spriteInfo->width * scale + 0x7f) >> 8;
		size_t outLength = width * height;
		if (outLength > 0) {
			scaleBuffer(&spriteInfo->decodedBuffer.front(), spriteInfo->width, spriteInfo->height, scale, outLength);
			buffer = &_decodeBuf.front();
		} else {
			buffer = NULL;
		}
	} else {
Beispiel #5
0
int main ()
{
  printf ("Results of sprite1_test:\n");
  
  try
  {
    Test test (L"Sprite 1", true);

    RenderManager render_manager = test.RenderManager ();
        
    render_manager.LoadResource ("data/sprites.rfx");    
    render_manager.LoadResource ("data/bottom.jpg");
    render_manager.LoadResource ("data/sprites.xmtl");
    
    Entity     entity    = render_manager.CreateEntity ();
    Primitive  primitive = render_manager.CreatePrimitive ();
//    SpriteList sprites   = primitive.AddStandaloneSpriteList (SpriteMode_Oriented, math::vec3f (0, 1.0f, 0));
//    SpriteList sprites   = primitive.AddStandaloneSpriteList (SpriteMode_Billboard, math::vec3f (0, 1.0f, 0));
//    SpriteList sprites   = primitive.AddBatchingSpriteList (SpriteMode_Oriented, math::vec3f (0, 1.0f, 0));
    SpriteList sprites   = primitive.AddBatchingSpriteList (SpriteMode_Oriented, math::vec3f (0, 1.0f, 0));
    Sprite     sprite;

    primitive.Buffers ().ReserveDynamicBuffers (8192, 8192);

    entity.SetWorldScissor (Box (math::vec3f (0.0f), math::vec3f (1.0f)));
    entity.EnableScissor ();

    sprite.position   = math::vec3f (0.0f);
    sprite.size       = math::vec2f (1.0f);
    sprite.color      = math::vec4f (1.0f);
    sprite.tex_offset = math::vec2f (0.0f);
    sprite.tex_size   = math::vec2f (1.0f);
    sprite.normal     = math::vec3f (0, 0, 1.0f);
    sprite.rotation   = math::anglef ();

    sprites.SetMaterial ("sprite");
    sprites.Add (1, &sprite);

    entity.SetPrimitive (primitive);

    entity.SetWorldMatrix (math::rotate (math::degree (45.0f), math::vec3f (0, 0, 1)));
    
    Frame frame = render_manager.CreateFrame ();

    frame.DisableAutoCleanup ();
    frame.SetRenderTarget ("main_color_target", test.Window ().ColorBuffer ());
    frame.SetRenderTarget ("main_depth_stencil_target", test.Window ().DepthStencilBuffer ());
    frame.SetEffect ("main");
    frame.SetClearColor (math::vec4f (0.0f, 0.0f, 1.0f, 1.0f));
    frame.SetEntityDrawHandler (&update_entity_frame_transformations);

    common::PropertyMap entity_dependent_properties;

    frame.SetEntityDependentProperties (entity_dependent_properties);

    entity_dependent_properties.SetProperty ("myObjectMatrix", math::mat4f (1.0f));
    
    common::PropertyMap frame_properties = frame.Properties ();
    common::PropertyMap entity_properties = entity.Properties ();
    
    frame_properties.SetProperty ("myProjMatrix", get_ortho_proj (-2, 2, -2, 2, -15, 15));
    frame_properties.SetProperty ("myViewMatrix", inverse (math::lookat (math::vec3f (0, 0, 10), math::vec3f (0.0f), math::vec3f (0, 1, 0))));

    frame.SetViewProjectionMatrix (frame_properties.GetMatrix ("myProjMatrix") * frame_properties.GetMatrix ("myViewMatrix"));
    
    frame.AddEntity (entity); 
    
    test.ShowWindow ();
    
    syslib::Application::RegisterEventHandler (syslib::ApplicationEvent_OnIdle, xtl::bind (&idle, xtl::ref (test), xtl::ref (entity), xtl::ref (frame)));
            
    return test.Run ();
  }
  catch (std::exception& e)
  {
    printf ("%s\n", e.what ());
  }

  return 0;
}
Beispiel #6
0
Level::Level( int which ) {
	Starfield starfield( 350 );
	Hud hud;
	Timer *timer = Timer::Instance();
	Video *video = Video::Instance();
	SpriteList *spriteList = SpriteList::Instance();
	Ship *player = new Ship(); // the player sprite
	bool quit = false;
	SDL_Event event;

	camera = Camera::Instance();

	camera->Follow( player );

	player->UseAI( false );
	player->IsPlayer( true );

	player->SetThrust( 5. );
	
	// add player
	spriteList->Add( player );

	Ship *test = new Ship( 15, 15 );
	
	spriteList->Add( test );

	if( SDL_Init( SDL_INIT_JOYSTICK ) != 0 )
		cout << "massive joystick error" << endl; // move to an input class

	timer->Reset();
	
	hud.Message( HUD_MSG_COMMAND, "Good morning, pilot." );
	
	while( !quit ) {
		// erase
		video->Blank();

		// update
		// get user input
		while( SDL_PollEvent( &event ) ) {
			switch( event.type ) {
				case SDL_QUIT:
					quit = true;
					break;
				case SDL_JOYAXISMOTION:
					cout << "joystick motion!" << endl;
					if(event.jaxis.which == 0)
						player->Turn( (float)-20 * 0.15f );
					break;
				case SDL_KEYDOWN:
					switch( event.key.keysym.sym ) {
						case SDLK_ESCAPE:
							quit = true;
							break;
						case SDLK_w:
							player->ThrottleUp();
							break;
						case SDLK_s:
							player->ThrottleDown();
							break;
						default:
							break;
					}
					break;
				case SDL_MOUSEMOTION:
					if(( event.motion.xrel ) && ( event.motion.xrel != 160 )) {
						if( abs(event.motion.xrel) > 20 )
							if(event.motion.xrel < 0)
								player->Turn( (float)-20 * 0.15f );
							else
								player->Turn( (float)20 * 0.15f );
						else
							player->Turn( (float)event.motion.xrel * 0.15f );
					}
					break;
				case SDL_MOUSEBUTTONDOWN:
					if( event.button.button == 1) player->Fire();
					if( event.button.button == 4) player->ThrottleUp();
					if( event.button.button == 5) player->ThrottleDown();
					break;
				default:
					break;
			}
		}

		for( int n = timer->GetLoops(); n ; --n ) {
			// update various systems
			camera->Update();
			starfield.Update();
			spriteList->Update();
			hud.Update();
		}

		// draw
		starfield.Draw();
		spriteList->Draw();
		hud.Draw();

		video->Update();

		timer->Delay();
	}
}
Beispiel #7
0
void Sprite::loadList(int resourceId, SpriteList &spriteList) {
	SpriteInfo *spriteInfo;
	ByteArray spriteListData;
	uint16 oldSpriteCount;
	uint16 newSpriteCount;
	uint16 spriteCount;
	uint i;
	int outputLength, inputLength;
	uint32 offset;
	const byte *spritePointer;
	const byte *spriteDataPointer;

	_vm->_resource->loadResource(_spriteContext, resourceId, spriteListData);

	if (spriteListData.empty()) {
		return;
	}

	ByteArrayReadStreamEndian readS(spriteListData, _spriteContext->isBigEndian());

	spriteCount = readS.readUint16();

	debug(9, "Sprites: %d", spriteCount);

	oldSpriteCount = spriteList.size();
	newSpriteCount = oldSpriteCount + spriteCount;

	spriteList.resize(newSpriteCount);

	bool bigHeader = _vm->getGameId() == GID_IHNM || _vm->isMacResources();

	for (i = oldSpriteCount; i < spriteList.size(); i++) {
		spriteInfo = &spriteList[i];
		if (bigHeader)
			offset = readS.readUint32();
		else
			offset = readS.readUint16();

		if (offset >= spriteListData.size()) {
			// ITE Mac demos throw this warning
			warning("Sprite::loadList offset exceeded");
			spriteList.resize(i);
			return;
		}

		spritePointer = spriteListData.getBuffer();
		spritePointer += offset;

		if (bigHeader) {
			Common::MemoryReadStreamEndian readS2(spritePointer, 8, _spriteContext->isBigEndian());

			spriteInfo->xAlign = readS2.readSint16();
			spriteInfo->yAlign = readS2.readSint16();

			spriteInfo->width = readS2.readUint16();
			spriteInfo->height = readS2.readUint16();

			spriteDataPointer = spritePointer + readS2.pos();
		} else {
			Common::MemoryReadStreamEndian readS2(spritePointer, 4, false);

			spriteInfo->xAlign = readS2.readSByte();
			spriteInfo->yAlign = readS2.readSByte();

			spriteInfo->width = readS2.readByte();
			spriteInfo->height = readS2.readByte();
			spriteDataPointer = spritePointer + readS2.pos();
		}

		outputLength = spriteInfo->width * spriteInfo->height;
		inputLength = spriteListData.size() - (spriteDataPointer - spriteListData.getBuffer());
		spriteInfo->decodedBuffer.resize(outputLength);
		if (outputLength > 0) {
			decodeRLEBuffer(spriteDataPointer, inputLength, outputLength);
			byte *dst = &spriteInfo->decodedBuffer.front();
#ifdef ENABLE_IHNM
			// IHNM sprites are upside-down, for reasons which i can only
			// assume are perverse. To simplify things, flip them now. Not
			// at drawing time.

			if (_vm->getGameId() == GID_IHNM) {
				byte *src = &_decodeBuf[spriteInfo->width * (spriteInfo->height - 1)];

				for (int j = 0; j < spriteInfo->height; j++) {
					memcpy(dst, src, spriteInfo->width);
					src -= spriteInfo->width;
					dst += spriteInfo->width;
				}
			} else
#endif
				memcpy(dst, &_decodeBuf.front(), outputLength);
		}
	}
}
Beispiel #8
0
void SpriteHolder::Add(Sprite* s){
	sprites[s->GetType()].push_back(s);

	SpriteList * list = new SpriteList();
	switch (s->GetType()){
	case spritetype_t::PLAYER:
		GetSprites(spritetype_t::ENEMY_BULLET, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		GetSprites(spritetype_t::ENEMY, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		break;
	case spritetype_t::PLAYER_BULLET:
		GetSprites(spritetype_t::ENEMY, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		break;
	case spritetype_t::ENEMY:
		GetSprites(spritetype_t::PLAYER, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		GetSprites(spritetype_t::PLAYER_BULLET, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		break;
	case spritetype_t::ENEMY_BULLET:
		GetSprites(spritetype_t::PLAYER, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		break;
	case spritetype_t::POWER_UP:
		GetSprites(spritetype_t::PLAYER, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it) {
			CollisionChecker::Get().Register(s, *it);
		}
		break;
	default:
		break;
	}
	delete list;
}
Beispiel #9
0
	static ShotIterator WPN_RemoveShot(ShotIterator shot, SpriteList& spriteList)
	{
		spriteList.removeSprite(shot->getSprite());
		return d6Shots.erase(shot);
	}
Beispiel #10
0
	void WPN_AddShot(Player& player, SpriteList& spriteList, Orientation orientation)
	{
		Sprite shotSprite(player.getWeapon().shotAnimation, player.getWeapon().textures.shot);
		d6Shots.push_back(Shot(player, spriteList.addSprite(shotSprite), orientation));
		player.getWeapon().shotSample.play();
	}
void Effect07::Init() 
{
	// calculate sprites
	int nrSprites = 0;

	for (int i = 0; i < 125; i++)
	{
		if (oyiseer[i]) nrSprites++;
	}

	for (int i = 0; i < 55; i++)
	{
		if (rob[i]) nrSprites++;
	}

	for (int i = 0; i < 135; i++)
	{
		if (zabutom[i]) nrSprites++;
	}

	// create a new scene

	float offset[3] = {1.15f, 0.25f, -0.65f};

	scene = new Scene();	

	SpriteList* spriteList = new SpriteList(nrSprites, 0.1f, textureLoader->GetTexture("credits"), BLEND_ALPHA);

	int index = 0;

	// oyiseer
	for (int y = 0; y < 5; y++)
	{
		for (int x = 0; x < 25; x++)
		{
			if (oyiseer[(y * 25) + x])
			{
				spriteList->sprite[index].x = ((-25 / 2.f) + x) * 0.1f;
				spriteList->sprite[index].y = (y * -0.1f) + offset[1];
				spriteList->sprite[index].z = 0;

				index++;
			}
		}
	}

	// rob
	for (int y = 0; y < 5; y++)
	{
		for (int x = 0; x < 11; x++)
		{
			if (rob[(y * 11) + x])
			{
				spriteList->sprite[index].x = ((-11 / 2.f) + x) * 0.1f;
				spriteList->sprite[index].y = (y * -0.1f) + offset[0];
				spriteList->sprite[index].z = 0;

				index++;
			}
		}
	}

	// zabotum
	for (int y = 0; y < 5; y++)
	{
		for (int x = 0; x < 27; x++)
		{
			if (zabutom[(y * 27) + x])
			{
				spriteList->sprite[index].x = ((-27 / 2.f) + x) * 0.1f;
				spriteList->sprite[index].y = (y * -0.1f) + offset[2];
				spriteList->sprite[index].z = 0;

				index++;
			}
		}
	}

	spriteList->Finish(true);

	fx07Centers = new Vector[spriteList->nrSprites];
	fx07Directions = new Vector[spriteList->nrSprites];

	srand(456);

	for (int i = 0; i < spriteList->nrSprites; i++)
	{
		fx07Centers[i].x = spriteList->sprite[i].x;
		fx07Centers[i].y = spriteList->sprite[i].y;

		float period = rand() % 1000;

		fx07Directions[i].x = sin((period / 1000.f) * _2PI) * 1.f;
		fx07Directions[i].y = cos((period / 1000.f) * _2PI) * 1.f;
	}

	scene->AddSpriteList(spriteList);
}