def display(self): # called each loop g.screen.fill((255,255,192)) g.screen.blit(g.magician,(g.sx(0),g.sy(18.0))) cx=g.sx(26); cy=g.sy(5.0); utils.centre_blit(g.screen,g.target,(cx,cy)); if g.aim>0: self.display_n_glow(g.aim,(cx,cy)) x=g.sx(3);y=g.sy(3.0) pale=False if buttons.active('plus'): pale=True for i in range(len(g.top)): x=self.display_n(g.top[i],(x,y),True,False,pale);x+=g.sp1 x=g.sx(3);y=g.sy(13) for i in range(len(g.buffr)): m=g.buffr[i] if m=='plus': g.screen.blit(g.plus,(x,y));x+=g.plus.get_width() elif m=='times': g.screen.blit(g.times,(x,y));x+=g.times.get_width() elif m=='equals': g.screen.blit(g.equals,(x,y));x+=g.equals.get_width() else: x=self.display_n(g.buffr[i],(x,y)) x+=g.sp2 buttons.draw() self.slider.draw() if self.correct(): utils.centre_blit(g.screen,g.smiley,(g.sx(16),g.sy(12))) if g.score>0: utils.display_score()
def mouse_over(self): for i in range(10): c = self.centres[i] cx = c[0] cy = c[1] w2 = self.w2 h2 = self.h2 if utils.mouse_in(cx - w2, cy - h2, cx + w2, cy + h2): n = self.yes[i] v = value(n) s = suit(n) h = self.help1() if h == 'nos': utils.display_number(v, c, g.font1, utils.CYAN, utils.ORANGE) elif h == 'odd_even': if odd(v): utils.display_number(v, c, g.font1, utils.CYAN, utils.RED) else: utils.display_number(v, c, g.font1, utils.RED, utils.CYAN) elif h == 'suit': utils.centre_blit(g.screen, g.suits[s], c) elif h == 'colour': img = g.red if colour(n) == 'b': img = g.black utils.centre_blit(g.screen, img, c) elif h == 'castle': utils.centre_blit(g.screen, g.castle, c) elif h == 'castle_x': utils.centre_blit(g.screen, g.castle_x, c) elif h == 'xo1': utils.centre_blit(g.screen, g.xo1, c) return
def set_bgd_lookFor(self): self.bgd.fill((128, 0, 0)) for n in self.obj_bgd: x = random.randint(self.x1, self.x2) y = random.randint(self.y1, self.y2) utils.centre_blit(self.bgd, self.imgs[n - 1], (x, y)) y = self.y1 k = 0 ind1 = 0 for r in range(self.nr): x = self.x1 for c in range(self.nc): n = self.obj_grid[k] ind = n - 1 img = self.imgs[ind] if n in self.to_find: lf = lookFor[ind1] lf.img = img lf.cx = x lf.cy = y lf.found = False lf.xy = utils.centre_to_top_left(img, (x, y)) ind1 += 1 else: utils.centre_blit(self.bgd, img, (x, y)) x += self.dx k += 1 y += self.dy
def display(self): g.screen.fill((255, 255, 192)) g.screen.blit(g.bgd, (g.x0, 0)) self.acr.draw() utils.centre_blit(g.screen, g.scores, g.scores_c) utils.display_number(g.score, g.score_c, g.font1) pygame.draw.rect(g.screen, utils.BLACK, g.vinc) utils.display_number(g.target, g.target_c, g.font1) utils.text_blit1(g.screen,g.percent,g.font1,g.percent_xy,\ utils.BLACK,False) if g.best > 0: s = 'Best: ' + str(g.best) + '%' utils.text_blit1(g.screen, s, g.font1, g.best_xy, utils.BLACK, False) if g.count == 2: utils.text_blit(g.screen, 'twice', g.font3, g.count_c, utils.ORANGE, False) if g.count > 2: s = str(g.count) + ' times' utils.text_blit(g.screen, s, g.font3, g.count_c, utils.ORANGE, False) buttons.draw() if self.acr.message != None: utils.message1(g.screen, g.font1, self.acr.message, g.message_c) if g.help_on: utils.centre_blit(g.screen, g.help_img, g.help_cxy)
def wish_display(self): new = False if wishes == []: new = True g.screen.blit(g.clouds, (g.sx(0), 0)) #g.screen.fill(g.bgd_colour) object_names = obj_names + ('2entrance', ) if self.side == 4: object_names += obj_names4 cy = g.sy(4.5) dx = g.sy(8.5) dy = g.sy(7.5) ind = 0 for r in range(3): if r == 2: cy -= g.sy(1) cx = g.sx(4) for c in range(4): if r == 0: if c < 3: cx += g.sy(1) else: cx -= g.sy(3) name = object_names[ind] if name == 'magic': ind += 1 name = object_names[ind] obj = name2obj(object_names[ind]) utils.centre_blit(g.screen, obj.img0, (cx, cy)) if new: xy = utils.centre_to_top_left(obj.img0, (cx, cy)) wishes.append((obj, xy)) cx += dx ind += 1 if ind == len(object_names): break cy += dy if ind == len(object_names): break if new: wishes.reverse()
def draw_turtle(self): if self.turtle_showing: self.no_turtle_screen = copy.copy(self.screen) x = self.x + self.offset y = self.y + self.offset imgr = pygame.transform.rotate(img, -self.h) utils.centre_blit(self.screen, imgr, (x, y))
def help1(self): img = self.help_imgs[self.layout] if img == None: return if self.layout > 6: utils.centre_blit(g.screen, img, g.centre) else: g.screen.blit(img, (g.offset, 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 display(self): g.screen.fill(utils.BLACK) self.board.draw() utils.display_number(g.score, (g.sx(22.6), g.yc), g.font2, utils.CREAM) utils.centre_blit(g.screen, g.star, (g.sx(27.6), g.yc)) utils.display_number1(g.best, (g.sx(28.6), g.yc), g.font2, utils.CREAM) buttons.draw()
def display(self): if self.tessl.complete(): g.screen.fill((0, 0, 0)) else: cols = [(128, 0, 128), (255, 255, 192), (0, 255, 0), (0, 255, 0), (128, 0, 128)] cols += [(0, 255, 0), (0, 0, 255), (255, 193, 127), (255, 255, 255), (0, 0, 0)] cols += [(255, 255, 192), [0, 0, 0]] g.screen.fill(cols[g.tesses[g.tess_n - 1] - 1]) self.tessl.draw() pygame.draw.rect(g.screen, (0, 0, 0), (g.sx(0), g.sy(21.55), g.sy(32), g.sy(2.55))) if self.tessl.complete(): if g.max_n < g.tess_n: g.max_n = g.tess_n self.max_n = g.max_n utils.centre_blit(g.screen, g.magician, (g.sx(16.6), g.sy(16.9))) g.button_display = True if self.tessl.carrying: g.button_display = False self.buttons_control() buttons.draw() x = g.sx(.2) y = g.sy(.2) s = str(g.tess_n) + ' / ' + str(len(g.tesses)) + ' (' + str( g.max_n) + ')' utils.display_string(s, (x, y))
def display(self): if g.menu: g.screen.fill((125,0,0)) g.screen.blit(g.bgd,(g.offset,0)) self.menu_hide() menu_tablet.draw() elif g.help1: g.screen.fill((0,0,124)) self.chess.help1() else: g.screen.fill((192,255,255)) self.chess.draw() if g.state in (1,2): tablet.draw() if self.chess.layout>6: # draw black/white "whose move?" circle img=None if g.state==1: img=g.w_img if g.state==2: img=g.b_img if g.state==6: img=g.smile if g.state==7: img=g.frown if img!=None: utils.centre_blit(g.screen,img,g.bw) if self.chess.layout not in (11,13,15,17): l=self.chess.layout s=self.chess.layout_scores[l] both=False if g.top==19 or g.top>l: both=True img=g.ghost for ind in range(2): if ind==0: if s>0 or both: img=g.star else: if s==1 and not both: img=g.ghost utils.centre_blit(g.screen,img,g.star_c[ind]) buttons.draw()
def draw(self): g.screen.blit(g.board, (g.x0 - g.border, g.y0 - g.border)) for cell in self.cells: if cell.piece != None: if cell != self.selected: if self.layout < 7 and self.aim == 10: pass else: img = self.imgs[cell.piece] x = cell.x + g.d2 - img.get_width() / 2 y = cell.y + g.dd - img.get_height() - g.base g.screen.blit(img, (x, y)) self.draw_number(cell) if self.selected != None: cell = self.selected if cell.piece != None: img = self.glow[cell.piece] x = cell.x + g.d2 - img.get_width() / 2 y = cell.y + g.dd - img.get_height() - g.base + g.glow if self.layout < 7 and self.aim == 10: pass elif self.layout == 1 and self.aim == 6: pass else: g.screen.blit(img, (x, y)) self.draw_number(cell) if self.layout > 9: #games img = None if g.state == 4: if utils.odd(self.layout): img = self.wmate else: img = self.bmate if g.state == 5: img = self.stale if img != None: utils.centre_blit(g.screen, img, g.centre) self.check() # manage successes & top
def glow(self): if self.glow_active: ind = self.glow_ind cx = g.imgs[ind].cx cy = g.imgs[ind].cy utils.centre_blit(g.screen, g.glow[ind], (cx, cy)) d = pygame.time.get_ticks() - self.glow_ms if d < 0 or d >= self.glow_time: self.glow_active = False
def draw_anims(self): for ind in range(2): a = self.anim[ind] if a.ms != None: n = a.n if n > 0: if n > 26: n = 26 utils.centre_blit(g.screen, self.balls[n], (a.x, a.y))
def display(self): g.screen.fill((0,0,70)) buttons.draw() self.grid.draw() self.slider.draw() utils.display_number(g.score,self.score_cxy,g.font2,utils.CREAM) if self.grid.complete(): utils.centre_blit(g.screen,g.smiley,self.smiley_cxy)
def display(self): g.screen.blit(g.sky, g.sky_xy) self.soko.draw() buttons.draw() s = str(g.pattern) + ' / ' + str(g.puzzles_n) utils.text_blit1(g.screen, s, g.font2, (g.sx(.5), g.sy(.5)), utils.BLUE, False) if not g.demo_mode and self.soko.complete(): utils.centre_blit(g.screen, g.smiley, g.smiley_c)
def glow(self, y=False): if self.glow_active: ind = self.glow_ind cx = g.imgs[ind].cx cy = g.imgs[ind].cy img = g.glow[ind] if y: img = g.glowy[ind] utils.centre_blit(g.screen, img, (cx, cy))
def grid(self): # only for setting up original grid g.screen.fill((0, 0, 0)) y = g.y0 for r in range(5): x = g.x0 for c in range(5): utils.centre_blit(g.screen, g.sq, (x, y)) x = x + g.dd y = y + g.dd
def display(self): g.screen.fill((0, 0, 0)) buttons.draw() self.slider.draw() self.omm.draw() utils.display_number(self.omm.n, g.number_c, g.font2, self.omm.colr_n) s = str(len(om.found[g.level - 1])) + ' / ' + str(self.omm.total) utils.text_blit(g.screen, s, g.font1, g.progress_c, utils.CREAM) if self.omm.complete(): utils.centre_blit(g.screen, g.smiley, g.smiley_c)
def number(self,n): if n<10: utils.centre_blit(g.screen,g.digits[n],self.target_c) else: dx=g.sy(.6) n1=n/10; n2=n-n1*10; img1=g.digits[n1]; img2=g.digits[n2] x,y=self.target_c; y-=img1.get_height()/2 xoffset=(img1.get_width()-img2.get_width())/2 g.screen.blit(img1,(x-img1.get_width()+dx+xoffset,y)) g.screen.blit(img2,(x-dx+xoffset,y))
def display(self): g.screen.fill((255, 255, 192)) if g.state == 1: utils.centre_blit(g.screen, g.title, g.title_c) elif g.state == 2: g.title = None self.menu.draw() self.slider.draw() elif g.state == 3: self.jigsaw.draw() buttons.draw()
def draw(): if g.turtles_on: for turtle in g.turtles: if turtle.active: imgr=pygame.transform.rotate(turtle.img,-turtle.h) x=g.txy[0]+turtle.x; y=g.txy[1]+turtle.y if x<g.x1: continue if x>g.x2: continue if y<g.y1: continue if y>g.y2: continue utils.centre_blit(g.screen,imgr,(x,y))
def draw_number(self, cell): if cell.number != None: cx = cell.x + g.d2 cy = cell.y + g.d2 img = self.nos[cell.number] if cell.number == self.aim: img = self.nos_yellow[cell.number] if self.aim == 10: img = self.nos_yellow[cell.number] if self.layout == 1 and self.aim == 6: img = self.nos_yellow[cell.number] if cell.number in self.wrong: img = self.nos_red[cell.number] utils.centre_blit(g.screen, img, (cx, cy))
def display(): g.screen.fill((0,255,0)) for img in g.imgs: # img from ImgClickClass (centred) img.draw(g.screen) if g.wrong: img=g.imgs[g.wrong_ind] utils.centre_blit(g.screen,g.wrong_img,(img.cx,img.cy)) img=g.imgs[g.right_ind] utils.centre_blit(g.screen,g.glow[g.right_ind],(img.cx,img.cy)) buttons.draw() ladder() g.screen.blit(g.magician,(g.sx(3.2),g.sy(18.2)))
def display(self): grey = 100 g.screen.fill((grey, grey, grey)) buttons.draw() g.screen.blit(g.help1, g.help1_xy) utils.display_number(g.count, (g.xc, g.yc), g.font2, utils.CREAM) colour = utils.YELLOW if g.helped > 5: colour = utils.RED utils.display_number(g.helped, (g.xc, g.yc + g.sy(6)), g.font1, colour) if g.finished: utils.centre_blit(g.screen, g.smiley, (g.sx(4), g.smiley_y)) self.board.draw()
def display(self): if self.name == 'dark': if not in_bag('lamp'): g.screen.fill((0, 0, 0), (g.x0, g.y0, g.s0, g.s0)) else: if self.name in ('gas','dungeon','pool','ice','vines','teleporter'\ ,'wizard','trapdoor','treasure','genie','casino'\ ,'laser','secret'): g.screen.blit(self.bgd, (g.x0, g.y0)) else: g.screen.fill(g.floor, (g.x0, g.y0, g.s0, g.s0)) if self.name == 'map': utils.centre_blit(g.screen, g.map2, (g.cx, g.cy)) if self.name == 'dark' and not in_bag('lamp'): pass else: if self.name == 'casino': casino_display() else: g.casino_running = False if self.name == 'trapdoor': img = None if in_bag('goggles'): img = g.green_hole if g.trap_ms <> -1: img = g.hole if img <> None: g.screen.blit(img, (g.trap_x, g.trap_y)) self.show_helper(self.name) for corner in corners: # objects top_left = self.obj_top_left(corner) if top_left <> None: obj = self.corner[corner] g.screen.blit(obj.img, top_left) if g.health > 0: img = g.player if self.name == 'thieves' and in_bag('cloak'): img = g.player_pale if g.telep_ms == None: # not teleporting utils.centre_blit(g.screen, img, (g.player_cx, g.player_cy)) if self.name in ('gas', 'dark', 'thieves'): # draw over objects g.screen.blit(self.bgd, (g.x0, g.y0)) self.centre() if g.steal_ms <> None: g.screen.blit(g.steal, g.steal_xy) self.wall() # 0=outside, 1=open door, 2=closed door, 3=high window for v in 'NSEW': if self.connect[v] > 0: colour = utils.BLACK if self.connect[v] == 1: colour = utils.WHITE elif self.connect[v] == 2: colour = (162, 126, 87) b = connect_box(v) pygame.draw.rect(g.screen, colour, (b[0], b[1], b[2] - b[0], b[3] - b[1]))
def draw_nos(self): # draw the numbers with glow in correct position pos = self.calc_pos(self.tu.step_count) x = g.n_cx0 for i in range(5): if i == pos: x_glow = x n = g.numbers[i] utils.centre_blit(g.screen, g.n[n - 1], (x, g.n_cy0)) x += g.n_dx if not self.tu.changed or g.show_help: if self.tu.step_count < self.tu.steps: # no glow if finished n = self.tu.current[pos] utils.centre_blit(g.screen, g.n_glow[n - 1], (x_glow, g.n_cy0))
def display(self,wait=False): g.screen.fill((0,0,100)) if wait: utils.centre_blit(g.screen,g.wait,(g.sx(16),g.sy(10))) else: self.rects.draw() buttons.draw() self.slider.draw() if g.magic_show: utils.centre_blit(g.screen,g.magic,(g.sx(27.8),g.sy(3.2))) if g.score>0: x=g.sx(29.5); y=g.sy(8) utils.display_number(g.score,(x,y),g.font2,utils.CREAM)
def draw(self): ind = 0 for item in self.items: g.screen.blit(item.img, (item.x, item.y)) xn, yn = item.x + self.pic_w / 2, int(item.y + self.pic_h + self.gutter_y / 2.5) if item == self.green: pygame.draw.rect(g.screen,utils.GREEN,\ (item.x,item.y,self.pic_w,self.pic_h),self.edge) if g.best[ind] == 3: utils.centre_blit(g.screen, g.star, (xn, yn)) utils.display_number(g.best[ind], (xn, yn), g.font1, (135, 191, 47)) ind += 1
def draw(self): if self.complete(): g.screen.blit(self.final, self.rect) g.screen.blit(g.frame, self.frame_rect) else: grey = 100 pygame.draw.rect(g.screen, (grey, grey, grey), self.rect, 2) if self.carry != None: self.carry.cx = g.mx + self.dx self.carry.cy = g.my + self.dy if self.carry.group > 0: self.align(self.carry) for pce in self.pieces: img = pce.img utils.centre_blit(g.screen, img, (pce.cx, pce.cy))
def display(self): g.screen.fill(self.colors[1]) if not self.sugar: g.screen.blit(g.bgd, (g.sx(0), 0)) self.let.draw() if self.sugar: self.back_button.set_sensitive(False) self.tick_button.set_sensitive(False) else: buttons.off(['back', 'tick']) if g.state in (2, 4): if len(self.let.ans) > 0: if self.sugar: self.back_button.set_sensitive(True) else: buttons.on('back') if len(self.let.ans) > 1: if self.sugar: self.tick_button.set_sensitive(True) else: buttons.on('tick') buttons.draw() #utils.display_number(g.state,(10,10),g.font1) if g.state == 3: ln = len(self.let.ans) if ln == 2: s = _('Your word scores one point.') else: s = _('Your word scores %s points.' % (str(2 ** (ln - 2)))) utils.text_blit(g.screen, s, g.font2, g.message_cxy, self.colors[0], False) if g.state == 4: s = _('Sorry, %s is not in my word list' % self.let.ans) utils.text_blit(g.screen, s, g.font2, g.message_cxy, self.colors[0], False) if self.sugar: self.label.set_markup( '<span><big><b> %s (%s)</b></big></span>' % (str(g.score), str(g.best))) else: if g.score > 0: s = _('Total: %s' % (str(g.score))) utils.text_blit(g.screen, s, g.font1, g.score_cxy, self.colors[0], False) if g.best > 0: s = _('Best: %s' % (str(g.best))) utils.text_blit(g.screen, s, g.font1, g.best_cxy, self.colors[0], False) if g.help_on: utils.centre_blit(g.screen, g.help_img, g.help_cxy)
def display_score(self): if self.sugar: self.label.set_markup( '<span><big><b> %s (%s)</b></big></span>' % ( str(int(g.score)), str(int(g.best)))) else: text = g.font2.render(str(g.score), True, utils.ORANGE, utils.BLUE) w = text.get_width() h = text.get_height() x = g.sx(5.15) y = g.sy(19.6) d = g.sy(.3) pygame.draw.rect(g.screen, utils.BLUE, (x - d, y - d, w + 2 * d, h + 2 * d - g.sy(.2))) g.screen.blit(text, (x, y)) utils.centre_blit(g.screen, g.sparkle, (x - d + g.sy(.05), y - d + g.sy(1.1)))
def display(self): g.screen.fill(self.colors[1]) if not self.sugar: g.screen.fill((255, 255, 192)) g.screen.blit(g.magician, (g.sx(0), g.sy(18.0))) cx = g.sx(26) cy = g.sy(5.0) utils.centre_blit(g.screen, g.target, (cx, cy)) if g.aim > 0: self.display_n_glow(g.aim, (cx, cy)) x, y = g.xy1 pale = False if g.state == 2: pale = True for i in range(len(g.top)): x = self.display_n(g.top[i], (x, y), True, False, pale) x += g.sp1 x, y = g.xy3 for i in range(len(g.buffr)): m = g.buffr[i] if m == 'plus': g.screen.blit(g.plus, (x, y)) x += g.plus.get_width() elif m == 'times': g.screen.blit(g.times, (x, y)) x += g.times.get_width() elif m == 'equals': g.screen.blit(g.equals, (x, y)) x += g.equals.get_width() else: x = self.display_n(g.buffr[i], (x, y)) x += g.sp2 if len(g.top) == 0: buttons.off(['plus', 'times']) buttons.draw() if not self.sugar: self.slider.draw() if g.state == 4: utils.centre_blit(g.screen, g.smiley, (g.sx(16), g.sy(12))) if g.score > 0: self.display_score() if not self.sugar and g.best > 0: utils.text_blit( g.screen, str(g.best), g.font2, g.best_c, utils.ORANGE)
def ladder(self): if g.score > g.best: g.best = g.score if g.best > 11: cx = g.sx(30.55) cy = g.sy(13.25) utils.centre_blit(g.screen, g.star, (cx, cy)) utils.display_number(g.best, (cx, cy), g.font2) if g.score > 0: n = g.score - 1 if n > 11: n = 11 g.screen.blit(g.ladder, (g.sx(26.95), g.sy(13.7))) x = g.man_x0 + n * g.man_dx y = g.man_y0 + n * g.man_dy g.screen.blit(g.man, (x, y)) cx = x + g.man_sc_dx cy = y + g.man_sc_dy if g.score < g.best or g.best < 12: utils.centre_blit(g.screen, g.star, (cx, cy)) utils.display_number(g.score, (cx, cy), g.font2)
def display(self): g.screen.fill(self.colors[1]) if self.aim.running or self.aim.glow_active: pass else: x = g.imgs[g.green].x y = g.imgs[g.green].y w = g.imgs[g.green].w h = g.imgs[g.green].h # pygame.draw.rect(g.screen, self.colors[0], (x,y,w,h), g.sy(.2)) for img in g.imgs: # img from ImgClick (centred) img.draw(g.screen) if g.wrong: img = g.imgs[g.wrong_ind] utils.centre_blit(g.screen, g.wrong_img, (img.cx, img.cy)) img = g.imgs[g.right_ind] utils.centre_blit(g.screen, g.glowy[g.right_ind], (img.cx, img.cy)) if not self.sugar: buttons.draw() self.slider.draw() self.ladder() self.aim.glow() self.player.glow(True)
def help1(self): x1 = g.x1 + 4 * g.dd y1 = g.y1 + 6 * g.dd dx = 0 dy = -g.dd steps = 0 angle = 0 n = 0 for j in self.current: for k in range(j): steps += 1 x2 = x1 + dx y2 = y1 + dy pygame.draw.line(g.screen, self.color, (x1, y1), (x2, y2), 4) x1 = x2 y1 = y2 if dy == -g.dd: dx = g.dd dy = 0 angle = 90 elif dx == g.dd: dx = 0 dy = g.dd angle = 180 elif dy == g.dd: dx = -g.dd dy = 0 angle = 270 else: dx = 0 dy = -g.dd angle = 0 n += 1 if n == g.help1: break utils.centre_blit(g.screen, g.turtle, (x2, y2), angle) self.step_count = steps
def display(self): # called each loop if g.big: g.screen.fill(self.colors[1]) utils.centre_blit(g.screen, g.big_surface, (g.sx(16), g.sy(11.5))) else: if self.sugar: g.screen.fill(self.colors[1]) else: g.screen.blit(g.bgd, (g.sx(0), 0)) g.screen.blit(g.box, (g.x0, g.y0)) g.screen.blit(g.box, (g.x1, g.y1)) if not self.sugar: utils.centre_blit(g.screen, g.magician, g.magician_c) self.draw_goal() utils.centre_blit(g.screen, g.turtle, (g.x0 + 4 * g.dd, g.y0 + 6 * g.dd)) self.tu.draw() if self.tu.win: utils.centre_blit(g.screen, g.smiley, (g.sx(16.6), g.sy(2.2))) if self.sugar: self.cyan_button.set_sensitive(True) else: buttons.on('cyan') if not self.journal: utils.save() self.draw_nos() if not self.sugar: buttons.draw() self.slider.draw() if g.score > 0: if self.sugar: self.label.set_markup( '<span><big><b> %s</b></big></span>' % (str(g.score))) else: utils.display_score() utils.display_number1(g.pattern, (g.sx(2.4), g.sy(2)), g.font1, utils.BLUE)
def draw(self): if self.between_levels: return x1 = g.x1 + 4 * g.dd y1 = g.y1 + 6 * g.dd dx = 0 dy = -g.dd steps = 0 angle = 0 x2 = x1 y2 = y1 # in case we haven't moved yet - for turtle image done = True n = 0 for i in range(4): for j in self.current: for k in range(j): steps += 1 if not g.show_help: if steps > self.step_count: done = False break x2 = x1 + dx y2 = y1 + dy pygame.draw.line(g.screen, self.color, (x1, y1), (x2, y2), 4) x1 = x2 y1 = y2 if not g.show_help: if steps > self.step_count: break if dy == -g.dd: dx = g.dd dy = 0 angle = 90 elif dx == g.dd: dx = 0 dy = g.dd angle = 180 elif dy == g.dd: dx = -g.dd dy = 0 angle = 270 else: dx = 0 dy = -g.dd angle = 0 if g.show_help: n += 1 if n == g.help1: self.step_count = steps break if g.show_help: if n == g.help1: break elif steps > self.step_count: break img = g.turtle if self.crashed: img = g.crash utils.centre_blit(g.screen, img, (x2, y2), angle) d8 = 8 * g.dd if not g.show_help: if abs(x2 - g.x1) < .1 or abs(x2 - (g.x1 + d8)) < .1 or \ abs(y2 - g.y1) < .1 or abs(y2 - (g.y1 + d8)) < .1: if not self.crashed: g.crash_drawn = False self.running = False self.crashed = True elif done: self.win = correct(self.current) if self.win: if not g.finale: if g.help2 > 5: g.help2 = 5 g.score = g.score + 6 - g.help2 g.finale = True
def display(self): # called each loop if g.big: g.screen.fill(self.colors[1]) utils.centre_blit(g.screen, g.big_surface, (g.sx(16), g.sy(11.5))) else: if self.sugar: g.screen.fill(self.colors[1]) else: g.screen.blit(g.bgd, (g.sx(0), 0)) g.screen.blit(g.box, (g.x0, g.y0)) g.screen.blit(g.box, (g.x1, g.y1)) if not self.sugar: utils.centre_blit(g.screen, g.magician, g.magician_c) self.draw_goal() utils.centre_blit(g.screen, g.turtle, (g.x0 + 4 * g.dd, g.y0 + 6 * g.dd)) self.tu.draw() if self.tu.win: if self.sugar: if self.good_job is None: path = self.parent.good_job_image_path() self.good_job = utils.load_image(path, True) if g.w > g.h: utils.centre_blit( g.screen, self.good_job, (g.sx(7), g.sy(17))) else: utils.centre_blit(g.screen, self.good_job, (g.sx(7), g.sy(38))) else: utils.centre_blit(g.screen, g.smiley, (g.sx(16.6), g.sy(2.2))) if self.sugar: self.cyan_button.set_sensitive(True) else: buttons.on('cyan') if not self.journal: utils.save() self.draw_nos() if not self.sugar: buttons.draw() self.slider.draw() if g.score > 0: if self.sugar: self.parent.update_score(int(g.score)) else: utils.display_score() utils.display_number1(g.pattern, (g.sx(2.4), g.sy(2)), g.font1, utils.WHITE)