{"id":247,"date":"2025-10-20T15:17:31","date_gmt":"2025-10-20T15:17:31","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/k_rai\/?p=247"},"modified":"2025-10-20T15:17:31","modified_gmt":"2025-10-20T15:17:31","slug":"alien-invasion-10-03-25","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/k_rai\/2025\/10\/20\/alien-invasion-10-03-25\/","title":{"rendered":"Alien Invasion 10\/03\/25"},"content":{"rendered":"\n<p>I worked on my project of alien invasion by first making the background and the color. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"832\" height=\"303\" src=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-4.png\" alt=\"\" class=\"wp-image-248\" srcset=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-4.png 832w, https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-4-300x109.png 300w, https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-4-768x280.png 768w\" sizes=\"auto, (max-width: 832px) 100vw, 832px\" \/><\/figure>\n\n\n\n<p>The [ pygame.display ] displays the window that is Customizable with the Height and how tall it is, important when we need to start the Invasion. <\/p>\n\n\n\n<p>The sys and pygame modules already the has tools that we need helping us not do more work. Like the exit inside the sys module that helps the player exit out<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"435\" height=\"223\" src=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-5.png\" alt=\"\" class=\"wp-image-249\" srcset=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-5.png 435w, https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-5-300x154.png 300w\" sizes=\"auto, (max-width: 435px) 100vw, 435px\" \/><\/figure>\n\n\n\n<p>I created the setting module that stores all the value in one place allowing us to access the settings at any time making it easier to change the game&#8217;s apereance and the values. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"351\" height=\"197\" src=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-6.png\" alt=\"\" class=\"wp-image-251\" srcset=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-6.png 351w, https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-6-300x168.png 300w\" sizes=\"auto, (max-width: 351px) 100vw, 351px\" \/><\/figure>\n\n\n\n<p>This is the ship image i&#8217;ll be putting on the screen <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"632\" height=\"374\" src=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-7.png\" alt=\"\" class=\"wp-image-252\" srcset=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-7.png 632w, https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-7-300x178.png 300w\" sizes=\"auto, (max-width: 632px) 100vw, 632px\" \/><\/figure>\n\n\n\n<p>pygame.image.load helps to import the picture from the images folder to the window screen. Using the get_rect() to assign it to self.screen_rect allows us to correctly place the ship on the screen.  <\/p>\n\n\n\n<p>Attributes like midbottom, midtop, midleft and midright helps to just use the x and y attributes instead of manually having to do the calculation <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"570\" height=\"332\" src=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-8.png\" alt=\"\" class=\"wp-image-253\" srcset=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-8.png 570w, https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-8-300x175.png 300w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/figure>\n\n\n\n<p>if statements inside the update function manages the ship movements in the direction left and right<\/p>\n\n\n\n<p>The blitme function draws the image at the specific point helped by the self.rect <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"443\" height=\"525\" src=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-9.png\" alt=\"\" class=\"wp-image-254\" srcset=\"https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-9.png 443w, https:\/\/theroyalscode.com\/students\/k_rai\/wp-content\/uploads\/2025\/10\/alien-invasion-9-253x300.png 253w\" sizes=\"auto, (max-width: 443px) 100vw, 443px\" \/><\/figure>\n\n\n\n<p>Check events checks for what kind of event we want and each keypresses are in KEYDOWN event. WE need to check if the key was pressed that triggers the action. <\/p>\n\n\n\n<p>Like if the right arrow was pressed then the ship moves right increasing the value  of self.ship.rect represented by the  pygame.K_RIGHT <\/p>\n\n\n\n<p>The pygame.KEYUP looks for whether the key pressed down is released or not so the ship stops moving if the key is released. <\/p>\n\n\n\n<p class=\"has-big-font-size\"><strong>[ its short because i had to do this twice and lost all my progress ] <\/strong><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I worked on my project of alien invasion by first making the background and the color. The [ pygame.display ] displays the window that is Customizable with the Height and how tall it is, important when we need to start the Invasion. The sys and pygame modules already the has tools that we need helping [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":232,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-247","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-free-friday"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/posts\/247","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/comments?post=247"}],"version-history":[{"count":2,"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/posts\/247\/revisions"}],"predecessor-version":[{"id":258,"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/posts\/247\/revisions\/258"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/media\/232"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/media?parent=247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/categories?post=247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/k_rai\/wp-json\/wp\/v2\/tags?post=247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}