User Tools

Site Tools


en:guides:beginners:text_and_game_over

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:guides:beginners:text_and_game_over [2018/06/29 05:38 (7 years ago)] – In line with init projects sausageen:guides:beginners:text_and_game_over [2024/11/19 04:21 (4 months ago)] (current) – Highlights sausage
Line 16: Line 16:
 Graphic  = ScoreGraphic Graphic  = ScoreGraphic
 Position = (-380, -280, 0) Position = (-380, -280, 0)
 +Scale    = 2
 </code> </code>
  
Line 22: Line 23:
 Now, in code, add a score variable and a scoreObject at the top of the file: Now, in code, add a score variable and a scoreObject at the top of the file:
  
-<code=cpp>+<code=cpp [highlight_lines_extra="3,4"]>
 orxOBJECT *hero; orxOBJECT *hero;
 orxOBJECT *herosGun; orxOBJECT *herosGun;
Line 31: Line 32:
 Next, create a score object and assign it to the scoreObject variable in the Init() function: Next, create a score object and assign it to the scoreObject variable in the Init() function:
  
-<code=cpp>+<code=cpp [highlight_lines_extra="3"]> 
 +hero = orxObject_CreateFromConfig("HeroObject"); 
 +herosGun = (orxOBJECT*)orxObject_GetChild(hero);
 scoreObject = orxObject_CreateFromConfig("ScoreObject"); scoreObject = orxObject_CreateFromConfig("ScoreObject");
 </code> </code>
Line 42: Line 45:
  
     orxCHAR formattedScore[6];     orxCHAR formattedScore[6];
-    orxString_Print(formattedScore, "%d", score);+    orxString_NPrint(formattedScore, sizeof(formattedScore), "%d", score);
  
     orxObject_SetTextString(scoreObject, formattedScore);     orxObject_SetTextString(scoreObject, formattedScore);
Line 50: Line 53:
 Add 250 points whenever a monster is hit with a bullet. Add UpdateScore() function calls to: Add 250 points whenever a monster is hit with a bullet. Add UpdateScore() function calls to:
  
-<code=cpp>+<code=cpp [highlight_lines_extra="5,12"]>
 if (orxString_Compare(senderObjectName, "BulletObject") == 0){ if (orxString_Compare(senderObjectName, "BulletObject") == 0){
     CreateExplosionAtObject(pstRecipientObject, "JellyExploder");     CreateExplosionAtObject(pstRecipientObject, "JellyExploder");
Line 68: Line 71:
 And of course, 1000 points bonus if the star is reached. Add the following code: And of course, 1000 points bonus if the star is reached. Add the following code:
  
-<code=cpp>+<code=cpp [highlight_lines_extra="3,8"]>
 if (orxString_Compare(senderObjectName, "StarObject") == 0){ if (orxString_Compare(senderObjectName, "StarObject") == 0){
     orxObject_SetLifeTime(pstSenderObject, 0);     orxObject_SetLifeTime(pstSenderObject, 0);
Line 86: Line 89:
 A final thing for the game will be to add a game over panel when the hero dies. For this, we'll have an object that gets created using a timeline track after a two second delay. First, a game over asset: A final thing for the game will be to add a game over panel when the hero dies. For this, we'll have an object that gets created using a timeline track after a two second delay. First, a game over asset:
  
-{{ tutorials:community:sausage:gameover.png?nolink |}}+{{ tutorials:tracks:gameover.png?nolink |}}
  
-Save this into the ''data/texture'' folder as "gameover.png".+Save this into the ''data/texture'' folder as ''gameover.png''.
  
 Create a simple gameover graphic and object: Create a simple gameover graphic and object:
Line 111: Line 114:
 Then finally, change the physics handler code, so that when the hero is destroyed, create the timeline track. After a two second delay, the ''GameOverObject'' will be created on screen: Then finally, change the physics handler code, so that when the hero is destroyed, create the timeline track. After a two second delay, the ''GameOverObject'' will be created on screen:
  
-<code=cpp>+<code=cpp [highlight_lines_extra="7,16"]>
 if (orxString_Compare(recipientObjectName, "HeroObject") == 0 && if (orxString_Compare(recipientObjectName, "HeroObject") == 0 &&
     orxString_Compare(senderObjectName, "MonsterObject") == 0     orxString_Compare(senderObjectName, "MonsterObject") == 0
Line 131: Line 134:
 </code> </code>
  
-Because we never had a reference to the scene before in order to add the PopUpGameOverTrack, we'll need to make a variable reference to it at the top of the code:+Because we never had a reference to the ''scene'' before in order to add the PopUpGameOverTrack, we'll need to make a variable reference to it at the top of the code:
  
-<code=cpp>+<code=cpp [highlight_lines_extra="3"]>
 orxOBJECT *hero; orxOBJECT *hero;
 orxOBJECT *herosGun; orxOBJECT *herosGun;
Line 141: Line 144:
 </code> </code>
  
-And then set the ''scene'' variable on the  orxObject_CreateFromConfig("Scene") in the init() function:+And then set the ''scene'' variable on the  orxObject_CreateFromConfig("Scene") in the ''init()'' function:
  
-<code=cpp>+<code=cpp [highlight_lines_extra="3"]> 
 +scoreObject = orxObject_CreateFromConfig("ScoreObject"); 
 +orxObject_Enable(herosGun, orxFALSE);
 scene = orxObject_CreateFromConfig("Scene"); scene = orxObject_CreateFromConfig("Scene");
 </code> </code>
Line 157: Line 162:
 If you need quick examples, you can visit the [[en:examples:]] section and search by subject. If you need quick examples, you can visit the [[en:examples:]] section and search by subject.
  
-If you get stuck, please post it to the [[http://orx-project.org/forum|forum]], and for general chat, come and join us over in [[https://gitter.im/orx/orx|gitter]]. Hope to see you there.+If you get stuck, please post over on our [[https://orx-project.org/discord|Discord]]. Hope to see you there.
  
 {{section>en:guides:beginners:toc&noheader&nofooter&noeditbutton}} {{section>en:guides:beginners:toc&noheader&nofooter&noeditbutton}}
en/guides/beginners/text_and_game_over.1530275910.txt.gz · Last modified: 2018/06/29 08:38 (7 years ago) (external edit)