Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gb/gb.h>
- #include <stdio.h>
- #include "GameCharacter.c"
- #include "duszek.c"
- //create struct called GameCharacter and an instance of it called duszekchar
- //create an unsigned byte called spritesize set to 8, and an array of 2 unsigned 8bit ints called playerlocation
- struct GameCharacter duszekchar;
- UBYTE spritesize = 8;
- INT8 playerlocation[2];
- //some sort of delay
- void performantdelay(UINT8 numloops){
- UINT8 i;
- for(i = 0; i < numloops; i++){
- wait_vbl_done();
- }
- }
- void placegamecharacter(struct GameCharacter* character, UINT8 x, UINT8 y){
- move_sprite(character->spritids[0], x, y);
- move_sprite(character->spritids[1], x + spritesize, y);
- move_sprite(character->spritids[2], x, y + spritesize);
- move_sprite(character->spritids[3], x + spritesize, y + spritesize);
- }
- //create a function that sets the attributes for GameCharacter duszekchar
- void setupduszekchar(){
- duszekchar.x = playerlocation[0];
- duszekchar.y = playerlocation[1];
- duszekchar.width = 16;
- duszekchar.height = 16;
- //load the sprites for duszekchar
- set_sprite_tile(0, 0);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1, 1);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2, 2);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3, 3);
- duszekchar.spritids[3] = 3;
- placegamecharacter(&duszekchar,duszekchar.x,duszekchar.y);
- }
- void flipspriteL(){
- set_sprite_tile(0, 4);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1, 5);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2, 6);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3, 7);
- duszekchar.spritids[3] = 3;
- wait_vbl_done();
- }
- void flipspriteR(){
- set_sprite_tile(0, 0);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1, 1);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2, 2);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3, 3);
- duszekchar.spritids[3] = 3;
- wait_vbl_done();
- }
- void animatesprite(struct GameCharacter* character, INT8 movex, INT8 movey){
- while(movex>0){
- scroll_sprite(character->spritids[0], 1, 0);
- scroll_sprite(character->spritids[1], 1, 0);
- scroll_sprite(character->spritids[2], 1, 0);
- scroll_sprite(character->spritids[3], 1, 0);
- movex -= 1;
- playerlocation[0]+=1;
- wait_vbl_done();
- }
- while(movex<0){
- scroll_sprite(character->spritids[0],-1,0);
- scroll_sprite(character->spritids[1],-1,0);
- scroll_sprite(character->spritids[2],-1,0);
- scroll_sprite(character->spritids[3],-1,0);
- movex += 1;
- playerlocation[0]-=1;
- wait_vbl_done();
- }
- while(movey>0){
- scroll_sprite(character->spritids[0], 0, 1);
- scroll_sprite(character->spritids[1], 0, 1);
- scroll_sprite(character->spritids[2], 0, 1);
- scroll_sprite(character->spritids[3], 0, 1);
- movey -= 1;
- playerlocation[0]+=1;
- wait_vbl_done();
- }
- while(movey<0){
- scroll_sprite(character->spritids[0],0,-1);
- scroll_sprite(character->spritids[1],0,-1);
- scroll_sprite(character->spritids[2],0,-1);
- scroll_sprite(character->spritids[3],0,-1);
- movey += 1;
- playerlocation[1]-=1;
- wait_vbl_done();
- }
- }
- void main(){
- set_sprite_data(0,8,duszek);
- playerlocation[0] = 80;
- playerlocation[1] = 72;
- INT8 tileindexL = playerlocation[0];
- INT8 tileindexR = playerlocation[0]+8;
- setupduszekchar();
- SHOW_SPRITES;
- DISPLAY_ON;
- while(1){
- switch(joypad()){
- case J_LEFT:
- if(tileindexL < tileindexR){
- flipspriteL();
- tileindexL += 8;
- tileindexR -= 8;
- }
- else{
- animatesprite(&duszekchar, -16,0);
- }
- break;
- case J_RIGHT:
- if(tileindexL > tileindexR){
- flipspriteR();
- tileindexL -= 8;
- tileindexR += 8;
- }
- else{
- animatesprite(&duszekchar, 16,0);
- }
- break;
- case J_UP:
- animatesprite(&duszekchar, 0,-16);
- break;
- case J_DOWN:
- animatesprite(&duszekchar, 0,16);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement