I've seen that a couple of other people that aren't me have viewed this. That's great! Please, if you have any experience in developing for this target, please send me a message, I'm looking for advice and help and I am open to suggestions. Thank you!
Also, the game being developed within is my attempt at a simple 2-D game remake, Super Metroid.
Let it be noted that my graphics library does NOT have to be used in conjunction with the game files, the game files are an extenion upon the graphics library.
In addition, as can be seen, I am attempting to create my own graphics libraries from scratch. You can use Vita2D, but I have opted out of this, in order to further my learning experience. This includes rendering my own file format of rgba with a header, and my own functions to draw to the screen.
Ensure that your vita is unlocked. For help with setting up a development environment, read more here. For unlocking the vita, read more here. For the API, read here.
The assets seen are taken from a sprite sheet containing all sprites from the original Super Metroid for the SNES. I do not claim ownership to any of the material.
The RGBA file format associated with this project is created using a PNG to RGBA converter, then the RGBA files are custom made by inserting three "words" (4 bytes) into the beginning of each file. The first word contains the height of the image, the second word contains the width, and the third word contains the total number of animation states present within the image. This RGBA file can then be preloaded into the system, loaded, or directly read from memory and then displayed using the functions in the filesystem and graphics namespaces.
Please note that this documentation does not include or describe the packaged Vita2d calls that lie within the code. Those are there for testing purposes and their documentation and source can be found here
namespace |    functions      |     members     | classes |
---|---|---|---|
colors | functions | members | classes |
filesystem | functions | members | classes |
font | functions | members | classes |
game | functions | members | classes |
graphics | functions | members | classes |
io | functions | members | classes |
preloaded | functions | members | classes |
utils | functions | members | classes |
uint32_t RGBA832(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
- Generates a 32 bit formatted RGBA color.
uint16_t RGB16(unsigned char r, unsigned char g, unsigned char b)
- Generates a 16 bit formatted RGB color, no alpha.
uint32_t pixelToRGBA832(filesystem::pixel p)
- Generates a 32 bit formatted RGBA color from a provided filesystem::pixel
.
filesystem::Texture* loadFile(std::string filename)
- Returns a Texture. The pixels** of the Texture contains all RGBA values of the texture loaded and the texture is formatted to width and height of the corresponding rgba file.
filesystem::Header* readHeader(SceUID file)
- Returns a Header*. This reads the 3 word header of a custom made RGBA file, and returns it as an object that can be attributed to a Texture object.
filesystem::Texture* preload(filesystem::preloaded_animations animation)
- Returns a Texture*. This Texture* can be used in conjunction with the preload graphics display functions to draw a texture. In order to use this function, you must declare a filesystem::preloaded_animations type, you must create an entry for the preloaded texture within the preloaded.hpp file, and lastly you must add a condition case in graphics::draw_texture_preloaded(filesystem::Texture* texture, unsigned int posX, unsigned int posY)
with the format if(texture->preloaded == filesystem::preloaded_animations) animation_to_draw = preloaded::animation;
.
filesystem::Header* readHeader(SceUID file)
- Returns a Header*. This reads the 3 word header of a custom made RGBA file, and returns it as an object that can be attributed to a Texture object.
void preloadTiles()
- This function will assign the tiles
member of the game namespace to a static pointer of an array containing Texture*
.
void drawPlayer()
- Draws the player, applies friction, updates animation states, changes animation states.
void applyFriction()
- Applies a negative velocity force to ensure that the playeer will slow down if no force is given from the user, this is done automatically in drawPlayer.
void checkPlayerMaxSpeed()
- Ensures that the player does not surpass the set value of game::PLAYER_CURRENT_MAX_MOVE_SPEED
.
void setUp()
- Turns off basic functionality from the PS Vita, such as the dimming and timeout of the display.
void initializeFramebuffers()
- Initializes two framebuffers, these should be freed prior to ending the program.
void swapFramebuffers()
- Swaps the initialized frame buffers, should preferably be done upon a vertical blank from the system.
void colorScreen(uint16_t color)
- Sets the framebuffers's color (base member variable) completely to the supplied color. This color may be obtained from colors::RGB16(unsigned char r, unsigned char g, unsigned char b)
or may be self-formatted.
void draw_pixel(uint32_t x, uint32_t y, uint32_t color)
- Sets a pixel at a given x and y coordinate in the current framebuffer to a supplied color. This color may be obtained from colors::RGBA832(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
or may be self-formatted.
uint32_t getPixel(uint32_t x, uint32_t y)
- Gets a unsigned thirty-two bit color at a given x and y coordinate in the current framebuffer.
void draw_texture_loaded(filesystem::Texture* texture, unsigned int posX, unsigned int posY)
- Draws a loaded texture using the provided Texture* at a given position x and y.
void draw_texture_loaded_scale(filesystem::Texture* texture, unsigned int posX, unsigned int posY, double newHeightScale, double newWidthScale)
- Draws a loaded texture using the provided Texture* at a given position x and y after scaling the texture with the provided scale proportions in the width and height directions.
void draw_texture_loaded_part(filesystem::Texture* texture, unsigned int posX, unsigned int posY, unsigned int heightPerPiece, unsigned int widthPerPiece, unsigned int pieceNum)
- Draws a portion of a loaded texture using the provided Texture* and the provided portion number at a given position x and y. Useful for animation.
void draw_texture_loaded_scale_part(filesystem::Texture* texture, unsigned int posX, unsigned int posY, unsigned int heightPerPiece, unsigned int widthPerPiece, unsigned int newHeightScale, unsigned int newWidthScale, unsigned int pieceNum)
- Draws a portion loaded texture using the provided Texture* using the provided portion number at a given position x and y after scaling the texture with the provided scale proportions in the width and height directions. Useful for animation.
void draw_texture_file(std::string filename, unsigned int posX, unsigned int posY)
- Draws a texture directly from a file at a given position x and y. (Note: This only works with formatted RGBA files)
void draw_texture_file_part(std::string filename, unsigned int posX, unsigned int posY, unsigned int heightPerPiece, unsigned int widthPerPiece, unsigned int pieceNum)
- Draws a portion of a texture using the portion number provided directly from a file at a given position x and y. Useful for animation. (Note: This only works with formatted RGBA files)
void draw_texture_file_scale_part(std::string filename, unsigned int posX, unsigned int posY, unsigned int heightPerPiece, unsigned int widthPerPiece, unsigned int newHeightScale, unsigned int newWidthScale, unsigned int pieceNum)
- Draws a portion of a texture using the portion number provided directly from a file at a given position x and y and scaled using the provided width and height scales. Useful for animation. (Note: This only works with formatted RGBA files)
void draw_texture_preloaded(filesystem::Texture* texture, unsigned int posX, unsigned int posY)
- Draws a preloaded texture at a given coordinate x and y. (Note: This texture MUST be preloaded following the steps explained here
void draw_texture_preloaded_part(filesystem::Texture* texture, unsigned int posX, unsigned int posY, unsigned int heightPerPiece, unsigned int widthPerPiece, unsigned int pieceNum)
- Draws a portion of a preloaded texture using the provided portion number at a given coordinate x and y. (Note: This texture MUST be preloaded following the steps explained here
void draw_texture_preloaded_scale_part(filesystem::Texture* texture, unsigned int posX, unsigned int posY, unsigned int heightPerPiece, unsigned int widthPerPiece, unsigned int newHeightScale, unsigned int newWidthScale, unsigned int pieceNum)
- Draws a portion of a preloaded texture using the provided portion number at a given coordinate x and y that will also be scaled using the provided new width and height scales. (Note: This texture MUST be preloaded following the steps explained here
void draw_tile(unsigned int tileNum, unsigned int x, unsigned int y)
- Draws the specified tile number from tiles to the screen at the specified x and y position.
game::Position checkBounds(int posX, int posY, unsigned int x, unsigned int y)
- Returns a game::Position
object that represents bounds that are drawable to the screen. This bound is a position representing the coordinate (posX + x, posY + y). This stops segmentation faults in which a position out the bounds of the framebuffer is written to.
unsigned int align_mem(unsigned int addr, unsigned int align)
- Alignes an address to an align offset.
void printc(int x, int y, uint32_t color, char c)
- Prints a character to a given x and y coordinate.
void prints(int x, int y, uint32_t color, const char *string)
- Prints a string to a given x and y coordinate.
void printsf(int x, int y, uint32_t color, const char *s, ...)
- Prints a formatted string to a given x and y coordinate.
preloaded_animations
- Enumerated type representing all types of preloaded animations. Values are currently
NOT_PRELOADED
- Represents a texture type that is not currently preloaded.IDLE_ANIMATION
- Represents the idle animation texture.RIGHT_RUN_ANIMATION
- Represents the right run animation texture.LEFT_RUN_ANIMATION
- Represents the left run animation texture.
double PLAYER_MAX_MOVE_SPEED
- Represents the maximum allowed movement speed of the player in the game.
double PLAYER_CURRENT_MAX_MOVE_SPEED
- Represents the current maximum allowed movement speed of the player in the game. As this may change diuring the game, power-ups, etc..
double SPEED_MODIFIER
- Represents a modifier that may affect the speed of a player (different terrain, etc.).
PAUSED
- Represents a gamestate in which the game is currently paused.UNPAUSED
- Represents a gamestate in which the game is currently unpaused.
movestate
- Enumerated type representing the possible movestates of the player. Values are currently
IDLE
- Represents a movestate in which the player is not moving.MOVING_RIGHT
- Represents a gamestate in which the player is moving to the right.MOVING_LEFT
- Represents a gamestate in which the player is moving to the left.
tileCount
- Represents the total amount of tiles in the tile member of the preloaded namespace.
filesystem::Texture** tiles
- Texture** containing an array of [Texture](#textureClassObject]* containing all preloaded tiles. Must preload tiles first.
int DISPLAY_STRIDE_IN_PIXELS
- Value representing the stride of the display of the PS Vita screen in pixels.
SceUID fb_memuid
- Array (size two) that will be containing the UID's for the frame buffers in order to release them later.
SceCtrlData pad
- Structure containing all the controls and their current states (pressed/unpressed).
unsigned int maps[][][]
- A three dimensional array of tiles and their positioning in a map. The first dimension is the map number, the second dimension is the X position of the tile, and the third dimension is the Y position of a tile. The value is the tile number to be rendered at that position.
unsigned char tile
- Two dimensional array containing all RGBA values for all preloaded tiles.
unsigned char* fontStyle
- The current fontStyle to be used in the project. (note: automatically set in utils.cpp)
Header(unsigned int height, unsigned int width, unsigned int states)
- Constructor to create new Header with specified height, width, and states.Header()
- Constructor to create new Header with height, width, and states set to zero.unsigned int height
- Represents the height in pixels for the Texture in which the Header will reside in.unsigned int width
- Represents the width in pixels for the Texture in which the Header will reside in.unsigned int states
- Represents the states for the Texture in which the Header will reside in.
pixel
- Class containing all the necessary information of a pixel.
pixel(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
- Constructor to create a pixel with the specified red, green, blue, and alpha.pixel()
- Constructor to create a pixel with the red, green, blue, and alpha set to zero.unsigned char red
- Represents the red value of the pixel.unsigned char green
- Represents the green value of the pixel.unsigned char blue
- Represents the blue value of the pixel.unsigned char alpha
- Represents the alpha value of the pixel.
Texture
- Class containing all the necessary information of a pixel.
filesystem::preloaded_animations preloaded
- If the texture is preloaded, this will contain the filesystem::preloaded_animations value which it represents.filesystem::Header header
- The header of the texture.pixel** pixels
- Pointer to a two-dimensional array of size [height][width] that contains all pixel data for the texture.void format(unsigned int height, unsigned int width, unsigned int states)
- Formats the header to represent the specified height, width, and states. Format also resizes the pixel body for the texture to the new specified height and width.Texture(unsigned int height, unsigned int width, unsigned int states)
- Crates a new texture and formats the header and pixel body to represent the specified height, width, and states.
double x
- The current velocity in the x direction.double y
- The current velocity in the y direction.Velocity(double x, double y)
- Constructor to create a Velocity object with the given x and y velocity.Velocity()
- Constructor to create a Velocity object with the x and y velocity equal to zero.
int x
- The current position on the x axis.int y
- The current position on the y axis.Position(int x, int y)
- Constructor to create a Position object with the given x and y coordinates.Position()
- Constructor to create a Velocity object with the x and y position set to the center of the screen.
Entity
- Class containing information for an Entity.
Position position
- The current position of the entity.int y
- The current position on the y axis.Entity(int x, int y)
- Constructor to create a Entity object with the given x and y coordinates.Entity()
- Constructor to create an Entity object with the x and y position set to the center of the screen.
Position lastPosition
- The previous position of the player.Movestate movestate
- The movestate of the player.Movestate previousMovestate
- The previous movestate of the player.double animationFrame
- The current animation frame to use when drawing the player to the screen.unsigned int health
- The current amount of health the player has.unsigned int missiles
- The current amount of missiles the player has.Velocity velocity
- The current velocity of the player.Player()
- Creates a new Player object that has an IDLE movestate and a previous movestate of IDLE as well.Player(int x, int y)
- Creates a new Player object that has an IDLE movestate and a previous movestate of IDLE as well at the specified x and y position.
Position positon
- The position of the camera.Camera()
- Creates a new Camera object that has an x and y coordinate of center screen.Camera(int x, int y)
- Creates a new Camera object at the specified x and y coordinates.