def activate(self): self.is_active = True def deactivate(self): self.is_active = False def show_debug_info(self): if not self.debug_mode: return info = f"len(bullets): {len(self.bullets)}\n" info += f"x={self.x:.2f}, y={self.y:.2f}\n" pyxel.text(0, 0, info, 9) # test if __name__ == "__main__": pyxel.init(200, 200) pyxel.load("../asset.pyxres") player = Player(100, 100, 10, 10, 2) player.activate() def update(): player.update() def draw(): pyxel.cls(0) player.draw() pyxel.run(update, draw)
import pyxel def update(): ... def draw(): x = 10 + pyxel.frame_count / 4 pyxel.cls(1) pyxel.blt(x, 60, 0, 3, 0, 10, 16, 0) pyxel.init(180, 120) pyxel.load("assets.pyxres") pyxel.run(update, draw)
def __init__(self): pyxel.init(SCREEN_WIDTH, SCREEN_HEIGHT) pyxel.load('my_resource.pyxel') self.restart() pyxel.run(self.update, self.draw)
self.floor1 = floor(self.player) # インスタンス生成ここまで pyxel.run(self.update, self.draw) def update(self): # 更新 self.stage1.update() # game stage 更新 # 可動物体の更新 # self.floor_initials[0] = self.floor0.update(*self.floor_initials[0]) # self.floor_initials[1] = self.floor1.update(*self.floor_initials[1]) self.player.update() self.floor0.update() # self.do_you_hit(0) # self.do_you_hit(1) def draw(self): # 描画 self.stage1.draw() self.floor0.draw() self.floor1.draw() self.player.draw() ############################################################ ### 実行 ############################################################ pyxel.init(WINDOW_WIDTH, WINDOW_HIGHT, caption="Be cool!!") # ウィンドウを初期化 pyxel.load("./assets.pyxel") start_screen()
{} {} {} | {} {} {} | {} {} {} --------------------- {} {} {} | {} {} {} | {} {} {} {} {} {} | {} {} {} | {} {} {} {} {} {} | {} {} {} | {} {} {} """.format(*[ val if val else ' ' for row in update_board(puzzle_board, 4, 4, 8) for val in row ])) pyxel.cls(3) pyxel.text(1, 1, "8", 0) # pyxel.show() is_valid = True print(pyxel.load('my_resource.pyxres', True, True)) image = pyxel.image(0) print(dir(image)) pyxel.mouse(True) def draw(): global puzzle_board global solution_board global is_valid global cell_selected global selected_value global game_won if game_won: pyxel.cls(10) # Make bakcground yellow if game is won
def __init__(self, resource_file): resource_file = os.path.join(os.getcwd(), resource_file) root, ext = os.path.splitext(resource_file) if ext != ".pyxel": resource_file += ".pyxel" pyxel.init(APP_WIDTH, APP_HEIGHT, caption="Pyxel Editor - {}".format(resource_file)) try: pyxel.load(resource_file) except FileNotFoundError: pass super().__init__(None, 0, 0, pyxel.width, pyxel.height) self._resource_file = resource_file self._editor_list = [ ImageEditor(self), TileMapEditor(self), SoundEditor(self), MusicEditor(self), ] self._editor_button = RadioButton(self, 1, 1, 3, EDITOR_IMAGE_X, EDITOR_IMAGE_Y, 4, 0) self._undo_button = ImageButton(self, 48, 1, 3, EDITOR_IMAGE_X + 36, EDITOR_IMAGE_Y) self._redo_button = ImageButton(self, 57, 1, 3, EDITOR_IMAGE_X + 45, EDITOR_IMAGE_Y) self._save_button = ImageButton(self, 75, 1, 3, EDITOR_IMAGE_X + 54, EDITOR_IMAGE_Y) self.help_message = "" self._editor_button.add_event_handler( "change", lambda value: self.set_editor(value)) self.add_event_handler("update", self.__on_update) self.add_event_handler("draw", self.__on_draw) self._undo_button.add_event_handler("press", self.__on_undo_button_press) self._undo_button.add_event_handler("repeat", self.__on_undo_button_press) self._redo_button.add_event_handler("press", self.__on_redo_button_press) self._redo_button.add_event_handler("repeat", self.__on_redo_button_press) self._save_button.add_event_handler("press", self.__on_save_button_press) self._editor_button.add_event_handler( "mouse_hover", self.__on_editor_button_mouse_hover) self._undo_button.add_event_handler("mouse_hover", self.__on_undo_button_mouse_hover) self._redo_button.add_event_handler("mouse_hover", self.__on_redo_button_mouse_hover) self._save_button.add_event_handler("mouse_hover", self.__on_save_button_mouse_hover) self.set_editor(0) image_file = os.path.join(os.path.dirname(__file__), "assets", "editor_160x160.png") pyxel.image(3, system=True).load(EDITOR_IMAGE_X, EDITOR_IMAGE_Y, image_file) pyxel.mouse(True) pyxel.run(self.update_widgets, self.draw_widgets)
def __init__(self): pyxel.init(width=WIDTH, height=HEIGHT, caption="Flappy Bird", fps=35) pyxel.load(assets) self.reset() pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(250, 180, caption="Sprites") pyxel.load("asset/asset.pyxel") pyxel.playm(0, loop=True) # play music NO.0 pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(WIDTH, HEIGHT) pyxel.load('quest.pyxres') self.myChara = Chara.MyChara() pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(WINDOW_WIDTH, WINDOW_HEIGHT, caption=WINDOW_TITLE) pyxel.load(PYXEL_FILE_NAME) pyxel.run(self.update, self.draw)
from random import randint as RDI from pyxel import init, load, playm, run, btnp, KEY_Q, btn, KEY_LEFT, GAMEPAD_1_LEFT, KEY_RIGHT, GAMEPAD_1_RIGHT, play, cls, blt, text import pyxel W = H = 160 score = pVY = 0 pX, pY, p_alive = 72, -16, 1 cl_far, cl_near = [(-10, 75), (40, 65), (90, 60)], [(10, 25), (70, 35), (H, 15)] floor = [(i * 60, RDI(8, 104), 1) for i in range(4)] fruit = [(i * 60, RDI(0, 104), RDI(0, 2), 1) for i in range(4)] _, __, ___ = init(W, H, caption="Pyxel Jump", scale=1), load("assets/jump_game.pyxres"), playm(0, loop=1) def update(): global pX, pY, pVY, p_alive, score if btnp(KEY_Q): quit() if btn(KEY_LEFT) or btn(GAMEPAD_1_LEFT): pX = max(pX - 2, 0) if btn(KEY_RIGHT) or btn(GAMEPAD_1_RIGHT): pX = min(pX + 2, pyxel.width - 16) for i, (x, y, a) in enumerate(floor): # update_floor if a and x - 16 <= pX <= x + 40 and y - 16 <= pY <= y + 8 and 0 < pVY: a, score, pVY, _ = 0, score + 10, -12, play(3, 3) floor[i] = (x - 4 + 240, RDI(8, 104), 1) if x - 4 < -40 else (x - 4, y + (a == 0) * 6, a) for i, (x, y, k, a) in enumerate(fruit): if a and abs(x - pX) < 12 and abs(y - pY) < 12: a, score, pVY, _ = 0, score + (k + 1) * 100, min(pVY, -8), play(3, 4) fruit[i] = (x - 2 + 240, RDI(0, 104), RDI(0, 2), 1) if x - 2 < -40 else (x - 2, y, k, a)
def __init__(self): pyxel.init(self.W, self.H, caption="Flocking", fps=self.FPS) pyxel.load("asset/slime.pyxel") self.flock = FlockingBoid(self.FLOCK_SIZE, self.OBSTACLE_SIZE) # pyxel.mouse(visible=True) pyxel.run(self.update, self.draw)
import random import pyxel import sqlite3 as sqlite pyxel.init(255, 255) # assets pyxel.load('resources.pyxel') # SQLITE CONTAINMENT AREA con = sqlite.connect('spaceShooter.sqlite3') cur = con.cursor() try: cur.execute("SELECT * FROM highs") except sqlite.Error: cur.execute( "CREATE TABLE highs(id INTEGER PRIMARY KEY, high TEXT, value REAL)") cur.execute("INSERT INTO Highs VALUES(1, 'Score', 0)") cur.execute("INSERT INTO highs VALUES(2, 'Speed', 1.0)") con.commit() finally: cur.execute("SELECT * FROM highs") highs = cur.fetchall() con.close() # END SQLITE CONTAINMENT AREA # variables startWave = [[128, 50, 0], [50, 50, 1], [32, 50, 0], [64, 60, 1]] playerX = 125 playerY = 200 spawnCounter = 0 moveCounter = 0 score = 0
def __init__(self): pyxel.init(128, 128, caption="Snake Game", fps=5) pyxel.load( os.path.dirname(os.path.abspath(__file__)) + "/assets.pyxel") pyxel.run(self.update, self.draw)
def init(): pyxel.init(250, 150, caption='NASU') pyxel.load('assets/nasu.pyxres') drawBackGround()
def update(self): pyxel.load('pyxresのファイル') #qを押した時終了 if pyxel.btnp(pyxel.KEY_Q): pyxel.quit() self.draw_c()
def __init__(self): self.gatos = [] pyxel.init(200, 200) pyxel.mouse(True) pyxel.load('gato.pyxel') pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(160, 144, fps=30, caption="Tetris") pyxel.load("assets/tetris.pyxres") self.setup() pyxel.run(self.update, self.draw)
def __init__(self): WIDTH = 192 HEIGHT = 250 CAPTION = "Mario Game Beta 5.0" self.mario = Mario() self.kong = Donkey() self.win_condition = False self.barrels = {} ####################### self.platforms = {} for i in range(1, 24): if i < 3: name = 'platform_' + str(i) x = 16 * (i - 1) y = 242 obj = statics.Platform(x, y) self.platforms[name] = obj elif i < 14: for j in range(2): if j == 0: name = 'platform_' + str(i) + '.' + str(j + 1) x = 16 * (i - 1) y = 242 - (i - 2) obj = statics.Platform(x, y) self.platforms[name] = obj elif j == 1: name = 'platform_' + str(i) + '.' + str(j + 1) x = 16 * (i - 1) y = 140 - (i - 2) obj = statics.Platform(x, y) self.platforms[name] = obj elif i > 13: if i == 16: name = 'platform_' + str(i) x = 16 * (i - 15) y = 180 + 1 obj = statics.Platform(x, y) self.platforms[name] = obj else: name = 'platform_' + str(i) x = 16 * (i - 15) y = 180 + (i - 15) obj = statics.Platform(x, y) self.platforms[name] = obj for i in range(10): if i < 3: name = 'platform' + str(100 + i) x = 16 * i y = 70 obj = statics.Platform(x, y) self.platforms[name] = obj else: name = 'platform' + str(100 + i) x = 16 * i y = 70 + (i - 2) obj = statics.Platform(x, y) self.platforms[name] = obj for i in range(6): name = 'platform' + str(200 + i) x = 100 + 16 * i y = 40 obj = statics.Platform(x, y) self.platforms[name] = obj ################ self.invisiplats = {} name = 'inv_1' x = 145 y = 188 obj = statics.InvisiPlat(x, y) self.invisiplats[name] = obj name = 'inv_2' x = 160 y = 77 obj = statics.InvisiPlat(x, y) self.invisiplats[name] = obj name = 'inv_3' x = 32 y = 139 obj = statics.InvisiPlat(x, y) self.invisiplats[name] = obj ################ self.ladders = {} name = 'ladder_1' x = 118 yl = 229 yh = 187 obj = statics.Ladder(x, yh, yl) self.ladders[name] = obj name = 'ladder_2' x = 50 yl = 176 yh = 138 obj = statics.Ladder(x, yh, yl) self.ladders[name] = obj name = 'ladder_3' x = 130 yl = 126 yh = 76 obj = statics.Ladder(x, yh, yl) self.ladders[name] = obj name = 'ladder_4' x = 101 yl = 67 yh = 41 obj = statics.Ladder(x, yh, yl) self.ladders[name] = obj ################## self.scores_path = 'highscores.txt' try: with open(self.scores_path, "r") as file: self.highscores = eval(file.readline()) except: self.highscores = [] for i in range(5): self.highscores.append(0) with open(self.scores_path, "w") as file: file.write(str(self.highscores)) ################## """ We thought at first that ladders could be iterably generated, but soon changed our mind. self.ladders = {} for i in range(1,9): name = 'ladder_' + str(i) x = 117 y = 236-6*i obj = classes.Ladder(x,y) self.ladders[name] = obj """ pyxel.init(WIDTH, HEIGHT, caption=CAPTION) pyxel.load("opjects.pyxres") pyxel.playm(0, loop=True) pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(200, 150, caption='Sound Play') pyxel.load('make_sound.pyxres') # 导入声音文件 pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(255, 160) #window sizeの指定 最大(255,255) pyxel.load("picture.pyxres") #画像読み込み pyxel.run(self.update_menu, self.draw_menu)
def __on_update(self): if pyxel._drop_file: ext = os.path.splitext(pyxel._drop_file)[1] if ext == pyxel.RESOURCE_FILE_EXTENSION: pyxel.stop() if pyxel.btn(pyxel.KEY_CONTROL) or pyxel.btn(pyxel.KEY_SUPER): editor = self._editor_list[self._editor_button.value] editor.reset_history() if isinstance(editor, ImageEditor): pyxel.load(pyxel._drop_file, tilemap=False, sound=False, music=False) elif isinstance(editor, TileMapEditor): pyxel.load(pyxel._drop_file, image=False, sound=False, music=False) elif isinstance(editor, SoundEditor): pyxel.load(pyxel._drop_file, image=False, tilemap=False, music=False) elif isinstance(editor, MusicEditor): pyxel.load(pyxel._drop_file, image=False, tilemap=False, sound=False) else: for editor in self._editor_list: editor.reset_history() pyxel.load(pyxel._drop_file) pyxel._caption(pyxel._drop_file) else: self._editor_list[ self._editor_button.value].call_event_handler( "drop", pyxel._drop_file) if pyxel.btn(pyxel.KEY_LEFT_ALT) or pyxel.btn(pyxel.KEY_RIGHT_ALT): editor = self._editor_button.value editor_count = len(self._editor_list) if pyxel.btnp(pyxel.KEY_LEFT): self._set_editor((editor - 1) % editor_count) elif pyxel.btnp(pyxel.KEY_RIGHT): self._set_editor((editor + 1) % editor_count) editor = self._editor_list[self._editor_button.value] self._undo_button.is_enabled = editor.can_undo self._redo_button.is_enabled = editor.can_redo if pyxel.btn(pyxel.KEY_CONTROL) or pyxel.btn(pyxel.KEY_SUPER): if pyxel.btnp(pyxel.KEY_S): self._save_button.press() if editor.can_undo and pyxel.btnp(pyxel.KEY_Z, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME): self._undo_button.press() if editor.can_redo and pyxel.btnp(pyxel.KEY_Y, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME): self._redo_button.press()
import pyxel def update(): if pyxel.btnp(pyxel.KEY_Q): pyxel.quit() def draw(): pyxel.cls(0) pyxel.circ(80, 60, 20, 8) pyxel.circ(80, 60, 15, 9) pyxel.circ(80, 60, 10, 10) pyxel.circ(80, 60, 5, 0) pyxel.blt(66, 90, 0, 0, 0, 16, 16, 0) pyxel.init(160, 120, caption="Eye of Sauron") pyxel.load('01_eye_of_sauron.pyxel') pyxel.run(update, draw)
def __init__(self, resource_file): resource_file = os.path.join(os.getcwd(), resource_file) root, ext = os.path.splitext(resource_file) if ext != pyxel.RESOURCE_FILE_EXTENSION: resource_file += pyxel.RESOURCE_FILE_EXTENSION pyxel.init(APP_WIDTH, APP_HEIGHT, caption="Pyxel Editor - {}".format(resource_file)) pyxel.mouse(True) if os.path.exists(resource_file): pyxel.load(resource_file) if ext == ".pyxel": resource_file = root + pyxel.RESOURCE_FILE_EXTENSION super().__init__(None, 0, 0, pyxel.width, pyxel.height) self._resource_file = resource_file self._editor_list = [ ImageEditor(self), TileMapEditor(self), SoundEditor(self), MusicEditor(self), ] self._editor_button = RadioButton( self, 1, 1, pyxel.IMAGE_BANK_FOR_SYSTEM, EDITOR_IMAGE_X, EDITOR_IMAGE_Y, 4, 0, ) self._undo_button = ImageButton( self, 48, 1, pyxel.IMAGE_BANK_FOR_SYSTEM, EDITOR_IMAGE_X + 36, EDITOR_IMAGE_Y, ) self._redo_button = ImageButton( self, 57, 1, pyxel.IMAGE_BANK_FOR_SYSTEM, EDITOR_IMAGE_X + 45, EDITOR_IMAGE_Y, ) self._save_button = ImageButton( self, 75, 1, pyxel.IMAGE_BANK_FOR_SYSTEM, EDITOR_IMAGE_X + 54, EDITOR_IMAGE_Y, ) self.help_message = "" self._editor_button.add_event_handler( "change", lambda value: self._set_editor(value)) self.add_event_handler("update", self.__on_update) self.add_event_handler("draw", self.__on_draw) self._undo_button.add_event_handler("press", self.__on_undo_button_press) self._undo_button.add_event_handler("repeat", self.__on_undo_button_press) self._redo_button.add_event_handler("press", self.__on_redo_button_press) self._redo_button.add_event_handler("repeat", self.__on_redo_button_press) self._save_button.add_event_handler("press", self.__on_save_button_press) self._editor_button.add_event_handler( "mouse_hover", self.__on_editor_button_mouse_hover) self._undo_button.add_event_handler("mouse_hover", self.__on_undo_button_mouse_hover) self._redo_button.add_event_handler("mouse_hover", self.__on_redo_button_mouse_hover) self._save_button.add_event_handler("mouse_hover", self.__on_save_button_mouse_hover) image_file = os.path.join(os.path.dirname(__file__), "assets", EDITOR_IMAGE_NAME) pyxel.image(pyxel.IMAGE_BANK_FOR_SYSTEM, system=True).load(EDITOR_IMAGE_X, EDITOR_IMAGE_Y, image_file) self._set_editor(0) pyxel.run(self.update_widgets, self.draw_widgets)
def __init__(self): pyxel.init(WIDTH, HEIGHT, caption="SpaceShooter!", fps=60) self.assets = pyxel.load("assets.pyxel") self.reset() pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(160, 120, caption="test lol") pyxel.load("assets/data.pyxres") pyxel.run(self.update, self.draw)
import pyxel import random pyxel.init(256, 256) pyxel.load("my_resource.pyxres") # データファイル読込 pyxel.play(2, 0) # チャンネル2にSOUND 0を流す
def __init__(self): pyxel.init(WIDTH, HEIGHT) pyxel.load("mychara.pyxres") pyxel.run(self.update, self.draw)
def __init__(self): ''' クラス初期化 ''' # コマンドライン引数取得 args = sys.argv print(len(args)) print(args) if len(args) != 7: args = ["", "HIDER_LV1", "6", "6", "5", "2", "1"] # StateStackの初期化 stateStack.clear() # Pyxel初期化 pyxel.init(256, 192) pyxel.load("../source/assets/onyxofblack.pyxres") # プレイヤーパーティ生成 playerParty.initialize() level = int(args[2]) for idx in range(5): member = HumanGenerator.generate(level) member.isPlayer = True # 装備の指定 member.weapon = weaponParams[int( args[3])] if args[3] != "" else None member.armor = armorParams[int(args[4])] if args[4] != "" else None member.shield = shieldParams[int( args[5])] if args[5] != "" else None member.helmet = helmetParams[int( args[6])] if args[6] != "" else None _log = member.name _log += " level=" + str(member.level) _log += " life=" + str(member.life) _log += " str=" + str(member.strength) _log += "+" + \ str(member.weapon.attack if member.weapon != None else 0) _log += " def=" + str(member.defend) _log += "+" + \ str(member.armor.armor if member.armor != None else 0) _log += "+" + \ str(member.shield.armor if member.shield != None else 0) _log += "+" + \ str(member.helmet.armor if member.helmet != None else 0) _log += " dex=" + str(member.dexterity) _log += " weapon=" _log += member.weapon.name if member.weapon != None else "None" _log += " armor=" _log += member.armor.name if member.armor != None else "None" _log += " shield=" _log += member.shield.name if member.shield != None else "None" _log += " helm=" _log += member.helmet.name if member.helmet != None else "None" print(_log) playerParty.addMember(member) # 敵パーティー生成 enemyParty.generate(monsterParams[args[1]]) for value in enemyParty.memberList: print(value) # BattleStateをstateStackに登録 stateStack.push(State.BATTLE) pyxel.run(self.update, self.draw)
def _pyxel_init(): pyxel.init(160, 120, caption='Hello: ②ø†∞') pyxel.load('test_resource.pyxel') import sound pyxel.run(self.update, self.draw)