;ò ;Bc@s6dZdZdadadddfZdkZdkZdkZdkZdk Tdk l Z l Z l Z lZlZlZlZlZdklZlZlZd klZdkZd fd „ƒYZd fd „ƒYZdfd„ƒYZhdd<dd<dd<dd<dd<dd<dd<dd<d d!<d"d#<d$d%<d&d'<d(d)<d*d+iii)iñiN(s*(s trace_errorsMyErrors load_images load_sounds load_musics char2surfs font2surfstxtfmt(sCPSpritesCPGroupsCPinit(sMenuItemsImgcBstZdZRS(s! Container to store image objects(s__name__s __module__s__doc__(((s ./lib/pong.pysImg+s sSndcBstZdZRS(s! Container to store sound objects(s__name__s __module__s__doc__(((s ./lib/pong.pysSnd.s sMisccBstZdZRS(s% Container to store all kind of stuff(s__name__s __module__s__doc__(((s ./lib/pong.pysMisc1s s__name__sdefaultssoundsyess computerAIseasysgameplayssinglesbatsizes72sbatspeeds12s ballspeeds3sgoalsizes300s winpointss11s useprofilesnones left_keyupsqs left_keydownsas right_keyupsps right_keydownslsButtoncBstZd„ZRS(NcCsti||||ƒdS(N(sMenuItems__init__sselfsimgspossdata(sselfsimgspossdata((s ./lib/pong.pys__init__Hs(s__name__s __module__s__init__(((s ./lib/pong.pysButtonGssWinnercBstZd„Zd„ZRS(NcCse|iƒ}|djoddf}n ddf}tiiƒti i t i i ||ƒƒdS(NsleftiÈi–iô(sselfs load_stuffsimgssidespossSndswinnersplayspygamesdisplaysupdatesImgsscreensblit(sselfssidesimgspos((s ./lib/pong.pys__init__Ls     cCs tiSdS(N(sImgswinner(sself((s ./lib/pong.pys load_stuffSs(s__name__s __module__s__init__s load_stuff(((s ./lib/pong.pysWinnerKs sLosercBstZd„Zd„ZRS(NcCsti||ƒdS(N(sWinners__init__sselfsside(sselfsside((s ./lib/pong.pys__init__WscCs tiSdS(N(sImgsloser(sself((s ./lib/pong.pys load_stuffYs(s__name__s __module__s__init__s load_stuff(((s ./lib/pong.pysLoserVs sPcPlayercBs tZdZd„Zd„ZRS(sjThe computer player. This will control the bat by adding pygame events to the pygame event queue. cCsùttiiƒttiiƒf\|_|_tiid|_tii |_ hd|i<|_ t |_ dfttidƒddf|_dti_tiddjodddf|_n(tiddjoddf|_nd S( sbat must be a Bat class object.iskeyis ballspeedis computerAIshards impossibleN(sordsMiscsbat_lsupsdownsselfsrects batstartysballsxoffsets balldirections event_dictsKEYUPskeystatesintsrc_dicsAIlists init_speed(sself((s ./lib/pong.pys__init__`s0 ( cCs)|itjo3t|_|itii|i|i ƒƒ|Sn?t i i djot i id|ijo|Sn t|_ti|iƒo|Snt i id}t i iiddƒd}||jo|i|i dtZddfd„Zd„Zd„Zd„Zd„ZRS(Nii,cCsvyttidƒ}Wnttfj onXd|f}ti|ƒi ƒ|_ d|_ |i i ƒ|_dS(Nsgoalsizeii(sintsMiscsrc_dicsss TypeErrorsKeyErrorssizespygamesSurfacesconvertsselfsimagesscoresget_rectsrect(sselfssizess((s ./lib/pong.pys__init__·s  cCs ||_dS(N(ssidesself(sselfsside((s ./lib/pong.pysset_scoreboardÁscCs|ii|ƒdS(N(sselfsrectsmove_ipspos(sselfspos((s ./lib/pong.pysmoveÃscCs6tiiƒ|id7_tiid|iƒdS(Ni( sSndsgoalsplaysselfsscoresMiscs scoreboards set_scoresside(sself((s ./lib/pong.pysscoredÅs cCs |iSdS(N(sselfsscore(sself((s ./lib/pong.pys get_scoreÉs(s__name__s __module__s__init__sset_scoreboardsmovesscoreds get_score(((s ./lib/pong.pysGoal¶s    sBallcBs&tZdd„Zd„Zd„ZRS(NicCs1ti|ƒyttidƒ}Wnttfj onX|}t i ddfƒi ƒ|_ t ii|i tddfddƒ|i i|i iddfƒtƒ|i iƒ|_ddf\|_|_|ii|i|iƒti| |fƒ|_ti| |fƒ|_|iƒdS(Ns ballspeedii ii†iú(sCPSprites__init__sselfsintsMiscsrc_dicsss TypeErrorsKeyErrorsspeedspygamesSurfacesconvertsimagesdrawscirclesGREENs set_colorkeysget_atsRLEACCELsget_rectsrectsxpossypossmove_ipsrandomschoicesxoffsetsyoffsetsmove(sselfsspeedss((s ./lib/pong.pys__init__Ís&  %cCs |id |_|iidjotiiƒ|i |_n|iidjo#tiiƒt|iƒ|_n|ii djotiiƒ|i |_ n|ii djo#tiiƒt|i ƒ|_ n|ii|i7_|ii |i 7_ dS(Niiüi%iÐi$( sselfsrectsoldrectscenterxsSndsbumpsplaysxoffsetsabsscenterysyoffset(sself((s ./lib/pong.pysmoveâs    cGs©|iƒxBtitifD].}|ii|iƒo|iƒdSqqW|iiti iƒp|iiti iƒ}|o|i |_ t iiƒndS(Niÿÿÿÿ(sselfsmovesMiscsgoal_lsgoal_rsobjsrects colliderectsscoredsbat_rsbat_lscollidesxoffsetsSndspongsplay(sselfsargssobjscollide((s ./lib/pong.pysupdateós   1 (s__name__s __module__s__init__smovesupdate(((s ./lib/pong.pysBallÌs  sBatcBs)tZddd„Zd„Zd„ZRS(Ni@i cCsti|ƒt|_y*ttidƒ}ttidƒ}Wnt t fj onX|}|}||_d|_ ||_ ddf\|_|_|diƒ|diƒf\|_|_tid|fƒ|_|iitƒ|iiƒ|_dS(Nsbatspeedsbatsizeiiiâii(sCPSprites__init__sselfsNones current_keysintsMiscsrc_dicsssbss TypeErrorsKeyErrorssizesspeeds init_speedstopsbottoms action_keyssuppersupsdownspygamesSurfacesimagesfillsGREENsget_rectsrect(sselfs action_keysssizesspeedsssbs((s ./lib/pong.pys__init__s"     ,cCs|ii|d|dƒdS(Nii(sselfsrectsmove_ipspos(sselfspos((s ./lib/pong.pys set_positionscGsÂxptiD]e}to tG|GHn|itjo•y|iiƒ}Wnt j oqoX||i jo|i |_|i |_n3||ijo"|i |_t|iƒ|_n||_q y|iiƒ}Wnctj oW}toti|IJn|i}||i jp ||ijo d|_qoq X||i jp ||ijo d|_q q W|iid|iƒ}|i|ijo|i|ijo ||_ndS(s/This keeps moving until a keyup event is raisediN(sMiscseventssevents_PDEBUGs__name__stypesKEYDOWNsunicodesupperscs ValueErrorsselfsups init_speedsspeedsdownsabss current_keys Exceptionsinfossyssstderrsrectsmovesnewrectstopsbottom(sselfsargssinfoscsnewrectsevent((s ./lib/pong.pysupdates<        &(s__name__s __module__s__init__s set_positionsupdate(((s ./lib/pong.pysBatÿs sGamecBsqtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z RS( sS Pong - part of childsplay.py, a suite of educational games for young children. c CsJ|t_|t_yYtiƒ}|iƒd}||d}|djo|i ||ƒn|t _Wn3t j o'} dG| GHtƒdGHtt _nXtodGt iGHn||_||_tii|idƒ|_dd fdd fdd fftg|_d d dfg|_ttitiƒt _|iƒdS(Nis useprofilesnonesError in config file parsing sUsing hardcoded defaultss config dictsPongDatai‚iFiÜirs single.jpgsmulti_person.jpgs multi_pc.jpg(sscreensImgsbackgrs defaults_dictscopysdsrc_dicskeyssnsprofilesupdatesMiscs Exceptionsinfos trace_errors_PDEBUGsbasepathsselfsbasedirslibdirsosspathsjoinsdatadirsNones gamelevelss gameitemssCPinitsactivess_setup( sselfsscreensbackgrsrc_dicsbasepathslibdirsprofilesdsnsinfo((s ./lib/pong.pys__init__<s.        *cCs$tiidddfƒtiiƒtƒt_t t i i |idƒdƒt_t t i i |idƒdƒt_t|_t|_tidiƒdjoˆtt i i |idƒƒt_tt i i |idƒƒt_tt i i |idƒƒt_tt i i |idƒƒt_n…tt i i |idƒƒt_tt i i |id ƒƒt_tt i i |id ƒƒt_tt i i |id ƒƒt_tid d jo#|itdggƒd|_n8tid djo#|itdggƒd|_ndS(s Set all the stuff we needis winner.jpgis loser.jpgssoundsnosspick.wavs winner.oggsgoal.wavsbump.wavsgameplaysmultis2smultipcs3N(sImgsscreensfillspygamesdisplaysupdates ScoreBoardsMiscs scoreboards load_imagesosspathsjoinsselfsdatadirswinnerslosersNones skipstarts skipssplashsrc_dicslowers load_soundsSndspongsgoalsbumps load_musicsrestart(sself((s ./lib/pong.pys_setupXs.  $$  !!!%!!!! cCsdSdS(sxMust return the original, not translated, title of this game. It's needed by the high score class of childsplay.sPongN((sself((s ./lib/pong.pys__str__uscCs|o|i o|i||ƒdSntodGtGtGHn|i o|i ƒn|i ƒt i i ƒtƒt _t iidƒt iiddfƒtƒt _t iidƒtot iiddfƒnt iiddfƒtiit iit iiƒtiit iit iiƒtii ƒd d f\}}yt id }t id }Wn+tt fj od d f\}}nXt!d||fd|ƒt _"t i"i#ddfƒyt id}t id}Wn+tt fj oddf\}}nXt!d||fd|ƒt _$tot i$i#ddfƒnt i$i#ddfƒt%ƒt _&t i'i(t i&ƒtot ot)ƒ|_*nt i'i(t i"t i$gƒt i'i+tiƒ}tii |ƒti-i.dƒdS(s.Try to hit the ball back and defend your goal.NsONEPLAYER,PCPLAYERsleftiidsrightiìÿÿÿiis right_keyups right_keydownspsls action_keyssspeediiÜs left_keyups left_keydownsqsaiiÐ(/slevelsselfs skipstarts _get_choicesitemss_PDEBUGs ONEPLAYERsPCPLAYERs skipssplashs_splash_controlss _draw_fieldsMiscs scoreboardsupdatesGoalsgoal_rsset_scoreboardsmovesgoal_lsImgsscreensblitsimagesrectspygamesdisplayslspeedsrspeedsrc_dicsusds TypeErrorsKeyErrorsBatsbat_rs set_positionsbat_lsBallsballsactivessaddsPcPlayersPCplayersdrawsrstimeswait(sselfslevelsitemssrspeedslspeedsdsusr((s ./lib/pong.pysstartzs\         cCsÌtiidddfƒtiidddfƒtiddddƒiddƒ}tii tit |dƒtii tit ddfddfdƒtii tit ddfddfdƒdS( Nii iôiàÿÿÿiiŽiiä( sImgsscreensfillsbackgrspygamesRectsinflatesboxsdrawsrectsGREENsline(sselfsbox((s ./lib/pong.pys _draw_field±s"$    c Csdtiidddfƒtdƒ}t|gdƒ}t|ddtƒ\} }t|ddtƒ\}}tii | ddfƒtii |ddfƒt iiƒg}d}t id d fƒ}|i ttii|id ƒƒd dfƒ|i ttii|id ƒƒd dfƒ|iƒ}|i ttidiƒ|tƒddfƒ|i ttidiƒ|tƒddfƒ|i ttidiƒ|tƒddfƒ|i ttidiƒ|tƒddfƒ|i tii |ddfƒƒ|i tii |ddfƒƒt ii|ƒt i!i"dƒd|_#dS(Nis3Use these keys on your keyboard to control the bat.i i0iixiÈiði<i,s arrow_up.pngisarrow_down.pngs left_keyupiiFs left_keydowni¾s right_keyups right_keydowni(idi¼i ($sImgsscreensfills_stxtstxtfmtstxtlists font2surfsGREENss1sspamss2sblitspygamesdisplaysupdatesrectssfsizesSurfacessurfs load_imagesosspathsjoinsselfsdatadirsconvertssurf_rs char2surfsMiscsrc_dicsuppersappendstimeswaits skipssplash( sselfssurfss2stxtlistsfsizessurf_rsspamsrectsstxtss1((s ./lib/pong.pys_splash_controlsÄs.  .. ////""c Cs¹tdƒ}t|dtƒ}tiiti i |ddfƒƒxot t ||dddfƒD]O\}}}tii|i|ƒ}tt|ƒ||ƒ}tii|ƒqbWdS( séDisplay the three chooses of game play. This will put the menu items in the actives group which then will be updated in the game loop. When the users picks one the result will be handled by the restart method.s Please, choose the game to play:i6iPi s1s2s3N(s_sheads char2surfsGREENssspygamesdisplaysupdatesImgsscreensblitsmapsNones positionssimagesspossimgsdatasosspathsjoinsselfsdatadirsButtons load_imagesobjsMiscsactivessadd( sselfs positionssimagessheadsimgspossssobjsdata((s ./lib/pong.pys _get_choiceßs %cCs²to dG|GHn|dd|ddf\}}|djo!tiiƒ|it t ƒnK|djo da n|djoda da ntiiƒd|_ dS(sˆUsed to restart the game when there's a goal. This is also used to set the global vars when ending the first level(menu choices)s restart v = iiiÿÿÿÿs2s3N( s_PDEBUGsvsobjsvalsMiscsactivessemptysselfsstartsNones ONEPLAYERsPCPLAYERsstop(sselfsvsobjsval((s ./lib/pong.pysrestartìs "       cCstdƒSdS(NsPong(s_(sself((s ./lib/pong.pys helptitleÿsc Csntdƒtdƒtdƒtdƒtdƒtdƒtdƒdtd ƒtd ƒdtd ƒg }|SdS( NsThe aim of the game:s>The classic pong game where you must hit a ball with your bat.s&There are three levels to choose from:s,Single play - Hit the ball against the wall.s?Multi player against the computer - Try to defeat the computer.s+Multi player - Play against another player.s9In the multiplayer modes, the one who has 11 points wins.s snThe game has a configuration file called 'pongrc', located in the .childsplay directory of your homedirectory.sEIn this file you can set a number of options to change the game play.sDifficulty : 5-8 years(s_stext(sselfstext((s ./lib/pong.pyshelpsf cCsþtddf\}|_t_to|ii|ƒ}nt djo|o dG|GHngt_ xX|D]P}|i t jp|i tjp |i tjo|}ti i|ƒqlqlWtii|ƒ}|o|i|ƒn|itifSdS(Niisevents(sNonesitemsselfsstopsMiscsscoresPCPLAYERsPCplayersplayseventss_PDEBUGseventstypesKEYDOWNsKEYUPsMOUSEBUTTONDOWNsappendsactivessrefreshsvsrestart(sselfseventsseventsitemsv((s ./lib/pong.pysloops  0(s__name__s __module__s__doc__s__init__s_setups__str__sstarts _draw_fields_splash_controlss _get_choicesrestarts helptitleshelpsloop(((s ./lib/pong.pysGame9s     7     ('sRCFILEs_PDEBUGs ONEPLAYERsPCPLAYERsGREENsosssyssrandomspygamespygame.constantssutilss trace_errorsMyErrors load_images load_sounds load_musics char2surfs font2surfstxtfmts SpriteUtilssCPSpritesCPGroupsCPinitsCPMenusMenuItemsTimersImgsSndsMiscs defaults_dictsButtonsWinnersLosersPcPlayers ScoreBoardsGoalsBallsBatsGame(!sGoalsImgstxtfmts defaults_dictsrandomsGREENs load_musics load_imagesCPGroupsSndsBallsGamesCPSprites font2surfsPcPlayerspygames char2surfs load_soundsBatsMyErrorsButtons ScoreBoardsTimerssyss_PDEBUGsRCFILEsCPinitsWinnersMiscs trace_errorsMenuItemsLosersos((s ./lib/pong.pys?s0 7  „ *03: