当前位置:主页 > 资料 >

Pyxel: a retro game development environment in Python
栏目分类:资料   发布日期:2018-08-02   浏览次数:

导读:本文为去找网小编(www.7zhao.net)为您推荐的Pyxel: a retro game development environment in Python,希望对您有所帮助,谢谢! [ | | ] Pyxelis a retro game development environment in Python. Thanks to its simple specific

本文为去找网小编(www.7zhao.net)为您推荐的Pyxel: a retro game development environment in Python,希望对您有所帮助,谢谢! copyright www.7zhao.net



[ | | ] www.7zhao.net

Pyxelis a retro game development environment in Python.

去找(www.7zhao.net欢迎您

Thanks to its simple specifications inspired by retro gaming consoles, such as only 16 colors can be displayed and only 4 sounds can be played back at the same time, you can feel free to enjoy making pixel art style games.

内容来自www.7zhao.net

The specifications of the gaming console, APIs, and paletts of Pyxel are reffering to awesome and .

欢迎访问www.7zhao.net

Pyxel is open souce and free to use. Let's start making a retro game with Pyxel!

www.7zhao.net

Specifications

  • Run on Windows, Mac, and Linux
  • Code writing with Python3
  • Fixed 16 color palette
  • 256x256 sized 4 image banks
  • 4 channels with 64 definable sound banks
  • Keyboard, mouse, and joystick(WIP) inputs
  • Image and sound editor (WIP)

How to Install

Windows

After installing , the following pip command installs Pyxel: 欢迎访问www.7zhao.net

pip install pyxel 内容来自www.7zhao.net 

Mac

After installing and , install Pyxel with pip command. 欢迎访问www.7zhao.net

If package manager is ready, the following command installs all the necessary packages: 本文来自去找www.7zhao.net

brew install python3 glfw
pip3 install pyxel 

欢迎访问www.7zhao.net

Linux

Install the required packages in a way appropriate for each distribution. 本文来自去找www.7zhao.net

Arch:

pacman -S python python-pip glfw portaudio
pip install pyxel copyright www.7zhao.net 

Debian:

apt-get install python3 python3-pip glfw libportaudio2 libasound-dev
pip3 install pyxel copyright www.7zhao.net 

Install examples

After installing Pyxel, the examples of Pyxel will be copied to the current directory with the following command:

本文来自去找www.7zhao.net

install_pyxel_examples 

欢迎访问www.7zhao.net

How to Use

Create Pyxel Application

After importing the Pyxel module in your python code, specify the window size with init function first, then starts the Pyxel application with run function. 去找(www.7zhao.net欢迎您

import pyxel

pyxel.init(160, 120)

def update():
    if pyxel.btnp(pyxel.KEY_Q):
        pyxel.quit()

def draw():
    pyxel.cls(0)
    pyxel.rect(10, 10, 20, 20, 11)

pyxel.run(update, draw) 
内容来自www.7zhao.net

The arguments of run function are update function to update each frame and draw function to draw screen when necessary. copyright www.7zhao.net

In an actual application, it is recommended to wrap pyxel code in a class as below: 去找(www.7zhao.net欢迎您

import pyxel

class App:
    def __init__(self):
        pyxel.init(160, 120)
        self.x = 0
        pyxel.run(self.update, self.draw)

    def update(self):
        self.x = (self.x + 1) % pyxel.width

    def draw(self):
        pyxel.cls(0)
        pyxel.rect(self.x, 0, self.x + 7, 7, 9)

App() 欢迎访问www.7zhao.net 

Special Controls

The following special controls can be performed while a Pyxel application is running: www.7zhao.net

  • Alt(Option)+1
    Save the screenshot to the desktop
  • Alt(Option)+2
    Reset the recording start time of the screen capture video
  • Alt(Option)+3
    Save the screen capture video (gif) to the desktop (up to 30 seconds)
  • Alt(Option)+0
    Toggle the performance monitor (fps, update time, and draw time)
  • Alt(Option)+Enter
    Toggle full screen

Create Images

There are the following methods to create images for Pyxel:

去找(www.7zhao.net欢迎您

Image.set
Image.load
 
内容来自www.7zhao.net

Please refer to the API reference for usage of Image.set and Image.load . www.7zhao.net

Because Pyxel uses the same palette as , when creating png images for Pyxel, it is recommended to use in PICO-8 palette mode. 本文来自去找www.7zhao.net

API Reference

System

  • width , height
    The width and height of the screen

    本文来自去找www.7zhao.net

  • frame_count
    The number of the elapsed frames www.7zhao.net

  • init(width, height, [caption], [scale], [palette], [fps], [border_width], [border_color])

    Initialize the Pyxel application with screen size ( width , height ) www.7zhao.net

    It is also possible to specify the window title with caption , the display magnification with scale , the palette color with palette , the frame rate with fps , and the margin width and color outside the screen with border_width and border_color

    www.7zhao.net

  • run(update, draw)
    Start the Pyxel application and call update function for frame update and draw function for drawing 去找(www.7zhao.net欢迎您

  • quit()
    End the Pyxel application at the end of the current frame www.7zhao.net

Input

  • mouse_x , mouse_y
    The current position of the mouse cursor 去找(www.7zhao.net欢迎您

  • btn(key)
    Return True if key is pressed, otherwise return False ( )

    欢迎访问www.7zhao.net

  • btnp(key, [hold], [period])
    Return True if key is pressed at that frame, otherwise return False . When hold and period are specified, True will be returned at the period frame interval when the key is held down for more than hold frames

    去找(www.7zhao.net欢迎您

  • btnr(key)
    Return True if key is released at that frame, otherwise return False 本文来自去找www.7zhao.net

Graphics

  • image(img)
    Operate the image bank img (0-3) (see the Image class) e.g. pyxel.image(0).load(0, 0, 'title.png')

    内容来自www.7zhao.net

  • clip(x1, y1, x2, y2)
    Set the drawing area of the screen to ( x1 , y1 )-( x2 , y2 ). Reset the drawing area with clip()

    www.7zhao.net

  • pal(col1, col2)
    Replace color col1 with col2 at drawing. pal() to reset to the initial palette

    内容来自www.7zhao.net

  • cls(col)
    Clear screen with color col 内容来自www.7zhao.net

  • pix(x, y, col)
    Draw a pixel of color col at ( x , y ) 内容来自www.7zhao.net

  • line(x1, y1, x2, y2, col)
    Draw a line of color col from ( x1 , y1 ) to ( x2 , y2 )

    copyright www.7zhao.net

  • rect(x1, y1, x2, y2, col)
    Draw a rectangle of color col from ( x1 , y1 ) to ( x2 , y2 ) 欢迎访问www.7zhao.net

  • rectb(x1, y1, x2, y2, col)
    Draw the outline of a rectangle of color col from ( x1 , y1 ) to ( x2 , y2 ) copyright www.7zhao.net

  • circ(x, y, r, col)
    Draw a circle of radius r and color col at ( x , y )

    欢迎访问www.7zhao.net

  • circb(x, y, r, col)
    Draw the outline of a circle of radius r and color col at ( x , y )

    内容来自www.7zhao.net

  • blt(x, y, img, sx, sy, w, h, [colkey])
    Copy the region of size ( w , h ) from ( sx , sy ) of the image bank img (0-3) to ( x , y ). If negative value is set for w and/or h , it will reverse horizontally and/or vertically. If colkey is speficied, treated as transparent color

    去找(www.7zhao.net欢迎您

  • text(x, y, s, col)
    Draw a string s of color col at ( x , y )

    欢迎访问www.7zhao.net

Audio

  • sound(snd)
    Operate the sound bank snd (0-63) (see the Sound class) e.g. pyxel.sound(0).speed = 60

    copyright www.7zhao.net

  • play(ch, snd, loop=False)
    Play the sound bank snd (0-63) on channel ch (0-3). Play in order when snd is a list 内容来自www.7zhao.net

  • stop(ch)
    Stop playback of channel ch (0-3)

    内容来自www.7zhao.net

Image Class

  • width , height
    The width and height of the Image 去找(www.7zhao.net欢迎您

  • data
    The data of the Image (NumPy array) www.7zhao.net

  • set(x, y, data)

    Set the image as a list of strings at ( x , y ) 欢迎访问www.7zhao.net

    e.g. pyxel.image(0).set(10, 10, ['1234', '5678', '9abc', 'defg'])

    www.7zhao.net

  • load(x, y, filename)
    Read png image at ( x , y )

    www.7zhao.net

  • copy(x, y, img, sx, sy, width, height)
    Copy the region of size ( width , height ) from ( sx , sy ) of the image bank img (0-3) to ( x , y )

    去找(www.7zhao.net欢迎您

Sound Class

  • note
    List of note(0-127) (33 = 'A2' = 440Hz)

    去找(www.7zhao.net欢迎您

  • tone
    List of tone(0:Triagnle / 1:Square / 2:Pulse / 3:Noise) 去找(www.7zhao.net欢迎您

  • volume
    List of volume(0-7) www.7zhao.net

  • effect
    List of effects(0:None / 1:Slide / 2:Vibrato / 3:FadeOut) www.7zhao.net

  • speed
    The length of one note(120 = 1 second per tone)

    www.7zhao.net

  • set(note, tone, volume, effect, speed)
    Set a note, tone, volume, and effect with a string. If the tone, volume, and effect length are shorter than the note, it is repeated from the beginning

    copyright www.7zhao.net

  • set_note(note)

    Set the note with a string consists of 'CDEFGAB'+'#-'+'0123' or 'R'. Case-insensitive and whitespace is ignored

    欢迎访问www.7zhao.net

    e.g. pyxel.sound(0).set_note('G2B-2D3R RF3F3F3') 欢迎访问www.7zhao.net

  • set_tone(tone)

    Set the tone with a string consists of 'TSPN'. Case-insensitive and whitespace is ignored www.7zhao.net

    e.g. pyxel.sound(0).set_tone('TTSS PPPN')

    www.7zhao.net

  • set_volume(volume)

    Set the volume with a string consists of '01234567'. Case-insensitive and whitespace is ignored 去找(www.7zhao.net欢迎您

    e.g. pyxel.sound(0).set_volume('7777 7531')

    本文来自去找www.7zhao.net

  • set_effect(effect)

    Set the effect with a string consists of 'NSVF'. Case-insensitive and whitespace is ignored

    去找(www.7zhao.net欢迎您

    e.g. pyxel.sound(0).set_effect('NFNF NVVS')

    内容来自www.7zhao.net

License

Pyxel is under . It can be reused within proprietary software provided that all copies of the licensed software include a copy of the MIT License terms and the copyright notice.

copyright www.7zhao.net

copyright www.7zhao.net


本文原文地址:https://github.com/kitao/pyxel

以上为Pyxel: a retro game development environment in Python文章的全部内容,若您也有好的文章,欢迎与我们分享!

内容来自www.7zhao.net

Copyright ©2008-2017去找网版权所有   皖ICP备12002049号-2 皖公网安备 34088102000435号   关于我们|联系我们| 免责声明|友情链接|网站地图|手机版