Пример #1
0
MapGridNode::MapGridNode(const vn::vector2i &index) {
    vn::color_t color(0xFF, 0xFF, 0xFF, 0x20);
    Quad *p = vnnew Quad();
    *p << vn::aabox2f(0, 0, 38, 2) << color << vn::Render2DInterface::kAlphaAdditive;
    addRenderable(p, false);
    
    p = vnnew Quad();
    *p << vn::aabox2f(0, 2, 2, 40) << color << vn::Render2DInterface::kAlphaAdditive;
    addRenderable(p, false);
    
    p = vnnew Quad();
    *p << vn::aabox2f(38, 0, 40, 38) << color << vn::Render2DInterface::kAlphaAdditive;
    addRenderable(p, false);
    
    p = vnnew Quad();
    *p << vn::aabox2f(2, 38, 40, 40) << color << vn::Render2DInterface::kAlphaAdditive;
    addRenderable(p, false);

    Text *t = vnnew Text();
    vn::c8 buf[32];
    sprintf(buf, "%u,%u", index.x + 1, index.y + 1);
    *t << vn::color_t(0xFF, 0xFF, 0xFF, 0x80) << vn::Render2DInterface::kAlphaAdditive << vn::RenderText::kCenter;
    *t << vn::FontManager::instance().defaultFont() << buf;
    SceneNode *node = vnnew SceneNode();
    node->setPosition(vn::vector2f(20, 20));
    node->setScale(vn::vector2f(0.6f, 0.6f));
    node->addRenderable(t, false);
    addChild(node, false);
    
    setPosition(index * 40);
    setLocalBoundingBox(vn::aabox2f(0, 0, 40, 40));
}
Пример #2
0
void LevelScreen::ReceiveMessage(Message* m)
{
    if(m->GetMessageName() == "FoodConsumed")
    {
        std::stringstream ss;
        
        m_highscoreCounter += m_snake->getPointMultiplicator();
        
        ss << std::setfill('0') << std::setw(4) << m_highscoreCounter;
        
        m_highscore->SetDisplayString(ss.str());
    }
    else if(m->GetMessageName() == "PowerupConsumed")
    {
        std::stringstream ss;
        m_highscoreCounter += m_snake->getPointMultiplicator();
        ss << std::setfill('0') << std::setw(4) << m_highscoreCounter;
        
        Powerup* powerup = static_cast<Powerup*>(m->GetSender());
        
        if(powerup != NULL)
        {
            m_popupText->SetColor(1.f, 1.f, 1.f);
            m_popupText->SetDisplayString(powerup->getDescription());
            m_popupText->ChangeColorTo(Color(1.0,0.0,0.0), 5.0, true, "HidePopup");
            theWorld.Add(m_popupText, kUILayer);
        }
    }
    else if(m->GetMessageName() == "HidePopup")
    {
        theWorld.Remove(m_popupText);
    }
    else if(m->GetMessageName() == "EnterPressed")
    {
        theSwitchboard.UnsubscribeFrom(this, "EnterPressed");
        theSwitchboard.Broadcast(new Message("ShowMenu"));
    }
    else if(m->GetMessageName() == "ObstacleHit")
    {
        theWorld.Remove(m_popupText);
        m_snake->stop();
                
        TextActor* gameOver = new TextActor("popup", "GAME OVER");
        gameOver->SetPosition(-4.8f, 4.0f);
        gameOver->SetColor(1.f, 1.f, 1.f);
        
        TextActor* hitEnterText = new TextActor("standard", "Hit [Enter] to get back to menu...");
        hitEnterText->SetPosition(-8.8f, 0.0f);
        hitEnterText->SetColor(1.f, 1.f, 1.f);
        
        addRenderable(gameOver, kUILayer);
        addRenderable(hitEnterText, kUILayer);
        
        theSwitchboard.SubscribeTo(this, "EnterPressed");
    }
}
Пример #3
0
void populateWorld(void){
	RenderableMold* deerMold = loadRenderableMold("Resources/deer-obj.obj","Resources/deer texture.tga");
	int i;
	for(i = 0 ; i < 30 ; i++){
		vec3 position = (vec3){-30*i,0,0};
		Renderable r = (Renderable){1,position,EMPTY_VEC3,EMPTY_VEC3,deerMold};
		addRenderable(r);
	}
	vec3 scale = (vec3){0.5,0.5,0.5};
	for(i = 0 ; i < 30 ; i++){
		vec3 position = (vec3){0,0,30*i};
		Renderable r = (Renderable){1,position,EMPTY_VEC3,scale,deerMold};
		addRenderable(r);
	}
}
Пример #4
0
void Particles::createGeometry()
{
	gb = AllocateThis(GeometryBuffer);
	gb->setBufferAccess(BufferAccess::Write);
	gb->setBufferUsage(BufferUsage::Dynamic);
	
	material = MaterialCreate(AllocatorGetHeap(), "ParticlesMaterial");

	Material* pMaterial = material.Resolve();
	pMaterial->setDepthWrite(false);
	pMaterial->setBlending(BlendSource::SourceAlpha, BlendDestination::One);
	pMaterial->setShader("Tex");

	RenderBatchPtr renderable = AllocateHeap(RenderBatch);
	renderable->setPrimitiveType(PrimitiveType::Points);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(material);
	renderable->setRenderLayer(RenderLayer::Transparency);

	renderable->onPreRender.Bind( this, &Particles::onPreRender );
	renderable->onPostRender.Bind( this, &Particles::onPostRender );
	
	addRenderable(renderable);

	particles.resize(MAX_PARTICLES);
}
Пример #5
0
GameObject*  GameScreen::addGameObject(GameObject* go)
{
	// Use the built in code
	addRenderable(go);
	mGameObjects.push_back(go);
	return go;
}
Пример #6
0
void UIBox::resize(int width, int height) {
    //Renderable *renderable;
    float ratio = (width / (float)height);

    int bWidth  = (int)(_uiBorder * width),
        bHeight = (int)(_uiBorder * height * ratio);

    UIElement::resize(width, height);

    clearRenderables();

    // Add the center box
    Vec2f boxPosition(0, 0);
    Vec2f boxDimensions((float)_dimensions.x, (float)_dimensions.y);
    if(_uiBorder > 0) {
        // Subtract space for the border if there is a border that protrudes inwards
        boxPosition += Vec2f((float)bWidth, (float)bHeight);
        boxDimensions -= Vec2f(bWidth * 2.0f, bHeight * 2.0f);
    }
    addRenderable(Renderable::OrthoBox(boxPosition, boxDimensions, false, false, _material));

    if(_uiBorder != 0) {
        int bXOffset = 0, bYOffset = 0;
        if(_uiBorder < 0) {
            bXOffset = bWidth;
            bYOffset = bHeight;
        }
        
        // Top border
        addRenderable(Renderable::OrthoBox(Vec2f((float)bWidth, (float)_dimensions.h), Vec2f((float)(_dimensions.w - (bWidth * 2)), (float)-bHeight), false, false, _borderMaterial));

        // Bottom border
        addRenderable(Renderable::OrthoBox(Vec2f((float)bWidth, 0.0f), Vec2f((float)(_dimensions.w - (bWidth * 2)), (float)bHeight), false, false, _borderMaterial));
        
        // Left border
        addRenderable(Renderable::OrthoBox(Vec2f((float)bWidth, 0.0f), Vec2f((float)-bWidth, (float)_dimensions.y), false, false, _borderMaterial));

        // Right border
        addRenderable(Renderable::OrthoBox(Vec2f((float)_dimensions.w, 0.0f), Vec2f((float)-bWidth, (float)_dimensions.y), false, false, _borderMaterial));
    }
}
Пример #7
0
void Overlay::createGeometry()
{
    material = MaterialCreate(AllocatorGetThis(), "OverlayMaterial");

    renderable = AllocateThis(Renderable);
    renderable->setPrimitiveType(PrimitiveType::Quads);
    renderable->setGeometryBuffer( AllocateThis(GeometryBuffer) );
    renderable->setMaterial(material);
    renderable->setRenderLayer(RenderLayer::Overlays);
    renderable->onPreRender.Bind(this, &Overlay::onPreRender);

    addRenderable( renderable );
}
Пример #8
0
void Entity::updateRenderable(MeshHandle meshHandle)
{
	clearAllRenderable();
	IMesh *pMesh = gEngModule->pMeshMgr->getDataPtr(meshHandle);
	const SubMeshVec &subMeshVec = pMesh->getSubMeshVec();
	for (int i = 0; i < subMeshVec.size(); ++i)
	{
		Renderable *pRenderable = new StaticRenderable(meshHandle, i);
		addRenderable(pRenderable);
		std::string mtlName = subMeshVec[i].mtlName;
		IMaterial *pMaterial = gEngModule->pMaterialMgr->create("res/mesh/" + mtlName);
		pRenderable->setMaterial(gEngModule->pMaterialMgr->getHandle(pMaterial->getName()));
	}
}
Пример #9
0
bool Game::onKeyDown(const SDL_KeyboardEvent &tEvent)
{
	switch(tEvent.keysym.sym)
	{
	case SDLK_q:
	{
		std::unique_ptr<Entities::Box> box(m_factory.createBox(b2Vec2(75, 45)));
		box->body()->SetTransform(worldToPhysics(m_lastPos), 0);
		box->body()->SetAwake(false);
		addRenderable(box.release());
		return true;
	}

	case SDLK_w:
	{
		std::unique_ptr<Entities::Light> light(m_factory.createLight());
		light->setScale(0.5f);
		light->init();
		light->body()->SetTransform(worldToPhysics(m_lastPos), 0);
		light->body()->SetAwake(false);
		addRenderable(light.release());
		return true;
	}

	case SDLK_e:
	{
		std::unique_ptr<Entities::Box> box(m_factory.createChest());
		box->body()->SetTransform(worldToPhysics(m_lastPos), 0);
		box->body()->SetAwake(false);
		addRenderable(box.release());
		return true;
	}

	default:
		return false;
	}
}
Пример #10
0
void GizmoRotate::buildGeometry()
{
	//material->setLineWidth(3.0f);

	lines = generateCircles();

	RenderablePtr renderable = AllocateHeap(Renderable);
	renderable->setPrimitiveType(PrimitiveType::Lines);
	renderable->setGeometryBuffer(lines);
	renderable->setMaterial(material);
	renderable->setRenderLayer(RenderLayer::PostTransparency);
	renderable->setRenderPriority(100);

	addRenderable(renderable);
}
Пример #11
0
void GameScreen::deathTick(float delta)
{

	// If the player hits "R", restart the game
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::R))
	{
		resetLevel();
		mPlayerScore = 0;
	}
	else
	{
		// If death hasn't been initialized (ie: the death animation hasn't started) start it
		if(mDeathObjects.size() == 0)
		{
			mPromptText.setString("Press [R] to restart the level");
			// This is a list of directions.  Basically it's an array of Vectors without the overhead
			int numDirs = 8;
			// Start pointing straight right, then spiral around clockwise
			int xDir[] = { 1, 1, 0,-1,-1,-1, 0, 1};
			int yDir[] = { 0, 1, 1, 1, 0,-1,-1,-1};
			float velocity = 50.0f;
			DeathParticle* tPart;
			// Build a bunch of death particles
			for(int i = 0; i < 33; ++i)
			{
				tPart = new DeathParticle((float)xDir[i % numDirs], (float)yDir[i % numDirs], velocity * (i + 1)/ numDirs);
				tPart->position.x = player->position.x;
				tPart->position.y = player->position.y;
				mDeathObjects.push_back(tPart);
				// Push it to GameObjects to automagically handle drawing. This should probably be extracted
				// into a renderables list, and a gameobjects list, but for jam, not necessary
				addRenderable(tPart);
			}

			// Change the player to not render
			player->mRenderingEnabled = false;
		}

		// Meow update them all
		for(std::vector<GameObject*>::iterator itor = mDeathObjects.begin(); 
			itor != mDeathObjects.end();
			++itor)
		{
			(*itor)->update(delta);
		}
	}
}
Пример #12
0
void TerrainChunk::markDirty(PaletteIndex index) {
    // Don't need to handle empty voxels.
    if (index == VoxelPalette::EmptyVoxel) {
        return;
    }

    if (index >= _paletteRenderables.size()) {
        _paletteRenderables.resize(index + 1, NULL);
    }

    if (_paletteRenderables[index] == NULL) {
        _paletteRenderables[index] = new BlockTerrainChunkRenderable(
            _terrain, this, index, _terrain->getPalette()->getMaterialForIndex(index));
        addRenderable(_paletteRenderables[index]);
    }

    _paletteRenderables[index]->markDirty();
}
Пример #13
0
LevelScreen::LevelScreen() :
    m_grid(32,
           24),
    m_foodGenerator(&m_grid),
    m_highscoreCounter(0)
{
    //TODO: CREATE SOME KIND OF LEVEL-WRAPPER, WHICH ADDS THE ACTORS IN THE GRID
    
    theSwitchboard.SubscribeTo(this, "FoodConsumed");
    theSwitchboard.SubscribeTo(this, "PowerupConsumed");
    theSwitchboard.SubscribeTo(this, "ObstacleHit");
    theSwitchboard.SubscribeTo(this, "HidePopup");
    
    m_snake = new Snake(&m_grid);
    
    //TESTCODE
    //m_snake->addPowerup(new InvulnerablePowerup(Vector2(0,0), 10000));
    //m_snake->addPowerup(new FastPowerup(Vector2(0,0), 10000));
    //m_snake->addPowerup(new FastPowerup(Vector2(0,0), 10000));
    //TESTCODE END
    
    //Generate obstacles to dodge
    MovingObstacle* obstacle = new MovingObstacle(Vector2(6, 0), Vector2(0,1), 1.0, 5.0, "Resources/Images/obstacles/spikecube.png", m_snake);
    CirclingObstacle* circleObstacle = new CirclingObstacle(Vector2(0,0), 1.0, 8.0, "Resources/Images/obstacles/spikecube.png", m_snake);
    
    //Generate UI elements
    m_statusbox = new StatusBox(MathUtil::ScreenToWorld(100, 20), m_snake, 10);
    
    m_highscore = new TextActor("Console", "0000");
    m_highscore->SetPosition(MathUtil::ScreenToWorld(5, 25));
    m_highscore->SetColor(1, 1, 1);
    
    m_popupText = new TextActor("popup", "", TXT_Center);
    
    //Prepare the grid
    m_grid.LoadBackground(kBackgroundLayer);
    m_grid.AddActor(m_snake);
    
    //Add the renderables to the world and m_objects vector
    addRenderable(obstacle, kObstacleLayer);
    addRenderable(circleObstacle, kObstacleLayer);
    addRenderable(m_snake, kSnakeHeadLayer);
    addRenderable(m_highscore, kUILayer);
    addRenderable(m_popupText, kUILayer);
    addRenderable(m_statusbox, kUILayer);
}
Пример #14
0
void Model::build()
{
	if( modelBuilt ) return;

	MeshRenderablesMap::iterator it = meshRenderables.find(mesh);
	
	if( it == meshRenderables.end() )
	{
		RenderablesVector& rends = meshRenderables[mesh];
	
		if( !MeshBuild(mesh, rends) )
		{
			LogError("Error building mesh '%s'", mesh->getPath().c_str());
			return;
		}
	}

	RenderablesVector& rends = meshRenderables[mesh];

	for( size_t i = 0; i < rends.size(); ++i )
	{
		Renderable* rend = rends[i].get();
		rend->onPreRender.Bind(this, &Model::onRender);
		
		addRenderable( rend );
	}

	// Updates the model bounding box.
	updateBounds();
	
	// Re-compute the bounding box.
	Transform* transform = getEntity()->getTransform().get();
	transform->markBoundingVolumeDirty();

	prepareSkinning();

	modelBuilt = true;
}
Пример #15
0
Renderable* Renderer::addRenderable(Geometry* geometry, ShaderInfo* shader, glm::mat4 whereMatrix, char* whereUniformLocation){
	UniformInfo* noUniforms = addUniformInfo(0, 0, 0, shader);
	Renderable* render = addRenderable(geometry, shader, noUniforms, 0, 0, whereMatrix, whereUniformLocation);
	return render;
}
Пример #16
0
RenderQueue::RenderQueue(Renderable* r) {
    mQueueID = QUEUE_5_MAIN;
    addRenderable(r);
}
Пример #17
0
void MapBlockCornerNode::updateCorner() {
    clearRenderables();
    vn::c8 path[256];
    sprintf(path, "1002:/map.imgs|corner_%u_%u.png", m_corner->type.type , m_corner->type.value & 0xF);
    vn::PicturePtr pic = vn::PictureManager::instance().createPicture(path);
    Quad *quad = vnnew Quad();
    addRenderable(quad, false);
    
    if (m_corner->type.type == 4) {
        *quad << pic.ptr();
        switch (m_corner->type.value & 0xF) {
            // 1 1
            // 0 0
            case 3:
                setLocalBoundingBox(vn::aabox2f(-20, 0, 20, 20));
                break;
                
            // 0 1
            // 0 1
            case 6:
                setLocalBoundingBox(vn::aabox2f(-20, -20, 0, 20));
                break;
                
            // 0 0
            // 1 1
            case 12:
                
                setLocalBoundingBox(vn::aabox2f(-20, -20, 20, 0));
                break;
                
            // 1 0
            // 1 0
            case 9:
                setLocalBoundingBox(vn::aabox2f(0, -20, 20, 20));
                break;
                
            // 0 0
            // 0 1
            case 4:
                setLocalBoundingBox(vn::aabox2f(-20, -20, 20, 20));
                break;
                
            // 1 0
            // 0 0
            case 1:
                setLocalBoundingBox(vn::aabox2f(-20, -20, 20, 20));
                break;
                
            // 0 1
            // 0 0
            case 2:
                setLocalBoundingBox(vn::aabox2f(-20, -20, 20, 20));
                break;
                
            // 0 0
            // 1 0
            case 8:
                setLocalBoundingBox(vn::aabox2f(-20, -20, 20, 20));
                break;
                
            // 0 1
            // 1 1
            case 14:
                setLocalBoundingBox(vn::aabox2f(-20, -20, 0, 0));
                break;
                
            // 1 0
            // 1 1
            case 13:
                setLocalBoundingBox(vn::aabox2f(0, -20, 20, 0));
                break;
                
            // 1 1
            // 1 0
            case 11:
                setLocalBoundingBox(vn::aabox2f(0, 0, 20, 20));
                break;
                
            // 1 1
            // 0 1
            case 7:
                setLocalBoundingBox(vn::aabox2f(-20, 0, 0, 20));
                break;
                
        }
        *quad << getLocalBoundingBox();
        return ;
    }
    
    
    setLocalBoundingBox(vn::aabox2f(-20, -20, 20, 20));
    *quad << getLocalBoundingBox();
    if (!pic.null()) {
        if (pic->size > vn::vector2f(40, 40)) {
            vn::aabox2f rect(pic->texcoords[0], pic->texcoords[2]);
            vn::vector2f size = rect.size() / 3;
            int x = m_corner->position.x % 3;
            int y = m_corner->position.y % 3;
            rect.min_corner.x += x * size.x;
            rect.min_corner.y += y * size.y;
            rect.max_corner = rect.min_corner + size;
            pic->buildTexcoord(rect);
        }
        *quad << pic.ptr();
    }
}
Пример #18
0
void GameWidget::init()
{
	glEnable( GL_TEXTURE_2D );
	glEnable( GL_DEPTH_TEST );

	ShaderInfo* textShad = addShaderInfo( "res/texture.vert", "res/texture.frag" );

	Neumont::ShapeData teapot = Neumont::ShapeGenerator::makeTeapot( 5, glm::mat4() );

	TextureInfo* brick = addTexture( "res/brick.png" );
	TextureInfo* mask = addTexture( "res/Frigate.png" );

	tightness = 40.0f;
	
	GeometryInfo* cubeGeo = loadFile( "res/cube.mod" );
	setUpAttribs( cubeGeo );
	GeometryInfo* maskGeo = loadFile( "res/Frigate.mod" );
	setUpAttribs( maskGeo );
	GeometryInfo* teapotGeo = addGeometry( teapot.verts, teapot.numVerts, teapot.indices, teapot.numIndices, GL_TRIANGLES );
	setUpAttribs( teapotGeo );

	camera = Camera( float(width())/height(), 0.1, 100 );
	camera.setFrom( glm::vec3( 0,0,4) );
	camera.setTo( glm::vec3(0,0,0) );

	renderableTests = new Renderable*[3];
	renderableTests[0] = addRenderable( maskGeo, glm::scale( glm::vec3( 0.02f ) ), textShad, mask );
	renderableTests[1] = addRenderable( cubeGeo, glm::translate( glm::vec3( -0.3, -0.4, 0 ) ) * glm::scale(glm::vec3(0.15)) , textShad, brick );


	addUniformParameter( textShad, "mvp", PT_MAT4, (float*)&camera.mvp );

	
	setUniformParameter( textShad, "amblight", PT_VEC4, (float*)&glm::vec4(0.1f,0.1f,0.1f,1) );
	setUniformParameter( textShad, "diffpos", PT_VEC4, (float*)&glm::vec4(0.0f,8.0f,0.0f,1) );
	setUniformParameter( textShad, "difflight", PT_VEC4, (float*)&glm::vec4(0.8f,0.8f,0.8f,1));
	setUniformParameter( textShad, "specColor", PT_VEC4, (float*)&glm::vec4(0.8f,0.8f,0.8f,1));
	addUniformParameter( textShad, "tightness", PT_FLOAT, (float*)&(tightness) );
	addUniformParameter( textShad, "eye", PT_VEC4, (float*)&camera.from);

	DebugShapes::addPoint( textShad, glm::translate(glm::vec3(0,2,0))*glm::rotate( glm::mat4(), 40.0f, glm::normalize( glm::vec3( -0.8f,0.4f,0.1f ) ) ) );
	DebugShapes::addPoint( textShad, glm::translate(glm::vec3(3,-2,0)), -1, true );
	DebugShapes::addLine( textShad, glm::vec3(-1, 2, 0), glm::vec3(3, 3, 1), glm::vec4(0,1,1,1), 7 );
	DebugShapes::addVector( textShad, glm::vec3(-1, 0, 0), glm::vec3(0, 0, 1), glm::vec4(1,0,1,1), 8 );
	DebugShapes::addCube( textShad, glm::translate(glm::vec3(2,2,0)), glm::vec4(1,1,0,1), 8, false );
	DebugShapes::addSphere( textShad, glm::translate(glm::vec3(-3.0f,-2.0f,0.0f)), glm::vec4(1,0.5f,0,1), 3, true );
	DebugShapes::addSphere( textShad, glm::translate(glm::vec3(3.0f,2.0f,0.0f)), glm::vec4(1,0,0,1), 6, true );

	DebugShapes::addPoint( textShad, glm::translate(glm::vec3(-3,0,-5)), -1, false );
	DebugShapes::addLine( textShad, glm::vec3(-3,2,-5), glm::vec3(3, 2, -5), glm::vec4(0,1,1,1), -1, false );
	DebugShapes::addVector( textShad, glm::vec3(-1.5f, 0, -5), glm::vec3(0, 0, 1), glm::vec4(1,0,1,1), -1, false );
	DebugShapes::addCube( textShad, glm::translate(glm::vec3(0,0,-5)), glm::vec4(1,1,0,1), -1, false );
	DebugShapes::addSphere( textShad, glm::translate(glm::vec3(3,0,-5)), glm::vec4(1,0,0,1), -1, false );

	// HIPPO
	DebugMenus::watchFloat( "FPS", fps );
	DebugMenus::watchFloat( "Delta Time", delta );
	DebugMenus::slideFloat("Specular Tightness", tightness, 0.0f, 100.0f );
	DebugMenus::slideVector( "Ship Position", shipPos, -1.0f, 1.0f );
	DebugMenus::toggleBool("Ship visible", renderableTests[0]->visible);
}
Пример #19
0
GameScreen::GameScreen(void) : GRAVITY(50.0f), MAX_FALL_VELOCITY(500), MIN_FALL_VELOCITY(150.0f),
	GEN_BONUS_COUNT(250), GEN_OBSTACLE_COUNT(400), GEN_CLOUD_COUNT(600),
	mPlayerScore(0), SCORE_VALUE(500), mState(GameState::PLAYING), bgverts(sf::Quads,4), SAVED_STATE_DELAY(1500.0f),
	bgUpStartColor(76,201,255), bgUpEndColor(0,107,184), bgDownStartColor(61,161,204), bgDownEndColor(175,62,0),
	mFont_ubuntu(), DEBUGTEXT("DEBUG", mFont_ubuntu), 
	mPromptText("Prompt", mFont_ubuntu), mScoreText("Score: 0", mFont_ubuntu),
	DBG_FALLSPEED(0),DBG_TRAVELED(1), DBG_PLAYER_YVEL(2)
{
	this->mID = "GameScreen";
	mFallSpeed = 0.0f;

	// try loading the bgm
	if(!mBGM.openFromFile("assets/audio/bgtrack.ogg"))
	{
		std::cerr << "Unable to load background audio track" << std::endl;
	}
	mBGM.setVolume(mBGM.getVolume() * 0.9f);
	mBGM.play();
	mBGM.setLoop(true);

	if(!mSmashBuff.loadFromFile("assets/audio/hit_hurt.wav"))
	{
		std::cerr << "Unable to load hit_hurt audio track" << std::endl;
	}
	mSmash.setBuffer(mSmashBuff);
	mSmash.setVolume(mSmash.getVolume() * 0.25f);
	
	if(!mScoreBuff.loadFromFile("assets/audio/score.wav"))
	{
		std::cerr << "Unable to load score audio track" << std::endl;
	}
	mScore.setBuffer(mScoreBuff);

	if(!mYeahBuff.loadFromFile("assets/audio/yea.ogg"))
	{
		std::cerr << "Unable to load yea audio track" << std::endl;
	}
	mYeah.setBuffer(mYeahBuff);
	
	// Make the player
	player = new Player();
	addGameObject(player);

	// Initialize some basic level data
	mLevelTraveled = 0.0f;
	mLevelDistance = 10000.0f;

	// Build the background verts (for the changing background)
	bgverts[0] = sf::Vertex(sf::Vector2<float>(0.0f,0.0f), bgUpStartColor);
	bgverts[1] = sf::Vertex(sf::Vector2<float>(500.0f,0.0f), bgUpStartColor);
	bgverts[2] = sf::Vertex(sf::Vector2<float>(500.0f,700.0f), bgDownStartColor);
	bgverts[3] = sf::Vertex(sf::Vector2<float>(0.0f,700.0f), bgDownStartColor);

	float maxObjectDistance = -1.0;

	// Add some clouds
	Cloud* tCloud;	
	for(int c = 0; c < GEN_CLOUD_COUNT; ++c)
	{
		tCloud = new Cloud();
		tCloud->position.x = (float)(rand() % 400);
		tCloud->position.y = (float)(rand() % 100 * c);
		if(tCloud->position.y > mLevelDistance) break;
		addRenderable(tCloud);
		if(tCloud->position.y > maxObjectDistance) maxObjectDistance = tCloud->position.y;
	}

	// Add some bonuses
	Bonus* bonus;
	for(int i = 0; i < GEN_BONUS_COUNT; ++i)
	{
		bonus = new Bonus();
		bonus->name = "Bonus " + std::to_string(i);
		bonus->position.x = (float)(rand() % 425 + 25);
		bonus->position.y = (float)(500.0f + i * 150.0f);
		// Make sure we don't go too far yo
		if(bonus->position.y > mLevelDistance) break;

		addGameObject(bonus);

		if(bonus->position.y > maxObjectDistance) maxObjectDistance = bonus->position.y;
	}


	// Add some obstacles
	Obstacle* obs;
	for(int o = 0; o < GEN_OBSTACLE_COUNT; ++o)
	{
		obs = new Obstacle();
		obs->position.x = (float)(rand() % 425 + 25);
		obs->position.y = (float)(rand() % 100 + 250 * (o + 3));
		if(obs->position.y > mLevelDistance) break;
		addGameObject(obs);
		if(obs->position.y > maxObjectDistance) maxObjectDistance = obs->position.y;
	}

	

	// Add the ground. Basically make it a straight line, except in the middle.
	// 5 on the left, 5 on the right
	Ground* tGround;
	const float groundY = mLevelDistance + 550.0f;
	//const int groundY = 350;

	for(int g = 0; g < 5; ++g)
	{
		// Make the left side
		tGround = new Ground();
		tGround->position.x = 16.0f + g * 32.0f;
		//tGround->position.y = mLevelDistance + 250.0f;
		tGround->position.y = groundY;
		addGameObject(tGround);

		// Meow make the right side
		tGround = new Ground();
		tGround->position.x = 450.0f - (16 + g * 32);
		tGround->position.y = groundY;
		addGameObject(tGround);
	}


	// Build the minimap
	mMiniMap = new MiniMap();
	mMiniMap->mDistance = maxObjectDistance;
	// TODO: Figure out what's up with the MiniMap
	//mMiniMap->preDrawObjects(mRenderables);
	
	// ******** Font dealings *********

	// Load the text font for text drawing
	mFont_ubuntu.loadFromFile("assets/fonts/UbuntuMono.ttf");

	// Display the score
	mScoreText.setCharacterSize(18);
	mScoreText.setStyle(sf::Text::Regular);
	mScoreText.setColor(sf::Color::Blue);
	mScoreText.setPosition(320.0f, 10.0f);

	mPromptText.setCharacterSize(20);
	mPromptText.setStyle(sf::Text::Regular);
	mPromptText.setPosition(250.0f, 450.0f);
	mPromptText.setColor(sf::Color::White);
	mPromptText.setOrigin(mPromptText.getLocalBounds().width * 0.5f, mPromptText.getLocalBounds().height * 0.5f);


	DEBUGTEXT.setCharacterSize(10);
	DEBUGTEXT.setStyle(sf::Text::Regular);
	DEBUGTEXT.setColor(sf::Color::Black);
	DEBUGTEXT.setPosition(5.0f, 10.0f);

	DEBUGLABELS = new std::pair<std::string, float>[3];
	DEBUGLABELS[DBG_FALLSPEED] = std::make_pair("Fallspeed: ", 0.0f);
	DEBUGLABELS[DBG_TRAVELED] = std::make_pair("Distance Traveled: ", 0.0f);
	DEBUGLABELS[DBG_PLAYER_YVEL] = std::make_pair("Player Y Velocity: ", 0.0f);
}
Пример #20
0
 //-----------------------------------------------------------------------
 void RenderQueue::addRenderable(Renderable* pRend, uint8 groupID)
 {
     addRenderable(pRend, groupID, mDefaultRenderablePriority);
 }
Пример #21
0
//-----------------------------------------------------------------------
void RenderQueue::addRenderable(Renderable* pRend, ushort priority) {
  addRenderable(pRend, mDefaultQueueGroup, priority);
}
Пример #22
0
void TestScene::load()
{
	//load skybox
	TextureCB* skybox = dynamic_cast<TextureCB*>(DDSLoader::loadDDSTex(	"Assets\\skybox\\sbrightmip.dds",
																		"Assets\\skybox\\sbleftmip.dds",
																		"Assets\\skybox\\sbupmip.dds",
																		"Assets\\skybox\\sbdownmip.dds",
																		"Assets\\skybox\\sbbackmip.dds",
																		"Assets\\skybox\\sbfrontmip.dds"));
	if (skybox != nullptr)
		addCubeMap(skybox);

	//load testmodel "uglypot"
	std::list<Model*> models = OBJLoader::loadOBJ("Assets\\Models\\uglypot.obj");
	Texture2D* wooddiff = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\wooddiff_RGBA32UI.dds"));
	Texture2D* woodspec = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodspec_RGBA32UI.dds"));
	Texture2D* woodgloss = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodgloss_RGBA32UI.dds"));
	Texture2D* woodnormal = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodnormal_RGBA32UI.dds"));
	Texture2D* woodheight = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodheight_RGBA32UI.dds"));
	Texture2D* metaldiff = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metaldiff_RGBA32UI.dds"));
	Texture2D* metalspec = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalspec_RGBA32UI.dds"));
	Texture2D* metalgloss = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalgloss_RGBA32UI.dds"));
	Texture2D* metalnormal = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalnormal_RGBA32UI.dds"));
	Texture2D* metalheight = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalheight_RGBA32UI.dds"));
	//this thing will be forward shaded
	ForwardShader* forward = new ForwardShader();
	forward->load("BaseVertex.vert", "BaseFrag.frag");
	addShader(forward);



	addTexture(wooddiff);
	addTexture(woodspec);
	addTexture(woodgloss);
	addTexture(woodnormal);
	addTexture(woodheight);
	addTexture(metaldiff);
	addTexture(metalspec);
	addTexture(metalgloss);
	addTexture(metalnormal);
	addTexture(metalheight);

	//load wood and metal material
	Material* wood = new Material();
	wood->addTexture(wooddiff);
	wood->addTexture(woodspec);
	wood->addTexture(woodgloss);
	wood->addTexture(woodnormal);
	wood->addTexture(woodheight);
	wood->setShader(forward);
	Material* metal = new Material();
	metal->addTexture(metaldiff);
	metal->addTexture(metalspec);
	metal->addTexture(metalgloss);
	metal->addTexture(metalnormal);
	metal->addTexture(metalheight);
	metal->setShader(forward);

	addMaterial(wood);
	addMaterial(metal);
	std::list<Model*>::iterator moit = models.begin();
	std::vector<Mesh*>::iterator mshit = (*moit)->getMeshes().begin();

	//2 submeshes
	(*mshit++)->setMaterial(wood);
	(*mshit)->setMaterial(metal);

	m_models.splice(end(m_models), models);
	//create an instance of this model and add it to the scene gameobjects
	RenderableGameObject* go = new RenderableGameObject();
	go->setModel(*moit);
	go->getTransform().setTranslate(glm::vec3(0.0f, 0.0f, -2.0f));
	addRenderable(go);

	//create a directional light
	DirectionalLight* dirlight = new DirectionalLight(glm::vec3(1.0f, -1.0f, -1.0f), Transform(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f)), glm::vec4(1.0f, 1.0f, 0.8f, 1.0f));
	addDirectionalLight(dirlight);

	PointLight* pointlight = new PointLight(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), Transform(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f)), 1.0f, 0.7f, 1.8f, 7.0f);
	addPointLight(pointlight);
	//create a flycam
	FPSCamera* cam = new FPSCamera(45.0f, 800, 600, 0.1f, 100.0f, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f));
	cam->Fly(true);
	cam->recalcProj();
	m_camera = cam;

	int dummy = 0;
}
Пример #23
0
void Game::onInit()
{
	m_factory.setResources(this);
	m_factory.setWorld(&m_world);
	m_factory.setGame(this);
	m_factory.init();

	m_background = loadTexture("textures/background.png");

	glGenFramebuffers(1, &m_lightFB);
	glGenTextures(1, &m_lightTexture);

	// Setup light texture

	glBindFramebuffer(GL_FRAMEBUFFER, m_lightFB);
	glBindTexture(GL_TEXTURE_2D, m_lightTexture);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 800, 600, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_lightTexture, 0);
	glBindTexture(GL_TEXTURE_2D, 0);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	const float width = 800;
	const float height = 2400;

	// Light
	{
		std::unique_ptr<Entities::Light> light(m_factory.createLight());
		light->setActive(true);
		//light->setPos(b2Vec2(width*0.5f, 150));
		light->init();
		light->body()->SetTransform(worldToPhysics(b2Vec2(70, 200)), 0);
		m_defaultLight = light.get();
		m_renderables.push_back(std::unique_ptr<Renderable>(light.release()));
	}

	// Left
	{
		std::unique_ptr<Entities::Box> testBox(m_factory.createBricks(b2Vec2(60, height), true));
		testBox->body()->SetTransform(worldToPhysics(b2Vec2(0, height*0.5f)), 0);

		m_ground = testBox.get()->body().body();
		m_renderables.push_back(std::unique_ptr<Renderable>(testBox.release()));
	}
	
	// Right
	{
		std::unique_ptr<Entities::Box> testBox(m_factory.createBricks(b2Vec2(60, height), true));
		testBox->body()->SetTransform(worldToPhysics(b2Vec2(width, height*0.5f)), 0);
		m_renderables.push_back(std::unique_ptr<Renderable>(testBox.release()));
	}

	// Bottom
	{
		std::unique_ptr<Entities::Box> testBox(m_factory.createBricks(b2Vec2(width, 60), true));
		testBox->body()->SetTransform(worldToPhysics(b2Vec2(width*0.5f, height)), 0);
		m_renderables.push_back(std::unique_ptr<Renderable>(testBox.release()));
	}	

	// Light joint
	{
		b2DistanceJointDef jointDef;
		jointDef.Initialize(m_ground, m_defaultLight->body().body(),
							b2Vec2(0, m_defaultLight->body()->GetPosition().y),
							m_defaultLight->body()->GetPosition());
		jointDef.collideConnected = true;
		m_world.CreateJoint(&jointDef);
	}

	// Supports
	for(int i = 0; i < 20; i++)
	{
		std::unique_ptr<Entities::Box> testBox(m_factory.createHalfBricks(b2Vec2(200, 20)));
		testBox->body()->SetTransform(worldToPhysics(b2Vec2(-80, -40 - 40*i)), 0);

		b2MouseJointDef jointDef;
		jointDef.maxForce = 100;
		jointDef.collideConnected = true;
		jointDef.bodyA = m_ground;
		jointDef.bodyB = testBox->body().body();
		jointDef.target = testBox->body()->GetPosition();
		testBox->setDragJoint(m_world.CreateJoint(&jointDef));

		testBox->body()->SetFixedRotation(true);

		m_renderables.push_back(std::unique_ptr<Renderable>(testBox.release()));
	}

	// Boxes
	for(int i = 0; i < 500; i++)
	{
		int row = i / 3;
		int col = i % 3;

		int xoff = col - 1;

		float xmod = (row & 1) ? 0 : 30;

		b2Vec2 pos = worldToPhysics(b2Vec2(400 + xmod + xoff*55, row*-60));

		if(!(i % 36))
		{
			std::unique_ptr<Entities::Light> light(m_factory.createLight());
			light->setScale(0.3f);
			light->init();
			light->body()->SetTransform(pos, 0);
			m_renderables.push_back(std::unique_ptr<Renderable>(light.release()));
		}
		else if((rand() / float(RAND_MAX)) > 0.99f)
		{
			std::unique_ptr<Entities::Box> testBox(m_factory.createChest());
			testBox->body()->SetTransform(pos, 0);
			addRenderable(testBox.release());	
		}
		else
		{
			std::unique_ptr<Entities::Box> testBox(m_factory.createDirt());
			testBox->body()->SetTransform(pos, 0);
			addRenderable(testBox.release());
		}
	}

	updateCamera();

	for(int i = 0; i < 600; i++)
		m_world.Step(1/60.f, 6, 2);
}
Пример #24
0
	//-----------------------------------------------------------------------
    void RenderQueue::addRenderable(Renderable* pRend)
    {
        addRenderable(pRend, mDefaultQueueGroup, mDefaultRenderablePriority);
    }
