{"id":1957,"date":"2019-05-05T18:15:57","date_gmt":"2019-05-05T16:15:57","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=1957"},"modified":"2019-05-13T06:46:45","modified_gmt":"2019-05-13T04:46:45","slug":"pythonista-make-a-game-faster","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/pythonista-make-a-game-faster\/","title":{"rendered":"Pythonista: make a game faster"},"content":{"rendered":"<h1>The playlist<\/h1>\n<p>Here you will find the playlist of the tutorial about making this game. You can find the official documentation here: <a href=\"http:\/\/omz-software.com\/pythonista\/docs\/ios\/scene.html#introduction\">http:\/\/omz-software.com\/pythonista\/docs\/ios\/scene.html#introduction<\/a> .<\/p>\n<p>I am going to add the new videos util the game will be completed. Have fun.<\/p>\n<p><iframe loading=\"lazy\" title=\"Pythonista game faster (on ipad) 1 : create a SHIP\" width=\"747\" height=\"560\" src=\"https:\/\/www.youtube.com\/embed\/g-_sjvQFCqc?list=PL_38rYkBIiiVsPWcNfMyYVg90Bvz9gB9y&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>We made a game before with Pythonista. Now, we want to make it even faster, to show how easy is to make a game on the Ipad with this app, Pythonista.<\/p>\n<h2>The Ship<\/h2>\n<p>First, we create the ship attaching it to the ground Node.<\/p>\n<p>From the documentation:<\/p>\n<pre class=\"lang:default decode:true \">from scene import *\r\n\r\nclass MyScene (Scene):\r\n    def setup(self):\r\n        self.background_color = 'midnightblue'\r\n        self.ship = SpriteNode('spc:PlayerShip1Orange')\r\n        self.ship.position = self.size \/ 2\r\n        self.add_child(self.ship)\r\n\r\nrun(MyScene())<\/pre>\n<p>&nbsp;<\/p>\n<p><iframe loading=\"lazy\" title=\"Pythonista game faster (on ipad) 1 : create a SHIP\" width=\"747\" height=\"560\" src=\"https:\/\/www.youtube.com\/embed\/g-_sjvQFCqc?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h2>Movement of the ship with tilting<\/h2>\n<p><iframe loading=\"lazy\" title=\"Pythonista game faster (on Ipad) II : move the SHIP\" width=\"747\" height=\"560\" src=\"https:\/\/www.youtube.com\/embed\/OJ8P3VNZ5e4?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h2>Enemies<\/h2>\n<p><iframe loading=\"lazy\" title=\"Pythonista game faster (on Ipad) III - Enemys are coming\" width=\"747\" height=\"560\" src=\"https:\/\/www.youtube.com\/embed\/jVH4rcjVQis?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<pre class=\"lang:default decode:true \"># import scene\r\n# create a class Game\r\n# def setup\r\n# create a ground Node\r\n# create ship and position\r\n# add ship to ground\r\n# run the Game\r\n\r\nfrom scene import *\r\nimport random\r\n\r\nclass Game(Scene):\r\n\tdef setup(self):\r\n\t\tground = Node(parent=self)\r\n\t\tself.ship = SpriteNode('spc:PlayerShip1Blue')\r\n\t\tself.ship.position = self.size.w \/ 2, 51\r\n\t\tground.add_child(self.ship)\r\n\r\n# def update\r\n# use gravity and abs(g.y) to change position\r\n# put the limit from 0 to the screen width\r\n\t\t\t\t\t\t\r\n\tdef update(self):\r\n\t\tg = gravity()\r\n\t\tif abs(g.y) &gt; 0.05:\r\n\t\t\tself.ship.position = max(0, min(self.size.w, self.ship.position.x + g.x * 120)), 51\r\n\r\n# create a class Enemy\r\n# import the random module\r\n# if random = create enemy at a random pos\t\t\r\n# make the enemy move\r\n\r\n\t\tif random.random() &lt; .01:\r\n\t\t\tenemy = Enemy(parent=self)\r\n\t\t\tenemy.position = random.uniform(0, self.size.w), self.size.h+60\r\n\t\t\tenemy.run_action(\r\n\t\t\t\tAction.sequence(\r\n\t\t\t\t\tAction.move_by(random.uniform(-100,500), 200, 2),\r\n\t\t\t\t\tAction.move_to(random.uniform(100,500), 500, 2),\r\n\t\t\t\t\tAction.move_to(random.uniform(100,500), 300,2),\r\n\t\t\t\t\tAction.move_to(random.uniform(-1,1)*500,0,3),\r\n\t\t\t\t\tAction.remove()\r\n\t\t\t\t)\r\n\t\t\t)\r\n\t\r\n\t\r\nclass Enemy(SpriteNode):\r\n\t\tdef __init__(self, **kwargs):\r\n\t\t\tSpriteNode.__init__(self,'spc:EnemyRed1', **kwargs)\r\n\t\t\r\nrun(Game())<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"Let&#8217;s make another game with pythonista on the ipad, this time with a space ship.\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/pythonista-make-a-game-faster\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":1963,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1,363],"tags":[137,225,4,226],"class_list":["post-1957","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples","category-pythonista-game","tag-game","tag-ipad","tag-python","tag-pythonista"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":false,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/1957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=1957"}],"version-history":[{"count":6,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/1957\/revisions"}],"predecessor-version":[{"id":1996,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/1957\/revisions\/1996"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/1963"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=1957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=1957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=1957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}