Beispiel #1
0
 def draw(self):
     self.draw_legend()
     utils.display_number(self.count, (g.sx(16), g.sy(8)), g.font2)
     img = self.scales[self.state]
     utils.centre_blit(g.screen, img, self.c)
     g.screen.blit(self.light_img, self.light_xy)
     g.screen.blit(self.heavy_img, self.heavy_xy)
     for ball in self.z:
         if ball.active:
             if ball != self.carry:
                 img = self.ball_img(ball)
                 utils.centre_blit(g.screen, img, ball.c)
     if self.carry != None:
         ball = self.carry
         img = self.ball_img(ball)
         x, y = g.pos
         x -= self.mdx
         y -= self.mdy
         utils.centre_blit(g.screen, self.shadow,
                           (x + g.sy(.35), y + g.sy(1.1)))
         utils.centre_blit(g.screen, img, (x, y))
         if utils.mouse_on_img(self.light_img, self.light_xy):
             self.drop_ball('light')
         if utils.mouse_on_img(self.heavy_img, self.heavy_xy):
             self.drop_ball('heavy')
     if self.result != None:
         utils.centre_blit(g.screen, self.result[0], self.result[1])
 def click(self):
     if g.state == 1:
         if self.castle.current_room.name == 'map':
             if utils.mouse_in_rect(g.map2_rect):
                 g.state = 4
                 return True
         if utils.mouse_on_img(g.bag_img, (g.bag_x, g.bag_y)):
             g.state = 2
             return True
         if g.wishes > 0:
             x = g.wish_x
             y = g.wish_y
             if utils.mouse_on_img(g.wish_current_img, (x, y)):
                 g.state = 3
                 return True
     elif g.state == 2:  # inside bag
         for ind in range(5, -1, -1):  # reverse order to display
             obj = g.bag[ind]
             if obj <> None:
                 (cx, cy) = g.inside_bag_cxy[ind]
                 x = cx - obj.img0.get_width() / 2
                 y = cy - obj.img0.get_height() / 2
                 if utils.mouse_on_img(obj.img0, (x, y)):
                     if self.castle.drop(obj):
                         g.bag[ind] = None
                         return True
                     return False
         g.state = 1
         return True
     elif g.state == 3:  # wishes
         self.castle.wish_click()
     elif g.state == 4:  # map
         g.state = 1
         return True
Beispiel #3
0
 def click(self):  # deal with click
     mx, my = pygame.mouse.get_pos()
     if self.carrying <> None:  # dropping piece
         piece = self.carrying
         self.carrying = None
         piece.c = (mx + self.dx, my + self.dy)
         if self.check(piece):  # check if in place
             self.glowing = piece
             self.ms = pygame.time.get_ticks()
         else:  # check not out of sight
             cx, cy = piece.c
             h2 = self.images[piece.img_n].get_height() / 2
             ylim = g.sy(21.55)
             if (cy - h2) > ylim: piece.c = (cx, ylim + h2 - g.sy(.4))
         return True
     else:
         for ind in range(len(self.pieces) - 1, 0, -1):
             piece = self.pieces[ind]
             if not piece.done:
                 img = self.images[piece.img_n]
                 if utils.mouse_on_img(img, piece.c):
                     self.top(ind)
                     self.dx = piece.c[0] - mx
                     self.dy = piece.c[1] - my
                     self.carrying = piece
                     return True
         return False
Beispiel #4
0
 def display(self):
     g.screen.fill(utils.WHITE)
     if g.toc_showing:
         g.screen.blit(self.toc.surf, (g.offset, 0))
         buttons.draw()
         return
     g.screen.blit(self.layout.surf, (g.offset, 0))
     if g.jig:
         self.jig.draw()
     if g.mouse_locn:
         x, y = pygame.mouse.get_pos()
         m = '(' + str(x) + ',' + str(y) + ')'
         cxy = (g.sx(29), g.sy(1.2))
         utils.message(g.screen, g.font1, m, cxy, 5)
     if g.colors:
         g.screen.blit(g.colors_img, g.colors_xy)
         if utils.mouse_on_img(g.colors_img, g.colors_xy):
             c = g.screen.get_at(pygame.mouse.get_pos())
             r, g1, b = '0', '0', '0'
             if c[0] > 200: r = '255'
             if c[1] > 200: g1 = '255'
             if c[2] > 200: b = '255'
             m = '(' + r + ',' + g1 + ',' + b + ')'
             cxy = (g.sx(5.3), g.sy(19.5))
             utils.message(g.screen, g.font1, m, cxy, 5)
     if self.layout.movie != None: self.layout.movie.draw()
     buttons.on(['fd', 'back'])
     if g.page == 1: buttons.off('back')
     elif g.page == g.last_page: buttons.off('fd')
     buttons.draw()
     if g.rect_on:
         pygame.draw.rect(g.screen, utils.GREEN, g.rect)
     if self.popup != None:
         surf, x, y = self.popup
         g.screen.blit(surf, (x, y))
