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/02/13 20:47 (7 years ago)] – ↷ Page moved from guides:beginners:text_and_game_over to en:guides:beginners:text_and_game_over iarwainen:guides:beginners:text_and_game_over [2024/11/19 04:21 (4 months ago)] (current) – Highlights sausage
Line 15: Line 15:
 [ScoreObject] [ScoreObject]
 Graphic  = ScoreGraphic Graphic  = ScoreGraphic
-Position = (2020, 0)+Position = (-380-280, 0) 
 +Scale    = 2
 </code> </code>
  
-Interesting to note the special Text definition. ScoreGraphic uses this instead of a texture from file. And the ScoreObject uses the graphic section as others before.+Interesting to note the special ''Text'' definition. ''ScoreGraphic'' uses this instead of a texture from file. And the ''ScoreObject'' uses the graphic section as others before.
  
 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 48: Line 51:
 </code> </code>
  
-Add 250 points whenever a monster is hit with a bullet:+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 66: Line 69:
 </code> </code>
  
-And of course, 1000 points bonus if the star is reached:+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/object 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 95: Line 98:
 [GameOverGraphic] [GameOverGraphic]
 Texture = gameover.png Texture = gameover.png
 +Pivot   = center
  
 [GameOverObject] [GameOverObject]
 Graphic  = GameOverGraphic Graphic  = GameOverGraphic
-Position = (280250, -0.1)+Position = (00, -0.1)
 </code> </code>
  
-Create a timeline track with a single command to create the GameOverObject:+Create a timeline track with a single command to create the ''GameOverObject'':
  
 <code=ini> <code=ini>
Line 108: Line 112:
 </code> </code>
  
-Then finally in the physics handler code, 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 130: 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 140: Line 144:
 </code> </code>
  
-And then set the 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 154: Line 160:
 If you need more help, go to the [[en:tutorials:main|tutorials]] section where many of these concepts are covered in greater detail. If you need more help, go to the [[en:tutorials:main|tutorials]] section where many of these concepts are covered in greater detail.
  
-If you need quick examples, you can visit the [[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>guides:beginners:toc&noheader&nofooter&noeditbutton}}+{{section>en:guides:beginners:toc&noheader&nofooter&noeditbutton}}
en/guides/beginners/text_and_game_over.1518583673.txt.gz · Last modified: 2018/02/14 00:47 (7 years ago) (external edit)