Пример #1
0
void CreateSmallFireballOnObject (CObject *objP, fix size_scale, int bSound)
{
	fix			size;
	CFixVector	vPos, vRand;
	short			nSegment;

vPos = objP->info.position.vPos;
vRand = CFixVector::Random();
vRand *= (objP->info.xSize / 2);
vPos += vRand;
size = FixMul (size_scale, I2X (1) / 2 + d_rand () * 4 / 2);
nSegment = FindSegByPos (vPos, objP->info.nSegment, 1, 0);
if (nSegment != -1) {
	CObject *explObjP = /*Object*/CreateExplosion (nSegment, vPos, size, VCLIP_SMALL_EXPLOSION);
	if (!explObjP)
		return;
	AttachObject (objP, explObjP);
	if (bSound || (d_rand () < 8192)) {
		fix vol = I2X (1) / 2;
		if (objP->info.nType == OBJ_ROBOT)
			vol *= 2;
		audio.CreateObjectSound (SOUND_EXPLODING_WALL, SOUNDCLASS_EXPLOSION, objP->Index (), 0, vol);
		}
	}
}
Пример #2
0
void CVTOLVehicleManager::DestroyVTOL(IEntity *pVTOL, SVTOLInfo &info)
{
	const Matrix34& mat = pVTOL->GetWorldTM();
	const float k_offsetDist = 5.0f;

	CreateExplosion(m_pExplosionEffect, mat.GetTranslation(), 2.0f, m_explosionSignalId);
	CreateExplosion(m_pExplosionEffect, mat.TransformPoint(Vec3(0.f, k_offsetDist, 0.f)), 2.0f);
	CreateExplosion(m_pExplosionEffect, mat.TransformPoint(Vec3(0.f,-k_offsetDist, 0.f)), 2.0f);

	//Hide existing vehicle
	pVTOL->SetPos(Vec3(0.f,0.f,0.f));
	pVTOL->Hide(true);
	info.state = EVS_Invisible;
	info.stateTime = 0.f;  // this may allow clients to do their own respawn handling, stopping the need for respawned RMI below

	//Remove from HUD radar
	SHUDEvent hudEvent(eHUDEvent_RemoveEntity);
	hudEvent.AddData((int)pVTOL->GetId());
	CHUDEventDispatcher::CallEvent(hudEvent);
}
Пример #3
0
Object CreateObject(Vector2 pos, float r, ALLEGRO_BITMAP* obj_bitmap, ALLEGRO_BITMAP* exp_bitmap)
{
    Object object;
    object.pos = pos;
    object.vel = CreateVector2(0, 0);
    object.acc = CreateVector2(0, 0);
    object.r = r;
    object.d = 2 * r;
    object.first_update = true;

    // inicjalizujemy obiekt eksplozji (parametry na podstawie pliku graficznego):
    object.explosion = CreateExplosion(CreateAnimation(object.pos, 38, 1, CreateSize(128, 128), CreateSize(object.d * 4, object.d * 4), exp_bitmap));
    object.entrance_animation.active = false;

    object.bitmap = obj_bitmap;

    return object;
}
Пример #4
0
void CreateVClipOnObject (CObject *objP, fix xScale, ubyte nVClip)
{
	fix			xSize;
	CFixVector	vPos, vRand;
	short			nSegment;

vPos = objP->info.position.vPos;
vRand = CFixVector::Random();
vRand *= (objP->info.xSize / 2);
vPos += vRand;
xSize = FixMul (xScale, I2X (1) + d_rand ()*4);
nSegment = FindSegByPos (vPos, objP->info.nSegment, 1, 0);
if (nSegment != -1) {
	CObject *explObjP = /*Object*/CreateExplosion (nSegment, vPos, xSize, nVClip);
	if (!explObjP)
		return;

	explObjP->info.movementType = MT_PHYSICS;
	explObjP->mType.physInfo.velocity = objP->mType.physInfo.velocity * (I2X (1) / 2);
	}
}
Пример #5
0
void keyboard_s (int key, int x, int y)
{
    switch (key)
    {
        case GLUT_KEY_F1:
            ll = ll - 50;
            break;

        case GLUT_KEY_F2:
            ll = ll + 50;
            break;

        case GLUT_KEY_F3:
            CreateExplosion();
            break;

        case GLUT_KEY_LEFT:
            px = px - 10;
            if(side > -30)
            side = side - 2;
            break;

        case GLUT_KEY_RIGHT:
            px = px + 10;
            if(side < 30)
            side = side + 2;
            break;

        case GLUT_KEY_PAGE_UP:
            pz = pz + 50;
            break;

        case GLUT_KEY_PAGE_DOWN:
            pz = pz - 50;
            break;
            break;

    }
}
Пример #6
0
void Asteroids::OnPlayerKilled(int lives_left)
{
    SmartPtr<GameObject> explosion = CreateExplosion();
    explosion->SetPosition(mSpaceship->GetPosition());
    explosion->SetRotation(mSpaceship->GetRotation());
    mGameWorld->AddObject(explosion);
    // Format the lives left message using an string-based stream`
    std::ostringstream msg_stream;
    msg_stream << "Lives: " << lives_left;
    // Get the lives left message as a string
    std::string lives_msg = msg_stream.str();
    mLivesLabel->SetText(lives_msg);

    if (lives_left > 0)
    {
        SetTimer(1000, CREATE_NEW_PLAYER);
    }
    else
    {
        SetTimer(500, SHOW_GAME_OVER);
    }
}
void InducedExplosion(
	float ex0[], float ey0[],  // 적기의 좌상좌표
	float ex1[], float ey1[],  // 적기의 우하좌표
	int num_enemy,             // 적기의 갯수
	float x0[], float y0[],    // 후폭풍의 좌상좌표
	float x1[], float y1[],    // 후폭풍의 우하좌표
	int num_explosion          // 후폭풍의 갯수
) {
	// 적기와 후폭풍의 접촉 판정 처리:
	// 모든 적기와 후폭풍간에 접촉 판정 처리를 수행하고
	// 적기가 폭풍에 닿았다면 파괴시킴.
	// 그리고, 적기가 사라진 자리에 새로운 후폭풍을 생성함.
	// 파괴와 생성의 구체적인 처리는
	// DestroyEnemy, CreateExplosion 함수에서 수행하기로 함.
	for (int i=0; i<num_enemy; i++) {
		for (int j=0; j<num_explosion; j++) {
			if (ex0[i]<x1[j] && x0[j]<ex1[i] && 
				ey0[i]<y1[j] && y0[j]<ey1[i]) {
				DestroyEnemy(i);
				CreateExplosion(ex0[i], ey0[i]);
			}
		}
	}
}
Пример #8
0
//	-----------------------------------------------------------------------------
//if an effect is hit, and it can blow up, then blow it up
//returns true if it blew up
int CSegment::CheckEffectBlowup (int nSide, CFixVector& vHit, CObject* blowerP, int bForceBlowup)
{
	int				tm, tmf, ec, nBitmap = 0;
	int				bOkToBlow = 0, nSwitchType = -1;
	short				nSound, bPermaTrigger;
	ubyte				vc;
	fix				u, v;
	fix				xDestSize;
	tEffectClip*	ecP = NULL;
	CBitmap*			bmP;
	CWall*			wallP;
	CTrigger*		trigP;
	CObject*			parentP = (!blowerP || (blowerP->cType.laserInfo.parent.nObject < 0)) ? NULL : OBJECTS + blowerP->cType.laserInfo.parent.nObject;
	//	If this CWall has a CTrigger and the blowerP-upper is not the CPlayerData or the buddy, abort!

if (parentP) {
	if ((parentP->info.nType == OBJ_ROBOT) && ROBOTINFO (parentP->info.nId).companion)
		bOkToBlow = 1;
	if (!(bOkToBlow || (parentP->info.nType == OBJ_PLAYER)) &&
		 ((wallP = Wall (nSide)) && (wallP->nTrigger < gameData.trigs.m_nTriggers)))
		return 0;
	}

if (!(tm = m_sides [nSide].m_nOvlTex))
	return 0;

tmf = m_sides [nSide].m_nOvlOrient;		//tm flags
ec = gameData.pig.tex.tMapInfoP [tm].nEffectClip;
if (ec < 0) {
	if (gameData.pig.tex.tMapInfoP [tm].destroyed == -1)
		return 0;
	nBitmap = -1;
	nSwitchType = 0;
	}
else {
	ecP = gameData.eff.effectP + ec;
	if (ecP->flags & EF_ONE_SHOT)
		return 0;
	nBitmap = ecP->nDestBm;
	if (nBitmap < 0)
		return 0;
	nSwitchType = 1;
	}
//check if it's an animation (monitor) or casts light
bmP = gameData.pig.tex.bitmapP + gameData.pig.tex.bmIndexP [tm].index;
LoadBitmap (gameData.pig.tex.bmIndexP [tm].index, gameStates.app.bD1Data);
//this can be blown up...did we hit it?
if (!bForceBlowup) {
	HitPointUV (nSide, &u, &v, NULL, vHit, 0);	//evil: always say face zero
	bForceBlowup = !PixelTranspType (tm, tmf,  m_sides [nSide].m_nFrame, u, v);
	}
if (!bForceBlowup)
	return 0;

if (IsMultiGame && netGame.bIndestructibleLights && !nSwitchType)
	return 0;
//note: this must get called before the texture changes,
//because we use the light value of the texture to change
//the static light in the CSegment
wallP = Wall (nSide);
bPermaTrigger = (trigP = Trigger (nSide)) && (trigP->flags & TF_PERMANENT);
if (!bPermaTrigger)
	SubtractLight (Index (), nSide);
if (gameData.demo.nState == ND_STATE_RECORDING)
	NDRecordEffectBlowup (Index (), nSide, vHit);
if (nSwitchType) {
	xDestSize = ecP->xDestSize;
	vc = ecP->nDestVClip;
	}
else {
	xDestSize = I2X (20);
	vc = 3;
	}
/*Object*/CreateExplosion (short (Index ()), vHit, xDestSize, vc);
if (nSwitchType) {
	if ((nSound = gameData.eff.vClipP [vc].nSound) != -1)
		audio.CreateSegmentSound (nSound, Index (), 0, vHit);
	if ((nSound = ecP->nSound) != -1)		//kill sound
		audio.DestroySegmentSound (Index (), nSide, nSound);
	if (!bPermaTrigger && (ecP->nDestEClip != -1) && (gameData.eff.effectP [ecP->nDestEClip].nSegment == -1)) {
		tEffectClip	*newEcP = gameData.eff.effectP + ecP->nDestEClip;
		int nNewBm = newEcP->changingWallTexture;
		if (ChangeTextures (-1, nNewBm)) {
			newEcP->xTimeLeft = EffectFrameTime (newEcP);
			newEcP->nCurFrame = 0;
			newEcP->nSegment = Index ();
			newEcP->nSide = nSide;
			newEcP->flags |= EF_ONE_SHOT | ecP->flags;
			newEcP->flags &= ~EF_INITIALIZED;
			newEcP->nDestBm = ecP->nDestBm;

			Assert ((nNewBm != 0) && (m_sides [nSide].m_nOvlTex != 0));
			m_sides [nSide].m_nOvlTex = nNewBm;		//replace with destoyed
			}
		}
	else {
		Assert ((nBitmap != 0) && (m_sides [nSide].m_nOvlTex != 0));
		if (!bPermaTrigger)
			m_sides [nSide].m_nOvlTex = nBitmap;		//replace with destoyed
		}
	}
else {
	if (!bPermaTrigger)
		m_sides [nSide].m_nOvlTex = gameData.pig.tex.tMapInfoP [tm].destroyed;
	//assume this is a light, and play light sound
	audio.CreateSegmentSound (SOUND_LIGHT_BLOWNUP, Index (), 0, vHit);
	}
return 1;		//blew up!
}
Пример #9
0
/**********************************************************
 *
 * SUBROUTINE mover()
 *
 * Used to used  to move the movable objects at a set interval
 *
 *********************************************************/
void mover(int toggle)
{

    int i;

    update_animation();

    // move stars
    for ( i = 0; i < NUM_STAR; i++ )
    {
        if(star[i].z > 3000)
        {
            star[i].z = -6000;
            star[i].x = -3000 + (rand() % 6001);
            star[i].y = -2000 + (rand() % 4001);
        }
        star[i].z = star[i].z + 40;
    }
    if(jump)
    {
        if(py < 100)
        {
            py += 10;
            descend = 0;
        }
        else
        {
            jump = 0;
            descend = 1;
        }
    }

    if(descend)
    {
        if(py > -10)
        {
            py -= 10;
            jump = 0;
        }
        else
        {
            descend = 0;
            jump = 0;
        }
    }

    // move enemy
    ez = ez + 50;

    if(ez > 3000)
    {
        ez = -6000;
        ex = (rand() % 201);
        ey = -10;
    }

    // move road
    road_z += 40;


    if(road_z > 6000)
    {
        road_z = -6000;
        road_x = 0;
        road_y = 0;

    }

    //move wall make sure that enemy and the walls don't collide
    wall_z  += 40;

    if(wall_z > 3500)
    {
        wall_z = -6000;
        wall_x = (ex + rand()) % 201;
        wall_y = -10;

    }
    // move bullet and check for kill

    if(bullet == 1 && space == 1)
    {
        bz = bz - 300;
        if(bz < -7000) bullet = 0;

        //check if bullet hit enemy spaceship
        if(bx > ex-prs && bx < ex+prs && by > ey-prs && by < ey+prs && bz > ez-200 && bz < ez+200 )
        {
            fx = 0;
            fy = 0;
            fz = -12;
            ez = 4000;
            // make explosion if hit by bullet
            flag1++;
            if(flag2 - flag1 > 20)
            {
                CreateExplosion ();
                Mix_PlayMusic(blast,0);
                score = score + 100;
                flag1 = 0;
                flag2 = 1;
            }
        }
    }

    flag2++;

    //  Toggle movement
    if (toggle>0)
    move = !move;
    //  Increment light position
    else
    zh = (zh+5)%360;

    if(side < 0) side = side + 1;
    if(side > 0) side = side - 1;

    if(up < 0) up = up + 1;
    if(up > 0) up = up - 1;

    //  Animate flight using Lorenz transform
    Ex = -2*dim*Sin(th)*Cos(ph);
    Ey = +2*dim        *Sin(ph);
    Ez = +2*dim*Cos(th)*Cos(ph);
    Ox = Oy = Oz = 0;
    X = Y = Z = 0;
    Dx = 1; Dy = 0; Dz = 0;
    Ux = 0; Uy = 1; Uz = 0;

    //  Set timer to go again
    if (move && toggle>=0) glutTimerFunc(50,mover,0);
    //  Tell GLUT it is necessary to redisplay the scene
    glutPostRedisplay();
}
Пример #10
0
/**********************************************************
 *
 * SUBROUTINE display()
 *
 * This is our main rendering subroutine, called each frame
 *
 *********************************************************/
