{"id":894,"date":"2026-02-13T09:13:36","date_gmt":"2026-02-13T01:13:36","guid":{"rendered":"https:\/\/edu.circuspi.com\/?p=894"},"modified":"2026-03-09T15:56:20","modified_gmt":"2026-03-09T07:56:20","slug":"8-designing-game-win-and-loss-conditions","status":"publish","type":"post","link":"https:\/\/edu.circuspi.com\/index.php\/gamebit-en\/8-designing-game-win-and-loss-conditions\/","title":{"rendered":"8. Designing Game Win and Loss Conditions"},"content":{"rendered":"\n<p>We are going to add conditions to determine victory or defeat, transforming the simple &#8220;Orange Dinosaur eats Burger&#8221; interaction into an exciting mini-game. For example, we can add a &#8220;<strong>Scoring Mechanism<\/strong>&#8221; where eating a burger adds a point, and the eaten burger &#8220;<strong>Randomly<\/strong>&#8221; respawns elsewhere. Or, we could add &#8220;bad food&#8221; that gives the dinosaur a stomach ache. As long as you have an idea, you can add it to your game to make it richer.<\/p>\n\n\n\n<p>Since this continues from the previous unit, you need to have &#8220;<strong>Two Sprites<\/strong>&#8221; prepared: one controlled by the player, and another to be eaten or destroyed. If you have been following this tutorial series step-by-step, you are already prepared!<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">8.1 Learning to Calculate Scores<\/h2>\n\n\n\n<p>First, open your project from the previous unit. You should have two sprites, and when they overlap, the non-player sprite is destroyed.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"863\" height=\"418\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-1_01.png\" alt=\"\" class=\"wp-image-1191\"\/><\/figure>\n\n\n\n<p>Taking the characters in the image as an example, our idea is: when the Burger is &#8220;<strong>destroyed<\/strong>&#8220;, we &#8220;<strong>gain points<\/strong>&#8220;. In MakeCode Arcade, a group of blocks is dedicated to handling this information: the &#8220;<strong>Info<\/strong>&#8221; category in the <strong>Block Toolbox<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"796\" height=\"495\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-1_02.png\" alt=\"\" class=\"wp-image-1192\"\/><\/figure>\n\n\n\n<p>The &#8220;<strong>Info<\/strong>&#8221; category contains blocks like &#8220;<strong>Score<\/strong>&#8220;, &#8220;<strong>Life<\/strong>&#8220;, and &#8220;<strong>Countdown<\/strong>&#8220;, which we will use in order.<\/p>\n\n\n\n<p>When we drag score-related blocks into the <strong>Workspace<\/strong> and assemble the code correctly, a score area will appear in the top-right corner of the <strong>Game Simulator<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1043\" height=\"498\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-1_03.png\" alt=\"\" class=\"wp-image-1194\"\/><\/figure>\n\n\n\n<p>Now, let&#8217;s drag the &#8220;<strong>set score to ( 0 )<\/strong>&#8221; block and place it inside the &#8220;<strong>on start<\/strong>&#8221; block (it can be placed anywhere inside). Placing it in &#8220;<strong>on start<\/strong>&#8221; ensures the score resets to zero when the game restarts.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1145\" height=\"457\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-1_04.png\" alt=\"\" class=\"wp-image-1195\"\/><\/figure>\n\n\n\n<p>Next, we need a block to help us adjust the score. Also found in &#8220;<strong>Info<\/strong>,&#8221; drag out the &#8220;<strong>change score by ( 1 )<\/strong>&#8221; block.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"494\" height=\"394\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-1_05.png\" alt=\"\" class=\"wp-image-1196\"\/><\/figure>\n\n\n\n<p>The &#8220;1&#8221; in &#8220;<strong>change score by ( 1 )<\/strong>&#8221; means adding 1 to the current score. If you enter a negative number, it will subtract from the score, as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1144\" height=\"576\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-1_06.png\" alt=\"\" class=\"wp-image-1197\"\/><\/figure>\n\n\n\n<p>We can add this block to the &#8220;<strong>code that runs after the burger is eaten<\/strong>.&#8221; This way, when the Orange Dinosaur overlaps with the Burger, besides destroying the Burger, we also gain 1 point.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"258\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-1_07.png\" alt=\"\" class=\"wp-image-1198\"\/><\/figure>\n\n\n\n<p>Once finished, run it in the <strong>Game Simulator<\/strong> and pay attention to whether the score increases!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"620\" height=\"848\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-1_08.gif\" alt=\"\" class=\"wp-image-1199\"\/><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">8.2 Understanding Random Generation<\/h2>\n\n\n\n<p>Since the <strong>&#8220;Burger&#8221;<\/strong> is gone after being eaten, we need it to reappear. The method is simple: just create another burger. Besides setting its position, remember to set its &#8220;<strong>Kind<\/strong>&#8221; correctly so it meets the &#8220;<strong>Overlap Conditions<\/strong>.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"776\" height=\"368\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_01.png\" alt=\"\" class=\"wp-image-1200\"\/><\/figure>\n\n\n\n<p>However, you will notice the burger always appears in a fixed spot. In a normal game, it should be &#8220;<strong>Randomly Generated<\/strong>&#8221; in different places. We can find the convenient block &#8220;<strong>pick random ( 0 ) to ( 10 )<\/strong>&#8221; within the &#8220;<strong>Math<\/strong>&#8221; category in the <strong>Block Toolbox<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"522\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_02.png\" alt=\"\" class=\"wp-image-1201\"\/><\/figure>\n\n\n\n<p>We can fill in two numbers, and it will randomly generate a new number between them. Quick thinkers might already know what to use this for!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1600\" height=\"672\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_03.png\" alt=\"\" class=\"wp-image-1202\"\/><\/figure>\n\n\n\n<p>That&#8217;s right! We can use it to &#8220;<strong>Generate Coordinates<\/strong>.&#8221; Place this block into the <strong>x<\/strong> and <strong>y<\/strong> coordinate fields respectively. Fill in the ranges: <strong>0~160<\/strong> for the x-coordinate and <strong>0~120<\/strong> for the y-coordinate (based on screen pixel size).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"935\" height=\"379\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_04.png\" alt=\"\" class=\"wp-image-1203\"\/><\/figure>\n\n\n\n<p>After finishing, run it in the <strong>Game Simulator<\/strong>. Test it a few times, and you might notice that sometimes the burger disappears or gets stuck, as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"329\" height=\"459\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_05.png\" alt=\"\" class=\"wp-image-1204\"\/><\/figure>\n\n\n\n<p>This is because we didn&#8217;t restrict it to appear strictly <em>within<\/em> the visible screen area. We can use the &#8220;<strong>set [mySprite] stay in screen &lt;ON&gt;<\/strong>&#8221; block found in the &#8220;<strong>Sprites<\/strong>&#8221; category.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"681\" height=\"312\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_06.png\" alt=\"\" class=\"wp-image-1205\"\/><\/figure>\n\n\n\n<p>Place this block <strong>after<\/strong> the &#8220;create sprite&#8221; block. This adds a restriction immediately when the burger is created, so it won&#8217;t go out of bounds when randomly positioning. <\/p>\n\n\n\n<p><em>Remember to select the correct <strong>Variable Name<\/strong> (the target) at the beginning of the block.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"966\" height=\"427\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_07.png\" alt=\"\" class=\"wp-image-1206\"\/><\/figure>\n\n\n\n<p>Test it in the <strong>Game Simulator<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"338\" height=\"476\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_08.gif\" alt=\"\" class=\"wp-image-1207\"\/><\/figure>\n\n\n\n<p>We have completed the scoring and random spawning functions, but the game feels a bit empty. Let&#8217;s add some sound! Specifically, when the burger is eaten. Add the &#8220;<strong>Music<\/strong>&#8221; block we learned earlier to the destruction event. You can find a suitable sound effect or design one yourself.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"882\" height=\"467\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_09.png\" alt=\"\" class=\"wp-image-1208\"\/><\/figure>\n\n\n\n<p>While you&#8217;re at it, add some background music to enrich the game presentation. Remember to set the &#8220;<strong>looping<\/strong>&#8221; option to &#8220;<strong>true<\/strong>&#8221; for continuous playback.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"656\" height=\"496\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_10.png\" alt=\"\" class=\"wp-image-1209\"\/><\/figure>\n\n\n\n<p><strong>Adding a Challenge: The Countdown<\/strong> Gaining points endlessly without a result isn&#8217;t a game. Let&#8217;s add an element of excitement: a &#8220;<strong>Countdown Timer<\/strong>.&#8221; We will set a rule: if the score doesn&#8217;t meet the target when time runs out, the player loses.<\/p>\n\n\n\n<p>Drag out the &#8220;<strong>start countdown ( 10 ) seconds<\/strong>&#8221; block from the &#8220;<strong>Info<\/strong>&#8221; category.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"454\" height=\"475\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_11.png\" alt=\"\" class=\"wp-image-1210\"\/><\/figure>\n\n\n\n<p>Place this block at the very bottom of the &#8220;<strong>on start<\/strong>&#8221; block. This means the countdown begins just as the game starts. Feel free to set the duration.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"648\" height=\"494\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_12.png\" alt=\"\" class=\"wp-image-1211\"\/><\/figure>\n\n\n\n<p>Then, we need to determine the result when the timer ends. Drag out the &#8220;<strong>on countdown end<\/strong>&#8221; block from &#8220;<strong>Info<\/strong>&#8221; and place it in the <strong>Workspace<\/strong> (empty area).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"449\" height=\"400\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_13.png\" alt=\"\" class=\"wp-image-1212\"\/><\/figure>\n\n\n\n<p>Next, we need to judge if our score meets the target. Drag out the &#8220;<strong>if&#8230; then&#8230; else<\/strong>&#8221; block from &#8220;<strong>Logic<\/strong>&#8221; and place it inside &#8220;<strong>on countdown end<\/strong>.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"379\" height=\"429\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_14.png\" alt=\"\" class=\"wp-image-1213\"\/><\/figure>\n\n\n\n<p>Drag out the &#8220;<strong>score<\/strong>&#8221; block (the oval shape) from &#8220;<strong>Info<\/strong>.&#8221; This block stores our current score.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"447\" height=\"401\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_15.png\" alt=\"\" class=\"wp-image-1214\"\/><\/figure>\n\n\n\n<p>To compare the score, we need a &#8220;<strong>Comparison<\/strong>&#8221; block. Drag out the &#8220;<strong>&lt; ( 0 ) = ( 0 ) &gt;<\/strong>&#8221; block from &#8220;<strong>Logic<\/strong>.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"367\" height=\"284\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_16.png\" alt=\"\" class=\"wp-image-1215\"\/><\/figure>\n\n\n\n<p>Combine these three blocks. In the dropdown menu of the comparison block, select &#8220;<strong>&gt;<\/strong>&#8221; (greater than).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"386\" height=\"331\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_17.png\" alt=\"\" class=\"wp-image-1216\"\/><\/figure>\n\n\n\n<p>Choose your own target score.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"407\" height=\"323\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_18.png\" alt=\"\" class=\"wp-image-1217\"\/><\/figure>\n\n\n\n<p>Finally, the most critical block: select &#8220;<strong>game over &lt;LOSE&gt;<\/strong>&#8221; from the &#8220;<strong>Game<\/strong>&#8221; category. The option at the end determines whether the game is won or lost.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"702\" height=\"354\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_19.png\" alt=\"\" class=\"wp-image-1218\"\/><\/figure>\n\n\n\n<p>Add the different &#8220;<strong>Results<\/strong>&#8221; (Win\/Lose) into the condition slots sequentially. Now, an exciting and fun game is complete!!\ud83c\udf89\ud83c\udf89\ud83c\udf89<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"524\" height=\"468\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-08-2_20.png\" alt=\"\" class=\"wp-image-1219\"\/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are going to add conditions to determine victory or  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":438,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,23],"tags":[],"table_tags":[],"class_list":{"0":"post-894","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-gamebit-en","8":"category-freeinfo-en","9":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/comments?post=894"}],"version-history":[{"count":4,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/894\/revisions"}],"predecessor-version":[{"id":1224,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/894\/revisions\/1224"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/media\/438"}],"wp:attachment":[{"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/media?parent=894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/categories?post=894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/tags?post=894"},{"taxonomy":"table_tags","embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/table_tags?post=894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}