def __init__(self, env): super().__init__() pyxel.image(0).load(0, 0, 'ruby.gif') self.env = env block_width = pyxel.width / GRID_HORIZONTAL_COUNT block_height = pyxel.height / GRID_VERTICAL_COUNT self.height = 20 self.width = 28 player_pos = env.player_pos() self.x = player_pos[0] self.y = player_pos[1] self.v_vert = GRAVITY_VELOCITY_START self.v_hor = 0.0 self.dir = DIR_LEFT self.jump_limit_default = 2 self.jump_limit = self.jump_limit_default
def __on_draw(self): if self._is_tilemap_mode: pyxel.bltm( self.x, self.y, self.parent.image, self.parent.tilemap, self.viewport_x, self.viewport_y, 16, 16, ) for i in range(16): y = self.y + i * 8 for j in range(16): x = self.x + j * 8 val = self._overlay_canvas.data[i, j] if val >= 0: sx = (val % 32) * 8 sy = (val // 32) * 8 pyxel.blt(x, y, self.parent.image, sx, sy, 8, 8) else: for i in range(16): y = self.y + i * 8 for j in range(16): x = self.x + j * 8 val = self._overlay_canvas.data[i, j] if val >= 0: col = self._overlay_canvas.data[i, j] else: data = pyxel.image(self.parent.image).data col = data[self.viewport_y + i, self.viewport_x + j] pyxel.rect(x, y, x + 7, y + 7, col) pyxel.line(self.x, self.y + 63, self.x + 127, self.y + 63, 1) pyxel.line(self.x + 63, self.y, self.x + 63, self.y + 127, 1) if self.parent.tool == TOOL_SELECT and self._select_x1 >= 0: x1 = self._select_x1 * 8 + 12 y1 = self._select_y1 * 8 + 17 x2 = self._select_x2 * 8 + 19 y2 = self._select_y2 * 8 + 24 pyxel.rectb(x1, y1, x2, y2, 0) pyxel.rectb(x1 + 1, y1 + 1, x2 - 1, y2 - 1, 15) pyxel.rectb(x1 + 2, y1 + 2, x2 - 2, y2 - 2, 0)
def __init__(self): # pyxel.init(imp.WINDOW_W, imp.WINDOW_H, caption="Pyxel Shooting", scale=3, fps=60) pyxel.init(imp.WINDOW_W, imp.WINDOW_H, caption="Pyxel Shooting", scale=3, fps=60, palette=[ 0x000000, 0xc8cbd2, 0x000000, 0xa7a5a2, 0xe057cd, 0x335793, 0x099c9e, 0xffffff, 0xef337b, 0x1f2856, 0x000000, 0xffff00, 0x000000, 0x000000, 0x000000, 0x000000 ]) pyxel.load("assets/my_resource.pyxres") pyxel.image(0).load(0, 0, "assets/img0.png") # メインScene タイトル セット self.SetSubScene(SceneTitle()) imp.StarScene = star.Star() pyxel.run(self.update, self.draw)
def __init__(self): self.IMG_ID0 = 0 self.IMG_ID1 = 1 # self.IMG_ID2 = 2 self.IMG_ID0_X = 60 self.IMG_ID0_Y = 65 self.MOUSE_X_PRE = 80 self.MOUSE_Y_PRE = 0 pyxel.init(WINDOW_W, WINDOW_H, caption="Cat Game") pyxel.image(self.IMG_ID0).load(0, 0, "assets/pyxel_logo_38x16.png") pyxel.image(self.IMG_ID1).load(0, 0, "assets/cat_16x16.png") # pyxel.mouse(True) # make instance self.mcat = cat(self.IMG_ID1) self.Balls = [] # self.mouse_count = 0 pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(120, 160, title="Evil Snails In Space") pyxel.image(0).set( 0, 0, [ "00c00c00", "0c7007c0", "0c7007c0", "c703b07c", "77033077", "785cc587", "85c77c58", "0c0880c0", ], ) pyxel.image(0).set( 8, 0, [ "00088000", "00ee1200", "08e2b180", "02882820", "00222200", "00012280", "08208008", "80008000", ], ) pyxel.sound(0).set("a3a2c1a1", "p", "7", "s", 5) pyxel.sound(1).set("a3a2c2c2", "n", "7742", "s", 10) self.scene = SCENE_TITLE self.score = 0 self.background = Background() self.player = Player(pyxel.width / 2, pyxel.height - 20) pyxel.run(self.update, self.draw)
def update(self): if pyxel.btnp(pyxel.KEY_Q): pyxel.quit() if pyxel.btnp(pyxel.MOUSE_LEFT_BUTTON): if (pyxel.mouse_x > self.option1.x and pyxel.mouse_x < (self.option1.x + self.option1.side) and pyxel.mouse_y > self.option1.y and pyxel.mouse_y < (self.option1.y + self.option1.side)): if (self.option1.color == 12): self.option1.color = 0 # pyxel.image(0).load(0, 0, "assets/forest.png") REPLACE WITH CONSEQUENCE else: self.option1.color = 12 pyxel.image(0).load(0, 0, "assets/sunset.png") if (pyxel.mouse_x > self.option2.x and pyxel.mouse_x < (self.option2.x + self.option2.side) and pyxel.mouse_y > self.option2.y and pyxel.mouse_y < (self.option2.y + self.option2.side)): if (self.option2.color == 12): self.option2.color = 0 # pyxel.image(0).load(0, 0, "assets/lake.png") self.gender = 1 else: self.option2.color = 12
def margePyxelFiles(img_file_path, music_file_path, save_to): """img_file + music_file -> marged_file assume 'pixel-artist' and 'music-maker' work together this comine img_bank and music_bank (no check data exist or not)""" # FIXME: the game-window never ended Corretly # check all file extension is .pyxel try: assert os.path.basename(img_file_path).split(".")[-1] == "pyxel" assert os.path.basename(music_file_path).split(".")[-1] == "pyxel" assert os.path.basename(save_to).split(".")[-1] == "pyxel" except AssertionError: print("AssertionError: Check file paths (extension must be .pyxel)") # === Constants from constants.py=== RENDERER_IMAGE_COUNT=4 AUDIO_SOUND_COUNT = 65 AUDIO_MUSIC_COUNT = 8 pyxel.init(1,1) # need to pyxel.load data = {"version": pyxel.VERSION} # load img data from 'img_file_path' pyxel.load(img_file_path) image_list = [ pyxel.image(i).data.dumps() for i in range(RENDERER_IMAGE_COUNT - 1) ] data["image"] = image_list # tilemap_list = [ # (pyxel.tilemap(i).data.dumps(), pyxel.tilemap(i).refimg) # for i in range(RENDERER_TILEMAP_COUNT) # ] # data["tilemap"] = tilemap_list # load music data from 'music_file_path' pyxel.load(music_file_path) sound_list = [pyxel.sound(i) for i in range(AUDIO_SOUND_COUNT - 1)] data["sound"] = sound_list music_list = [pyxel.music(i) for i in range(AUDIO_MUSIC_COUNT - 1)] data["music"] = music_list pickled_data = pickle.dumps(data) with gzip.open(save_to, mode="wb") as fp: fp.write(pickled_data) print("Corretly Saved Data. : {}".format(save_to)) pyxel.quit()
def on_draw(self): for i in range(16): y = self.y + i * 8 for j in range(16): x = self.x + j * 8 if self._canvas[i, j] >= 0: col = self._canvas[i, j] else: data = pyxel.image(self.parent.image_button.value).data col = data[self.edit_y + i, self.edit_x + j] pyxel.rect(x, y, x + 7, y + 7, col) pyxel.line(self.x, self.y + 63, self.x + 127, self.y + 63, 1) pyxel.line(self.x + 63, self.y, self.x + 63, self.y + 127, 1)
def __init__(self): # ウィンドウ初期化 pyxel.init(160, 120, caption="Hello Pyxel") # イメージ 0 番を定義 self.cat = { 'width' : 16, 'height' : 16, 'path' : 'assets/cat_16x16.png', } # 画像の読み込み self.cat['image'] = pyxel.image(0).load(0, 0, self.cat['path']) # エンジン起動 pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(SCREEN_WIDTH, SCREEN_HEIGHT, caption='Blackjack') pyxel.image(0).load(0, 0, 'suits.png') pyxel.image(1).load(0, 0, 'values.png') pyxel.image(2).load(0, 0, 'card_back.png') self.game = GameState() self.debug = Debug() '''self.player = Hand(PLAYER_X, PLAYER_Y) self.dealer = Hand(DEALER_X, DEALER_Y) self.split = Hand(SPLIT_X, SPLIT_Y)''' pyxel.run(self.update, self.draw)
def __on_mouse_up(self, key, x, y): if key != pyxel.KEY_LEFT_BUTTON: return self._is_dragged = False if self.parent.tool >= TOOL_PENCIL and self.parent.tool <= TOOL_CIRC: if self._is_tilemap_mode: dest = pyxel.tilemap( self.parent.tilemap).data[self.viewport_y:self.viewport_y + 16, self.viewport_x:self.viewport_x + 16, ] data = {} data["tilemap"] = self.parent.tilemap data["pos"] = (self.viewport_x, self.viewport_y) data["before"] = dest.copy() index = self._overlay_canvas.data != -1 dest[index] = self._overlay_canvas.data[index] self._overlay_canvas.clear() data["after"] = dest.copy() self.parent.add_edit_history(data) else: dest = pyxel.image( self.parent.image).data[self.viewport_y:self.viewport_y + 16, self.viewport_x:self.viewport_x + 16, ] data = {} data["image"] = self.parent.image data["pos"] = (self.viewport_x, self.viewport_y) data["before"] = dest.copy() index = self._overlay_canvas.data != -1 dest[index] = self._overlay_canvas.data[index] self._overlay_canvas.clear() data["after"] = dest.copy() self.parent.add_edit_history(data)
def __on_mouse_up(self, key, x, y): if key != pyxel.MOUSE_LEFT_BUTTON: return self._is_dragged = False if self.parent.tool >= TOOL_PENCIL and self.parent.tool <= TOOL_CIRC: data = (pyxel.tilemap(self.parent.tilemap).data if self._is_tilemap_mode else pyxel.image( self.parent.image).data) dest = data[self.viewport_y:self.viewport_y + 16, self.viewport_x:self.viewport_x + 16, ] self._add_pre_history(dest) index = self._overlay_canvas.data != OverlayCanvas.COLOR_NONE dest[index] = self._overlay_canvas.data[index] self._overlay_canvas.clear() self._add_post_history(dest)
def __init__(self): pyxel.init(SCREEN_WIDTH, SCREEN_HEIGHT) # initialization pyxel.image(0).load(0, 0, 'suits.png') pyxel.image(1).load(0, 0, 'values.png') pyxel.image(2).load(0, 0, 'card_back.png') self.state = INTRO self.shoe = list() self.dealer = Hand(4, 4) self.player = Hand(4, SCREEN_HEIGHT - CARD_HEIGHT - 12) self.player.bet = 5 self.split = Hand(SCREEN_WIDTH // 2 + 4, SCREEN_HEIGHT - CARD_HEIGHT - 12) # TODO -- move over? self.chips = 100 pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(256, 256, caption="Title", fullscreen=True) pyxel.image(0).load(0, 0, "assets/group_of_seven.jpg") pyxel.image(1).load(0, 0, "assets/sunset.png") pyxel.image(2).load(0, 0, "assets/title.png") pyxel.mouse(True) self.option1 = Option(2, 200, 5, 12) self.option2 = Option(102, 200, 5, 12) self.blurbText = 0 # EVERYTHING MUST BE ABOVE THIS LINE pyxel.run(self.update, self.draw)
def __init__(self): """Initialise the instance. """ if self.initialized: return assets = os.path.join(os.path.dirname(__file__), 'assets') pyxel.image(STATIC_IMAGES).load(0, 0, os.path.join(assets, 'sprites.png')) pyxel.image(BACKGROUND_IMAGE).load( 0, 0, os.path.join(assets, 'background.png')) pyxel.image(PLAYER_IMAGE).load(0, 0, os.path.join(assets, 'player.png')) self.initialized = True
def on_release(self, key, x, y): if key != pyxel.KEY_LEFT_BUTTON: return self._is_dragged = False img = self.parent.image_button.value dest = pyxel.image(img).data[self.edit_y:self.edit_y + 16, self.edit_x:self.edit_x + 16] data = {} data['img'] = img data['pos'] = (self.edit_x, self.edit_y) data['before'] = dest.copy() index = self._canvas != -1 dest[index] = self._canvas[index] self._canvas[:, :] = -1 data['after'] = dest.copy() self.parent.add_edit_history(data)
def copy(self, x, y, img, sx, sy, width, height): image = pyxel.image(img) rect = self._get_copy_rect( sx, sy, image.width, image.height, x, y, self.width, self.height, width, height, ) if not rect: return sx, sy, dx, dy, cw, ch = rect src_data = image._data[sy:sy + ch, sx:sx + cw] self._data[dy:dy + ch, dx:dx + cw] = src_data
def __init__(self, t): super(BossWarehouse, self).__init__() self.isBossRush = t[2] self.x = 256 + 48 self.y = 95.5 #95.5 self.layer = gcommon.C_LAYER_GRD | gcommon.C_LAYER_SKY self.left = -36 self.top = -44 self.right = 64 self.bottom = 44 self.hp = boss.BOSS_WAREHOUSE_HP self.score = 15000 self.subState = 0 self.subCnt = 0 self.hitcolor1 = 12 self.hitcolor2 = 6 self.ground = True self.shotHitCheck = True # 自機弾との当たり判定 self.hitCheck = True # 自機と敵との当たり判定 self.enemyShotCollision = False # 敵弾との当たり判定を行う self.countMover = enemy.CountMover(self, __class__.moveTable, True) self.gunRad = math.pi self.gun_cx = self.x + 20.0 self.gun_cy = self.y self.wheelCnt = 0 self.gunWidth = 56 self.gunHeight = 56 self.sideShotInterval = __class__.sideShotIntervalTable[GameSession.difficulty] self.crazyShotInterval = __class__.crazyShotIntervalTable[GameSession.difficulty] self.image = [None]* self.gunWidth self.work = [None]* self.gunHeight for y in range(self.gunWidth): self.image[y] = [0]*self.gunHeight img = pyxel.image(2) for y in range(self.gunWidth): for x in range(self.gunHeight): self.image[y][x] = img.get(x +176, y +104) self.timerObj = None if self.isBossRush: self.timerObj = enemy.Timer1.create(35)
def on_drag(self, key, mx, my, dx, dy): if key == pyxel.KEY_LEFT_BUTTON: img = self.parent._image_button.index x = self.parent.edit_x + mx // 8 y = self.parent.edit_y + my // 8 col = self.parent._color_button.index pyxel.image(img).data[y, x] = col elif key == pyxel.KEY_RIGHT_BUTTON: self.offset_x -= dx self.offset_y -= dy if abs(self.offset_x) >= 8: offset = (self.offset_x // 8) * 8 self.parent.edit_x += offset self.offset_x -= offset if abs(self.offset_y) >= 8: offset = (self.offset_y // 8) * 8 self.parent.edit_y += offset self.offset_y -= offset self.parent.edit_x = min(max(self.parent.edit_x, 0), 240) self.parent.edit_y = min(max(self.parent.edit_y, 0), 240)
def __on_mouse_down(self, key, x, y): if key != pyxel.MOUSE_LEFT_BUTTON: return x, y = self._screen_to_view(x, y) self._press_x = x self._press_y = y self._is_dragged = True self._is_assist_mode = False if self.parent.tool == TOOL_SELECT: self._select_x1 = self._select_x2 = x self._select_y1 = self._select_y2 = y elif TOOL_PENCIL <= self.parent.tool <= TOOL_CIRC: self._overlay_canvas.pix(x, y, self.parent.color) elif self.parent.tool == TOOL_BUCKET: data = ( pyxel.tilemap(self.parent.tilemap).data if self._is_tilemap_mode else pyxel.image(self.parent.image).data ) dest = data[ self.viewport_y : self.viewport_y + 16, self.viewport_x : self.viewport_x + 16, ] self._add_pre_history(dest) self._overlay_canvas.fill(x, y, self.parent.color, dest) self._add_post_history(dest) self._last_x = x self._last_y = y
def __init__(self): pyxel.init(240, 160, caption='test game') self.levelname = 'level2' self.assets_dir = 'assets' self.assets = os.path.realpath( os.path.join(os.getcwd(), os.path.dirname(__file__), self.assets_dir, self.levelname)) pyxel.image(0).load(0, 0, os.path.join(self.assets, '../animation.png')) pyxel.image(1).load(0, 0, os.path.join(self.assets, 'tileset.png')) pyxel.image(2).load(0, 0, os.path.join(self.assets, 'background.png')) self.level = Level(self.assets, 'mapfile.txt', 16) self.camera = Camera(self.level) self.player = Player() self.sparkle_emitter = ParticleEmitter(self.player) self.test_val = 0 pyxel.run(self.update, self.draw)
def __init__(self): self.IMG_ID0 = 0 self.IMG_ID1 = 1 self.IMG_ID2 = 2 self.IMG_ID0_X = 60 self.IMG_ID0_Y = 65 pyxel.init(WINDOW_W, WINDOW_H, caption="Hello Pyxel") pyxel.image(self.IMG_ID0).load(0, 0, "pic/pyxel_logo_38x16.png") pyxel.image(self.IMG_ID1).load(0, 0, "pic/cat_16x16.png") pyxel.image(self.IMG_ID2).load(0, 0, "pic/animal_mouse.png") # pyxel.mouse(True) self.mcat = cat(self.IMG_ID1) self.Balls = [] self.Enemies = [] # flag self.flag = 1 self.GameOver_flag = 0 pyxel.run(self.update, self.draw)
def __init__(self): pyxel.init(160, 120) pyxel.image(0).load(0, 0, 'PyxelArt/Cat.png') pyxel.image(1).load(0, 0, 'PyxelArt/Man.png') pyxel.image(2).load(0, 0, 'PyxelArt/Kitty.png') self.x = pyxel.width / 2 self.y = pyxel.height / 2 self.music = Music() self.cave = Cave() self.ocean = Ocean() self.glimmer = Glimmer() self.Fish = Fish() self.Bell = Bell() self.Cat = Cat() self.bell = False self.cat = False self.fish = False self.atCave = False self.isCat = False self.catFed = False self.testcat = testCat() pyxel.run(self.update, self.draw)
import pyxel pyxel.init(150, 150) pyxel.image(0).load(0, 0, "assets/ember.png") class Ember: def __init__(self): self.x = 0 self.y = 50 def mozgat(self): if pyxel.btn(pyxel.KEY_RIGHT): self.x += 1.1 if pyxel.btn(pyxel.KEY_LEFT): # ha balra self.x -= 1.1 # csökkentjük def rajzol(self): if pyxel.btn(pyxel.KEY_RIGHT) or pyxel.btn( pyxel.KEY_LEFT): # akkor is, ha balra i = 1 + int(pyxel.frame_count / 4) % 2 else: i = 0 w = -16 if pyxel.btn(pyxel.KEY_LEFT) else 16 pyxel.blt(self.x, self.y, 0, i * 16, 0, w, 16, 12) # Itt hozunk létre egy konkrét embert. ember = Ember() # Bevett szokás, hogy az osztály neve nagybetűs, a # konkrét objektum (vagy példány) neve pedig kisbetűs.
def __init__(self): pyxel.init(160, 120, caption="Hello Pyxel") pyxel.image(0).load(0, 0, "assets/pyxel_logo_38x16.png") pyxel.run(self.update, self.draw)
def __load(self): img_bank = pyxel.image(self.__img) for y in range(PyxelSpec.Image.Size[1]): for x in range(PyxelSpec.Image.Size[0]): img_bank.set(x, y, self.__col if self.__font.Data[y][x] else 0)
def __on_drop(self, filename): _, ext = os.path.splitext(filename) if ext.lower() == ".png": pyxel.image(self.image).load(0, 0, filename) return
def run(self): width_px = self.TILE_SIZE * self.WIDTH height_px = self.TILE_SIZE * self.HEIGHT pyxel.init(width_px, height_px) pyxel.image(0).load(0, 0, 'tile.png') pyxel.run(self._tick, self._draw)
def init(self): pyxel.image(1).load(0,0,"assets/stageList.png")
def __init__(self, width=153, height=170, debugging=False): # Initialize game state self.game_state = GameState.INTRO self.debugging = debugging self._main_cat_asset = 0 self._exploding_cat_asset = 1 self._golden_cat_asset = 2 self._main_bg = 1 self._playing_bg = 2 self._losing_bg = 3 self._width = width self._height = height self._grid_size = 12 self._grid_start_x = 5 self._grid_start_y = 22 self._grid_draw_size = 12 self.game_grid = [] self.game_grid_evaled = {} # What string to display self.elapsed_frames = 0 self.clicked_tiles = {} self.clicked_group_times = {} self.reveal_groups = {} self.golden_cat_x = -1 self.golden_cat_y = -1 self._play_real_button_pos = self.pyxel_button_centered('Play', 100) self._help_button_pos = self.pyxel_button_centered('Help', 120) self._help_back_button_pos = self.pyxel_button_centered('Back', 135) self._playing_real_back_button = self.pyxel_button('Back', 5, 5) self._replay_button = self.pyxel_button_centered('Play Again', 80) self._won_playagain_button = self.pyxel_button_centered( 'Play Again', 100) pyxel.init(self._width, self._height, caption='Quantum Catsweeper') pyxel.image(self._main_cat_asset).load(0, 0, 'assets/cat_16x16.png') pyxel.image(self._exploding_cat_asset).load( 0, 0, 'assets/explo_cat_31x25.png') pyxel.image(self._golden_cat_asset).load( 0, 0, 'assets/golden_cat_16x16.png') # Sound pyxel.sound(self._main_bg).set( 'e2e2c2g1 g1g1c2e2 d2d2d2g2 g2g2rr' 'c2c2a1e1 e1e1a1c2 b1b1b1e2 e2e2rr', 'p', '6', 'vffn fnff vffs vfnn', 25) pyxel.sound(self._playing_bg).set( 'f0c1f0c1 g0d1g0d1 c1g1c1g1 a0e1a0e1' 'f0c1f0c1 f0c1f0c1 g0d1g0d1 g0d1g0d1', 't', '7', 'n', 25) pyxel.sound(self._losing_bg).set( 'c1g1c1g1 c1g1c1g1 b0g1b0g1 b0g1b0g1' 'a0e1a0e1 a0e1a0e1 g0d1g0d1 g0d1g0d1', 't', '7', 'n', 25) pyxel.play(self._main_bg, [0, 1], loop=True) pyxel.run(self.update, self.draw)