Beispiel #5
0
def which_tn():
    n = g.solved + 1
    if n == 11: n = 10
    for ind in range(n):
        tn = tns[ind]
        if utils.mouse_on_img(tn.img, tn.xy): return ind  # puzzle number
    return -1
Beispiel #6
0
 def click(self):
     cxy = (self.frame_cx, self.frame_cy)
     if utils.mouse_on_img1(self.frame, cxy):
         if self.carry:
             self.carry = False
             return True
         else:
             mx, my = g.pos
             self.dx = self.frame_cx - mx
             self.dy = self.frame_cy - my
             self.carry = True
             return True
     for ind in range(self.find_n - 1, -1, -1):
         lf = lookFor[ind]
         if not lf.found:
             if utils.mouse_on_img(lf.img, lf.xy):
                 if ind == self.find_ind[self.current_ind]:
                     lf.found = True
                     self.found += 1
                     if not self.next1():
                         self.complete = True
                         g.count += 1
                     return True
                 else:
                     return False
     return False
Beispiel #7
0
def which_piece():
    for ind in range(1, 10):  # piece 0 is fixed
        ind1 = 10 - ind
        pce = pieces[z[ind1]]
        if utils.mouse_on_img(pce.img, pce.xy):
            i = z[ind1]
            z.remove(i)
            z.append(i)  # move to top
            return pce
    return None
Beispiel #8
0
 def check_panell(self):
     x, y = g.panel_xy
     img = g.panel_imgl[0]
     for ind in range(6):
         if utils.mouse_on_img(img, (x, y + g.panel_offset)):
             g.carry_ind = ind
             g.turtles[ind].active = False
             return True
         y += g.panel_dy
     return False
 def which(self):
     l = utils.copy_list(self.pieces)
     for i in range(35):
         pce = l.pop()
         img = pce.img
         if utils.mouse_on_img(img, (pce.x, pce.y)):
             if not pce.fixed:
                 if pce.group > 0:
                     self.top_gp(pce.group)
                 else:
                     self.top(pce)
                 return pce
     return None
 def which(self):
     l = utils.copy_list(self.pieces)
     for i in range(self.total):
         pce = l.pop()
         img = pce.img
         if utils.mouse_on_img(img, (pce.cx, pce.cy)):
             if pce.group > 0:
                 lst = utils.copy_list(self.pieces)
                 for pce1 in lst:
                     if pce1.group == pce.group: self.top(pce1)
             else:
                 self.top(pce)
             return pce
     return None
Beispiel #11
0
 def wish_click(self):
     for obj, xy in wishes:
         if utils.mouse_on_img(obj.img0, xy):
             ind = bag_free_ind()
             if ind == -1:
                 g.bag_full_ms = -1
             else:
                 g.bag[ind] = obj
                 g.wishes -= 1
                 g.bag_ms = -1
             g.state = 1
             return
     g.state = 1
     return  # empty space click
Beispiel #12
0
 def check_panelr(self, left_click=True):
     x, y = g.panel_xy
     img = g.panel_imgr[0]
     for ind in range(6):
         if utils.mouse_on_img(img, (x + g.panel_dx, y)):
             g.turtles[ind].angle = None  # reset circle
             if left_click:
                 self.inc(ind)
                 return True
             else:
                 self.dec(ind)
                 return True
         y += g.panel_dy
     return False
Beispiel #13
0
 def right_button_display(self):
     if self.right_displaying:
         d = pygame.time.get_ticks() - self.rms
         if d >= 500:
             g.redraw = True
             self.rms = pygame.time.get_ticks()
             self.down = not self.down
             if self.down:
                 self.carry = self.pieces[self.demo]
                 self.rotate()
                 self.carry = None
             if g.mx > 0 and g.my > 0:
                 pce = self.pieces[self.demo]
                 if not utils.mouse_on_img(pce.img, (pce.cx, pce.cy)):
                     self.right_displaying = False
Beispiel #14
0
 def centre(self):  # displays entrances/objects if mouse over
     # 1=open door, 2=closed door, 3=high window
     if g.box_ms == None:  # don't cover box glow
         for v in 'NSEW':
             img = None
             if self.connect[v] == 1: img = g.open_door
             if self.connect[v] == 2: img = g.door
             if self.connect[v] == 3: img = g.window
             if img == g.window and in_bag('ladder'): img = g.window_ladder
             if img <> None:
                 b = connect_box(v)
                 if utils.mouse_in(b[0], b[1], b[2], b[3]):
                     utils.centre_blit(g.screen, img, (g.cx, g.cy))
                     return True
         for corner in corners:
             top_left = self.obj_top_left(corner)
             if top_left <> None:
                 obj = self.corner[corner]
                 if utils.mouse_on_img(obj.img, top_left):
                     img = obj.img0
                     if obj.name == 'token': img = g.token
                     if obj.name == 'fuel': img = g.fuel
                     utils.centre_blit(g.screen, img, (g.cx, g.cy))
                     if obj.name in jewel_names:
                         v = value(obj.name)
                         utils.display_number(v,(g.cx,g.cy),g.font2\
                                              ,utils.CREAM,None,g.font3)
                     return True
     if self.name == 'entrance':
         if utils.mouse_on_img(g.box_closed, (g.box_x, g.box_c_y)):
             g.screen.blit(g.box_open, (g.box_x, g.box_o_y))
             utils.display_number(g.score, g.score_c, g.font2, utils.CREAM)
         else:
             utils.centre_blit(g.screen, g.box_current_img, g.box_cxy)
         return True
     return False
Beispiel #15
0
 def rotate(self):  # response to right click
     if self.carry:
         pce = self.carry
     else:
         pce = self.which()
     if pce <> None:
         pce.angle += 1
         if pce.angle == 4: pce.angle = 0
         if pce.angle > 0:
             pce.rotated = pygame.transform.rotate(pce.img, -pce.angle * 90)
         self.align(pce)
         if self.carry:
             img = pce.img
             if pce.angle > 0: img = pce.rotated
             if not utils.mouse_on_img(img, (pce.cx, pce.cy)):
                 self.carry = None  # no longer on piece
Beispiel #16
0
 def help_check(self):
     if utils.mouse_on_img(g.help1, g.help1_xy):
         pygame.mouse.set_visible(False)
         g.glow_sq = None  # turn off any glow
         self.display()
         utils.centre_blit(g.screen, g.thinking, g.thinking_xy)
         pygame.display.flip()
         self.board.find_move()
         # flush event queue
         while gtk.events_pending():
             gtk.main_iteration()
         for event in pygame.event.get():
             pass
         pygame.mouse.set_visible(True)
         return True
     return False
 def do_click(self):
     # load number
     x,y=self.load_c; d=self.load_d
     if utils.mouse_in(x-d,y-d,x+d,y+d):
         g.load_n+=1
         if g.load_n>g.saved_n: g.load_n=1
         return True
     # save number
     x,y=self.save_c; d=self.load_d
     if utils.mouse_in(x-d,y-d,x+d,y+d):
         g.save_n+=1
         if g.save_n>(g.saved_n+1): g.save_n=1
         return True
     if self.sim.in_box(): return True
     # help (printer image)
     if utils.mouse_on_img(self.sim.printer,self.sim.printer_xy):
         g.help_on=True; buttons.off('help'); return
     n=self.sim.n_pad()
     if n==None: return False
     if n=='enter': self.do_key(13); return True
     if n=='back': self.do_key(8); return True
     if len(self.sim.inos)==4: self.sim.inos=self.sim.inos[1:]
     self.sim.inos.append(n)
     return True