{"id":335,"date":"2011-05-12T15:42:32","date_gmt":"2011-05-12T12:42:32","guid":{"rendered":"http:\/\/python.pingviinitiivul.ee\/?p=335"},"modified":"2011-05-12T16:54:55","modified_gmt":"2011-05-12T13:54:55","slug":"kakskummend-uheksa","status":"publish","type":"post","link":"https:\/\/python.pingviinitiivul.ee\/?p=335","title":{"rendered":"Kaksk\u00fcmmend \u00fcheksa"},"content":{"rendered":"<p>V\u00f5tame n\u00e4idiseks \u00fche lihtsa PyGame n\u00e4ite, milles saab liigutada palli:<\/p>\n<p><code><br \/>\n#!\/usr\/bin\/python<br \/>\n# -*- coding: utf-8 -*-<br \/>\nbif = \"bg.jpg\"<br \/>\nmif = \"ball.png\"<br \/>\nimport pygame<br \/>\nfrom pygame import *<br \/>\npygame.init()<br \/>\nekraan=pygame.display.set_mode((800, 600), 0, 32)<br \/>\ntaust=pygame.image.load(bif).convert()<br \/>\nhiir1=pygame.image.load(mif).convert_alpha()<br \/>\nhiir2=pygame.image.load(mif).convert_alpha()<br \/>\nx,  y = 0,  0<br \/>\nliigutax,  liigutay = 0,  0<br \/>\nhiir = hiir1<br \/>\nwhile True :<br \/>\n&nbsp;&nbsp;&nbsp;     for syndmus in pygame.event.get() :<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;         if syndmus.type == QUIT:<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;             pygame.quit()<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;             sys.exit()<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;         if syndmus.type==KEYDOWN:<br \/>\n &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;            if syndmus.key==K_LEFT:<br \/>\n &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                liigutax=-1<br \/>\n &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;            elif syndmus.key==K_RIGHT:<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                 liigutax=+1<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;             elif syndmus.key==K_UP:<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                 liigutay=-1<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;             elif syndmus.key==K_DOWN:<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                 liigutay=+1<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;             elif syndmus.key==K_SPACE:<br \/>\n &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                hiir=hiir2<br \/>\n &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                ekraan.blit(hiir,  (x,  y))<br \/>\n &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;            elif syndmus.key==K_TAB:<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                 hiir=hiir1<br \/>\n &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                ekraan.blit(hiir,  (x,  y))<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;         if syndmus.type==KEYUP:<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;            if syndmus.key==K_LEFT:<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                 liigutax=0<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;             elif syndmus.key==K_RIGHT:<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                 liigutax=0<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;             elif syndmus.key==K_UP:<br \/>\n &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                liigutay=0<br \/>\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;             elif syndmus.key==K_DOWN:<br \/>\n &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                liigutay=0<br \/>\n&nbsp;&nbsp;&nbsp;     x+=liigutax<br \/>\n&nbsp;&nbsp;&nbsp;     y+=liigutay<br \/>\n&nbsp;&nbsp;&nbsp;     ekraan.blit(taust,  (0, 0))<br \/>\n&nbsp;&nbsp;&nbsp;     ekraan.blit(hiir,  (x,  y))<br \/>\n &nbsp;&nbsp;&nbsp;    pygame.display.update()<\/code><\/p>\n<p>Vajalikud <a href='http:\/\/python.pingviinitiivul.ee\/wp-content\/uploads\/2011\/05\/pildid.zip'>pildid<\/a> on siin.<\/p>\n<p><object width=\"640\" height=\"390\"><param name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/iRS10eHzAGQ&#038;hl=en_US&#038;feature=player_embedded&#038;version=3\"><\/param><param name=\"allowFullScreen\" value=\"true\"><\/param><param name=\"allowScriptAccess\" value=\"always\"><\/param><embed src=\"http:\/\/www.youtube.com\/v\/iRS10eHzAGQ&#038;hl=en_US&#038;feature=player_embedded&#038;version=3\" type=\"application\/x-shockwave-flash\" allowfullscreen=\"true\" allowScriptAccess=\"always\" width=\"640\" height=\"390\"><\/embed><\/object><\/p>\n<p>Ja selle keerukam j\u00e4tk:<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"349\" src=\"http:\/\/www.youtube.com\/embed\/615JTGsEH_c\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>L\u00f5peks meie oma kahe &#8220;asjaga&#8221; programm: punane pall, mida saab klaviatuurilt juhtida ja rakett, mis j\u00e4litab palli. J\u00e4litamisalgoritm on praegu &#8220;aeglustuv&#8221;, sihtm\u00e4rgi juurde j\u00f5udes on &#8220;rakett&#8221; v\u00e4ga aeglane.<\/p>\n<p><code><br \/>\n#!\/usr\/bin\/python<br \/>\n# -*- coding: utf-8 -*-<br \/>\nbif = \"bg.jpg\"<br \/>\nmif = \"ball.png\"<br \/>\ngif = \"ball2.png\"<br \/>\nrif = \"rakett.png\"<\/p>\n<p>import pygame, sys<br \/>\nfrom pygame import *<\/p>\n<p>pygame.init()<\/p>\n<p>ekraan=pygame.display.set_mode((800, 600), 0, 32)<br \/>\ntaust=pygame.image.load(bif).convert()<br \/>\nhiir1=pygame.image.load(mif).convert_alpha()<br \/>\nhiir2=pygame.image.load(gif).convert_alpha()<br \/>\nrakett=pygame.image.load(rif).convert_alpha()<\/p>\n<p>x, y = 0, 0<br \/>\nrx, ry = 700, 550<br \/>\nliigutax, liigutay = 0, 0<br \/>\npall = hiir1<\/p>\n<p>kell = pygame.time.Clock()<br \/>\nkiirus = 1<\/p>\n<p>while True :<br \/>\n&nbsp;&nbsp;&nbsp;       for syndmus in pygame.event.get() :<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;           if syndmus.type == QUIT:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;               pygame.quit()<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;               sys.exit()<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;           if syndmus.type==KEYDOWN:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;               if syndmus.key==K_LEFT:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   liigutax=-1<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;               elif syndmus.key==K_RIGHT:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   liigutax=+1<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;               elif syndmus.key==K_UP:<br \/>\n &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                  liigutay=-1<br \/>\n &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;              elif syndmus.key==K_DOWN:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   liigutay=+1<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;               elif syndmus.key==K_SPACE:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   hiir=hiir2<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   ekraan.blit(pall, (x, y))<br \/>\n &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;              elif syndmus.key==K_TAB:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   hiir=hiir1<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   ekraan.blit(pall, (x, y))<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;           if syndmus.type==KEYUP:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;               if syndmus.key==K_LEFT:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   liigutax=0<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;               elif syndmus.key==K_RIGHT:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   liigutax=0<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;               elif syndmus.key==K_UP:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   liigutay=0<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;               elif syndmus.key==K_DOWN:<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;                   liigutay=0<br \/>\n&nbsp;&nbsp;&nbsp;       x+=liigutax<br \/>\n&nbsp;&nbsp;&nbsp;       y+=liigutay<\/p>\n<p>&nbsp;&nbsp;&nbsp;       milli = kell.tick()<br \/>\n&nbsp;&nbsp;&nbsp;       sekundid = milli \/ 1000.<br \/>\n&nbsp;&nbsp;&nbsp;       dm =sekundid * kiirus<\/p>\n<p>&nbsp;&nbsp;&nbsp;       if rx<>x :<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   \trx-=((rx-x)\/kiirus*sekundid)<br \/>\n&nbsp;&nbsp;&nbsp;       if ry<>y :<br \/>\n&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   \try-=((ry-y)\/kiirus*sekundid)<br \/>\n&nbsp;&nbsp;&nbsp;       #rx+=dm<\/p>\n<p>&nbsp;&nbsp;&nbsp;       if x < 0 : x = 0\n&nbsp;&nbsp;&nbsp;       elif x > 799 : x=799<br \/>\n&nbsp;&nbsp;&nbsp;       if y < 0 : y=0\n&nbsp;&nbsp;&nbsp;       elif y > 599 : y=599<\/p>\n<p>&nbsp;&nbsp;&nbsp;       ekraan.blit(taust, (0, 0))<br \/>\n&nbsp;&nbsp;&nbsp;   ekraan.blit(pall, (x, y))<br \/>\n&nbsp;&nbsp;&nbsp;       ekraan.blit(rakett, (rx, ry))<br \/>\n&nbsp;&nbsp;&nbsp;       pygame.display.update()<\/code><\/p>\n<p>Rakett v\u00f5ib olla suvaline v\u00e4ike osalt l\u00e4bipaistev PNG (ka muu pilt, aga PNG l\u00e4bipaistvus v\u00f5imaldab ilusamat tulemust). N\u00e4iteks kiir korras tehtud rakett:<br \/>\n<a href=\"http:\/\/python.pingviinitiivul.ee\/wp-content\/uploads\/2011\/05\/rakett.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/python.pingviinitiivul.ee\/wp-content\/uploads\/2011\/05\/rakett.png\" alt=\"\" title=\"rakett\" width=\"40\" height=\"40\" class=\"alignnone size-full wp-image-345\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>V\u00f5tame n\u00e4idiseks \u00fche lihtsa PyGame n\u00e4ite, milles saab liigutada palli: #!\/usr\/bin\/python # -*- coding: utf-8 -*- bif = &#8220;bg.jpg&#8221; mif = &#8220;ball.png&#8221; import pygame from pygame import * pygame.init() ekraan=pygame.display.set_mode((800, 600), 0, 32) taust=pygame.image.load(bif).convert() hiir1=pygame.image.load(mif).convert_alpha() hiir2=pygame.image.load(mif).convert_alpha() x, y = 0, &hellip; <a href=\"https:\/\/python.pingviinitiivul.ee\/?p=335\">J\u00e4tka lugemist <span class=\"meta-nav\">&rarr;<\/span><\/a><\/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-335","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/posts\/335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=335"}],"version-history":[{"count":8,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/posts\/335\/revisions"}],"predecessor-version":[{"id":342,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/posts\/335\/revisions\/342"}],"wp:attachment":[{"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}