Working with the screen
void setimagesize(fixed size);
sets the size of the Image using a multiplier indicating the size.Affects only the functions putimage, putimage, putimagerle
setimagesize(2.1)
;
void setclip(int x, int y, int width, int height);
sets the area in which the drawing and scrolling takes place. Does not affect sprites.
void gotoxy(int x, int y);
moves the Cursor to the Text screen co-ordinates denoted by x & y.
gotoxy(6,6);
void scroll(int dir);
scrolls the Screen in the direction indicated by dir. 2 = x – 1 (i.e. Left) 1 = y – 1 (i.e. Up) 0 = x+ 1 (i.e. Right) any other number = y + 1 (i.e. Down)
scroll(2);
void delayredraw();
delays the redrawing of the Screen for a small period of time
void clearscreen();
Clears the entire screen with the color setbgcolor. Does not affect sprites.
void setframerate(int fps);
Changes the framerate in the range of 1-40 frames per second.
setframerate(40);
Image work
void putimage(int address, int x, int y, int w, int h);
puts an image on the Screen. The image is denoted by address. The Screen co-ordinates by x & y, and the image width & height by w & h.
putimage(eat_spr, eatx * 3, eaty * 3, 3, 3);
void putimage1bit(int address, int x, int y, int w, int h);
puts a 1bit image on the Screen. The image is denoted by address. The Screen co-ordinates by x & y, and the image width & height by w & h.
putimage1bit(startscreen, 0, 16, 64, 32);
void putimagerle(int address, int x, int y, int w, int h);
puts an RLE image on the Screen. The image is denoted by address. The Screen co-ordinates by x & y, and the image width & height by w & h.
putimagerle(earth, 0, 0, 16, 16);
Work with palette and colors.
void setpalette(int n, int r5g6b5);
changes the Palette colour denoted by n to the colour denoted by r5g6b5 (as an RGB value).
setpallette(14, 0xE718);
void setcolor(int color);
sets the current Pen colour to the colour from the Palette denoted by col (i.e. a value between 0 & 15).
setcolor(0);
void setbgcolor(int color);
sets the current Background colour to the colour from the Palette denoted by col (i.e. a value between 0 & 15).
setcolor(0);
Working with sprites
int spritegetvalue(int n, int type);
returns the value for the Sprite specified in n, according to the type.
x = spritegetvalue(1, S_LIVES);
void spritesetvalue(int n, int type, int value);
sets the value denoted by value of the type denoted by type for the Sprite denoted by n.
spritesetvalue(i, S_WIDTH, 8);
The available values for type are:
- S_X the x co-ordinate
- S_Y the y co-ordinate
- S_SPEEDX the Speed in the x direction
- S_SPEEDY the Speed in the y direction
- S_WIDTH the Width
- S_HEIGHT the Height
- S_IS_ONEBIT whether the Sprite is 1 bit, or not. 1 = True, 0 = False
- S_ANGLE the Angle of the Sprite (0-360)
- S_LIVES number of Lives for the Sprite
- S_COLLISION the ID of the Sprite that this Sprite is currently colliding with
- S_SOLID whether the Sprite is Solid, or not. 1 = True, 0 = False
- S_GRAVITY whether the Sprite is affected by Gravity, or not. 1 = True, 0 = False
- S_ON_COLLISION the Function to execute when the Sprite collides with another Sprite. NB: when entering the name of the Function, just use the name, not the brackets. For example, use bombcollision, not bombcollision().
- S_ON_EXIT_SCREEN the Function to execute when the Sprite moves off Screen. NB: when entering the name of the Function, just use the name, not the brackets. For example, use exit, not exit().
- S_IS_SCROLLED whether the Sprite is scrolled with the Screen, or not. 1 = True, 0 = False
- S_FLIP_HORIZONTAL flip Sprite horizontally 1 = True, 0 = False
int angbetweenspr(int n1, int n2);
returns the angle, in degrees, between the two Sprites denoted by n1 & n2.
x = angbetweenspr(1, 2);
void getsprite(int n, int address);
gets the Sprite denoted by address (i.e. the name of the Sprite in its definition) and assigns it to the Sprite denoted by n.
这个更像是设置spite,下列代码将1号sprite设置为bird数组指定的内容
getsprite(1, bird);
void putsprite(int n, int x, int y);
puts the Sprite denoted by n at the co-ordinates on the Screen denoted by x & y.
putsprite(1, 5, 60);
void spritespeed(int n, int speed, int direction);
Sets the sprite to n speed in the direction (0 - 360 degrees).
spritespeed(1, 12, 120);
int getspriteinxy(int x, int y);
Gets the number of the sprite which is in the x & y position
Working with geometry
void putpixel(int x, int y);
puts a Pixel at the co-ordinates on the Screen denoted by x & y.
putpixel(stars.x,stars.y);
int getpixel(int x, int y);
returns the contents of the Pixel at the co-ordinates denoted by x & y.
color = getpixel(x * 2, y * 2);
void line(int x, int y, int x1, int y1);
draws a line from point x&y to point x1&y1
void rect(int x, int y, int x1, int y1);
draws a square from point x&y (top left corner) to point x1&y1 (bottom right corner)
void fillrect(int x, int y, int x1, int y1);
draws a filled square from the point x&y (top left corner) to the point x1&y1 (bottom right corner).
void triangle(int x, int y, int x1, int y1, int x2, int y2);
draws a triangle between points x&y x1&y1 x2&y2
void filltriangle(int x, int y, int x1, int y1, int x2, int y2);
draws a filled triangle between points x&y x1&y1 x2&y2
void circle(int x, int y, int r);
draws a circle with its center at the x&y point and radius r
void fillcircle(int x, int y, int r);
draws a filled circle with its center at the x&y point and radius r
Working with strings
char putchar(char c);
prints a character to the Screen at the current x & y text co-ordinates.
putchar(10);
int puts(char[] message);
prints a 1-D char array to the Screen at the current x & y co-ordinates.
puts(“Press any key”);
int putn(int number);
prints an integer in decimal format
int printf(char[] formatString, arg-list...);
prints a line with a specified formatting. Supported %d (number int) %f (number fixed) %s (string) %c (character)
printf("a+b=%d", a + b);
int getchar();
gets a character from the keyboard. The program is interrupted and waits for the character to be entered.
loadfont(char[] font, char first, char end);
Load the font picture and initialize the characters from first to end. The characters should follow the order according to ASCII.
loadfont(font1, 'a', 'z'); // the picture font1 contains letters A to Z, in ACII order (means A, B, C, D, etc.)
setfontsize(int picture_width, int picture_height, int character_width, int character_height);
Sets the size of the font previously loaded.
setfontsize(32, 32, 8, 16); // the size of the picture is 32x32 and the size of each character is 8x16
drawstring(char[] text, int x, int y);
Draws the text on the screen at coordinates x and y.
drawstring("lorem ipsum\ndolor sit amet", 9, 25); // the \n is a line-break
drawchar(char character, int x, int y);
Draws the character on the screen at coordinates x and y.
drawchar("b", 6, 14);
Working with a tile map.
void loadtile(int adress, int imgwidth, int imgheight, int width, int height);
loads a Tile denoted by address, setting the required width & height, based on the original width & height of the Tile (imgwidth & imgheight).
loadtile(maze, 8, 8, 15, 15);
void drawtile(int x, int y);
draws a Tile at the Screen co-ordinates denoted by x & y.
drawtile(4 ,4);
void setcollisionmap(int adress);
If it is not used, the sprites' collisions with the tiles are checked against the tiles map. Otherwise, they are checked against the collision map. The collision map must be a single bit. Its size is the same as the size of the collision map.
int gettileinxy(int x, int y);
gets the address of the image in a cell at x&y at the Screen co-ordinates denoted by x & y.
x = gettileinxy(x1, y1);
Working with particles
void setparticle(int gravity, int count, int time);
creates a Particle. The Gravity value is denoted by gravity, where a value of 0 denotes no Gravity and an integer value denotes the amount of Gravity (Added to the speed along the y axis every frame). The number of Particles to be displayed is set by count and the length of Time that the Particle should run for is set by time (in milliseconds).
setparticle(0, 4, 1000);
void setemitter(int time, int dir, int dir1, int speed);
sets the Emitter for the Particle. The time for the Emitter to run is denoted by time (in milliseconds), the x direction is denoted by dir, the y direction is denoted by dir1 and the speed of the Particles is denoted by speed.
setemitter(50, angle - 10, angle + 10, 9);
void emittersize(int width, int height, int size);
sets the size of the emitter area (width, height) and the size of the sprite (size)
void drawparticle(int x, int y, int color);
draws the Particle at the co-ordinates denoted by x & y and in the colour denoted by color.
drawparticle(64, 64, 6);
Button operation
int getkey();
returns the value of the key currently being pressed on the keyboard. The value returned will be one of the following (the number in brackets is the integer value representing the key): KEY_UP (1), KEY_LEFT (4), KEY_DOWN (2), KEY_RIGHT (8), KEY_A (16), KEY_B (32), KEY_SELECT (64), KEY_START (128) NB: UP, DOWN, LEFT & RIGHT map to the Arrow keys or WASD, A is the z key, B is the x key SELECT is the c key and START is the v key.
key = getkey();
Working with timers
int gettimer(int n);
returns the current value of the Timer, in milliseconds, denoted by n. Total 8 timers from 0 to 7
x = gettimer(0);
void settimer(int n, int time);
sets the Timer denoted by n to the time, in milliseconds, denoted by time.
settimer(0, 1000);
Working with data storage
int savedata(int name, int array, int count);
Saves the array in flash memory. "name" indicates the name of the storage. Count indicates the number of bytes to be saved. (int and fixed contains two bytes, and the size of the array should be multiplied by two). Returns the number of bytes saved.
int loaddata(int name, int array);
Uploads previously saved data under the name "name" to an array. Returns the number of bytes loaded.
Working with sound and music
void tone(int freq, int delay);
Plays the sound at the right frequency for the right time.
void loadrtttl(int address, int isLoop);
Loads a melody in rtttl format into the player. isLoop can be 0 (play once) and 1 (play in a circle).
void playrtttl();
Play the melody
void pausertttl();
Pause the melody
void stoprtttl();
Stop the melody
Mathematical functions
fixed sin(int angle);
Returns sinus from angle (takes values in degrees from 0 to 360)
fixed cos(int angle);
Returns cosinus from angle (takes values in degrees from 0 to 360)
int distance(int x1, int y1, int x2, int y2);
Returns the distance between two points
Working with memory
*int malloc(int size);
Allocates memory by returning a pointer or 0 if no memory was allocated.
void free(*int array);
Releases previously allocated memory. Accepts pointer.
void memcpy(*int array1, *int array2, int size);
Copies Array2 to Array1 with a long "size"
char arr[] = {0,1,2,3,4}'
char buf[5];
memcpy(buf, arr, 5);
putn(buf[2]);