def ping(self, delete_method): c = objects.Objects.get_controller() if self.curVertex.borderVertices: curVertex = self.curVertex for asID in self.curVertex.borderVertices.keys(): destVertexList = self.curVertex.borderVertices[asID] for destVertex in destVertexList: if destVertex.asID not in c.visibleASes: self.isSelectable = False self.isDestroyed = True pingAction = MoveTo(self.curVertex.position, 0.6) pingAction += MoveTo(destVertex.position, 2) pingAction += MoveTo(self.curVertex.position, 2) pingAction += CallFunc(c._show_as, asID) # pingAction += CallFunc(utils.play_sound, "Visible.wav") pingAction += CallFunc(delete_method, self) pingAction += CallFunc(curVertex._update_visibility) self.do(pingAction) self.dispatch_event("Ping") utils.play_sound("ping.wav") return True # We successfully pinged. Return True. return False
def main(): global time audio_path = 'audio/modulated2.wav' audioBuffer, time = read_wav(audio_path) sinal_desmodulado = desmodulando_wav(audioBuffer) filtrado = filtrando(sinal_desmodulado) play_sound(sinal_desmodulado, FS)
def update(self): # make a copy of the list and its objects before moving self.old_blocks = copy.deepcopy(self.blocks) for block in self.blocks: block.move(self.blocks, self.walls) if block.rect.colliderect(self.end_rect): # Wait a bit before switching to new level # just to make the collision with the end blockless rude if self.seconds_win is None: self.seconds_win = pygame.time.get_ticks() # starter tick else: if (pygame.time.get_ticks() - self.seconds_win) / 1000 > 0.2: if len(LEVELS) > self.level + 1: self.switch_to_scene( TransitionScene(self.screen, self.level + 1)) else: self.switch_to_scene(WinScene(self.screen)) # raise SystemExit("You have passed all levels!") # calculate how many seconds have passed since the scene started self.seconds = (pygame.time.get_ticks() - self.start_ticks) / 1000 if self.seconds > self.max_time: # if time runs out, reset to the same level self.switch_to_scene(TransitionScene(self.screen, self.level)) self.seconds_left = int(self.max_time - self.seconds) if self.seconds_left == self.beep_at_seconds_left: play_sound("resources/sounds/beep.wav") self.beep_at_seconds_left -= 1
def q2_5_d(): ipnoisyfilename = 'helloworld_noisy_16bit.wav' _, sampleX_16bit = read_sound(ipnoisyfilename) x = fnNormalize16BitToFloat(sampleX_16bit) B = [1, -0.7653668, 0.99999] A = [1, -0.722744, 0.888622] y_ifil = signal.lfilter(B, A, x) y_ifil_16bit = fnNormalizeFloatTo16Bit(y_ifil) y_ifil_name = 'y_ifil.wav' save_sound(y_ifil_name, 16000, y_ifil_16bit) play_sound(y_ifil_name) [f1, t1, Sxx1] = signal.spectrogram(x, 16000, window=('blackmanharris'), nperseg=512, noverlap=int(0.9 * 512)) [f2, t2, Sxx2] = signal.spectrogram(y_ifil, 16000, window=('blackmanharris'), nperseg=512, noverlap=int(0.9 * 512)) _, ax = plt.subplots(2, 1) ax[0].pcolormesh(t1, f1, 10 * np.log10(Sxx1)) ax[1].pcolormesh(t2, f2, 10 * np.log10(Sxx2)) plt.show()
def perform_research(self,researchName,researchFactory): utils.play_sound("Clock.wav") researchType = RESEARCH[researchName] researchType.on_start(self.player) action = Delay(researchType.buildTime) action += CallFunc(self.finish_research,researchType,self.player,None) self.do(action)
def attack(self, target, m): # Already gauranteed that self.pid and target.pid != if self.is_attacking and type(self) != BufferOverflow: # Ignore for BufferOverflow as it can attack >1 unit # DEBUG # print "already attacking" return self.shouldAttack.add(target) if self.can_attack(target): path = m.get_path(self.curVertex, target.curVertex, self.pid, self, "attack") if path and len(path) <= self.attackRange + 1: self.attackingPath = path self.is_attacking = True c = objects.Objects.get_controller() c.client_attack_animation(self.pid, self.uid, target.pid, target.uid, self.attackingPath) self.targetVid = target.curVertex.vid self.sourceVid = self.curVertex.vid self.schedule_interval(self.attack_action, 1, target, m) else: # Can't attack. Let the user know utils.play_sound("error.wav") return
def perform_research(self, researchName, researchFactory): utils.play_sound("Clock.wav") researchType = RESEARCH[researchName] researchType.on_start(self.player) action = Delay(researchType.buildTime) action += CallFunc(self.finish_research, researchType, self.player, None) self.do(action)
def perform_research(self,researchName,owner,researchFactory): if owner.idleCPUs: if owner.pid == self.pid: utils.play_sound("Clock.wav") researchType = RESEARCH[researchName] researchType.on_start(owner) self.start_cpu(researchType, owner, researchF=researchFactory) return True return False
def perform_research(self, researchName, owner, researchFactory): if owner.idleCPUs: if owner.pid == self.pid: utils.play_sound("Clock.wav") researchType = RESEARCH[researchName] researchType.on_start(owner) self.start_cpu(researchType, owner, researchF=researchFactory) return True return False
def join_game(self): constants.MULTIPLAYER = True utils.play_sound("Enter.wav") c = Objects.get_client() c.start_server() # start client server connection = c.server_connect() # connect to game server if not connection: c.stop_server() menu_player.stop() self.game_started = True
def on_win(self): Objects.reset_game() server = Objects.get_server(self.levelName) server.curLevel = self.level+1 utils.play_sound("Enter.wav") game = Scene(server.map, server) game.add(ImageLayer(os.path.join("images", "backgrounds", "notebook-paper.png")), z=BACKGROUND_Z) director.push(game) menu_player.stop() self.game_started = True
def main(): print("Scanning for Motion") pir = MotionSensor(4) while (True): if (pir.wait_for_motion()): print("Motion detected") #snapshot_file = utils.take_snapshot(snapshots_dir) my_date = datetime.datetime.now().strftime("%B %d %Y %-H %M %S") print(my_date) utils.play_sound() #utils.copy_snapshot(snapshot_file) time.sleep(10)
def q2_3_b(): impulseH = np.zeros(8000) impulseH[1] = 1 impulseH[4000] = 0.5 impulseH[7900] = 0.3 play_sound(ipcleanfilename) Fs, sampleX_16bit = read_sound(ipcleanfilename) sampleX_float = fnNormalize16BitToFloat(sampleX_16bit) y = convolve(sampleX_float, impulseH) y_16bit = fnNormalizeFloatTo16Bit(y) save_file_name = "t2_16bit.wav" save_sound(save_file_name, Fs, y_16bit) play_sound(save_file_name)
def start_game(self): constants.MULTIPLAYER = True server = Objects.get_controller() server.client_start_game() if server.serverStarted: utils.play_sound("Enter.wav") game = Scene(server.map, server) menu_player.stop() game.add(ImageLayer( os.path.join("images", "backgrounds", "notebook-paper.png")), z=BACKGROUND_Z) director.push(game) self.game_started = True else: print "start server first"
def post(self): """Play sound""" url = self.get_argument("url") response = yield utils.play_sound(url) if response != "OK": return self.finish({"status": "error"}) return self.finish({"status": "OK"})
def move_unit(self, unit, path): dest = self.map.vertices[str(path[-1])] if dest != unit.destVertex: #if this gets called after update location unit.curVertex.remove_troop(unit) unit.destVertex = dest self.cm.remove_tricky(unit) # first vertex if unit.pid == self.pid: utils.play_sound("Move.wav") action = MoveTo(unit.curVertex.position, 0.2) # intermediate vertices for i in range(1, len(path)): vertex = self.map.vertices[str(path[i])] action += MoveTo(vertex.position, 1 / unit.speed) unit.do(action)
def on_key_release(self, k, m): # Determine the type of units we've selected so we can assign hotkeys # appropriately selType = None # scrolling logic if k in self.arrow_flags.keys(): self.arrow_flags[k] = 0 if k == key.LCTRL or k == key.RCTRL: # Reset so we can select the units we hotkeyed. self.isControlDown = False # Delete the selected unit. if k == key.BACKSPACE: if len(self.selectedUnits) > 0: temp = list(self.selectedUnits) self._deselect_all_units() for unit in temp: utils.play_sound("delete.wav") unit.destroy_action() if len(self.selectedUnits) > 0: selType = type(self.selectedUnits[0]) actNum = None if selType and issubclass(selType, Troop): actNum = TROOP_HOTKEYS.get(k, None) elif selType and issubclass(selType, Building): actNum = BUILDING_HOTKEYS.get(k, None) if actNum != None: for unit in self.selectedUnits: if actNum < len(unit.actionList): self._deselect_all_units() self.execute_action( unit.get_action_list(self.player)[actNum], unit) break return True
def on_key_release(self, k, m): # Determine the type of units we've selected so we can assign hotkeys # appropriately selType = None # scrolling logic if k in self.arrow_flags.keys(): self.arrow_flags[k] = 0 if k == key.LCTRL or k == key.RCTRL: # Reset so we can select the units we hotkeyed. self.isControlDown = False # Delete the selected unit. if k == key.BACKSPACE: if len(self.selectedUnits) > 0: temp = list(self.selectedUnits) self._deselect_all_units() for unit in temp: utils.play_sound("delete.wav") unit.destroy_action() if len(self.selectedUnits) > 0: selType = type(self.selectedUnits[0]) actNum = None if selType and issubclass(selType, Troop): actNum = TROOP_HOTKEYS.get(k, None) elif selType and issubclass(selType, Building): actNum = BUILDING_HOTKEYS.get(k, None) if actNum != None: for unit in self.selectedUnits: if actNum < len(unit.actionList): self._deselect_all_units() self.execute_action(unit.get_action_list(self.player)[actNum], unit) break return True
def POD(self, target): hitEnemyTroop = False if target.building != None and type(target.building) == Firewall and target.building.pid != self.pid: # DESTROY FIREWALL target.building.destroy_action() hitEnemyTroop = True self.isDestroyed = True s = objects.Objects.get_controller() for slot in target.troopSlots.values(): troop = slot.troop if troop.pid != self.pid: # Halves the health of this troop troop.on_attack((troop.health + 1) / 2,self) self.isDestroyed = True hitEnemyTroop = True if self.pid == s.pid: if hitEnemyTroop: utils.play_sound("ping_of_death.wav") else: utils.play_sound("ping_of_death_fail.wav")
def attack(self, target, m): # Already gauranteed that self.pid and target.pid != if self.is_attacking and type(self) != BufferOverflow: # Ignore for BufferOverflow as it can attack >1 unit # DEBUG # print "already attacking" return self.shouldAttack.add(target) if self.can_attack(target): path = m.get_path(self.curVertex, target.curVertex, self.pid, self, "attack") if path and len(path) <= self.attackRange + 1: self.attackingPath = path self.is_attacking = True c = objects.Objects.get_controller() c.client_attack_animation(self.pid,self.uid,target.pid,target.uid,self.attackingPath) self.targetVid = target.curVertex.vid self.sourceVid = self.curVertex.vid self.schedule_interval(self.attack_action, 1, target, m) else: # Can't attack. Let the user know utils.play_sound("error.wav") return
def POD(self, target): hitEnemyTroop = False if target.building != None and type( target.building ) == Firewall and target.building.pid != self.pid: # DESTROY FIREWALL target.building.destroy_action() hitEnemyTroop = True self.isDestroyed = True s = objects.Objects.get_controller() for slot in target.troopSlots.values(): troop = slot.troop if troop.pid != self.pid: # Halves the health of this troop troop.on_attack((troop.health + 1) / 2, self) self.isDestroyed = True hitEnemyTroop = True if self.pid == s.pid: if hitEnemyTroop: utils.play_sound("ping_of_death.wav") else: utils.play_sound("ping_of_death_fail.wav")
def build_unit_common(self, tid, owner, curVertex=None, uid=-1, builder=None, onInit=False): # print "build unit common", tid, owner.pid #check for valid conditions if owner.idleCPUs or tid == "CPU": #create the unit unitType = eval(tid) newUnit = unitType(curVertex, pid=owner.pid) #no empty slot if newUnit.slotIndex == -1: print "vertex full" if newUnit.pid == self.pid: utils.play_sound("error.wav") return None #add to map and set uid newUnit.add_to_map(self.map) uid = owner.set_unit_uid(newUnit, uid) #tutorial if newUnit.pid == self.pid: self.dispatch_event("player_add_unit", tid) if newUnit.buildTime == 0 or onInit: #instentaneous upgrade to encrypted newUnit.health = newUnit.maxHealth self._complete_build(newUnit, owner, newUnit.uid, onInit=onInit) #start building unit and tell client if not onInit: if tid != "CPU": self.start_cpu(newUnit, owner, builder) elif builder: self.remove_unit(builder) if owner == self.player: utils.play_sound("Clock.wav") # set visibility if type(curVertex) == Vertex and owner.pid == self.pid: self._show_as(curVertex.asID) return newUnit print "no idle CPU" if owner.pid == self.pid and not onInit: utils.play_sound("error.wav") return None
def q2_4_c(): h1 = np.array( [0.06523, 0.14936, 0.21529, 0.2402, 0.21529, 0.14936, 0.06523], dtype='float') h2 = np.array( [-0.06523, -0.14936, -0.21529, 0.7598, -0.21529, -0.14936, -0.06523], dtype='float') _, x1 = fnGenSampledSinusoid(0.1, 700, 0, 16000, 0, 0.05) _, x2 = fnGenSampledSinusoid(0.1, 3333, 0, 16000, 0, 0.05) x = x1 + x2 y1 = np.convolve(x, h1) t1 = np.arange(0, len(y1), 1) * (1 / 16000) y2 = np.convolve(x, h2) t2 = np.arange(0, len(y2), 1) * (1 / 16000) [f, t, Sxx] = signal.spectrogram(x, 16000, window=('blackmanharris'), nperseg=512, noverlap=int(0.9 * 512)) plt.pcolormesh(t, f, 10 * np.log10(Sxx)) plt.show() _, ax = plt.subplots(2, 1) ax[0].plot(t1, y1) ax[0].grid() ax[1].plot(t2, y2) ax[1].grid() plt.show() [f1, t1, Sxx1] = signal.spectrogram(y1, 16000, window=('blackmanharris'), nperseg=512, noverlap=int(0.9 * 512)) [f2, t2, Sxx2] = signal.spectrogram(y2, 16000, window=('blackmanharris'), nperseg=512, noverlap=int(0.9 * 512)) _, ax = plt.subplots(2, 1) ax[0].pcolormesh(t1, f1, 10 * np.log10(Sxx1)) ax[1].pcolormesh(t2, f2, 10 * np.log10(Sxx2)) plt.show() x_16bit = fnNormalizeFloatTo16Bit(x) y1_16bit = fnNormalizeFloatTo16Bit(y1) y2_16bit = fnNormalizeFloatTo16Bit(y2) x_file_name = 'x_16bit.wav' y1_file_name = 'y1_16bit.wav' y2_file_name = 'y2_16bit.wav' save_sound(x_file_name, 16000, x_16bit) save_sound(y1_file_name, 16000, y1_16bit) save_sound(y2_file_name, 16000, y2_16bit) play_sound(x_file_name) play_sound(y1_file_name) play_sound(y2_file_name)
def build_unit_common(self, tid, owner, curVertex=None, uid=-1, builder=None, onInit=False): # print "build unit common", tid, owner.pid #check for valid conditions if owner.idleCPUs or tid == "CPU": #create the unit unitType = eval(tid) newUnit = unitType(curVertex, pid=owner.pid) #no empty slot if newUnit.slotIndex == -1: print "vertex full" if newUnit.pid == self.pid: utils.play_sound("error.wav") return None #add to map and set uid newUnit.add_to_map(self.map) uid = owner.set_unit_uid(newUnit, uid) #tutorial if newUnit.pid == self.pid: self.dispatch_event("player_add_unit", tid) if newUnit.buildTime == 0 or onInit: #instentaneous upgrade to encrypted newUnit.health = newUnit.maxHealth self._complete_build(newUnit, owner, newUnit.uid,onInit=onInit) #start building unit and tell client if not onInit: if tid != "CPU": self.start_cpu(newUnit, owner, builder) elif builder: self.remove_unit(builder) if owner == self.player: utils.play_sound("Clock.wav") # set visibility if type(curVertex) == Vertex and owner.pid == self.pid: self._show_as(curVertex.asID) return newUnit print "no idle CPU" if owner.pid == self.pid and not onInit: utils.play_sound("error.wav") return None
def _select_units(self, units): for unit in units: if issubclass(type(unit), Unit) and unit.pid == self.pid: utils.play_sound("click_troop.wav") unit.set_is_selected(True, self.map, self.cm, self.player) self.selectedUnits.append(unit)
def on_mouse_release(self, x, y, buttons, modifiers): clicked_units = self.collision_manager.objs_touching_point(x, y) if(len(clicked_units) > 0): clicked = clicked_units.pop() if type(clicked) == BuildingsDetailsButton: utils.play_sound("Enter.wav") self.load_building_panel() elif type(clicked) == UtilityTroopDetailsButton: utils.play_sound("Enter.wav") self.load_utility_troops_panel() elif type(clicked) == AttackTroopDetailsButton: utils.play_sound("Enter.wav") self.load_attack_troops_panel() elif type(clicked) == ResourceDetailsButton: utils.play_sound("Enter.wav") self.load_resource_troops_panel() elif type(clicked) == BackButtonUD: utils.play_sound("Enter.wav") self.clear_panel(self.get_children()) self.load_overview_panel() elif type(clicked) == BackButton: utils.play_sound("Enter.wav") self.clear_panel(self.get_children()) self.load_instructions() elif type(clicked) == UnitDetailsButton: utils.play_sound("Enter.wav") self.clear_panel(self.get_children()) self.load_overview_panel() elif type(clicked) == ControlsButton: utils.play_sound("Enter.wav") self.clear_panel(self.get_children()) self.load_controls() elif type(clicked) == TechTreeButton: utils.play_sound("Enter.wav") self.clear_panel(self.get_children()) self.load_tech_tree() else: pass
def move_unit(self, dest, unit, pid): if issubclass(type(unit), Troop) and dest != unit.curVertex and dest.emptyTroopSlots and unit.isSelectable: path = self.map.get_path(unit.curVertex, dest, pid, unit) #check for firewall if not path: utils.play_sound("firewall.wav") return #check for sinkhole sinkHoleIndex = -1 for i in range(1,len(path)): vertID = path[i] vert = self.map.vertices[vertID] if vert.building != None and type(vert.building) == Sinkhole and type(unit) != EncryptedTroop and vert.building.pid != pid: sinkHoleIndex = i if sinkHoleIndex != -1: dest = unit.curVertex t = path[:sinkHoleIndex] t.reverse() path = path[:sinkHoleIndex + 1] + t #set unit logical position unit.isSelectable = False unit.curVertex.remove_troop(unit) slot = dest.add_trans_troop(unit) unit.destVertex = dest if unit.pid == self.pid: self.dispatch_event("click_on_move", unit.__class__.__name__, dest.vid) #dispatch to client for p in self.connectedClients.keys(): d = self.connect_end_point(self.connectedClients[p]) def c(ampProto): return ampProto.callRemote(MoveTroop, pid=pid, uid=unit.uid, vid=-1, path=path) d.addCallback(c) d.addErrback(err) reactor.callLater(10, d.cancel) # first vertex if pid == self.pid: utils.play_sound("Move.wav") action = CallFuncS(self.cm.remove_tricky) action += MoveTo(unit.curVertex.position, 0.2) else: action = MoveTo(unit.curVertex.position, 0.2) # intermediate vertices for i in range(1, len(path)): vertex = self.map.vertices[path[i]] action += MoveTo(vertex.position, 1 / unit.speed) action += CallFuncS(self.update_location, vertex.position, pid, vertex) if i == sinkHoleIndex: action += CallFunc(utils.play_sound, "Sinkhole.wav") action += CallFunc(unit.on_attack,math.ceil(unit.health/3.0),vertex.building) action += Delay(1) # final position if type(dest.building) != RSA or type(unit) == EncryptedTroop or dest.building.pid != unit.pid: action += MoveTo(slot.position, 0.2) action += CallFuncS(self.update_location, slot.position, pid) else: action += CallFuncS(self.upgrade_unit,"EncryptedTroop") action += CallFuncS(self.cm.add) unit.do(action) return path return []
def stop_cpu(self, cpu, owner): if owner.pid == self.pid: utils.play_sound("Clock_end.wav") owner.idleCPUs.append(cpu)
print("Full test num: ", full_test_num, "\nFail time: ", fail_time) number = input("Input the No. of the test: ") # GPIO config utils.Gpio_config(sensor, switch, sensor_bounce_time, switch_bounce_time) mixer.init() #-------------------------------------------- main try: while True: #总测试循环 key = input() if (key == "" or key == " "): ##输入回车 # 开始一组K-test test_num = utils.Start_single_test(test_num) utils.play_sound(Sound['BI'], delay=0.3) t = Get_time_stamp() time.sleep(0.1) # 100毫秒的延迟,消除干扰 while True: # 单次测试循环 delta_t = (Get_time_stamp() - t) / 1000 # 大于fail_time认为失败 if (delta_t > fail_time): result_list, success_num = utils.Record_test_result( FAILED, 0, test_num, success_num, result_list) utils.play_sound(Sound['FAIL']) break # fail_time内锡纸接触认为成功 if (GPIO.event_detected(sensor)):
def new_game(self): constants.MULTIPLAYER = True utils.play_sound("Enter.wav") Objects.get_server(self.levelName).start_server()
def move_unit(self, dest, unit, pid): if issubclass( type(unit), Troop ) and dest != unit.curVertex and dest.emptyTroopSlots and unit.isSelectable: path = self.map.get_path(unit.curVertex, dest, pid, unit) #check for firewall if not path: utils.play_sound("firewall.wav") return #check for sinkhole sinkHoleIndex = -1 for i in range(1, len(path)): vertID = path[i] vert = self.map.vertices[vertID] if vert.building != None and type( vert.building ) == Sinkhole and type( unit) != EncryptedTroop and vert.building.pid != pid: sinkHoleIndex = i if sinkHoleIndex != -1: dest = unit.curVertex t = path[:sinkHoleIndex] t.reverse() path = path[:sinkHoleIndex + 1] + t #set unit logical position unit.isSelectable = False unit.curVertex.remove_troop(unit) slot = dest.add_trans_troop(unit) unit.destVertex = dest if unit.pid == self.pid: self.dispatch_event("click_on_move", unit.__class__.__name__, dest.vid) #dispatch to client for p in self.connectedClients.keys(): d = self.connect_end_point(self.connectedClients[p]) def c(ampProto): return ampProto.callRemote(MoveTroop, pid=pid, uid=unit.uid, vid=-1, path=path) d.addCallback(c) d.addErrback(err) reactor.callLater(10, d.cancel) # first vertex if pid == self.pid: utils.play_sound("Move.wav") action = CallFuncS(self.cm.remove_tricky) action += MoveTo(unit.curVertex.position, 0.2) else: action = MoveTo(unit.curVertex.position, 0.2) # intermediate vertices for i in range(1, len(path)): vertex = self.map.vertices[path[i]] action += MoveTo(vertex.position, 1 / unit.speed) action += CallFuncS(self.update_location, vertex.position, pid, vertex) if i == sinkHoleIndex: action += CallFunc(utils.play_sound, "Sinkhole.wav") action += CallFunc(unit.on_attack, math.ceil(unit.health / 3.0), vertex.building) action += Delay(1) # final position if type(dest.building) != RSA or type( unit) == EncryptedTroop or dest.building.pid != unit.pid: action += MoveTo(slot.position, 0.2) action += CallFuncS(self.update_location, slot.position, pid) else: action += CallFuncS(self.upgrade_unit, "EncryptedTroop") action += CallFuncS(self.cm.add) unit.do(action) return path return []
def on_mouse_release(self, x, y, buttons, modifiers): x, y = self.scroller.pixel_from_screen(x, y) if self.infoLayer.miniMapToggled and self.infoLayer.miniMap.cshape.touches_point(x,y): return #I'm not sure why we need this, please talk to me - Robert # if self.statusMenu.menuButton.cshape.touches_point(x,y): # director.pop() clicked_units = self.cm.objs_touching_point(x, y) temp_units = [] actionButton = None for unit in clicked_units: if type(unit) == ActionButton: actionButton = unit break if unit.opacity == 255: # Using opacity to check unit is visible and finished building if issubclass(type(unit),Unit) and not unit.isSelectable: continue temp_units.append(unit) if type(unit) == TutorialXButton: # Delete the sticky note. self.map.remove(self.stickyNote) self.map.remove(self.stickyXButton) self.cm.remove_tricky(self.stickyXButton) utils.play_sound("delete.wav") if self.stickyNote.levelFiveCounter in [1,2]: # Adds the sticky note for levels 2-5 self.stickyNote = StickyNote("5", self.stickyNote.levelFiveCounter) self.stickyXButton = TutorialXButton(self.stickyNote) self.map.add(self.stickyNote) self.map.add(self.stickyXButton) self.cm.add(self.stickyXButton) clicked_units = temp_units[:1] if buttons == 1: # left button if self.curAction: if self.curAction == "Shake": for unit in list(clicked_units): if type(unit) == Handshake and unit.pid == self.pid: self.hand_shake(unit,self.selectedUnits.pop()) elif self.curAction == "Attack": for unit in list(clicked_units): if (issubclass(type(unit), Unit) and unit.pid != self.pid) or issubclass(type(unit), Vertex): if self.selectedUnits: self.dispatch_event("player_unit_attack", self.selectedUnits[0]) attacker = self.selectedUnits.pop() if type(self) == ClientController: self.server_attack_unit(attacker,unit) else: self.attack_unit(unit,attacker) self.curAction = None return self._deselect_all_units() if actionButton: self.execute_action(actionButton.name, actionButton.unitParent) else: self._select_units(clicked_units) if buttons == 4: # right button if not self.selectedUnits: return for unit in list(clicked_units): if type(unit) == Vertex: self._move_selected_units(unit) return
def on_mouse_release(self, x, y, buttons, modifiers): x, y = self.scroller.pixel_from_screen(x, y) if self.infoLayer.miniMapToggled and self.infoLayer.miniMap.cshape.touches_point( x, y): return #I'm not sure why we need this, please talk to me - Robert # if self.statusMenu.menuButton.cshape.touches_point(x,y): # director.pop() clicked_units = self.cm.objs_touching_point(x, y) temp_units = [] actionButton = None for unit in clicked_units: if type(unit) == ActionButton: actionButton = unit break if unit.opacity == 255: # Using opacity to check unit is visible and finished building if issubclass(type(unit), Unit) and not unit.isSelectable: continue temp_units.append(unit) if type(unit) == TutorialXButton: # Delete the sticky note. self.map.remove(self.stickyNote) self.map.remove(self.stickyXButton) self.cm.remove_tricky(self.stickyXButton) utils.play_sound("delete.wav") if self.stickyNote.levelFiveCounter in [1, 2]: # Adds the sticky note for levels 2-5 self.stickyNote = StickyNote( "5", self.stickyNote.levelFiveCounter) self.stickyXButton = TutorialXButton(self.stickyNote) self.map.add(self.stickyNote) self.map.add(self.stickyXButton) self.cm.add(self.stickyXButton) clicked_units = temp_units[:1] if buttons == 1: # left button if self.curAction: if self.curAction == "Shake": for unit in list(clicked_units): if type(unit) == Handshake and unit.pid == self.pid: self.hand_shake(unit, self.selectedUnits.pop()) elif self.curAction == "Attack": for unit in list(clicked_units): if (issubclass(type(unit), Unit) and unit.pid != self.pid) or issubclass( type(unit), Vertex): if self.selectedUnits: self.dispatch_event("player_unit_attack", self.selectedUnits[0]) attacker = self.selectedUnits.pop() if type(self) == ClientController: self.server_attack_unit(attacker, unit) else: self.attack_unit(unit, attacker) self.curAction = None return self._deselect_all_units() if actionButton: self.execute_action(actionButton.name, actionButton.unitParent) else: self._select_units(clicked_units) if buttons == 4: # right button if not self.selectedUnits: return for unit in list(clicked_units): if type(unit) == Vertex: self._move_selected_units(unit) return
def on_multi(self): utils.play_sound("Enter.wav") s = Scene(MultiplayerMenu(self.levelName)) s.add(ImageLayer(os.path.join("images", "backgrounds", "menu-chalkboard.png"))) director.push(s)
def trigger(self): self.current_alarm = self.alarms[self.next_alarm] sound = self.alarms[self.current_alarm].get('sound', default=self.alarm_sound) utils.play_sound(sound) self.refresh()
def on_intro(self): utils.play_sound("Enter.wav") image = os.path.join("images", "backgrounds", "notebook-paper.png") director.push(Scene(Intro(image)))