void display(void)
{
    int i;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue


    width =  glutGet(GLUT_WINDOW_WIDTH);
    height = glutGet(GLUT_WINDOW_HEIGHT);

    glWindowPos2i(width - 100, height - 15);

    if(enter && flag3)
    {
        SwitchGameplay(2);
        glFlush(); // This force the execution of OpenGL commands
        glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer
        return;
    }

    Print("Score: %d", score);
    if(over)
    {
        SwitchGameplay(1);
        glFlush(); // This force the execution of OpenGL commands
        glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer
        return;
    }
    //  Erase the window and the depth buffer
    glClearColor(0,0.3,0.7,0);


    Background(3.5*dim); // draw space like looking texture
    gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f,10000.0f);
    glMatrixMode(GL_MODELVIEW); // Modeling transformation
    glLoadIdentity(); // Initialize the model matrix as identity
    //  Perspective - set eye position
    gluLookAt(Ex,Ey,Ez , Ox,Oy,Oz , Ux,Uy,Uz);



    for ( i = 0; i < NUM_STAR; i++ )
    {
        stars(star[i].x, star[i].y, star[i].z, star[i].a, star[i].b, star[i].c);
    }

    // draw laser cannon if fired
    if(bullet == 1 && space == 1)
    {
        laser_bullet(bx,by,bz,5,5,400);
    }

    // check if spaceship is hit by enemy
    if(px > ex-40 && px < ex+40 && py > ey-40 && py < ey+40 && pz > ez-40 && pz < ez+40 )
    {
        space = 0;
        CreateExplosion ();
        Mix_PlayMusic(blast,0);
        over = 1;
        enemy = 0;
    }
    // Check if spaceship hits the wall
    if(px >= wall_x-100 && px <= wall_x+100 && py >= wall_y-30 && py <= wall_y+10 && pz >= wall_z-100 && pz <= wall_z+100 )
    {
        space = 0;
        CreateExplosion ();
        Mix_PlayMusic(blast,0);
        over = 1;
    }

    // gravity, check if the spaceship fell off the road
    if( (px > 200 || px < -200) )
    {
        py -= 5;

        if( py < -40)
        {
            space = 0;
            gravity = 1;
            CreateExplosion ();
            Mix_PlayMusic(blast,0);
            over = 1;
        }
    }


    if(space)
    spaceship(px, py, pz, -90+up, side, 180,0.85,0.85,0.85);

    if(enemy == 1)
    spaceship(ex, ey, ez, -90, 0, 0,1,1,1);

    glLoadIdentity();
    glTranslatef(fx,fy,fz);

    if (fuel > 0)
    {
        glPushMatrix ();

        glBegin (GL_POINTS);

        for (i = 0; i < NUM_PARTICLES; i++)
        {
            glColor3fv (particles[i].color);
            glVertex3fv (particles[i].position);
        }

        glEnd ();

        for (i = 0; i < NUM_DEBRIS; i++)
        {
            glPushMatrix ();

            glTranslatef (debris[i].position[0],
            debris[i].position[1],
            debris[i].position[2]);

            glRotatef (debris[i].orientation[0], 1.0, 0.0, 0.0);
            glRotatef (debris[i].orientation[1], 0.0, 1.0, 0.0);
            glRotatef (debris[i].orientation[2], 0.0, 0.0, 1.0);

            glScalef (debris[i].scale[0],
            debris[i].scale[1],
            debris[i].scale[2]);

            glBegin (GL_TRIANGLES);
            glColor3f(((float) rand ()) / ((float) RAND_MAX), ((float) rand ()) / ((float) RAND_MAX), 0.3);
            glVertex3f (0.0, 0.5, 0.0);
            glVertex3f (-0.25, 0.0, 0.0);
            glVertex3f (0.25, 0.0, 0.0);
            glEnd ();

            glPopMatrix ();
        }
    }


    Road(road_x, road_y, road_z);
    wall(wall_x, wall_y, wall_z);

    glFlush(); // This force the execution of OpenGL commands
    glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer


    flag3++;
}
Пример #11
0
ParticleComponent* ParticleFactory::CreateParticleSystem(ParticlePrefabs prefab, GameObject* object, IScene* scene)
{
	switch (prefab)
	{
	case ParticleFactory::PointFire:
		{
			std::shared_ptr<ParticlePointEmitter> emitter = std::make_shared<ParticlePointEmitter>
				(ParticlePointEmitter(90, physx::PxVec3(0.0f, 0.0f, 0.0f), 
				physx::PxVec3(-0.7f, 1.0f, -0.70f).getNormalized(), physx::PxVec3(0.70f, 1.0f, 0.70f).getNormalized(),
				0.0f, 1.50f, 2.50f));
			return CreateFireEffect(emitter, object, scene);

			
		}
		break;
	case ParticleFactory::SphereFire:
		{
			std::shared_ptr<SphereEmitter> emitter = std::make_shared<SphereEmitter>
				(SphereEmitter(90, physx::PxVec3(0.0f), 0.0f, 0.15f, 0.250f, true, 0.40f, true));
			return CreateFireEffect(emitter, object, scene);
			
		}
		break;
	case ParticleFactory::PointSmoke:
		{
			std::shared_ptr<ParticlePointEmitter> emitter = std::make_shared<ParticlePointEmitter>
				(ParticlePointEmitter(90, physx::PxVec3(0.0f, 0.10f, 0.0f), 
				physx::PxVec3(-0.5f, 1.0f, -0.50f).getNormalized(), physx::PxVec3(0.50f, 1.0f, 0.50f).getNormalized(),
				0.0f, 1.50f, 2.50f));
			return CreateSmokeEffect(emitter, object, scene);
			
		}
		break;
	case ParticleFactory::SphereSmoke:
		{
			std::shared_ptr<SphereEmitter> emitter = std::make_shared<SphereEmitter>
				(SphereEmitter(90, physx::PxVec3(0.0f), 0.0f, 0.25f, 0.50f, true, 0.50f, false));
			return CreateSmokeEffect(emitter, object, scene);
		}
		break;
	case ParticleFactory::WaterMist:
		return CreateWaterMistEffect(object, scene);
		break;
	case ParticleFactory::EarthExplosion:
		return CreateExplosion(physx::PxVec4(0.410f, 0.41f, 0.41f, 0.8f),
			physx::PxVec4(0.55f, 0.27f, 0.062f, 0.0f),
			object, scene);
		break;
	case ParticleFactory::FireExplosion:
		return CreateExplosion(physx::PxVec4(1.0f, 0.3f, 0.0f, 1.0f), 
			physx::PxVec4(1.0f, 0.0f, 0.0f, 0.20f),
			object, scene);
		break;
	case ParticleFactory::WaterExplosion:
		return CreateExplosion(physx::PxVec4(0.3f, 0.0f, 1.0f, 1.0f), 
			physx::PxVec4(0.0f, 0.0f, 1.0f, 0.20f),
			object, scene);
		break;
	default:
		return nullptr;
		break;
	}
}
Пример #12
0
void Object::Killed(Event *ev)
{
	Entity * ent;
	Entity * attacker;
	Vector dir;
	Event * event;
	const char * name;
	
	takedamage = DamageNo;
	setSolidType( SOLID_NOT );
	hideModel();
	
	attacker	= ev->GetEntity( 1 );
	
	if (flags & FlagDieExplode)
	{
		CreateExplosion( origin, 50.0f, this, this, this );
	}
	
	if (flags & FlagDieGibs)
	{
		setSolidType( SOLID_NOT );
		hideModel();
		
		CreateGibs( this, -150.0f, edict->s.scale, 3 );
	}
	
	//
	// kill the killtargets
	//
	name = KillTarget();
	if ( name && strcmp( name, "" ) )
	{
		ent = NULL;
		do
		{
			ent = G_FindTarget( ent, name );
			if ( !ent )
			{
				break;
			}
			ent->PostEvent( EV_Remove, 0.0f );
		}
		while ( 1 );
	}
	
	//
	// fire targets
	//
	name = Target();
	if ( name && strcmp( name, "" ) )
	{
		ent = NULL;
		do
		{
			ent = G_FindTarget( ent, name );
			if ( !ent )
			{
				break;
			}
			event = new Event( EV_Activate );
			event->AddEntity( attacker );
			ent->ProcessEvent( event );
		}
		while ( 1 );
	}
	
	PostEvent( EV_Remove, 0.0f );
}
Пример #13
0
bool FrameFunc()
{
	float delta = hge->Timer_GetDelta();



	if (hge->Input_KeyDown(VK_F5))
		Save_Game();
	if (hge->Input_KeyDown(VK_F6))
		Load_Game();



	//Background
	if(g_vBGPosition.x> 0) g_vBGPosition.x -= BACKGROUND_SCROLLING_SPEED;
	else g_vBGPosition	= hgeVector(1780,0);

	if (hge->Input_KeyDown(VK_ESCAPE))
		isMenuActivate = !isMenuActivate;
	if (isMenuActivate)
	{
		int id = gui->Update(delta);
		switch (id)
		{
		case 1:
			isMenuActivate = false;
			break;
		case 2:
			Load_Game();
			isMenuActivate = false;
			break;
		case 3:
			Save_Game();
			break;
		case 4:
			MessageBox(0, (LPCSTR)"This game was created by \nMOROZOV Dima(Kypoptnik/mimmimmimmim\n)", (LPCSTR)"Credits", WM_CLOSE);
			break;

		case 5: return true;
		}
		return false;
	}


	//Explosionsdeleteanimation
	for(auto i = Explosions.begin(); i != Explosions.end();)
	{
		if((*i).Animation->GetFrame() == 2)
		{
			delete (*i).Animation;
			i = Explosions.erase(i);
		}
		else 
		{
			(*i).Animation->Update(delta);
			i++;
		}
	}
		double nitr=0.18;
	//Enemies 
	int ij=1;
	if (score>10){
	nitr=nitr+0.04;
	ij++;}
	if(score>50)
		{
	nitr=nitr+0.04;
		ij++;}
	if(score>100)
		{
	nitr=nitr+0.04;
		ij++;}
	if(score>200)
		{
	nitr=nitr+0.04;
		ij++;}
	if(score>500)
		{
	nitr=nitr+0.04;
		ij++;}
	if(score>1000)
		{
	nitr=nitr+0.04;
		ij++;}
	if(score>1500)
		{
		nitr=nitr+0.04;
		ij++;}
	level=ij;


	
	for (int i=Enemies.size();i < ij;i++)
	{

		enemy* Enemy = new enemy(hgeVector(hge->Random_Int(1200,1690), hge->Random_Int(60,530)), 
								hgeVector(-hge->Random_Int(1,7), hge->Random_Int(-3,2)),
								g_tEColors[hge->Random_Int(0,4)],
								(nitr));
		Enemies.push_back(Enemy);
	}

	for(auto i = Enemies.begin(); i != Enemies.end();)
	{
		if((*i)->GetPosition().x < -	100 || (*i)->GetPosition().y > 1680 || (*i)->GetPosition().y < 20)
		{
			score++;
			delete (*i);
			i = Enemies.erase(i);
		}
		else
		{
			(*i)->Update(delta);
			i++;
		}
	}
	
	//Player
	Player1->Update(delta);

	//Enemy vs Player
	for(auto i = Enemies.begin(); i != Enemies.end();) //
	{
		if((*i)->GetBoundingBox().Intersect(&Player1->GetBoundingBox()))  //Intersect _ проверяет координаты
		{
			CreateExplosion((*i)->GetPosition());
			score-=8;

			delete (*i);
			i = Enemies.erase(i);

			Player1->SetPosition(hgeVector(150,268));
			Player1->SetVelocity(hgeVector(0,0));
		}
		else i++;
	}

	//Enemy vs Enemy

	for(int i =0; i<Enemies.size(); i++) //
	{
		for (int j= i+1; j<Enemies.size();j++)
		{
			if(Enemies[i]->GetBoundingBox().Intersect(&(Enemies[j]->GetBoundingBox())))  //Intersect _ проверяет координаты
			{
				//CreateExplosion((*i)->GetPosition());
				CreateExplosion((Enemies[i])->GetPosition());
				delete (Enemies[j]);
				Enemies.erase(Enemies.begin()+j);
				delete (Enemies[i]);
				Enemies.erase(Enemies.begin()+i);
				break;
				break;
			}
		}
	}


	//Score
	if(score<=0)
	{
		score =0;
	}
	return false;


}
Пример #14
0
void Asteroids::OnObjectRemoved(GameWorld* world, SmartPtr<GameObject> object)
{
    if (object->GetType() == GameObjectType("Asteroid"))
    {
        SmartPtr<GameObject> explosion = CreateExplosion();
        explosion->SetPosition(object->GetPosition());
        explosion->SetRotation(object->GetRotation());
        mGameWorld->AddObject(explosion);

        mAsteroidCount--;

        if(object->GetScale() > 0.2) {
            float newVel[4][2] = { {-1.0,-1.0}, { 1.0,-1.0},
                                   { 1.0, 1.0}, {-1.0, 1.0} };
            GLVector3f obPos = object->GetPosition();

            for(int i = 0; i < 4; i++)
            {
                SmartPtr<GameObject> newAsteroid = CreateAsteroid(obPos.x, obPos.y);
                float f = 5;    //force
                newAsteroid->SetVelocity(GLVector3f(newVel[i][0] * f + (rand() % 4), newVel[i][1] * f + (rand() % 4), 0.0));
                newAsteroid->SetScale(object->GetScale()/2);
                mGameWorld->AddObject(newAsteroid);
                mAsteroidCount++;
            }
        }

        if (mAsteroidCount <= 0)
        {
            SetTimer(500, START_NEXT_LEVEL);
        }
    }
    if (object->GetType() == GameObjectType("AsteroidOre"))
    {
        SmartPtr<GameObject> explosion = CreateExplosion();
        explosion->SetPosition(object->GetPosition());
        explosion->SetRotation(object->GetRotation());
        mGameWorld->AddObject(explosion);

        float newPos[4][2] = { {-1.0,-1.0}, { 1.0,-1.0},
                               { 1.0, 1.0}, {-1.0, 1.0} };
        GLVector3f obPos = object->GetPosition();
        float obRot = object->GetRotation();
        int sep = 5; // how much to separate the ore fromt he position of the asteroid

        for(int i = 0; i < 4; i++)
        {
            SmartPtr<GameObject> ore = CreateOre();
            ore->SetPosition(GLVector3f(obPos.x + newPos[i][0] * sep + (rand() % 4), obPos.y + newPos[i][1] * sep + (rand() % 4), 0.0));
            ore->SetRotation(obRot);
            mGameWorld->AddObject(ore);
        }

        int noA = 1 + (rand() % 3);
        cout << "RAND A: " << noA << endl;

        for (int i = 0; i < noA; i++)
        {
            SmartPtr<GameObject> newAsteroid = CreateAsteroid(obPos.x, obPos.y);
            float rA = rand() % 360; // a random angle
            cout << "RAND ANGLE: " << rA << endl;
            newAsteroid->SetVelocity(GLVector3f( cos(DEG2RAD * rA), sin(DEG2RAD * rA), 0.0));
            cout << "Object Scale: " << object->GetScale() << endl;
            newAsteroid->SetScale(object->GetScale());
            mGameWorld->AddObject(newAsteroid);
            mAsteroidCount++;
        }
    }
}
Пример #15
0
void Explosion::Update()
{
	if (!g_pServerDE) return;

	g_pServerDE->SetNextUpdate(m_hObject, 0.01f);

	// Init
	if (m_bFirstUpdate)
	{
		m_bFirstUpdate = DFALSE;
		m_fStartTime = g_pServerDE->GetTime();

		DVector vPos;
		g_pServerDE->GetObjectPos(m_hObject, &vPos);

		CreateExplosion(&vPos);
		return;
	}

	DFLOAT fTime = g_pServerDE->GetTime() - m_fStartTime;

	// Remove everything if we're done.
	if (fTime > m_fDuration)
	{
		if (m_hLight) g_pServerDE->RemoveObject(m_hLight);
		if (m_hModel) g_pServerDE->RemoveObject(m_hModel);
		g_pServerDE->RemoveObject(m_hObject);
		return;
	}

	DFLOAT fMul = (fTime / m_fDuration);
	// Square it to give a curve to the rise
	fMul = (DFLOAT)pow(fMul, 0.4);
	
	// Scale the model
	if (m_hModel)
	{
		DVector vScale, vDims;

		vScale.x = m_fMinScale + (fMul * (m_fMaxScale - m_fMinScale));
		vScale.y = vScale.z = vScale.x;

		g_pServerDE->GetObjectDims( m_hModel, &vDims );
		VEC_MUL( vDims, vDims, vScale);
//		g_pServerDE->SetObjectDims( m_hModel, &vDims );
		g_pServerDE->ScaleObject(m_hModel, &vScale);
	}

	DFLOAT fScaleUDur = m_fDuration*0.75f;
	DFLOAT fScaleDDur = m_fDuration*0.25f;

	// Scale light
	if (m_hLight)
	{
		if (m_fDuration <= 0) return;

		DFLOAT fRange  = m_fMaxLightRadius - m_fMinLightRadius;
		DFLOAT fRadius = 0.0f;
		DFLOAT fModelAlpha = 1.0f;

		if (fTime <= fScaleUDur)
		{
			fRadius = m_fMinLightRadius + (fTime * fRange / fScaleUDur);
		}
		else
		{	
			DFLOAT fNewDeltaTime = fTime - fScaleUDur;
			fRadius = m_fMaxLightRadius - (fNewDeltaTime * fRange / fScaleDDur);
			fModelAlpha = 1.0f - (fNewDeltaTime / fScaleDDur);
			if (fModelAlpha < 0.0f) fModelAlpha = 0.0f;
		}
		fModelAlpha *= 0.4f;

		g_pServerDE->SetLightRadius(m_hLight, fRadius);

		
		// Adjust alpha on model...

		if (m_hModel)
		{
			g_pServerDE->SetObjectColor(m_hModel, m_vLightColor.x*fModelAlpha, m_vLightColor.y*fModelAlpha, m_vLightColor.z*fModelAlpha, fModelAlpha);
		}

		// and on the shockwave
		if (m_hShockwave)
		{
			g_pServerDE->SetObjectColor(m_hShockwave, m_vLightColor.x*fModelAlpha, m_vLightColor.y*fModelAlpha, m_vLightColor.z*fModelAlpha, fModelAlpha);
		}
	}
}