{"id":901,"date":"2026-02-13T09:25:44","date_gmt":"2026-02-13T01:25:44","guid":{"rendered":"https:\/\/edu.circuspi.com\/?p=901"},"modified":"2026-03-09T16:04:40","modified_gmt":"2026-03-09T08:04:40","slug":"9-bringing-game-sprites-to-life","status":"publish","type":"post","link":"https:\/\/edu.circuspi.com\/index.php\/gamebit-en\/9-bringing-game-sprites-to-life\/","title":{"rendered":"9. Bringing Game Sprites to Life"},"content":{"rendered":"\n<p>In the previous unit, we completed a game where the player must eat a specific number of burgers within a time limit to win.<\/p>\n\n\n\n<p>Actually, we can add more elements to enrich the game content. For instance, we can add a &#8220;charming villain&#8221; (an enemy)\ud83d\ude08; if the player accidentally touches them, they lose health.\ud83d\udc94<\/p>\n\n\n\n<p>Of course, this villain shouldn&#8217;t just stand still; they need to behave dynamically. This is the focus of this unit: &#8220;<strong>Bringing Sprites to Life<\/strong>,&#8221; making the characters on screen flexible and alive.<\/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\">9.1 Making Sprites Move Automatically \u2013 Adding an Enemy<\/h2>\n\n\n\n<p>First, open the game designed in the previous unit. We are going to add an &#8220;<strong>Enemy<\/strong>.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1026\" height=\"603\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-1_01.png\" alt=\"\" class=\"wp-image-1225\"\/><\/figure>\n\n\n\n<p>You should be familiar with adding sprites. Click on &#8220;<strong>Sprites<\/strong>&#8221; in the <strong>Block Toolbox<\/strong>, use the create sprite block, and place it inside &#8220;<strong>on start<\/strong>.&#8221; <\/p>\n\n\n\n<p>You can design the sprite&#8217;s pattern yourself, just like the editor did, or use a pattern from the <strong>Gallery<\/strong>. Since it&#8217;s a villain, remember to make it look fierce!\ud83d\udc79\ud83d\udc79\ud83d\udc79<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1174\" height=\"856\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-1_02.png\" alt=\"\" class=\"wp-image-1226\"\/><\/figure>\n\n\n\n<p>After designing the pattern, besides remembering to &#8220;<strong>Rename the Variable<\/strong>,&#8221; please set the &#8220;<strong>Kind<\/strong>&#8221; to &#8220;<strong>Enemy<\/strong>.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"452\" height=\"288\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-1_03.png\" alt=\"\" class=\"wp-image-1227\"\/><\/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\">9.2 Making Sprites Move Automatically \u2013 Adding Life (Health) Function<\/h2>\n\n\n\n<p>We want to set a rule: during the game, if the controlled sprite touches the enemy, health will be deducted. Since our current game doesn&#8217;t have a health design, we need to add this feature. Click on &#8220;<strong>Info<\/strong>&#8221; in the <strong>Block Toolbox<\/strong>. You can see blocks related to &#8220;<strong>Life<\/strong>&#8221; here.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"394\" height=\"391\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-2_01.png\" alt=\"\" class=\"wp-image-1228\"\/><\/figure>\n\n\n\n<p>Just like the &#8220;<strong>Score<\/strong>&#8221; blocks in the previous unit, simply drag the Life-related blocks into the <strong>Workspace<\/strong>. After assembling the code correctly, a heart icon will appear in the top-left 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=\"539\" height=\"443\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-2_02.png\" alt=\"\" class=\"wp-image-1229\"\/><\/figure>\n\n\n\n<p>Now, drag the &#8220;<strong>set life to ( 3 )<\/strong>&#8221; block into &#8220;<strong>on start<\/strong>.&#8221; It can be placed anywhere, as long as it is <strong>before<\/strong> the &#8220;<strong>start countdown ( 10 ) seconds<\/strong>&#8221; block.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"336\" height=\"212\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-2_03.png\" alt=\"\" class=\"wp-image-1231\"\/><\/figure>\n\n\n\n<p>You can set the number of lives yourself. You can even set it to 100. Note that if the number exceeds 4 hearts, the display style will automatically adjust to avoid blocking the screen.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"327\" height=\"438\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-2_04.png\" alt=\"\" class=\"wp-image-1232\"\/><\/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\">9.3 Making Sprites Move Automatically \u2013 Reducing Life<\/h2>\n\n\n\n<p>We taught the method for triggering events when sprites touch in Unit 6: the &#8220;<strong>Overlaps<\/strong>&#8221; block in the &#8220;<strong>Sprites<\/strong>&#8221; list. The difference this time is that we need to set the <em>other<\/em> Kind to &#8220;<strong>Enemy<\/strong>.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"549\" height=\"203\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-3_01.png\" alt=\"\" class=\"wp-image-1233\"\/><\/figure>\n\n\n\n<p>When the player touches the villain, we will change the initial life value. Click on &#8220;<strong>Info<\/strong>&#8221; in the <strong>Block Toolbox<\/strong> and find &#8220;<strong>change life by ( -1 )<\/strong>.&#8221; The usage is the same as &#8220;<strong>change score<\/strong>.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"573\" height=\"226\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-3_02.png\" alt=\"\" class=\"wp-image-1234\"\/><\/figure>\n\n\n\n<p>The &#8220;<strong>on overlaps<\/strong>&#8221; block functions such that it executes continuously as long as the sprites are overlapping. Because the program runs very fast, it might happen that before you can separate the sprites, your health is drained instantly. Therefore, we need to pause the program briefly upon contact (creating a temporary invincibility or cooldown period).<\/p>\n\n\n\n<p>Click on &#8220;<strong>Loops<\/strong>&#8221; in the <strong>Block Toolbox<\/strong> to find the &#8220;<strong>pause ( 100 ) ms<\/strong>&#8221; block.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"424\" height=\"534\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-3_03.png\" alt=\"\" class=\"wp-image-1235\"\/><\/figure>\n\n\n\n<p>Drag this block out and place it <strong>below<\/strong> &#8220;<strong>change life by ( -1 )<\/strong>.&#8221; This prevents instant death from rapid health deduction!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"565\" height=\"258\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-3_04.png\" alt=\"\" class=\"wp-image-1236\"\/><\/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\">9.4 Making Sprites Move Automatically \u2013 Enemy Patterns<\/h2>\n\n\n\n<p>Before making the villain move, we need to adjust everyone&#8217;s initial positions to avoid losing health the moment the game starts.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"428\" height=\"339\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-4.png\" alt=\"\" class=\"wp-image-1237\"\/><\/figure>\n\n\n\n<p>Common enemy behavior patterns fall into two types: &#8220;<strong>Chasing the Player<\/strong>&#8221; and &#8220;<strong>Teleporting<\/strong>.&#8221; Let&#8217;s introduce them in order.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">9.4.1 Chasing the Player<\/h3>\n\n\n\n<p>Before we explain, you might have thought: &#8220;Since it needs to chase the player, do we need to know the &#8216;Player&#8217;s coordinates&#8217; and the &#8216;Enemy&#8217;s coordinates,&#8217; calculate the angle of the shortest distance, and then pursue?&#8221;<\/p>\n\n\n\n<p>No, no, no. While theoretically correct, practical operation doesn&#8217;t need to be that complex. MakeCode Arcade has already figured it out for us.<\/p>\n\n\n\n<p>Let&#8217;s click on &#8220;<strong>Sprites<\/strong>.&#8221; Inside the &#8220;<strong>Physics<\/strong>&#8221; section of the list, you can find the &#8220;<strong>set [myEnemy] follow [mySprite]<\/strong>&#8221; block.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"702\" height=\"358\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-4-1_01.png\" alt=\"\" class=\"wp-image-1238\"\/><\/figure>\n\n\n\n<p>Drag this block into &#8220;<strong>on start<\/strong>.&#8221; Click the &#8220;<strong>+<\/strong>&#8221; sign at the end of the block to see the &#8220;<strong>Speed<\/strong>&#8221; setting field. The default speed of 100 makes the enemy as fast as the player\u2014playing at this speed is extremely difficult! You&#8217;ll be caught in the blink of an eye. So, please change it to a lower number.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"496\" height=\"295\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-4-1_02.png\" alt=\"\" class=\"wp-image-1239\"\/><\/figure>\n\n\n\n<p>After setting it, test it with the <strong>Game Simulator<\/strong> and repeatedly adjust it to a speed you feel is appropriate.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"404\" height=\"546\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-4-1_03.gif\" alt=\"\" class=\"wp-image-1240\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">9.4.2 Teleporting<\/h3>\n\n\n\n<p>Another method is to make the enemy instantly &#8220;<strong>Change Position<\/strong>&#8221; at a &#8220;<strong>Fixed Frequency<\/strong>.&#8221; For example, setting the enemy to change position every two seconds creates a thrill when the enemy suddenly appears in front of you during gameplay.<\/p>\n\n\n\n<p>We learned how to randomly change positions in previous units. The key is: <em>How do we automatically change the position after a specific interval?<\/em><\/p>\n\n\n\n<p>We can use the &#8220;<strong>on game update every ( 500 ) ms<\/strong>&#8221; block found in the &#8220;<strong>Game<\/strong>&#8221; category.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"568\" height=\"323\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-4-2_01.png\" alt=\"\" class=\"wp-image-1241\"\/><\/figure>\n\n\n\n<p>When we set the &#8220;<strong>Interval<\/strong>,&#8221; this block will continuously run the code inside it according to that interval. We want to change the enemy&#8217;s position every 2 seconds, so enter <strong>2000<\/strong> (since the unit is milliseconds) or select <strong>2 seconds<\/strong> from the dropdown menu.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"298\" height=\"147\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-4-2_02.png\" alt=\"\" class=\"wp-image-1242\"\/><\/figure>\n\n\n\n<p>Finally, place the &#8220;<strong>Random Position<\/strong>&#8221; method inside this block. <strong>Remember to select the Enemy&#8217;s variable name.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"596\" height=\"177\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-4-2_03.png\" alt=\"\" class=\"wp-image-1243\"\/><\/figure>\n\n\n\n<p>Once finished, try playing 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=\"266\" height=\"362\" src=\"https:\/\/edu.circuspi.com\/wp-content\/uploads\/2026\/02\/eng-09-4-2_04.gif\" alt=\"\" class=\"wp-image-1244\"\/><\/figure>\n\n\n\n<p>In this unit, we learned about &#8220;<strong>Life (Health)<\/strong>&#8221; and &#8220;<strong>Animating Sprites<\/strong>.&#8221; In addition to the original tension of the time limit, the addition of the villain adds a lot of excitement and fun to the process. Currently, the gameplay mainly involves using the joystick to dodge.<\/p>\n\n\n\n<p>Next, we will add the ability for the character to attack, just like the fighter jet in the &#8220;Space Destroyer&#8221; example, which can fire beams to destroy meteors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous unit, we completed a game where the pla [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":444,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,23],"tags":[],"table_tags":[],"class_list":{"0":"post-901","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\/901","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=901"}],"version-history":[{"count":3,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/901\/revisions"}],"predecessor-version":[{"id":1245,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/posts\/901\/revisions\/1245"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/media\/444"}],"wp:attachment":[{"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/media?parent=901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/categories?post=901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/tags?post=901"},{"taxonomy":"table_tags","embeddable":true,"href":"https:\/\/edu.circuspi.com\/index.php\/wp-json\/wp\/v2\/table_tags?post=901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}