コード例 #1
0
void UniversalArrangeCMPT::GetPhysicsStaticVisitor::
visit(Object* object, bool& bFetchNext)
{
	ISprite* sprite = static_cast<ISprite*>(object);
	if (!sprite->getBody())
	{
		bFetchNext = true;
		return;
	}

	b2Body* body = sprite->getBody()->getBody();
	if (m_type == e_uncertain)
	{
		m_type = (body->GetType() == b2_staticBody) ? e_checked : e_unchecked;
		bFetchNext = true;
	}
	else if ((m_type == e_unchecked && body->GetType() == b2_staticBody)
		|| (m_type == e_checked && body->GetType() != b2_staticBody))
	{
		m_type = e_uncertain;
		bFetchNext = false;
	}
	else
	{
		bFetchNext = true;
	}
}
コード例 #2
0
ファイル: ArrangeSpriteOP.cpp プロジェクト: bigstupidx/drag2d
	void ArrangeSpriteOP<TBase>::TranslateVisitor::
		visit(ICloneable* object, bool& bFetchNext)
	{
		ISprite* sprite = static_cast<ISprite*>(object);
		sprite->translate(m_delta);
		bFetchNext = true;
	}
コード例 #3
0
///<summary>
/// Handles the situation if a sprite dies due to collision with a projectile
///</summary>
void ProjectileMethodsHandleIfSpriteDead(ISprite &sprite, ProjectileWeaponInfo &weaponInfo)
{
	// If the player killed this sprite, drop a power up
	// If a tower killed this sprite, then add experience to that tower
	if ((sprite.getHealth() <= 0.0f) && (sprite.getHealth() >= -100.0f))
	{

		if (weaponInfo.triggeredByType == TOWER_SPRITE)
		{
			// Only increase experience randomly, so that it has a chance to go down
			// and provides a random element :D
			if(rand() % 3 != 0)
			{
				if(weaponInfo.WeaponExperiencePoints < weaponInfo.MaxWeaponExperiencePoints)
				{
					weaponInfo.WeaponExperiencePoints += 7.0f;
				}
			}
		}
		else
		{
			// This is the kind of power up created by our gun...
			SPRITE_POWER_UP powerUpType = (SPRITE_POWER_UP) (rand() % POWER_UP_GUN_LARGE);
			sprite.setPowerUpType(powerUpType);
		}
		sprite.setHealth(-200);

	}
}
コード例 #4
0
ファイル: Renderer.cpp プロジェクト: Niblitlvl50/Mono1
void Renderer::DrawSprite(const ISprite& sprite, const math::Vector& offset) const
{
    const mono::ITexturePtr texture = sprite.GetTexture();
    const SpriteFrame& current_frame = sprite.GetCurrentFrame();
    UseShader(m_texture_shader.get());
    m_texture_shader->SetShade(sprite.GetShade());
    DrawSprite(current_frame.texture_coordinates, current_frame.size, current_frame.center_offset + offset, texture);
}
コード例 #5
0
void UniversalArrangeCMPT::SetPhysicsStaticVisitor::
visit(Object* object, bool& bFetchNext)
{
	ISprite* sprite = static_cast<ISprite*>(object);
	if (sprite->getBody())
		sprite->getBody()->getBody()->SetType(m_bChecked ? b2_staticBody : b2_dynamicBody);

	bFetchNext = true;
}
コード例 #6
0
ファイル: ArrangeSpriteOP.cpp プロジェクト: bigstupidx/drag2d
	void ArrangeSpriteOP<TBase>::RotateVisitor::
		visit(ICloneable* object, bool& bFetchNext)
	{
		ISprite* sprite = static_cast<ISprite*>(object);

		float angle = Math::getAngleInDirection(sprite->getPosition(), m_start, m_end);
		sprite->rotate(angle);

		bFetchNext = false;
	}
コード例 #7
0
	bool OnSetupSample()
	{
		mainLight = mMainScene->createLight( nullptr );
		mainLight->setName( "mainLight" );
		mainLight->translate( CFTO_LOCAL , Vector3(0,0,20) );
		mainLight->setLightColor( ColorKey(1,1,1) );

		sprite = mMainScene->createSprite( nullptr );
		sprite->setRectArea( nullptr , 64 , 64  , "Spell_Fire_FlameShock" , 0 , nullptr , false , 0 , 0 , 0 , CF_FILTER_POINT );
		sprite->setRectPosition( Vector3(0,0,0) );

		sprite->setRenderOption( CFRO_ALPHA_BLENGING , TRUE );
		sprite->setRenderOption( CFRO_SRC_BLEND , CF_BLEND_SRC_ALPHA );
		sprite->setRenderOption( CFRO_DEST_BLEND , CF_BLEND_INV_SRC_ALPHA );
		return true; 
	}
コード例 #8
0
ファイル: PasteSymbolOP.cpp プロジェクト: jjiezheng/drag2d
bool PasteSymbolOP::onMouseLeftDown(int x, int y)
{
	if (ZoomViewOP::onMouseLeftDown(x, y)) return true;

	ISymbol* symbol = m_libraryPanel->getSymbol();
	if (symbol)
	{
		m_pos = m_editPanel->transPosScreenToProject(x, y);
		ISprite* sprite = SpriteFactory::Instance()->create(symbol);
		sprite->translate(m_pos);
		if (m_pScale)
			sprite->setScale(*m_pScale);
		m_panelImpl->insertSprite(sprite);
		sprite->release();
	}

	return false;
}
コード例 #9
0
///<summary>
/// Handles projection collisions with other sprites...
///</summary>			
void ProjectileShot::handleSpriteCollisions(LevelInfo *levelInfo, ISprite &sprite, IAudio *soundToPlay, float projectileDamage)
{
	LevelMethodCollisionSet collisionSet;
	std::vector<SpriteBullet>::iterator spriteIterator = myWeaponInfo.Projectiles.begin();
	for(int idx = 0; idx < myWeaponInfo.CurrentMaxProjectiles; idx++)
	{		
		// Handle all the controls and inputs for our baddie sprites!
		if(spriteIterator->isDead() == false)		
		{		
			if(spriteIterator->getLocation().z >= (spriteIterator->getWaterLevel() - 1.0f))
			{
				collisionSet = LevelMethodsCheckCollisionSet(myWeaponInfo.Projectiles.at(idx), sprite);
				if((collisionSet.collisionABIntersects == true) || (collisionSet.collisionACIntersects == true) || (collisionSet.collisionBCIntersects == true))
				{																
					if ((sprite.getCurrentAnimation() != DEATH_FALLBACKSLOW) && (sprite.getCurrentAnimation() != DEATH_FALLBACK)
							&& (sprite.getCurrentAnimation() != DEATH_FALLFORWARD))
					{
						LevelMethodsHandleSparkEffects(levelInfo, &myWeaponInfo.Projectiles.at(idx), 1);
						// If the sprite isn't dying, collide with the sucka...
						// If it's not in pain, play the hurty sound, and modify their health...
						// If we hit both A and B handle a front collision (change movement by 180 degrees)
						if(collisionSet.collisionABIntersects == true)
						{			
							spriteIterator->handleCollision(FRONT_ATTACK, 7.0f);
							spriteIterator->setJump(JUMP_STATE_READY);
						}
						// If we hit both A and C handle a rear left collision (change movement by 45 degrees)
						if(collisionSet.collisionACIntersects == true)
						{
							spriteIterator->handleCollision(LEFT_SIDE_ATTACK, 7.0f);
							spriteIterator->setJump(JUMP_STATE_READY);
						}
						// If we hit both B and C handle a rear right collision (change movement by 315 degrees)
						if(collisionSet.collisionBCIntersects == true)
						{
							spriteIterator->handleCollision(RIGHT_SIDE_ATTACK, 7.0f);
							spriteIterator->setJump(JUMP_STATE_READY);
						}					

						if((sprite.getCurrentAnimation() != PAIN_A)	&& (sprite.getCurrentAnimation() != PAIN_B)
							&& (sprite.getCurrentAnimation() != PAIN_C))
						{						
							soundToPlay->playOnce();																						
						}
						sprite.modifyHealthBy(-projectileDamage);

					}

					ProjectileMethodsHandleIfSpriteDead(sprite, myWeaponInfo);

				}			
			}
		}
		spriteIterator++;
	}
}
コード例 #10
0
bool SpritesPanelImpl::DragSymbolTarget::
OnDropText(wxCoord x, wxCoord y, const wxString& data)
{
	wxString sType = data.substr(0, data.find(","));
	wxString sIndex = data.substr(data.find(",") + 1);

	long index;
	sIndex.ToLong(&index);

	ISymbol* symbol = m_panelImpl->m_libraryPanel->getSymbol(index);
	if (symbol)
	{
		Vector pos = m_panelImpl->m_editPanel->transPosScreenToProject(x, y);
		ISprite* sprite = SpriteFactory::create(symbol);
		sprite->translate(pos);
		m_panelImpl->insertSprite(sprite);
		sprite->release();
	}

	return true;
}
コード例 #11
0
bool PasteSymbolRandomOP::onMouseLeftDown(int x, int y)
{
	if (ZoomViewOP::onMouseLeftDown(x, y)) return true;

	ISymbol* symbol = m_randomValue.symbol;
	if (!symbol) 
		symbol = m_libraryPanel->getSymbol();
	if (symbol) 
	{
		m_pos = m_editPanel->transPosScreenToProject(x, y);
		ISprite* sprite = SpriteFactory::Instance()->create(symbol);
		sprite->translate(m_pos);
		if (m_randomValue.scale != 1.0f) 
			sprite->setScale(m_randomValue.scale);
		if (m_randomValue.angle != 0.0f) 
			sprite->setTransform(m_pos, m_randomValue.angle);
		m_panelImpl->insertSprite(sprite);
		sprite->release();
	}

	changeRandomValue();

	return false;
}
コード例 #12
0
void CombinationSymbol::loadResources()
{
	CombinationFileAdapter adapter;
	adapter.load(m_filepath.c_str());

	for (size_t i = 0, n = adapter.m_data.size(); i < n; ++i)
	{
		ISprite* sprite = NULL;

		const CombinationFileAdapter::Entry& entry = adapter.m_data[i];
		ISymbol* symbol = SymbolMgr::Instance()->getSymbol(entry.filepath);
		sprite = SpriteFactory::Instance()->create(symbol);

		sprite->setTransform(entry.pos, entry.angle);
		sprite->setScale(entry.scale);
		sprite->setMirror(entry.xMirror, entry.yMirror);

		m_sprites.push_back(sprite);
	}

//	moveToCenter();

	initBounding();
}
コード例 #13
0
ファイル: Example.cpp プロジェクト: JohanKallberg/DiceInvader
int APIENTRY WinMain(
	HINSTANCE instance,
	HINSTANCE previousInstance,
	LPSTR commandLine,
	int commandShow)
{
	DiceInvadersLib lib("DiceInvaders.dll");
	IDiceInvaders* system = lib.get();

	system->init(640, 480);

	ISprite* sprite = system->createSprite("data/player.bmp");

	float horizontalPosition = 320;
	float lastTime = system->getElapsedTime();
	while (system->update())
	{
		sprite->draw(int(horizontalPosition), 480-32);

		float newTime = system->getElapsedTime();
		float move = (newTime - lastTime) * 160.0f;
		lastTime = newTime;
		
		IDiceInvaders::KeyStatus keys;
		system->getKeyStatus(keys);
		if (keys.right)
			horizontalPosition += move;
		else if (keys.left)
			horizontalPosition -= move;
	}

	sprite->destroy();
	system->destroy();

	return 0;
}
コード例 #14
0
ファイル: ArrangeSpriteOP.cpp プロジェクト: bigstupidx/drag2d
	void ArrangeSpriteOP<TBase>::autoAlign(const std::vector<ISprite*>& sprites)
	{
		m_autoAlignHor[0].set(0, 0);
		m_autoAlignHor[1].set(0, 0);
		m_autoAlignVer[0].set(0, 0);
		m_autoAlignVer[1].set(0, 0);

		std::vector<ISprite*> sources;
		m_spritesImpl->traverseSprites(FetchAllVisitor<ISprite>(sources));

		// not support multi src now
		if (sprites.size() > 1)
			return;

		const float DIS = 5;

		ISprite *horNearest = NULL, *verNearest = NULL;
		float disHor = DIS, disVer = DIS;
		// hor
		for (size_t i = 0, n = sources.size(); i < n; ++i)
		{
			ISprite *dst = sprites[0], *src = sources[i];

			if (src == dst) continue;

			const float srcHalfHeight = src->getBounding()->height() * 0.5f;
			const float dstHalfHeight = dst->getBounding()->height() * 0.5f;

			float srcDown = src->getPosition().y - srcHalfHeight;
			float srcUp = src->getPosition().y + srcHalfHeight;

			float dstDown = dst->getPosition().y - dstHalfHeight;
			float dstUp = dst->getPosition().y + dstHalfHeight;

			// up
			if (float dis = fabs(dstUp - srcUp) < disHor)
			{
				disHor = dis;
				horNearest = src;
			}
			else if (float dis = fabs(dstUp - srcDown) < disHor)
			{
				disHor = dis;
				horNearest = src;
			}
			// down
			if (float dis = fabs(dstDown - srcUp) < disHor)
			{
				disHor = dis;
				horNearest = src;
			}
			else if (float dis = fabs(dstDown - srcDown) < disHor)
			{
				disHor = dis;
				horNearest = src;
			}	
		}
		// ver
		for (size_t i = 0, n = sources.size(); i < n; ++i)
		{
			ISprite *dst = sprites[0], *src = sources[i];

			if (src == dst) continue;

			const float srcHalfWidth = src->getBounding()->width() * 0.5f;
			const float dstHalfWidth = dst->getBounding()->width() * 0.5f;

			float srcLeft = src->getPosition().x - srcHalfWidth;
			float srcRight = src->getPosition().x + srcHalfWidth;

			float dstLeft = dst->getPosition().x - dstHalfWidth;
			float dstRight = dst->getPosition().x + dstHalfWidth;

			// left
			if (float dis = fabs(dstLeft - srcLeft) < disVer)
			{
				disVer = dis;
				verNearest = src;
			}
			else if (float dis = fabs(dstLeft - srcRight) < disVer)
			{
				disVer = dis;
				verNearest = src;
			}
			// right
			if (float dis = fabs(dstRight - srcLeft) < disVer)
			{
				disVer = dis;
				verNearest = src;
			}
			else if (float dis = fabs(dstRight - srcRight) < disVer)
			{
				disVer = dis;
				verNearest = src;
			}
		}

		//////////////////////////////////////////////////////////////////////////

		if (horNearest)
			autoAlign(horNearest, sprites[0]);
		if (verNearest && verNearest != horNearest)
			autoAlign(verNearest, sprites[0]);

		//////////////////////////////////////////////////////////////////////////

// 		for (size_t i = 0, n = sprites.size(); i < n; ++i)
// 		{
// 			for (size_t j = 0, m = sources.size(); j < m; ++j)
// 			{
// 				if (sprites[i] != sources[j])
// 					autoAlign(sources[j], sprites[i]);
// 			}
// 		}
	}
コード例 #15
0
int APIENTRY WinMain(
	HINSTANCE instance,
	HINSTANCE previousInstance,
	LPSTR commandLine,
	int commandShow)
{
	DiceInvadersLib lib("DiceInvaders.dll");
	IDiceInvaders* system = lib.get();
	static int screenX = 640;
	static int screenY = 480;
	system->init(screenX, screenY);

	ISprite* sprite = system->createSprite("data/player.bmp");
	ISprite* rocket = system->createSprite("data/rocket.bmp");
	ISprite* alien1 = system->createSprite("data/enemy1.bmp");
	ISprite* alien2 = system->createSprite("data/enemy2.bmp");
	ISprite* bomb = system->createSprite("data/bomb.bmp");
	
	//initiate player
	Vec2f playerPos = Vec2f(screenX / 2, screenY - 32);
	float lastTime = system->getElapsedTime();
	std::vector<Vec2f> rocketPos;
	static int maxNbrRockets = 6;

	//initiate alienArmy
	int aliensRow = 8;
	int aliensCol =2;
	std::vector<Vec2f> alienPos;
	std::vector<Alien> aliens;
	for (int i = 0; i < aliensCol; i++){
		for (int j = 0; j < aliensRow; j++){
			alienPos.push_back(Vec2f(j * 64, i * 64));
		}
	}
	CreateArmy(aliens,*alien1,*alien2);
	int rightAlien = alienPos.size() - 1;
	int leftAlien = 0;
	float alienDirection = 1.0f;
	Vec2f alienMovement = Vec2f(0,0);
	

	//int nbrBombs = 0;
	std::vector<Vec2f> bombPos;
	static int maxNbrBombs = 6;
	int lives = 3;

	float lastRocketFireTime = lastTime;
	while (system->update())
	{

		
		//draw everything
		//lives
		system->drawText(screenX - 142, 8, "Lives: ");
		for (int i = 1;i <= lives; i++){
			sprite->draw(screenX - i * 32, 0);
		}
		//player
		sprite->draw(int(playerPos.x), int(playerPos.y));
		for (int i = 0; i < rocketPos.size(); i++){
			rocket->draw(int(rocketPos[i].x), int(rocketPos[i].y));
		}
		//alien1->draw(screenX - 32, screenY - 32);
		for (int i = 0; i < alienPos.size(); i++){
			
			alien1->draw(int(alienPos[i].x), int(alienPos[i].y));
		}
		for (int i = 0; i < bombPos.size(); i++){
			bomb->draw(int(bombPos[i].x), bombPos[i].y);
		}
		//get player movement
		float newTime = system->getElapsedTime();
		float move = (newTime - lastTime) * 160.0f;
		float alienSpeed = (newTime - lastTime) * 120.0f;
		lastTime = newTime;
		IDiceInvaders::KeyStatus keys;
		system->getKeyStatus(keys);
		if (keys.right){
			if (playerPos.x + move + 32 <= screenX)
				playerPos.x += move;
		}
		else if (keys.left){
			if (playerPos.x - move >= 0)
				playerPos.x -= move;
		}

		//move rockets (before instantiating new ones)
		for (int i = 0; i < rocketPos.size(); i++){
			rocketPos[i].y -= move;
			if (rocketPos[i].y < 0){//remove the rocket outside screen
				rocketPos.erase(rocketPos.begin() + i);
			}

		}
		if (keys.fire&&rocketPos.size() < maxNbrRockets){
			if (lastRocketFireTime + 0.5f < newTime){
				lastRocketFireTime = newTime;
					rocketPos.push_back(Vec2f(playerPos.x, playerPos.y - 32));
			}
		}


		//calculate alien movement
		if (alienPos[alienPos.size() - 1].x + 32 >= screenX&&alienDirection == 1.0f){
			alienDirection = -1.0f;
			alienMovement = Vec2f(-alienSpeed, 32.0f);
		}
		else if (alienPos[leftAlien].x <= 0 && alienDirection == -1.0f){
			alienDirection = 1.0f;
			alienMovement = Vec2f(alienSpeed, 32.0f);
		}
		else{
			alienMovement = Vec2f(alienSpeed*alienDirection, 0.0f);
		}

		//process aliens  
		for (auto it = alienPos.begin(); it < alienPos.end(); ++it){
			//move
			(*it) = (*it) + alienMovement;
			if ((*it).y > screenY){
				//game over
				break;
			}
		}
		//Split loops as a fix to a bug where the position whould randomly change on collision
		for (auto it = alienPos.begin(); it < alienPos.end(); ++it){
			//detect collision
			for (int j = 0; j< rocketPos.size(); j++){
				if (rocketPos[j].x + 16 >(*it).x &&    rocketPos[j].x + 16 < (*it).x + 32
					&& rocketPos[j].y + 16 > (*it).y && rocketPos[j].y + 16 <(*it).y + 32){
					it =alienPos.erase(it); 
					rocketPos.erase(rocketPos.begin() + j);
				}
			}
			if (it != alienPos.end()&&(playerPos.x + 16 > (*it).x &&    playerPos.x + 16 < (*it).x + 32
				&& playerPos.y< (*it).y))
			{
				lives--;
				it = alienPos.erase(it);
			}
			if (it == alienPos.end())
				break;//if we removed last object in vector
		}
		

		//spawn bombs
		int random = rand()%100000;
		if (random == 1 && bombPos.size()<maxNbrBombs){
			int alien = rand() % alienPos.size();
			bombPos.push_back(alienPos[alien]);
		}
	
		//move bombs
		for (int i = 0; i < bombPos.size(); i++){
			bombPos[i].y += move;

			//collision detection
			if (bombPos[i].x + 16 > playerPos.x &&    bombPos[i].x + 16 < playerPos.x + 32
				&& bombPos[i].y + 16 > playerPos.y && bombPos[i].y + 16 < playerPos.y + 32){
				lives--;
				bombPos.erase(bombPos.begin() + i);
			}

			else if (bombPos[i].y > screenY ){//remove rockets outside screen
				bombPos.erase(bombPos.begin() + i);
			}

			
		}

	}
	alien1->destroy();
	rocket->destroy();
	sprite->destroy();
	system->destroy();
	return 0;
}