示例#1
0
 def start(self):
     """Mandatory method."""
     self.SPG.tellcore_set_dice_minimal_level(6)
     fs = 36
     self.scoreboard = ScoreBoard(self.rc_dic, size=fs)
     Img.winner = utils.load_image(os.path.join(self.my_datadir,'winner.jpg'),1)
     Img.loser = utils.load_image(os.path.join(self.my_datadir,'loser.jpg'),1)
     self.skipstart = None# used when the user sets a predefined game play in the config file
     self.skipsplash = None
     if self.rc_dic['sound'].lower() == 'no':
         Snd.pong = utils.load_sound(os.path.join(self.my_datadir,''))
         Snd.winner = utils.load_sound(os.path.join(self.my_datadir,''))
         Snd.goal = utils.load_sound(os.path.join(self.my_datadir,''))
         Snd.bump = utils.load_sound(os.path.join(self.my_datadir,''))
     else:
         Snd.pong = utils.load_sound(os.path.join(self.my_datadir,'pick.wav'))
         Snd.winner = utils.load_music(os.path.join(self.my_datadir,'winner.ogg'))
         Snd.goal = utils.load_sound(os.path.join(self.my_datadir,'goal.wav'))
         Snd.bump = utils.load_sound(os.path.join(self.my_datadir,'bump.wav'))
     #set kind of game play
     # we only check for multi and multipc, anything else is considerd single play
     # which is the default
     if self.rc_dic['gameplay'] == 'multi':
         self.restart([[None,'2']])
         self.skipstart = 1
     elif self.rc_dic['gameplay'] == 'multipc':
         self.restart([[None,'3']])
         self.skipstart = 1
示例#2
0
 def _made_hole(self, obj):
     # Keeps also track of the score
     # This replaces _level_1,_level_2 and _level_3
     if self.level > 1 and obj == 'blue':
         return  # we pot a red blue ball in the levels > 1
     obj.remove(Misc.group)  # remove the ball from the group
     obj.remove_sprite()
     utils.load_music(Snd.hurra).play()
     if (
             len(Misc.group) == (self.level > 1)
     ):  # true if there are no balls in level 1 or there's in levels 2 and 3
         s = int(self.pointstoadd / self.throws)
         ## Consider this a placeholder, it doesn't work as it should
         #self.cpg.scorething(s)# Update the score display
         self.maxpoints += self.pointstoadd
         self.points += s
         self.tries += 1
         txt, sz = utils.text2surf(str(self.points) + '  ' + _("points"),
                                   48, (8, 0, 120),
                                   bold=True)
         self.screen.blit(txt, (200, 200))
         pygame.display.update()
         pygame.time.wait(2000)
         # update the counter in the menubar
         Misc.execounter.increase_counter()
         if self.tries == self.n_balls:
             self.SPG.tellcore_level_end(
                 store_db=True
             )  #signal to childsplay that this level is ended. See return val of def loop
             if self.level == 3:
                 self.stop = 1
                 Misc.score = self.points
                 self.screen.blit(self.backgr, (0, 0))
                 MovingSign(_("You won!!"), 80, (100, 100), (100, 300), 1,
                            (8, 0, 120), self.screen, self.backgr, 0)
                 txt, sz = utils.text2surf(str(self.points) + '  ' +
                                           _("points"),
                                           48, (8, 0, 120),
                                           bold=True)
                 self.screen.blit(txt, (200, 200))
                 pygame.display.update()
                 for i in range(0, 3):
                     utils.load_music(Snd.hurra).play()
                     pygame.time.wait(1000)
         else:
             self.next_exercise()
示例#3
0
 def start(self):
     """Mandatory method."""
     # Your top blit position, this depends on the menubar position 
     self.tile = 'tileset_1'
     if self.blit_pos[1] == 0:
         self.blit_pos_y = 10
     else:
         self.blit_pos_y = 110
     self.SPG.tellcore_set_dice_minimal_level(2)
     p = os.path.join(self.CPdatadir,'good_%s.png' % self.lang)
     if not os.path.exists(p):
         p = os.path.join(self.CPdatadir,'thumbs.png')
     self.ThumbsUp = SPSpriteUtils.MySprite(utils.load_image(p))
     self.good = utils.load_music(os.path.join(self.CPdatadir, 'good1.ogg'))
     self.wrong = utils.load_music(os.path.join(self.CPdatadir, 'wrong1.ogg'))
     self.score = 0
     self.AreWeDT = False
     self.pre_level_flag = False
示例#4
0
    def __init__(self, app, force_music=False):
        logging.info('Initializing menu')

        self.app = app

        logging.info('Loading fonts')

        self.title_font = utils.load_font('monofur.ttf', 62)
        self.normal_font = utils.load_font('monofur.ttf', 18)
        self.small_font = utils.load_font('monofur.ttf', 15)

        self.musics_volume = self.app.config.getfloat('connectfour',
                                                      'music_volume')

        if not pygame.mixer.music.get_busy() or force_music:
            utils.load_music('menu.wav', volume=self.musics_volume)

        self.load_gui()
示例#5
0
 def start(self):
     """Mandatory method."""
     # Your top blit position, this depends on the menubar position
     self.tile = 'tileset_1'
     if self.blit_pos[1] == 0:
         self.blit_pos_y = 10
     else:
         self.blit_pos_y = 110
     self.SPG.tellcore_set_dice_minimal_level(2)
     p = os.path.join(self.CPdatadir, 'good_%s.png' % self.lang)
     if not os.path.exists(p):
         p = os.path.join(self.CPdatadir, 'thumbs.png')
     self.ThumbsUp = SPSpriteUtils.MySprite(utils.load_image(p))
     self.good = utils.load_music(os.path.join(self.CPdatadir, 'good1.ogg'))
     self.wrong = utils.load_music(
         os.path.join(self.CPdatadir, 'wrong1.ogg'))
     self.score = 0
     self.AreWeDT = False
     self.pre_level_flag = False
示例#6
0
    def __init__(self,SPGoodies):
        """SPGoodies is a class object that SP sets up and will contain references
        to objects, callback methods and observers
        TODO: add more explaination"""
        self.logger =  logging.getLogger("childsplay.synonyms.Activity")
        self.logger.info("Activity started")
        self.SPG = SPGoodies
        self.scoredisplay = self.SPG.get_scoredisplay()
        self.theme = self.SPG.get_theme()
        self.screen = self.SPG.get_screen()
        self.screenclip = self.SPG.get_screenclip()
        self.blit_pos = self.screenclip.left, self.screenclip.top
        self.orgscreen = pygame.Surface(self.screenclip.size) # we use this to restore the screen
        self.orgscreen.blit(self.screen, (0, 0), self.screenclip)
        self.backgr = self.SPG.get_background()
        self.language = self.SPG.get_localesetting()[0][:2]
        
        self.CPdatadir = os.path.join(self.SPG.get_libdir_path(),'CPData')
        # Location of the alphabet sounds dir
        self.absdir = self.SPG.get_absdir_path()# alphabet sounds dir

        self.setup()

        self.logger.debug("rchash: %s" % self.rchash)
        # You MUST call SPInit BEFORE using any of the SpriteUtils stuff
        # it returns a reference to the special CPGroup
        self.actives = SPSpriteUtils.SPInit(self.screen,self.backgr)
        
        self.background = utils.load_image(os.path.join(self.my_datadir, self.theme, 'background.png'))
        self.good_sound = utils.load_music(os.path.join(self.CPdatadir,'good.ogg'))
        self.wrong_sound = utils.load_music(os.path.join(self.CPdatadir,'wrong.ogg'))
        
        i = utils.load_image(os.path.join(self.my_datadir, self.theme, 'begin.png'))
        i_ro = utils.load_image(os.path.join(self.my_datadir, self.theme, 'begin_ro.png'))
        self.beginbut = SimpleTransImgButton(i, i_ro, (634, 530))
        
        i = utils.load_image(os.path.join(self.my_datadir, self.theme, 'newquestion.png'))
        i_ro = utils.load_image(os.path.join(self.my_datadir, self.theme, 'newquestion_ro.png'))
        self.newquestionbut = TransImgButton(i, i_ro, (560, 500))
        self.newquestionbut.connect_callback(self._on_newquestionbut_clicked, MOUSEBUTTONDOWN)
示例#7
0
 def _made_hole(self,obj):
     # Keeps also track of the score
     # This replaces _level_1,_level_2 and _level_3
     if self.level > 1 and obj == 'blue':
         return# we pot a red blue ball in the levels > 1
     obj.remove(Misc.group)# remove the ball from the group
     obj.remove_sprite()
     utils.load_music(Snd.hurra).play()
     if (len(Misc.group) == (self.level > 1)): # true if there are no balls in level 1 or there's in levels 2 and 3
         s = int(self.pointstoadd / self.throws)
         ## Consider this a placeholder, it doesn't work as it should
         #self.cpg.scorething(s)# Update the score display
         self.maxpoints += self.pointstoadd
         self.points += s
         self.tries += 1
         txt,sz = utils.text2surf(str(self.points)+'  '+_("points"), 48, (8, 0, 120), bold=True)
         self.screen.blit(txt, (200,200))
         pygame.display.update()
         pygame.time.wait(2000)
         # update the counter in the menubar
         Misc.execounter.increase_counter()
         if self.tries == self.n_balls:
             self.SPG.tellcore_level_end(store_db=True)#signal to childsplay that this level is ended. See return val of def loop
             if self.level == 3:
                 self.stop = 1
                 Misc.score = self.points
                 self.screen.blit(self.backgr, (0,0))
                 MovingSign(_("You won!!"), 80, (100,100), (100,300), 1, (8,0,120), self.screen, self.backgr, 0)
                 txt,sz = utils.text2surf(str(self.points)+'  '+_("points"), 48, (8, 0, 120), bold=True)
                 self.screen.blit(txt, (200,200))
                 pygame.display.update()
                 for i in range(0,3):
                     utils.load_music(Snd.hurra).play()
                     pygame.time.wait(1000)
         else:
             self.next_exercise()
示例#8
0
 def play(self):
     utils.load_music(self.sound).play(1)
示例#9
0
 def start(self):
     """Mandatory method."""
 
     img = utils.load_image(os.path.join(self.my_datadir,'4row_red.png'))
     self.spacesize = PILSIZE
     self.RedImg = pygame.transform.smoothscale(img, (self.spacesize, self.spacesize))
     
     img = utils.load_image(os.path.join(self.my_datadir,'4row_black.png'))
     self.BlackImg = pygame.transform.smoothscale(img, (self.spacesize, self.spacesize))
     
     img = utils.load_image(os.path.join(self.my_datadir,'4row_board.png'))
     img = pygame.transform.smoothscale(img, (self.spacesize, self.spacesize))
     self.boardImg = img
     
     self.gameClock = pygame.time.Clock()# tobe removed
     self.draggingToken = False
     self.tokenx, self.tokeny = None, None
     
     row = self.SPG.get_current_user_dbrow()
     user_id = self.SPG.get_current_user_id()
     UserImg = None
     offset = 0
     if user_id > 1:# demo is 1
         p = os.path.join(HOMEDIR, 'braintrainer', 'faces', 'big', '%s.png' % user_id)
         if os.path.exists(p):
             UserImg = utils.aspect_scale(utils.load_image(p), (125,125))
             offset = 12
     if not UserImg:
         st = utils.char2surf(row.first_name, 20, fcol=BLACK)
         sn =  utils.char2surf(row.last_name, 20, fcol=BLACK)
         surf = pygame.Surface((150,80), SRCALPHA, 32)
         surf.blit(st,(8,4))
         surf.blit(sn, (8,30))  
         UserImg = surf
     self.UserImg = SPSpriteUtils.SPSprite(UserImg)
     surf = UserImg.copy()
     pygame.draw.rect(surf, GREEN, UserImg.get_rect(), 10)
     self.TurnImgUser = SPSpriteUtils.SPSprite(surf)
     
     AIimg = utils.load_image(os.path.join(self.my_datadir,'computer.png'))
     self.AIimg = SPSpriteUtils.SPSprite(AIimg)
     surf = AIimg.copy()
     pygame.draw.rect(surf, GREEN, AIimg.get_rect(), 10)
     self.TurnAIimg = SPSpriteUtils.SPSprite(surf)
     
     self.WinnerImg = utils.load_image(os.path.join(self.my_datadir,'winner.png'))
     
     self.numbershash = {}
     for i in range(1, BOARDWIDTH+1):
         self.numbershash[i] = utils.load_image(os.path.join(self.my_datadir,'%s.png' % i))
     
     # sounds
     
     self.winSnd = utils.load_music(os.path.join(self.my_datadir,'won.ogg'))
     self.lossSnd = utils.load_music(os.path.join(self.my_datadir,'loss.ogg'))             
            
     # various constants
     self.FPS = 30 # frames per second to update the screen
     WINDOWWIDTH = 800 # width of the program's window, in pixels
     WINDOWHEIGHT = 600 # height in pixels
     
     self.XMARGIN = int((WINDOWWIDTH - BOARDWIDTH * self.spacesize) / 2) # approx. number of pixels on the left or right side of the board to the edge of the window
     self.YMARGIN = int((WINDOWHEIGHT - BOARDHEIGHT * self.spacesize) / 2 + 80) # approx. number of pixels above or below board
     
     self.REDpos = (self.XMARGIN - self.spacesize * 2, self.YMARGIN + (BOARDHEIGHT - 1) * self.spacesize)
     self.BLACKpos = (self.XMARGIN + BOARDWIDTH * self.spacesize + self.spacesize, self.YMARGIN + (BOARDHEIGHT - 1) * self.spacesize)
     self.UserImgpos = (2 + offset, 380)
     self.UserImg.moveto(self.UserImgpos)
     self.TurnImgUser.moveto(self.UserImgpos)
     self.AIimgpos = (660, 380)
     self.AIimg.moveto(self.AIimgpos)
     self.TurnAIimg.moveto(self.AIimgpos)
     self.winner = 'tie'
     self.difficulty = 1# never more then 2, system will freeze
     self.AreWeDT = False
示例#10
0
    def __init__(self, SPGoodies):
        """SPGoodies is a class object that SP sets up and will contain references
        to objects, callback methods and observers
        TODO: add more explaination"""
        self.logger = logging.getLogger("childsplay.ichanger.Activity")
        self.logger.info("Activity started")
        self.SPG = SPGoodies
        self.lang = self.SPG.get_localesetting()[0][:2]
        self.scoredisplay = self.SPG.get_scoredisplay()
        self.displayedscore = 0
        self.theme = self.SPG.get_theme()
        self.screen = self.SPG.get_screen()
        self.screenclip = self.SPG.get_screenclip()
        self.blit_pos = self.screenclip.left, self.screenclip.top
        self.orgscreen = pygame.Surface(
            self.screenclip.size)  # we use this to restore the screen
        self.orgscreen.blit(self.screen, (0, 0), self.screenclip)
        self.backgr = self.SPG.get_background()
        # The location of the activities Data dir
        self.my_datadir = os.path.join(self.SPG.get_libdir_path(), 'CPData',
                                       'IchangerData')
        self.rchash = utils.read_rcfile(
            os.path.join(self.my_datadir, 'ichanger.rc'))
        self.rchash['theme'] = self.theme
        self.my_rchash = self.rchash[self.theme]
        self.logger.debug("found rc: %s" % self.rchash)
        # Location of the CPData dir which holds some stuff used by multiple activities
        self.CPdatadir = os.path.join(self.SPG.get_libdir_path(), 'CPData')
        # Location of the alphabet sounds dir
        self.absdir = self.SPG.get_absdir_path()  # alphabet sounds dir
        # You MUST call SPInit BEFORE using any of the SpriteUtils stuff
        # it returns a reference to the special CPGroup
        self.actives = SPSpriteUtils.SPInit(self.screen, self.backgr)

        imgdir = os.path.join(self.my_datadir, 'images', self.theme)
        if not os.path.exists(imgdir):
            imgdir = os.path.join(self.my_datadir, 'images', 'childsplay')

        self.imagepaths_org = [f for f in glob.glob(os.path.join(imgdir, '*'))\
                            if os.path.basename(f) not in ('cardfront.png', 'cardback.png')]
        self.imagepaths = self.imagepaths_org[:]
        random.shuffle(self.imagepaths)
        self.opencard = utils.load_image(os.path.join(imgdir, 'cardfront.png'))
        self.closedcard = utils.load_image(os.path.join(
            imgdir, 'cardback.png'))

        boxsurf = utils.load_image(os.path.join(self.my_datadir, 'box.png'))
        self.pausesnd = utils.load_music(
            os.path.join(self.CPdatadir, 'pause_0_35.ogg'))
        self.good_sound = utils.load_music(
            os.path.join(self.CPdatadir, 'good.ogg'))
        self.wrong_sound = utils.load_music(
            os.path.join(self.CPdatadir, 'wrong.ogg'))
        p = os.path.join(self.CPdatadir, 'good_%s.png' % self.lang)
        if not os.path.exists(p):
            p = os.path.join(self.CPdatadir, 'thumbs.png')
        self.good_image = SPSpriteUtils.MySprite(utils.load_image(p))
        self.good_image.moveto((229, 296))
        # Your top blit position, this depends on the menubar position
        if self.blit_pos[1] == 0:
            y = 10
        else:
            y = 110
        self.cardpositions = [(10, y), (260, y), (10, y + 250), (260, y + 250)]
        #self.start_pos = (600, 380 + y)
        self.but_pos = [(560, 420 + y), (700, 400 + y)]
        boxpos = (510, y)
        self.box = TextBox(boxsurf, boxpos)
示例#11
0
    def loop(self,events):
        """Mandatory method.
        This is the main eventloop called by the core 30 times a minute."""
        if not self.buttonpressed:
            for event in events:
                if event.type is MOUSEBUTTONDOWN:
                    #if self.ball1 in Misc.actives.sprites():
                    if len(Misc.actives):
                        continue
                    if event.button >= 2:
                        self.logger.debug("button >=2 down")
                        if self.ball1.callback(event.pos, event.button):
                            # put stick in position to see the direction it will have
                            self.stick.prepare(event.pos, (self.ball1.posreal[0]+self.ball1.size[0]/2, self.ball1.posreal[1]+self.ball1.size[1]/2))
                            Misc.group.add(self.stick)
                            Misc.group.refresh()
                    else:
                        self.logger.debug("button 1 down")
                        if self.ball1.callback(event.pos, event.button):
                            # there will be a kick. Begin counting the time buttonmouse is pressed.
                            self.buttonpressed = 1
                            self.timepressed = 0
                            self.stick.prepare(event.pos, (self.ball1.posreal[0]+self.ball1.size[0]/2, self.ball1.posreal[1]+self.ball1.size[1]/2))
                            Misc.group.add(self.stick)
                            Misc.group.refresh()
                if event.type is KEYDOWN and (event.key == 113):
                    # My mind is going down...
                    #self.stop = 1
                    self.start(self.level,None)
                if event.type is MOUSEBUTTONUP:
                    Misc.group.remove(self.stick)
                    Misc.group.refresh()
        else:
            if len(events):
                for event in events:
                    if event.type is MOUSEBUTTONUP and event.button == 1:
                        # stick was released. It's time to roll.
                        self.stick.remove(Misc.group)
                        self.buttonpressed = 0
                        #Misc.group.refresh()
                        Misc.actives.add(self.ball1)
                        strength = self.timepressed / 2
                        self.ball1.direc = (self.ball1.direc[0] * strength, self.ball1.direc[1] * strength)
                        self.throws += 1
                        utils.load_music(Snd.throw).play()
            else:
                # strength is going up
                if self.timepressed < self.stick.maxstrength:
                    self.timepressed += 1
                    self.stick.grow(self.timepressed)
        if Misc.actives.sprites():
            #pygame.time.wait(10)
            self.movethings()
            # Call refresh with a event to let it call callback and update methods.
            # See the game fallingletters for a simple implementation of this in action.
            v = Misc.group.refresh(pygame.event.Event(USEREVENT))# The ball returns 1 when it goes into the hole 
            # the ball also removes it self from the grou. see the ball class

            # check the return val from the on_update method
            # for the format see the reference and the ball class
            if v:
                #print "return val from inside refresh:", v # just as info to see how the return val looks like :-)
                if v[0][1][1] == 1:
                    self._made_hole(v[0][1][0])
        return 
示例#12
0
 def play(self):
     utils.load_music(self.sound).play(1)
