def touch_began(self, touch): # set firing and play sound on two finger touch if(len(self.touches) == 2 and not(self.firing)): sound.play_effect('Laser_1') self.firing = True self.laser.frame.x = self.ship.frame.x + (self.ship.frame.w / 2) - 3 self.laser.alpha = 1
def generate_outcome(): global player_choice computer_choice = choice(SIGNS) v['cpu_outcome'].text = computer_choice if player_choice == computer_choice: play_effect('Laser_3') v['game_result'].text = "It's a draw! Both played %s." % (player_choice) elif player_choice == 'Paper' and computer_choice == 'Rock': player_win('Paper', 'covers', 'rock') elif player_choice == 'Scissors' and computer_choice == 'Paper': player_win('Scissors', 'cut', 'paper') elif player_choice == 'Rock' and computer_choice == 'Scissors': player_win('Rock', 'crushes', 'scissors') elif player_choice == 'Rock' and computer_choice == 'Paper': player_win('Rock', 'crushes', 'paper') elif computer_choice == 'Paper' and player_choice == 'Rock': player_loss('Paper', 'covers', 'rock') elif computer_choice == 'Scissors' and player_choice == 'Paper': player_loss('Scissors', 'cut', 'paper') elif computer_choice == 'Rock' and player_choice == 'Scissors': player_loss('Rock', 'crushes', 'scissors') elif computer_choice == 'Rock' and player_choice == 'Paper': player_loss('Rock', 'crushes', 'paper') else: v['game_result'].text = "Whoops! This wasn\'t supposed to happen!"
def touch_began(self, touch): for key in chain(self.black_keys, self.white_keys): if key.hit_test(touch): key.touch = touch # print(touch.__dict__) sound.play_effect(key.name) return
def touch_ended(self, node, touch): if node == self: return for square in self.get_children_with_name('*'): #print(square.name) if isinstance(square, sk_BoardSquare) and touch in square: target_fen_loc = square.name save_fen_loc = node.fen_loc #node.move() is called on a different thread so it returns None!!! move_was_made = node.move(target_fen_loc) # always returns None!! #print('mwm 1', move_was_made) # fails!! move_was_made = node.fen_loc != save_fen_loc #print('mwm 2', move_was_made) if move_was_made: for piece in self.get_children_with_name('*'): # remove the killed sk_ChessPiece if (piece != node and isinstance(piece, sk_ChessPiece) and piece.fen_loc == node.fen_loc): if piece.piece.ptype == 'king': import dialogs dialogs.hud_alert('Game over man!') piece.remove_from_parent() #import dialogs #dialogs.hud_alert(str(type(self.view.superview))) self.view.superview.update_view(node.piece) node.position = square.position sound.play_effect('8ve:8ve-tap-professional') else: node.position = self.save_position sound.play_effect('8ve:8ve-beep-rejected') not_str = '' if move_was_made else 'not ' fmt = '{} at {} was {}moved to square {}\n' print(fmt.format(node.name, save_fen_loc, not_str, square.name))
def touch_began(self,touch): if self.cc_mode == 'I': x,y = touch.location string = self.closest(x,self.stringX) fret = self.closest(y,self.fretY) location = (string,fret) if location in self.touched.keys(): del self.touched[location] else: for key in self.touched.keys(): if key[0] == string: del self.touched[key] break self.touched[location] = (self.tuning['notes'][string]+fret,self.tuning['octave'],string,fret) octave,tone = divmod((self.tuning['notes'][string]+fret),12) waveName = 'waves/' + NOTE_FILE_NAMES[tone] + "{}.wav".format(octave+self.tuning['octave']) sound.play_effect(waveName) self.set_needs_display() elif self.cc_mode == 'S': # play two octave scale starting at this root x,y = touch.location string = self.closest(x,self.stringX) fret = self.closest(y,self.fretY) location = (string,fret) octave,tone = divmod((self.tuning['notes'][string]+fret),12) if tone != self.key: sound.play_effect('Error') return None self.scaleFrets = calc_two_octave_scale(location) self.set_needs_display()
def losing(self): score_value = int(self.score.text) sound.play_effect(fail_sound) self.green_timer_background.fill_color = color3 for square in self.squares: if square.star: square.star_icon.run_action(A.sequence(A.scale_to(0, 1), A.remove())) if square.state in (0, 3): square.state = 0 square.color = color3 try: square.red_square.run_action(A.remove()) except: pass bg_target = choice(self.bg_list).position square.run_action(A.sequence(A.wait(2),A.group(A.scale_to(0, 3), A.fade_to(0, 2), A.move_to(bg_target[0], bg_target[1], 2, TIMING_SINODIAL)), A.remove())) self.start.color = color3 self.finish.color = color3 self.score_change(-1 * int(self.score.text), self.win) self.score.text = "0" self.backdrop5.color = color3 self.level_label.text = choice(fail_text) self.move_counters() self.destroy_crosses() self.save(score_value) for bg in self.bg_list: bg.color = color3
def update(self, dt): self.y -= self.speed self.x = self.initial_x + sin(self.y / 100) * self.amp self.amp = max(self.amp * 0.99, 0) if self.y < -64: self.removed = True if self.dead: self.a -= 0.1 if self.a <= 0: self.removed = True else: self.t += 1 if not self.dead and self.t % self.fire_freq == 0: play_effect('Laser_5') if self.bullet_type == 1: bullet = Bullet(self.x, self.y) bullet.vy = -10 bullet.bullet_type = 1 self.scene.enemy_bullets.append(bullet) elif self.bullet_type == 2: for vx in [-3, 3]: bullet = Bullet(self.x, self.y) bullet.vy = -10 bullet.vx = vx bullet.bullet_type = 2 self.scene.enemy_bullets.append(bullet) else: for vx in [-3, 0, 3]: bullet = Bullet(self.x, self.y) bullet.vy = -10 bullet.vx = vx bullet.bullet_type = 3 self.scene.enemy_bullets.append(bullet)
def panic(self, pos): sound.play_effect("drums:Drums_06") for b in self.swarm: b.startled = True s = SpriteNode("shp:wavering", position=pos, scale=0, parent=self) s.run_action(A.sequence(A.group(A.scale_to(2), A.fade_to(0)), A.remove())) self.run_action(A.sequence(A.wait(1), A.call(self.end_panic)))
def killsoldier(self) : ###kill soldier and play explosion. play_effect(sounds[1]) self.setscore(self.count + 1) self.explosion.start(self, self.soldier.pos) self.shaker = 10 self.soldier.setpos(self.soldierpos)
def losing(self): score_value = int(self.score.text) sound.play_effect(fail_sound) self.green_timer_background.fill_color = color3 self.sparkle(color3, self.start.position, image='shp:RoundRect') for square in self.squares: if square.star: square.star_icon.z_position = 1 square.star_icon.run_action(A.sequence(A.scale_to(0, 1), A.remove())) if square.state == 3: self.sparkle(color3, square.position, image='shp:RoundRect') square.state = 0 if square.state == 0: square.color = color3 try: square.red_square.run_action(A.remove()) except: pass bg_target = choice(self.bg_list).position square.run_action(A.sequence(A.wait(2),A.group(A.scale_to(0, 3), A.fade_to(0, 2), A.move_to(bg_target[0], bg_target[1], 2, TIMING_SINODIAL)), A.remove())) self.start.color = color3 self.finish.color = color3 self.score.color = color3 self.backdrop5.color = color3 self.level_label.text = choice(fail_text) self.move_counters() self.save(score_value) for bg in self.bg_list: bg.color = color3
def draw(self): background(0, 0, 0) last_beat = int(self.beat) self.beat += 1.0/7.5 self.beat %= 16 play = int(self.beat) != last_beat for y in xrange(16): beat_row = int(self.beat) == y for x in xrange(8): if self.grid[x][y]: h = x / 8.0 r, g, b = hsv_to_rgb(h, 1, 1) if play and int(self.beat) == y: play_effect(self.sounds[x]) if beat_row: h = x / 8.0 r, g, b = hsv_to_rgb(h, 1, 1) fill(r, g, b) else: r, g, b = hsv_to_rgb(h, 1, 0.5) fill(r, g, b) elif beat_row: fill(1, 1, 1) else: fill(0.50, 0.50, 0.50) rect(x*(self.bounds.w/4), y*(self.bounds.h/9), self.bounds.w/4, self.bounds.h/9)
def draw(self, bright=False): colour = self.sl if self.state else self.bg colormod = 1 if bright else 0.8 fill(*[i*colormod for i in colour]) rect(*self.bounds) if self.state and bright: sound.play_effect(self.drum)
def draw ( self ): # 毎回、描画しないと通ったところに色が残ってしまう background(1, 1, 1) fill(1, 0, 0) g = gravity () self.x += g.x * 100 self.y += g.y * 100 self.x = min ( self.size.w - 40, max( 0, self.x )) self.y = min ( self.size.h - 40, max( 0, self.y )) # 動く四角を描画 image('_Image_1', self.x, self.y, 40, 40) m_rect = Rect( self.x, self.y, 40, 40 ) # 障害物を描画 fill(1, 1, 0) for s in self.s_rect: image('_Image_2', s.x, s.y, s.w, s.h ); # あたり判定 for i, s in enumerate( self.s_rect ): if m_rect.intersects( s ): ''' # あたった四角の色をかえる fill( 1, 0, 0 ) rect( s.x, s.y, s.w, s.h ) ''' # あたった四角を消す del self.s_rect[i] # 音をだす sound.play_effect('Crashing')
def touch_ended(self, touch): if time() - self.last_touch_up_time < MAX_DOUBLE_TAP_DELAY: sound.play_effect('Beep') self.double_tap_start_time = time() self.last_touch_up_time = 0 else: self.last_touch_up_time = time()
def die(self): self.animation_done = False self.animate('scale_x', 0.01, repeat=2) self.animate('scale_y', 0.01, repeat=2, completion=self.death_completion) for i in xrange(4): sound.play_effect('Hit_{}'.format(i+1)) time.sleep(0.5)
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 end_game(self): if self.score > self.highscore: with open('.Match3Highscore', 'w') as f: f.write(str(self.score)) self.highscore = self.score sound.play_effect('digital:ZapTwoTone') self.show_game_over_menu()
def disp_end_game(self, status): if status == 'OK': # ゲームクリアの表示を設定 message = 'Game Clear' color = '#00ff00' background_color = '#ffff00' effect = 'arcade:Powerup_1' else: # ゲームオーバーの表示を設定 message = 'Time Up' color = '#ff0000' background_color = '#000000' effect = 'arcade:Explosion_1' # ゲーム完了画面を表示 end_font = ('Arial Rounded MT Bold', 80) self.end_label = LabelNode(message, end_font, parent=self) self.end_label.position = (self.size.w/2, self.size.h - 300) self.end_label.z_position = 1 self.end_label.color = color self.background_color = background_color # ゲーム終了状態にする self.game_over = True # ゲーム終了サウンドを鳴らす sound.play_effect(effect)
def touch_pu2(self): sound.play_effect(button_sound) self.can_flip = False self.stop_squares_moving() self.level_label.text = "Restore a locked square" if self.unlock == False: self.unlock = True elif self.unlock == True: self.unlock = False self.destroy_crosses() self.level_label.text = "Level " + str(self.level) return self.powerup2.run_action(pressed_action_2) self.powerup2_bg.run_action(pressed_action_2) self.p2_count.run_action(pressed_action_2) for square in self.squares: if square.state == 0 and self.unlock and square.last_state == 1: square.red_square = SpriteNode(texture = Texture('typb:Cross'), color = color3) square.red_square.position = square.position square.red_square.z_position = 0.4 self.add_child(square.red_square) square.red_square.run_action(A.repeat(A.sequence(A.scale_to(0.85, 0.4, TIMING_EASE_IN_OUT), A.scale_to(0.95, 0.4, TIMING_EASE_IN_OUT)), 0)) elif square.state == 0 and self.unlock and square.last_state == 2: square.red_square = SpriteNode(texture = Texture('typw:Cross'), color = color2) square.red_square.position = square.position square.red_square.z_position = 0.4 self.add_child(square.red_square) square.red_square.run_action(A.repeat(A.sequence(A.scale_to(0.85, 0.4, TIMING_EASE_IN_OUT), A.scale_to(0.95, 0.4, TIMING_EASE_IN_OUT)), 0))
def touch_pu3(self): self.unlock = False self.stop_squares_moving() self.level_label.text = "Flip a single square" self.powerup3.run_action(pressed_action_2) self.powerup3_bg.run_action(pressed_action_2) self.p3_count.run_action(pressed_action_2) sound.play_effect(button_sound) if self.can_flip == False: self.can_flip = True elif self.can_flip == True: self.can_flip = False self.level_label.text = "Level " + str(self.level) for square in self.squares: square.remove_all_actions() square.scale = 1 return for item in (self.black_count, self.white_count): item.run_action(A.repeat(A.sequence(A.scale_to(0.85, 0.4, TIMING_EASE_IN_OUT), A.scale_to(0.95, 0.4, TIMING_EASE_IN_OUT)), 0)) try: if self.star_square: self.star_square.star_icon.run_action(A.repeat(A.sequence(A.scale_to(0.85, 0.4, TIMING_EASE_IN_OUT), A.scale_to(0.95, 0.4, TIMING_EASE_IN_OUT)), 0)) except: pass for square in self.squares: if square.state in (1, 2): square.run_action(A.repeat(A.sequence(A.scale_to(0.85, 0.4, TIMING_EASE_IN_OUT), A.scale_to(0.95, 0.4, TIMING_EASE_IN_OUT)), 0))
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 Randomize(self): if self.Randum > -40: sound.play_effect('Click_1', ((self.Randum+40.0)/65.0), 3+(self.Randum/15.0)) else: sound.play_effect('Ding_3', 1.5, 0.9) self.FirstDisplay = random.choice(self.First) self.SecondDisplay = random.choice(self.Second) self.ThirdDisplay = random.choice(self.Third)
def update_score(self): if(self.env.state == GAME_PLAY): for tower in self.towers: if tower.passed == False: if tower.left() < self.player.bounds.right(): tower.passed = True self.env.score += 1 sound.play_effect('Coin_1')
def save_bookmarks(sender): bookmarks_file = dialogs.input_alert("name") + ".txt" txt = book_marks.segments for x in txt: with open("Notes/" + bookmarks_file, "a", encoding="utf-8") as outfile: outfile.write(time_stamp + "\n" + str(x) + "\n") sound.play_effect("rpg:BookFlip2") console.alert("Saved to {}".format(bookmarks_file))
def touch_began(self, touch): if self.player.dead and not self.touch_disabled: play_effect('Powerup_1') self.setup() return elif not self.player.dead: self.frame_count = 0 self.fire()
def open_main(sender): sound.play_effect('ui:click3') sheet.close() sheet.wait_modal() main.present() with open('Files/main_text.txt','r') as infile: main['view1']['textview1'].text = infile.read() main['textview1']
def move(self, direction, tile, ty, tx): by, bx = self.getBlankPosition() btile = self.board[by][bx] tile.bounds, btile.bounds = btile.bounds, tile.bounds self.board[ty][tx] = btile self.board[by][bx] = tile sound.play_effect("Click_1")
def collect_item(self, item, value=10): sound.play_effect('digital:PowerUp7') item.remove_from_parent() self.items.remove(item) # ---[2] # Simply add 10 points to the score for every coin, then update the score label accordingly: self.score += value self.score_label.text = str(self.score)
def disarm_system(sender): global system_armed system_armed = False sound.play_effect('digital:TwoTone2') v['status_label'].text_color=('#00e800') v['status_label'].text = ("System Status: SAFE") v['disarm_system_button'].enabled = False v['arm_system_button'].enabled = True
def captureOutput_didOutputMetadataObjects_fromConnection_(_self, _cmd, _output, _metadata_objects, _conn): objects = ObjCInstance(_metadata_objects) for obj in objects: s = str(obj.stringValue()) if s not in found_codes: found_codes.add(s) sound.play_effect('digital:PowerUp7') main_view['label'].text = 'Last scan: ' + s
def handle_touch(self, event): if self.airhorn_sound: self.airhorn_sound.stop() self.airhorn_sound = sound.play_effect('rsc/airhorn_single.m4a')
def draw(self): background(0.0, 0.0, 0.4) if (self.gamestate == "play"): #fill(self.flapper.r, self.flapper.g, self.flapper.b, self.flapper.a) #rect(300, self.flapper.y, self.flapper.w, self.flapper.h) image('_Image_4', 300, self.flapper.y, self.flapper.w, self.flapper.h) self.flapper.doGravity(Vec2(0.0, -.63)) self.flapper.doVelocity() fill(0.0, 1.0, 0.0, 1.0) for i in self.walls: rect(i.x - self.flapper.x + 300, i.y, i.w, i.h) fill(0.8, 0.5, 0.0, 1.0) for i in self.goals: rect(i.x - self.flapper.x + 300, i.y, i.w, i.h) if (self.ticks % 100 == 0): self.genWall() self.cullExcessWalls() for i in self.goals: if (self.flapper.collideWithWall(i)): self.points += 1 self.goals.pop(self.goals.index(i)) break for i in self.walls: if (self.flapper.collideWithWall(i)): self.gamestate = "dead" sound.play_effect('Clank', 1.0) self.deadtime = time.time() for i in range(219): z = Flapper(300 + self.flapper.w / 2, self.flapper.y + self.flapper.h / 2, 7.0, 7.0, 1.0, 0.0, 0.0, 0.0) xdir = random.random() - .5 ydir = random.random() - .5 dist = math.sqrt(xdir ** 2 + ydir ** 2) if dist == 0: xdir = 0 ydir = 0 else: xdir /= dist ydir /= dist z.secondaryInit(Vec2(xdir, ydir) * random.randint(0, 20)) self.deathparticles.append(z) break tint(1.0, 1.0, 1.0, 1.0) text("Points: " + str(self.points), "Arial", 20.0, 5.0, self.bounds.h - 25.0, 3) if (self.flapper.y < 0 or self.flapper.y + self.flapper.h > self.bounds.h + 20): self.gamestate = "dead" self.deadtime = time.time() sound.play_effect('Clank', 1.0) for i in range(219): z = Flapper(300 + self.flapper.w / 2, self.flapper.y + self.flapper.h / 2, 7.0, 7.0, 1.0, 0.0, 0.0, 0.0) xdir = random.random() - .5 ydir = random.random() - .5 dist = math.sqrt(xdir ** 2 + ydir ** 2) if dist == 0: xdir = 0 ydir = 0 else: xdir /= dist ydir /= dist z.secondaryInit(Vec2(xdir, ydir) * random.randint(0, 20)) self.deathparticles.append(z) self.ticks += 1 elif (self.gamestate == "dead"): #fill(self.flapper.r, self.flapper.g, self.flapper.b, self.flapper.a) #rect(300, self.flapper.y, self.flapper.w, self.flapper.h) fill(0.0, 1.0, 0.0, 1.0) for i in self.walls: rect(i.x - self.flapper.x + 300, i.y, i.w, i.h) fill(0.8, 0.5, 0.0, 1.0) for i in self.goals: rect(i.x - self.flapper.x + 300, i.y, i.w, i.h) fill(1.0, 0.0, 0.0, 1.0) for i in self.deathparticles: ellipse(i.x, i.y, i.w, i.h) i.doGravity(Vec2(0.0, -0.63)) i.doVelocity() tint(1.0, 1.0, 1.0, 1.0) text("You Died", "Arial", 32.0, self.bounds.w / 2, self.bounds.h / 2 + 32, 5) text("Points: " + str(self.points), "Arial", 32.0, self.bounds.w / 2, self.bounds.h / 2 - 32, 5)
def loading2(self): print("Okay Processing...") sound.play_effect("data-stream.mp3") sleep(5) image3.show()
def update(self): # this method is called, hopefully, 60 times a second if config.gamescene == True: config.gamescene = False self.dismiss_modal_scene() self.move_paddle() if (self.started == False): self.load_level(levels[self.level]) self.started = True # check every update to see if a ball has touched a brick else: pass #move the ball self.Ball.position = self.Ball.position + self.ball_velocity # now check if the ball has touched the paddle if self.Ball.frame.intersects(self.paddle.frame): # you should change the velocity to a different angle here self.ball_velocity.y = self.ball_velocity.y * (-1) if config.sound == True: sound.set_volume(50) sound.play_effect('8ve:8ve-tap-mellow') else: sound.set_volume(0) # bounce ball off walls if self.Ball.position.y <= 0: self.ball_velocity.y = self.ball_velocity.y * (0) self.present_modal_scene(GameOver()) # really it should not bounce, the game should end if self.Ball.position.x <= 0: self.ball_velocity.x = self.ball_velocity.x * (-1) if self.Ball.position.x >= self.size_of_screen_x: self.ball_velocity.x = self.ball_velocity.x * (-1) if self.Ball.position.y >= self.size_of_screen_y: self.ball_velocity.y = self.ball_velocity.y * (-1) if self.size.w > 760: #iPad brick_w, brick_h = 64, 32 else: #iPhone brick_w, brick_h = 32, 16 if len(self.bricks) > 0 and len(self.shoot_ball) > 0: #print('missile check') for brick in self.bricks: for shoot in self.shoot_ball: if brick.frame.contains_rect(shoot.frame): shoot.remove_from_parent() self.shoot_ball.remove(shoot) brick.remove_from_parent() self.bricks.remove(brick) if len(self.bricks) > 0 and len(self.Balls) > 0: for brick in self.bricks: for self.Ball in self.Balls: if brick.frame.contains_rect(self.Ball.frame): brick.remove_from_parent() self.bricks.remove(brick) if self.Ball.frame.intersects(brick.frame): #self.ball_velocity.y = self.ball_velocity.y * (-1) self.ball_velocity.y = self.ball_velocity.y * (-1)
def touch_began(self, touch): sound.play_effect('Click_1') #creates a query of the locations recorded and opens it on google maps #because the query accepts at most around 20 points, if you have more #than 20 points it will create a new list and get points evenly spaced #throughout the path to a total of less than 20. Looks representative #and accurate. def mapView(self): googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] webbrowser.open(self.query) #when you run across a landmark (photo) you placed down, it will #notify you its present and you can tap to reveal the photo def openLandmark(self): sound.play_effect('Click_1') self.imageModeOpen = True self.imageMode = False self.heightPhoto = (self.photoHeight/self.photoWidth) * \ (self.size.x-20) self.widthPhoto = (self.photoWidth/self.photoWidth) * \ (self.size.x-20) self.heightFrame = self.heightPhoto + 10 self.widthFrame = self.widthPhoto + 10 self.halfScreenFrame = self.size.y / 2 - self.heightFrame / 2 self.halfScreen = self.size.y / 2 - self.heightPhoto / 2 #asked a question on the omz (Pythonista) forum and they answered! #'https://forum.omz-software.com/topic/5263/displaying-an-image- #from-album-in-photos-onto-screen-in-scene-module' #opens the image and has it hidden. self.img = ui.Button(name='image') self.img.frame = (10, self.halfScreen, self.widthPhoto, self.heightPhoto) self.img.background_image = self.ui_image self.img.enable = False self.img.hidden = False self.view.add_subview(self.img) #when you tap, get the current location to perform functions current = location.get_location() #solved the close points problem using rounding latLong = (round(current['latitude'], 4), round(current['longitude'], 4)) picTaken = latLong in self.photoLocations #get the location on the screen of the touch x, y = touch.location #if the image is open, close it when you tap (has to be off the image) if self.imageModeOpen == True: self.imageModeOpen = False self.img.hidden = True #if you have the loop Prompt, you must tap an answer in order to use #the other functions if self.loopPrompt == True: if x > 50 and x < self.size.x/2 and y < self.size.y/2 \ and y > self.size.y/2 - 50: self.loopPrompt = False self.loopPromptState = 1 elif x > self.size.x/2 and x < self.size.x-50 \ and y < self.size.y/2 and y > self.size.y/2 - 50: self.loopPrompt = False self.loopPromptState = 2 #when it has the more menu open, you must are not able to tap any of #the other buttons, other than the ones in the more menu elif self.MoreState == True: #SOS State tap, call the cops if you tap if x < self.size.w/2 + 30 and x > self.size.w/2 - 30 \ and y > 50 and y < 100 and self.MoreState == True: webbrowser.open('tel:911') #MapView tap elif x < 100 and x > 50 and y < 220 and y > 160 and \ len(self.locations) >= 2: mapView(self) #create the query, but make it a link for phone users, and copy #it to the clipboard elif x < self.size.x/2+40 and x > self.size.x/2-40 and \ y < 220 and y > 160 and len(self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] clipboard.set(self.query[7:]) self.clipState = True #tap on Trace button to reveal the path elif x < self.size.x-50 and x > self.size.x-100 and y < 220 \ and y > 160 and len(self.locations) > 2: self.pathState = True #tap on theme button to switch the theme elif x < self.size.w/2 + 30 and x > self.size.w/2 - 30 \ and y > self.size.y-95-40 and y < self.size.y-95+40: self.themeSwitch += 1 if self.themeSwitch % 2 == 0: self.theme = self.lightMode elif self.themeSwitch % 2 == 1: self.theme = self.darkMode #tap off a button while in the more menu, and it exits the menu else: self.MoreState = False self.clipState = False self.pathState = False #open landmark by tapping on the banner elif y > 150 and y < 200 and self.imageMode == True: openLandmark(self) #if in image mode, tap off the image to get rid of it off the screen elif y < 150 and y > 200 and self.imageMode == True: self.imageMode = False #reset button resets everything elif x < 100 and x > 50 and y < 100 and y > 50: self.measuringOn = False self.functionState = 0 self.background_color = self.theme["backgroundColor"] self.locations = [] self.needMore = False self.photoCount = 0 self.photoLocations = [] self.locationsLeft = [] self.needMore = False self.timerCount = 0 #more button is a small and out of the way, opens up more menu elif x < self.size.w/2 + 25 and x > self.size.w/2 - 25 and y < 30 \ and y > 0: self.MoreState = True #take photos and add to album elif x < self.size.w/2 + 30 and x > self.size.w/2 - 30 \ and y > 50 and y < 100 and self.MoreState == False and \ self.measuringOn == True and picTaken == False: imageree = photos.capture_image() if imageree != None: #open up the camera and you can take photo photos.save_image(imageree) time.sleep(1) self.photoCount += 1 allAssets = photos.get_assets() theImage = allAssets[-1] #if there is no album, create album 'Thread' try: self.photoLibrary = [a for a in photos.get_albums() \ if a.title == 'Thread'][0] except IndexError: self.photoLibrary = photos.create_album('Thread') #add the image to the album for the user to have and for #future use in the app's use (landmarks!) theImage = allAssets[len(allAssets) - 1] self.photoLibrary.add_assets([theImage]) self.photoLocations += [latLong] #compass State: Letters (NWSE) or degrees elif x < 325 and x > 275 and y < 100 and y > 50: self.compassStat = not (self.compassStat) #go to measuring mode when tapped for the first time elif self.measuringOn == False and self.functionState == 0: self.measuringOn = True self.background_color = self.theme["backgroundColor"] self.functionState += 1 #if you need more values do not let the user stop recording elif self.measuringOn == True and self.functionState == 1 \ and len(self.locations) < 4: self.needMore = True #if you have enough locations, when you tap you can move to next state elif self.measuringOn == True and self.functionState == 1 \ and len(self.locations) > 3: #sound.play_effect('arcade:Laser_1') self.needMore = False self.measuringOn = False self.background_color = self.theme["backgroundColor"] self.functionState += 1 #move function state up to state 4 so you can begin tracing back elif self.measuringOn == False and self.functionState == 3: #sound.play_effect('arcade:Laser_1') self.background_color = self.theme["backgroundColor"] self.functionState += 1
def draw(self): #Box self.cx =self.size.w * 0.5 self.cy = self.size.h * 0.5 #pitch,roll,yaw self.cx2 =self.size.w * 0.5 self.cy2 = self.size.h * 0.5-scale*3.5 time.sleep(0.1) self.testCounter += 1 #motion ax,ay,az = motion.get_user_acceleration() gx,gy,gz= motion.get_gravity() gravity_vectors=motion.get_attitude() mx,my,mz,ma=motion.get_magnetic_field() pitch, roll, yaw = [x for x in gravity_vectors] pitch = -pitch*180/math.pi roll=roll*180/math.pi yaw=-yaw*180/math.pi #redraw screen fill(0.9,0.9,0.9) stroke_weight(0) #pitch,roll,yaw ellipse(self.cx2-scale*3-self.R,self.cy2-self.R-130,self.R*2,self.R*2) tint(0,0,0,1) text('Reset', font_name='Helvetica', font_size=12.0, x=self.cx2-111.5, y=self.cy2+self.R-167, alignment=5) # ellipse(self.cx2-0.0-self.R,self.cy2-self.R,self.R*2,self.R*2) stroke_weight(1) fill(0.5,0.5,0.5) #compass draw ellipse(self.cx2+scale*3-self.R,self.cy2-self.R-130,self.R*2,self.R*2) fill(0.7,0.7,0.7) stroke_weight(0) ellipse(self.cx2+scale*3-self.R+3,self.cy2-self.R-127,self.R*1.85,self.R*1.85) fill(0.8,0.8,0.8) ellipse(self.cx2+scale*3-self.R+6,self.cy2-self.R-124,self.R*1.7,self.R*1.7) roll_sin = math.sin(math.radians(roll)) roll_cos = math.cos(math.radians(roll)) pitch_sin = math.sin(math.radians(pitch)) pitch_cos = math.cos(math.radians(pitch)) yaw_sin = math.sin(math.radians(yaw)) yaw_cos = math.cos(math.radians(yaw)) # line(self.cx2-roll_cos*self.R-scale*3,self.cy2-roll_sin*self.R,self.cx2+roll_cos*self.R-scale*3,self.cy2+roll_sin*self.R) # line(self.cx2-pitch_cos*self.R-0,self.cy2-pitch_sin*self.R,self.cx2+pitch_cos*self.R-0,self.cy2+pitch_sin*self.R) stroke(0,0,0) stroke_weight(2) line(self.cx2-yaw_cos*self.R+scale*3,self.cy2-yaw_sin*self.R-130,self.cx2+yaw_cos*self.R+scale*3,self.cy2+yaw_sin*self.R-130) stroke(1,0,0) line(300,72.5,self.cx2+yaw_cos*self.R+scale*3,self.cy2+yaw_sin*self.R-130) #circle on top of compass stroke_weight(1) stroke(0,0,0) fill(0.9,0.9,0.9) ellipse(self.cx2+scale*3-self.R+9.5,self.cy2-self.R-120.5,self.R*1.5,self.R*1.5) yawMatrix = numpy.matrix([[yaw_cos, -yaw_sin, 0],[yaw_sin, yaw_cos, 0],[0, 0, 1]]) pitchMatrix = numpy.matrix([[pitch_cos, 0, pitch_sin],[0, 1, 0],[-pitch_sin, 0, pitch_cos]]) rollMatrix = numpy.matrix([[1, 0, 0],[0, roll_cos, -roll_sin],[0, roll_sin, roll_cos]]) R = yawMatrix * pitchMatrix * rollMatrix R = numpy.array(R) #x_3d,y_3d,z_3d = numpy.transpose(numpy.dot(self.Box,R),(2,0,1)) #zmin = numpy.argmin(z_3d) #derive the direction (NSEW) def directionText(yaw): directionSym = '' #Direction if yaw > 60 and yaw <= 120: directionSym = 'N' elif yaw > 120 and yaw <= 150: directionSym = 'NE' elif (yaw > 150 and yaw <= 180) or (yaw >= -180 and yaw <= -150): directionSym = 'E' elif yaw > -150 and yaw <= -120: directionSym = 'SE' elif yaw > -120 and yaw <= -60: directionSym = 'S' elif yaw > -60 and yaw <= -30: directionSym = 'SW' elif yaw > -30 and yaw <= 30: directionSym = 'W' elif yaw > 30 and yaw <= 60: directionSym = 'NW' else: directionSym = '' return directionSym #text tint(0,0,0,1) text('Thread 1.0', font_name='Courier', font_size=16.0, x=self.cx2, y=self.cy2+self.R+400, alignment=5) if self.measuringOn == False and self.checkedOnce == 0: text('Tap to Start', font_name='Helvetica', font_size=16.0, x=self.cx2, y=self.cy2+self.R+150, alignment=5) elif self.measuringOn == True and self.checkedOnce == 1: if self.testCounter//10 % 3 == 0: text('Measuring.', font_name='Helvetica', font_size=16.0, x=self.cx2, y=self.cy2+self.R+150, alignment=5) elif self.testCounter//10 % 3 == 1: text('Measuring..', font_name='Helvetica', font_size=16.0, x=self.cx2, y=self.cy2+self.R+150, alignment=5) elif self.testCounter//10 % 3 == 2: text('Measuring...', font_name='Helvetica', font_size=16.0, x=self.cx2, y=self.cy2+self.R+150, alignment=5) text('Tap to Stop', font_name='Helvetica', font_size=16.0, x=self.cx2, y=self.cy2+self.R+120, alignment=5) elif self.measuringOn == False and self.checkedOnce == 2: text('Calculating', font_name='Helvetica', font_size=16.0, x=self.cx2, y=self.cy2+self.R+120, alignment=5) #compass text if self.compassStat == False: text(directionText(yaw), font_name='Helvetica', font_size=10.0, x=self.cx2+scale*3, y=self.cy2+self.R-167, alignment=5) else: tempYaw = yaw+180+90 if tempYaw > 360: tempYaw = tempYaw % 360 text(str(round(tempYaw,2)), font_name='Helvetica', font_size=10.0, x=self.cx2+scale*3, y=self.cy2+self.R-167, alignment=5) if self.measuringOn == True: if self.testCounter % 10: current = location.get_location() latLong = (current['latitude'], current['longitude']) self.locations += [latLong] sound.play_effect('arcade:Laser_2') elif self.checkedOnce == 2 and len(self.locations) > 2: self.locationsReversed = copy.deepcopy(self.locations) self.locationsReversed.reverse() #now use the locations and map it onto a map so you know the direciton between points (NWSE) #start saying stuff like "Point North and Move Forward" #Now it makes sense why we use the compass. #test texts self.checkedOnce += 1 elif self.checkedOnce == 3 or self.checkedOnce == 4: locationList = str(self.locations[0]) + ' ' + str(self.locations[-1]) text(locationList, font_name='Helvetica', font_size=5.0, x=self.cx2, y=self.cy2+self.R+80, alignment=5) locationListReversed = str(self.locationsReversed[0]) + ' ' + str(self.locationsReversed[-1]) text(locationListReversed, font_name='Helvetica', font_size=5.0, x=self.cx2, y=self.cy2+self.R+60, alignment=5)
def touch_ended(self, touch): if self.game_over: #Start a new game if the current game has ended: self.new_game() play_effect('Powerup_3') return #At least 2 tiles have to be removed: sel_count = len(filter(lambda (x): x and x.selected, self.grid)) if sel_count < 2: play_effect('Error') for tile in self.grid: if tile is not None: tile.selected = False return #The first tile is 10 points, the second 20, etc.: score_added = ((sel_count * (sel_count + 1)) / 2) * 10 self.score += score_added play_effect('Coin_3') #Show the added score as an animated text layer: score_layer = TextLayer(str(score_added), 'GillSans-Bold', 40) score_layer.frame.center(touch.location) self.effects.add_layer(score_layer) from_frame = score_layer.frame to_frame = Rect(from_frame.x, from_frame.y + 200, from_frame.w, from_frame.h) score_layer.animate('frame', to_frame, duration=0.75) score_layer.animate('alpha', 0.0, delay=0.3, completion=score_layer.remove_layer) #Remove selected tiles: for i in xrange(len(self.grid)): tile = self.grid[i] if tile is None: continue if tile.selected: self.grid[i] = None #Adjust the positions of the remaining tiles: self.drop_tiles() #If at least one tile has a neighbor with the same image, #another move is possible: can_move = max(map(len, map(self.neighbors, self.grid))) > 0 if not can_move: play_effect('Bleep') rest = len(filter(lambda x: x is not None, self.grid)) msg = 'Perfect!' if rest == 0 else 'Game Over' #Show an animated 'Game Over' message: font_size = 100 if self.size.w > 700 else 50 game_over_layer = TextLayer(msg, 'GillSans', font_size) game_over_layer.frame.center(self.size.w / 2, self.size.h / 2) game_over_layer.alpha = 0.0 self.effects.add_layer(game_over_layer) #When the animation completes, the game_over flag is set, #so that the next tap starts a new game: completion = partial(setattr, self, 'game_over', True) game_over_layer.animate('alpha', 1.0, duration=1.0, completion=completion) game_over_layer.animate('scale_x', 1.2, autoreverse=True, duration=1.0) game_over_layer.animate('scale_y', 1.2, autoreverse=True, duration=1.0)
def play_effect(self, name, volume=0.5, pitch=1.0): iId = soundOrig.play_effect(name, volume, pitch) self._l.append(iId) return iId
def Beat01(self): if self.finished: return #サウンド snd = sound.play_effect(BGM)
def __bMA(self, sender): sound.play_effect('Drums_01') self.document_email(self.get_data()) console.hud_alert('Emailed file:' + self.document_name + ' ' + self.document_size)
def touch_began(self, touch): sound.play_effect('Beep')
def buttontapped(sender): n = sender.title global shows_result label = sender.superview['label1'] label2 = sender.superview['label2'] shows_result = '0' if sender.name in '0123456789': sound.play_effect('ui:switch9') if label.text == '0': label.text = n else: label.text += n if n == '-x': sound.play_effect('ui:switch9') label.text = '-' elif n in '+-÷×**': sound.play_effect('ui:switch9') if label.text[-1] in '+-÷×': label.text = label.text[:-1] + n else: label.text += n elif n == 'x!': sound.play_effect('ui:switch9') label2.text = label.text + '! =' label.text = str(math.factorial(int(label.text))) elif n == '.' and label.text[-1] != '.': sound.play_effect('ui:switch9') label.text += n elif n == 'AC': sound.play_effect('ui:switch9') label.text = '0' label2.text = '' elif n == 'C': sound.play_effect('ui:switch9') label.text = label.text[:-1] if len(label.text) == 0: label.text = '0' elif n == '=': sound.play_effect('ui:switch9') try: label2.text = label.text + ' =' expr = label.text.replace('÷', '/').replace('×', '*') label.text = str(eval(expr)) except (SyntaxError, ZeroDivisionError): label.text = 'ERROR' shows_result = True elif n != '=': shows_result = False label2.text = ''
text = sys.argv[1] url = sys.argv[2] PASSWORD = '******' USER = '******' tags = console.input_alert('Tags', 'Enter your tags below') console.show_activity() query = {'url': url, 'description': text, 'tags': tags} query_string = urlencode(query) pinboard_url = 'https://api.pinboard.in/v1/posts/add?' + query_string r = requests.get(pinboard_url, auth=(USER, PASSWORD)) console.clear() if r.status_code != 200: print 'Could not post:', r.text elif r.status_code == 200: tags = tags.split(' ') tags = ','.join(tags) sound.play_effect('Powerup_2') print 'Link saved successfully' print text print "tags: " + tags
def touch_began(self, touch): play_effect(self.click_sound) w = self.size.w h = self.size.h l = touch.location def touchingText(x, y, width, height): if self.ipad: width *= 1.5 height *= 1.5 return l in Rect(w * x - width / 2, h * y - height / 2, width, height) if self.state == 'Menu': if touchingText(0.5, 0.63, 100, 60): self.state = 'Starting Classic' if touchingText(0.5, 0.5, 100, 60): self.state = 'Starting Timed' if touchingText(0.5, 0.37, 100, 60): self.state = 'Highscores' elif self.state.startswith('Starting'): if touchingText(0.85, 0.05, 100, 60): self.state = 'Menu' else: self.taps = 0 self.startTime = time.time() self.speed = 0 self.state = self.state[9:] elif self.state == 'Classic': self.taps += 1 if self.taps >= 100: self.time = time.time() - self.startTime self.speed = 100 / self.time self.state = 'Classic Win' elif self.state == 'Timed': self.taps += 1 elif self.state.endswith('Win'): if touchingText(0.85, 0.05, 100, 60): if self.state == 'Classic Win': if self.highscores[ 'Classic'] is None or self.time < self.highscores[ 'Classic']: self.highscores['Classic'] = self.time else: if self.highscores[ 'Timed'] is None or self.taps > self.highscores[ 'Timed']: self.highscores['Timed'] = self.taps if self.highscores[ 'Speed'] is None or self.speed > self.highscores[ 'Speed']: self.highscores['Speed'] = self.speed self.state = 'Menu' elif self.state == 'Highscores': if touchingText(0.85, 0.05, 100, 60): self.state = 'Menu'
def touch_ended(self, touch): # this method is called, when user releases a finger from the screen if self.stats_label.frame.contains_point(touch.location): self.stats_label_down = True sound.play_effect('assets/Chop.caf') self.start_time = time.time() self.present_modal_scene(StatsScene()) if self.shoprub_label.frame.contains_point(touch.location): self.shoprub_label_down = True sound.play_effect('assets/Chop.caf') self.start_time = time.time() self.present_modal_scene(ShopRubScene()) if self.shop_label.frame.contains_point(touch.location): self.shop_label_down = True sound.play_effect('assets/Chop.caf') self.start_time = time.time() self.present_modal_scene(HitAndRunShopScene()) if self.run_label.frame.contains_point(touch.location): self.run_label_down = True sound.play_effect('assets/Chop.caf') run(GameScene(), show_fps=True, orientation=PORTRAIT) if self.credits_label.frame.contains_point(touch.location): self.credits_label_down = True sound.play_effect('assets/Chop.caf') self.start_time = time.time() self.present_modal_scene(CreditsScene()) if self.help_label.frame.contains_point(touch.location): self.help_label_down = True sound.play_effect('assets/Chop.caf') self.start_time = time.time() self.present_modal_scene(HelpScene())
def touch_began(self, touch): touch_loc = self.menu_bg.point_from_scene(touch.location) for btn in self.buttons: if touch_loc in btn.frame: sound.play_effect('8ve:8ve-tap-resonant') btn.texture = Texture('pzl:Button2')
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 new_game(self): sound.play_effect('Coin_2') self.deal() self.root_layer.animate('scale_x', 1.0) self.root_layer.animate('scale_y', 1.0)
def Generate(f, nsamples): N = SampleRate // f buf = [random() - 0.5 for i in range(N)] samples = [] bufSize = len(buf) for i in range(nsamples): samples.append(buf[0]) avg = 0.997 * 0.5 * (buf[0] + buf[1]) buf.append(avg) buf.pop(0) tempbuf = [int(x * max_val) for x in samples] data = array('h', tempbuf).tostring() file.writeframes(data) file = wave.open('karplus_strong.wav', 'wb') file.setparams( (nchannels, swdth, frame_rate, nframes, 'NONE', 'nonecompressed')) for i in range(len(notes)): Generate(notes[i], 44100 // duration[i]) file.close() sound.play_effect('karplus_strong.wav')
def touch_began(self, touch): if (self.gamestate == "play"): self.flapper.doTouch() sound.play_effect('Jump', 1.0) elif (self.gamestate == "dead" and (self.deadtime + 1.0) < time.time()): self.setup()
def update(self, dt): self.layer.update(dt) # on one finger touch - move ship if (len(self.touches) == 1): touch = self.touches[self.touches.keys()[0]] # move ship towards touch location # only move ship if relative touch location is greater than 5 pixels/points from ship if (abs(self.ship.frame.x - (touch.location.x - (45 * screen_factor))) > (5 * screen_factor)): if (self.ship.frame.x < touch.location.x - (45 * screen_factor)): # the further the touch location, the faster the ship should move self.ship.frame.x += ( 3 + (abs(self.ship.frame.x - (touch.location.x - (45 * screen_factor))) / (screen_size.w / 64))) * screen_factor else: # the further the touch location, the faster the ship should move self.ship.frame.x -= ( 3 + (abs(self.ship.frame.x - (touch.location.x - (45 * screen_factor))) / (screen_size.w / 64))) * screen_factor # if ship is firing, move laser up screen if (self.firing): self.laser.frame.y += 7 * screen_factor if (self.laser.frame.y > screen_size.h + 10): self.laser.frame.y = (screen_size.h / 20) * 4 self.laser.alpha = 0 self.firing = False # move space monsters for i in range(5): frame = self.space_monster[i].frame if (frame.x > screen_size.w - frame.w): self.space_monster_move_x[i] = randint( -self.space_monster_max_speed, -1) elif (frame.x < 0): self.space_monster_move_x[i] = randint( 1, self.space_monster_max_speed) frame.x = frame.x + (self.space_monster_move_x[i] * screen_factor) # regen space monsters if (self.space_monster[i].alpha == 0): random_regen = randint(1, 200) if (random_regen == 1): self.space_monster[ i].frame.x = -self.space_monster[i].frame.w self.space_monster[i].alpha = 1 elif (random_regen == 200): self.space_monster[i].frame.x = screen_size.w self.space_monster[i].alpha = 1 # do space monster firing if (self.space_monster_firing[i]): self.space_monster_laser[i].frame.y -= 7 * screen_factor if (self.space_monster_laser[i].frame.y < -self.space_monster_laser[i].frame.h): self.space_monster_firing[i] = False else: if (self.space_monster[i].alpha == 1): if (randint(1, self.space_monster_fire_rate) == 1): self.space_monster_laser[i].frame = Rect( self.space_monster[i].frame.x + (self.space_monster[i].frame.w / 2), self.space_monster[i].frame.y - 15, 6 * screen_factor, 20 * screen_factor) self.space_monster_laser[i].alpha = 1 self.space_monster_firing[i] = True sound.play_effect('Laser_6') # detect players laser to space monster collision for i in range(5): # if collision detected and space monster is currently alive (visible) if (self.laser.frame.intersects(self.space_monster[i].frame) and self.space_monster[i].alpha == 1): # update laser properties self.laser.frame.y = (screen_size.h / 20) * 3 self.laser.alpha = 0 self.firing = False self.space_monster[i].alpha = 0 # update space monster properties if (self.space_monster_fire_rate > 22): self.space_monster_fire_rate -= 30 if (self.space_monster_max_speed < 15): self.space_monster_max_speed += 1 # add points self.score += 2 * (6 - i) # play sound sound.play_effect('Explosion_2') # detect space monster laser to player collision for i in range(5): # create a test frame - ship frame is larger than image test_frame = Rect(self.ship.frame.x + (self.ship.frame.w / 4), self.ship.frame.y + (self.ship.frame.h / 4), self.ship.frame.w - (self.ship.frame.w / 2), self.ship.frame.h - (self.ship.frame.h / 2)) # if collision detected if (self.space_monster_laser[i].frame.intersects(test_frame)): sound.play_effect('Explosion_4') sleep(5) main_scene.switch_scene(Intro)
def player_killed_sounds(): for i in xrange(4): sound.play_effect('Hit_{}'.format(i+1)) time.sleep(0.5)
def __bOA(self, sender): sound.play_effect('Drums_01') self.set_data(self.document_read()) console.hud_alert('Opened file: ' + self.document_name + ' ' + self.document_size)
def Beat04(self): if self.finished: return sound.play_effect('arcade:Laser_4')
def high_score_sounds(): for i in xrange(4): sound.play_effect('Jump_{}'.format(i+1)) time.sleep(0.3)
def update(self): # makes the player move left if (self.player.position.x - self.player_move_speed) > (self.screen_center_x * 0.25): if self.left_button_down == True: playerMove = Action.move_by(-1 * self.player_move_speed, 0.0, 0.1) self.player.run_action(playerMove) # makes the player move right if (self.player.position.x + self.player_move_speed ) < self.size_of_screen_x - (self.screen_center_x * 0.25): if self.right_button_down == True: playerMove = Action.move_by(self.player_move_speed, 0.0, 0.1) self.player.run_action(playerMove) # makes the goalie move if self.movingLeft == True: goalieMove = Action.move_by(-1 * self.goalie_move_speed, 0.0, 0.1) self.goalie.run_action(goalieMove) if self.goalie.position.x < self.leftBound: self.goalie.position.x = self.leftBound self.goalie_move_speed = random.randint(10, 50) self.movingLeft = False if self.movingLeft == False: goalieMove = Action.move_by(self.goalie_move_speed, 0.0, 0.1) self.goalie.run_action(goalieMove) if self.goalie.position.x > self.rightBound: self.goalie_move_speed = random.randint(10, 50) self.goalie.position.x = self.rightBound self.movingLeft = True # check every update to see if a puck is off the screen for puck in self.pucks: if puck.position.y > self.size_of_screen_y * 1.1: puck.remove_from_parent() self.pucks.remove(puck) # check every update to see if a puck has entered the net for puck in self.pucks: if self.net.frame.contains_rect(puck.frame): puck.remove_from_parent() self.pucks.remove(puck) sound.play_effect('./assets/sounds/goal.wav') self.score = self.score + 1 # check every update to see if a new defender should be created defender_create_chance = random.randint(1, 120) if defender_create_chance <= self.defender_attack_rate: if self.game_over == False: self.add_defender() # check every update to see if a defender is off screen for defender in self.defender: if defender.position.y < -50: defender.remove_from_parent() self.defender.remove(defender) # limits you to one puck on the screen if len(self.pucks) > 0: self.shoot_button_down = False # check every update to see if a defender has hit the player if len(self.defender) > 0: for defender_hit in self.defender: if defender_hit.frame.intersects(self.player.frame): sound.play_effect('./assets/sounds/game_over.wav') defender_hit.remove_from_parent() self.defender.remove(defender_hit) self.game_over = True self.menu_button.alpha = 1 self.game_over_background.alpha = 1 self.game_over_label.alpha = 1 self.player_move_speed = 0 self.goalie_move_speed = 0 # check every update to see if a puck has hit a defender if len(self.defender) > 0 and len(self.pucks) > 0: for defender in self.defender: for puck in self.pucks: if defender.frame.contains_rect(puck.frame): sound.play_effect('./assets/sounds/game_over.wav') puck.remove_from_parent() self.pucks.remove(puck) defender.remove_from_parent() self.defender.remove(defender) self.game_over = True self.menu_button.alpha = 1 self.game_over_background.alpha = 1 self.game_over_label.alpha = 1 self.player_move_speed = 0 self.goalie_move_speed = 0 # check every update to see if a puck has hit the goalie for puck in self.pucks: if self.goalie.frame.intersects(puck.frame): sound.play_effect('./assets/sounds/game_over.wav') puck.remove_from_parent() self.pucks.remove(puck) self.game_over = True self.menu_button.alpha = 1 self.game_over_background.alpha = 1 self.game_over_label.alpha = 1 self.player_move_speed = 0 self.goalie_move_speed = 0 else: pass # shows the score self.score_label.text = 'Score: ' + str(self.score)
def __bSSA(self, sender): sound.play_effect('Drums_01') ProjectSettingsSheet()
def touch_began(self, touch): current = location.get_location() latLong = (round(current['latitude'], 4), round(current['longitude'], 4) ) #solved the close points problem using rounding picTaken = latLong in self.photoLocations x, y = touch.location if self.loopPrompt == True: if x > 50 and x < self.size.x / 2 and y < self.size.y / 2 and y > self.size.y / 2 - 50: self.loopPrompt = False self.loopPromptState = 1 elif x > self.size.x / 2 and x < self.size.x - 50 and y < self.size.y / 2 and y > self.size.y / 2 - 50: self.loopPrompt = False self.loopPromptState = 2 elif self.MoreState == True: #SOS State if x < self.size.w / 2 + 30 and x > self.size.w / 2 - 30 and y > 50 and y < 100 and self.MoreState == True: webbrowser.open('tel:911') #MapView elif x < 100 and x > 50 and y < 220 and y > 160 and len( self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] webbrowser.open(self.query) elif x < self.size.x / 2 + 40 and x > self.size.x / 2 - 40 and y < 220 and y > 160 and len( self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] clipboard.set(self.query[7:]) self.clipState = True elif x < self.size.x - 50 and x > self.size.x - 100 and y < 220 and y > 160: self.pathState = True else: self.MoreState = False self.clipState = False self.pathState = False #open landmark elif y > 150 and y < 200 and self.imageMode == True: sound.play_effect('arcade:Laser_2') self.imageModeOpen = True self.imageMode = False #reset button elif x < 100 and x > 50 and y < 100 and y > 50: self.measuringOn = False self.checkedOnce = 0 self.background_color = 'white' self.locations = [] self.needMore = False self.photoCount = 0 self.photoLocations = [] self.locationsLeft = [] self.needMore = False self.timerCount = 0 #more button elif x < self.size.w / 2 + 25 and x > self.size.w / 2 - 25 and y < 30 and y > 0: self.MoreState = True #take photos and add to album elif x < self.size.w / 2 + 30 and x > self.size.w / 2 - 30 and y > 50 and y < 100 and self.MoreState == False and self.measuringOn == True and picTaken == False: imageree = photos.capture_image() if imageree != None: photos.save_image(imageree) time.sleep(1) self.photoCount += 1 allAssets = photos.get_assets() theImage = allAssets[-1] #print("Divider") # Find the album or create it: try: self.photoLibrary = [ a for a in photos.get_albums() if a.title == 'Thread' ][0] except IndexError: self.photoLibrary = photos.create_album('Thread') # Add the file as an asset to the library: # asset = photos.create_image_asset(theImage) # Add the asset to the album: theImage = allAssets[len(allAssets) - 1] self.photoLibrary.add_assets([theImage]) self.photoLocations += [latLong] #compass State: Letters (NWSE) or degrees elif x < 325 and x > 275 and y < 100 and y > 50: self.compassStat = not (self.compassStat) elif self.measuringOn == False and self.checkedOnce == 0: #sound.play_effect('arcade:Laser_2') self.measuringOn = True self.background_color = 'white' self.checkedOnce += 1 elif self.measuringOn == True and self.checkedOnce == 1 and len( self.locations) < 4: #sound.play_effect('arcade:Laser_1') self.needMore = True elif self.measuringOn == True and self.checkedOnce == 1 and len( self.locations) > 3: #sound.play_effect('arcade:Laser_1') self.needMore = False self.measuringOn = False self.background_color = 'white' self.checkedOnce += 1 elif self.measuringOn == False and self.checkedOnce == 3: #sound.play_effect('arcade:Laser_1') self.background_color = 'white' self.checkedOnce += 1
def draw(self): self.shot_fired = False self.star_field.update() self.star_field.draw() removed_bullets = set() removed_enemy_bullets = set() removed_enemies = set() fill(1, 1, 0) for bullet in self.bullets: bullet.update() bullet.draw() if bullet.y > 1024: removed_bullets.add(bullet) player_rect = self.player.bbox() fill(1, 0, 1) for bullet in self.enemy_bullets: bullet.update() bullet.draw() if bullet.y < -4: removed_enemy_bullets.add(bullet) elif not self.player.dead and bullet.hit_test(player_rect): removed_enemy_bullets.add(bullet) self.energy -= 10 play_effect('Explosion_6') for enemy in self.enemies: enemy.update(self.dt) enemy.draw() enemy_rect = enemy.bbox() if not enemy.dead: for bullet in self.bullets: if bullet.hit_test(enemy_rect): removed_bullets.add(bullet) enemy.energy -= 1 enemy.hit = True self.delay(0.1, partial(enemy.__setattr__, 'hit', False)) if enemy.energy <= 0: enemy.dead = True self.explosion(enemy) self.score += enemy.points play_effect('Explosion_4') else: play_effect('Explosion_5') if not self.player.dead and player_rect.intersects(enemy_rect): play_effect('Explosion_6') enemy.dead = True self.explosion(enemy) self.energy -= 10 if enemy.removed: removed_enemies.add(enemy) removed_powerups = set() for powerup in self.powerups: powerup.update() powerup.draw() if player_rect.intersects(powerup.bbox()): if powerup.powerup_type == 0: play_effect('Coin_2') self.energy = min(100, self.energy + 20) else: play_effect('Powerup_3') self.frenzy = True self.delay(5.0, partial(self.__setattr__, 'frenzy', False)) removed_powerups.add(powerup) elif powerup.y < -32: removed_powerups.add(powerup) map(self.powerups.remove, removed_powerups) map(self.enemies.remove, removed_enemies) map(self.bullets.remove, removed_bullets) map(self.enemy_bullets.remove, removed_enemy_bullets) if not self.player.dead and self.energy <= 0: self.game_over() if not self.player.dead: self.player.update() self.player.draw() self.draw_status_bar() self.effects_layer.update(self.dt) self.effects_layer.draw() tint(1, 1, 1) self.frame_count += 1 if not self.player.dead and len(self.touches) > 0: if self.frame_count % 12 == 0: self.fire()
def __bSA(self, sender): sound.play_effect('Drums_01') self.document_write(self.get_data()) console.hud_alert('Saved file:' + self.document_name + ' ' + self.document_size)