#include #include #include #define MAXCOINS 100 #include #include #include #include HGE *hge = 0; hgeResourceManager* myRes; hgeSprite* bgSprite; hgeAnimation* coinAnim; hgeFont* font1; HCHANNEL chan[2]; HEFFECT coinSound; hgeParticleSystemInfo sparkles; hgeParticleManager *particleManager; float mouseX, mouseY; //coordinates of the mouse cursor int collected = 0; //how many coins were collected bool done = false; struct Coin{ bool exists; //does the coin exist? hgeRect loc; //the location of the coin on the screen }; Coin coins[MAXCOINS]; bool FrameFunc() { hge->Input_GetMousePos(&mouseX, &mouseY); //get the current mouse position float dt=hge->Timer_GetDelta(); //get the time since the last call to FrameFunc coinAnim->Update(dt); //update the coin animation particleManager->Update(dt); //update all particles //when left mouse is clicked, check to see if coin is clicked if(hge->Input_GetKey()==HGEK_LBUTTON){ for(int i=0; iEffect_Play(coinSound); //play a sound particleManager->SpawnPS(&sparkles, mouseX, mouseY); //spawn a particle coins[i].exists = false; collected++; } } } hge->Gfx_BeginScene(); hge->Gfx_Clear(0); //clear the screen, filling it with black bgSprite->RenderStretch(0, 0, 800, 600); //render the background sprite stretched //render all coins for(int i=0; iRenderStretch(coins[i].loc.x1, coins[i].loc.y1, coins[i].loc.x2, coins[i].loc.y2); } font1->SetScale(1.0); //set text size to normal font1->SetColor(ARGB(255,0,0,0)); //set color of text to black font1->printf(5, 5, "Coins collected: %d", collected); //display amount of coins collected particleManager->Render(); //render all particles hge->Gfx_EndScene(); return done; } int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_HIDEMOUSE, false); hge->System_SetState(HGE_TITLE, "Coin Collector"); hge->System_SetState(HGE_LOGFILE, "tut.log"); if(hge->System_Initiate()) { myRes = new hgeResourceManager("resource.res"); hge->Random_Seed(0); bgSprite = myRes->GetSprite("bgSprite"); coinAnim = myRes->GetAnimation("coin"); coinAnim->Play(); //start playback of animation font1 = myRes->GetFont("font1"); coinSound = myRes->GetEffect("coinSound"); sparkles = myRes->GetParticleSystem("coinCollected")->info; particleManager= new hgeParticleManager(); //initialize all coins for(int i=0; iRandom_Float(0, 770); randY = hge->Random_Float(0, 570); coins[i].loc = hgeRect(randX, randY, randX+32, randY+32); } hge->System_Start(); } else { MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL); } delete myRes; delete particleManager; hge->System_Shutdown(); hge->Release(); return 0; }