示例#13
0
 def next_level(self,level,dbmapper):
     """Mandatory method.
     Return True if there levels left.
     False when no more levels left."""
     # Your top blit position, this depends on the menubar position 
     if self.blit_pos[1] == 0:
         self.ty = 10
     else:
         self.ty = 110
     if level > 6: return False
     self.level = level
     # make sure we don't have a timer running
     self.stop_timer()
     # db_mapper is a Python class object that provides easy access to the 
     # dbase.
     self.db_mapper = dbmapper
     # make sure we don't have fish left in the actives group.
     self.actives.empty()
     self.WeAreAquarium = False
     self.aquarium_counter = 0
     #self.aquariumsound = False
     self.aquariumsound = utils.load_music(random.choice(self.aquarium_music_list))
     #detrmine which background pic we will use:
     backimage = os.path.join(self.my_datadir, 'backgrounds', \
                              self.theme,'%s.jpg' % level)
     if not os.path.exists(backimage):
         backimage = os.path.join(self.my_datadir, 'backgrounds', \
                              'childsplay','%s.jpg' % level)
     # remember that SPC sets a clip in relation to the theme used
     self.coral_surf = utils.load_image(backimage)
     self.screen.blit(self.coral_surf,(0,self.ty-10))
     pygame.display.update()
     self.backgr.blit(self.coral_surf,(0,self.ty-10))
     random.shuffle(self.imagelist)
     # get values for the fish objects
     data = self.level_data[level-1]
     startx = data[1]
     delay = data[2]# lower = faster
     step = data[3] # higher = faster
     self.timersleep = data[4] # seconds between fish start
     react = 0
     self.logger.debug("setup fish with: x=%s,delay=%s,step=%s,timer=%s" % \
                                             (startx,delay,step,self.timersleep))
     # setup the fish objects, in two steps
     fishobjects = []
     for item in self.imagelist[:data[0]]:
         # we use copies, this way we can reuse the image list.
         s1, s2 = item[0].convert_alpha(),item[1].convert_alpha()
         # position and position are set when the level is started
         fishobjects.append(Fish((s1,s2), self.score_observer, self))
     
     # setup the objects and put them in a seperate list
     # we don't destroy them so we can use them in any level.
     self.livefish = []
     for obj in fishobjects:
         y = random.randint(self.ty,410+self.ty)
         if startx == 0:
             x = random.choice((-90,890))
         else:
             x = startx
         if x > 0:
             # we move from right to left and we must mirror the original image
             obj.mirror_image()
         if level >= 3:# third level, we adjust some of the speeds
             d = data[2]
             delay = random.choice((d,d,d//2))
             s = data[3]
             step = random.choice((s,s,s*2))
         if level == 6:
             d = data[2]
             delay = d//3
             s = data[3]
             step = s*2
         obj.start(x,y,step,delay,react)
         self.livefish.append(obj)
     
     # we need total fish for score calculation.
     self.totalfish = len(self.livefish)
     # we store the number of fish this level will have.
     self.db_mapper.insert('fish',self.totalfish)
     
     self.aquariumsound.play(-1)
     return True
示例#14
0
    def loop(self, events):
        """Mandatory method.
        This is the main eventloop called by the core 30 times a minute."""
        if not self.buttonpressed:
            for event in events:
                if event.type is MOUSEBUTTONDOWN:
                    #if self.ball1 in Misc.actives.sprites():
                    if len(Misc.actives):
                        continue
                    if event.button >= 2:
                        self.logger.debug("button >=2 down")
                        if self.ball1.callback(event.pos, event.button):
                            # put stick in position to see the direction it will have
                            self.stick.prepare(event.pos,
                                               (self.ball1.posreal[0] +
                                                self.ball1.size[0] / 2,
                                                self.ball1.posreal[1] +
                                                self.ball1.size[1] / 2))
                            Misc.group.add(self.stick)
                            Misc.group.refresh()
                    else:
                        self.logger.debug("button 1 down")
                        if self.ball1.callback(event.pos, event.button):
                            # there will be a kick. Begin counting the time buttonmouse is pressed.
                            self.buttonpressed = 1
                            self.timepressed = 0
                            self.stick.prepare(event.pos,
                                               (self.ball1.posreal[0] +
                                                self.ball1.size[0] / 2,
                                                self.ball1.posreal[1] +
                                                self.ball1.size[1] / 2))
                            Misc.group.add(self.stick)
                            Misc.group.refresh()
                if event.type is KEYDOWN and (event.key == 113):
                    # My mind is going down...
                    #self.stop = 1
                    self.start(self.level, None)
                if event.type is MOUSEBUTTONUP:
                    Misc.group.remove(self.stick)
                    Misc.group.refresh()
        else:
            if len(events):
                for event in events:
                    if event.type is MOUSEBUTTONUP and event.button == 1:
                        # stick was released. It's time to roll.
                        self.stick.remove(Misc.group)
                        self.buttonpressed = 0
                        #Misc.group.refresh()
                        Misc.actives.add(self.ball1)
                        strength = self.timepressed / 2
                        self.ball1.direc = (self.ball1.direc[0] * strength,
                                            self.ball1.direc[1] * strength)
                        self.throws += 1
                        utils.load_music(Snd.throw).play()
            else:
                # strength is going up
                if self.timepressed < self.stick.maxstrength:
                    self.timepressed += 1
                    self.stick.grow(self.timepressed)
        if Misc.actives.sprites():
            #pygame.time.wait(10)
            self.movethings()
            # Call refresh with a event to let it call callback and update methods.
            # See the game fallingletters for a simple implementation of this in action.
            v = Misc.group.refresh(pygame.event.Event(
                USEREVENT))  # The ball returns 1 when it goes into the hole
            # the ball also removes it self from the grou. see the ball class

            # check the return val from the on_update method
            # for the format see the reference and the ball class
            if v:
                #print "return val from inside refresh:", v # just as info to see how the return val looks like :-)
                if v[0][1][1] == 1:
                    self._made_hole(v[0][1][0])
        return
示例#15
0
 def __init__(self,SPGoodies):
     """SPGoodies is a class object that SP sets up and will contain references
     to objects, callback methods and observers
     TODO: add more explaination"""
     self.logger =  logging.getLogger("childsplay.ichanger.Activity")
     self.logger.info("Activity started")
     self.SPG = SPGoodies
     self.lang = self.SPG.get_localesetting()[0][:2]
     self.scoredisplay = self.SPG.get_scoredisplay()
     self.displayedscore = 0
     self.theme = self.SPG.get_theme()
     self.screen = self.SPG.get_screen()
     self.screenclip = self.SPG.get_screenclip()
     self.blit_pos = self.screenclip.left, self.screenclip.top
     self.orgscreen = pygame.Surface(self.screenclip.size) # we use this to restore the screen
     self.orgscreen.blit(self.screen, (0, 0), self.screenclip)
     self.backgr = self.SPG.get_background()
     # The location of the activities Data dir
     self.my_datadir = os.path.join(self.SPG.get_libdir_path(),'CPData','IchangerData')
     self.rchash = utils.read_rcfile(os.path.join(self.my_datadir, 'ichanger.rc'))
     self.rchash['theme'] = self.theme
     self.my_rchash = self.rchash[self.theme]
     self.logger.debug("found rc: %s" % self.rchash)
     # Location of the CPData dir which holds some stuff used by multiple activities
     self.CPdatadir = os.path.join(self.SPG.get_libdir_path(),'CPData')
     # Location of the alphabet sounds dir
     self.absdir = self.SPG.get_absdir_path()# alphabet sounds dir
     # You MUST call SPInit BEFORE using any of the SpriteUtils stuff
     # it returns a reference to the special CPGroup
     self.actives = SPSpriteUtils.SPInit(self.screen,self.backgr)
     
     imgdir = os.path.join(self.my_datadir,'images', self.theme)
     if not os.path.exists(imgdir):
         imgdir = os.path.join(self.my_datadir, 'images','childsplay')
     
     self.imagepaths_org = [f for f in glob.glob(os.path.join(imgdir, '*'))\
                         if os.path.basename(f) not in ('cardfront.png', 'cardback.png')]
     self.imagepaths = self.imagepaths_org[:]
     random.shuffle(self.imagepaths)
     self.opencard = utils.load_image(os.path.join(imgdir,'cardfront.png'))
     self.closedcard = utils.load_image(os.path.join(imgdir,'cardback.png'))
     
     boxsurf = utils.load_image(os.path.join(self.my_datadir,'box.png'))
     self.pausesnd = utils.load_music(os.path.join(self.CPdatadir,'pause_0_35.ogg'))
     self.good_sound=utils.load_music(os.path.join(self.CPdatadir,'good.ogg'))
     self.wrong_sound=utils.load_music(os.path.join(self.CPdatadir,'wrong.ogg'))
     p = os.path.join(self.CPdatadir,'good_%s.png' % self.lang)
     if not os.path.exists(p):
         p = os.path.join(self.CPdatadir,'thumbs.png')
     self.good_image = SPSpriteUtils.MySprite(utils.load_image(p))
     self.good_image.moveto((229,296))
     # Your top blit position, this depends on the menubar position
     if self.blit_pos[1] == 0:
         y = 10
     else:
         y = 110
     self.cardpositions = [(10, y), (260, y), (10, y+250), (260, y+250)]
     #self.start_pos = (600, 380 + y)
     self.but_pos = [(560, 420 + y), (700, 400+y)]
     boxpos = (510, y)
     self.box = TextBox(boxsurf, boxpos)