def setup(self): global plot_size global offset global cols global rows if self.size.w <= 700 : rows = 16 self.tstart = Point(0,0) self.shaker = 0 self.finished = False self.setscore(1) self.scorepos = Point(self.bounds.w - 100, self.bounds.h - 20) self.root_layer = Layer(self.bounds) plot_size = self.size.h / (rows + 2) moverate = plot_size * 2.0 cols = int(self.size.w / plot_size - 2) offset.x = int((self.size.w - (cols * plot_size)) / 2) offset.y = int((self.size.h - (rows * plot_size)) / 2) for image in images: load_image(image) for snd in sounds : load_effect(snd) self.soldierpos = Point(cols / 2, -1) #add n rows of n columns of spots self.plots = [ [plot(Point(c, r), self) for c in xrange(cols)] for r in xrange(rows) ] self.soldier = soldier(self.soldierpos, self) self.explosion = explosion()
def setup(self): w, h = self.size.as_tuple() self.field = Rect(16, (h - w - 44) / 2 + 16, w - 32, w - 32) for effect in ['Coin_1', 'Explosion_3', 'Powerup_2']: load_effect(effect) self.load_highscore() self.new_game()
def tableview_did_select(self, tableview, section, row): # Called when the user selects a row if not tableview.editing: fi = self.lists[section][row] if section == 0: console.show_activity() nav.push_view(make_file_list(fi)) console.hide_activity() elif section == 1: filetype = fi.fileinfo.filetype if fi.fileinfo.file_ext in ("htm", "html"): webbrowser.open("file://" + fi.path) nav.close() elif filetype in ("code", "code_tags", "text"): open_path(fi.path) nav.close() elif filetype == "audio": spath = rel_to_app(fi.path.rsplit(".", 1)[0]) sound.load_effect(spath) sound.play_effect(spath) elif filetype == "image": console.show_image(fi.path) else: console.quicklook(fi.path) nav.close()
def __init__(self, path): self.__path = system.getSystemPath(path) try: open(self.__path).close() sound.load_effect(self.__path) except IOError: raise error.SourceNotFoundError(path)
def setup(self): self.white_keys = [] self.black_keys = [] white_key_names = ['Piano_C3', 'Piano_D3', 'Piano_E3', 'Piano_F3', 'Piano_G3', 'Piano_A3', 'Piano_B3', 'Piano_C4'] black_key_names = ['Piano_C3#', 'Piano_D3#', 'Piano_F3#', 'Piano_G3#', 'Piano_A3#'] for key_name in chain(white_key_names, black_key_names): sound.load_effect(key_name) white_positions = range(8) black_positions = [0.5, 1.5, 3.5, 4.5, 5.5] key_w = self.size.w key_h = self.size.h / 8 for i in range(len(white_key_names)): pos = white_positions[i] key = Key(Rect(0, pos * key_h, key_w, key_h)) key.name = white_key_names[i] self.white_keys.append(key) for i in range(len(black_key_names)): pos = black_positions[i] key = Key(Rect(0, pos * key_h + 10, key_w * 0.6, key_h - 20)) key.name = black_key_names[i] key.color = Color(0, 0, 0) key.highlight_color = Color(0.2, 0.2, 0.2) self.black_keys.append(key)
def tableview_did_select(self, tableview, section, row): u"""Called when the user selects a row. """ if not tableview.editing: fi = self.lists[section][row] if section == 0: console.show_activity("Loading file list...") self.app.push_view(self.app.make_file_list(fi)) console.hide_activity() elif section == 1: group = fi.constants.group if fi.constants.ext in (u"htm", u"html"): webbrowser.open(u"file://" + fi.path) self.app.close() elif group in ("code", "code_tags", "text"): open_path(fi.path) self.app.close() elif group == "audio": spath = rel_to_app(fi.path.rsplit(u".", 1)[0]) sound.load_effect(spath) sound.play_effect(spath) elif group == "image": console.show_image(fi.path) else: self.app.close() time.sleep(ANIM_DELAY) console.quicklook(fi.path)
def tableview_did_select(self, tableview, section, row): u"""Called when the user selects a row. """ if not tableview.editing: fi = self.lists[section][row] if section == 0: console.show_activity() self.app.push_view(self.app.make_file_list(fi)) console.hide_activity() elif section == 1: group = fi.constants.group if fi.constants.ext in (u"htm", u"html"): webbrowser.open(u"file://" + fi.path) self.app.close() elif group in ("code", "code_tags", "text"): open_path(fi.path) self.app.close() elif group == "audio": spath = rel_to_app(fi.path.rsplit(u".", 1)[0]) sound.load_effect(spath) sound.play_effect(spath) elif group == "image": console.show_image(fi.path) else: self.app.close() time.sleep(ANIM_DELAY) console.quicklook(fi.path)
def setup(self): self.white_keys = [] self.black_keys = [] white_key_names = [ "weier3.wav", "weier5.wav", "weier7.wav", "weier8.wav", "weier10.wav", "weier0.wav", "weier2.wav", ] black_key_names = ["weier4.wav", "weier6.wav", "weier9.wav", "weier11.wav", "weier1.wav"] for key_name in chain(white_key_names, black_key_names): sound.load_effect(key_name) white_positions = range(7) black_positions = [0.5, 1.5, 3.5, 4.5, 5.5] key_w = self.size.w / 7 key_h = self.size.h for i in range(len(white_key_names)): pos = white_positions[i] key = Key(Rect(pos * key_w, 0, key_w, key_h)) key.name = white_key_names[i] self.white_keys.append(key) for i in range(len(black_key_names)): pos = black_positions[i] key = Key(Rect(pos * key_w + 10, key_h * 0.4, key_w - 20, key_h)) key.name = black_key_names[i] key.color = Color(0, 0, 0) key.highlight_color = Color(0.2, 0.2, 0.2) self.black_keys.append(key)
def setup(self): self.white_keys = [] self.black_keys = [] white_key_names = [ 'Piano_C3', 'Piano_D3', 'Piano_E3', 'Piano_F3', 'Piano_G3', 'Piano_A3', 'Piano_B3', 'Piano_C4' ] black_key_names = [ 'Piano_C3#', 'Piano_D3#', 'Piano_F3#', 'Piano_G3#', 'Piano_A3#' ] for key_name in chain(white_key_names, black_key_names): sound.load_effect(key_name) white_positions = range(8) black_positions = [0.5, 1.5, 3.5, 4.5, 5.5] key_w = self.size.w key_h = self.size.h / 8 for i in range(len(white_key_names)): pos = white_positions[i] key = Key(Rect(0, pos * key_h, key_w, key_h)) key.name = white_key_names[i] self.white_keys.append(key) for i in range(len(black_key_names)): pos = black_positions[i] key = Key(Rect(0, pos * key_h + 10, key_w * 0.6, key_h - 20)) key.name = black_key_names[i] key.color = Color(0, 0, 0) key.highlight_color = Color(0.2, 0.2, 0.2) self.black_keys.append(key)
def setup(self): sound.load_effect('Beep') sound.set_volume(1.0) self.alarm_timer = 0 self.bg_red = True self.timer = 180 self.start_time = 0.0 self.running = False self.dt = 0.0 self.alert = False # gesture recognition self.gesture = Gesture.TAP self.start_touches = {} self.touch_count = {} #Render all the digits as individual images: self.numbers = {} font_size = 200 if self.size.w > 700 else 100 for s in chain(string.digits, [':', '.']): #render_text returns a tuple of #an image name and its size. self.numbers[s] = render_text(s, 'Helvetica-Bold', font_size)
def setup(self): sound.load_effect('beep1.ogg') self.label = scene.LabelNode( "Hello World", font_name='Times New Roman', color=(255, 0, 0, 255), parent=self)
def setup(self): self.loaded = False with shelve.open('100TapsSave') as save: if 'Highscores' not in save: save['Highscores'] = {'Classic': None, 'Timed': 0, 'Speed': 0} self.highscores = save['Highscores'] self.startTime = 0 self.taps = 0 self.state = 'Menu' self.click_sound = '' load_effect(self.click_sound) self.loaded = True self.ipad = self.size.w > 400 self.f = 'Arial' self.s = 40 self.titleF = 'Futura' self.titleS = 50 self.smallS = 30 if self.ipad: self.s *= 1.5 self.titleS *= 1.5 self.smallS *= 1.5
def setup(self): global plot_size global offset global cols global rows if self.size.w <= 700: rows = 16 self.tstart = Point(0, 0) self.shaker = 0 self.finished = False self.setscore(1) self.scorepos = Point(self.bounds.w - 100, self.bounds.h - 20) self.root_layer = Layer(self.bounds) plot_size = self.size.h / (rows + 2) moverate = plot_size * 2.0 cols = int(self.size.w / plot_size - 2) offset.x = int((self.size.w - (cols * plot_size)) / 2) offset.y = int((self.size.h - (rows * plot_size)) / 2) for image in images: load_image(image) for snd in sounds: load_effect(snd) self.soldierpos = Point(cols / 2, -1) #add n rows of n columns of spots self.plots = [[plot(Point(c, r), self) for c in xrange(cols)] for r in xrange(rows)] self.soldier = soldier(self.soldierpos, self) self.explosion = explosion()
def setup(self): self.start_time = 0.0 self.intro = 5 self.stop_time = 0.0 self.last_seconds = 0 self.running = False for effect in ['Click_1', 'Click_2','Boing_1','Beep']: sound.load_effect(effect)
def __init__(self, x, y, w, h, bgcolour, slcolour, drum): self.size = Size(w, h) self.bounds = Rect(x, y, w, h) self.bg = bgcolour # Default background colour self.sl = slcolour # Background colour when selected self.state = 0 self.drum = drum sound.load_effect(self.drum)
def tableview_did_select(self, tableview, section, row): u"""Called when the user selects a row. """ key = self.lists[section][1][row][0] if key == "ios.quick_look": # Preview - Quick Look self.app.close() time.sleep(ANIM_DELAY) console.quicklook(self.fi.path) elif key == "editor.edit": # Open in Editor - editor open_path(self.fi.path) self.app.close() elif key == "editor.copy_edit": # Copy & Open - editor destdir = full_path( os.path.join(full_path(u"~"), u"Documents/temp")) if not os.path.exists(destdir): os.mkdir(destdir) destfile = full_path( os.path.join(destdir, self.fi.basename().lstrip(u"."))) shutil.copy(self.fi.path, destfile) editor.reload_files() open_path(destfile) self.app.close() elif key == "editor.copy_edit_txt": # Copy & Open as Text - editor destdir = full_path( os.path.join(full_path(u"~"), u"Documents/temp")) if not os.path.exists(destdir): os.mkdir(destdir) destfile = full_path( os.path.join(destdir, self.fi.basename().lstrip(u".") + u".txt")) shutil.copy(self.fi.path, destfile) editor.reload_files() open_path(destfile) self.app.close() elif key == "console.print_image": # Show in Console - console console.show_image(self.fi.path) elif key == "sound.play_sound": # Play Sound - sound spath = rel_to_app(self.fi.path.rsplit(u".", 1)[0]) sound.load_effect(spath) sound.play_effect(spath) elif key == "webbrowser.open": # Open Website - webbrowser webbrowser.open(u"file://" + self.fi.path) self.app.close() elif key == "ios.open_in": # Open In - External Apps if console.open_in(self.fi.path): self.app.close() else: console.hud_alert(u"Failed to Open", "error")
def setup(self): for effect in ('Click_1', 'Woosh_1', 'Woosh_2', 'Coin_4'): sound.load_effect(effect) for i in IMAGES: load_image(i) load_image(SEL_IMAGE) self.root_layer = Layer(self.bounds) self.effectsLayer = Layer(self.bounds) self.newGame(4, 4, 5)
def setup(self): global CurrentPosition global Hint global CurrentHintID global CurrentHint global hintImage global photoImage global gameState # This will be called before the first frame is drawn. sound.load_effect('8ve-beep-hightone') if not isEditor: loadCurrentGameHint() pass
def setup(self): # This will be called before the first frame is drawn. self.flapper = Flapper(10.0, 300.0, 50, 50, 1.0, 0.0, 0.0, 1.0) self.flapper.secondaryInit(Vec2(6.0, 0.0)) self.walls = [] self.goals = [] self.deathparticles = [] self.ticks = 0 self.points = 0 self.deadtime = 0.0 self.gamestate = "play" sound.load_effect('Jump') sound.load_effect('Clank')
def setup(self): #Use different sizes on iPad and iPhone: global tile_size, cols, rows ipad = self.is_iPad() # self.size.w > 700 tile_size = 64 if ipad else 40 cols = 12 if ipad else 8 rows = 12 if ipad else 10 if not ipad and self.size.h > 480: rows += 2 #iPhone 5 #Preload some sound effects to reduce latency: for sound_effect in ['Click_1', 'Error', 'Coin_3']: load_effect(sound_effect) self.new_game()
def setup(self): #Use different sizes on iPad and iPhone: global tile_size, cols, rows ipad = self.size.w > 700 tile_size = 64 if ipad else 40 cols = 12 if ipad else 8 rows = 12 if ipad else 10 if not ipad and self.size.h > 480: rows += 2 #iPhone 5 #Preload some sound effects to reduce latency: for sound_effect in ['Click_1', 'Error', 'Coin_3']: load_effect(sound_effect) self.new_game()
def tableview_did_select(self, tableview, section, row): u"""Called when the user selects a row. """ key = self.lists[section][1][row][0] if key == "ios.quick_look": # Preview - Quick Look self.app.close() time.sleep(ANIM_DELAY) console.quicklook(self.fi.path) elif key == "editor.edit": # Open in Editor - editor open_path(self.fi.path) self.app.close() elif key == "editor.copy_edit": # Copy & Open - editor destdir = full_path(os.path.join(full_path(u"~"), u"Documents/temp")) if not os.path.exists(destdir): os.mkdir(destdir) destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip(u"."))) shutil.copy(self.fi.path, destfile) editor.reload_files() open_path(destfile) self.app.close() elif key == "editor.copy_edit_txt": # Copy & Open as Text - editor destdir = full_path(os.path.join(full_path(u"~"), u"Documents/temp")) if not os.path.exists(destdir): os.mkdir(destdir) destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip(u".") + u".txt")) shutil.copy(self.fi.path, destfile) editor.reload_files() open_path(destfile) self.app.close() elif key == "console.print_image": # Show in Console - console console.show_image(self.fi.path) elif key == "sound.play_sound": # Play Sound - sound spath = rel_to_app(self.fi.path.rsplit(u".", 1)[0]) sound.load_effect(spath) sound.play_effect(spath) elif key == "webbrowser.open": # Open Website - webbrowser webbrowser.open(u"file://" + self.fi.path) self.app.close() elif key == "ios.open_in": # Open In - External Apps if console.open_in(self.fi.path): self.app.close() else: console.hud_alert(u"Failed to Open", "error")
def setup(self): self.beat = 0.0 set_volume(1.0) self.sounds = ['Drums_01', 'Drums_02', 'Drums_03', 'Drums_06', 'Drums_10', 'Drums_11', 'Drums_11', 'Drums_15'] for effect in self.sounds: load_effect(effect) try: with open('Drums.data', 'r') as f: self.grid = pickle.load(f) except EOFError: self.grid = [[False for col in range(16)] for row in range(8)]
def setup(self): self.beat = 0.0 set_volume(1.0) self.sounds = ['Drums_01', 'Drums_02', 'Drums_03', 'Drums_06', 'Drums_10', 'Drums_11', 'Drums_11', 'Drums_15'] for effect in self.sounds: load_effect(effect) try: with open('Drums.data', 'r') as f: self.grid = pickle.load(f) except EOFError: self.grid = [[False for col in xrange(16)] for row in xrange(8)]
def touch_moved(self, touch): #print(touch.location[0]) sound.load_effect('ui:click3') dx = -(self.initialPos[1] - touch.location[1]) Dt = 100 dt = 10 if abs(dx) > 20: taptic_peek() sound.play_effect('ui:click4') self.initialPos = touch.location if dx > 0: self.counter += 1 else: self.counter -= 1
def __init__(self,timelimit=60*60): compressedui = '''\ QlpoOTFBWSZTWUc9NZEAAyzfgFUQUGd/9T+E3Qq/r976QAL8wYDa1TCSQIZMptTU9U9T1A A0xGTQAA9IESJSm9KYyjI0B6gHqfqmmg0ZAbSaBzTEwAJgAmAAEwABMEUo1MU2INIaeoAA AABoBpXQDYpCgnMlgf2mycngJQSSASdLEzlBE5ICGEGigpRUClAG9AcCEJCOSCFKfaGiDh SsfT89nQ2zcEg7mdbgkZNxVIFjoWDp1dnjaTI1uRycNb7nnbm6zJ2+GcDwENYpsTVsTYQs jG7KAq2mEMMSkuwJSUW4hREinC29Pg1yR0haUlpFTbJAfX57Ye3OtskxEvGlTtjiG/o5O1 y81U2oR68XN1cHU6FvutEzMm/AyR01Pa1mGUPZ0Mw5JEJpFNMKIa138TPQzFWCJsSK2OyA 4HOW09a8cJT3yMr5jxDYXpkIyiSpoz7PudZRMPhnrQdFRcUkjIzUeFoBjuxhhVt5Pg/HcO wNGq04b69+xCsnEVEmieM6Y4ak91LUOZ2kIQ0fqgQPX8ULqlLasbsYz1tKzYU5pRn2rDO9 Q2rXbPdptKEJ0aD4VxleN50jnWw+ON2hltb5LIXqDxDl707pG9cQj4Bejn50dsursYDwHp 0VkiHnSQFKlqkhgSNCx9DNMp8OUbMJS729xDWYaYSI/5IXHo/sCVoMEHUkRDjGgCdxUOkS 5ZDiqmYM6UgmNxH6UvdcWiOU1yRmLRHdtUTOSOR/gJFiQtrri8yVzCTMKFw52QyvaUu/gr ZxwNVIH2GoNpoojgqBqtzzagE1RIwSHRFmxqkRBZIwAyJlUvcb+NjMhYZBrcw4W+JEFx7G QJyBwFAWjcTJhzD1BUma8ICoTS2pWfKQmhiQCDkpfsTbjcpgP3zM+tE+ZcE/4u5IpwoSCO emsiA= ''' pyui = bz2.decompress(b64decode(compressedui)) v = ui.load_view_str(pyui.decode('utf-8')) self.v = v self.v.present('sheet') self.timelimit=timelimit self.startTime = time.time() self.gameBegun = False self.playerOne = self.v["playerOne"] self.playerTwo = self.v["playerTwo"] self.playerOne.tint_color='green' self.playerTwo.tint_color='green' self.playerOne.sound='casino:ChipsStack3' self.playerTwo.sound='casino:ChipsStack6' self.playerOne.border_width=1 self.playerTwo.border_width=1 self.playerOne.height=44 self.playerTwo.height=44 self.playerOne.opponentTimeElapsed = 0 self.playerTwo.opponentTimeElapsed = 0 self.playerOne.latestTurnElapsed = 0 self.playerTwo.latestTurnElapsed = 0 self.playerOne.currentOppTime=0 self.playerTwo.currentOppTime=0 self.lastPlayerToTap = "NOBODY" self.lastTimeToggled=self.startTime sound.load_effect(self.playerOne.sound) sound.load_effect(self.playerTwo.sound) self.mainLoop()
def setup(self): self.string_keys = [[], [], [], []] self.string_buttom = [[], [], [], []] self.string_base = [ key_names_piano[9], key_names_piano[4], key_names_piano[0], key_names_piano[7] ] self.string_toplay = [ key_names_piano[9], key_names_piano[4], key_names_piano[0], key_names_piano[7] ] # 此处可以修改成4根琴弦 each_string_key_number = 8 string4_key_names = set_string_key_names(7, each_string_key_number) string3_key_names = set_string_key_names(0, each_string_key_number) string2_key_names = set_string_key_names(4, each_string_key_number) string1_key_names = set_string_key_names(9, each_string_key_number) string_key_names = [ string1_key_names, string2_key_names, string3_key_names, string4_key_names ] key_w = self.size.w / 12 key_h = self.size.h / (each_string_key_number + 2) string_key_positions = range(each_string_key_number, 0, -1) for i in range(4): for j in range(each_string_key_number): pos = string_key_positions[j] key = Key( Rect(self.size.w - (i + 1) * key_w, (pos + 1) * key_h, key_w, key_h)) key.name = string_key_names[i][j] self.string_keys[i].append(key) sound.load_effect(key.name) key_buttom = Key( Rect(self.size.w - (i + 1) * key_w, 0, key_w, key_h)) key_buttom.color = [0, 0, 1] self.string_buttom[i].append(key_buttom)
def __init__(self, scene): self.health = 12 self.images = { 12: 'Clock_12', 11: 'Clock_11', 10: 'Clock_10', 9: 'Clock_9', 8: 'Clock_8', 7: 'Clock_7', 6: 'Clock_6', 5: 'Clock_5', 4: 'Clock_4', 3: 'Clock_3', 2: 'Clock_2', 1: 'Clock_1' } self.layer = Layer(Rect(0, 0, 96, 96)) self.layer.image = self.images[self.health] scene.root_layer.add_layer(self.layer) sound.load_effect('Clank')
def setup(self): self.white_keys = [] self.black_keys = [] self.all_keys = [] r=0.49*min(self.size.w, self.size.h) key_textures = [Texture(img) for img in make_key_images(0.5*r,r,scale=1.0)] key_names = ['weier%d.wav'%i for i in range(12)] for key_name in key_names: sound.load_effect(key_name) white_positions = [3,5,7,8,10,0,2]#0=A black_positions = [ 4,6, 9,11,1] for i in range(12): ang=pi/6*(6+i) texture_index=0 if i in white_positions else 2 key=Key(SpriteNode(key_textures[texture_index],scale=1.0,position=(self.size.w/2+cos(ang)*0.75*r,self.size.h/2+sin(ang)*0.75*r))) key.node.rotation=ang [key.texture, key.highlight_texture] = key_textures[texture_index:texture_index+2] key.name=key_names[i] self.all_keys.append(key) for i in chain(white_positions,black_positions): key=self.all_keys[i] self.add_child(key.node) self.white_keys.append(key)
with open(file_name) as f: for line in f.readlines(): if line.istitle(): player_name = line if not player_name: player_name = console.input_alert('What is your name? ').title() if player_name: with open(file_name, 'w') as f: f.write(player_name) return player_name or 'default' player_name = get_username() # to reduce latency, preload sound effects for s in 'Boing_1 Crashing Powerup_1'.split(): sound.load_effect(s) def tinted_text(s, x, y, tint_color = scene.Color(0, 0, 1)): scene.tint(0, 0, 0) scene.text(s, GAME_FONT, 48, x + 2, y - 2) scene.tint(*tint_color) scene.text(s, GAME_FONT, 48, x, y) def shadow_text(s, x, y): tinted_text(s, x, y, scene.Color(0.0, 0.5, 1.0)) def score_text(s, x, y): tinted_text(s, x, y, scene.Color(1.0, 1.0, 0.4)) class Sprite(scene.Layer): def __init__(self, rect = scene.Rect(), parent = None, image_name = 'PC_Grass_Block'):
def setup(self): self.loaded = False self.sound = 'Coin_3' load_effect(self.sound) self.animationLength = 6 self.soundInterval = 1 self.gameStartTime = time.time() self.isBackgroundBroken = False self.isDistanceBroken = False self.isSoundBroken = False self.diagonal = abs(Point(self.size.w, self.size.h) - Point(0, 0)) self.distance = self.diagonal self.titleF = 'AvenirNext-Heavy' self.titleS = 65 self.f = 'Futura' self.s = 40 self.instrF = 'Arial' self.instrS = 20 self.gameModeF = 'AppleColorEmoji' self.ipad = self.size.w > 400 if self.ipad: self.titleS *= 1.5 self.s *= 1.5 self.instrS *= 1.5 self.goodItems = [ 'bubble', 'shell', 'fish', 'key', 'blowfish', 'tropical fish', 'octopus', 'dolphin', 'whale' ] self.badItems = ['monster', 'shoe', 'bomb', 'poo', 'toilet', 'cactus'] self.itemsList = self.goodItems + self.badItems self.requirements = { 'Easy': ('key', 0), # Easy is unlocked by default 'Medium': ('bubble', 1), 'Hard': ('shell', 5), 'Expert': ('fish', 10), 'Sound': ('key', 1), 'Colour': ('blowfish', 15), 'Distance': ('tropical fish', 20), 'SoundColour': ('octopus', 25), 'SoundDistance': ('dolphin', 35), 'ColourDistance': ('whale', 50) } with shelve.open('SonarSave') as save: if 'Items' in save: self.items = save['Items'] self.highscores = save['Highscores'] else: self.items = {} for item in self.itemsList: self.items[item] = 0 self.highscores = [None for i in range(4) ] # Easy medium, hard, expert self.goToMenu() self.loaded = True
def setup(self): self.kenny = Character(self.size.w/2, self.size.h/2, 1) load_effect('Footstep') load_image('Boy') self.bg_color = Color(0, 0, 0) self.score = Score()
def setup(self): # pre-load sounds sound.load_effect('Laser_1') sound.load_effect('Explosion_2') sound.load_effect('Explosion_4') sound.load_effect('Laser_6') # main layer self.layer = Layer(Rect(0, 0, screen_size.w, screen_size.h)) # score self.score = 0 # ship sprite self.ship = Layer(Rect((screen_size.w / 2) - 50, (screen_size.h / 20) * 2, (100 * screen_factor), (100 * screen_factor))) self.ship.image = 'Red_Triangle_1' self.ship.alpha = 1.0 self.ship.blendmode = BLEND_ADD self.layer.add_layer(self.ship) # ship's laser sprite self.laser = Layer(Rect((screen_size.w / 2) - 3, (screen_size.h / 20) * 4, 6 * screen_factor, 20 * screen_factor)) self.laser.background = Color(1,1,1,1) self.laser.alpha = 0 self.layer.add_layer(self.laser) # firing - is player currently firing? self.firing = False # space monster self.space_monster = [] self.space_monster_move_x = [] self.space_monster_laser = [] self.space_monster_firing =[] self.space_monster_fire_rate = 400 self.space_monster_max_speed = 2 for i in range(5): # space monster sprite space_monster = Layer(Rect(0, (screen_size.h / 9) * (2+(5-i)), (100 * screen_factor), (100 * screen_factor))) space_monster.image = 'Alien_Monster' space_monster.alpha = 0 space_monster.blendmode = BLEND_ADD self.space_monster.append(space_monster) self.layer.add_layer(self.space_monster[i]) # move x is current movement on x axis self.space_monster_move_x.append(randint(-3, 3)) # don't stop moving if(self.space_monster_move_x[i] == 0): self.space_monster_move_x[i] = 1 # space monster laser space_monster_laser = Layer(Rect(0, 0, 6 * screen_factor, 20 * screen_factor)) space_monster_laser.background = Color(1,1,1,1) space_monster_laser.alpha = 0 self.space_monster_laser.append(space_monster_laser) self.layer.add_layer(self.space_monster_laser[i]) self.space_monster_firing.append(False)
def setup(self): self.root_layer = Layer(self.bounds) for effect in ['Click_1', 'Click_2', 'Coin_2', 'Coin_5']: sound.load_effect(effect) self.deal()
def setup(self): # pre-load sounds sound.load_effect('Laser_1') sound.load_effect('Explosion_2') sound.load_effect('Explosion_4') sound.load_effect('Laser_6') # main layer self.layer = Layer(Rect(0, 0, screen_size.w, screen_size.h)) # score self.score = 0 # ship sprite self.ship = Layer( Rect((screen_size.w / 2) - 50, (screen_size.h / 20) * 2, (100 * screen_factor), (100 * screen_factor))) self.ship.image = 'Red_Triangle_1' self.ship.alpha = 1.0 self.ship.blendmode = BLEND_ADD self.layer.add_layer(self.ship) # ship's laser sprite self.laser = Layer( Rect((screen_size.w / 2) - 3, (screen_size.h / 20) * 4, 6 * screen_factor, 20 * screen_factor)) self.laser.background = Color(1, 1, 1, 1) self.laser.alpha = 0 self.layer.add_layer(self.laser) # firing - is player currently firing? self.firing = False # space monster self.space_monster = [] self.space_monster_move_x = [] self.space_monster_laser = [] self.space_monster_firing = [] self.space_monster_fire_rate = 400 self.space_monster_max_speed = 2 for i in range(5): # space monster sprite space_monster = Layer( Rect(0, (screen_size.h / 9) * (2 + (5 - i)), (100 * screen_factor), (100 * screen_factor))) space_monster.image = 'Alien_Monster' space_monster.alpha = 0 space_monster.blendmode = BLEND_ADD self.space_monster.append(space_monster) self.layer.add_layer(self.space_monster[i]) # move x is current movement on x axis self.space_monster_move_x.append(randint(-3, 3)) # don't stop moving if (self.space_monster_move_x[i] == 0): self.space_monster_move_x[i] = 1 # space monster laser space_monster_laser = Layer( Rect(0, 0, 6 * screen_factor, 20 * screen_factor)) space_monster_laser.background = Color(1, 1, 1, 1) space_monster_laser.alpha = 0 self.space_monster_laser.append(space_monster_laser) self.layer.add_layer(self.space_monster_laser[i]) self.space_monster_firing.append(False)
def tableview_did_select(self, tableview, section, row): # Called when the user selects a row key = self.lists[section][1][row][0] if key == "shellista-cd": # Go Here - Shellista nav.close() print("Launching Shellista...") try: from Shellista import Shell except ImportError as err: print("Failed to import Shellista: " + err.message) print("See note on Shellista integration at the top of filenav.py.") print("> logout") return shell = Shell() shell.prompt = '> ' shell.onecmd("cd " + self.fi.path) print("> cd " + self.fi.path) shell.cmdloop() elif key == "ios-qlook": # Preview - Quick Look nav.close() time.sleep(1) # ui thread will hang otherwise console.quicklook(self.fi.path) elif key == "pysta-edit": # Open in Editor - Pythonista open_path(self.fi.path) nav.close() elif key == "pysta-cpedit": # Copy & Open - Pythonista destdir = full_path(os.path.join(SCRIPT_ROOT, "temp")) if not os.path.exists(destdir): os.mkdir(destdir) destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip("."))) shutil.copy(self.fi.path, destfile) editor.reload_files() open_path(destfile) nav.close() elif key == "pysta-cptxt": # Copy & Open as Text - Pythonista destdir = full_path(os.path.join(SCRIPT_ROOT, "temp")) if not os.path.exists(destdir): os.mkdir(destdir) destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip(".") + ".txt")) shutil.copy(self.fi.path, destfile) editor.reload_files() open_path(destfile) nav.close() elif key == "console-printimg": # Show in Console - console console.show_image(self.fi.path) elif key == "sound-playsound": # Play Sound - sound spath = rel_to_app(self.fi.path.rsplit(".", 1)[0]) sound.load_effect(spath) sound.play_effect(spath) elif key == "webbrowser-open": # Open Website - webbrowser webbrowser.open("file://" + self.fi.path) nav.close() elif key == "ios-openin": # Open In - External Apps if console.open_in(self.fi.path): nav.close() else: console.hud_alert("Failed to Open", "error")
def load_effect(self, name): soundOrig.load_effect(name)
# https://gist.github.com/freekrai/4197073 import console console.show_activity() import urllib from urllib import urlencode import bs4 import requests import webbrowser import sys import sound sound.load_effect('Powerup_2') import keychain import clipboard console.hide_activity() numArgs = len(sys.argv) if numArgs < 2: url = clipboard.get() console.show_activity() soup = bs4.BeautifulSoup(urllib.urlopen(url)) title = soup.title.string text = title.encode('utf-8') console.hide_activity() else:
for line in text_file: if line.istitle(): player_name = line else: player_name = console.input_alert('What is your name? ').title() text_file = open("names.json", "w") text_file.write(player_name) text_file.close() else: player_name = console.input_alert('What is your name? ').title() text_file = open("names.json", "w") text_file.write(player_name) text_file.close() # to reduce latency, preload effects in load_effect('Boing_1') load_effect('Crashing') class Player(object): def __init__(self): self.bounds = Rect() self.velocity = 0 def draw(self): tint(1,1,1) image('Alien', self.bounds.x, self.bounds.y + IMAGE_Y_OFFSET) class GroundBlock(object): def __init__(self): self.bounds = Rect()
#http://trekcore.com/audio/warp/tng_warp4_clean.mp3 #http://trekcore.com/audio/warp/tng_warp_out4.mp3 import requests, sound, ui #download sound effects from the web url_fmt = 'http://trekcore.com/audio/warp/{}.mp3' filenames = 'tng_warp_out4.caf tng_warp4_clean.caf'.split() for filename in filenames: with open(filename, 'wb') as out_file: url = url_fmt.format(filename.rstrip('.caf')) out_file.write(requests.get(url).content) sound.load_effect(filename) def warp_action(sender): sound.play_effect(filenames[sender.value]) sw = ui.Switch() sw.action = warp_action view = ui.View(name = 'Captain Picard Wants Warp Speed') view.add_subview(sw) view.present() sw.center = view.center
import console console.show_activity() import urllib from urllib import urlencode import bs4 import requests import webbrowser import sys import sound sound.load_effect('Powerup_2') import keychain import clipboard console.hide_activity() numArgs = len(sys.argv) if numArgs < 2: url = clipboard.get() console.show_activity() soup = bs4.BeautifulSoup(urllib.urlopen(url)) title = soup.title.string text = title.encode('utf-8') console.hide_activity() else: text = sys.argv[1] url = sys.argv[2]
import sound, time for effect in ['Click_1', 'Click_2', 'Coin_2', 'Coin_5','Piano_G4#','Woosh_2','Woosh_1','Spaceship','Shot','Pulley','Jump','Footstep','Footstep','Footstep','Error','Ding_1','Ding_2','Ding_3','Crashing','Drums_16','Drums_15','Drums_14','Drums_13','Drums_13','Drums_13','Coin_1','Coin_2','Coin_3','Coin_4','Coin_5','Explosion_1','Explosion_2','Explosion_3','Explosion_4','Explosion_5','Explosion_6','Explosion_7','Hit_1','Hit_2','Hit_3','Hit_4','Jump_1','Jump_2','Jump_3','Jump_4','Jump_5','Laser_1','Laser_2','Laser_3','Laser_4','Laser_5','Laser_6','Powerup_1','Powerup_2','Powerup_3','Piano_G4#']: sound.load_effect(effect) sound.play_effect(effect) time.sleep(0.5) notes = 'C3', 'D3', 'E3', 'C3' for note in notes: sound.play_effect('Piano_' + note) time.sleep(0.5)
from scene import * from tile import Tile, getTileSize from settings import data from button import TextButton import sound import random sound.load_effect("Click_1") class PuzzleScene(Scene): # For use with pcista _pgwindowtitle = "Slide Puzzle (NOT SUPPORTED YET)" def setup(self): self.tsize = getTileSize(self.size) tsx, tsy = data.dtilesize pos = Point(data.pstart.x - (data.pbwidth + tsx/2), data.pstart.y - (data.boardsize[1] * tsy + data.pbwidth - tsy/2)) size = Size(data.boardsize[0] * tsx + data.pbwidth * 2, data.boardsize[1] * tsy + data.pbwidth * 2) self.pbbounds = Rect(pos.x, pos.y, *size) self.board = self.generateBoard(data.boardsize[0], data.boardsize[1], data.pstart, data.dtilesize) self.animated_tile = None self.button = TextButton( "Shuffle", Point(550, 780),
def setup(self): self.kenny = Character(self.size.w / 2, self.size.h / 2, 1) load_effect('Footstep') load_image('Boy') self.bg_color = Color(0, 0, 0) self.score = Score()
# http://www.macstories.net/links/quickly-email-a-picture-on-ios-using-pythonista/ # http://6d1f0d2e5a9f9c27cec8-28b934f7b0292a7dfd0ff5946ebc82f1.r53.cf1.rackcdn.com/2012-11-14_221033-ImageMail.py # Example for sending an email with an attached image using smtplib # # IMPORTANT: You need to enter your email login in the main() function. # The example is prepared for GMail, but other providers # should be possible by changing the mail server. import smtplib import sound sound.load_effect('Bleep') from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart from email import encoders import Image import clipboard import console import keychain from io import BytesIO def get_attachment(img): bytes = BytesIO() img.save(bytes, format='JPEG') msg = MIMEBase('image', 'jpeg') msg.set_payload(bytes.getvalue()) encoders.encode_base64(msg) msg.add_header('Content-Disposition', 'attachment', filename='image.jpeg') return msg
#http://trekcore.com/audio/warp/tng_warp4_clean.mp3 #http://trekcore.com/audio/warp/tng_warp_out4.mp3 import requests, sound, ui #download sound effects from the web url_fmt = 'http://trekcore.com/audio/warp/{}.mp3' filenames = 'tng_warp_out4.caf tng_warp4_clean.caf'.split() for filename in filenames: with open(filename, 'w') as out_file: url = url_fmt.format(filename.rstrip('.caf')) out_file.write(requests.get(url).content) sound.load_effect(filename) def warp_action(sender): sound.play_effect(filenames[sender.value]) sw = ui.Switch() sw.action = warp_action view = ui.View(name='Captain Picard Wants Warp Speed') view.add_subview(sw) view.present() sw.center = view.center
def tableview_did_select(self, tableview, section, row): # Called when the user selects a row key = self.lists[section][1][row][0] if key == "shellista-cd": # Go Here - Shellista nav.close() print("Launching Shellista...") try: from Shellista import Shell except ImportError as err: print("Failed to import Shellista: " + err.message) print("See note on Shellista integration at the top of filenav.py.") print("> logout") return shell = Shell() shell.prompt = "> " shell.onecmd("cd " + self.fi.path) print("> cd " + self.fi.path) shell.cmdloop() elif key == "ios-qlook": # Preview - Quick Look nav.close() time.sleep(1) # ui thread will hang otherwise console.quicklook(self.fi.path) elif key == "pysta-edit": # Open in Editor - Pythonista open_path(self.fi.path) nav.close() elif key == "pysta-cpedit": # Copy & Open - Pythonista destdir = full_path(os.path.join(SCRIPT_ROOT, "temp")) if not os.path.exists(destdir): os.mkdir(destdir) destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip("."))) shutil.copy(self.fi.path, destfile) editor.reload_files() open_path(destfile) nav.close() elif key == "pysta-cptxt": # Copy & Open as Text - Pythonista destdir = full_path(os.path.join(SCRIPT_ROOT, "temp")) if not os.path.exists(destdir): os.mkdir(destdir) destfile = full_path(os.path.join(destdir, self.fi.basename().lstrip(".") + ".txt")) shutil.copy(self.fi.path, destfile) editor.reload_files() open_path(destfile) nav.close() elif key == "console-printimg": # Show in Console - console console.show_image(self.fi.path) elif key == "sound-playsound": # Play Sound - sound spath = rel_to_app(self.fi.path.rsplit(".", 1)[0]) sound.load_effect(spath) sound.play_effect(spath) elif key == "webbrowser-open": # Open Website - webbrowser webbrowser.open("file://" + self.fi.path) nav.close() elif key == "ios-openin": # Open In - External Apps if console.open_in(self.fi.path): nav.close() else: console.hud_alert("Failed to Open", "error")
def setup(self): self.state = 'Menu' self.maxSpeed = 60 with shelve.open('TapDefenseSave') as save: if 'Highscores' not in save: save['Highscores'] = {'YOLO': 0, 'Have Fun': 0} self.highscores = save['Highscores'] self.sounds = [ 'Piano_G4#', 'Piano_F4', 'Piano_D4#', 'Piano_G3#', 'Piano_C4', 'Piano_C4#', 'Piano_G4' 'Coin_3', 'Error' ] for i in self.sounds: load_effect(i) self.music = { 1: 'G4#', 13: 'G4#', 25: 'F4', 37: 'D4#', 43: 'G4#', 97: 'G4#', 109: 'G4#', 121: 'F4', 133: 'D4#', 139: 'G4#', 193: 'G4#', 205: 'G4#', 217: 'G3#', 229: 'G3#', 241: 'G4#', 253: 'G4#', 265: 'G3#', 277: 'C4', 289: 'D4#', 313: 'C4#', 337: 'C4', 361: 'G4' } self.all_images = [ 'Ant', 'Baby_Chick_1', 'Baby_Chick_2', 'Baby_Chick_3', 'Bactrian_Camel', 'Bear_Face', 'Bird', 'Blowfish', 'Boar', 'Bug', 'Cat_Face_Crying', 'Cat_Face_Grinning', 'Cat_Face_Heart-Shaped_Eyes', 'Cat_Face_Kissing', 'Cat_Face_Pouting', 'Cat_Face_Smiling', 'Cat_Face_Weary', 'Cat_Face_With_Tears_Of_Joy', 'Cat_Face_With_Wry_Smile', 'Cat_Face', 'Chicken', 'Cow_Face', 'Dog_Face', 'Dolphin', 'Elephant', 'Fish', 'Frog_Face', 'Hamster_Face', 'Honeybee', 'Horse_Face', 'Horse', 'Koala', 'Lady_Beetle', 'Monkey_Face', 'Monkey_Hear-No-Evil', 'Monkey_See-No-Evil', 'Monkey_Speak-No-Evil', 'Monkey', 'Mouse_Face', 'Octopus', 'Panda_Face', 'Penguin', 'Pig_Face', 'Pig_Nose', 'Pile_Of_Poo', 'Poodle', 'Rabbit_Face', 'Sheep', 'Snail', 'Snake', 'Spiral_Shell', 'Tiger_Face', 'Tropical_Fish', 'Turtle', 'Whale', 'Wolf_Face' ] self.f = 'Futura' self.instrF = 'DejaVuSansMono' self.scoreF = 'ChalkboardSE-Regular' self.smallS = 20 self.s = 30 self.largeS = 40 self.titleS = 50 self.ipad = self.size.w > 400 if self.ipad: self.smallS *= 1.5 self.s *= 1.5 self.largeS *= 1.5 self.titleS *= 1.5