def __on_update(self): if self._is_playing: self._is_playing = False for i in range(pyxel.MUSIC_CHANNEL_COUNT): if pyxel.play_pos(i) >= 0: self._is_playing = True play_pos = pyxel.play_pos(i) self._play_pos[ i] = play_pos // 100 if play_pos >= 0 else -1 else: self._play_pos[i] = -1 if pyxel.btnp(pyxel.KEY_SPACE): if self._is_playing: self._stop_button.press() else: self._play_button.press() if self._is_playing: return if not self._play_button.is_enabled: self._stop() if self._loop_button.is_enabled and pyxel.btnp(pyxel.KEY_L): self._loop_button.press() self.field_cursor.process_input()
def __on_update(self): self._is_playing = pyxel.play_pos(0) >= 0 self._play_pos = pyxel.play_pos(0) sound = pyxel.sound(self._sound_picker.value) if self._speed_picker.value != sound.speed: self._speed_picker.value = sound.speed if pyxel.btnp(pyxel.KEY_SPACE): if self._is_playing: self._stop_button.press() else: self._play_button.press() if self._is_playing: return if not self._play_button.is_enabled: self._stop() if self._loop_button.is_enabled and pyxel.btnp(pyxel.KEY_L): self._loop_button.press() if pyxel.btnp(pyxel.KEY_PAGE_UP): self.octave = min(self.octave + 1, 3) if pyxel.btnp(pyxel.KEY_PAGE_DOWN): self.octave = max(self.octave - 1, 0) self.field_cursor.process_input()
def _update(self): pyxel.stop() # BGM停止 pyxel.play(3, self.sound) while pyxel.play_pos(3) != -1: yield yield self.command() yield self.releaseback()
def _runaway(self, offence, deffence): yield f"\n{offence.name}は逃げ出した!" pyxel.play(3, 9) while pyxel.play_pos(3) != -1: yield "" self.releaseback() yield ""
def draw(self): pyxel.cls(1) pyxel.text(6, 6, "sound(snd).set(note,tone,volume,effect,speed)", 7) pyxel.rect(12, 14, 177, 35, 2) pyxel.text(16, 17, "note :[CDEFGAB] + [ #-] + [0-4] or [R]", 9) pyxel.text(16, 25, "tone :[T]riangle [S]quare [P]ulse [N]oise", 9) pyxel.text(16, 33, "volume:[0-7]", 9) pyxel.text(16, 41, "effect:[N]one [S]lide [V]ibrato [F]adeOut", 9) pyxel.text(6, 53, "music(msc).set(ch0,ch1,ch2,ch3)", 7) pyxel.text(6, 62, "play(ch,snd,loop=False)", 7) pyxel.text(6, 71, "playm(msc,loop=False)", 7) pyxel.text(6, 80, "stop([ch])", 7) pyxel.rectb(6, 97, 188, 47, 14) pyxel.rect(6, 91, 29, 7, 14) pyxel.text(7, 92, "CONTROL", 1) pyxel.text(12, 102, "1: Play all channels", 14) pyxel.text(12, 110, "2: Play channel #0 (Melody)", 14) pyxel.text(12, 118, "3: Play channel #1 (Bass)", 14) pyxel.text(12, 126, "4: Play channel #2 (Drums)", 14) pyxel.text(12, 134, "5: Stop playing", 14) pyxel.text(137, 107, "play_pos(ch)", 15) for i in range(3): x = 140 + i * 16 y = 123 + math.sin(pyxel.frame_count * 0.1 + i * 2.1) * 5 col = 15 if pyxel.play_pos(i) else 13 pyxel.pal(1, col) pyxel.blt(x, y, 0, 0, 0, 8, 8, 0) pyxel.pal()
def __on_draw(self): pyxel.blt( self.x, self.y, EDITOR_IMAGE, 208, 0, 12, 123, ) notes = self.get_field(0) if (self.is_playing_var and not notes or not self.is_playing_var and self.note_var is None): return note = notes[pyxel.play_pos(0) [1]] if self.is_playing_var else self.note_var key = note % 12 x = self.x y = self.y + (59 - note) * 2 if note == -1: pyxel.rect(x, y + 1, 12, 2, PIANO_KEYBOARD_REST_COLOR) elif key == 0 or key == 5: pyxel.rect(x, y + 1, 7, 1, PIANO_KEYBOARD_PLAY_COLOR) pyxel.rect(x + 7, y, 5, 2, PIANO_KEYBOARD_PLAY_COLOR) elif key == 4 or key == 11: pyxel.rect(x, y + 1, 7, 1, PIANO_KEYBOARD_PLAY_COLOR) pyxel.rect(x + 7, y + 1, 5, 2, PIANO_KEYBOARD_PLAY_COLOR) elif key == 2 or key == 7 or key == 9: pyxel.rect(x, y + 1, 7, 1, PIANO_KEYBOARD_PLAY_COLOR) pyxel.rect(x + 7, y, 5, 3, PIANO_KEYBOARD_PLAY_COLOR) else: pyxel.rect(x, y + 1, 6, 1, PIANO_KEYBOARD_PLAY_COLOR)
def play_sound(snd): is_played = False for i in range(4): if pyxel.play_pos(i) == -1: pyxel.play(i, snd) is_played = True break return is_played
def _yakusou(self): yield f"{g_player.name}はやくそうをつかった!" pyxel.play(3, 17) while pyxel.play_pos(3) != -1: yield "" v = 6 + random.randrange(5) g_player.hp = min(g_player.hp + v, g_player.maxhp) g_player.items.remove("やくそう") yield f"\n{g_player.name}のHPは{v}かいふくした!🔻"
def _yakusou(self, offence, _): yield f"\n{offence.name}はやくそうをつかった!" pyxel.play(3, 17) while pyxel.play_pos(3) != -1: yield "" v = 6 + random.randrange(3) offence.hp = min(offence.hp + v, offence.maxhp) offence.items.remove("やくそう") yield f"\n{offence.name}のHPは{v}かいふくした!"
def _heal(self, offence, _): yield f"\n{offence.name}はヒールをとなえた!" pyxel.play(3, 17) while pyxel.play_pos(3) != -1: yield "" v = 6 + random.randrange(3) offence.hp = min(offence.hp + v, offence.maxhp) offence.mp -= 2 yield f"\n{offence.name}のHPは{v}かいふくした!"
def _heal(self): # 以下、コマンドへの対応、最初の\nがあるのでBattleとの共有化はできない yield f"{g_player.name}はヒールをとなえた!" pyxel.play(3, 17) while pyxel.play_pos(3) != -1: yield "" v = 6 + random.randrange(5) g_player.hp = min(g_player.hp + v, g_player.maxhp) g_player.mp -= 2 yield f"\n{g_player.name}のHPは{v}かいふくした!🔻"
def play_sound(snd, looping=False): if globals.g_sound_on == False: return if snd not in SOUNDS: return if pyxel.play_pos(3) != -1: return pyxel.play(3, snd, loop=looping)
def sound(snd): if (SOUND_ON): n = pyxel.play_pos(0) if n >= 0: pass #print("snd=" + hex(n)) if (n == -1): pyxel.play(0, snd) else: if sound_priority[int(n / 10)] < sound_priority[snd]: pyxel.stop(0) pyxel.play(0, snd)
def _return_ticket(self): yield "もどりふだはさいしょのしろのばしょにもどります。\nつかいますか?" yesno = SelectBox(*SelectBox.YesNoParameters) yield "" if yesno.index == 0: yield f"\n{g_player.name}はもどりふだをつかった!" g_player.items.remove("もどりふだ") pyxel.play(3, 17) while pyxel.play_pos(3) != -1: yield "" yield Field(12, 3) # 音の変更 else: yield ""
def _fire(self, offence, deffence): yield f"\n{offence.name}はファイアをとなえた!" pyxel.play(3, 16) for x, y in ((-2, -2), (-2, 2), (2, 2), (-2, 2), (1, -2), (-1, 1), (0, -1), (0, 1), (0, 0)): if offence == g_player: self.offset = (x, y) else: camera(-x, -y) yield "" while pyxel.play_pos(3) != -1: yield "" v = 5 + random.randrange(3) deffence.hp = max(deffence.hp-v, 0) yield f"\n{deffence.name}に{v}のダメージ!"
def _attack(self, offence, deffence): yield f"\n{offence.name}のこうげき!" pyxel.play(3, 16) for x, y in ((-2, -2), (-2, 2), (2, 2), (-2, 2), (1, -2), (-1, 1), (0, -1), (0, 1), (0, 0)): if offence == g_player: self.offset = (x, y) else: camera(-x, -y) yield "" while pyxel.play_pos(3) != -1: yield "" a = max([v for k, v in (("どうのけん", 3), ("はがねのけん", 7)) if k in offence.items] + [0]) v = 2 + random.randrange(3) + a deffence.hp = max(deffence.hp-v, 0) yield f"\n{deffence.name}に{v}のダメージ!"
def __on_update(self): if self.is_playing_var: return mx = pyxel.mouse_x my = pyxel.mouse_y if self.is_hit(mx, my): self._preview_sound = self._hit_sound_button(mx, my) if (self._preview_sound is not None and self._preview_sound != self._last_preview_sound): pyxel.play(0, self._preview_sound, loop=True) else: self._preview_sound = None if self._preview_sound is None and pyxel.play_pos(0) is not None: pyxel.stop(0) self._last_preview_sound = self._preview_sound
def __on_draw(self): # Draw frame self.draw_panel(self.x, self.y, self.width, self.height) pyxel.text(self.x + 5, self.y + 8, f"CH{self._ch}", TEXT_LABEL_COLOR) pyxel.blt( self.x + 20, self.y + 1, EDITOR_IMAGE, 0, 102, 191, 19, MUSIC_FIELD_BACKGROUND_COLOR, ) # Draw cursor if self.is_playing_var: play_pos = pyxel.play_pos(self._ch) if play_pos is None: cursor_x = -1 cursor_y = -1 else: cursor_x = play_pos[0] cursor_y = self._ch cursor_width = 1 cursor_col = MUSIC_FIELD_CURSOR_PLAY_COLOR else: cursor_x = self.field_cursor.x cursor_y = self.field_cursor.y cursor_width = self.field_cursor.width cursor_col = (MUSIC_FIELD_CURSOR_SELECT_COLOR if self.field_cursor.is_selecting else MUSIC_FIELD_CURSOR_EDIT_COLOR) if cursor_y == self._ch: for i in range(len(self.data) + 1): if cursor_x <= i < cursor_x + cursor_width: x = self.x + (i % 16) * 12 + 21 y = self.y + (cursor_y - self._ch + i // 16) * 10 + 2 pyxel.rect(x, y, 9, 7, cursor_col) # Draw sounds for i in range(len(self.data)): x = self.x + 22 + (i % 16) * 12 y = self.y + (i // 16) * 10 + 3 col = (MUSIC_FIELD_SOUND_SELECT_COLOR if cursor_y == self._ch and cursor_x <= i < cursor_x + cursor_width else MUSIC_FIELD_SOUND_NORMAL_COLOR) pyxel.text(x, y, f"{self.data[i]:0>2}", col)
def sound(cls, snd, ch=0): if Settings.soundVolume > 0: n = pyxel.play_pos(ch) #if n >=0: # pass # #print("snd=" + hex(n)) if (n == -1): pyxel.play(ch, snd) else: sn = int(n / 100) if sn < len(cls.sound_priority): if cls.sound_priority[sn] < cls.sound_priority[snd]: pyxel.stop(ch) pyxel.play(ch, snd) else: print("Illegal sound number! " + str(sn))
def _update(self): dx, dy = (-1, 0, 1, 0)[self.direction], (0, -1, 0, 1)[self.direction] while True: [npc.update() for npc in self.NPCs] [v() for k, v in self.HotKeys.items() if pyxel.btnp(k)] # ホットキー(開発中のみ?) if btnpA() or btnpB(): if s := [npc for npc in self.NPCs if self.x+dx == npc.x and self.y+dy == npc.y]: # NPCに話しかける、宝箱を開けるなど for it in s[0]._react(): # 会話コルーチンの連続呼び出し self.textbox = TextBox(it, self.textbox.text0 if self.textbox else "") yield self.textbox = None else: # 話す相手(NPC)がいなければ、コマンドメニューをだす command = None def other(): nonlocal command; command = True spells = [i for i in [_ for _ in g_player.spells if Spells[_] <= g_player.mp] if i in ("ヒール")] # MPが足りて、フィールドで使えるものだけ items = [i for i in g_player.items if i in ("やくそう", "もどりふだ", "どうのけん")] # フィールドで使えるものだけ yield SelectBox(-120, 8, ("じゅもん", "どうぐ"), (lambda: SelectBox(-124, 4, spells, [other]*len(spells)), lambda: SelectBox(-124, 4, items, [other]*len(items)))) if command: command = {"ヒール": self._heal, "やくそう": self._yakusou, "もどりふだ": self._return_ticket, "どうのけん": self._soards}[SelectBox.selectedItem] for it in command(): # コルーチン(ジェネレーター)の連続呼び出し self.textbox = TextBox(it, self.textbox.text0 if self.textbox else "") yield self.textbox = None # if btnpB(): pass # Aボタンと同じ動作をするようにした d = arrowkeys((0, 1, 2, 3)) if None is not d: self.idle_start = pyxel.frame_count self.direction, dx, dy = d, (-1, 0, 1, 0)[d], (0, -1, 0, 1)[d] if not self.isblocked(self.x+dx, self.y+dy): # 進める for i in range(1, 8, 1): # マスからマスの途中はアニメ self.sx, self.sy = self.sx + dx, self.sy + dy yield self.x, self.y, self.sx, self.sy = self.x + dx, self.y + dy, 0, 0 if pyxel.tilemap(self.MapID).get(self.x, self.y) == 6: # 毒沼 g_player.hp -= 1 self.fdraw_poison = True if g_player.hp <= 0: yield TextBox(f"{g_player.name}はしんでしまった!🔻") yield Title() elif [command() for x, y, command in self.traps if x == self.x and y == self.y]: # 階段など pass elif m := self.encont_monster(self.x, self.y): yield Battle(m) else: # 進めない pyxel.play(3, 2) while pyxel.play_pos(3) != -1: yield
def __on_draw(self): # Draw frame pyxel.rect(self.x, self.y, self.width, self.height, 7) if self.is_playing_var: x = pyxel.play_pos(0)[1] * 4 + 31 pyxel.rect(x, 25, 3, 123, PIANO_ROLL_CURSOR_PLAY_COLOR) elif self.field_cursor.y == 0: x = self.field_cursor.x * 4 + 31 w = self.field_cursor.width * 4 - 1 col = ( PIANO_ROLL_CURSOR_SELECT_COLOR if self.field_cursor.is_selecting else PIANO_ROLL_CURSOR_EDIT_COLOR ) pyxel.rect(x, 25, w, 123, col) pyxel.blt( self.x, self.y, EDITOR_IMAGE, 0, 7, 193, 72, PIANO_ROLL_BACKGROUND_COLOR, ) pyxel.blt( self.x, self.y + 72, EDITOR_IMAGE, 0, 7, 193, 51, PIANO_ROLL_BACKGROUND_COLOR, ) # Draw notes notes = self.get_field(0) for i, note in enumerate(notes): pyxel.rect( i * 4 + 31, 143 - note * 2, 3, 3, PIANO_ROLL_NOTE_COLOR if note >= 0 else PIANO_ROLL_REST_COLOR, )
def __on_update(self): if self.is_playing_var: self.is_playing_var = None for i in range(pyxel.NUM_CHANNELS): if pyxel.play_pos(i) is not None: self.is_playing_var = True break if pyxel.btnp(pyxel.KEY_SPACE): if self.is_playing_var: self._stop_button.is_pressed_var = True else: self._play_button.is_pressed_var = True if self.is_playing_var: return if not self._play_button.is_enabled_var: self._stop() if self._loop_button.is_enabled_var and pyxel.btnp(pyxel.KEY_L): self.should_loop_var = not self.should_loop_var self.field_cursor.process_input()
def Update(self): self.controller.Update() if 9 in self.controller.up_list: self.Clear() return if not self.game: if pyxel.play_pos(0) != -1: pyxel.stop(0) return if pyxel.play_pos(0) == -1: pyxel.playm(0, loop=True) if self.enemy_pre_position == self.enemy_position: self.game_count += 1 if self.game_count > 30: self.game = False print('[###,###]CLEAR THE GAME') return else: self.game_count = 0 self.pre_pos = self.pos[:] self.pos[0] += self.controller.stick[0] * self.move_scale self.pos[1] += self.controller.stick[1] * self.move_scale self.enemy_pre_position = self.enemy_position[:] self.enemy_position[0] += self.enemy_normal[0] self.enemy_position[1] += self.enemy_normal[1] result = self.field.JudgeLine(self.field.border_line, self.field.border_line_sub, self.enemy_position) if len(result) > 0: self.enemy_position = self.enemy_pre_position[:] self.enemy_pre_normal = self.enemy_normal[:] self.enemy_normal = [0, 0] start_time = time() while 2 > time() - start_time and (self.enemy_normal == [0, 0] or self.enemy_normal == self.enemy_pre_normal): self.enemy_normal = [[ -1 * self.move_scale, 0, 1 * self.move_scale ][ri(-1, 1)], [-1 * self.move_scale, 0, 1 * self.move_scale][ri(-1, 1)]] if not 2 > time() - start_time: self.game = False self.game_message = 'GAMEOVER' print('[###,###]GAMEOVER') return result = self.field.JudgeLine(self.field.creation_line, self.field.creation_line_sub, self.enemy_position) if len(result) > 0: self.game = False self.game_message = 'GAMEOVER' print('[###,###]GAMEOVER') return result = self.field.JudgeLine(self.field.creation_line, self.field.creation_line_sub, self.pos) if len(result) > 0: if self.field.creation[0][0] != self.pos: self.pos = self.pre_pos[:] return self.pre_on_line = self.on_line result = self.field.JudgeLine(self.field.border_line, self.field.border_line_sub, self.pos) if len(result) > 0: self.on_line = True else: self.on_line = False if not self.on_line and self.pre_on_line: # 領域外に出たとき result = self.field.JudgeLine(self.field.border_line, self.field.border_line_sub, self.pre_pos) for num, index in result: normal = [0, 0] normal[num] = self.field.border_line_normal[num][index] if normal == self.controller.stick: self.field.creation[0][0] = self.pre_pos[:] self.field.creation[1][0] = self.field.ConvertToNormal( self.controller.stick) self.field.creation[2][0] = self.pos[:] self.field.CreationUpdate(self.controller.stick, self.pos, self.pre_pos) return self.pos = self.pre_pos[:] self.on_line = True return elif self.on_line and not self.pre_on_line: print(f'[{self.pos[0]:>3},{self.pos[1]:>3}]draw end') self.field.creation[0][1] = self.pos[:] self.field.creation[1][1] = self.field.ConvertToNormal( self.controller.stick) self.field.creation[2][1] = self.pre_pos[:] self.field.CreationUpdate(self.controller.stick, self.pos, self.pre_pos) if self.field.Search(self.enemy_position) == 'error': self.game = False self.game_message = 'GAMEOVER' print('[###,###]GAMEOVER') return self.field.UpdateAllLine() self.field.UpdateBorderLine() self.field.CreationClear() elif not self.on_line and not self.pre_on_line: self.field.CreationUpdate(self.controller.stick, self.pos, self.pre_pos) # 領域の塗りつぶしと割合の計算 if not self.on_line and self.pre_pos != self.pos: pyxel.play(1, 1) elif pyxel.play_pos(1) != -1: pyxel.stop(1)
def __on_is_playing_var_get(self, value): return pyxel.play_pos(0) is not None