Beispiel #1
0
/**
* Called the first frame to set things up in the gameobject. Called first by Start()
*/
void GameMap::EarlyStart ( )
{
	//Construct a random map. Make sure there are no 3 tiles already matched
	int i=0, j=0, k;
	srand(time(NULL));
	for(;i<m_tilesX;i++)
	{
		for(j=0;j<m_tilesY;j++)
		{
			//initialise every map location with a random jewel 
			GameJewelPtr jewel = boost::make_shared<GameJewel>(this, TEX_JEWEL_BLUE, Rect(0, 0, m_tileSize, m_tileSize));
		
			//Also add this as child node
			GameObjectPtr gameObject(jewel);
			AddChild(gameObject);

			pJewelsMap[i][j] = jewel.get();
			
			JewelTypes type = (JewelTypes)(JT_BLUE + rand()%5);
			jewel->getTransform().SetPosition(Vector2(i*m_tileSize, -1*m_tileSize));
			jewel->MoveTo(Vector2(i*m_tileSize, j*m_tileSize), kJewelMoveDownInitialSpeed*(i+j+1));

			do
			{
				jewel->setJewelType(type);	
				type = (JewelTypes)(JT_BLUE + rand()%5);

			}while(SearchAndDestroyJewels(false));			
		}
	}
}
bool OrbitingLight::InitializeAsync()
{
    Vector<3> raxis = !!rotationAxis[0] ? Vector<3> { 1, 0, 0 } :
                      !!rotationAxis[1] ? Vector<3> { 0, 1, 0 } :
                                          Vector<3> { 0, 0, 1 };
    gameObject()->localTransform()->SetPosition(raxis * distance);
    return GlEngine::GameComponent::InitializeAsync();
}
	IComponent::~IComponent()
	{
		if (!gameObject_.expired())
		{
			std::shared_ptr<GameObject> go = gameObject();
			go->components_.erase(std::find(go->components_.begin(), go->components_.end(), this));
		}
	}
GameObjectPtr GameObjectRegistry::CreateGameObject( uint32_t inFourCCName )
{
	//no error checking- if the name isn't there, exception!
	GameObjectCreationFunc creationFunc = mNameToGameObjectCreationFunctionMap[ inFourCCName ];

	GameObjectPtr gameObject( creationFunc() );

	//should the registry depend on the world? this might be a little weird
	//perhaps you should ask the world to spawn things? for now it will be like this
	World::sInstance->AddGameObject( gameObject );

	return gameObject;
}
void SWSpriteRenderer::render( SWCamera* camera )
{
	if ( getMaterial() && m_sprite.isValid() )
	{
		SWTransform* transform = gameObject()->getComponent<SWTransform>();
		const TMatrix4x4& model = transform->getWorldMatrix();
		const TMatrix4x4& VPMat = camera->getVPMatrix();
		const tvec2& offset = m_sprite()->getScaledOffset();
		const tvec2& size   = m_sprite()->getScaledSize();

		tquat scaler( offset.x, offset.y, size.x, size.y );

		SWMaterial* material = getMaterial();
		material->setTexture( "TEXTURE_0", m_sprite()->getTexture() );
		material->setMatrix4x4( "MATRIX_MVP", ( model * VPMat ) );
		material->setVector4( "SCALER", scaler );
		material->apply();
	}

	if ( getMesh() ) getMesh()->draw();
}
Beispiel #6
0
void SWFontRenderer::render( SWCamera* camera )
{
	if ( !getMesh() ) return;
	if ( !getMaterial() ) return;
	if ( !m_texture.isValid() ) return;
	if ( m_text.size() == 0 ) return;
	if ( m_textChanged )
	{
		m_textChanged = false;
		updateMesh();
	}

	SWTransform* transform = gameObject()->getComponent<SWTransform>();
	const TMatrix4x4& model = transform->getWorldMatrix();
	const TMatrix4x4& VPMat = camera->getVPMatrix();

	SWMaterial* material = getMaterial();
	material->setTexture( "TEXTURE_0", m_texture() );
	material->setMatrix4x4( "MATRIX_MVP", ( model * VPMat ) );
	material->apply();

	getMesh()->draw();
}
Beispiel #7
0
 GameObject *Canvas::createGameObject() {
     return gameObject()->scene()->createGameObject();
 }
Beispiel #8
0
int main(int argc, char* argv [])
{
    al_init();
    al_init_primitives_addon();
    al_install_keyboard();
    al_init_image_addon();

	ALLEGRO_CONFIG *configFile = al_load_config_file("data/config/config.ini");
	if (configFile == NULL)
	{
		al_show_native_message_box(NULL, "A fatal error has ocurred!",
			"The configuration file has not been found!", 
			"Be sure to always have a valid conf.ini in /data/config/ for the program to work...", "Understood", ALLEGRO_MESSAGEBOX_ERROR);
		return 0;
	}

	std::string dispW = al_get_config_value(configFile, "DISPLAY", "RESX");
	std::string dispH = al_get_config_value(configFile, "DISPLAY", "RESY");
	std::string fullscreenMode = al_get_config_value(configFile, "DISPLAY", "FULLSCREEN");

	int iDispW = stoi(dispW);
	int iDispH = stoi(dispH);
	bool bfullscreenMode = stoi(fullscreenMode);

	assert(iDispW < 5000 && iDispW > 0);
	assert(iDispH < 5000 && iDispH > 0);

	if (bfullscreenMode == true)
		al_set_new_display_flags(ALLEGRO_FULLSCREEN);

	ALLEGRO_DISPLAY *display = al_create_display(iDispW, iDispH);
	if (display == NULL)
	{
		al_show_native_message_box(NULL, "A fatal error has ocurred!",
			"Display creation failed!",
			"The resolution selected is not supported by your screen/video card...", "Understood", ALLEGRO_MESSAGEBOX_ERROR);
		return 0;
	}

    al_clear_to_color(al_map_rgb(255, 0, 0));
    al_flip_display();

    bool done = false;
    bool redraw = false;

    ALLEGRO_TIMER *timer = al_create_timer(1.0 / 60.0);

    ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();

    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));
    al_register_event_source(queue, al_get_timer_event_source(timer));

    //**********************
    ALLEGRO_BITMAP *test = al_load_bitmap("data/background.png");

    int x = 320, y = 240;

	Vec2D size(40.0f, 40.0f);

	TestObject gameObject(Vec2D(10.0f, 10.0f));
	gameObject.AddComponent(new RenderComponent());
    gameObject.AddComponent(new PhysicsComponent(size, size, size, true));
    //*********************

    al_start_timer(timer);

	//newManager.AddComponent(new PhysicsComponent(Vec2D(), Vec2D(), Vec2D(5.0f, 10.0f), false));

    while (!done)
    {
        ALLEGRO_EVENT ev;
        al_wait_for_event(queue, &ev);

        switch (ev.type)
        {
            case ALLEGRO_EVENT_TIMER:
                redraw = true;
                gameObject.Update();
                break;
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                done = true;
                break;
            case ALLEGRO_EVENT_KEY_DOWN:
                if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
                {
                    done = true;
                }
                //************
                else
                {
					// NOTHING
                }
                //************
                break;
            default:
                break;
        }

        if (redraw && al_is_event_queue_empty(queue))
        {
            redraw = false;

            al_clear_to_color(al_map_rgb(0, 0, 0));
            al_draw_bitmap(test, 0, 0, NULL);

			//PhysicsComponent *test = (PhysicsComponent*) newManager.GetComponentByType(COMP_PHYSICS);
			//Vec2D pos = test->GetPosition();

            al_draw_filled_circle(x, y, 89, al_map_rgb(255, 0, 255));

            al_flip_display();
        }
    }

	al_destroy_config(configFile);
    al_destroy_display(display);
    al_destroy_event_queue(queue);
    al_destroy_timer(timer);
}
	IComponent::IComponent(std::weak_ptr<GameObject> go) : 
		gameObject_(go), enabled_(true)
	{
		gameObject()->components_.push_back(this);
	}