{"id":6012,"date":"2023-02-27T10:11:00","date_gmt":"2023-02-27T10:11:00","guid":{"rendered":"https:\/\/www.goodacademic.com\/blog\/questions\/starters-to-make-a-star-wars-space-invaders-type-game\/"},"modified":"2023-02-27T10:11:00","modified_gmt":"2023-02-27T10:11:00","slug":"starters-to-make-a-star-wars-space-invaders-type-game","status":"publish","type":"questions","link":"https:\/\/www.goodacademic.com\/blog\/questions\/starters-to-make-a-star-wars-space-invaders-type-game\/","title":{"rendered":"Starters to make a Star wars space invaders type game"},"content":{"rendered":"<div class=\"col-sm-12 messageContent\">\n <b>Learning Goal: <\/b>I&#8217;m working on a python exercise and need a sample draft to help me learn.<\/p>\n<p>import pgzrun<\/p>\n<p>import random<\/p>\n<p># constants<\/p>\n<p>WIDTH = 800<\/p>\n<p>HEIGHT = 600<\/p>\n<p># initialise score<\/p>\n<p>score = 0<\/p>\n<p># store image inside image folder in the same directory<\/p>\n<p>#ship = Actor(&#8216;playership1_red&#8217;)<\/p>\n<p>ship = Actor(&#8216;playerflacon3_white&#8217;)<\/p>\n<p>ship.x = 400<\/p>\n<p>ship.y = 500<\/p>\n<p>gem = Actor(&#8216;gemyellow&#8217;)<\/p>\n<p>gem.x = 400<\/p>\n<p>gem.y = 100<\/p>\n<p>def update():<\/p>\n<p>global score<\/p>\n<p>if keyboard.left:<\/p>\n<p>if ship.x &lt;= 15: #detects if ship has reached left side of screen<\/p>\n<p>ship.x = 15<\/p>\n<p>ship.x = ship.x &#8211; 5<\/p>\n<p>if keyboard.right:<\/p>\n<p>if ship.x &gt;= 785: #detects if ship has reached right side of screen<\/p>\n<p>ship.x = 785<\/p>\n<p>ship.x = ship.x + 5<\/p>\n<p>if keyboard.up:<\/p>\n<p>if ship.y &lt;= 0: #detects if ship has reached the top of screen<\/p>\n<p>ship.y = 15<\/p>\n<p>ship.y = ship.y &#8211; 5<\/p>\n<p>if keyboard.down:<\/p>\n<p>if ship.y &gt;= 600: #detects if ship has reached the bottom of screen<\/p>\n<p>ship.y = 600<\/p>\n<p>ship.y = ship.y + 5<\/p>\n<p>gem.y = gem.y + 4<\/p>\n<p>if gem.y &gt; 600:<\/p>\n<p>gem.y = 0<\/p>\n<p>if gem.colliderect(ship):<\/p>\n<p>gem.x = random.randint(20, 780)<\/p>\n<p>gem.y = 0<\/p>\n<p>score = score + 10<\/p>\n<p>def draw ():<\/p>\n<p>screen.clear()<\/p>\n<p>ship.draw()<\/p>\n<p>enemy.draw()<\/p>\n<p>gem.draw()<\/p>\n<p>screen.draw.text(&#8216;Score: &#8216; + str(score), (15,10), color=(255,255,255), fontsize=30)<\/p>\n<p>pgzrun.go() # Must be last line<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learning Goal: I&#8217;m working on a python exercise and need a sample draft to help me learn. import pgzrun import random # constants WIDTH = 800 HEIGHT = 600 # initialise score score = 0 # store image inside image folder in the same directory #ship = Actor(&#8216;playership1_red&#8217;) ship = Actor(&#8216;playerflacon3_white&#8217;) ship.x = 400 ship.y [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":[],"disciplines":[734],"paper_types":[],"tagged":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/6012"}],"collection":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions"}],"about":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/types\/questions"}],"author":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/comments?post=6012"}],"version-history":[{"count":0,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/6012\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/media?parent=6012"}],"wp:term":[{"taxonomy":"disciplines","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/disciplines?post=6012"},{"taxonomy":"paper_types","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/paper_types?post=6012"},{"taxonomy":"tagged","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/tagged?post=6012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}