Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gb/gb.h>
- #include <gb/drawing.h>
- unsigned char flappy[] = //sprite data
- {
- 0x00,0x00,0x00,0x00,0x07,0x07,0x0F,0x08,
- 0x1F,0x11,0x7F,0x79,0x87,0x85,0x87,0x84,
- 0xC7,0x84,0x7F,0x44,0x39,0x3F,0x20,0x3F,
- 0x18,0x1F,0x07,0x07,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0xE0,0xE0,0x90,0x90,
- 0x08,0x08,0x14,0x14,0x14,0x14,0x84,0x84,
- 0xFE,0x7E,0xFF,0x81,0xFE,0x7E,0xFE,0x82,
- 0x7C,0xFC,0x80,0x80,0x00,0x00,0x00,0x00,
- 0xFF,0xFF,0xFF,0x80,0x9C,0xE3,0x9C,0xE3,
- 0x9C,0xE3,0x9C,0xE3,0x9C,0xE3,0x9C,0xE3,
- 0xFF,0xFF,0x4E,0x71,0x4E,0x71,0x4E,0x71,
- 0x4E,0x71,0x4E,0x71,0x4E,0x71,0x4E,0x71,
- 0xFF,0xFF,0xFF,0x01,0x01,0xFF,0x01,0xFF,
- 0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,
- 0xFF,0xFF,0x02,0xFE,0x02,0xFE,0x02,0xFE,
- 0x02,0xFE,0x02,0xFE,0x02,0xFE,0x02,0xFE,
- 0x4E,0x71,0x4E,0x71,0x4E,0x71,0x4E,0x71,
- 0x4E,0x71,0x4E,0x71,0x4E,0x71,0xFF,0xFF,
- 0xFF,0x80,0x9C,0xE3,0x9C,0xE3,0x9C,0xE3,
- 0x9C,0xE3,0x9C,0xE3,0x9C,0xE3,0xFF,0xFF,
- 0x02,0xFE,0x02,0xFE,0x02,0xFE,0x02,0xFE,
- 0x02,0xFE,0x02,0xFE,0x02,0xFE,0xFF,0xFF,
- 0xFF,0x01,0x01,0xFF,0x01,0xFF,0x01,0xFF,
- 0x01,0xFF,0x01,0xFF,0x01,0xFF,0xFF,0xFF,
- 0x4E,0x71,0x4E,0x71,0x4E,0x71,0x4E,0x71,
- 0x4E,0x71,0x4E,0x71,0x4E,0x71,0x4E,0x71,
- 0x4E,0x71,0x4E,0x71,0x4E,0x71,0x4E,0x71,
- 0x4E,0x71,0x4E,0x71,0x4E,0x71,0x4E,0x71,
- 0x02,0xFE,0x02,0xFE,0x02,0xFE,0x02,0xFE,
- 0x02,0xFE,0x02,0xFE,0x02,0xFE,0x02,0xFE,
- 0x02,0xFE,0x02,0xFE,0x02,0xFE,0x02,0xFE,
- 0x02,0xFE,0x02,0xFE,0x02,0xFE,0x02,0xFE
- };
- INT16 y = 80, v = 0, xt = 125, xb = 250, score = 0; // y = y ordinate for bird, v = bird's (negative) velocity, xt and xb = x ordinate for pipes (confusingly xt(op) is the lower one, xb(ottom) is the upper one. whoops!)
- UINT8 alive = 0, speed = 6; //alive determines if the game loop runs. speed determines the delay between frames (lower = faster)
- void main(){
- gotogxy(5,3); //set text position
- gprintf("Flappy Bird"); //print to screen
- gotogxy(2,5); //reset text position...
- gprintf("Made by Dante S-K");
- gotogxy(5,14);
- gprintf("PRESS START");
- SPRITES_8x16; //all sprites are handled as two sprites joined together, one on top of the other, making one 8x16 sprite. everything is made with two halves.
- set_sprite_data(0,16,flappy); //load all 16 sprites into memory (4 for the bird, 4 for the top pipe, 4 for the bottom pipe and 4 for the mid pipe)
- //set each sprite's tiles: set_sprite_tile(spriteno, tileno). numbers in comments to keep track of sprite number.
- set_sprite_tile(0,0); //bird L 0
- set_sprite_tile(1,2); //bird R 1
- set_sprite_tile(2,4); //top L 2
- set_sprite_tile(3,6); //top R 3
- set_sprite_tile(4,8); //bottom L 4
- set_sprite_tile(5,10); //bottom R 5
- set_sprite_tile(6,12); //pipe L 6 these all use the same tiles, hence the repeated 12 (left half) and 14 (right half)
- set_sprite_tile(7,14); //pipe R 7
- set_sprite_tile(8,12); //pipe L 8
- set_sprite_tile(9,14); //pipe R 9
- set_sprite_tile(10,12); //pipe L 10
- set_sprite_tile(11,14); //pipe R 11
- set_sprite_tile(12,12); //pipe L 12
- set_sprite_tile(13,14); //pipe R 13
- set_sprite_tile(14,12); //pipe L 14
- set_sprite_tile(15,14); //pipe R 15
- set_sprite_tile(16,12); //pipe L 16
- set_sprite_tile(17,14); //pipe R 17
- SHOW_SPRITES;
- move_sprite(0,82,88); //initial bird position on start screen
- move_sprite(1,90,88);
- while(1){ //----------------------- game loop -----------------------
- while(alive == 1){ //you start dead
- delay(speed); //stops "speed" number of ticks before next frame
- xt --; //pipe movement, constantly moving left
- xb --;
- if (xt == 0){
- xt = 250; //loop pipes when they reach left side of screen
- score ++; //increase score for each pipe that passes
- gotogxy(2,2);
- gprintf("%d",score);
- }
- if (xb == 0){
- xb = 250;
- score ++;
- gotogxy(2,2);
- gprintf("%d",score);
- }
- if (score == 10){ //speed increases with score
- speed = 5;
- }
- if (score == 25){
- speed = 4;
- }
- v++; //gravity (v acts downwards)
- y+=v/10;
- move_sprite(0,30,y); //move bird's left side
- move_sprite(1,38,y); //move bird's right side
- if (joypad() & J_A && v > 0){v=-30;} //jump if player presses A while bird is falling
- move_sprite(2,xt,96); //move lower pipe sprite
- move_sprite(3,xt+8,96);
- move_sprite(6,xt,112);
- move_sprite(7,xt+8,112);
- move_sprite(8,xt,128);
- move_sprite(9,xt+8,128);
- move_sprite(10,xt,144);
- move_sprite(11,xt+8,144);
- move_sprite(4,xb,64); //upper pipe
- move_sprite(5,xb+8,64);
- move_sprite(12,xb,48);
- move_sprite(13,xb+8,48);
- move_sprite(14,xb,32);
- move_sprite(15,xb+8,32);
- move_sprite(16,xb,16);
- move_sprite(17,xb+8,16);
- //death conditions
- if (y < 16 || y > 144){ //screen top or bottom
- alive = 0;
- }
- if (y > 82 && xt > 16 && xt < 46){ //collision with pipes
- alive = 0;
- }
- if (y < 80 && xb > 16 && xb < 46){
- alive = 0;
- }
- } //end of "alive" loop
- if (joypad() & J_START){ //restart
- y = 80, v = 0, xt = 125, xb = 250, alive = 1;
- move_sprite(0,30,80); //initial bird position
- move_sprite(1,38,80);
- move_sprite(2,125,96); //initial pipe position
- move_sprite(3,133,96);
- move_sprite(6,125,112);
- move_sprite(7,133,112);
- move_sprite(8,125,128);
- move_sprite(9,133,128);
- move_sprite(10,125,144);
- move_sprite(11,133,144);
- move_sprite(4,0,0); //initial pipe position
- move_sprite(5,0,0);
- move_sprite(12,0,0);
- move_sprite(13,0,0);
- move_sprite(14,0,0);
- move_sprite(15,0,0);
- move_sprite(16,0,0);
- move_sprite(17,0,0);
- gotogxy(5,3); //clear text
- gprintf(" ");
- gotogxy(2,5);
- gprintf(" ");
- gotogxy(4,14);
- gprintf(" ");
- score = 0;
- gotogxy(2,2);
- gprintf("%d ",score);
- speed = 6;
- waitpad(J_A); //wait for player to press A
- }
- }
- //---------------------- end game loop ---------------------
- }
Advertisement
Add Comment
Please, Sign In to add comment