Exemplo n.º 1
0
/*********************************************************************
 * Animates a muzzle flash billboard with firing sound and does
 * damage to borbie.  This method is only called when the soldier
 * is within range and has direct line of sight.  He has an 80%
 * chance of hitting his target.
 *********************************************************************/
void Soldier::fire(int distance){
	lastFireTime = gameInstance->getDevice()->getTimer()->getTime();
	IBillboardSceneNode * bill;
	bill = smgr->addBillboardSceneNode();
	bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
    bill->setMaterialTexture(0, driver->getTexture("assets/textures/muzFlash.png"));
	bill->setMaterialFlag(video::EMF_LIGHTING, false);
	bill->setMaterialFlag(video::EMF_ZBUFFER, false);
	float randomNum = Random::randomFloat(-10.0, 15.0);
	bill->setSize(core::dimension2d<f32>(30.0+randomNum, 30.0+randomNum));
	bill->setID(0);//not pickable by ray caster
		
	//get enemy position, adjust muzzle flash height to barrel
	vector3df start = sceneNode->getPosition();
	start.Y+=60;
	bill->setPosition(start);

    this->audioSystem->playSound3d(gameInstance->gunShot1,
	    this);
	
	const int MUZZLE_FLASH_TIME = 50;
	
	ISceneNodeAnimator* anim =
	    gameInstance->getSceneManager()->createDeleteAnimator(MUZZLE_FLASH_TIME);
	bill->addAnimator(anim);
	anim->drop();
    if (!miss(distance))
	    gameInstance->player->applyBulletDamage(BULLET_DAMAGE);
    else
        gameInstance->player->ricochet();		
}
void CRaycastTankExample::createMuzzleFlash(irr::scene::IBoneSceneNode *node)
{
    IBillboardSceneNode *muzzleFlash = device->getSceneManager()->addBillboardSceneNode(0,
        dimension2d<f32>(30.0f, 30.0f), node->getAbsoluteTransformation().getTranslation());

    muzzleFlash->setMaterialFlag(EMF_LIGHTING, false);
    muzzleFlash->setMaterialTexture(0,device->getVideoDriver()->getTexture("particlewhite.bmp"));
    muzzleFlash->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);


    ISceneNodeAnimator* deleteAnim = device->getSceneManager()->createDeleteAnimator(100);
    muzzleFlash->addAnimator(deleteAnim);
    deleteAnim->drop();
}
Exemplo n.º 3
0
/** Tests the offset capability of the fly circle animator */
bool flyCircleAnimator(void)
{
	IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO,
										core::dimension2du(160,120), 32);
	if (!device)
		return false;

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

	const f32 offsetDegrees[] = { 0.f, 45.f, 135.f, 270.f };

	for(u32 i = 0; i < sizeof(offsetDegrees) / sizeof(offsetDegrees[0]); ++i)
	{
		IBillboardSceneNode * node = smgr->addBillboardSceneNode();
		// Have the animator rotate around the Z axis plane, rather than the default Y axis
		ISceneNodeAnimator * animator = smgr->createFlyCircleAnimator(
				vector3df(0, 0, 0), 30.f, 0.001f,
				vector3df(0, 0, 1), (offsetDegrees[i] / 360.f));
		if(!node || !animator)
			return false;

		node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
		node->setMaterialTexture(0, driver->getTexture("../media/particle.bmp"));
		node->setMaterialFlag(video::EMF_LIGHTING, false);

		node->addAnimator(animator);
		animator->drop();
	}

	(void)smgr->addCameraSceneNode(0, vector3df(0, 0, -50), vector3df(0, 0, 0));

	bool result = false;

	// Don't do device->run() since I need the time to remain at 0.
	if (driver->beginScene(true, true, video::SColor(0, 80, 80, 80)))
	{
		smgr->drawAll();
		driver->endScene();
		result = takeScreenshotAndCompareAgainstReference(driver, "-flyCircleAnimator.png", 100);
	}

	device->closeDevice();
	device->run();
	device->drop();

	return result;
}
Exemplo n.º 4
0
/** The result should be as follows: We have three times the same image, a billboard with a cube and the text in front.
They are replicated three times, one centered in the screen without viewport, one in the upper left (qurter screen) and
one on the right (half screen). The latter is stretched due to the changed aspect ratio.
The two viewport scenes get the texture drawn over the center as well, using draw2dimage. This should mark the proper
image position with the top left corner of the texture.
Finally, each scene has a checkbox drawn at the left side, vertically centered. This will show whether GUI elements adhere
to viewports as well. */
static bool viewPortText(E_DRIVER_TYPE driverType)
{
	IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);
	if (!device)
		return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager * smgr = device->getSceneManager();
	IGUIEnvironment* env = smgr->getGUIEnvironment();

	stabilizeScreenBackground(driver);

	env->addCheckBox(true, core::recti(10,60,28,82));

	logTestString("Testing driver %ls\n", driver->getName());

	IBillboardSceneNode * bnode = smgr->addBillboardSceneNode(0,dimension2d<f32>(32,32),core::vector3df(0,0,10));
	bnode->setMaterialFlag(video::EMF_LIGHTING, false);
	bnode->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
	bnode->setMaterialTexture(0, driver->getTexture("../media/fire.bmp"));

	smgr->addTextSceneNode(device->getGUIEnvironment()->getBuiltInFont(), L"TEST", video::SColor(255,255,255,255), 0);
	smgr->addCubeSceneNode();
	smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

	driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(255,100,101,140));
	smgr->drawAll();
	env->drawAll();
	driver->setViewPort(rect<s32>(0,0,160/2,120/2));
	smgr->drawAll();
	env->drawAll();
	driver->draw2DImage(driver->getTexture("../media/fire.bmp"), core::vector2di(160/2,120/2));
	driver->setViewPort(rect<s32>(160/2,0,160,120));
	smgr->drawAll();
	env->drawAll();
	driver->draw2DImage(driver->getTexture("../media/fire.bmp"), core::vector2di(160/2,120/2));
	driver->endScene(); 

	bool result = takeScreenshotAndCompareAgainstReference(driver, "-viewPortText.png", 98.71f);

	device->closeDevice();
	device->run();
	device->drop();

	return result;
}
Exemplo n.º 5
0
void loop(s4 &game_state)
{
    ICameraSceneNode* camera = irrlicht->smgr->addCameraSceneNode();
    matrix4 ortho;
    ortho.buildProjectionMatrixOrthoLH(
        irrlicht->driver->getScreenSize().Width/ortho_scale,
        irrlicht->driver->getScreenSize().Height/ortho_scale,-1.0,1000.0);
    camera->setProjectionMatrix(ortho);
    camera->setPosition({0,0,-100});
    camera->setTarget({0,0,0});

    irrlicht->hud->setActiveCamera(camera);

    IBillboardSceneNode* qnode = irrlicht->smgr->addBillboardSceneNode();
    qnode->setMaterialFlag(EMF_WIREFRAME,true);

    // --------------------------------------
 
    p("---- Game loop start ----");

    d32         dt = 0.0f;
    const d32   maxDelta = 1.0f/60.0f * 5.0f; 
    const d32   tick_ms = 0.01666f; // TODO: change this back to 30ms?
    d32         render_dt = 0.0f;
    const d32   render_ms = RENDER_TIME_STEP;
    uint32      time_physics_prev = btclock->getTimeMicroseconds();

    while(irrlicht->device->run() && game_state == GAME_STATE_PLAY)
    {
        const uint32 time_physics_curr = btclock->getTimeMicroseconds();
        const d32 frameTime = ((d32)(time_physics_curr - time_physics_prev)) / 1000000.0; // todo: is this truncated correctly?
        time_physics_prev = time_physics_curr;
        d32 capped_dt = frameTime;
        if (capped_dt > maxDelta) { capped_dt = maxDelta; }

        render_dt += capped_dt;
        if ( render_dt >= render_ms )
        {
            render_dt = 0.0f;

            update_player();
            update_enemies();
            update_missiles(ply->missiles,ply->num_missile);

            irrlicht->hud->getRootSceneNode()->setPosition(camera->getPosition() + vector3df(0,0,100));

            irrlicht->driver->beginScene(true, true, SColor(255,59,120,140));
            irrlicht->smgr->drawAll();  
            irrlicht->driver->clearZBuffer(); 
            irrlicht->hud->drawAll();

            irrlicht->driver->endScene();
        }

        dt += capped_dt;
        while( dt >= tick_ms ) 
        {
            dt -= tick_ms;
            receiver->input();

            clear_quads(quadtree);
            step_player();
            step_enemies();
            step_missiles(ply->missiles, ply->num_missile); 

            QuadTree::Quad* fq = get_quad_from_pos(quadtree,ply->curr_pos);
            qnode->setSize(dimension2d<f32>(1,1));
            qnode->setPosition(fq->pos.irr());
            qnode->setSize(dimension2d<f32>(fq->width,fq->width));
 
            if (receiver->debug_key.state)
            {
                for (s4 i = 0; i < fleet->num_squad; i++)
                {
                    if (fleet->squads[i].mode != scatter)
                        fleet->squads[i].mode = scatter;
                    else
                        fleet->squads[i].mode = to_positions;
                }
            }
            if (receiver->restart.state) { game_state = GAME_STATE_RESET; return; }
            if (receiver->QUIT) { game_state = GAME_STATE_QUIT; return; }

            empty_transient_soft(memory);
        }

        alpha = dt / tick_ms;

        core::stringw str = L"Coquelicot // score: ";
        str += score;
        str += L" // FPS: ";
        str += (s32)irrlicht->driver->getFPS();
        irrlicht->device->setWindowCaption(str.c_str());
    } 
}