Last active
November 18, 2020 01:09
-
-
Save TheEpicFace007/c3d34935024461da7557d6a535450e6b to your computer and use it in GitHub Desktop.
jumping for a gameboy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| GUY.C | |
| Tile Source File. | |
| Info: | |
| Form : All tiles as one unit. | |
| Format : Gameboy 4 color. | |
| Compression : None. | |
| Counter : None. | |
| Tile size : 8 x 8 | |
| Tiles : 0 to 0 | |
| Palette colors : None. | |
| SGB Palette : None. | |
| CGB Palette : None. | |
| Convert to metatiles : No. | |
| This file was generated by GBTD v2.2 | |
| */ | |
| /* Start of tile array. */ | |
| unsigned char guy[] = | |
| { | |
| 0x7C,0x7C,0x7C,0x44,0x7C,0x44,0x7C,0x44, | |
| 0x7C,0x7C,0x10,0x10,0x7C,0x7C,0x10,0x10 | |
| }; | |
| /* End of GUY.C */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| GUY.H | |
| Include File. | |
| Info: | |
| Form : All tiles as one unit. | |
| Format : Gameboy 4 color. | |
| Compression : None. | |
| Counter : None. | |
| Tile size : 8 x 8 | |
| Tiles : 0 to 0 | |
| Palette colors : None. | |
| SGB Palette : None. | |
| CGB Palette : None. | |
| Convert to metatiles : No. | |
| This file was generated by GBTD v2.2 | |
| */ | |
| /* Bank of tiles. */ | |
| #define guyBank 0 | |
| /* Start of tile array. */ | |
| extern unsigned char guy[]; | |
| /* End of GUY.H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <gb/gb.h> | |
| #include <stdio.h> | |
| #include <stdbool.h> | |
| #include "guy.c" | |
| #include "main.h" | |
| void main() | |
| { | |
| UINT8 player_location_x = 10; | |
| UINT8 player_location_y = 100; | |
| set_sprite_data(0, 1, guy); | |
| set_sprite_tile(0, 0); | |
| move_sprite(0, player_location_x, player_location_y); | |
| DISPLAY_ON; | |
| SHOW_SPRITES; | |
| bool is_jumping = false; | |
| while (1) | |
| { | |
| INT8 old_player_y = player_location_y; | |
| switch (joypad()) | |
| { | |
| case J_LEFT: | |
| if (is_jumping) | |
| break; | |
| player_location_x -= 2; | |
| move_sprite(0, player_location_x, player_location_y); | |
| break; | |
| case J_RIGHT: | |
| if (is_jumping) | |
| break; | |
| player_location_x += 2; | |
| move_sprite(0, player_location_x, player_location_y); | |
| break; | |
| case J_A: | |
| if (is_jumping) | |
| break; | |
| else | |
| is_jumping = true; | |
| for (int i = 0; i <= 5; i++) | |
| { | |
| player_location_y--; | |
| move_sprite(0, player_location_x, player_location_y); | |
| performantdelay(3); | |
| } | |
| for (int i = 0; i <= 5; i++) | |
| { | |
| player_location_y++; | |
| move_sprite(0, player_location_x, player_location_y); | |
| performantdelay(3); | |
| } | |
| is_jumping = false; | |
| break; | |
| } | |
| performantdelay(2); | |
| } | |
| } | |
| void performantdelay(UINT8 numloops) | |
| { | |
| UINT8 i; | |
| for(i = 0; i < numloops; i++) | |
| { | |
| wait_vbl_done(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void performantdelay(UINT8 numloops); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment