コード例 #1
0
ファイル: Level.cpp プロジェクト: KyryloBR/SDLEngine
void Level::update()
{
	ObjectLayer * pObjects;
	for (int i = 0; i < m_layers.size(); ++i)
	{
		if (m_pPlayer->getPosition()->getX() + m_pPlayer->getWidth() > 635)
		{
			TileLayer * pTile = dynamic_cast<TileLayer*>(m_layers[i]);
			if (pTile && pTile->getNumColumns() + pTile->getColumnIncrement() < pTile->getTileIDs().at(0).size())
			{
 				pTile->setColumns(20);
				m_pPlayer->setPosition(Vector2D(10, 330));
				BulletHandler::Instance()->clearAll();
				scrollObjects();
			}
			else
			{
				m_pPlayer->setVelocity(Vector2D(0.0, 0.0));
			}
		}
		m_layers[i]->update();
		pObjects = dynamic_cast<ObjectLayer*>(m_layers[i]);
		if (pObjects)
		{
			CollisionManager::Instance()->checkEnemyPlayerBulletCollision(BulletHandler::Instance()->getBulletPlayer(), pObjects->getObjects());
		}
	}
	CollisionManager::Instance()->checkPlayerEnemyBulletCollision(m_pPlayer, BulletHandler::Instance()->getBulletEnemy());
	BulletHandler::Instance()->update();
	if (m_pPlayer->isDead())
	{
		Game::Instance()->getStateMachine()->changeState(new GameOverState());
	}
}
コード例 #2
0
void
ObjectDeleteCommandImpl::undo()
{
  for(Objects::iterator i = objects.begin(); i != objects.end(); ++i)
  {
    object_layer.add_object(*i);
  }
}
コード例 #3
0
void
ObjectDeleteCommandImpl::execute()
{
  for(Objects::iterator i = objects.begin(); i != objects.end(); ++i)
  {
    object_layer.delete_object(*i);
  }
}
コード例 #4
0
ファイル: Level.cpp プロジェクト: KyryloBR/SDLEngine
void Level::scrollObjects()
{
	for (int i = 0; i < m_layers.size(); ++i)
	{
		ObjectLayer * pObjects = dynamic_cast<ObjectLayer*>(m_layers[i]);
		if (pObjects)
		{
			for (int i = 0; i < pObjects->getObjects()->size(); ++i)
			{
				if (pObjects->getObjects()->at(i)->getType() != std::string("Player") && pObjects->getObjects()->at(i)->getPosition()->getX() > Game::Instance()->getWindowWidth())
				{
					pObjects->getObjects()->at(i)->setPosition(Vector2D(pObjects->getObjects()->at(i)->getPosition()->getX() - Game::Instance()->getWindowWidth(), pObjects->getObjects()->at(i)->getPosition()->getY()));
				}
			}
		}
	}
}
コード例 #5
0
ファイル: LevelParser.cpp プロジェクト: paubereng/BaseCode
void LevelParser::parseObjectLayer(TiXmlElement * pObjectElement, std::vector<Layer*>* pLayers, Level* pLevel)
{
	ObjectLayer* pObjectLayer = new ObjectLayer();
	std::cout << pObjectElement->FirstChildElement()->Value();
	for (TiXmlElement* e = pObjectElement->FirstChildElement(); e !=
		NULL; e = e->NextSiblingElement())
	{
		std::cout << e->Value();
		if (e->Value() == std::string("object"))
		{
			int x, y, width, height, numSprites, speedX, speedY, maxSpeed, callbackId, collitionmargin;
			double friction;
			char* textureID;

			e->Attribute("x", &x);
			e->Attribute("y", &y);
			GameObject* pGameObject = GameObjectFactory::Instance()->CreateGameObject(e->Attribute("type"));
			

			for (TiXmlElement* properties = e->FirstChildElement();
			properties != NULL; properties = properties->NextSiblingElement())
			{
				if (properties->Value() == std::string("properties"))
				{
					for (TiXmlElement* property = properties->FirstChildElement(); property != NULL; property = property->NextSiblingElement())
					{
						if (property->Value() == std::string("property"))
						{
							if (property->Attribute("name") == std::string("textureWidth"))
							{
								property->Attribute("value", &width);
							}
							else if (property->Attribute("name") == std::string("textureHeight"))
							{
								property->Attribute("value", &height);
							}
							else if (property->Attribute("name") == std::string("speedY"))
							{
								property->Attribute("value", &speedY);
							}
							else if (property->Attribute("name") == std::string("textureID"))
							{
								const size_t len = strlen(property->Attribute("value"));
								textureID = new char[len + 1];
								strncpy(textureID, property->Attribute("value"), len);
								textureID[len] = '\0';
								
							}
							else if (property->Attribute("name") == std::string("speedX"))
							{
								property->Attribute("value", &speedX);
							}
							else if (property->Attribute("name") == std::string("numFrames"))
							{
								property->Attribute("value", &numSprites);
							}
							else if (property->Attribute("name") == std::string("maxSpeed"))
							{
								property->Attribute("value", &maxSpeed);
							}
							else if (property->Attribute("name") == std::string("callbackId"))
							{
								property->Attribute("value", &callbackId);
							}
							else if (property->Attribute("name") == std::string("friction"))
							{
								property->Attribute("value", &friction);
							}
							else if (property->Attribute("name") == std::string("collitionmargin"))
							{
								property->Attribute("value", &collitionmargin);
							}
						}
					}
				}
			}
			if (dynamic_cast<CollisionObject*>(pGameObject))
			{
				CollisionObject* pCollisionObj = dynamic_cast< CollisionObject* >(pGameObject);
				pCollisionObj->setCollisionLayers(pLevel->getCollisionLayers());
				pCollisionObj->setCollisionMargin(collitionmargin);
				TheCamera::Instance()->setTarget(dynamic_cast<Player*>(pGameObject));
				TheCamera::Instance()->setPosition(dynamic_cast<Player*>(pGameObject)->getPosition());
			}
			pGameObject->load(new LoaderParams(x, y, width, height, textureID, numSprites, speedX, speedY, maxSpeed, friction, callbackId));
			if (textureID == "Player")
			{
				pLevel->setPlayer(dynamic_cast<Player*>(pGameObject));
			}
			pObjectLayer->getGameObjects()->push_back(pGameObject);
		}
	}
	pLayers->push_back(pObjectLayer);
}
コード例 #6
0
void
ObjectAddCommandImpl::undo()
{
  for(std::vector<ObjMapObject>::iterator i = objs.begin(); i != objs.end(); ++i)
    objmap.delete_object(*i);
}
コード例 #7
0
void
ObjectAddCommandImpl::execute()
{
  for(std::vector<ObjMapObject>::iterator i = objs.begin(); i != objs.end(); ++i)
    objmap.add_object(*i);
}
コード例 #8
0
ファイル: TmxMap.cpp プロジェクト: EemeliSyynimaa/yam2d
	void Map::ParseText(const string &text) 
	{
		// Create a tiny xml document and use it to parse the text.
		TiXmlDocument doc;
		doc.Parse(text.c_str());
	
		// Check for parsing errors.
		if (doc.Error()) 
		{
			has_error = true;
			error_code = TMX_PARSING_ERROR;
			error_text = doc.ErrorDesc();
			return;
		}

		TiXmlNode *mapNode = doc.FirstChild("map");
		TiXmlElement* mapElem = mapNode->ToElement();

		// Read the map attributes.
		mapElem->Attribute("version", &version);
		mapElem->Attribute("width", &width);
		mapElem->Attribute("height", &height);
		mapElem->Attribute("tilewidth", &tile_width);
		mapElem->Attribute("tileheight", &tile_height);

		// Read the orientation
		std::string orientationStr = mapElem->Attribute("orientation");

		if (!orientationStr.compare("orthogonal")) 
		{
			orientation = TMX_MO_ORTHOGONAL;
		} 
		else if (!orientationStr.compare("isometric")) 
		{
			orientation = TMX_MO_ISOMETRIC;
		}

		// Read the map properties.
		const TiXmlNode *propertiesNode = mapElem->FirstChild("properties");
		if (propertiesNode) 
		{
			properties.Parse(propertiesNode);
		}

		// Iterate through all of the tileset elements.
		const TiXmlNode *tilesetNode = mapNode->FirstChild("tileset");
		while (tilesetNode) 
		{
			// Allocate a new tileset and parse it.
			Tileset *tileset = new Tileset();
			tileset->Parse(tilesetNode->ToElement());

			// Add the tileset to the list.
			tilesets.push_back(tileset);

			tilesetNode = mapNode->IterateChildren("tileset", tilesetNode);
		}

		// Find all layers and object groups.
		TiXmlNode *layerNode = mapNode->FirstChild();
		while( layerNode != 0 )
		{
			if( std::string("layer") == layerNode->Value() )
			{
				// Allocate a new layer and parse it.
				TileLayer *layer = new TileLayer(this);
				layer->Parse(layerNode);

				// Add the layer to the list.
				layers.push_back(layer);
			}

			if( std::string("objectgroup") == layerNode->Value() )
			{
				// Allocate a new object group and parse it.
				ObjectLayer *objectGroup = new ObjectLayer(this);
				objectGroup->Parse(layerNode);
		
				// Add the object group to the list.
				layers.push_back(objectGroup);
			}

			layerNode = layerNode->NextSibling();
		}
	}
コード例 #9
0
ファイル: LevelParser.cpp プロジェクト: dscravag/Prehisto
void LevelParser::parseObjectLayer(TiXmlElement* pObjectElement, std::vector<Layer*> *pLayers, Level* pLevel)
{
    // create an object layer
    ObjectLayer* pObjectLayer = new ObjectLayer();
    
    for(TiXmlElement* e = pObjectElement->FirstChildElement(); e != NULL; e = e->NextSiblingElement())
    {
        if(e->Value() == std::string("object"))
        {
            int x, y, width, height, numFrames, callbackID = 0, animSpeed = 0;
            std::string textureID;
            std::string type;
            
            // get the initial node values type, x and y
            e->Attribute("x", &x);
            e->Attribute("y", &y);
            
            type = e->Attribute("type");
            GameObject* pGameObject = TheGameObjectFactory::Instance()->create(type);
            
            // get the property values
            for(TiXmlElement* properties = e->FirstChildElement(); properties != NULL; properties = properties->NextSiblingElement())
            {
                if(properties->Value() == std::string("properties"))
                {
                    for(TiXmlElement* property = properties->FirstChildElement(); property != NULL; property = property->NextSiblingElement())
                    {
                        if(property->Value() == std::string("property"))
                        {
                            if(property->Attribute("name") == std::string("numFrames"))
                            {
                                property->Attribute("value", &numFrames);
                            }
                            else if(property->Attribute("name") == std::string("textureHeight"))
                            {
                                property->Attribute("value", &height);
                            }
                            else if(property->Attribute("name") == std::string("textureID"))
                            {
                                textureID = property->Attribute("value");
                            }
                            else if(property->Attribute("name") == std::string("textureWidth"))
                            {
                                property->Attribute("value", &width);
                            }
                            else if(property->Attribute("name") == std::string("callbackID"))
                            {
                                property->Attribute("value", &callbackID);
                            }
                            else if(e->Attribute("name") == std::string("animSpeed"))
                            {
                                property->Attribute("value", &animSpeed);
                            }
                        }
                    }
                }
            }
            // load the object
            pGameObject->load(std::unique_ptr<LoaderParams>(new LoaderParams(x, y, width, height, textureID, numFrames,callbackID, animSpeed)));
            // set the collision layers
            pGameObject->setCollisionLayers(pLevel->getCollisionLayers());
            
            if(type == "Player")
            {
                pLevel->setPlayer(dynamic_cast<Player*>(pGameObject));
            }
            
            pObjectLayer->getGameObjects()->push_back(pGameObject);
        }
    }
    
    pLayers->push_back(pObjectLayer);
}
コード例 #10
0
ファイル: LevelParser.cpp プロジェクト: carretero4/BaseCode
void LevelParser::parseObjectLayer(TiXmlElement* pObjectElement, std::vector<Layer*> *pLayers, Level *pLevel)
{
	ObjectLayer* pObjectLayer = new ObjectLayer();

	for (TiXmlElement* e = pObjectElement->FirstChildElement(); e != NULL; e = e->NextSiblingElement())
	{
		if (e->Value() == std::string("object"))
		{

			int x, y, width, height, spriteNum, rowNum, callbackID;
			std::string textureID, fileName;
			// get the initial node values type, x and y
			e->Attribute("x", &x);
			e->Attribute("y", &y);
			e->Attribute("width", &m_width);
			e->Attribute("height", &m_height);
			
			GameObject* pGameObject = GameObjectFactory::Instance()->CreateGameObject(e->Attribute("type"));
			// get the property values
			for (TiXmlElement* properties = e->FirstChildElement(); properties != NULL; properties = properties->NextSiblingElement())
			{
				if (properties->Value() == std::string("properties"))
				{
					for (TiXmlElement* property = properties->FirstChildElement(); property != NULL; property = property->NextSiblingElement())
					{
						if (property->Value() == std::string("property"))
						{
							if (property->Attribute("name") == std::string("callbackID"))
							{
								property->Attribute("value", &callbackID);
							}
							else if (property->Attribute("name") == std::string("rowNum"))
							{
								property->Attribute("value", &rowNum);
							}
							else if (property->Attribute("name") == std::string("spriteNum"))
							{
								property->Attribute("value", &m_spriteNum);
							}
							else if (property->Attribute("name") == std::string("fileName"))
							{
								property->Attribute("value", &m_fileName);
							}
							else if (property->Attribute("name") == std::string("textureID")) {
								textureID = property->Attribute("value");
							}
							
						}
					}
				}
			}
			if (m_fileName == 1) { file = "gorda.png"; }
			else if (m_fileName == 2) { file = "cine.png"; }

			
			pObjectLayer->getGameObjects()->push_back(pGameObject);

			if (pGameObject != NULL) {
				pGameObject->load(new LoaderParams(x, y - m_height, m_width, m_height, textureID, file, m_spriteNum, rowNum, callbackID));
			    pGameObject->setCollisionLayers(pLevel->getCollisionLayers());
				if (textureID == "player") // check if it's the player
				{
					//Camera::Instance()->setTarget(pGameObject);
				}
				pObjectLayer->getGameObjects()->push_back(pGameObject);
			}
		}
	}
	pLayers->push_back(pObjectLayer);
}
コード例 #11
0
ファイル: LevelParser.cpp プロジェクト: iiechapman/Sandman2D
//For extracting objects from object layers
void LevelParser::parseObjectLayer
(TiXmlElement *pObjectElement, vector<ILayer *> *pLayers,
 string layerType, Level* pLevel ,PlayState* newState){
    
    //Create an object layer
    ObjectLayer* pObjectLayer = new ObjectLayer();
    pObjectLayer->setType(layerType);
    cout << "Created new " << pObjectLayer->getType() << " layer\n";
    //cout << "Current Value: ";
    //cout << pObjectElement->FirstChildElement()->Value() << "\n";
    
    for (TiXmlElement* e = pObjectElement->FirstChildElement();
         e != NULL; e = e->NextSiblingElement()){
        cout << "Checking " << e->Value() << "\n";
        if (e->Value() == string("object")){
            int x(0), y(0), width(0), height(0), numFrames(1), callbackID(0), animSpeed(1);
            
            SDL_Color color;
            SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
            
            string textureID(""),name(""),lockTo(""),scrollLock(""),ai("");
            
            
            //Get initial values
            e->Attribute("x", &x);
            e->Attribute("y", &y);
            //cout << "Y: " << x << "\nY: " << y << "\n";
            name = e->Attribute("name");
            
            int GID = 0;
            e->Attribute("gid",&GID);
            
            
            //Check if object exists in element library
            IGameObject* pGameObject;
            if ((*newState->getElements())[name]){
                GameObjectParams* elementParams = (*newState->getElements())[name];
                cout << "Loaded from library: " << elementParams->getName() << "\n";
                pGameObject = GameObjectFactory::Instance()->create(elementParams->getType());
            } else {
                cout << "Object \"" << e->Attribute("name") << "\" not found in library!\n";
                pGameObject = GameObjectFactory::Instance()->create(e->Attribute("type"));
            }
            
            
            //Prep game object params
            pGameObject->load
            (*new GameObjectParams
             (name, (x), (y-height),width, height, textureID,callbackID,animSpeed));
            
            //Load default params per element library
            if ((*newState->getElements())[name]){
                pGameObject->GetParams() = *(*newState->getElements())[name];
            }
            
            
            pGameObject->GetParams().getPosition().setX(x);
            pGameObject->GetParams().getPosition().setY(y);
            
            //Overload properties based on unique object params IN TILED
            for (TiXmlElement* properties = e->FirstChildElement();
                 properties != NULL; properties = properties->NextSiblingElement()){
                if (properties->Value() == string("properties")){
                    
                    for (TiXmlElement* property = properties->FirstChildElement();
                         property!=NULL; property = property->NextSiblingElement()){
                        
                        if (property->Value() == string("property")){
                            
                            if (property->Attribute("name") == string("numFrames")){
                                property->Attribute("value",&numFrames);
                                pGameObject->GetParams().setMaxFrames(numFrames);
                                cout << "Set frames to " << numFrames << "\n";
                                
                            } else if (property->Attribute("name") == string("lockTo")){
                                lockTo = property->Attribute("value");
                                pGameObject->GetParams().setLockTo(lockTo);
                                
                            } else if (property->Attribute("name") == string("ai")){
                                ai = property->Attribute("value");
                                
                                cout << "checking ai flag\n";
                                
                                if (ai == string("true")){
                                    pGameObject->GetParams().setAI(true);
                                } else {
                                    pGameObject->GetParams().setAI(false);
                                }
                                
                            } else if (property->Attribute("name") == string("textureHeight")){
                                property->Attribute("value",&height);
                                pGameObject->GetParams().setHeight(height);
                                
                            } else if (property->Attribute("name") == string("scrollLock")){
                                scrollLock = property->Attribute("value");
                                pGameObject->GetParams().setScrolling(scrollLock != string("true"));
                                
                            } else if (property->Attribute("name") == string("textureWidth")){
                                property->Attribute("value",&width);
                                pGameObject->GetParams().setWidth(width);
                                
                            } else if (property->Attribute("name") == string("animSpeed")){
                                property->Attribute("value",&animSpeed);
                                pGameObject->GetParams().setAnimSpeed(animSpeed);
                                
                            } else if (property->Attribute("name") == string("callbackID")){
                                property->Attribute("value",&callbackID);
                                pGameObject->GetParams().setCallBackID(callbackID);
                                
                            } else if (property->Attribute("name") == string("textureID")){
                                textureID = property->Attribute("value");
                                pGameObject->GetParams().setTextureID(textureID);
                                
                            } else if (property->Attribute("name") == string("blendMode")){
                                if (property->Attribute("value") == string("add")){
                                    blendMode = SDL_BLENDMODE_ADD;
                                } else if (property->Attribute("value") == string("blend")){
                                    blendMode = SDL_BLENDMODE_BLEND;
                                } else if (property->Attribute("value") == string("mod")){
                                    blendMode = SDL_BLENDMODE_MOD;
                                }
                                pGameObject->GetParams().setBlendMode(blendMode);
                                
                            } else if (property->Attribute("name") == string("alpha")){
                                int temp;
                                property->Attribute("value",&temp);
                                color.a = temp;
                                
                            }  else if (property->Attribute("name") == string("red")){
                                int temp;
                                property->Attribute("value",&temp);
                                color.r = temp;
                                
                            }  else if (property->Attribute("name") == string("green")){
                                int temp;
                                property->Attribute("value",&temp);
                                color.g = temp;
                                
                            }  else if (property->Attribute("name") == string("blue")){
                                int temp;
                                property->Attribute("value",&temp);
                                color.b = temp;
                            }
                            pGameObject->GetParams().setColor(color);
                            
                        }
                    }
                }
            }
            

            //If object is player set game player pointer accordingly
            if (pObjectLayer->getType() == string("player")){
                cout << "Adding player to object spot "
                << pObjectLayer->getGameObjects()->size() << "\n";
                
                if (Game::Instance()->isLiveModeOn()){
                    pGameObject = 0;
                } else {
                    pLevel->setPlayer(dynamic_cast<Player*>(pGameObject));
                    Game::Instance()->setPlayer(dynamic_cast<Player*>(pGameObject));
                }
            }
            
            if (pGameObject){
                if(pGameObject->GetParams().getType() == string("Light")){
                    pGameObject->GetParams().getPosition().setX
                    (pGameObject->GetParams().getPosition().getX() - pGameObject->GetParams().getWidth()/2);
                    
                    pGameObject->GetParams().getPosition().setY
                    (pGameObject->GetParams().getPosition().getY() - pGameObject->GetParams().getHeight()/2);
                }
            }
            
            if (pGameObject){
                pObjectLayer->getGameObjects()->push_back(pGameObject);
                cout << "Created new " << pGameObject->GetParams().getType() << "\n";
            }
        }
    }
    pLayers->push_back(pObjectLayer);
}