C reference: the window and drawing
These calls come from #include <macaw.h>. They open your window, draw into it, and work with pictures, sprites and maps. A picture is a number: 0 means there isn't one, and for drawinto it means the window itself. The Drawing chapter explains the Lua calls these are built on, and the C chapter shows how a C program fits together.
The window
window
void window(int w, int h, const char *title)
Says what size your window should be and what its title bar says. Call it in main, and it takes the place of Lua's WINDOW table.
w: the width of the inside of the window, in pixels. It's at least 8, and made smaller if it wouldn't fit on the screen.h: the height of the inside of the window, in pixels. It's at least 8, and made smaller if it wouldn't fit.title: the words in the title bar.NULLkeeps the program's own name.
realtime
void realtime(int on)
Makes your window draw every frame, which games and animations need. Without it, _draw runs only when something may have changed.
on: 1 to draw every frame, 0 to go back to drawing only when needed.
windowscale
void windowscale(int scale)
Shows every pixel of your window bigger, for pixel art. Call it in main.
scale: how many screen pixels across each of your pixels is: 2 shows each as 2 x 2. It's kept between 1 and 4, and made smaller if the window wouldn't fit.
resizable
void resizable(int on)
Says whether people can resize your window with its size box. Windows can be resized unless you say otherwise.
on: 1 to let people resize it, 0 to stop them.
redraw
void redraw(void)
Asks for your window to be drawn again on the next frame. Call it from _update when something changes what the window shows, such as a timer or a download.
It takes nothing.
close
void close(void)
Closes your window, asking first if it has unsaved work.
It takes nothing.
settitle
void settitle(const char *title)
Changes the words in your window's title bar while the program runs.
title: the new title.
windowmin
void windowmin(int w, int h)
Sets the smallest size people can resize your window to. Call it in main, before the window opens.
w: the smallest width, in pixels. 0 means the usual 96, and it's never below 16.h: the smallest height, in pixels. 0 means the usual 48, and it's never below 16.
windowcolors
void windowcolors(int colours)
Asks for the screen to show this many colours while your program runs. Call it in main; the person is asked when the window opens, and if they don't allow it, your program closes.
colours: 8, 256 orCOLORS_THOUSANDS. Any other number, such as 0, leaves the screen as it is.
windowcursor
void windowcursor(int on)
Shows or hides the pointer while it's over your window. Hide it when you draw your own pointer.
on: 1 to show the pointer, 0 to hide it.
fullscreen
void fullscreen(int on)
Asks to make your window fill the screen, or puts it back. Asking shows the person a question, and if they don't allow it, your program closes. Leaving full screen never asks.
on: 1 to ask for full screen, 0 to go back to a normal window.
focused
int focused(void)
Tells you whether your window is the one in front, for example to pause a game when it isn't.
It takes nothing.
Returns 1 if your window is in front, or 0 if it isn't.
Drawing
cls
void cls(int colour)
Fills the whole window, or the picture you're drawing into, with one colour. It stays inside the clip rectangle, and the camera doesn't move it.
colour: the colour to fill it with, from 0 to 255.
pset
void pset(int x, int y, int colour)
Sets one pixel to a colour.
x: how far the pixel is from the window's left edge, in pixels.y: how far the pixel is from the window's top, in pixels.colour: the colour to set it to, from 0 to 255.
pget
int pget(int x, int y)
Reads the colour of one pixel of the window, or of the picture you're drawing into.
x: how far the pixel is from the window's left edge, in pixels.y: how far the pixel is from the window's top, in pixels.
Returns the pixel's colour, from 0 to 255, or 0 if the pixel is outside the window.
line
void line(int x0, int y0, int x1, int y1, int colour)
Draws a straight line from one point to another.
x0: how far the start is from the window's left edge, in pixels.y0: how far the start is from the window's top, in pixels.x1: how far the end is from the window's left edge, in pixels.y1: how far the end is from the window's top, in pixels.colour: the line's colour, from 0 to 255.
rect
void rect(int x, int y, int w, int h, int colour)
Draws the outline of a rectangle, one pixel thick.
x: how far its left edge is from the window's left edge, in pixels.y: how far its top edge is from the window's top, in pixels.w: its width in pixels. 0 or less draws nothing.h: its height in pixels. 0 or less draws nothing.colour: the outline's colour, from 0 to 255.
rectfill
void rectfill(int x, int y, int w, int h, int colour)
Fills a rectangle with one colour.
x: how far its left edge is from the window's left edge, in pixels.y: how far its top edge is from the window's top, in pixels.w: its width in pixels.h: its height in pixels.colour: the colour to fill it with, from 0 to 255.
circ
void circ(int x, int y, int r, int colour)
Draws the outline of a circle.
x: how far the centre is from the window's left edge, in pixels.y: how far the centre is from the window's top, in pixels.r: the radius, in pixels. A negative radius draws nothing.colour: the outline's colour, from 0 to 255.
circfill
void circfill(int x, int y, int r, int colour)
Draws a filled circle.
x: how far the centre is from the window's left edge, in pixels.y: how far the centre is from the window's top, in pixels.r: the radius, in pixels.colour: the colour to fill it with, from 0 to 255.
tri
void tri(int x0, int y0, int x1, int y1, int x2, int y2, int colour)
Draws a filled triangle between three corners.
x0: how far the first corner is from the window's left edge, in pixels.y0: how far the first corner is from the window's top, in pixels.x1: how far the second corner is from the window's left edge, in pixels.y1: how far the second corner is from the window's top, in pixels.x2: how far the third corner is from the window's left edge, in pixels.y2: how far the third corner is from the window's top, in pixels.colour: the colour to fill it with, from 0 to 255.
text
void text(const char *s, int x, int y, int colour)
Writes text in the built-in font. Each character takes a cell 6 pixels wide and 9 high, and \n starts a new line.
s: the text to write.x: how far the text's left edge is from the window's left edge, in pixels.y: how far the text's top is from the window's top, in pixels.colour: the text's colour, from 0 to 255.
textwidth
int textwidth(const char *s)
Measures how wide some text would be, so you can line it up before you write it.
s: the text to measure.
Returns its width in pixels: 6 for each character, or the widest line's width if it has more than one.
clip
void clip(int x, int y, int w, int h)
Limits drawing to a rectangle, so nothing is drawn outside it. The camera doesn't move the rectangle.
x: how far the rectangle's left edge is from the window's left edge, in pixels.y: how far the rectangle's top edge is from the window's top, in pixels.w: the rectangle's width in pixels.h: the rectangle's height in pixels.
noclip
void noclip(void)
Lets you draw anywhere in the window, or the picture you're drawing into, again after clip.
It takes nothing.
camera
void camera(int x, int y)
Moves everything drawn after it by -x, -y. Use it to scroll a world that's bigger than the window, and camera(0, 0) to put it back.
x: how far to the right the view moves, in pixels.y: how far down the view moves, in pixels.
box
void box(int x, int y, int w, int h, int fill, int outline)
Draws a filled rectangle with an outline in another colour.
x: how far its left edge is from the window's left edge, in pixels.y: how far its top edge is from the window's top, in pixels.w: its width in pixels.h: its height in pixels.fill: the colour inside, from 0 to 255.outline: the outline's colour, from 0 to 255, or -1 for no outline.
centertext
void centertext(const char *s, int x, int y, int colour)
Writes text centred on a point across, which is handy for titles and buttons.
s: the text to write.x: where the middle of the text goes, in pixels from the window's left edge.y: how far the text's top is from the window's top, in pixels.colour: the text's colour, from 0 to 255.
shadowtext
void shadowtext(const char *s, int x, int y, int colour, int shadow)
Writes text with a shadow one pixel down and to the right, so it stands out on a busy background.
s: the text to write.x: how far the text's left edge is from the window's left edge, in pixels.y: how far the text's top is from the window's top, in pixels.colour: the text's colour, from 0 to 255.shadow: the shadow's colour, from 0 to 255. 0 is black.
textscaled
void textscaled(const char *s, int x, int y, int colour, int scale)
Writes text with every pixel of the font made bigger.
s: the text to write.x: how far the text's left edge is from the window's left edge, in pixels.y: how far the text's top is from the window's top, in pixels.colour: the text's colour, from 0 to 255.scale: how big each font pixel is: 2 makes the text twice as big. Below 1 counts as 1.
wraptext
int wraptext(const char *s, int columns)
Breaks text into lines short enough to fit, breaking at spaces where it can. Read the lines afterwards with wrapline.
s: the text to break up. Each\nin it starts a new line.columns: the most characters a line can have. Below 1 counts as 1.
Returns how many lines there are.
wrapline
int wrapline(int i, char *buf, int size)
Gives you one of the lines the last wraptext made.
i: which line, counting from 0.buf: where to put the line's text.size: how many bytesbufholds. A line that's too long is cut short to fit.
Returns the whole line's length in characters, or -1 if there's no line i.
Colours
pal
void pal(int colour, int r, int g, int b)
Changes what one colour number looks like, everywhere on the screen, until you put it back with palreset.
colour: the colour number to change, from 0 to 255.r: how much red it has, from 0 to 255.g: how much green it has, from 0 to 255.b: how much blue it has, from 0 to 255.
palreset
void palreset(void)
Puts every colour back to how it normally looks, after pal.
It takes nothing.
drawpal
void drawpal(int from, int to)
From now on, anything you draw in one colour is drawn in another instead. Use it to flash a sprite white when it's hit, for example.
from: the colour to swap, from 0 to 255.to: the colour to draw instead, from 0 to 255.
drawpalreset
void drawpalreset(void)
Stops swapping colours, so every colour draws as itself again.
It takes nothing.
nearestcolor
int nearestcolor(int r, int g, int b)
Finds which of the 256 colours is closest to a mix of red, green and blue, as they look now.
r: how much red, from 0 to 255.g: how much green, from 0 to 255.b: how much blue, from 0 to 255.
Returns the nearest colour number, from 0 to 255.
The window's memory
screenmem
int screenmem(void)
Gives you the address of your window's picture in memory, so you can write pixels into it directly. Each pixel is one byte holding its colour: the pixel at x, y is at the address plus y * screenwidth() + x.
It takes nothing.
Returns the address. Turn it into a pointer with (unsigned char *)screenmem().
screenwidth
int screenwidth(void)
Tells you how wide your window's picture is. Ask again after the window is resized, because it gets a new picture.
It takes nothing.
Returns the width in pixels.
screenheight
int screenheight(void)
Tells you how tall your window's picture is. Ask again after the window is resized.
It takes nothing.
Returns the height in pixels.
The screen
display_width
int display_width(void)
Tells you how wide the whole screen is now.
It takes nothing.
Returns the screen's width in pixels.
display_height
int display_height(void)
Tells you how tall the whole screen is now.
It takes nothing.
Returns the screen's height in pixels.
display_current
void display_current(int *w, int *h, int *colours)
Tells you the screen's size and how many colours it shows, all in one call.
w: where to put the width in pixels: pass the address of anint, like&w, orNULL.h: where to put the height in pixels: pass the address of anint, like&h, orNULL.colours: where to put the number of colours (8, 256 orCOLORS_THOUSANDS): pass&colours, orNULL.
display_sizes
int display_sizes(void)
Finds out which sizes the screen can be. Read each one afterwards with display_size.
It takes nothing.
Returns how many sizes there are.
display_size
int display_size(int i, int *w, int *h)
Gives you one of the sizes the last display_sizes found. Call display_sizes first.
i: which size, counting from 0.w: where to put its width in pixels: pass the address of anint, like&w.h: where to put its height in pixels: pass the address of anint, like&h.
Returns 1 if there's a size i, or 0 if there isn't.
display_request
void display_request(int w, int h, int colours, void (*fn)(int ok))
Asks for the screen to be a different size or show a different number of colours. The person is asked first, and if they don't allow it, your program closes. The screen goes back when your program quits.
w: the width you want, in pixels, or 0 to keep it as it is.h: the height you want, in pixels, or 0 to keep it as it is.colours: 8, 256 orCOLORS_THOUSANDS, or 0 to keep it as it is.fn: your function to call with the answer:okis 1 once the screen has changed, 0 if that size isn't one it can be.NULLif you don't need to know.
Pictures
newpicture
int newpicture(int w, int h)
Makes a new, empty picture that you can draw into or draw from. Every pixel starts as colour 0.
w: its width in pixels, from 1 to 4096.h: its height in pixels, from 1 to 4096.
Returns the picture's number, or 0 if the size is out of range.
loadpicture
int loadpicture(const char *path)
Loads a picture from a file: a .pxl saved by Paint, or a .png.
path: the file's path, from your program's folder unless it starts with/.
Returns the picture's number, or 0 if the file couldn't be read.
freepicture
void freepicture(int p)
Lets go of a picture you've finished with. Don't use its number afterwards: that stops your program with an error.
p: the picture's number.
picturewidth
int picturewidth(int p)
Tells you how wide a picture is.
p: the picture's number.
Returns its width in pixels.
pictureheight
int pictureheight(int p)
Tells you how tall a picture is.
p: the picture's number.
Returns its height in pixels.
drawpicture
void drawpicture(int p, int x, int y, int key)
Draws a whole picture into the window, or into the picture you're drawing into.
p: the picture's number.x: how far its left edge goes from the window's left edge, in pixels.y: how far its top edge goes from the window's top, in pixels.key: a colour to leave out so it's see-through, usually 0, or -1 to draw every pixel.
drawpart
void drawpart(int p, int sx, int sy, int sw, int sh, int x, int y, int key)
Draws one rectangle of a picture, such as a single frame from a sheet of them.
p: the picture's number.sx: how far the part's left edge is from the picture's left edge, in pixels.sy: how far the part's top edge is from the picture's top, in pixels.sw: the part's width in pixels.sh: the part's height in pixels.x: how far it goes from the window's left edge, in pixels.y: how far it goes from the window's top, in pixels.key: a colour to leave out so it's see-through, usually 0, or -1 to draw every pixel.
drawinto
void drawinto(int p)
Sends all drawing into a picture instead of your window, so you can build something once and draw it many times. It also undoes any clip.
p: the picture to draw into, or 0 to go back to drawing into the window.
drawpictureex
void drawpictureex(int p, int x, int y, int key, int scale, int flipx, int flipy)
Draws a whole picture, made bigger or flipped.
p: the picture's number.x: how far its left edge goes from the window's left edge, in pixels.y: how far its top edge goes from the window's top, in pixels.key: a colour to leave out so it's see-through, usually 0, or -1 to draw every pixel.scale: how big each pixel is drawn: 2 makes it twice as big. Below 1 counts as 1.flipx: 1 to mirror it left to right, 0 not to.flipy: 1 to turn it upside down, 0 not to.
drawpartex
void drawpartex(int p, int sx, int sy, int sw, int sh, int x, int y, int key, int scale, int flipx, int flipy)
Draws one rectangle of a picture, made bigger or flipped.
p: the picture's number.sx: how far the part's left edge is from the picture's left edge, in pixels.sy: how far the part's top edge is from the picture's top, in pixels.sw: the part's width in pixels.sh: the part's height in pixels.x: how far it goes from the window's left edge, in pixels.y: how far it goes from the window's top, in pixels.key: a colour to leave out so it's see-through, usually 0, or -1 to draw every pixel.scale: how big each pixel is drawn: 2 makes it twice as big. Below 1 counts as 1.flipx: 1 to mirror it left to right, 0 not to.flipy: 1 to turn it upside down, 0 not to.
savepicture
int savepicture(int p, const char *path)
Saves a picture as a .pxl file, which Paint can open.
p: the picture's number.path: the file to save it as, from your program's folder unless it starts with/.
Returns 1 if it was saved, or 0 if it couldn't be.
parsepicture
int parsepicture(const char **rows, int n, const char *chars, const int *colours)
Makes a picture from rows of text, one character for each pixel. It's a quick way to draw small things in your code.
rows: an array of strings, one for each row of pixels, from the top.n: how many rows there are.chars: the characters you use, in a string, like".#o".NULLmeans.is colour 0, and0-9anda-vare colours 0 to 31.colours: an array giving the colour for each character inchars, in the same order. Characters not incharsare 0.
Returns the picture's number, or 0 if it couldn't be made. It's as wide as the longest row.
decodepicture
int decodepicture(const void *png, int n, int maxw, int maxh, int background, int sprite, int *w, int *h)
Makes a picture from PNG data in memory, such as a file you've read or something downloaded. It's shrunk to fit if it's too big.
png: where the PNG's bytes are.n: how many bytes there are.maxw: the widest the picture can be, in pixels, or 0 for any width (up to 4096).maxh: the tallest the picture can be, in pixels, or 0 for any height (up to 4096).background: the colour see-through parts are put on, as0xRRGGBB, or -1 for white.sprite: 1 for pixel art: no dithering, and see-through parts stay colour 0. 0 for a photo.w: where to put the PNG's own width before shrinking: pass the address of anint, like&w, orNULL.h: where to put the PNG's own height before shrinking: pass the address of anint, like&h, orNULL.
Returns the picture's number, or 0 if the data isn't a PNG it can read.
decodepicturefile
int decodepicturefile(const char *path, int maxw, int maxh, int background, int sprite, int *w, int *h)
The same as decodepicture, but reads the PNG from a file.
path: the PNG file's path, from your program's folder unless it starts with/.maxw: the widest the picture can be, in pixels, or 0 for any width (up to 4096).maxh: the tallest the picture can be, in pixels, or 0 for any height (up to 4096).background: the colour see-through parts are put on, as0xRRGGBB, or -1 for white.sprite: 1 for pixel art: no dithering, and see-through parts stay colour 0. 0 for a photo.w: where to put the PNG's own width before shrinking: pass the address of anint, like&w, orNULL.h: where to put the PNG's own height before shrinking: pass the address of anint, like&h, orNULL.
Returns the picture's number, or 0 if the file couldn't be read as a PNG.
importpicture
int importpicture(const void *png, int n, int maxw, int maxh, int *w, int *h)
Brings in a PNG made elsewhere, ready for editing: each pixel becomes the nearest of the 256 colours, and see-through parts become colour 0. It's made smaller only if it doesn't fit.
png: where the PNG's bytes are.n: how many bytes there are.maxw: the widest the picture can be, in pixels, or 0 for 256.maxh: the tallest the picture can be, in pixels, or 0 for 256.w: where to put the PNG's own width: pass the address of anint, like&w, orNULL.h: where to put the PNG's own height: pass the address of anint, like&h, orNULL.
Returns the picture's number, or 0 if the data isn't a PNG it can read.
importpicturefile
int importpicturefile(const char *path, int maxw, int maxh, int *w, int *h)
The same as importpicture, but reads the PNG from a file.
path: the PNG file's path, from your program's folder unless it starts with/.maxw: the widest the picture can be, in pixels, or 0 for 256.maxh: the tallest the picture can be, in pixels, or 0 for 256.w: where to put the PNG's own width: pass the address of anint, like&w, orNULL.h: where to put the PNG's own height: pass the address of anint, like&h, orNULL.
Returns the picture's number, or 0 if the file couldn't be read as a PNG.
pictureget
int pictureget(int p, int x, int y)
Reads the colour of one pixel of a picture.
p: the picture's number.x: how far the pixel is from the picture's left edge, in pixels.y: how far the pixel is from the picture's top, in pixels.
Returns the pixel's colour, from 0 to 255, or 0 if it's outside the picture.
pictureset
void pictureset(int p, int x, int y, int colour)
Sets one pixel of a picture to a colour. A pixel outside the picture is left alone.
p: the picture's number.x: how far the pixel is from the picture's left edge, in pixels.y: how far the pixel is from the picture's top, in pixels.colour: the colour to set it to, from 0 to 255.
picturesize
void picturesize(int p, int *w, int *h)
Tells you a picture's width and height in one call.
p: the picture's number.w: where to put the width in pixels: pass the address of anint, like&w, orNULL.h: where to put the height in pixels: pass the address of anint, like&h, orNULL.
pictureclear
void pictureclear(int p, int colour)
Fills a whole picture with one colour.
p: the picture's number.colour: the colour to fill it with, from 0 to 255.
picturecopy
int picturecopy(int p)
Makes a new picture that's the same as another one, so you can change the copy and keep the first.
p: the number of the picture to copy.
Returns the new picture's number.
picturegetrgb
void picturegetrgb(int p, int x, int y, int *r, int *g, int *b)
Reads a pixel's true colour as red, green and blue. That's what shows when the screen is in thousands of colours.
p: the picture's number.x: how far the pixel is from the picture's left edge, in pixels.y: how far the pixel is from the picture's top, in pixels.r: where to put the red, from 0 to 255: pass the address of anint, like&r, orNULL.g: where to put the green, from 0 to 255: pass the address of anint, like&g, orNULL.b: where to put the blue, from 0 to 255: pass the address of anint, like&b, orNULL.
picturesetrgb
void picturesetrgb(int p, int x, int y, int r, int g, int b)
Sets a pixel's true colour, which shows when the screen is in thousands of colours. The pixel's colour number becomes the nearest of the 256.
p: the picture's number.x: how far the pixel is from the picture's left edge, in pixels.y: how far the pixel is from the picture's top, in pixels.r: how much red, from 0 to 255.g: how much green, from 0 to 255.b: how much blue, from 0 to 255.
Sprites and the map
spr
void spr(int n, int x, int y)
Draws one 16 x 16 sprite from your program's sprite sheet, gfx.pxl. Colour 0 in it is see-through.
n: the sprite's number, from 0 to 255. Sprite 0 is the top-left one, and 16 starts the second row.x: how far its left edge goes from the window's left edge, in pixels.y: how far its top edge goes from the window's top, in pixels.
sprex
void sprex(int n, int x, int y, int w, int h, int flipx, int flipy)
Draws a block of sprites together, flipped if you like. A 2 x 2 block is a 32 x 32 sprite made of four.
n: the number of the block's top-left sprite, from 0 to 255.x: how far its left edge goes from the window's left edge, in pixels.y: how far its top edge goes from the window's top, in pixels.w: how many sprites across the block is. Below 1 counts as 1.h: how many sprites down the block is. Below 1 counts as 1.flipx: 1 to mirror it left to right, 0 not to.flipy: 1 to turn it upside down, 0 not to.
sspr
void sspr(int sx, int sy, int sw, int sh, int x, int y, int scale, int flipx, int flipy)
Draws any rectangle of the sprite sheet, given in pixels rather than sprites.
sx: how far the rectangle's left edge is from the sheet's left edge, in pixels.sy: how far the rectangle's top edge is from the sheet's top, in pixels.sw: the rectangle's width in pixels.sh: the rectangle's height in pixels.x: how far it goes from the window's left edge, in pixels.y: how far it goes from the window's top, in pixels.scale: how big each pixel is drawn: 2 makes it twice as big. Below 1 counts as 1.flipx: 1 to mirror it left to right, 0 not to.flipy: 1 to turn it upside down, 0 not to.
fget
int fget(int n)
Reads a sprite's flags, from gfx.flags. Flags mean whatever you decide, such as flag 0 for a solid tile.
n: the sprite's number, from 0 to 255.
Returns all 8 flags as one number, from 0 to 255: flag f is set if (fget(n) >> f) & 1 is 1.
fset
void fset(int n, int flags)
Sets all 8 of a sprite's flags at once, while your program runs.
n: the sprite's number, from 0 to 255.flags: the flags as one number, from 0 to 255: add1 << ffor each flagfyou want set.
map
void map(int cx, int cy, int x, int y, int cw, int ch, const char *layer)
Draws tiles from your program's map, map.map, each one a 16 x 16 sprite. Only the tiles inside the window are drawn, and empty tiles (0) aren't drawn at all.
cx: which column of the map to start from, counting tiles from 0.cy: which row of the map to start from, counting tiles from 0.x: how far from the window's left edge to draw, in pixels.y: how far from the window's top to draw, in pixels.cw: how many tiles across to draw, or 0 for the layer's whole width.ch: how many tiles down to draw, or 0 for the layer's whole height.layer: the layer's name, like"Terrain", orNULLfor the first layer.
mget
int mget(int x, int y, const char *layer)
Reads one tile of the map.
x: the tile's column, counting from 0.y: the tile's row, counting from 0.layer: the layer's name, orNULLfor the first layer.
Returns the tile's sprite number, or 0 if it's empty, off the map, or there's no such layer.
mset
void mset(int x, int y, int n, const char *layer)
Changes one tile of the map while your program runs. A tile off the map is left alone.
x: the tile's column, counting from 0.y: the tile's row, counting from 0.n: the sprite number to put there, from 0 to 255. 0 makes it empty.layer: the layer's name, orNULLfor the first layer.
mapwidth
int mapwidth(const char *layer)
Tells you how many tiles across a map layer is.
layer: the layer's name, orNULLfor the first layer.
Returns its width in tiles, or 0 if there's no such layer.
mapheight
int mapheight(const char *layer)
Tells you how many tiles down a map layer is.
layer: the layer's name, orNULLfor the first layer.
Returns its height in tiles, or 0 if there's no such layer.
maplayers
int maplayers(void)
Tells you how many layers your map has.
It takes nothing.
Returns how many layers there are.
maplayername
int maplayername(int i, char *buf, int size)
Gives you the name of one of the map's layers, to pass to map or mget.
i: which layer, counting from 0.buf: where to put the layer's name.size: how many bytesbufholds. A name that's too long is cut short to fit.
Returns the whole name's length, or 0 if there's no layer i.
Sprites as pictures
sprimage
int sprimage(int n, int w, int h)
Copies a sprite, or a block of them, into a picture of its own. Use it to scale a sprite or use it as a 3D texture.
n: the number of the top-left sprite, from 0 to 255.w: how many sprites across to copy, from 1 to 16, or 0 for 1.h: how many sprites down to copy, from 1 to 16, or 0 for 1.
Returns the new picture's number, or 0 if it couldn't be made.
spritesheet
int spritesheet(void)
Gives you your program's whole sprite sheet as a picture, 256 x 256 pixels. Whatever you draw into it shows in spr and map straight away.
It takes nothing.
Returns the sprite sheet's picture number. It's the same number each time.
Maps made elsewhere
importmap
int importmap(const char *path)
Reads a map made in another program: a Tiled map (.tmx or .json) or a CSV of tile numbers. It keeps at most 8 layers.
path: the map file's path, from your program's folder unless it starts with/.
Returns a number for the imported map, or 0 if it couldn't be read.
importmapimage
int importmapimage(const char *path, int tilesize)
Reads a picture of a whole level (a PNG) and cuts it into tiles. Each different tile becomes a sprite, numbered 1, 2, 3 in the order they're first met, and see-through tiles are 0.
path: the PNG file's path, from your program's folder unless it starts with/.tilesize: how many pixels across each tile is, from 4 to 64, or 0 for 16. Other sizes are made 16 x 16.
Returns a number for the imported map, or 0 if it couldn't be read.
imap_layers
int imap_layers(int m)
Tells you how many layers an imported map has.
m: the imported map's number.
Returns how many layers it has.
imap_layername
int imap_layername(int m, int layer, char *buf, int size)
Gives you the name of one of an imported map's layers.
m: the imported map's number.layer: which layer, counting from 0.buf: where to put the layer's name.size: how many bytesbufholds. A name that's too long is cut short to fit.
Returns the whole name's length, or -1 if there's no such layer.
imap_size
int imap_size(int m, int layer, int *w, int *h)
Tells you how big one layer of an imported map is, in tiles.
m: the imported map's number.layer: which layer, counting from 0.w: where to put its width in tiles: pass the address of anint, like&w, orNULL.h: where to put its height in tiles: pass the address of anint, like&h, orNULL.
Returns 1 if there's such a layer, or 0 if there isn't.
imap_get
int imap_get(int m, int layer, int x, int y)
Reads one tile of an imported map.
m: the imported map's number.layer: which layer, counting from 0.x: the tile's column, counting from 0.y: the tile's row, counting from 0.
Returns the tile's sprite number, or 0 if it's empty, off the map, or there's no such layer.
imap_picture
int imap_picture(int m)
Gives you a 256 x 256 picture of the imported map's tiles, each in its sprite's place, laid out like a sprite sheet.
m: the imported map's number.
Returns the picture's number, or 0 if the map brought no tiles with it.
imap_used
int imap_used(int m, int sprite)
Tells you whether the imported map's tiles fill a sprite, so you know which places in the sheet they take.
m: the imported map's number.sprite: the sprite number to ask about, from 0 to 255.
Returns 1 if the map's tiles fill that sprite, or 0 if they don't.
imap_notes
int imap_notes(int m)
Tells you how many notes the import left, about what was left out or changed. Read each one with imap_note.
m: the imported map's number.
Returns how many notes there are.
imap_note
int imap_note(int m, int i, char *buf, int size)
Gives you one of the import's notes, as text you can show the person.
m: the imported map's number.i: which note, counting from 0.buf: where to put the note's text.size: how many bytesbufholds. A note that's too long is cut short to fit.
Returns the whole note's length, or -1 if there's no note i.
imap_free
void imap_free(int m)
Lets go of an imported map you've finished with. A picture you got from imap_picture stays until you freepicture it.
m: the imported map's number.