Difference between revisions of "Gb.h"
(gb.h function overview page started with brief descriptions and an example) |
m (A couple of errors fixed) |
||
Line 6: | Line 6: | ||
== Important functions: == | == Important functions: == | ||
− | <code>delay(UINT16 d | + | <code>delay(UINT16 d)</code> waits for the specified number of milliseconds. |
<code>joypad(void)</code> checks the input buttons of the Game Boy and returns the state of each button. | <code>joypad(void)</code> checks the input buttons of the Game Boy and returns the state of each button. | ||
Line 16: | Line 16: | ||
<code>move_sprite( UINT8 nb, UINT8 x, UINT8 y)</code> moves sprite number <code>nb</code> to position <code>x</code>, <code>y</code> on the screen. | <code>move_sprite( UINT8 nb, UINT8 x, UINT8 y)</code> moves sprite number <code>nb</code> to position <code>x</code>, <code>y</code> on the screen. | ||
− | <code>SHOW_SPRITES</code> turns on the sprite layer. | + | <code>SHOW_SPRITES;</code> turns on the sprite layer. |
− | <!-- Honestly this code block could be | + | <!-- Honestly this code block could be stored elsewhere and transcluded --> |
<div class="toccolours mw-collapsible mw-collapsed"> | <div class="toccolours mw-collapsible mw-collapsed"> | ||
Example: | Example: | ||
Line 37: | Line 37: | ||
if(joypad() & J_START){ //If joypad() indicates that Start is pressed... | if(joypad() & J_START){ //If joypad() indicates that Start is pressed... | ||
set_sprite_data(0, 1, Check); //Turn the array into sprite number 0 | set_sprite_data(0, 1, Check); //Turn the array into sprite number 0 | ||
− | set_sprite_tile(0, 0); //Draw sprite number 0 to the screen | + | set_sprite_tile(0, 0); //Draw tile 0 of sprite number 0 to the screen |
move_sprite(0, 80, 80); //Move sprite number 0 to the middle of the screen | move_sprite(0, 80, 80); //Move sprite number 0 to the middle of the screen | ||
SHOW_SPRITES; //Turn on the sprite layer | SHOW_SPRITES; //Turn on the sprite layer |
Revision as of 09:12, 3 June 2016
gb/gb.h
handles basic inputs and drawing background and sprites to the screen.
Important definitions:
J_START
, J_SELECT
, J_B
, J_A
, J_DOWN
, J_UP
, J_LEFT
, and J_RIGHT
are keyed to these specific hardware inputs, and can be checked with the joypad()
function.
Important functions:
delay(UINT16 d)
waits for the specified number of milliseconds.
joypad(void)
checks the input buttons of the Game Boy and returns the state of each button.
set_sprite_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data)
feeds a tile as described in array data
into sprite data, starting at first_tile
and writing for nb_tiles
number of tiles.
set_sprite_tile(UINT8 nb, UINT8 tile)
displays tile number tile
of sprite number nb
.
move_sprite( UINT8 nb, UINT8 x, UINT8 y)
moves sprite number nb
to position x
, y
on the screen.
SHOW_SPRITES;
turns on the sprite layer.
Example:
#include <gb/gb.h> //include the main GBDK library header //This example successfully compiles under GBDK version 2.96a //and draws a rudimentary check mark when the start button is pressed. unsigned char Check[] = //A simple sprite to load, made in GBTD { 0x00,0x00,0x01,0x01,0x02,0x02,0x44,0x44, 0x28,0x28,0x10,0x10,0x00,0x00,0x00,0x00 }; int main(){ //the main and required function while(1){ //loop forever if(joypad() & J_START){ //If joypad() indicates that Start is pressed... set_sprite_data(0, 1, Check); //Turn the array into sprite number 0 set_sprite_tile(0, 0); //Draw tile 0 of sprite number 0 to the screen move_sprite(0, 80, 80); //Move sprite number 0 to the middle of the screen SHOW_SPRITES; //Turn on the sprite layer } } } //end of main function