Pyxel – это дань уважения игровым консолям золотого века, таким как SNES или Game Boy Color: крупные пиксели, мало цветов и минималистичный четырёхканальный звук.
Такие простые игры можно создавать быстро, и они будут без проблем работать на любых ПК и на любой ОС.
pip install pyxel
pyxel copy_examples
pyxel run pyxel_examples/02_jump_game.py
pyxel edit initiation.pyxres &
import pyxel
class App:
def __init__(self):
pyxel.init(160, 120, title="UFO static") # ширина, высота, название
pyxel.load("initiation.pyxres")
self.player_x = 72 # 🛸 позиция по оси x
self.player_y = 72 # 🛸 позиция по оси y
self.ship = (0, 0, 16, 16, 0) # x, y, ширина, высота, прозрачный цвет
pyxel.run(self.update, self.draw)
def update(self):
if pyxel.btnp(pyxel.KEY_Q):
pyxel.quit()
def draw(self):
pyxel.cls(0) # очистка экрана цветом 0
# Отрисовка 🛸
pyxel.blt(self.player_x, self.player_y, 0, *self.ship)
App()
pyxel watch . initiation.py
import pyxel
class App:
def __init__(self):
pyxel.init(160, 120, title="UFO shaken") # ширина, высота, название
pyxel.load("initiation.pyxres")
self.player_x = 72 # 🛸 позиция по оси x
self.player_y = 72 # 🛸 позиция по оси y
self.ship = (0, 0, 16, 16, 0) # x, y, ширина, высота, прозрачный цвет
pyxel.run(self.update, self.draw)
def update(self):
if pyxel.btnp(pyxel.KEY_Q):
pyxel.quit()
# 🛸 тряска на 1/16 за тик, начиная с y = 72
self.player_y = pyxel.cos(pyxel.frame_count * 360 / 16) + 72
def draw(self):
pyxel.cls(0) # очистка экрана цветом 0
# Отрисовка 🛸
pyxel.blt(self.player_x, self.player_y, 0, *self.ship)
App()
import pyxel
class App:
def __init__(self):
pyxel.init(160, 120, title="UFO shaken") # ширина, высота, название
pyxel.load("initiation.pyxres")
self.player_x = 72 # 🛸 позиция по оси x
self.player_y = 72 # 🛸 позиция по оси y
self.spaceship_r = (0, 0, 16, 16, 0) # x, y, ширина, высота, прозрачный цвет
self.spaceship_l = (16, 0, 16, 16, 0)
self.ship = self.spaceship_r # 🛸 смотрит ->
pyxel.run(self.update, self.draw)
def update(self):
if pyxel.btnp(pyxel.KEY_Q):
pyxel.quit()
if pyxel.btn(pyxel.KEY_LEFT) or pyxel.btn(pyxel.GAMEPAD1_BUTTON_DPAD_LEFT):
self.player_x = max(self.player_x - 2, 0) # летим ->
self.ship = self.spaceship_l # 🛸 смотрим <-
if pyxel.btn(pyxel.KEY_RIGHT) or pyxel.btn(pyxel.GAMEPAD1_BUTTON_DPAD_RIGHT):
self.player_x = min(self.player_x + 2, pyxel.width - 16) # летим ->
self.ship = self.spaceship_r # 🛸 смотрим ->
# 🛸 тряска на 1/16 за тик, начиная с y = 72
self.player_y = pyxel.cos(pyxel.frame_count * 360 / 16) + 72
def draw(self):
pyxel.cls(0) # очистка экрана цветом 0
# Отрисовка 🛸
pyxel.blt(self.player_x, self.player_y, 0, *self.ship)
App()
Источник: Garambrogne 2.0