Пример #25
0
void GameScreen::resetLevel()
{
	// First re-initialize all the shit in the gamescreen constructor
	mState = GameState::PLAYING;
	//mFallSpeed = 0.0f;

	// Pwn out all the gameobjects
	while(mGameObjects.size() > 0)
	{
		removeGameObject(mGameObjects.front());
	}
	// Then clear our ALL the renderables and gameobjects
	while(mRenderables.size() > 0)
	{
		removeRenderable(mRenderables.front());
	}
	while(mDeathObjects.size() > 0)
	{
		mDeathObjects.pop_back();
	}

	// Then reset the player
	player->reset();
	// Don't forget to friggin add the player back
	addGameObject(player);

	mLevelTraveled = 0.0f;
	bgverts[0].color = bgUpStartColor;
	bgverts[1].color = bgUpStartColor;
	bgverts[2].color = bgDownStartColor;
	bgverts[3].color = bgDownStartColor;

	float maxObjectDistance = -1.0;

	// Add some clouds
	Cloud* tCloud;	
	for(int c = 0; c < GEN_CLOUD_COUNT; ++c)
	{
		tCloud = new Cloud();
		tCloud->position.x = (float)(rand() % 400 + 25);
		tCloud->position.y = (float)(rand() % 100 * c);
		if(tCloud->position.y > mLevelDistance) break;
		addRenderable(tCloud);
		if(tCloud->position.y > maxObjectDistance) maxObjectDistance = tCloud->position.y;
	}

	// Add some bonuses
	Bonus* bonus;
	for(int i = 0; i < GEN_BONUS_COUNT; ++i)
	{
		bonus = new Bonus();
		bonus->name = "Bonus " + std::to_string(i);
		bonus->position.x = (float)(rand() % 425 + 25);
		bonus->position.y = 500.0f + i * 150.0f;
		// Make sure we don't go too far yo
		if(bonus->position.y > mLevelDistance) break;

		addGameObject(bonus);

		if(bonus->position.y > maxObjectDistance) maxObjectDistance = bonus->position.y;
	}

	// Add some obstacles
	Obstacle* obs;
	for(int o = 0; o < GEN_OBSTACLE_COUNT; ++o)
	{
		obs = new Obstacle();
		obs->position.x = (float)(rand() % 425 + 25);
		obs->position.y = (float)(rand() % 250 + 100 * (o + 3));
		if(obs->position.y > mLevelDistance) break;
		addGameObject(obs);
		if(obs->position.y > maxObjectDistance) maxObjectDistance = obs->position.y;
	}

	
	// Add the ground. Basically make it a straight line, except in the middle.
	// 5 on the left, 5 on the right
	Ground* tGround;
	const float groundY = mLevelDistance + 550.0f;
	//const int groundY = 350;

	for(int g = 0; g < 5; ++g)
	{
		// Make the left side
		tGround = new Ground();
		tGround->position.x = 16.0f + g * 32;
		//tGround->position.y = mLevelDistance + 250.0f;
		tGround->position.y = groundY;
		addGameObject(tGround);

		// Meow make the right side
		tGround = new Ground();
		tGround->position.x = 450.0f - (16 + g * 32);
		tGround->position.y = groundY;
		addGameObject(tGround);
	}
	
	mMiniMap->reset();
	mMiniMap->mDistance = maxObjectDistance;

	// Resume the shitty bgm
	mSmash.stop();
	if(mBGM.getStatus() != sf::Music::Playing)
	{
		mBGM.play();
	}
}