{"id":191,"date":"2026-05-29T13:08:06","date_gmt":"2026-05-29T13:08:06","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/d_eanes\/?p=191"},"modified":"2026-05-29T13:08:06","modified_gmt":"2026-05-29T13:08:06","slug":"free-friday-5-15-26","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/d_eanes\/2026\/05\/29\/free-friday-5-15-26\/","title":{"rendered":"Free Friday 5\/15\/26"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Today I worked on a Space Invaders game. This version includes sound effects, score tracking, multiple enemies, and a simple bullet system. I also added a background image and registered custom shapes for the player and invaders.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>Screen Setup<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>wn = turtle.Screen()\nwn.bgcolor(\"black\")\nwn.title(\"Space Invaders\")\nwn.bgpic(\"space_invaders_background.gif\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The game window now has a title and a background image. This helps define the play area visually and makes the sprites easier to see.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>Border Drawing<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>border_pen.setposition(-300, -300)\nfor side in range(4):\n    border_pen.fd(600)\n    border_pen.lt(90)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A simple white border outlines the playable space. It keeps the movement of the player and enemies contained and gives the game a clear frame.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>Score System<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>score = 0\nscore_pen.write(\"Score: %s\" % score)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The score is displayed in the upper\u2011left corner. It increases whenever the player destroys an enemy. The score text is cleared and rewritten each time it changes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>Player Setup<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>player.shape(\"player.gif\")\nplayer.setposition(0, -250)\nplayer.setheading(90)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The player uses a custom GIF shape and starts near the bottom of the screen. Movement is limited to left and right, which matches the classic Space Invaders style.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>Enemy Setup<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>x = random.randint(-200, 200)\ny = random.randint(100, 250)\nenemy.setposition(x, y)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A group of enemies is created and placed randomly near the top of the screen. They move horizontally as a formation. When one reaches a boundary, all enemies shift downward and reverse direction.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>Bullet System<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>if bulletstate == \"ready\":\n    os.system(\"afplay laser.wav&amp;\")\n    bulletstate = \"fire\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The bullet uses a small triangle shape and fires straight upward. It can only be fired again once it either hits an enemy or leaves the top of the screen. A laser sound plays each time the bullet is launched.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>Collision Detection<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>distance = math.sqrt((t1.xcor()-t2.xcor())**2 + (t1.ycor()-t2.ycor())**2)\nif distance &lt; 15:\n    return True\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Collisions are checked using simple distance calculations. When the bullet hits an enemy, an explosion sound plays, the enemy resets to a new position, and the score increases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>Main Game Loop<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>x = enemy.xcor()\nx += enemyspeed\nenemy.setx(x)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop moves each enemy, handles direction changes, updates the bullet, checks for collisions, and updates the score. If an enemy collides with the player, both sprites are hidden and the game ends.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"891\" src=\"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-content\/uploads\/2026\/05\/Screenshot-2026-05-29-013829-1024x891.png\" alt=\"\" class=\"wp-image-193\" srcset=\"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-content\/uploads\/2026\/05\/Screenshot-2026-05-29-013829-1024x891.png 1024w, https:\/\/theroyalscode.com\/students\/d_eanes\/wp-content\/uploads\/2026\/05\/Screenshot-2026-05-29-013829-300x261.png 300w, https:\/\/theroyalscode.com\/students\/d_eanes\/wp-content\/uploads\/2026\/05\/Screenshot-2026-05-29-013829-768x669.png 768w, https:\/\/theroyalscode.com\/students\/d_eanes\/wp-content\/uploads\/2026\/05\/Screenshot-2026-05-29-013829-1536x1337.png 1536w, https:\/\/theroyalscode.com\/students\/d_eanes\/wp-content\/uploads\/2026\/05\/Screenshot-2026-05-29-013829.png 1907w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Today I worked on a Space Invaders game. This version includes sound effects, score tracking, multiple enemies, and a simple bullet system. I also added a background image and registered custom shapes for the player and invaders. Screen Setup The game window now has a title and a background image. This helps define the play&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-191","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/posts\/191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/comments?post=191"}],"version-history":[{"count":3,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/posts\/191\/revisions"}],"predecessor-version":[{"id":196,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/posts\/191\/revisions\/196"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/media?parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/categories?post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_eanes\/wp-json\/wp\/v2\/tags?post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}