Beispiel #1
0
void Base::EquipScreen()
{
	int first, elist[NUMEQUIPTYPES], displaylist[7];
	selectbar = -1;

	sprintf_s(descstring2,2048,"\0");

	int items = 0;
	for(int i=1;i<NUMEQUIPTYPES;i++) if(equipment[i]) elist[items++] = i;

	if(ship[player].keys.UP)
	{
		ship[player].keys.UP = false;
		if(listselector>0)
		{
			--listselector;
			glyph.CreateGraphicalObject(equipdata[elist[listselector]].graphics.c_str(),1);
			soundeffect[MENUMOVE].SetSoundEffect(0);
		}
		else soundeffect[MENUREJECT].SetSoundEffect(0);
	}
	if(ship[player].keys.DOWN)
	{
		ship[player].keys.DOWN = false;
		if(listselector<(items-1))
		{
			++listselector;
			glyph.CreateGraphicalObject(equipdata[elist[listselector]].graphics.c_str(),1);
			soundeffect[MENUMOVE].SetSoundEffect(0);
		}
		else soundeffect[MENUREJECT].SetSoundEffect(0);
	}

	meter[0].value = ship[player].power;			//Ship power usage
	meter[0].maxvalue = ship[player].maxpower;
	if(ship[player].equipment[elist[listselector]])
	{
		meter[1].value = 0;			//Equipment power usage
		meter[1].maxvalue = ship[player].maxpower;
		meter[2].value = ship[player].power;			//Predicted power usage
		meter[2].maxvalue = ship[player].maxpower;
	}
	else
	{
		if(elist[listselector] == AUXILIARY_GENERATOR)
		{
			meter[1].value = 0;									//Equipment power usage
			meter[1].maxvalue = ship[player].maxpower-equipdata[elist[listselector]].power;
			meter[2].value = ship[player].power;			//Predicted power usage
			meter[2].maxvalue = ship[player].maxpower-equipdata[elist[listselector]].power;
		}
		else
		{
			meter[1].value = equipdata[elist[listselector]].power;			//Equipment power usage
			meter[1].maxvalue = ship[player].maxpower;
			meter[2].value = ship[player].power+equipdata[elist[listselector]].power;			//Predicted power usage
			meter[2].maxvalue = ship[player].maxpower;
		}
	}
	meter[0].type = MUSED;
	meter[1].type = MPOWER;
	meter[2].type = MTOTAL;

	if(listselector<=3) first = 0;		//First section
	else if(listselector>=items-4) first = items-7;	//Last section
	else first = listselector-3;		//Scrolling section

	if(items<8)
	{
		for(int i=0;i<items;i++)
		{
			if(i==listselector)
			{
				selectbar = i;
				sprintf_s(descstring,2048,"%s \0",equipdata[elist[i]].description.c_str());
				//DrawSmallString(EqDesc[list[i]],391,276,621,false);
			}
			displaylist[i] = elist[i];
		}
		if(items<7) for(int i=0;i<7-items;i++) displaylist[items+i] = -1;
	}
	else
	{
		for(int i=0;i<7;i++,first++)
		{
			if(first==listselector)
			{
				selectbar = i;
				sprintf_s(descstring,2048,"%s \0",equipdata[elist[first]].description.c_str());
				//DrawSmallString(EqDesc[elist[first]],391,276,621,false);
			}
			displaylist[i] = elist[first];
		}
	}

	sprintf_s(datastring,2048,"%s\n%s\n%s\n%s\n%s\n%s\n%s\0",
				displaylist[0]>-1?equipdata[displaylist[0]].name.c_str():"\0",
				displaylist[1]>-1?equipdata[displaylist[1]].name.c_str():"\0",
				displaylist[2]>-1?equipdata[displaylist[2]].name.c_str():"\0",
				displaylist[3]>-1?equipdata[displaylist[3]].name.c_str():"\0",
				displaylist[4]>-1?equipdata[displaylist[4]].name.c_str():"\0",
				displaylist[5]>-1?equipdata[displaylist[5]].name.c_str():"\0",
				displaylist[6]>-1?equipdata[displaylist[6]].name.c_str():"\0");


	if(ship[player].keys.OPERATE)
	{
		ship[player].keys.OPERATE = false;
		switch (button[buttonselector])
		{
		case EXIT:
			ChangeScreen(HOME);
			return;
		case SELECT:		//Select
			if(!ship[player].equipment[elist[listselector]])
			{
				if((ship[player].power + equipdata[elist[listselector]].power)<=ship[player].maxpower )
				{
					ship[player].equipment[elist[listselector]] = true;
					ship[player].power += equipdata[elist[listselector]].power;
					sprintf_s(messagestring,1024,"Added %s ",equipdata[elist[listselector]].name.c_str());

					if(elist[listselector] == BOMB) data->equipment[BOMB]--;
					if(elist[listselector] == LASER_DRONE)
					{
						CreateDrone(player);
					}
					if(elist[listselector] == LIGHTNING_DRONE)
					{
						CreateLightningDrone(player);
					}
					if(elist[listselector] == SHIELD_DRONE)
					{
						for(int i=0;i<3;i++) CreateShieldDrone(player,i);
					}
					if(elist[listselector] == AUXILIARY_GENERATOR)
					{
						ship[player].maxpower -= equipdata[AUXILIARY_GENERATOR].power;
						ship[player].power -= equipdata[AUXILIARY_GENERATOR].power;		//To reverse the addition above
					}
					if(elist[listselector] == SHIELD)
					{
						ship[player].shields = ship[player].maxshields;
					}
					soundeffect[MENUSELECT].SetSoundEffect(0);
					soundeffect[INSTALLITEM].SetSoundEffect(0);
				}
				else
				{
					sprintf_s(messagestring,1024,"Not enough power");
					soundeffect[MENUREJECT].SetSoundEffect(0);
				}
			}
			else
			{
				sprintf_s(messagestring,1024,"Equipment already installed");
				soundeffect[MENUREJECT].SetSoundEffect(0);
			}
			break;
		case REMOVE:		//Remove
			if(elist[listselector]==RADAR || elist[listselector]==SCANNER)
			{
				sprintf_s(messagestring,1024,"Cannot remove Radar or Scanner");
			}
			else if(elist[listselector]==AUXILIARY_GENERATOR && (ship[player].maxpower + equipdata[AUXILIARY_GENERATOR].power < ship[player].power)) sprintf_s(messagestring,1024,"Cannot remove generator: power overload!");
			else if(ship[player].equipment[elist[listselector]])
			{
				ship[player].equipment[elist[listselector]] = false;
				//data->equipment[elist[listselector]]++;
				ship[player].power -= equipdata[elist[listselector]].power;
				sprintf_s(messagestring,1024,"Removed %s",equipdata[elist[listselector]].name.c_str());
				if(elist[listselector] == LASER_DRONE)
				{
					SET(ship[player].drone->state,FORDESTRUCTION);
					ship[player].drone = NULL;
				}
				if(elist[listselector] == LIGHTNING_DRONE)
				{
					SET(ship[player].lightningdrone->state,FORDESTRUCTION);
					ship[player].lightningdrone = NULL;
				}
				if(elist[listselector] == SHIELD_DRONE)
				{
					SET(ship[player].shielddrone[0]->state,FORDESTRUCTION);
					SET(ship[player].shielddrone[1]->state,FORDESTRUCTION);
					SET(ship[player].shielddrone[2]->state,FORDESTRUCTION);
					ship[player].shielddrone[0] = NULL;
					ship[player].shielddrone[1] = NULL;
					ship[player].shielddrone[2] = NULL;
				}
				if(elist[listselector] == BOMB) data->equipment[BOMB]++;
				if(elist[listselector] == AUXILIARY_GENERATOR)
				{
					ship[player].maxpower += equipdata[AUXILIARY_GENERATOR].power;
					ship[player].power += equipdata[AUXILIARY_GENERATOR].power;		//To reverse the subtraction above
				}
				if(elist[listselector]==RADAR)
				{
					if(ship[player].equipment[SCANNER])
					{
						ship[player].equipment[SCANNER] = false;
						ship[player].power -= equipdata[SCANNER].power;
						sprintf_s(messagestring,1024,"Removed Radar and Scanner");
					}
				}
				soundeffect[MENUSELECT].SetSoundEffect(0);
			}
			else
			{
				sprintf_s(messagestring,1024,"Equipment not installed");
				soundeffect[MENUREJECT].SetSoundEffect(0);
			}
			return;
		case EQUIP:		//Equip screen
			ChangeScreen(EQUIP);
			return;
		case WEAPON:		//Weapon screen
			ChangeScreen(WEAPON);
			return;
		case SHIP:
			ChangeScreen(SHIP);
			return;
		}
	}

	return;
}
Beispiel #2
0
/** Start an asteroids game. */
void Asteroids::Start()
{
    // Add a player (watcher) to the game world
    mGameWorld->AddListener(&mPlayer);
    // Add a score keeper to the game world
    mGameWorld->AddListener(&mScoreKeeper);
    // Add this class as a listener of the score keeper
    mScoreKeeper.AddListener(this);
    // Add this class as a listener of the game world
    mGameWorld->AddListener(this);
    // Add this class as a listener of the player
    mPlayer.AddListener(this);
    // Create user interface
    CreateGUI();

    // Create an ambient light to show sprite textures
    GLfloat ambient_light[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    GLfloat diffuse_light[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light);
    glEnable(GL_LIGHT1);

    mSelectedShape = new Shape("ASSETS/selected.shape");

    Animation *explosion_anim = AnimationManager::GetInstance().CreateAnimationFromRawRGBA("explosion", 64, 1024, 64, 64, "ASSETS/explosion_fs.raw", "ASSETS/explosion_fs_alpha.raw");
    Animation *asteroid1_anim = AnimationManager::GetInstance().CreateAnimationFromRawRGBA("asteroid1", 128, 8192, 128, 128, "ASSETS/asteroid1_fs.raw", "ASSETS/asteroid1_fs_alpha.raw");
    Animation *asteroidOre1_anim = AnimationManager::GetInstance().CreateAnimationFromRawRGBA("asteroidOre1", 128, 8192, 128, 128, "ASSETS/asteroidOre1_fs.raw", "ASSETS/asteroidOre1_fs_alpha.raw");
    //Animation *droid_anim = AnimationManager::GetInstance().CreateAnimationFromRawRGBA("droid1", );
    Animation *spaceship_anim = AnimationManager::GetInstance().CreateAnimationFromRawRGBA("spaceship", 128, 128, 128, 128, "ASSETS/spaceship_fs.raw", "ASSETS/spaceship_fs_alpha.raw");

    // Add this as a listener to the world and the keyboard
    mGameWindow->AddKeyboardListener(this);
    // Add this as a listener to the world and the mouse
    mGameWindow->AddMouseListener(this);
    // Add the selection box to the world
    mGameWorld->GiveSelectionBox(mSelectionBox);


    // Create a spaceship and add it to the world
    //mGameWorld->AddObject(CreateSpaceship());
    // Create some asteroids and add them to the world
    mLevel = 1;
    mAsteroidCount = 1;

    int w = mGameDisplay->GetWidth();
    int h = mGameDisplay->GetHeight();

    cout << "width : " << w;
    cout << "height : " << h;

    // creating asteroids
    for (int i = 0; i < 10; i++)
    {
        int x = (rand() % w) - w/2;
        int y = (rand() % h) - h/2;
        mGameWorld->AddObject(CreateAsteroid(x,y));
        mAsteroidCount++;
    }

    //creating ore asteroids
    for (int i = 0; i < 10; i++)
    {
        int x = (rand() % w) - w/2;
        int y = (rand() % h) - h/2;
        mGameWorld->AddObject(CreateAsteroidOre(x,y));
        mAsteroidCount++;
    }


    // creating drones
    float rAngle = 0;
    GLVector3f zero(0.0, 0.0, 0.0);

    for(int i = 0; i < 2; i++){
        GLVector3f new_drone_offset(cos(DEG2RAD*rAngle), sin(DEG2RAD*rAngle), 0.0);
        new_drone_offset.normalize();
        GLVector3f drone_position = zero + (new_drone_offset * 20);

        mGameWorld->AddObject(CreateDrone(drone_position.x,drone_position.y));
        rAngle += 360 / 2;
    }

    // creaing a single ore for testing
    mGameWorld->AddObject(CreateOre(100,0));

    // Start the game
    GameSession::Start();
}