def do_key(self, key): if key in g.SQUARE: if buttons.active('new'): self.do_button('new') return if key in g.CIRCLE: if buttons.active('next'): self.do_button('next') return if key == pygame.K_v: g.version_display = not g.version_display return
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 main(): while True: ms=pygame.time.get_ticks() for event in pygame.event.get(): if event.type==QUIT: utils.exit() elif event.type == pygame.MOUSEBUTTONDOWN: # allow any button - left, right or middle glow_off() if click(): break display(); pygame.display.flip() # no pointer in case button pressed bu=buttons.check() if bu<>'':do_button(bu) elif event.type==KEYDOWN: if event.key==K_ESCAPE: utils.exit() if event.key==K_x: g.version_display=not g.version_display if g.player_n==0 and not buttons.active('green'): buttons.on("back") display() aim.do() aim.glow(); player.glow() if g.version_display: g.message=g.app+' Version '+g.ver g.message+=' '+str(g.w)+' x '+str(g.h) g.message+=' '+str(g.frame_rate)+'fps' utils.message(g.screen,g.font1,g.message) mx,my=pygame.mouse.get_pos() if my>g.pointer.get_height(): g.screen.blit(g.pointer,(mx,my)) pygame.display.flip() g.clock.tick(40) d=pygame.time.get_ticks()-ms; g.frame_rate=int(1000/d)
def do_key(self, key): if key in g.CROSS and not self.sugar: if utils.mouse_on_img1(g.magician, g.magician_c): self.help2() return bu = buttons.check() if bu != '': self.do_button(bu) return g.show_help = False self.check_nos(1) return if key in g.CIRCLE: self.check_nos(3) return if key in g.RIGHT: self.mouse_right() return if key in g.LEFT: self.mouse_left() return if key in g.SQUARE: if self.sugar and self.cyan_button.get_sensitive(): self.do_button('cyan') if not self.sugar and buttons.active('cyan'): self.do_button('cyan') return if key in g.TICK: self.change_level() return if key == pygame.K_v: g.version_display = not g.version_display return
def mouse_right2(self): # used for states 2 & 3 for i in range(5): # no infinite loop self.mouse_ind += 1 if self.mouse_ind == len(self.ops): self.mouse_ind = 0 if buttons.active(self.ops[self.mouse_ind]): self.mouse_set() return
def up(): r, c = rc() r -= 1 if r < 0: r = 2 n = 6 * r + c + 1 if buttons.active(str(n)): g.menu_green = n mouse()
def right(): r, c = rc() c += 1 if c == 6: c = 0 n = 6 * r + c + 1 if buttons.active(str(n)): g.menu_green = n mouse()
def mouse_left2(self): # used for states 2 & 3 for i in range(5): # no infinite loop self.mouse_ind -= 1 if self.mouse_ind < 0: self.mouse_ind = len(self.ops) - 1 if buttons.active(self.ops[self.mouse_ind]): self.mouse_set() return
def left(): r, c = rc() c -= 1 if c < 0: c = 5 n = 6 * r + c + 1 if buttons.active(str(n)): g.menu_green = n mouse()
def down(): r, c = rc() r += 1 if r == 3: r = 0 n = 6 * r + c + 1 if buttons.active(str(n)): g.menu_green = n mouse()
def do_key(self, key): if key in g.CROSS: bu = buttons.check() if bu != '': self.do_button(bu) return if g.state == 1: self.check_numbers() return if key in g.UP: if self.back_button.mouse_on(): if g.state == 1: self.mouse_init() elif buttons.active('back'): buttons.set_mouse('back') if g.state == 2: self.mouse_ind = 0 return if key in g.DOWN: if buttons.active('back'): if g.state in (1, 3): buttons.set_mouse('back') return if key in g.RIGHT: if not self.complete(): self.mouse_right() return if key in g.LEFT: if not self.complete(): self.mouse_left() return if key == pygame.K_m: self.mouse_auto = not self.mouse_auto self.mouse_init() return if key in g.SQUARE or key in g.CIRCLE: self.do_button('new') return if key in g.TICK: self.inc_level() return if key == pygame.K_v: g.version_display = not g.version_display return
def do_key(self, key): if key in g.TICK: self.change_level() self.set_delay() return if key == pygame.K_v: g.version_display = not g.version_display return if self.aim.running or self.aim.glow_active: return if key in g.CROSS: self.do_click() return if key in g.SQUARE: if self.sugar: if self.green_button.get_sensitive(): self.do_button('green') return elif self.back_button.get_sensitive(): self.do_button('back') return else: if buttons.active('green'): self.do_button('green') return if buttons.active('back'): self.do_button('back') return if key in g.RIGHT: g.green = self.rc.inc_c(g.green) g.imgs[g.green].mouse_set() if key in g.LEFT: g.green = self.rc.dec_c(g.green) g.imgs[g.green].mouse_set() if key in g.UP: g.green = self.rc.dec_r(g.green) g.imgs[g.green].mouse_set() if key in g.DOWN: g.green = self.rc.inc_r(g.green) g.imgs[g.green].mouse_set()
def check_numbers(self): if not buttons.active('plus') and not self.correct(): (mx,my)=pygame.mouse.get_pos() x1=g.sx(3);y1=g.sy(3.5);h=g.n[0].get_height() for i in range(len(g.top)): x=self.display_n(g.top[i],(x1,y1),False) w=x-x1 rect=pygame.Rect(x1,y1,w,h) if rect.collidepoint(mx,my): g.buffr.append(g.top[i]); del g.top[i] buttons.on(['back','plus','times']) if len(g.buffr)>1: buttons.on('equals') return True#**** x1=x+g.sp1 return False
def display(): aim.do() aim.draw() if not aim.running: aim.draw_turtle_abs() player.delay = 100 * (6 - g.level) player.do() player.draw() g.screen.blit(g.basic_imgs[g.shape], (g.basic_x, g.basic_y)) g.screen.blit(g.bgd, (g.sx(0), 0)) if buttons.active('cyan'): g.screen.blit(g.magician, (g.sx(1), g.sy(1.5))) utils.centre_blit(g.screen, g.sparkle, (g.sx(4.5), g.sy(3.1))) angler.draw() s = str(g.repeats[g.repeat]) c = (g.repeat_cx, g.repeat_cy) g.text_rect = utils.text_blit(g.screen, s, g.font2, c, (0, 0, 200)) s = str(g.aim_n + 1) + ' / ' + str(len(my_turtle.aims)) utils.text_blit1(g.screen, s, g.font1, (g.sx(6.3), g.sy(8.3)), (0, 0, 255)) buttons.draw() g.slider.draw()
def mouse_left(self): bu = '' cx = g.n_cx0 cy = g.n_cy0 c = None if not self.sugar: if utils.mouse_on_img1(g.magician, g.magician_c): c = (cx + 4 * g.n_dx, cy) elif buttons.mouse_on('cyan'): self.mouse_magician() return elif buttons.mouse_on('green'): if buttons.active('cyan'): bu = 'cyan' else: self.mouse_magician() return elif buttons.mouse_on('red'): bu = 'green' elif buttons.mouse_on('black'): bu = 'red' if bu != '': buttons.set_mouse(bu) return if c is None: c = (cx, cy) # default to 1st no. for i in range(5): n = g.numbers[i] if utils.mouse_on_img_rect(g.n[n - 1], (cx, cy)): c = (cx - g.n_dx, cy) break cx += g.n_dx cx, cy = c cx += g.sy(.2) cy += g.sy(1.2) c = cx, cy pygame.mouse.set_pos(c) g.pos = c return
def mouse_right(self): bu = '' if not self.sugar: if utils.mouse_on_img1(g.magician, g.magician_c): bu = 'green' if buttons.active('cyan'): bu = 'cyan' elif buttons.mouse_on('cyan'): bu = 'green' elif buttons.mouse_on('green'): bu = 'red' elif buttons.mouse_on('red'): bu = 'black' if bu != '': buttons.set_mouse(bu) return cx = g.n_cx0 cy = g.n_cy0 c = (cx, cy) # default to 1st no. if not buttons.mouse_on('black'): for i in range(5): n = g.numbers[i] if utils.mouse_on_img_rect(g.n[n - 1], (cx, cy)): if i == 4: self.mouse_magician() return c = (cx + g.n_dx, cy) break cx += g.n_dx cx, cy = c cx += g.sy(.2) cy += g.sy(1.2) c = cx, cy pygame.mouse.set_pos(c) g.pos = c return
def run(self): g.init() if not self.journal: utils.load() load_save.retrieve() self.buttons_setup() self.objects = jum.Objects() self.objects.setup() self.setup() if self.canvas <> None: self.canvas.grab_focus() ctrl = False pygame.key.set_repeat(600, 120) key_ms = pygame.time.get_ticks() going = True while going: if self.journal: # Pump GTK messages. while gtk.events_pending(): gtk.main_iteration() # Pump PyGame messages. for event in pygame.event.get(): if event.type == pygame.QUIT: if not self.journal: utils.save() going = False elif event.type == pygame.MOUSEMOTION: g.pos = event.pos g.redraw = True self.objects.update() if self.canvas <> None: self.canvas.grab_focus() elif event.type == pygame.MOUSEBUTTONDOWN: g.redraw = True if event.button == 1: if self.objects.click(): if self.objects.complete: buttons.off('next') else: self.display() bu = buttons.check() if bu != '': self.do_button(bu) if event.button == 3: if buttons.active('next'): self.do_button('next') self.flush_queue() elif event.type == pygame.KEYDOWN: # throttle keyboard repeat if pygame.time.get_ticks() - key_ms > 110: key_ms = pygame.time.get_ticks() if ctrl: if event.key == pygame.K_q: if not self.journal: utils.save() going = False break else: ctrl = False if event.key in (pygame.K_LCTRL, pygame.K_RCTRL): ctrl = True break self.do_key(event.key) g.redraw = True self.flush_queue() elif event.type == pygame.KEYUP: ctrl = False if not going: break if g.setup_on: self.objects.setup() g.redraw = True if (pygame.time.get_ticks() - self.setup_ms) > 2000: g.setup_on = False buttons.on('next') if g.redraw: self.display() if g.version_display: utils.version_display() g.screen.blit(g.pointer, g.pos) pygame.display.flip() g.redraw = False g.clock.tick(40)
def run(self, restore=False): self.g_init() if not self.journal: utils.load() load_save.retrieve() self.aim = simon.Simon(1200) # arg is glow time if self.sugar: self.set_delay(800) else: self.set_delay() self.player = simon.Simon(200) if restore: self.restore_pattern() self.aim.started = True if self.sugar: self.green_button.set_sensitive(True) self.back_button.set_sensitive(False) else: bx = g.sx(22.42) by = g.sy(20.8) buttons.Button('green', (bx, by), True) buttons.Button('back', (bx, by), True) buttons.off('back') self.slider = slider.Slider(g.sx(9), g.sy(20.8), 3, utils.BLUE) self.rc = rc_skip_last.RC(3, 5) if self.canvas is not None: self.canvas.grab_focus() ctrl = False pygame.key.set_repeat(600, 120) key_ms = pygame.time.get_ticks() going = True while going: if self.journal: # Pump GTK messages. while Gtk.events_pending(): Gtk.main_iteration() # Pump PyGame messages. for event in pygame.event.get(): if event.type == pygame.QUIT: if not self.journal: utils.save() going = False elif event.type == pygame.MOUSEMOTION: g.pos = event.pos g.redraw = True if self.canvas is not None: self.canvas.grab_focus() self.mouse_set() elif event.type == pygame.MOUSEBUTTONDOWN: g.redraw = True if event.button == 1: self.do_click() self.flush_queue() elif event.type == pygame.KEYDOWN: # throttle keyboard repeat if pygame.time.get_ticks() - key_ms > 110: key_ms = pygame.time.get_ticks() if ctrl: if event.key == pygame.K_q: if not self.journal: utils.save() going = False break else: ctrl = False if event.key in (pygame.K_LCTRL, pygame.K_RCTRL): ctrl = True break self.do_key(event.key) g.redraw = True self.flush_queue() elif event.type == pygame.KEYUP: ctrl = False if not going: break if self.sugar: if g.player_n == 0 and not self.green_button.get_sensitive(): self.back_button.set_sensitive(True) else: if g.player_n == 0 and not buttons.active('green'): buttons.on('back') self.player.do() self.aim.do() if g.redraw: self.display() if g.version_display: utils.version_display() if self.aim.running or self.aim.glow_active: pass else: g.screen.blit(g.pointer, g.pos) pygame.display.flip() g.redraw = False g.clock.tick(40)
def run(self, restore=False): self.g_init() if not self.journal: utils.load() load_save.retrieve() self.aim = simon.Simon(1200) # arg is glow time if self.sugar: self.set_delay(800) else: self.set_delay() self.player = simon.Simon(200) if restore: self.restore_pattern() self.aim.started = True if self.sugar: self.green_button.set_sensitive(True) self.back_button.set_sensitive(False) else: bx = g.sx(22.42) by = g.sy(20.8) buttons.Button('green', (bx, by), True) buttons.Button('back', (bx, by), True) buttons.off('back') self.slider = slider.Slider(g.sx(9), g.sy(20.8), 3, utils.BLUE) self.rc = rc_skip_last.RC(3, 5) if self.canvas is not None: self.canvas.grab_focus() ctrl = False pygame.key.set_repeat(600, 120) key_ms = pygame.time.get_ticks() going = True while going: if self.journal: # Pump GTK messages. while gtk.events_pending(): gtk.main_iteration() # Pump PyGame messages. for event in pygame.event.get(): if event.type == pygame.QUIT: if not self.journal: utils.save() going = False elif event.type == pygame.MOUSEMOTION: g.pos = event.pos g.redraw = True if self.canvas is not None: self.canvas.grab_focus() self.mouse_set() elif event.type == pygame.MOUSEBUTTONDOWN: g.redraw = True if event.button == 1: self.do_click() self.flush_queue() elif event.type == pygame.KEYDOWN: # throttle keyboard repeat if pygame.time.get_ticks() - key_ms > 110: key_ms = pygame.time.get_ticks() if ctrl: if event.key == pygame.K_q: if not self.journal: utils.save() going = False break else: ctrl = False if event.key in (pygame.K_LCTRL, pygame.K_RCTRL): ctrl = True break self.do_key(event.key) g.redraw = True self.flush_queue() elif event.type == pygame.KEYUP: ctrl = False if not going: break if self.sugar: if g.player_n == 0 and not self.green_button.get_sensitive(): self.back_button.set_sensitive(True) else: if g.player_n == 0 and not buttons.active('green'): buttons.on('back') self.player.do() self.aim.do() if g.redraw: self.display() if g.version_display: utils.version_display() if self.aim.running or self.aim.glow_active: pass else: g.screen.blit(g.pointer, g.pos) pygame.display.flip() g.redraw = False g.clock.tick(40)