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
guides:beginners:text_and_game_over [2015/10/24 19:04 (9 years ago)] sausageen:guides:beginners:text_and_game_over [2023/03/28 21:13 (13 months ago)] (current) iarwain
Line 15: Line 15:
 [ScoreObject] [ScoreObject]
 Graphic  = ScoreGraphic Graphic  = ScoreGraphic
-Position = (2020, 0)+Position = (-380-280, 0)
 </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:
Line 29: Line 29:
 </code> </code>
  
-Then a little function to increase the score and update the ScoreObject:+Next, create a score object and assign it to the scoreObject variable in the Init() function: 
 + 
 +<code=cpp> 
 +scoreObject = orxObject_CreateFromConfig("ScoreObject"); 
 +</code> 
 + 
 +Add a little function to increase the score and update the ScoreObject:
  
 <code=cpp> <code=cpp>
Line 36: Line 42:
  
     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 42: Line 48:
 </code> </code>
  
-Then 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>
Line 60: Line 66:
 </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>
Line 73: Line 79:
 } }
 </code> </code>
 +
 +Compile and run it. Shoot some monsters and collect the star and observe the score increasing.
  
 That takes care of having an active score object. That takes care of having an active score object.
Line 78: Line 86:
 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:
  
-{{ :en:orx: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 87: Line 95:
 [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 100: Line 109:
 </code> </code>
  
-Then finally in the 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>
Line 106: Line 115:
     orxString_Compare(senderObjectName, "MonsterObject") == 0     orxString_Compare(senderObjectName, "MonsterObject") == 0
 ){ ){
-    CreateExplosionAtObject(pstSenderObject, "HeroExploder");+    CreateExplosionAtObject(pstRecipientObject, "HeroExploder");
     orxObject_SetLifeTime(pstSenderObject, 0);     orxObject_SetLifeTime(pstSenderObject, 0);
     orxObject_Enable(pstRecipientObject, orxFALSE);     orxObject_Enable(pstRecipientObject, orxFALSE);
Line 115: Line 124:
     orxString_Compare(recipientObjectName, "MonsterObject") == 0     orxString_Compare(recipientObjectName, "MonsterObject") == 0
 ){ ){
-    CreateExplosionAtObject(pstRecipientObject, "HeroExploder"); +    CreateExplosionAtObject(pstSenderObject, "HeroExploder"); 
-    orxObject_SetLifeTime(pstSenderObject, 0);+    orxObject_SetLifeTime(pstRecipientObject, 0);
     orxObject_Enable(pstSenderObject, orxFALSE);     orxObject_Enable(pstSenderObject, orxFALSE);
     orxObject_AddTimeLineTrack(scene, "PopUpGameOverTrack");     orxObject_AddTimeLineTrack(scene, "PopUpGameOverTrack");
Line 122: Line 131:
 </code> </code>
  
-Becuase 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>
Line 132: Line 141:
 </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>
Line 144: Line 153:
 Well friends, that's game over. If you reached the end here, great job! You've learned many of the major features of Orx. Well friends, that's game over. If you reached the end here, great job! You've learned many of the major features of Orx.
  
-If you need more help, go to the [[en:orx:tutorials:by-subject|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 [[en:examples:]] section and search by subject.
  
-If you need quick examplesyou can visit the [[examples]] section and search by subject.+If you get stuckplease post it to the [[http://orx-project.org/forum|forum]]and for general chat, come and join us over on [[https://orx-project.org/discord|Discord]]. Hope to see you there.
  
-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.+{{section>en:guides:beginners:toc&noheader&nofooter&noeditbutton}}
en/guides/beginners/text_and_game_over.1445738643.txt.gz · Last modified: 2017/05/30 00:50 (7 years ago) (external edit)