Missile* UnitFactory::parseMissileBuffer( NetBuffer &netbuf )
{
    ObjSerial   serial = netbuf.getSerial();
    string      file( netbuf.getString() );
    string      name( netbuf.getString() );
    string      fullname( netbuf.getString() );
    int faction = netbuf.getInt32();
    string      mods( netbuf.getString() );
    const float damage( netbuf.getFloat() );
    float phasedamage  = netbuf.getFloat();
    float time = netbuf.getFloat();
    float radialeffect = netbuf.getFloat();
    float radmult = netbuf.getFloat();
    float detonation_radius = netbuf.getFloat();
    const string modifs( mods );

    cerr<<"NETCREATE MISSILE : "<<file<<" ("<<serial<<")"<<endl;

    string facname = FactionUtil::GetFactionName( faction );
    if ( facname.empty() ) {
        //Got an invalid faction number...
        cerr<<"    Missile has an invalid faction "<<faction<<endl;
        faction = 0;
    }
    Missile *mis = createMissile(
        file.c_str(), faction, modifs, damage, phasedamage, time, radialeffect, radmult, detonation_radius, serial );
    if (netbuf.version() <= 4951)
        mis->curr_physical_state = netbuf.getTransformation();
    else
        netbuf.getClientState().setUnitState( mis );
    mis->name     = name;
    mis->fullname = fullname;
    return mis;
}
示例#2
0
void Game::allLocking() {
	if (mouse.LeftIsPressed() && !mouseClicked) {
		//if (noOfLockedOn > 0) 
		if (playerShip.missileAmmunition > 0) fireMissile(true);
		mouseClicked = true;
	}

	if (mouse.RightIsPressed() && playerShip.missileAmmunition > 0) { //for now or maybe forever? Ok Ive decided forever, its better.
		if (!currentlyLocking && specificTarget == NULL && noOfLockedOn < playerShip.missileAmmunition) {
			findLockOn();
		} 
		else if (currentlyLocking && specificTarget) createLockOn();
	}
	else {
		if (specificTarget) { //coz accessing specificTarget->lockingOn when its null is impossible
			specificTarget->lockingOn = false;
			specificTarget->frame = 0;
			specificTarget->startTime = GetTickCount();
			specificTarget = NULL;
		}
		specificTarget = NULL;
		currentlyLocking = false;
	}

	if (!mouse.LeftIsPressed()) mouseClicked = false;

	for (int i = 0; i < pShipTargets.size(); i++) {
		if ((GetTickCount() - pShipTargets[i].startTime) > pShipTargets[i].lockOnDelay && !pShipTargets[i].lockedOn) {
			if (pShipTargets[i].ship == NULL) pShipTargets.erase(pShipTargets.begin() + i);
			pShipTargets[i].startTime = GetTickCount();
			pShipTargets[i].frame++;
			//pShipTargets[i].lockOnDelay make this a variable so slower for first 8. different speed for 8-37
			//pShipTargets[i].frame = rand() % 8; so they all dont rotate the same; //doesnt matter anymore since it only shows sometimes.
			if (/*!currentlyLocking &&*/ //hmmm keep this? Want other ships to have things over them while locking onto another?
				Distance(mouse.GetMouseX(), mouse.GetMouseY(), pShipTargets[i].ship->x, pShipTargets[i].ship->y) < 100) {
				pShipTargets[i].inMouseRange = true;
				
			}
			else pShipTargets[i].inMouseRange = false;

			if (pShipTargets[i].frame >= 8 && !pShipTargets[i].lockingOn) pShipTargets[i].frame = 0;
			if (pShipTargets[i].frame >= 38 && pShipTargets[i].lockingOn) {
				noOfLockedOn++;
				pShipTargets[i].lockedOn = true;
				pShipTargets[i].lockingOn = false;
				pShipTargets[i].frame = 39;
				currentlyLocking = false;
				createMissile(true, pShipTargets[i].ship);
				specificTarget = NULL;
			}
		}
	}
}
示例#3
0
void IASystem::run() {
    static auto clock = sf::Clock();
    int r;

    if(clock.getElapsedTime().asMilliseconds() > 1000) {

        for(auto i(0u); i < World::world.numberEntities; ++i) {
            if (World::world.used[i] &&
                World::world.hasComponents[i][IA]) {

                if (!AnEnnemyIsUnder(i)) {
                    r = rand()%10;
                    if (r == 0)
                    createMissile(World::world.aabbs[i].x + World::world.aabbs[i].w / 2, World::world.aabbs[i].y + World::world.aabbs[i].h + 20, false);
                }
            }
        }
        clock.restart();
    }
}
示例#4
0
Game::Game( HWND hWnd,const KeyboardServer& kServer,const MouseServer& mServer )
:	gfx( hWnd ),
	audio( hWnd ),
	kbd( kServer ),
	mouse( mServer )
{
	frameCount = 0;	
	keysPressedLastFrame = false;
	gameOver = false;
	invincible = true;
	paused = false;

	srand(static_cast <unsigned> (time(0)));

	plasmaShot = audio.CreateSound("tinkle.wav");
	tune = audio.CreateSound("Dark Trance for Kearney.wav");
	//use last few bars of song for menu music or gameover.
	//tune.Play();

	playerShip.x = 900;
	playerShip.y = 600;
	playerShip.lives = PLAYERSHIPLIVES;
	playerShip.rotation = 0.0f;
	playerShip.framesSinceHit = 0;
	playerShip.ifHit = 0;
	playerShip.missileAmmunition = 15;
	speed = 8.0f;
	weaponChoice = BULLET;
	for (int i = 0; i < playerShip.missileAmmunition; i++) {
		createMissile(true, NULL);
	}

	currentlyLocking = false;
	noOfLockedOn = 0;
	specificTarget = NULL;

	start = time(0);
	wave = 1;
	waveTimer = 0;
	nextSquadTimer = 0;	
	doneIt = false; //rename
	initialTimeBetweenWaves = 1;
	minTimeBetweenSquad = 6;
	minTimeBetweenWaves = 4;
	timeTillNextSquad = initialTimeBetweenWaves;
	totalEnemyShipCreatedLevel = 0;
	squadsCreatedLevel = 0;
	squadsDefeatedLevel = 0;
	squadsCreatedWave = 0;
	squadsDefeatedWave = 0;
	squadsPerWave = 15;
	totalInsectCreatedLevel = 0;

	//hahaaa very interesting. Explain reservations. vectors dynamic memory. Massive bug.
	insectKamikazeFleet.reserve(100);
	//ahaa not need for deque coz
	//http://stackoverflow.com/questions/15524475/deque-how-come-reserve-doesnt-exist
	//enemyShipFleet.reserve(100);
	//or even does deque solve our pointer/address problem????
	//ahaa deques dont reallocate when move elements or add or remove or insert.
	//http://stackoverflow.com/questions/13235372/will-stl-deque-reallocate-my-elements-c
	//does avoid us having to change a thousand .'s in to ->'s. Plus I havent thought of a a way of making the stack pointer in makeenemyship without using new.
	pShipTargets.reserve(50);
	squadVector.reserve(50);

	totalEnemyShipKillsLevel = 0;
	totalInsectKillsLevel = 0;

	totalShipCreatedLevel = 0;
	totalShipCreatedWave = 0;
	totalShipKillsLevel = 0;
	totalShipKillsWave = 0;

	wavesPerLevel = 3;

	fontArial24 = gfx.MakeFont("Arial", 24);
	fontGaramond36 = gfx.MakeFont("Garamond", 36);
	fontTimesNewRoman40 = gfx.MakeFont("Times new Roman", 40);

	playerShipTexture = gfx.LoadTexture("Player ship 3.bmp", D3DCOLOR_XRGB(0, 0, 0));
	enemyShipTexture = gfx.LoadTexture("Ship 3.bmp");
	insectKamikazeTexture = gfx.LoadTexture("insectAnm 15 frame bmp.bmp", D3DCOLOR_XRGB(0, 148, 255));
	plasmaBulletTexture = gfx.LoadTexture("Blue ball bullet 1.bmp", D3DCOLOR_XRGB(0, 0, 0));
	missileTexture = gfx.LoadTexture("Bomb 1 (cropped).bmp");
	missileLockTexture = gfx.LoadTexture("Missilelock1.bmp..bmp");
	explosionTexture = gfx.LoadTexture("Explosion 2 sprite sheet (2) shaded.bmp", D3DCOLOR_XRGB(33, 198, 255));
	//missileIconTexture = gfx.LoadTexture("Bomb Icon 1.bmp");
	//bulletIconTexture = gfx.LoadTexture("Laser Icon 1.bmp");
	missileIconTexture = gfx.LoadTexture("missileicon.hud.bmp", D3DCOLOR_XRGB(255, 255, 255));
	bulletIconTexture = gfx.LoadTexture("lasericon.hud.bmp", D3DCOLOR_XRGB(255, 255, 255));
	weaponHudTexture = gfx.LoadTexture("Weaponhud.bmp", D3DCOLOR_XRGB(255, 255, 255));
}