enemyBullet::enemyBullet(hgeVector position,HTEXTURE &texture,short damage,int p_slope)
{
	hge = hgeCreate(HGE_VERSION);
	Position = position + hgeVector(30,30);
	Velocity = hgeVector(8.0f,8.0f);
	Sprite  = new hgeSprite(texture,0,0,13,13);
    //Sprite->SetHotSpot(3,1.5);
	Damage = damage;  
	slope=p_slope;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	hge = hgeCreate(HGE_VERSION);
	hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
	hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
	hge->System_SetState(HGE_WINDOWED, true);
	hge->System_SetState(HGE_USESOUND, true);
	hge->System_SetState(HGE_FPS, HGEFPS_VSYNC);
	hge->System_SetState(HGE_TITLE, "NFS_project");
	    hge->System_SetState(HGE_SCREENWIDTH,1220);
    hge->System_SetState(HGE_SCREENHEIGHT,600);

	if(hge->System_Initiate())
	{
		fnt=new hgeFont("font1.fnt");
		//Background
		g_tBackground	= hge->Texture_Load("images/TheRoad.jpg");
		g_tBGGapFix		= hge->Texture_Load("images/Strips.jpg");
		g_eExplosion	= hge->Effect_Load("sounds/21410__heigh-hoo__blow.aif");
		g_sBackground	= new hgeSprite(g_tBackground, 0, 0, 1780, 600);
		g_sBGGapFix		= new hgeSprite(g_tBGGapFix, 0, 0, 64, 600);
		g_vBGPosition	= hgeVector(-982, 0);
		//Sounds
		g_eBGMusic		= hge->Effect_Load("sounds/mix_17m52s.mp3");
		hge->Effect_PlayEx(g_eBGMusic, 40, 0, 0, true);
		//Player
		Player1			= new Player(hgeVector(150, 268));
		//Enemies
		g_tEColors[0]	= hge->Texture_Load("images/car1.png");
		g_tEColors[1]	= hge->Texture_Load("images/car2.png");
		g_tEColors[2]	= hge->Texture_Load("images/car3.png");
		g_tEColors[3]	= hge->Texture_Load("images/car4.png");
		g_tEColors[4]	= hge->Texture_Load("images/car5.png");
		//Explosion
		g_tExplosion	= hge->Texture_Load("images/Explosion-Sprite-Sheet.png");

		gui = new hgeGUI;
		gui->AddCtrl(new hgeGUIMenuItem(1, fnt, NULL, 610, 200, 0.0f, "Start Race"));
		gui->AddCtrl(new hgeGUIMenuItem(2, fnt, NULL, 610, 240, 0.1f, "Load Game"));
		gui->AddCtrl(new hgeGUIMenuItem(3, fnt, NULL, 610, 280, 0.2f, "Save Game"));
		gui->AddCtrl(new hgeGUIMenuItem(4, fnt, NULL, 610, 320, 0.3f, "Credits"));
		gui->AddCtrl(new hgeGUIMenuItem(5, fnt, NULL, 610, 360, 0.4f, "Exit"));
		gui->SetNavMode(HGEGUI_UPDOWN | HGEGUI_CYCLED);
		gui->SetFocus(1);
		gui->Enter();

		hge->System_Start();
		
		delete gui;
	}
	
	return 0;
}
Exemple #3
0
//******** TDDD04 FIX **********
void PlayerAI::tick(GameObject* go, float deltaTime, IGameObjectManager* gom)
{
    go->setVelocity(hgeVector(0,0));
    go->setAngularVelocity(0.0f);

    if(m_input->down())
    {
        //TDDD04 Fix
        go->setVelocity(go->getVelocity() + hgeVector(0, PLAYER_ACCELERATION));
    }
    if(m_input->up())
    {
        go->setVelocity(go->getVelocity() + hgeVector(0, -PLAYER_ACCELERATION));
    }
    if(m_input->left())
    {
        go->setVelocity(go->getVelocity() + hgeVector(-PLAYER_ACCELERATION,0));
    }
    if(m_input->right())
    {
        //TDDD04 Fix
        go->setVelocity(go->getVelocity() + hgeVector(PLAYER_ACCELERATION,0));
    }

    if(m_input->down2())
    {
        go->setVelocity(go->getVelocity() + CreateVectorFromAngle(go->getRotation() + M_PI, PLAYER_ACCELERATION));
    }
    if(m_input->up2())
    {
        go->setVelocity(go->getVelocity() + CreateVectorFromAngle(go->getRotation(), PLAYER_ACCELERATION));
    }
    if(m_input->left2())
    {
        go->setVelocity(go->getVelocity() + CreateVectorFromAngle(go->getRotation() - (M_PI/2.0f), PLAYER_ACCELERATION));
    }
    if(m_input->right2())
    {
        go->setVelocity(go->getVelocity() + CreateVectorFromAngle(go->getRotation() + (M_PI/2.0f), PLAYER_ACCELERATION));
    }
    if(m_input->turnLeft())
    {
        go->setAngularVelocity(go->getAngularVelocity() - PLAYER_ANGULAR_ACCELERATION);
    }
    if(m_input->turnRight())
    {
        go->setAngularVelocity(go->getAngularVelocity() + PLAYER_ANGULAR_ACCELERATION);
    }
}
void d_barrier::Update(float dt)
{
	if ((GetPosition().x<end_x+1)&&(GetPosition().x>end_x-1))
	{	
		float temp=end_x;
		end_x=start_x;
		start_x=temp;
		temp=end_y;
		end_y=start_y;
		start_y=temp;
		dx=-dx;
		dy=-dy;
	}
	else if ((GetPosition().y<end_y+1)&&(GetPosition().y>end_y-1))
	{	
		float temp=end_y;
		end_y=start_y;
		start_y=temp;
		temp=end_x;
		end_x=start_x;
		start_x=temp;
		dy=-dy;
		dx=-dx;
	}
	SetPosition(hgeVector(GetPosition().x+dt*dx,GetPosition().y+dt*dy));
}
// Constructor
Protagonist::Protagonist(void): Player(230.0f),AssaultRifle(ASSAULTRIFLE,PRIMARY),SideArm(SEMIAUTO,SECONDARY),ShotGun(SHOTGUN,PRIMARY),RocketLauncher(ROCKETLAUNCHER,PRIMARY)
{
	eCURRENTSTANCE = IDLE;
	eCURRENTWEAPON = AssaultRifle.GetWeaponID();
	pCurrentWeapon = &AssaultRifle;
	       eFACING = FACERIGHT;
	     iGrenades = 6; 
	SpriteSheet[0] = SpriteSheet[1] = MainAnimation = 0;
	vDirection = hgeVector(1,0);
}
Exemple #6
0
bool CreateNewGame()
{

	HANDLE mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, NAME_MUTEX2);
	if (!mutex)
		mutex = CreateMutex(NULL, FALSE, NAME_MUTEX2);

	Map *map = new Map(0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 64, 64);
	char path[MAX_PATH];

	strcpy(path, PATH_T0_LEVELS);
	strcat(path, "\\");
	strcat(path, level_name.c_str());

	int count_entitys = 0;

	map->Load(path, count_entitys, next_level_name);
	map->UpdateEdges(GENERAL_MAP_LAYER);
	
	world->Create(map, map->GetLayers());

	Ray::tiles = map;

	InitiatePlayer(0);
	//RefreshPlayer(player);

	

		
	srand((unsigned)time(NULL));
	for (int i = 0; i < count_entitys; i++)
	{
		Entity *e = new Entity(hgeVector(128, 128), GENERAL_MAP_LAYER);
		
		int skin_id = rand()%2+1;

		e->Initiate(skin_id);
		e->SetSpeed(3.5f, 4.5f);

		Sleep(40);
		RefreshPlayer(e);

		world->InsertObject(e);
	}

	//wait_clients = CreateThread(NULL, 0, &WaitClients, NULL, 0, NULL);
	//srv_accept = CreateThread(NULL, 0, &Accept, (void *)world->GetWorldEntitys(), 0, NULL);

	return true;
	

}
void Load_Game()
{

	Enemies.clear();

	FILE *f= fopen("saved.game","rb");
	int n;
	fread(&n,sizeof(int),1,f);
	for (int i=0;i<n;i++)
	{
		enemy* Enemy = new enemy(hgeVector(hge->Random_Int(800,1670), hge->Random_Int(60,530)), 
								hgeVector(-hge->Random_Int(1,7), hge->Random_Int(-3,2)),
								g_tEColors[hge->Random_Int(0,4)],
								0.1);
		fread(Enemy,sizeof(enemy),1,f);
		Enemies.push_back(Enemy);
	}
	fread(&score,sizeof(int),1,f);
	fread(Player1,sizeof(Player),1,f);
	

}
HGE_Vector_t HGE_Vector_New(float x, float y) {
	HGE_Vector_t v = {hgeVector(x,y)};
	return v;
}
Exemple #9
0
hgeVector Input::getMousePosition( )
{
	float x, y;
	hge->Input_GetMousePos( &x, &y );
	return hgeVector( x, y );
}
Exemple #10
0
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	hge = hgeCreate(HGE_VERSION);
	hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
	hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
	hge->System_SetState(HGE_WINDOWED, true);
	hge->System_SetState(HGE_USESOUND, true);
	hge->System_SetState(HGE_FPS, HGEFPS_VSYNC);
	hge->System_SetState(HGE_TITLE, "Lizard");
	hge->System_SetState(HGE_SCREENWIDTH, 800);
	hge->System_SetState(HGE_SCREENHEIGHT, 600);
	hge->System_SetState(HGE_SCREENBPP, 32);
	if (hge->System_Initiate())
	{			
		//quad.tex=hge->Texture_Load("bg.png");
		quad.tex=hge->Texture_Load("images/bg.png");
		tex=hge->Texture_Load("images/cursor.png");
		snd=hge->Effect_Load("sounds/menu.wav");
		if(!quad.tex || !tex || !snd)
		{
			//Проверяем загруженны ли все тектсуры и звуки меню игрі
			MessageBox(NULL, "Can't load BG.PNG, CURSOR.PNG or MENU.WAV ", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
			hge->System_Shutdown();
			hge->Release();
			return 0;
		}

		// Set up the quad we will use for background animation
		quad.blend=BLEND_ALPHABLEND | BLEND_COLORMUL | BLEND_NOZWRITE;
		for(int i=0;i<4;i++)
		{
			// Set up z-coordinate of vertices
			quad.v[i].z=0.5f;
			// Set up color. The format of DWORD col is 0xAARRGGBB
			quad.v[i].col=0xFFFFFFFF;
		}
		quad.v[0].x=0; quad.v[0].y=0; 
		quad.v[1].x=800; quad.v[1].y=0; 
		quad.v[2].x=800; quad.v[2].y=600; 
		quad.v[3].x=0; quad.v[3].y=600; 
		// Load the font, create the cursor sprite
		fnt=new hgeFont("font1.fnt");
		spr=new hgeSprite(tex,0,0,32,32);
		// Create and initialize the GUI
		gui=new hgeGUI();
		gui->AddCtrl(new hgeGUIMenuItem(6,fnt,snd,400,100,0.0f,"Lizard"));
		gui->AddCtrl(new hgeGUIMenuItem(1,fnt,snd,400,200,0.0f,"Play"));
		gui->AddCtrl(new hgeGUIMenuItem(2,fnt,snd,400,240,0.1f,"Load Game"));
		gui->AddCtrl(new hgeGUIMenuItem(3,fnt,snd,400,280,0.2f,"Save Game"));
		gui->AddCtrl(new hgeGUIMenuItem(7,fnt,snd,400,320,0.0f,"Surv.Mode"));
		gui->AddCtrl(new hgeGUIMenuItem(4,fnt,snd,400,360,0.3f,"How to Play"));
		gui->AddCtrl(new hgeGUIMenuItem(5,fnt,snd,400,400,0.4f,"Exit"));
		gui->SetNavMode(HGEGUI_UPDOWN | HGEGUI_CYCLED);
		gui->SetCursor(spr);
		gui->SetFocus(1);
		gui->Enter();
		//Background
		bg = hge->Texture_Load("images/bg_1.jpg");
		sbg = new hgeSprite(bg, 0, 0 ,1720, 600);
		surv_bg = hge->Texture_Load("images/surv_mode.jpg");
		surv_sbg = new hgeSprite(surv_bg, 0, 0 ,1920, 1200);
		g_tBackground = hge->Texture_Load("images/lvl1.jpg");
		g_sBackground = new hgeSprite(g_tBackground, 0, 0, 1782, 600);
		g_tBackground2 = hge->Texture_Load("images/lvl2.jpg");
		g_sBackground2 = new hgeSprite(g_tBackground2, 0, 0, 1782, 600);
		g_tBackground3 = hge->Texture_Load("images/lvl3.jpg");
		g_sBackground3 = new hgeSprite(g_tBackground3, 0, 0, 1782, 600);
		g_tBackground4 = hge->Texture_Load("images/lvl44.jpg");
		g_sBackground4 = new hgeSprite(g_tBackground4, 0, 0, 1782, 600);
		fnt2 = new hgeFont("font1.fnt");
		fnt1 = new hgeFont("font1.fnt");
		//Player
		Player1 = new player(hgeVector(300, 530), hgeVector(5, 0),lvl);
		//Insects
		g_tEColors[0] = hge->Texture_Load("images/bonus_1.png");
		g_tEColors[1] = hge->Texture_Load("images/bonus_2.png");
		g_tEColors[2] = hge->Texture_Load("images/bonus_3.png");
		g_tEColors[3] = hge->Texture_Load("images/bonus_4.png");
		g_tEColors[4] = hge->Texture_Load("images/bonus_5.png");
		//Bee
		g_bee[0] = hge->Texture_Load("images/bee.png");
		g_bee[1] = hge->Texture_Load("images/bee.png");
		//Boss
		//Boss = new boss(hgeVector(300, 30), hgeVector(5, 0));
		g_boss[0] = hge->Texture_Load("images/boss.png");
		g_boss[1] = hge->Texture_Load("images/boss.png");
		//PB
		g_pb[0] = hge->Texture_Load("images/pb.png");
		g_pb[1] = hge->Texture_Load("images/pb.png");
		//HPB
		g_hpb[0] = hge->Texture_Load("images/hpb.png");
		g_hpb[1] = hge->Texture_Load("images/hpb.png");
		//Sounds
		g_eBGMusic  = hge->Effect_Load("sounds/lvl1.mp3");
		g_eBGMusic2 = hge->Effect_Load("sounds/lvl2.mp3");
		g_eBGMusic3 = hge->Effect_Load("sounds/lvl3.mp3");
		g_eBGMusic4 = hge->Effect_Load("sounds/lvl1.mp3");
		if(!g_tBackground || !g_tBackground2 || !g_tBackground3 || !g_tBackground4 || !g_tEColors || !g_bee || /*!g_boss ||*/ !g_pb || !g_hpb || !g_eBGMusic || !g_eBGMusic2 || !g_eBGMusic3)
		{
			//Проверяем загруженны ли все тектсуры и звуки основной игры
			MessageBox(NULL, "Can't load LVL1(2,3,4).PNG, bonus(1,2,3,4,5).PNG, BEE.PNG, HPB.PNG, PB.PNG or LVL1(2,3,4).MP3 ", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
			hge->System_Shutdown();
			hge->Release();
			return 0;
		}
		hge->System_Start();
		//Очищаем
		hge->Texture_Free(g_tBackground);
		hge->Texture_Free(g_tBackground2);
		hge->Texture_Free(g_tBackground3);
		hge->Texture_Free(g_tBackground4);
		hge->Effect_Free(g_eBGMusic);
		hge->Effect_Free(g_eBGMusic2);
		hge->Effect_Free(g_eBGMusic3);
		hge->Effect_Free(g_eBGMusic4);
		// Delete created objects and free loaded resources
		delete gui;
		delete fnt;
		delete spr;
		hge->Effect_Free(snd);
		hge->Texture_Free(tex);
		hge->Texture_Free(quad.tex);
	};
	delete g_sBackground;
	delete Player1;
	//delete Boss;
	for(auto i = Bosses.begin(); i != Bosses.end();)
	{
		delete (*i);
		i = Bosses.erase(i);
	}
	for(auto i = Insects.begin(); i != Insects.end();)
	{
		delete (*i);
		i = Insects.erase(i);
	}
	for (auto i = Bees.begin(); i != Bees.end();)
	{
		delete (*i);
		i = Bees.erase(i);
	}

	for (auto i = PB.begin(); i != PB.end();)
	{
		delete (*i);
		i = PB.erase(i);
	}

	for (auto i = HPB.begin(); i != HPB.end();)
	{
		delete (*i);
		i = HPB.erase(i);
	}

	//hge->Texture_Free(g_Player1);

	for (short b = 0; b < 2; b++) hge->Texture_Free(g_bee[b]);//удаляем 

	for (short b = 0; b < 1; b++)hge->Texture_Free(g_boss[b]);

	for (short i = 0; i < 5; i++) hge->Texture_Free(g_tEColors[i]);//удаляем

	for (short i = 0; i < 2; i++) hge->Texture_Free(g_pb[i]);

	for (short i = 0; i < 2; i++) hge->Texture_Free(g_hpb[i]);
	hge->System_Shutdown();
	hge->Release();
	// Clean up and shutdown
	return 0;
}
Exemple #11
0
bool FramePlay()
{
	if(play == 1)
	{
		if (level == 1)
		{
			ins = 7;
			beee = 2;
			hpp = 1;
		}
		else if (level == 2)
		{
			ins = 5;
			beee = 3;
			hpp = 1;
		}
		else if (level == 3)
		{
			ins = 3;
			beee = 5;
			hpp = 3;
		}
		else if (level == 4)
		{
			ins = 3;
			beee = 0;
			hpp = 3;
			bs = 1;
		}
		float delta = hge->Timer_GetDelta();
		//Insects
		if (Insects.size() < ins)
		{
			short Health = hge->Random_Int(50, 100);

			insects* Insect = new insects(hgeVector(hge->Random_Int(10, 800), 40), hgeVector(-hge->Random_Int(-4, 4), hge->Random_Int(1, 1)), g_tEColors[hge->Random_Int(0, 4)]);

			Insects.push_back(Insect);
		}

		for (auto i = Insects.begin(); i != Insects.end();)
		{
			if ((*i)->GetPosition().x < 0 || (*i)->GetPosition().y > 580 || (*i)->GetPosition().y < 20)
			{
				delete (*i);
				i = Insects.erase(i);
			}
			else
			{
				(*i)->Update(delta);
				i++;
			}
		}
		//Bee
		if (Bees.size() < beee)
		{
			short Health = hge->Random_Int(50, 100);
			bee* Bee = new bee(hgeVector(hge->Random_Int(10, 800), 40), hgeVector(-hge->Random_Int(-4, 4), hge->Random_Int(1, 1)), g_bee[hge->Random_Int(0, 1)]);
			Bees.push_back(Bee);
		}

		for (auto i = Bees.begin(); i != Bees.end();)
		{
			if ((*i)->GetPosition().x < 0 || (*i)->GetPosition().y > 580 || (*i)->GetPosition().y < 20)
			{
				delete (*i);
				i = Bees.erase(i);
			}
			else
			{
				(*i)->Update(delta);
				i++;
			}
		}
		//boss
		if (Bosses.size() < bs)
		{
			short Health = hge->Random_Int(50, 100);
			boss* Boss = new boss(hgeVector(hge->Random_Int(10, 800), 40), hgeVector(-hge->Random_Int(-4, 4), hge->Random_Int(1, 1)), g_boss[hge->Random_Int(0, 1)]);
			Bosses.push_back(Boss);
		}

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

		//PB
		if (count != 0 && count % 5 == 0 && PB.size() < 2)
		{
			short Health = hge->Random_Int(50, 100);
			point_bonus* point_bon = new point_bonus(hgeVector(hge->Random_Int(10, 800), 40), hgeVector(-hge->Random_Int(-4, 4), hge->Random_Int(1, 1)), g_pb[hge->Random_Int(0, 1)]);
			PB.push_back(point_bon);
		}

		for (auto i = PB.begin(); i != PB.end();)
		{
			if ((*i)->GetPosition().x < 0 || (*i)->GetPosition().y > 580 || (*i)->GetPosition().y < 20)
			{
				i = PB.erase(i);
			}
			else
			{
				(*i)->Update(delta);
				i++;
			}
		}
		//HPB
		if (HPB.size() < 2 && hp < 3 && count != 0 && count % 5 == 0)
		{
			short Health = hge->Random_Int(50, 100);
			hp_bonus* hp_bon = new hp_bonus(hgeVector(hge->Random_Int(10, 800), 40), hgeVector(-hge->Random_Int(-4, 4), hge->Random_Int(1, 1)), g_hpb[hge->Random_Int(0, 1)]);
			HPB.push_back(hp_bon);
		}

		for (auto i = HPB.begin(); i != HPB.end();)
		{
			if ((*i)->GetPosition().x < 0 || (*i)->GetPosition().y > 580 || (*i)->GetPosition().y < 20)
			{
				i = HPB.erase(i);
			}
			else
			{
				(*i)->Update(delta);
				i++;
			}
		}
		//Insects vs Player
		for (auto i = Insects.begin(); i != Insects.end();)
		{
			if ((*i)->GetBoundingBox().Intersect(&Player1->GetBoundingBox()))
			{
				delete (*i);
				i = Insects.erase(i);
				count++;
			}
			else i++;
		}
		//BOSS vs Player
		for (auto i = Bosses.begin(); i != Bosses.end();)
		{
			if ((*i)->GetBoundingBox().Intersect(&Player1->GetBoundingBox()))
			{
				delete (*i);
				i = Bosses.erase(i);
				if (count>175 && count<185)
					hp=hp-2;
				else if(count>200)
				{
					count=count+200;
					MessageBox(NULL, "You're WIN!!!", "WIN", MB_OK);
					play = 0;
					gui->Enter();
				}
			}
			else i++;
		}
		//Bee vs Player
		for (auto i = Bees.begin(); i != Bees.end();)
		{
			if ((*i)->GetBoundingBox().Intersect(&Player1->GetBoundingBox()))
			{
				delete (*i);
				i = Bees.erase(i);
				hp = hp - hpp;
			}
			else i++;
		}
		if (hp == 0 || hp < 0 )
		{
			MessageBox(NULL, "GAME OVER! Your HP - 0", "Game Over", MB_OK);
			play = 0;
			gui->Enter();
			return true;
		}
		//PB vs PLayer
		for (auto i = PB.begin(); i != PB.end();)
		{
			if ((*i)->GetBoundingBox().Intersect(&Player1->GetBoundingBox()))
			{
				(*i)->Bonus();
				i = PB.erase(i);
			}
			else i++;
		}
		//HPB vs PLayer
		for (auto i = HPB.begin(); i != HPB.end();)
		{
			if ((*i)->GetBoundingBox().Intersect(&Player1->GetBoundingBox()))
			{
				if (hp<5)
					(*i)->Bonus();
				i = HPB.erase(i);

			}
			else i++;
		}
		if (count>50 && count<150)
		{
			lvl=2;
			level = 2;
		}
		if (count>150 && count<175)
		{
			level = 3;
			lvl=3;
		}
		if (count>175 && count<180)
		{
			level = 4;
			lvl=4;
		}
		if (count>180 && count<200)
		{
			lvl = 5;
			level = 4;
		}
		if (count>200)
		{
			lvl=6;
			level = 4;
		}
		if(hge->Input_GetKeyState(HGEK_ESCAPE))
		{
			play = 0;
			game_menu = 3;
			gui->Enter();
		}
	}
	return false;
}
Exemple #12
0
HTEXTURE	g_tBackground2 = 0;
hgeSprite*	g_sBackground2 = NULL;

HTEXTURE	g_tBackground3 = 0;
hgeSprite*	g_sBackground3 = NULL;

HTEXTURE	g_tBackground4 = 0;
hgeSprite*	g_sBackground4 = NULL;

HTEXTURE    bg=0;
hgeSprite*	sbg = NULL;

HTEXTURE    surv_bg=0;
hgeSprite*	surv_sbg = NULL;

hgeVector	g_vBGPosition = hgeVector(0,0);


//Sound
HEFFECT		g_eBGMusic			= 0;
HEFFECT		g_eBGMusic2			= 0;
HEFFECT		g_eBGMusic3			= 0;
HEFFECT		g_eBGMusic4			= 0;

HEFFECT				snd;
HTEXTURE			tex;
hgeQuad				quad;

// Pointers to the HGE objects we will use
hgeGUI				*gui;
hgeFont				*fnt;
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;


}
Exemple #14
0
void Ant::step(float deltaTime)
{
    if ((this->dest - this->pos).Length() < dlen * 0.1f)
    {
#if 0
        int dx = rand() % (dMaxlen * 2 + 1) - dMaxlen;
        int dy = rand() % (dMaxlen * 2 + 1) - dMaxlen;
        if (dx > 0) dx += (int)dlen; else dx -= (int)dlen;
        if (dy > 0) dy += (int)dlen; else dy -= (int)dlen;
        this->dest = hgeVector(pos.x + dx, pos.y + dy);
#else
        int x = int((pos.x - border.left) / dlen + 0.5) * dlen + border.left;
        int y = int((pos.y - border.top) / dlen + 0.5) * dlen + border.top;
        hgeVector curDestPos = this->carryCake ? MainGameState::GetInstance()->getAntLairPos() : MainGameState::GetInstance()->getCakePos();
        //curDestPos.x > x
        if (rand() % 3)
        {
            int r = rand() % 3;
            if (r & 1)
            {
                if (curDestPos.x > x)
                    x += dlen;
                else if (curDestPos.x < x)
                    x -= dlen;
            }
            if (r & 2)
            {
                if (curDestPos.y > y)
                    y += dlen;
                else if (curDestPos.y < y)
                    y -= dlen;
            }
        }
        else
        {
            int r = rand() % 8;
            if (r >= 4) r ++;
            if (r % 3 == 0)
                x -= dlen;
            else if (r % 3 == 2)
                x += dlen;
            if (r / 3 == 0)
                y -= dlen;
            else if (r / 3 == 2)
                y += dlen;
        }
        this->dest = hgeVector(x, y);
#endif
        if (this->dest.x < border.left)
            this->dest.x = border.left;
        if (this->dest.x > border.right)
            this->dest.x = border.right;
        if (this->dest.y < border.top)
            this->dest.y = border.top;
        if (this->dest.y > border.bottom)
            this->dest.y = border.bottom;
    }

    if (this->carryCake)
    {
        // Óе°¸â£¬ËÍ»ØÒÏѨ
        if (MainGameState::GetInstance()->putCake(this->pos))
        {
            this->carryCake = false;
        }
    }
    else
    {
        // È¡µÃµ°¸â
        if (MainGameState::GetInstance()->getCake(this->pos))
        {
            this->carryCake = true;
            this->hp = min(this->getMaxHp(), this->getMaxHp() / 2 + this->hp);
        }
    }

    hgeVector curdir(0, -1);
    hgeVector oldPos = this->pos; 
    curdir.Rotate(this->angle);
    hgeVector destdir = *(this->dest - this->pos).Normalize();
    float offangle = curdir.Angle(&destdir);
    if (curdir.x * destdir.y - curdir.y * destdir.x < 0)
        offangle = -offangle;
    this->angle += offangle * 0.05f;
    this->pos += 60 * deltaTime * curdir * this->getSpeed() * min(1, 0.1 / abs(offangle));// * (1 - 2 * sqrt(abs(offangle)));

    if (this->pos.x < border.left)
        this->pos.x = border.left;
    if (this->pos.x > border.right)
        this->pos.x = border.right;
    if (this->pos.y < border.top)
        this->pos.y = border.top;
    if (this->pos.y > border.bottom)
        this->pos.y = border.bottom;

    this->moveMeter += (oldPos - this->pos).Length();
    this->applyDamageEffect();
}
HGE_Vector_t HGE_Vector_NewEmpty() {
	HGE_Vector_t v = {hgeVector()};
	return v;
}
Exemple #16
0
hgeVector c_gameobject::GetNewPosition_Rect(hgeRect BoundingBox1,hgeRect BoundingBox2)
{

    hgeVector A = PreviousPosition;
    hgeVector B = Position;
    hgeVector C;

    hgeVector NewPosition(0,0);
    hgeVector SwapPosition;

    c_bool PointUnderLine;
    c_bool A_coef_negative,
           B_coef_negative;
    c_bool A_coef_zero,
           B_coef_zero;
    c_bool Y_fixed;

    float Size_x = (BoundingBox1.x2 - BoundingBox1.x1) / 2;
    float Size_y = (BoundingBox1.y2 - BoundingBox1.y1) / 2;
    
    //Определим номер угла спрайта, который мы пересекли 
    //Верхний левый - 1, далее по часовой
    size_t angle_number = 0;

    //1.Верхний левый
    if (BoundingBox1.TestPoint(BoundingBox2.x1, BoundingBox2.y1))
    {
        angle_number = 1;
        C = hgeVector(BoundingBox2.x1, BoundingBox2.y1);
    }
    //2.Верхний правый
    if (BoundingBox1.TestPoint(BoundingBox2.x2, BoundingBox2.y1))
    {
        angle_number = 2;
        C = hgeVector(BoundingBox2.x2, BoundingBox2.y1);
    }
    //3.Нижний правый
    if (BoundingBox1.TestPoint(BoundingBox2.x2, BoundingBox2.y2))
    {
        angle_number = 3;
        C = hgeVector(BoundingBox2.x2, BoundingBox2.y2);
    }
    //4.Нижний левый
    if (BoundingBox1.TestPoint(BoundingBox2.x1, BoundingBox2.y2))
    {
        angle_number = 4;
        C = hgeVector(BoundingBox2.x1, BoundingBox2.y2);
    }

    //Смещаем точки, так как 'AB' - линия перемещения угла (который пересёк другой спрайт), а не центра
    switch (angle_number)
    {
    case 1:
        A.x = A.x + Size_x;
        A.y = A.y + Size_y;
        B.x = B.x + Size_x;
        B.y = B.y + Size_y;

        NewPosition.x -= Size_x;
        NewPosition.y -= Size_y;
        break;
    case 2:
        A.x = A.x - Size_x;
        A.y = A.y + Size_y;
        B.x = B.x - Size_x;
        B.y = B.y + Size_y;

        NewPosition.x += Size_x;
        NewPosition.y -= Size_y;
        break;
    case 3:
        A.x = A.x - Size_x;
        A.y = A.y - Size_y;
        B.x = B.x - Size_x;
        B.y = B.y - Size_y;

        NewPosition.x += Size_x;
        NewPosition.y += Size_y;
        break;
    case 4:
        A.x = A.x + Size_x;
        A.y = A.y - Size_y;
        B.x = B.x + Size_x;
        B.y = B.y - Size_y;

        NewPosition.x -= Size_x;
        NewPosition.y += Size_y;
        break;
    default:
        break;
    }

    // Уравнения прямых
    // AB: (A.y - B.y)*X + (B.x - A.x)*Y + (A.x*B.y - B.x*A.y) = 0
    // C-h: Y - C.y = 0
    // C-v: X - C.x = 0

    //Узнаем знак коэф. при Y
    //Если коэф. при Y меньше 0, то меняем точки местами (нужно для однозначности дальнейших результатов)
    if ((B.x - A.x) < 0)
    {
        B_coef_negative.SetTrue();

        SwapPosition = A;
        A = B;
        B = SwapPosition;
    }

    if ((B.x - A.x) == 0)
    {
        B_coef_zero.SetTrue();
    }

    //Узнаем знак коэф. при X
    if ((A.y - B.y) < 0)
    {
        A_coef_negative.SetTrue();
    }

    if ((A.y - B.y) == 0)
    {
        A_coef_zero.SetTrue();
    }

    //Проверяем ниже ли точка C относительно прямой AB
    //Так как ось Y инвертрована (отсчёт идёт сверху вниз),
    //то значение больше нуля означает, что точка лежит под линией
    if ((A.y - B.y)*C.x + (B.x - A.x)*C.y + (A.x*B.y - B.x*A.y) > 0)
    {
        PointUnderLine.SetTrue();
    }

    //    1\/2   3\/4
    // 16\           /5
    // 15/           \6
    //         o
    // 14\           /7
    // 13/           \8
    //   12/\11  10/\9
    //
    // POINT_UNDER : 1, 4, 7, 8, 10, 11, 13, 14
    // !POINT_UNDER: 2, 3, 5, 6, 9, 12, 15, 16  
    //
    // A_NEGATIVE  : 1, 3, 6, 8, 9, 11, 14, 16
    // !A_NEGATIVE : 2, 4, 5, 7, 10, 12, 13, 15
    //
    // B_NEGATIVE  : 2, 4, 5, 6, 7, 8, 9, 11,
    // !B_NEGATIVE : 1, 3, 10, 12, 13, 14, 15, 16
    //
    // Y_fixed: 1, 2, 3, 4, 9, 10, 11, 12
    // X_fixed: 5, 6, 7, 8, 13, 14, 15, 16

    switch (angle_number)
    {
    case 1:
        if (!A_coef_zero.GetState() && !B_coef_zero.GetState())
        {
            //1
            if (PointUnderLine.GetState() && A_coef_negative.GetState() && !B_coef_negative.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //2
            if (!PointUnderLine.GetState() && !A_coef_negative.GetState() && B_coef_negative.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //15
            if (!PointUnderLine.GetState() && !A_coef_negative.GetState() && !B_coef_negative.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
            //16
            if (!PointUnderLine.GetState() && A_coef_negative.GetState() && !B_coef_negative.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
        }
        else
        {
            //a
            if (B_coef_zero.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //h
            if (A_coef_zero.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
        }
        break;
    case 2:
        if (!A_coef_zero.GetState() && !B_coef_zero.GetState())
        {
            //3
            if (!PointUnderLine.GetState() && A_coef_negative.GetState() && !B_coef_negative.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //4
            if (PointUnderLine.GetState() && !A_coef_negative.GetState() && B_coef_negative.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //5
            if (!PointUnderLine.GetState() && !A_coef_negative.GetState() && B_coef_negative.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
            //6
            if (!PointUnderLine.GetState() && A_coef_negative.GetState() && B_coef_negative.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
        }
        else
        {
            //b
            if (B_coef_zero.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //c
            if (A_coef_zero.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
        }
        break;
    case 3:
        if (!A_coef_zero.GetState() && !B_coef_zero.GetState())
        {
            //9
            if (!PointUnderLine.GetState() && A_coef_negative.GetState() && B_coef_negative.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //10
            if (PointUnderLine.GetState() && !A_coef_negative.GetState() && !B_coef_negative.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //7
            if (PointUnderLine.GetState() && !A_coef_negative.GetState() && B_coef_negative.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
            //8
            if (PointUnderLine.GetState() && A_coef_negative.GetState() && B_coef_negative.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
        }
        else
        {
            //e
            if (B_coef_zero.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //d
            if (A_coef_zero.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
        }
        break;
    case 4:
        if (!A_coef_zero.GetState() && !B_coef_zero.GetState())
        {
            //11
            if (PointUnderLine.GetState() && A_coef_negative.GetState() && B_coef_negative.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //12
            if (!PointUnderLine.GetState() && !A_coef_negative.GetState() && !B_coef_negative.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //13
            if (PointUnderLine.GetState() && !A_coef_negative.GetState() && !B_coef_negative.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
            //14
            if (PointUnderLine.GetState() && A_coef_negative.GetState() && !B_coef_negative.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
        }
        else
        {
            //f
            if (B_coef_zero.GetState())
            {
                Y_fixed.SetTrue();
                Velocity.y = 0;
                JumpImpulse = 0;
            }
            //g
            if (A_coef_zero.GetState())
            {
                Velocity.x = 0;
                Acceleration = 0;
            }
        }
        break;
    default:
        break;
    }

    //Вычисляем новую позицию куда должны переместить угол нашего объекта (попавший внутрь другого спрайта)
    if (angle_number)
    {
        if (!A_coef_zero.GetState() && !B_coef_zero.GetState())
        {
            if (Y_fixed.GetState())
            {
                NewPosition.y += C.y;
                NewPosition.x += -(((A.x*B.y - B.x*A.y) - (-C.y)*(B.x - A.x)) / (A.y - B.y));
            }
            else
            {
                NewPosition.x += C.x;
                NewPosition.y += -(((A.y - B.y)*(-C.x) - (A.x*B.y - B.x*A.y)) / -(B.x - A.x));
            }
        }
        else
        {
            if (Y_fixed.GetState())
            {
                NewPosition.x += B.x;
                NewPosition.y += C.y;
            }
            else
            {
                NewPosition.x += C.x;
                NewPosition.y += B.y;
            }
        }
    }
    else
    //Если углы спрайтов не пересекались, то проверяем стороны
    {
        //1.Верхняя сторона
        if (PreviousPosition.y < BoundingBox2.y1)
        {
            NewPosition.y = BoundingBox2.y1 - Size_y;
            Velocity.y = 0;
            JumpImpulse = 0;
        }

        //2.Нижняя сторона
        if (PreviousPosition.y > BoundingBox2.y2)
        {
            NewPosition.y = BoundingBox2.y2 + Size_y;
            Velocity.y = 0;
            JumpImpulse = 0;
        }

        //3.Левая сторона
        if (PreviousPosition.x < BoundingBox2.x1)
        {
            NewPosition.x = BoundingBox2.x1 - Size_x;
            Velocity.x = 0;
            Acceleration = 0;
        }

        //4.Правая сторона
        if (PreviousPosition.x > BoundingBox2.x2)
        {
            NewPosition.x = BoundingBox2.x2 + Size_x;
            Velocity.x = 0;
            Acceleration = 0;
        }
    }

    return NewPosition;
 };
bool BApp::OnInit(void)
{
	// create pointer to HGE's interface
	hge = hgeCreate(HGE_VERSION);

	// set HGE's system states, most of them are default
	hge->System_SetState(HGE_FRAMEFUNC, static_OnLoop);		// set frame function
	hge->System_SetState(HGE_RENDERFUNC, static_OnRender);	// set rendering function
	hge->System_SetState(HGE_WINDOWED, true);				// windowed/fullscreen mode
	hge->System_SetState(HGE_USESOUND, true);				// enable/disable sounds
	hge->System_SetState(HGE_FPS, HGEFPS_VSYNC);			// vsync
	hge->System_SetState(HGE_TITLE, "Black Bird");			// window title

	// initialize HGE's with set system states
	if(hge->System_Initiate())
	{
		// initialize music
		b_eBGMusic0			= hge->Effect_Load("snd/deep_space.ogg");
		b_eBGMusic1			= hge->Effect_Load("snd/space_ambient.ogg");
		b_eBGMusic2			= hge->Effect_Load("snd/ambiance_space.ogg");
		b_eSFXGunshot		= hge->Effect_Load("snd/gun_shot.ogg");
		b_eSFXExplosion		= hge->Effect_Load("snd/explosion.aif");

		hge->Effect_PlayEx(b_eBGMusic0,  40, 0, 0, true);
		hge->Effect_PlayEx(b_eBGMusic1, 100, 0, 0, true);
		hge->Effect_PlayEx(b_eBGMusic2,  10, 0, 0, true);

		// initialize player
		b_pPlayerOne		= new BPlayer(hgeVector(10, 268), hgeVector(5, 0));

		// initialize bullets
		b_tBullet			= hge->Texture_Load("img/bullet.png");

		// initialize enemies
		b_tEColors[0]		= hge->Texture_Load("img/eSpritesheet_40x30.png");
		b_tEColors[1]		= hge->Texture_Load("img/eSpritesheet_40x30_hue1.png");
		b_tEColors[2]		= hge->Texture_Load("img/eSpritesheet_40x30_hue2.png");
		b_tEColors[3]		= hge->Texture_Load("img/eSpritesheet_40x30_hue3.png");
		b_tEColors[4]		= hge->Texture_Load("img/eSpritesheet_40x30_hue4.png");

		// initialize backgrounds
		b_tBackground		= hge->Texture_Load("img/farback.jpg");
		b_tStars			= hge->Texture_Load("img/starfield.png");
		b_tBGGapFix			= hge->Texture_Load("img/bg_gapfix.jpg");

			// subtle way to duplicate the background using them as tiles themselves
			b_sBackground	= new hgeSprite(b_tBackground, 0, 0, 1782, 600);
			b_sStars		= new hgeSprite(b_tStars,      0, 0,  800, 600);
			b_sBGGapFix		= new hgeSprite(b_tBGGapFix,   0, 0,   64, 600);
		
		// position of the background is set on the right side and also scrolls to right
		// backgroudnd is 1782px width and window is 800px.
		// 800 - 1782 = -982;
		b_vBGPosition		= hgeVector(-982, 0);	

		// start game loop
		hge->System_Start();
	}
	else
	{
		MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
		return false;
	}

	return true;
}