def __init__(self, mode, layerA=None, layerB=None, transitionType=TYPE_PUSH, transitionParameter=None, lengthInFrames=LENGTH_IN_FRAMES, callback=None): self.mode = mode if layerA == None: layerA = dmd.FrameLayer(False, dmd.Frame(128, 32)) self.layerA = layerA if layerB == None: layerB = dmd.FrameLayer(False, dmd.Frame(128, 32)) self.layerB = layerB self.callback = callback transition_class = self.get_class("procgame.dmd.transitions." + transitionType) if transitionParameter: self.transition = transition_class(transitionParameter) else: self.transition = transition_class() self.transition.progress_per_frame = 1.0 / lengthInFrames self.transition.completed_handler = self.finished self.transition.start() self.update()
def animate_to_index(self, new_index, inc=0): letter_spread = 10 letter_width = 7 if inc < 0: rng = range(inc * letter_spread, 1) elif inc > 0: rng = range(inc * letter_spread)[::-1] else: rng = [0] #print rng for x in rng: frame = dmd.Frame(width=128, height=10) for offset in range(-7, 8): index = new_index - offset #print "Index %d len=%d" % (index, len(self.letters)) if index < 0: index = len(self.letters) + index elif index >= len(self.letters): index = index - len(self.letters) (w, h) = self.font.size(self.letters[index]) #print "Drawing %d w=%d" % (index, w) self.letters_font.draw(frame, self.letters[index], 128 / 2 - offset * letter_spread - letter_width / 2 + x, 0, color=ep.CYAN) frame.fill_rect(64 - 5, 0, 1, 10, 10) frame.fill_rect(64 + 5, 0, 1, 10, 10) self.lowerhalf_layer.frames += [frame] self.current_letter_index = new_index # Prune down the frames list so we don't get too far behind while animating x = 0 while len(self.lowerhalf_layer.frames) > 15 and x < ( len(self.lowerhalf_layer.frames) - 1): del self.lowerhalf_layer.frames[x] x += 2 # Now draw the top right panel, with the selected initials in order: self.inits_frame.clear() init_spread = 8 x_offset = self.inits_frame.width / 2 - len( self.inits) * init_spread / 2 for x in range(len(self.inits)): self.init_font.draw(self.inits_frame, self.inits[x], x * init_spread + x_offset, 0, color=ep.GREEN) self.inits_frame.fill_rect( (len(self.inits) - 1) * init_spread + x_offset, 9, 8, 1, 1)
def __init__(self, font, font_path, text): super(DmdFontWidthsGame, self).__init__(pinproc.MachineTypeCustom) self.reset() w = 128 h = 32 self.font = font self.font_path = font_path self.text = text self.text_layer = dmd.TextLayer(0, 0, font) self.text_layer.set_text(text) mode = game.Mode(game=self, priority=9) mode.layer = dmd.GroupedLayer( w, h, [dmd.FrameLayer(frame=dmd.Frame(w, h)), self.text_layer]) self.modes.add(mode) self.dirty = False
def animate_to_index(self, new_index, inc = 0): letter_spread = 20 letter_width = self.letters_font_width if inc < 0: rng = range(inc * letter_spread, 1) elif inc > 0: rng = range(inc * letter_spread)[::-1] else: rng = [0] #print rng for x in rng: frame = dmd.Frame(width=self.game.dmd.width, height=self.init_font_height+2) for offset in range(-7, 8): index = new_index - offset #print "Index %d len=%d" % (index, len(self.letters)) if index < 0: index = len(self.letters) + index elif index >= len(self.letters): index = index - len(self.letters) (w, h) = self.letters_font.size(self.letters[index]) #print "Drawing %d w=%d" % (index, w) self.letters_font.draw(frame, self.letters[index], self.game.dmd.width/2 - offset * letter_spread - letter_width/2 + x, 0) frame.fill_rect(self.game.dmd.width/2-letter_width/2 - 4, 0, 2, self.letters_font_height+2, (255,255,0,255)) frame.fill_rect(self.game.dmd.width/2+letter_width/2 , 0, 2, self.letters_font_height+2, (255,255,0,255)) self.lowerhalf_layer.frames += [frame] self.current_letter_index = new_index # Prune down the frames list so we don't get too far behind while animating x = 0 while len(self.lowerhalf_layer.frames) > 15 and x < (len(self.lowerhalf_layer.frames)-1): del self.lowerhalf_layer.frames[x] x += 2 # Now draw the top right panel, with the selected initials in order: # self.inits_frame.clear() # init_spread = self.init_font_width + 3 # x_offset = self.inits_frame.width/2 - len(self.inits) * init_spread / 2 # for x in range(len(self.inits)): # self.init_font.draw(self.inits_frame, self.inits[x], x * init_spread + x_offset, 0) # self.inits_frame.fill_rect((len(self.inits)-1) * init_spread + x_offset, 9, 8, 1, 1) # Now draw the initials, being careful to change the display based on which option is highlighted: if(self.letters[self.current_letter_index]==self.char_back): self.inits_entry_layer.set_text(self.inits[:-2]) elif(self.letters[self.current_letter_index]==self.char_done): self.inits_entry_layer.set_text(self.inits[:-1], blink_frames = 15) else: self.inits_entry_layer.set_text(self.inits)
def __init__(self, width, height, percentage, border_width = 4, x = None, y = None, ext_color = (155,120,255), int_color = (128,25,20), bar_color = (128,255,0)): if(x is None): x = (480 - width)/2 if(y is None): y = (240 - height)/2 self.width = width self.height = height self.border_width = border_width self.ext_color = ext_color self.bar_color = bar_color self.int_color = int_color self.frame = dmd.Frame(width=width, height=height) self.frame.fill_rect(0, 0, width, height, ext_color) self.frame.fill_rect(border_width, border_width, width-(2*border_width), height-(2*border_width), int_color) self.frame.fill_rect(border_width, border_width, ((width-(2*border_width)) * percentage), height-(2*border_width), bar_color) (self.target_x_offset, self.target_y_offset) = (x,y)
def __init__(self, game, priority, left_text, right_text, entered_handler): super(HD_InitialEntryMode_ML, self).__init__(game, priority) self.entered_handler = entered_handler # self.init_font = dmd.font_named('Font09Bx7.dmd') # self.font = dmd.font_named('Font07x5.dmd') # self.letters_font = dmd.font_named('Font07x5.dmd') ## YOU almost CERTAINLY need to change these... self.init_font = self.game.fonts['large'] self.text_font = self.game.fonts['small'] self.letters_font = self.game.fonts['mono-tiny'] self.letters_font_mini = self.game.fonts['mono-micro'] self.init_font_height = self.init_font.size("Z")[1] self.text_font_height = self.text_font.size(left_text)[1] self.layer = dmd.GroupedLayer(self.display_width, self.display_height) self.layer.opaque = True self.layer.layers = [] if type(right_text) != list: right_text = [right_text] if type(left_text) != list: left_text = [left_text] seconds_per_text = 1.5 script = [] mh = 0 for text in left_text: words = text.split() h = self.text_font_height*len(words) mh = max(h, mh) frame = dmd.Frame(width=self.display_width, height=h) i = 0 for w in words: self.text_font.draw(frame, w, 0, i*self.text_font_height) i+=1 script.append({'seconds':seconds_per_text, 'layer':dmd.FrameLayer(frame=frame)}) topthird_left_layer = dmd.ScriptedLayer(width=self.display_width, height=mh, script=script) topthird_left_layer.composite_op = 'blacksrc' topthird_left_layer.target_y = self.display_height/2 - mh/2 topthird_left_layer.target_x = 10 self.layer.layers += [topthird_left_layer] script = [] mh = 0 for text in right_text: words = text.split() h = self.text_font_height*len(words) mh = max(h, mh) frame = dmd.Frame(width=self.display_width, height=h) i = 0 for w in words: self.text_font.draw(frame, w, self.display_width-(self.text_font.size(w)[0]), i*self.text_font_height) i+=1 script.append({'seconds':seconds_per_text, 'layer':dmd.FrameLayer(frame=frame)}) topthird_right_layer = dmd.ScriptedLayer(width=self.display_width, height=mh, script=script) topthird_right_layer.composite_op = 'blacksrc' topthird_right_layer.target_y = self.display_height/2 - mh/2 topthird_right_layer.target_x = -10 self.layer.layers += [topthird_right_layer] # the entered initials so far self.inits_layer = dmd.HDTextLayer(self.display_width/2, self.init_font_height/2+5, self.init_font, "center", vert_justify="center", line_color=(128,128,255), line_width=1, interior_color=(0,0,192),fill_color=(0,0,0)).set_text("") self.inits_layer.set_target_position(0, self.text_font_height+2) self.layer.layers += [self.inits_layer] self.letters = [] for idx in range(26): self.letters += [chr(ord('A')+idx)] self.letters += [' ', '.', self.char_back, self.char_done] self.current_letter_index = 0 self.inits = self.letters[self.current_letter_index] # Draw my fancy rows w = self.space_per_char*(self.columns_of_chars_in_palette+1) h = self.space_per_char*(30/self.columns_of_chars_in_palette+1.5) print("About to create a frame with w=" + str(w) + "; h=" + str(h)) self.char_optsF = dmd.Frame(width=w, height=h) for index in range(30): x = index % self.columns_of_chars_in_palette y = index / self.columns_of_chars_in_palette (w,h) = self.letters_font.size(self.letters[index]) if(index<28): self.letters_font.draw(self.char_optsF, self.letters[index], (x+1) * self.space_per_char - w/2, (y+1) * self.space_per_char - h/2) elif(index==28): (w,h) = self.letters_font_mini.size("DEL") self.letters_font_mini.draw(self.char_optsF, "DEL", (x+1) * self.space_per_char - w/2, (y+1) * self.space_per_char - h/2) elif(index==29): (w,h) = self.letters_font_mini.size("END") self.letters_font_mini.draw(self.char_optsF, "END", (x+1) * self.space_per_char - w/2, (y+1) * self.space_per_char - h/2) fbox = dmd.Frame(width=self.space_per_char+2, height=self.space_per_char+2) fbox.fill_rect(0, 0, self.space_per_char+2, self.space_per_char+2, (128,128,255)) fbox.fill_rect(2, 2, self.space_per_char-4+2, self.space_per_char-4+2, (0,64,128)) self.selection_box_layer = dmd.FrameLayer(opaque=False, frame=fbox) self.selection_box_layer.composite_op = "max" self.layer.layers += [self.selection_box_layer] self.char_opts_layer = dmd.FrameLayer(opaque=False, frame=self.char_optsF) self.char_opts_layer.set_target_position((self.display_width-(self.columns_of_chars_in_palette+1) * self.space_per_char)/2, self.init_font_height) # self.char_opts_layer.composite_op = "blacksrc" self.layer.layers += [self.char_opts_layer] self.animate_to_index(0)
def __init__(self, game, priority, left_text, right_text, entered_handler): super(HD_InitialEntryMode_ML, self).__init__(game, priority) self.entered_handler = entered_handler # self.init_font = dmd.font_named('Font09Bx7.dmd') # self.font = dmd.font_named('Font07x5.dmd') # self.letters_font = dmd.font_named('Font07x5.dmd') self.init_font = self.game.fonts['small'] self.text_font = self.game.fonts['large'] self.letters_font = self.game.fonts['med'] self.init_font_height = self.init_font.size("Z")[1] self.text_font_height = self.text_font.size("Z")[1] self.layer = dmd.GroupedLayer(480, 240) self.layer.opaque = True self.layer.layers = [] if type(right_text) != list: right_text = [right_text] if type(left_text) != list: left_text = [left_text] seconds_per_text = 1.5 script = [] for text in left_text: frame = dmd.Frame(width=450, height=self.text_font_height) self.text_font.draw(frame, text, 0, 0) script.append({'seconds':seconds_per_text, 'layer':dmd.FrameLayer(frame=frame)}) topthird_left_layer = dmd.ScriptedLayer(width=480, height=self.text_font_height, script=script) topthird_left_layer.composite_op = 'blacksrc' self.layer.layers += [topthird_left_layer] script = [] for text in right_text: frame = dmd.Frame(width=480, height=self.text_font_height) self.text_font.draw(frame, text, 480-(self.text_font.size(text)[0]), 0) script.append({'seconds':seconds_per_text, 'layer':dmd.FrameLayer(frame=frame)}) topthird_right_layer = dmd.ScriptedLayer(width=480, height=self.text_font_height, script=script) topthird_right_layer.composite_op = 'blacksrc' self.layer.layers += [topthird_right_layer] self.inits_frame = dmd.Frame(width=480, height=self.init_font_height) inits_layer = dmd.FrameLayer(opaque=False, frame=self.inits_frame) inits_layer.set_target_position(0, self.text_font_height+2) self.layer.layers += [inits_layer] self.lowerhalf_layer = dmd.FrameQueueLayer(opaque=False, hold=True) self.lowerhalf_layer.set_target_position(0, self.init_font_height+self.text_font_height) self.layer.layers += [self.lowerhalf_layer] self.letters = [] for idx in range(26): self.letters += [chr(ord('A')+idx)] self.letters += [' ', '.', self.char_back, self.char_done] self.current_letter_index = 0 self.inits = self.letters[self.current_letter_index] self.animate_to_index(0)
def __init__(self, game, priority, left_text, right_text, entered_handler, max_inits, extended=False): super(InitialEntryMode, self).__init__(game, priority) self.entered_handler = entered_handler self.init_font = self.game.assets.font_09Bx7 self.font = self.game.assets.font_07x5 self.letters_font = self.game.assets.font_07x5 self.layer = dmd.GroupedLayer(128, 32) self.layer.opaque = True self.layer.layers = [] self.knocks = 0 self.max_inits = max_inits self.extended = extended if type(right_text) != list: right_text = [right_text] if type(left_text) != list: left_text = [left_text, "MAX " + str(self.max_inits)] seconds_per_text = 1.5 script = [] for text in left_text: frame = dmd.Frame(width=128, height=8) self.font.draw(frame, text, 0, 0, color=ep.YELLOW) script.append({ 'seconds': seconds_per_text, 'layer': dmd.FrameLayer(frame=frame) }) topthird_left_layer = dmd.ScriptedLayer(width=128, height=8, script=script) topthird_left_layer.composite_op = 'blacksrc' self.layer.layers += [topthird_left_layer] script = [] for text in right_text: frame = dmd.Frame(width=128, height=8) self.font.draw(frame, text, 128 - (self.font.size(text)[0]), 0, color=ep.ORANGE) script.append({ 'seconds': seconds_per_text, 'layer': dmd.FrameLayer(frame=frame) }) if text == "Grand Champion": self.knocks += 2 elif text == 'High Score #1' or \ text == 'High Score #2' or \ text == 'High Score #3' or \ text == 'High Score #4': self.knocks += 1 topthird_right_layer = dmd.ScriptedLayer(width=128, height=8, script=script) topthird_right_layer.composite_op = 'blacksrc' self.layer.layers += [topthird_right_layer] self.inits_frame = dmd.Frame(width=128, height=10) inits_layer = dmd.FrameLayer(opaque=False, frame=self.inits_frame) inits_layer.set_target_position(0, 11) self.layer.layers += [inits_layer] self.lowerhalf_layer = dmd.FrameQueueLayer(opaque=False, hold=True) self.lowerhalf_layer.set_target_position(0, 24) self.layer.layers += [self.lowerhalf_layer] self.letters = [] for idx in range(26): self.letters += [chr(ord('A') + idx)] self.letters += [' ', '.'] if self.extended: self.letters += [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '(', ')', '@', '*', '&', '<', '>', '=', '^', '/', '-', '+', '!', '$', '"', "'" ] self.letters += [self.char_back, self.char_done] self.current_letter_index = 0 self.inits = self.letters[self.current_letter_index] self.animate_to_index(0)
def __init__(self, game, priority, left_text, right_text, entered_handler): super(HD_InitialEntryMode, self).__init__(game, priority) self.entered_handler = entered_handler self.init_font = self.game.fonts['high_score_entry_inits'] #dmd.hdfont_named('consolas', 12) self.text_font = self.game.fonts['high_score_entry_msg'] #dmd.hdfont_named('consolas', 12) self.letters_font = self.game.fonts['high_score_entry_letters'] #dmd.hdfont_named('consolas', 12) (self.init_font_width, self.init_font_height) = self.init_font.size("M") self.text_font_height = self.text_font.size("M")[1] self.letters_font_width = self.letters_font.size("M")[0] self.letters_font_height = self.letters_font.size("M")[1] # self.init_font_height = self.init_font_size[1] # self.init_font_width = self.init_font_size[0] # self.text_font_height = self.text_font.size("Z")[1] # self.letters_font_width = self.letters_font.size("Z")[0] self.layer = dmd.GroupedLayer(self.game.dmd.width, self.game.dmd.height) self.layer.opaque = True self.layer.layers = [] if type(right_text) != list: right_text = [right_text] if type(left_text) != list: left_text = [left_text] seconds_per_text = 1.5 script = [] for text in left_text: frame = dmd.Frame(width=self.game.dmd.width, height=self.text_font_height) self.text_font.draw(frame, text, 0, 0) script.append({'seconds':seconds_per_text, 'layer':dmd.FrameLayer(frame=frame)}) topthird_left_layer = dmd.ScriptedLayer(width=self.game.dmd.width, height=self.text_font_height, script=script) topthird_left_layer.composite_op = 'blacksrc' self.layer.layers += [topthird_left_layer] script = [] for text in right_text: frame = dmd.Frame(width=self.game.dmd.width, height=self.text_font_height) self.text_font.draw(frame, text, self.game.dmd.width-(self.text_font.size(text)[0]), 0) script.append({'seconds':seconds_per_text, 'layer':dmd.FrameLayer(frame=frame)}) topthird_right_layer = dmd.ScriptedLayer(width=self.game.dmd.width, height=self.text_font_height, script=script) topthird_right_layer.composite_op = 'blacksrc' self.layer.layers += [topthird_right_layer] # self.inits_frame = dmd.Frame(width=self.game.dmd.width, height=self.init_font_height) # inits_layer = dmd.FrameLayer(opaque=False, frame=self.inits_frame) # inits_layer.set_target_position(0, self.text_font_height+2) # self.layer.layers += [inits_layer] self.inits_entry_layer = dmd.HDTextLayer(self.game.dmd.width/2, self.text_font_height, self.init_font, "center", vert_justify="top", line_color=(128,128,255), line_width=0, interior_color=(0,0,255),fill_color=(0,0,0)).set_text("") self.inits_entry_layer.set_target_position(0, self.text_font_height) self.layer.layers += [self.inits_entry_layer] self.lowerhalf_layer = dmd.FrameQueueLayer(opaque=False, hold=True) self.lowerhalf_layer.set_target_position(0, self.init_font_height+self.text_font_height) self.layer.layers += [self.lowerhalf_layer] self.letters = [] for idx in range(26): self.letters += [chr(ord('A')+idx)] self.letters += [' ', '.', self.char_back, self.char_done] self.current_letter_index = 0 self.inits = self.letters[self.current_letter_index] self.animate_to_index(0)