Skip to content

SimplyAero/pynesgame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project is poorly implemented and deprecated, keeping it here for archiving reasons

pynesgame

NES-like sprite interface for pygame

Classes

pynes.Palette(palette: tuple)

Class representing an NES palette
The 'palette' argument must contain 3 values among the ones contained in the Color Reference
Example:
Super Mario's palette from Super Mario Bros can be:
('0x16', '0x18', '0x28')
The hex value is case sensitive, the 'x' must be lowercase, the digits must be uppercase
Instances of 'Palette' are iterables, elements can be edited but not added or deleted

pynes.NESSprite(data: str, size: tuple, palette: Palette)

Class representing an NES sprite
The 'data' argument must be an hex value, the exact value can be obtained by using the pixeltohex.py script
The 'size' argument must be a tuple containing two elements: (number of horizontal tiles, number of vertical tiles)
The 'palette' argument must be a pynes.Palette instance

Class variables

pynes.NESSprite.pixel_size

Size of a single "pixel" of the sprite, measured in pixels

Attributes

pynes.NESSprite.palette

Palette currently used by the sprite

pynes.NESSprite.size

Number of orizontal and vertical tiles

pynes.NESSprite.data

Colors used in each pixel

pynes.NESSprite.image

Image composed using the hex value recived

Methods

pynes.NESSprite.update()

Updates the sprite
If the sprite is part of a pygame.sprite.Group you can also use pygame.sprite.Group.update()

pynes.NESSprite.save(name: str)

Saves the generated sprite in name.png

pynes.NESSprite.change_data(data: str)

Changes the current hex value for the sprite

pynes.NESTile(data: str, palette: Palette)

Class representing an NES tile
The 'data' argument must be an hex value, the exact value can be obtained by using the pixeltohex.py script
The 'palette' argument must be a pynes.Palette instance

Class variables

pynes.NESTile.pixel_size

Size of a single "pixel" of the tile, measured in pixels

Attributes

pynes.NESSprite.palette

Palette currently used by the tile

pynes.NESTile.data

Colors used in each pixel

Methods

pynes.NESTile.update()

Updates the tile

pynes.NESTile.save(name: str)

Saves the generated tile in name.png

pynes.NESTile.change_data(data: str)

Changes the current hex value for the tile

Functions

pynes.update()

Updates every pynes.NESSprite instance

pynes.spritify(image_data: str, palette: Palette, size: tuple, pixel_size: int)

Creates a static image from an hex value, useful for creating animated sprites without having to re-parse data every frame The 'image_data' argument must be an hex value, the exact value can be obtained by using the pixeltohex.py script
The 'palette' argument must be a pynes.Palette instance
The 'size' argument must be a tuple containing two elements: (number of horizontal tiles, number of vertical tiles)
The 'pixel_size' argument represents how many pixels is a single square in the sprite

pixeltohex.py

A script that generates a readable hex value for the NESSprite
The input must be written in a file named 'convert.dat', every character must correspond to a pixel in the image, lines can be wrapped
Accepted characters: 0, 1, 2, 3
Every character must be the index of the color used in that pixel in the palette, 0 is transparent
The result will be written in 'result.dat'
Example:
0000001111100000
0000113222311000
0001322222223100
0013222222222100
0012222222222310
0122222221212310
1322222221212221
1222222221212221
1222223322223321
1322322222222321
0132122222122131
0011322222223110
0001133222231100
0013311111113310
0133333111133331
0011111000111110
will return
0x0300E0000E0338E0180F0CF8301F04F8201F06FC403F56ACC07F51AE807F51AE837F0DFEC87F05FE683727DA380F0EF81E071CF03F18FE0C7F3EFF1E3E003E0
And when converted it will become Kirby's sprite

test.py

Script that can be used to test if a sprite displays correctly
The input must be in a file called 'test.dat', and it must be formatted in this way:
hex value (without 0x)
number of horizontal tiles
number of vertical tiles
element [1] in the palette
element [2] in the palette
element [3] in the palette
The result will be saved in 'test.png'

Color reference

#007880 0x00
#010100 0x01
#020000 0x02
#033e28 0x03
#048f02 0x04
#05ae00 0x05
#06ab11 0x06
#078f16 0x07
#085030 0x08
#09007b 0x09
#0A0069 0x0A
#0B0059 0x0B
#0C0045 0x0C
#0D0000 0x0D
#0E0000 0x0E
#0F0000 0x0F
#10bcbf 0x10
#110178 0x11
#120686 0x12
#136648 0x13
#14dd00 0x14
#15e200 0x15
#16ff33 0x16
#17e55f 0x17
#18ab81 0x18
#1900b8 0x19
#1A00aa 0x1A
#1B07a5 0x1B
#1C0188 0x1C
#1D2c2c 0x1D
#1E0000 0x1E
#1F0000 0x1F
#20fdf8 0x20
#2138c0 0x21
#226889 0x22
#239e78 0x23
#24fe77 0x24
#25fd58 0x25
#26fd78 0x26
#27fd9e 0x27
#28feb4 0x28
#29bcf9 0x29
#2A5ed5 0x2A
#2B59f8 0x2B
#2C00e9 0x2C
#2D5c5f 0x2D
#2E0000 0x2E
#2F0000 0x2F
#30fdf8 0x30
#31a1e9 0x31
#32c5b8 0x32
#33dcb9 0x33
#34fbb8 0x34
#35f0c2 0x35
#36f4d1 0x36
#37fcdf 0x37
#38fcd8 0x38
#39dbf8 0x39
#3Ab6f9 0x3A
#3Baeef 0x3B
#3C00f7 0x3C
#3Dc9bf 0x3D
#3E0000 0x3E
#3F0000 0x3F

About

NES-like sprite interface for pygame

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages