{"id":534,"date":"2021-07-05T11:27:55","date_gmt":"2021-07-05T11:27:55","guid":{"rendered":"https:\/\/www.bearloga.space\/?page_id=534"},"modified":"2021-07-05T11:27:55","modified_gmt":"2021-07-05T11:27:55","slug":"klassy-sprite-i-group","status":"publish","type":"page","link":"https:\/\/www.bearloga.space\/uk\/klassy-sprite-i-group\/","title":{"rendered":"\u041a\u043b\u0430\u0441\u0441\u044b Sprite \u0438 Group"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u0412 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u0433\u0440 \u0441\u043f\u0440\u0430\u0439\u0442\u043e\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0432 \u0432\u0438\u0434\u0435 \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043d\u0438\u043c. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0432\u0441\u0435 \u0447\u0442\u043e \u0432 \u0438\u0433\u0440\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u043e\u043d\u043e\u043c, \u0430 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c-\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u043e\u0439 \u2013 \u044d\u0442\u043e \u0441\u043f\u0440\u0430\u0439\u0442.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0425\u043e\u0442\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043f\u0440\u0430\u0439\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c, \u0443 \u0432\u0441\u0435\u0445 \u0435\u0441\u0442\u044c \u043d\u0435\u0447\u0442\u043e \u043e\u0431\u0449\u0435\u0435, \u0447\u0442\u043e \u0432 pygame \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Sprite, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 pygame.sprite.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041d\u0430 \u0431\u0430\u0437\u0435 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u043f\u0440\u0430\u0439\u0442\u043e\u0432 \u0438 \u0443\u0436\u0435 \u043e\u0442 \u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043b\u0430\u0441\u0441 pygame.sprite.Sprite \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0425\u043e\u0442\u044f \u0442\u0430\u043a\u043e\u0432\u044b\u043c \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0442 Sprite.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412 \u043c\u043e\u0434\u0443\u043b\u0435 pygame.sprite \u043a\u0440\u043e\u043c\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 Sprite \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 Group \u0438 \u0440\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0435\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0440\u0430\u0439\u0442\u043e\u0432 \u0432 \u0433\u0440\u0443\u043f\u043f\u044b. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u0433\u0440\u0443\u043f\u043f\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u043d\u043e\u0432\u0438\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0441\u043f\u0440\u0430\u0439\u0442\u043e\u0432, \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u044d\u0442\u0443 \u0433\u0440\u0443\u043f\u043f\u0443.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 pygame.sprite.Sprite \u043a\u0430\u0441\u0430\u044e\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0432 \u0433\u0440\u0443\u043f\u043f\u0443, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0438\u0437 \u043d\u0435\u0435, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f. \u0422\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434 update() \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u043f\u0440\u0430\u0439\u0442\u0430, \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u043c \u043e\u0442 Sprite \u043a\u043b\u0430\u0441\u0441\u0435.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043a\u043e\u0434\u0430 \u043d\u0438\u0436\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0434\u043d\u0430, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043c\u0430\u0448\u0438\u043d\u043e\u043a \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437. \u041a\u0430\u0436\u0434\u0430\u044f \u0442\u0430\u043a\u0430\u044f \u043c\u0430\u0448\u0438\u043d\u043a\u0430 \u2013 \u043e\u0431\u044a\u0435\u043a\u0442-\u0441\u043f\u0440\u0430\u0439\u0442, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Car, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043e\u0442 Sprite.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0442 Sprite \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0437\u0430\u0432\u0435\u0441\u0442\u0438\u0441\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438 Surface \u0438 Rect, \u0438\u043c\u0435\u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e self.image \u0438 self.rect. \u0422\u0430\u043a \u043d\u0430\u0434\u043e, \u0447\u0442\u043e\u0431\u044b \u0441 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0433\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0433\u0440\u0443\u043f\u043f\u044b. \u0412 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u044c (\u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c), \u043d\u0435\u0432\u0430\u0436\u043d\u043e. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 load(). \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u0436\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Surface.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>from<\/strong> random <strong>import<\/strong> randint\n<strong>import<\/strong> pygame <strong>as<\/strong> pg\n<strong>import<\/strong> sys\n&nbsp;\nW = 400\nH = 400\nWHITE = (255, 255, 255)\n&nbsp;\n&nbsp;\n<strong>class<\/strong> Car(pg.sprite.Sprite):\n    <strong>def<\/strong> __init__(self, x, filename):\n        pg.sprite.Sprite.__init__(self)\n        self.image = pg.image.load(\n            filename).convert_alpha()\n        self.rect = self.image.get_rect(\n            center=(x, 0))\n&nbsp;\n&nbsp;\nsc = pg.display.set_mode((W, H))\n&nbsp;\n<em># \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 x \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0430<\/em>\ncar1 = Car(randint(1, W), 'car1.png')\n&nbsp;\n<strong>while<\/strong> 1:\n    <strong>for<\/strong> i <strong>in<\/strong> pg.event.get():\n        <strong>if<\/strong> i.type == pg.QUIT:\n            sys.exit()\n&nbsp;\n    sc.fill(WHITE)\n    sc.blit(car1.image, car1.rect)\n    pg.display.update()\n    pg.time.delay(20)\n&nbsp;\n    <em># \u043c\u0430\u0448\u0438\u043d\u043a\u0430 \u0435\u0437\u0434\u0438\u0442 \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437<\/em>\n    <strong>if<\/strong> car1.rect.y &lt; H:\n        car1.rect.y += 2\n    <strong>else<\/strong>:\n        car1.rect.y = 0\n&nbsp;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430. \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 update():<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">... \n<strong>class<\/strong> Car(pg.sprite.Sprite):\n    <strong>def<\/strong> __init__(self, x, filename):\n        pg.sprite.Sprite.__init__(self)\n        self.image = pg.image.load(\n            filename).convert_alpha()\n        self.rect = self.image.get_rect(\n            center=(x, 0))\n\u00a0\n    <strong>def<\/strong> update(self):\n        <strong>if<\/strong> self.rect.y &lt; H:\n            self.rect.y += 2\n        <strong>else<\/strong>:\n            self.rect.y = 0\n\u00a0\n\u00a0\nsc = pg.display.set_mode((W, H))\n\u00a0\n<em># \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 x \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0430<\/em>\ncar1 = Car(randint(1, W), 'car1.png')\n\u00a0\n<strong>while<\/strong> 1:\n    <strong>for<\/strong> i <strong>in<\/strong> pg.event.get():\n        <strong>if<\/strong> i.type == pg.QUIT:\n            sys.exit()\n\u00a0\n    sc.fill(WHITE)\n    sc.blit(car1.image, car1.rect)\n    pg.display.update()\n    pg.time.delay(20)\n\u00a0\n    car1.update()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043d\u0435 \u043e\u0434\u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u043a\u0430, \u0430 \u0442\u0440\u0438:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/younglinux.info\/sites\/default\/files\/images\/python\/car1.png\" alt=\"\u041c\u0430\u0448\u0438\u043d\u043a\u0430 1\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">...\ncar1 = Car(randint(1, W), 'car1.png')\ncar2 = Car(randint(1, W), 'car2.png')\ncar3 = Car(randint(1, W), 'car3.png')\n&nbsp;\n<strong>while<\/strong> 1:\n    <strong>for<\/strong> i <strong>in<\/strong> pg.event.get():\n        <strong>if<\/strong> i.type == pg.QUIT:\n            sys.exit()\n&nbsp;\n    sc.fill(WHITE)\n    sc.blit(car1.image, car1.rect)\n    sc.blit(car2.image, car2.rect)\n    sc.blit(car3.image, car3.rect)\n    pg.display.update()\n    pg.time.delay(20)\n&nbsp;\n    car1.update()\n    car2.update()\n    car3.update()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0415\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 100 \u043c\u0430\u0448\u0438\u043d\u043e\u043a, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f 100 \u0440\u0430\u0437 \u0432\u044b\u0437\u0432\u0430\u0442\u044c blit() \u0438 update(). \u041a\u043b\u0430\u0441\u0441 Group \u0440\u0435\u0448\u0430\u0435\u0442 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043f\u0440\u0430\u0439\u0442\u044b \u0432 \u0433\u0440\u0443\u043f\u043f\u0443 \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u043c add() \u0433\u0440\u0443\u043f\u043f\u044b (\u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0438\u043b\u0438 \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0423 \u0433\u0440\u0443\u043f\u043f \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b update() \u0438 draw(). \u041c\u0435\u0442\u043e\u0434 update() \u0433\u0440\u0443\u043f\u043f\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b update() \u0432\u0441\u0435\u0445 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u043d\u0435\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0410 \u043c\u0435\u0442\u043e\u0434 draw() \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 blit(). \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432 draw() \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u044c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">...\ncars = pg.sprite.Group()\ncars.add(Car(randint(1, W), 'car1.png'),\n         Car(randint(1, W), 'car2.png'))\ncars.add(Car(randint(1, W), 'car3.png'))\n&nbsp;\n<strong>while<\/strong> 1:\n    <strong>for<\/strong> i <strong>in<\/strong> pg.event.get():\n        <strong>if<\/strong> i.type == pg.QUIT:\n            sys.exit()\n&nbsp;\n    sc.fill(WHITE)\n&nbsp;\n    cars.draw(sc)\n&nbsp;\n    pg.display.update()\n    pg.time.delay(20)\n&nbsp;\n    cars.update()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u043e\u0432\u044b\u0435 \u043c\u0430\u0448\u0438\u043d\u043a\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u043b\u0438\u0441\u044c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0434\u0432\u0438\u0433\u0430\u043b\u0438\u0441\u044c \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e, \u0430 \u0432\u044b\u0435\u0437\u0434 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u044d\u043a\u0440\u0430\u043d\u0430 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u043b \u0431\u044b, \u0447\u0442\u043e \u043e\u043d \u0438\u0441\u0447\u0435\u0437\u0430\u0435\u0442.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u0439\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 pygame.time.set_timer(). \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u0436\u0434\u044b\u0435 3 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f type \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043e\u0439 pygame.USEREVENT. \u0418 \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c, \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>from<\/strong> random <strong>import<\/strong> randint\n<strong>import<\/strong> pygame <strong>as<\/strong> pg\n<strong>import<\/strong> sys\n&nbsp;\npg.time.set_timer(pg.USEREVENT, 3000)\n&nbsp;\nW = 400\nH = 400\nWHITE = (255, 255, 255)\nCARS = ('car1.png', 'car2.png', 'car3.png')\n<em># \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043c\u0430\u0448\u0438\u043d-\u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u0435\u0439<\/em>\nCARS_SURF = []\n&nbsp;\n<em># \u043d\u0430\u0434\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0440\u0435\u0436\u0438\u043c<\/em>\n<em># \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 image.load()<\/em>\nsc = pg.display.set_mode((W, H))\n&nbsp;\n<strong>for<\/strong> i <strong>in<\/strong> range(len(CARS)):\n    CARS_SURF.append(\n        pg.image.load(CARS[i]).convert_alpha())\n&nbsp;\n&nbsp;\n<strong>class<\/strong> Car(pg.sprite.Sprite):\n    <strong>def<\/strong> __init__(self, x, surf, group):\n        pg.sprite.Sprite.__init__(self)\n        self.image = surf\n        self.rect = self.image.get_rect(\n            center=(x, 0))\n        <em># \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0433\u0440\u0443\u043f\u043f\u0443<\/em>\n        self.add(group)\n        <em># \u0443 \u043c\u0430\u0448\u0438\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u043d\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c<\/em>\n        self.speed = randint(1, 3)\n&nbsp;\n    <strong>def<\/strong> update(self):\n        <strong>if<\/strong> self.rect.y &lt; H:\n            self.rect.y += self.speed\n        <strong>else<\/strong>:\n            <em># \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0432\u0435\u0440\u0445,<\/em>\n            <em># \u0430 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u0437 \u0432\u0441\u0435\u0445 \u0433\u0440\u0443\u043f\u043f<\/em>\n            self.kill()\n&nbsp;\n&nbsp;\ncars = pg.sprite.Group()\n&nbsp;\n<em># \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u043c\u0430\u0448\u0438\u043d\u0443,<\/em>\n<em># \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443<\/em>\nCar(randint(1, W),\n    CARS_SURF[randint(0, 2)], cars)\n&nbsp;\n<strong>while<\/strong> 1:\n    <strong>for<\/strong> i <strong>in<\/strong> pg.event.get():\n        <strong>if<\/strong> i.type == pg.QUIT:\n            sys.exit()\n        <strong>elif<\/strong> i.type == pg.USEREVENT:\n            Car(randint(1, W),\n                CARS_SURF[randint(0, 2)], cars)\n&nbsp;\n    sc.fill(WHITE)\n&nbsp;\n    cars.draw(sc)\n&nbsp;\n    pg.display.update()\n    pg.time.delay(20)\n&nbsp;\n    cars.update()\n&nbsp;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u041c\u0435\u0442\u043e\u0434 kill() \u0441\u043f\u0440\u0430\u0439\u0442\u0430 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0438\u0437 \u0432\u0441\u0435\u0445 \u0433\u0440\u0443\u043f\u043f, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f. \u0415\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 remove(), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0433\u0440\u0443\u043f\u043f. \u0423 \u0441\u043f\u0440\u0430\u0439\u0442\u043e\u0432 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u0443 \u0433\u0440\u0443\u043f\u043f \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 add(). \u0422\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u043c\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u0433\u0440\u0443\u043f\u043f\u0430.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412 \u043c\u043e\u0434\u0443\u043b\u0435 pygame.sprite \u0435\u0441\u0442\u044c \u0440\u044f\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0439 \u0441\u043f\u0440\u0430\u0439\u0442\u043e\u0432. \u041e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 spritecollideany() \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043b\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0441\u043f\u0440\u0430\u0439\u0442 \u0441 \u043b\u044e\u0431\u044b\u043c \u0438\u0437 \u0441\u043f\u0440\u0430\u0439\u0442\u043e\u0432 \u0438\u0437 \u0433\u0440\u0443\u043f\u043f\u044b. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0441\u043f\u0440\u0430\u0439\u0442, \u0447\u044c\u044f \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f, \u0432\u0442\u043e\u0440\u044b\u043c \u2013 \u0433\u0440\u0443\u043f\u043f\u0443.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432\u044b\u0448\u0435 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043c\u0430\u0448\u0438\u043d\u043a\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u043b\u0438\u0441\u044c \u0447\u0430\u0449\u0435. \u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u043f\u0440\u0430\u0439\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 &#8220;\u0435\u0434\u0435\u0442&#8221; \u043d\u0430\u0432\u0441\u0442\u0440\u0435\u0447\u0443 \u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u0438\u043c \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0435\u043b\u043a\u0430\u043c\u0438 \u0432\u043b\u0435\u0432\u043e \u0438 \u0432\u043f\u0440\u0430\u0432\u043e \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0435. \u0426\u0435\u043b\u044c \u0438\u0433\u0440\u044b \u2013 \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0442\u043e\u043b\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043e\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a: <a href=\"https:\/\/younglinux.info\/\" target=\"_blank\" rel=\"noopener\">https:\/\/younglinux.info\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u0433\u0440 \u0441\u043f\u0440\u0430\u0439\u0442\u043e\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0432 \u0432\u0438\u0434\u0435 \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[73],"tags":[],"class_list":["post-534","page","type-page","status-publish","hentry","category-pygame-vvedenie-v-razrabotku-igr-na-python-kurs"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/pages\/534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/comments?post=534"}],"version-history":[{"count":0,"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/pages\/534\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/media?parent=534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/categories?post=534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/tags?post=534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}