def btnpA(): return pyxel.btnp(pyxel.GAMEPAD_1_A) or pyxel.btnp( pyxel.KEY_1) or pyxel.btnp(pyxel.KEY_KP_1) or pyxel.btnp( pyxel.KEY_Z) or pyxel.btnp(pyxel.MOUSE_LEFT_BUTTON)
def update(self): if pyxel.btnp(pyxel.KEY_Q): pyxel.quit() self.update_player()
def checkLeftP(): return pyxel.btnp(pyxel.KEY_LEFT, KEY_HOLD, KEY_PERIOD) or pyxel.btnp( pyxel.GAMEPAD_1_LEFT, KEY_HOLD, KEY_PERIOD)
def update(self): if pyxel.btnp(pyxel.KEY_Q): pyxel.quit() self.rect_b.x = pyxel.mouse_x - self.rect_b.w * 0.5 self.rect_b.y = pyxel.mouse_y - self.rect_b.h * 0.5
def update(self): if pyxel.btnp(pyxel.KEY_Q): pyxel.quit() # ====== ctrl cat ====== dx = pyxel.mouse_x - self.mcat.pos.x # x軸方向の移動量(マウス座標 - cat座標) dy = pyxel.mouse_y - self.mcat.pos.y # y軸方向の移動量(マウス座標 - cat座標) if dx != 0: self.mcat.update(pyxel.mouse_x, pyxel.mouse_y, dx) # 座標と向きを更新 elif dy != 0: self.mcat.update(pyxel.mouse_x, pyxel.mouse_y, self.mcat.vec) # 座標のみ更新(真上or真下に移動) # ====== ctrl enemy ====== if pyxel.frame_count % 30 == 1: # 画面の右端から new_enemy = Enemy(self.IMG_ID2) new_enemy.update(random.randint(WINDOW_W, WINDOW_W+5), random.randint(0, WINDOW_H+5), -self.mcat.vec) self.Enemies.append(new_enemy) # 画面の左端から new_enemy = Enemy(self.IMG_ID2) new_enemy.update(random.randint(-5, 0), random.randint(0, WINDOW_H+5), -self.mcat.vec) self.Enemies.append(new_enemy) enemy_count = len(self.Enemies) for i in range(enemy_count): # P制御 ex = (self.mcat.pos.x - self.Enemies[i].pos.x) ey = (self.mcat.pos.y - self.Enemies[i].pos.y) Kp = self.Enemies[i].speed if ex != 0 or ey != 0: self.Enemies[i].update(self.Enemies[i].pos.x + ex * Kp, self.Enemies[i].pos.y + ey * Kp, self.mcat.vec) # 当たり判定(敵キャラと猫) if ((self.mcat.pos.x < self.Enemies[i].pos.x + ENEMY_W) and (self.Enemies[i].pos.x + ENEMY_W < self.mcat.pos.x + CAT_W) and (self.mcat.pos.y < self.Enemies[i].pos.y + ENEMY_H) and (self.Enemies[i].pos.y + ENEMY_H < self.mcat.pos.y + CAT_H) or (self.mcat.pos.x < self.Enemies[i].pos.x) and (self.Enemies[i].pos.x < self.mcat.pos.x + CAT_W) and (self.mcat.pos.y < self.Enemies[i].pos.y + ENEMY_H) and (self.Enemies[i].pos.y + ENEMY_H < self.mcat.pos.y + CAT_H) or (self.mcat.pos.x < self.Enemies[i].pos.x + ENEMY_W) and (self.Enemies[i].pos.x + ENEMY_W < self.mcat.pos.x + CAT_W) and (self.mcat.pos.y < self.Enemies[i].pos.y) and (self.Enemies[i].pos.y < self.mcat.pos.y + CAT_H) or (self.mcat.pos.x < self.Enemies[i].pos.x) and (self.Enemies[i].pos.x < self.mcat.pos.x + CAT_W) and (self.mcat.pos.y < self.Enemies[i].pos.y) and (self.Enemies[i].pos.y < self.mcat.pos.y + CAT_H)): # Game Overフラグを立てる self.GameOver_flag = 1 # ====== ctrl Ball ====== if pyxel.btnp(pyxel.MOUSE_LEFT_BUTTON): new_ball = Ball() if self.mcat.vec > 0: new_ball.update(self.mcat.pos.x + CAT_W/2 + 6, self.mcat.pos.y + CAT_H/2, self.mcat.vec, new_ball.size, new_ball.color) else: new_ball.update(self.mcat.pos.x + CAT_W/2 - 6, self.mcat.pos.y + CAT_H/2, self.mcat.vec, new_ball.size, new_ball.color) self.Balls.append(new_ball) ball_count = len(self.Balls) for i in range(ball_count): if 0 < self.Balls[i].pos.x and self.Balls[i].pos.x < WINDOW_W: # Ball update if self.Balls[i].vec > 0: self.Balls[i].update(self.Balls[i].pos.x + self.Balls[i].speed, self.Balls[i].pos.y, self.Balls[i].vec, self.Balls[i].size, self.Balls[i].color) else: self.Balls[i].update(self.Balls[i].pos.x - self.Balls[i].speed, self.Balls[i].pos.y, self.Balls[i].vec, self.Balls[i].size, self.Balls[i].color) # 当たり判定(敵キャラとボール) enemy_count = len(self.Enemies) for j in range(enemy_count): if ((self.Enemies[j].pos.x < self.Balls[i].pos.x) and (self.Balls[i].pos.x < self.Enemies[j].pos.x + ENEMY_W) and (self.Enemies[j].pos.y < self.Balls[i].pos.y) and (self.Balls[i].pos.y < self.Enemies[j].pos.y + ENEMY_H)): # 消滅(敵インスタンス破棄) del self.Enemies[j] if not self.GameOver_flag: self.Score += 100 break else: del self.Balls[i] ball_count -= 1 break
def update100(self): self.mouseManager.update() if self.state >= 100 and self.state < 200: if self.mouseManager.visible: n = gcommon.checkMouseMenuPos(self.menuRects) if n != -1: self.menuPos = n if gcommon.checkUpP(): BGM.sound(gcommon.SOUND_MENUMOVE) self.menuPos = (self.menuPos - 1) % 5 elif gcommon.checkDownP(): BGM.sound(gcommon.SOUND_MENUMOVE) self.menuPos = (self.menuPos + 1) % 5 elif pyxel.btnp(pyxel.KEY_T): gcommon.app.startStageSelect() return if self.menuPos == TITLEMENU_START: n = -1 if self.mouseManager.visible: n = gcommon.checkMouseMenuPos(self.difficultyRects) if gcommon.checkLeftP() or (gcommon.checkShotKeyP() and n == 0): if self.difficulty > 0: BGM.sound(gcommon.SOUND_MENUMOVE) self.difficulty -= 1 return elif gcommon.checkRightP() or (gcommon.checkShotKeyP() and n == 1): if self.difficulty < 2: BGM.sound(gcommon.SOUND_MENUMOVE) self.difficulty += 1 return elif gcommon.checkShotKeyRectP( self.menuRects[TITLEMENU_START]): BGM.stop() BGM.sound(gcommon.SOUND_GAMESTART) # ここですぐにはゲームスタートしない self.state = 200 self.cnt = 0 return elif self.menuPos == TITLEMENU_CUSTOMSTART: if gcommon.checkShotKeyRectP( self.menuRects[TITLEMENU_CUSTOMSTART]): BGM.sound(gcommon.SOUND_MENUMOVE) gcommon.app.startCustomStartMenu() return elif self.menuPos == TITLEMENU_BOSSRUSHSTART: if gcommon.checkShotKeyRectP( self.menuRects[TITLEMENU_BOSSRUSHSTART]): BGM.sound(gcommon.SOUND_MENUMOVE) gcommon.app.startBossRushStartMenu() return elif self.menuPos == TITLEMENU_OPTION: if gcommon.checkShotKeyRectP(self.menuRects[TITLEMENU_OPTION]): BGM.sound(gcommon.SOUND_MENUMOVE) gcommon.app.startOption() return elif self.menuPos == TITLEMENU_EXIT: if gcommon.checkShotKeyRectP(self.menuRects[TITLEMENU_EXIT]): pyxel.quit() if self.state == 102: # 明るくなる if self.subCnt > 3: self.subState += 1 self.subCnt = 0 if self.subState == len(TitleScene.colorTable3): self.subState = len(TitleScene.colorTable3) - 1 self.state = 103 self.subCnt += 1 elif self.state == 103: # 戻る if self.subCnt > 3: self.subState -= 1 self.subCnt = 0 if self.subState == 0: self.state = 104 self.cnt = 0 return self.subCnt += 1 elif self.state == 104: if self.subCnt > 32: self.state = 100 self.cnt = 0 return self.subCnt += 1 elif self.state == 200: # GAME START if self.cnt > 40: gcommon.app.startNormalGame(self.difficulty) self.cnt += 1 if self.cnt >= 5 * 60: self.cnt = 0 if self.state == 100: self.state = 102 self.subState = 0 self.subCnt = 0
def update(self): if pyxel.btnp(pyxel.KEY_Q): pyxel.quit()
def update(self) -> None: ''' 各フレームの処理。\n enqueueした後、completeするまでの間、各Stateのupdateメソッドは実行されず、このメソッドが呼ばれる。 ''' super().update() # メッセージ表示中の場合 if self.status == statusEnum.SHOW_MESSAGE: # 次のカラムへ self.messageCol += 1 # カラム数がその行の文字数を超えたら、カラムを戻して次の行へ if self.messageCol > len( self.messageList[self.idx + self.messageRow].message): self.messageCol = 0 self.messageRow += 1 # すべてのメッセージ、または現画面の最大行まで表示していなければ何もしない if self.messageRow < 5 and self.idx + self.messageRow < len( self.messageList): pass # すべてのメッセージを表示するか、現画面の最大行の表示を行った場合は、ステータスを変更する else: self.changeStatus() return # SPACEキー入力待ち状態の場合 if self.status == statusEnum.WAIT_KEY: # SPACEキーを押されたか if pyxel.btnp(pyxel.KEY_SPACE): # メッセージリストのインデックスに5加算し、次ページの表示の準備を行う self.idx += 5 # メッセージリストのインデックスがメッセージリストの要素数を超えているか判定する if self.idx < len(self.messageList): # 超えていない場合は、メッセージ表示を行う self.status = statusEnum.SHOW_MESSAGE self.messageRow = 0 self.messageCol = 0 else: # 超えている場合は、完了処理を行う self.complete() return # 選択肢入力待ち状態の場合 if self.status == statusEnum.WAIT_CHOOSE: # 選択肢辞書の要素を走査 for _key, _value in self.chooseDict.items(): # 定義されたいずれかのキーを押されたら、完了処理を行い登録されているコールバック関数を呼び出す。 if pyxel.btnp(_key): # 完了処理を行う self.complete() # コールバック関数実行 if _value != None: if type(_value) is tuple: _value[0](_value[1]) else: _value()
def update_title_scene(self): #ENTERでゲーム画面に遷移 if pyxel.btnp(pyxel.KEY_ENTER): #BGM再生(MUSIC 0番をloop再生) pyxel.playm(0, loop = True) self.scene = SCENE_PLAY
def update(): """This function just maps the Q key to `pyxel.quit`, which works just like `sys.exit`.""" if pyxel.btnp(pyxel.KEY_Q): pyxel.quit()
def update(): global objs, right_held, left_held, camera_x, camera_y, camera_speed, mouse, left_drag_x, left_drag_y, right_drag_x, right_drag_y, left_dragging, right_dragging, time_enabled if px.btnp(px.KEY_Q): px.quit() if px.btnp(px.KEY_1): mouse = MouseCreate() if px.btnp(px.KEY_2): mouse = MouseBlackHole() if px.btnp(px.KEY_SPACE): time_enabled = not time_enabled if px.btn(px.KEY_W): camera_y -= camera_speed if px.btn(px.KEY_S): camera_y += camera_speed if px.btn(px.KEY_D): camera_x += camera_speed if px.btn(px.KEY_A): camera_x -= camera_speed if px.btnp(px.MOUSE_MIDDLE_BUTTON): if "middle_click" in dir(mouse): mouse.middle_click() if px.btn(px.MOUSE_LEFT_BUTTON): if left_held == None: left_held = 0 else: left_held += 1 if left_held == held_time: left_drag_x, left_drag_y = px.mouse_x, px.mouse_y if "left_start_dragging" in dir(mouse): mouse.left_start_dragging() left_dragging = True elif left_held > held_time: if "left_dragging" in dir(mouse): mouse.left_dragging() else: if not left_held == None: if left_held <= held_time: if "left_click" in dir(mouse): mouse.left_click() left_held = None else: left_dragging = False if "left_stop_dragging" in dir(mouse): mouse.left_stop_dragging() left_drag_x, left_drag_y = None, None left_held = None if px.btn(px.MOUSE_RIGHT_BUTTON): if right_held == None: right_held = 0 else: right_held += 1 if right_held == held_time: right_drag_x, right_drag_y = px.mouse_x, px.mouse_y if "right_start_dragging" in dir(mouse): mouse.right_start_dragging() right_dragging = True elif right_held > held_time: if "right_dragging" in dir(mouse): mouse.right_dragging() else: if not right_held == None: if right_held <= held_time: if "right_click" in dir(mouse): mouse.right_click() right_held = None else: if "right_stop_dragging" in dir(mouse): mouse.right_stop_dragging() right_drag_x, right_drag_y = None, None right_dragging = False right_held = None if time_enabled: for self_obj in objs: for other_obj in objs: if other_obj == self_obj: continue self_obj.x_vec += -(4*other_obj.mass*(self_obj.x-other_obj.x))/(((self_obj.x-other_obj.x)**2+(self_obj.y-other_obj.y)**2)**(3/2)) self_obj.y_vec += -(4*other_obj.mass*(self_obj.y-other_obj.y))/(((self_obj.x-other_obj.x)**2+(self_obj.y-other_obj.y)**2)**(3/2)) for obj in objs: obj.x += obj.x_vec obj.y += obj.y_vec for self_obj in objs: for other_obj in objs: if other_obj == self_obj: continue if sqrt((self_obj.x-other_obj.x)**2+(self_obj.y-other_obj.y)**2) < mtor(self_obj.mass)+mtor(other_obj.mass): other_obj.x_vec = other_obj.mass/(other_obj.mass+self_obj.mass) * other_obj.x_vec + self_obj.mass/(other_obj.mass+self_obj.mass) * self_obj.x_vec other_obj.y_vec = other_obj.mass/(other_obj.mass+self_obj.mass) * other_obj.y_vec + self_obj.mass/(other_obj.mass+self_obj.mass) * self_obj.y_vec other_obj.x = other_obj.mass/(other_obj.mass+self_obj.mass) * other_obj.x + self_obj.mass/(other_obj.mass+self_obj.mass) * self_obj.x other_obj.y = other_obj.mass/(other_obj.mass+self_obj.mass) * other_obj.y + self_obj.mass/(other_obj.mass+self_obj.mass) * self_obj.y other_obj.mass += self_obj.mass objs = np.delete(objs, np.where(objs == self_obj), 0)
def update(): global x if pyxel.btnp(pyxel.KEY_Q): pyxel.quit() x = (x + Delta) % 160
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 btnpB(): return pyxel.btnp(pyxel.GAMEPAD_1_B) or pyxel.btnp( pyxel.KEY_2) or pyxel.btnp(pyxel.KEY_KP_2) or pyxel.btnp( pyxel.KEY_X) or pyxel.btnp(pyxel.MOUSE_RIGHT_BUTTON)
def update_title_scene(self): if pyxel.btnp(pyxel.KEY_ENTER): self.scene = SCENE_PLAY
def update(): global step step += 1 if pyxel.btnp(pyxel.KEY_Q): pyxel.quit()
def update(self): if pyxel.btnp(pyxel.KEY_A): # 按 A 键播放音乐 pyxel.play(ch=0, snd=0) elif pyxel.btnp(pyxel.KEY_D): pyxel.play(ch=0, snd=1)
def keys_pressed(self, *keys): for k in keys: if pyxel.btnp(k, 8, 8): return True
def draw_game(self): pyxel.cls(3) ##################################### # Dad talking to us @ top of screen # ##################################### pyxel.rect(0, 0, SCREEN_WIDTH, 48, 0) pyxel.blt(SCREEN_MARGIN, SCREEN_MARGIN, 0, DAD[0], DAD[1], 32, 32, 0) line_to_say = self.WHAT_LINE_IS_IT_ANYWAYS # if player is hit by shootie, then dad sasses. # # we pick from options and display the sass for # # ~200 frames # if self.dad_sassin: if self.line_chosen: if self.dialogue_timer == 0: self.dialogue_timer = pyxel.frame_count elif pyxel.frame_count - self.dialogue_timer > 200: # special case where dad sass is 2 lines # if self.DAD_LINE == 20: self.DAD_LINE = 21 self.dialogue_timer = 0 else: self.DAD_LINE = 14 self.dad_sassin = False self.line_chosen = False self.dialogue_timer = 0 else: self.DAD_LINE = random.randint(17, 20) self.line_chosen = True line_to_say = self.DAD_LINE pyxel.text(48, SCREEN_MARGIN, self.DAD_LINES[line_to_say], 7) ##################################### # GAMEPLAY # DRAWING THE OBJECTS AND PLAYER # IN GAME ##################################### # DRAW BAG OF SOULS AND THE POOF OF WISDOM # pyxel.blt(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, 0, BAG_A_SOULS[0], BAG_A_SOULS[1], 32, 32, 0) pyxel.blt(SCREEN_WIDTH - SCREEN_MARGIN - 32, 24, 0, POOF[0], POOF[1], 32, 16, 0) if (self.signal_new_tip): pyxel.blt(SCREEN_WIDTH - SCREEN_MARGIN - 27, 16, 0, FULL[0], FULL[1], 16, 16, 0) # DRAW PLAYER # if self.player is None: self.player = Player(SCREEN_WIDTH // 2, 24) if self.hard_mode: self.player.move = 4 self.player.pitchforks = 5 if self.player.dash and ( (pyxel.frame_count - self.dash_timer) > DASH_TIME): self.player.dash = False self.player.draw() self.player.update() if self.player.souls == 3: pyxel.blt(self.player.x, self.player.y - 8, 0, FULL[0], FULL[1], 16, 16, 0) ################ # UPDATE LEVEL # ################ if not self.hard_mode: if self.player.score > 10: self.numLives = 3 if self.player.score > 20: self.numHalos = 3 self.numLives = 7 elif self.player.score > 50: self.numHalos = 5 self.numLives = 10 ################ # INSTRUCTIONS # # AND TIPS # ################ if (self.player.x >= (SCREEN_WIDTH // 2)) and \ (self.player.x <= (SCREEN_WIDTH // 2) + 32) and \ (self.player.y >= SCREEN_HEIGHT // 2) and \ (self.player.y <= SCREEN_HEIGHT // 2 + 32): pyxel.text(SCREEN_WIDTH // 2, (SCREEN_HEIGHT // 2) + 34, "Bag of souls!\noooooh", 10) # Creating tips list based on what's out on the board # # You read tips list if not the first instructions # if (not self.seen_lives and not self.lives == []) or \ (not self.seen_rbs and not self.redbulls == []): self.signal_new_tip = True if not self.lives == [] and (4 not in self.tips_list): self.tips_list.insert(0, 4) if not self.redbulls == [] and (5 not in self.tips_list): self.tips_list.insert(0, 5) if (self.player.x <= SCREEN_WIDTH-SCREEN_MARGIN and \ self.player.x >= SCREEN_WIDTH-SCREEN_MARGIN-32 and \ self.player.y >= 16 and \ self.player.y <= 32): if pyxel.btnp(pyxel.KEY_SPACE): self.reading_tips = True self.next_tip = True # This means you are reading tips and not introduction to poof # if self.reading_tips: if self.next_tip: # This is first instructions # if self.first_tip: if self.tip_idx > 2: self.first_tip = False self.signal_new_tip = False self.tip_idx = 0 self.curr_tip_idx = self.tip_idx else: self.curr_tip_idx = self.tip_idx self.tip_idx = self.tip_idx + 1 # When poof gets new tips then we display the tips list # else: if self.signal_new_tip: if not self.seen_lives and not self.lives == []: self.seen_lives = True self.signal_new_tip = False if not self.seen_rbs and not self.redbulls == []: self.seen_rbs = True self.signal_new_tip = False self.curr_tip_idx = self.tips_list[self.tip_idx % len(self.tips_list)] self.tip_idx = self.tip_idx + 1 self.next_tip = False pyxel.text(64, 24, self.POOF_TIPS[self.curr_tip_idx], 10) # introduction to poof # else: pyxel.text(64, 24, "I am the poof of wisdom!", 10) pyxel.text( 64, 32, "Press [space] to hear my tips.\nI will signal when I get new ones.", 10) else: self.tip_idx = 0 self.reading_tips = False ############## # DRAW SOULS # ############## if len(self.souls) < 14: self.set_souls() else: for soul in self.souls: soul.draw() # DRAW NET TO CATCH SOULS # if pyxel.btn(pyxel.KEY_R): pyxel.blt(self.player.x - 8, self.player.y, 0, NET[0], NET[1], 16, 16, 0) # DRAW LIVES # if len(self.lives) < self.numLives: self.set_lives() else: for life in self.lives: life.draw() # DRAW HALOS # if len(self.halos) == 0: self.set_halos() else: for i in range(0, self.numHalos): self.halos[i].draw() # DRAW RED BULL # if (pyxel.frame_count % 100 == 0): will_redbull = random.randint(0, 100) if will_redbull > 85 and len(self.redbulls) < 5: self.add_elem_to_arr("rbs", self.redbulls, Redbull) for redbull in self.redbulls: redbull.draw() #################### # ITS SHOOTIE TIME # #################### # (SHOOTIES ARE THE BLUE BALLS THAT SHOOT OUT OF HALOS) # # DRAW SHOOTIES # if (pyxel.frame_count % self.shootie_speed == 0): for i in range(0, self.numHalos): diff_x = self.player.x - self.halos[i].x diff_y = self.player.y - self.halos[i].y shootie_move_x = 0 if (diff_x == 0) else (diff_x) / abs(diff_x) shootie_move_y = diff_y / abs(diff_y) if ( diff_x == 0) else (diff_y) / (diff_x) shootie = Shootie(self.halos[i], shootie_move_x, shootie_move_y) self.shooties.append(shootie) shootie.draw() # UPDATE SHOOTIE POS # for shootie in self.shooties: shootie.draw() if shootie.x <= self.player.x + 12 and \ shootie.x >= self.player.x + 4 and \ shootie.y <= self.player.y + 12 and \ shootie.y >= self.player.y + 4: self.shooties.remove(shootie) if self.player.pitchforks > 1: self.player.pitchforks = self.player.pitchforks - 1 self.dad_sassin = True else: pyxel.playm(2, loop=False) self.dead = True self.hard_mode = False # if shootie goes off bounds it dies # if shootie.x <= 0 or \ shootie.x >= SCREEN_WIDTH or \ shootie.y <= 48 or \ shootie.y >= SCREEN_HEIGHT: self.shooties.remove(shootie) # DRAW SCORE # pyxel.text(SCREEN_WIDTH // 2 - 16, 50, "SCORE: {:02}".format(self.player.score), 13) if (self.player.score > self.highscore): self.highscore = self.player.score if self.hard_mode: save_highscore(HARD_HIGH_SCORE_FILE, self.highscore) else: save_highscore(HIGH_SCORE_FILE, self.highscore) pyxel.text(SCREEN_MARGIN, 50, "HIGHSCORE: {:02}".format(self.highscore), 13) # DRAW PITCHFORKS # h_shift = 16 for i in range(self.player.pitchforks): pyxel.blt(SCREEN_WIDTH - h_shift - SCREEN_MARGIN, SCREEN_MARGIN + 36, 0, PITCHFORK[0], PITCHFORK[1], 16, 16, 0) h_shift = h_shift + 16
def update(self): if state.has_set_high_score: if pyxel.btnp(pyxel.KEY_UP) or pyxel.btnp(pyxel.GAMEPAD_1_UP): state.scoreboard.up() elif pyxel.btnp(pyxel.KEY_DOWN) or pyxel.btnp(pyxel.GAMEPAD_1_DOWN): state.scoreboard.down() elif pyxel.btnp(pyxel.KEY_RIGHT) or pyxel.btnp(pyxel.GAMEPAD_1_RIGHT): state.scoreboard.right() elif pyxel.btnp(pyxel.KEY_LEFT) or pyxel.btnp(pyxel.GAMEPAD_1_LEFT): state.scoreboard.left() elif pyxel.btnp(pyxel.KEY_SPACE) or pyxel.btnp(pyxel.GAMEPAD_1_A): state.scoreboard.enter(state.score) state.game.set_state(STATE_MENU) elif pyxel.btnp(pyxel.KEY_SPACE) or pyxel.btnp(pyxel.GAMEPAD_1_A): state.game.set_state(STATE_MENU)
def __on_update(self): if self._is_dragged and not self._is_assist_mode and pyxel.btn( pyxel.KEY_SHIFT): self._is_assist_mode = True x1 = self._press_x y1 = self._press_y x2 = self._last_x y2 = self._last_y if self.parent.tool == TOOL_PENCIL: self._overlay_canvas.clear() self._overlay_canvas.line(x1, y1, x2, y2, self.parent.color) elif self.parent.tool == TOOL_RECTB: self._overlay_canvas.clear() self._overlay_canvas.rectb(x1, y1, x2, y2, self.parent.color, True) elif self.parent.tool == TOOL_RECT: self._overlay_canvas.clear() self._overlay_canvas.rect(x1, y1, x2, y2, self.parent.color, True) elif self.parent.tool == TOOL_CIRCB: self._overlay_canvas.clear() self._overlay_canvas.circb(x1, y1, x2, y2, self.parent.color, True) elif self.parent.tool == TOOL_CIRC: self._overlay_canvas.clear() self._overlay_canvas.circ(x1, y1, x2, y2, self.parent.color, True) if (self.parent.tool == TOOL_SELECT and self._select_x1 >= 0 and pyxel.btn(pyxel.KEY_CONTROL)): if pyxel.btnp(pyxel.KEY_C): if self._is_tilemap_mode: data = pyxel.tilemap(self.parent.tilemap).data else: data = pyxel.image(self.parent.image).data src = data[self.viewport_y + self._select_y1:self.viewport_y + self._select_y2 + 1, self.viewport_x + self._select_x1:self.viewport_x + self._select_x2 + 1, ] self._copy_buffer = src.copy() elif self._copy_buffer is not None and pyxel.btnp(pyxel.KEY_V): x1 = self.viewport_x + self._select_x1 y1 = self.viewport_y + self._select_y1 height, width = self._copy_buffer.shape width -= max(self._select_x1 + width - 16, 0) height -= max(self._select_y1 + height - 16, 0) if self._is_tilemap_mode: data = pyxel.tilemap(self.parent.tilemap).data else: data = pyxel.image(self.parent.image).data dest = data[y1:y1 + height, x1:x1 + width] dest[:, :] = self._copy_buffer[:height, :width] if (pyxel.btn(pyxel.KEY_SHIFT) or pyxel.btn(pyxel.KEY_CONTROL) or pyxel.btn(pyxel.KEY_ALT)): return if pyxel.btnp(pyxel.KEY_LEFT, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME): self.viewport_x -= 8 if pyxel.btnp(pyxel.KEY_RIGHT, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME): self.viewport_x += 8 if pyxel.btnp(pyxel.KEY_UP, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME): self.viewport_y -= 8 if pyxel.btnp(pyxel.KEY_DOWN, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME): self.viewport_y += 8 self.viewport_x = min(max(self.viewport_x, 0), 240) self.viewport_y = min(max(self.viewport_y, 0), 240) self._h_scroll_bar.value = self.viewport_x // 8 self._v_scroll_bar.value = self.viewport_y // 8
def update(self): if self.midi_device_flag: if self.midi_input is not None: if self.midi_input.poll(): self.midi_events = self.midi_input.read(10) print("full midi_events:" + str(self.midi_events)) else: if pyxel.btnp(pyxel.KEY_E): self.add_key(1, 1) if pyxel.btnp(pyxel.KEY_D): self.add_key(1, -1) if pyxel.btnp(pyxel.KEY_R): self.add_key(2, 1) if pyxel.btnp(pyxel.KEY_F): self.add_key(2, -1) if pyxel.btnp(pyxel.KEY_T): self.add_key(3, 1) if pyxel.btnp(pyxel.KEY_G): self.add_key(3, -1) if pyxel.btnp(pyxel.KEY_Y): self.add_key(4, 1) if pyxel.btnp(pyxel.KEY_H): self.add_key(4, -1) if pyxel.btnp(pyxel.KEY_U): self.add_key(5, 1) if pyxel.btnp(pyxel.KEY_J): self.add_key(5, -1) if pyxel.btnp(pyxel.KEY_I): self.add_key(6, 1) if pyxel.btnp(pyxel.KEY_K): self.add_key(6, -1) self.midi_events = [[[ 0, self.key_channel, self.key_value[self.key_channel], 0 ], 0]] print("full midi_events:" + str(self.midi_events)) if pyxel.btnp(pyxel.KEY_Q): if self.midi_device_flag: self.midi_input.close() pygame.midi.quit() pyxel.quit()
def update(self): # ボタン押下 if pyxel.btnp(pyxel.KEY_Q): # 終了 pyxel.quit()
def update(self): if pyxel.btnp(pyxel.KEY_SPACE): self.store.dispatch(increment_counter())
def update(self): self.pal_test_is_enabled = (pyxel.frame_count // 30) % 10 >= 5 self.clip_test_is_enabled = pyxel.btn(pyxel.KEY_SPACE) if pyxel.btnp(pyxel.KEY_Q): pyxel.quit()
def update(self): if pyxel.btnp(pyxel.KEY_Q): pyxel.quit() self.scene_manager.update()
def checkShotKeyRectP(rect): if pyxel.btnp(pyxel.KEY_Z) or pyxel.btnp(pyxel.GAMEPAD_1_A) or pyxel.btnp(pyxel.GAMEPAD_1_Y) \ or (rect.contains(pyxel.mouse_x, pyxel.mouse_y) and pyxel.btnp(pyxel.MOUSE_LEFT_BUTTON)): return True else: return False
def update(self): if pyxel.btnp(pyxel.KEY_W): self.tm_v -= 8 if pyxel.btnp(pyxel.KEY_S): self.tm_v += 8 if pyxel.btnp(pyxel.KEY_A): self.tm_u -= 8 if pyxel.btnp(pyxel.KEY_D): self.tm_u += 8 if pyxel.btnp(pyxel.KEY_0): self.tm = 0 self.tm_u = 0 self.tm_v = 0 if pyxel.btnp(pyxel.KEY_1): self.tm = 1 self.tm_u = 0 self.tm_v = 0 if pyxel.btnp(pyxel.KEY_2): self.tm = 2 self.tm_u = 0 self.tm_v = 0 if pyxel.btnp(pyxel.KEY_3): self.tm = 3 self.tm_u = 0 self.tm_v = 0 if pyxel.btnp(pyxel.KEY_4): self.tm = 4 self.tm_u = 0 self.tm_v = 0 if pyxel.btnp(pyxel.KEY_5): self.tm = 5 self.tm_u = 0 self.tm_v = 0 if pyxel.btnp(pyxel.KEY_6): self.tm = 6 self.tm_u = 0 self.tm_v = 0 if pyxel.btnp(pyxel.KEY_7): self.tm = 7 self.tm_u = 0 self.tm_v = 0 print("Current: " + str(self.tm_u) + ", " + str(self.tm_v) + " Tilemap: " + str(self.tm))
def checkRightP(): return pyxel.btnp(pyxel.KEY_RIGHT, KEY_HOLD, KEY_PERIOD) or pyxel.btnp( pyxel.GAMEPAD_1_RIGHT, KEY_HOLD, KEY_PERIOD)
def update(self): if self.Game_ctr == 0: if pyxel.btnp(pyxel.KEY_S): self.Game_ctr = 1 self.Stage_count = 1 self.Mato = [] elif self.Game_ctr == 1: if pyxel.frame_count % 60 == 0: mato_s = randint(1, 4) for i in range(mato_s): new_mato = mato(randint(10, 90), randint(10, 75), randint(1, 4), 5, 5) self.Mato.append(new_mato) if len(self.bangs) > 0: self.hit_flug += 1 if self.hit_flug > 5: del self.bangs[0] self.hit_flug = 0 for c1 in self.Cara: c1.update() for c2 in self.Cara: if ((c2.pos_x > 100) or (c2.pos_x < 0) or (c2.pos_y) > 100 or (c2.pos_y < 0)): del c2 break if pyxel.btnp(pyxel.MOUSE_LEFT_BUTTON) == True: mouse_x = pyxel.mouse_x mouse_y = pyxel.mouse_y mato_count = len(self.Mato) #self.shot_flug = self.shot_flug + 1 for e in range(mato_count): if ((self.Mato[e].pos_x <= mouse_x <= self.Mato[e].pos_x + 16) and (self.Mato[e].pos_y <= mouse_y <= self.Mato[e].pos_y + 16)): new_bang = Bang(self.Mato[e].pos_x, self.Mato[e].pos_y, self.Mato[e].v) self.bangs.append(new_bang) new_cara = Cara(self.Mato[e].pos_x, self.Mato[e].pos_y, randint(1, 4)) self.Cara.append(new_cara) #self.hit_flug = 0 if self.Mato[e].v == 1: self.score += 10 elif self.Mato[e].v == 2: self.score += 20 elif self.Mato[e].v == 3: self.score += 30 elif self.Mato[e].v == 4: self.score += 50 del self.Mato[e] #self.score = self.score + 100 break #敵に当たったらbreak self.Stage_time += 1 if self.Stage_time >= 700: self.Game_ctr = 2 self.Stage_time = 0 elif self.Game_ctr == 2: self.Stage_time += 1 self.Mato = [] self.Cara = [] self.Movie_flug = True if self.Stage_time >= 100: self.Stage_time = 0 self.Movie_flug = False self.Game_ctr = 3 elif self.Game_ctr == 3: self.Stage_count += 1 self.Game_ctr = 1 if self.Stage_count == 5: self.Game_ctr = 99 elif self.Game_ctr == 99: print("Game end.")