Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (Folder: sprite_testing)
- #include <gb/gb.h>
- #include <stdio.h>
- #include "GameCharacter.c"
- #include "Foe.c"
- #include "Attack.c"
- #include "duszek.c"
- #include "flare.c"
- #include "dummkopf.c"
- struct GameCharacter duszekchar;
- struct Attack flareatk;
- struct Foe dummkopffoe;
- UBYTE spritesize = 8;
- INT8 playerlocation[2];
- void performantdelay(UINT8 numloops){
- UINT8 i;
- for(i = 0; i < numloops; i++){
- wait_vbl_done();
- }
- }
- UBYTE checkhit(struct Attack* attack, struct Foe* foe){
- return (((foe->x >= attack->x && foe->x <= attack->x+attack->width) && (foe->y >= attack->y && foe->y <= attack->y+attack->height) || (attack->x >= foe->x && attack->x <= foe->x+foe->width) && (attack->y >= foe->y && attack->y <= foe->y+foe->height)) && attack->hitbox == 1);
- }
- 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);
- }
- void placefoe(struct Foe* foe, UINT8 x, UINT8 y){
- move_sprite(foe->spritids[0],x,y);
- move_sprite(foe->spritids[1],x+8,y);
- move_sprite(foe->spritids[2],x,y+8);
- move_sprite(foe->spritids[3],x+8,y+8);
- }
- void setupflare(){
- flareatk.x = playerlocation[0]+16;
- flareatk.y = playerlocation[1];
- flareatk.width = 16;
- flareatk.height = 16;
- //frame 1 R
- set_sprite_tile(4,72);
- flareatk.attackframes[0] = 4;
- set_sprite_tile(5,73);
- flareatk.attackframes[1] = 5;
- set_sprite_tile(6,74);
- flareatk.attackframes[2] = 6;
- set_sprite_tile(7,75);
- flareatk.attackframes[3] = 7;
- //frame 2 R
- set_sprite_tile(4,80);
- flareatk.attackframes[0] = 4;
- set_sprite_tile(5,81);
- flareatk.attackframes[1] = 5;
- set_sprite_tile(6,82);
- flareatk.attackframes[2] = 6;
- set_sprite_tile(7,83);
- flareatk.attackframes[3] = 7;
- //frame 3 R
- set_sprite_tile(4,88);
- flareatk.attackframes[0] = 4;
- set_sprite_tile(5,89);
- flareatk.attackframes[1] = 5;
- set_sprite_tile(6,90);
- flareatk.attackframes[2] = 6;
- set_sprite_tile(7,91);
- flareatk.attackframes[3] = 7;
- }
- void setupduszek(){
- duszekchar.x = playerlocation[0];
- duszekchar.y = playerlocation[1];
- duszekchar.width = 16;
- duszekchar.height = 16;
- //load 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 setupdummkopf(){
- dummkopffoe.x = playerlocation[0]+16;
- dummkopffoe.y = playerlocation[1];
- dummkopffoe.width = 16;
- dummkopffoe.height = 16;
- // load sprites for dummkopf
- set_sprite_tile(8,97);
- dummkopffoe.spritids[0] = 8;
- set_sprite_tile(9,98);
- dummkopffoe.spritids[1] = 9;
- set_sprite_tile(10,99);
- dummkopffoe.spritids[2] = 10;
- set_sprite_tile(11,100);
- dummkopffoe.spritids[3] = 11;
- placefoe(&dummkopffoe, dummkopffoe.x,dummkopffoe.y);
- }
- void idleduszek(){
- 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;
- performantdelay(5);
- set_sprite_tile(0,8);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,9);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,10);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,11);
- duszekchar.spritids[3] = 3;
- performantdelay(4);
- set_sprite_tile(0,16);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,17);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,18);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,19);
- duszekchar.spritids[3] = 3;
- performantdelay(4);
- set_sprite_tile(0,8);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,9);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,10);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,11);
- duszekchar.spritids[3] = 3;
- performantdelay(4);
- }
- void attackduszek(){
- //duszek frame 1
- set_sprite_tile(0,24);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,25);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,26);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,27);
- duszekchar.spritids[3] = 3;
- performantdelay(3);
- //duszek frame 2
- set_sprite_tile(0,32);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,33);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,34);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,35);
- duszekchar.spritids[3] = 3;
- performantdelay(3);
- //duszek frame 3
- set_sprite_tile(0,40);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,41);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,42);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,43);
- duszekchar.spritids[3] = 3;
- performantdelay(3);
- //duszek frame 4 with flare
- set_sprite_tile(0,48);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,49);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,50);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,51);
- duszekchar.spritids[3] = 3;
- //flare frame 1
- set_sprite_tile(4,72);
- flareatk.attackframes[0] = 4;
- set_sprite_tile(5,73);
- flareatk.attackframes[1] = 5;
- set_sprite_tile(6,74);
- flareatk.attackframes[2] = 6;
- set_sprite_tile(7,75);
- flareatk.attackframes[3] = 7;
- move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
- move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
- move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
- move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
- performantdelay(3);
- // duszek frame 5 with flare
- set_sprite_tile(0,56);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,57);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,58);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,59);
- duszekchar.spritids[3] = 3;
- //flare frame 2
- //flareatk.hitbox = 1;
- set_sprite_tile(4,80);
- flareatk.attackframes[0] = 4;
- set_sprite_tile(5,81);
- flareatk.attackframes[1] = 5;
- set_sprite_tile(6,82);
- flareatk.attackframes[2] = 6;
- set_sprite_tile(7,83);
- flareatk.attackframes[3] = 7;
- move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
- move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
- move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
- move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
- performantdelay(3);
- // duszek frame 6 with flare
- set_sprite_tile(0,64);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,65);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,66);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,67);
- duszekchar.spritids[3] = 3;
- //flare frame 3
- set_sprite_tile(4,88);
- flareatk.attackframes[0] = 4;
- set_sprite_tile(5,89);
- flareatk.attackframes[1] = 5;
- set_sprite_tile(6,90);
- flareatk.attackframes[2] = 6;
- set_sprite_tile(7,91);
- flareatk.attackframes[3] = 7;
- move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
- move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
- move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
- move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
- performantdelay(3);
- // duszek frame 5 with flare
- set_sprite_tile(0,56);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,57);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,58);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,59);
- duszekchar.spritids[3] = 3;
- //flare frame 2
- set_sprite_tile(4,80);
- flareatk.attackframes[0] = 4;
- set_sprite_tile(5,81);
- flareatk.attackframes[1] = 5;
- set_sprite_tile(6,82);
- flareatk.attackframes[2] = 6;
- set_sprite_tile(7,83);
- flareatk.attackframes[3] = 7;
- move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
- move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
- move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
- move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
- performantdelay(3);
- // duszek frame 4 with flare
- set_sprite_tile(0,48);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,49);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,50);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,51);
- duszekchar.spritids[3] = 3;
- //flare frame 1
- //flareatk.hitbox = 0;
- set_sprite_tile(4,72);
- flareatk.attackframes[0] = 4;
- set_sprite_tile(5,73);
- flareatk.attackframes[1] = 5;
- set_sprite_tile(6,74);
- flareatk.attackframes[2] = 6;
- set_sprite_tile(7,75);
- flareatk.attackframes[3] = 7;
- move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
- move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
- move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
- move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
- performantdelay(3);
- // duszek frame 3
- set_sprite_tile(0,40);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,41);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,42);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,43);
- duszekchar.spritids[3] = 3;
- //clearing attack tiles
- set_sprite_tile(4,96);
- flareatk.attackframes[0] = 4;
- set_sprite_tile(5,96);
- flareatk.attackframes[1] = 5;
- set_sprite_tile(6,96);
- flareatk.attackframes[2] = 6;
- set_sprite_tile(7,96);
- flareatk.attackframes[3] = 7;
- move_sprite(flareatk.attackframes[0],flareatk.x,flareatk.y);
- move_sprite(flareatk.attackframes[1],flareatk.x+8,flareatk.y);
- move_sprite(flareatk.attackframes[2],flareatk.x,flareatk.y+8);
- move_sprite(flareatk.attackframes[3],flareatk.x+8,flareatk.y+8);
- performantdelay(3);
- // duszek frame 2
- set_sprite_tile(0,32);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,33);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,34);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,35);
- duszekchar.spritids[3] = 3;
- performantdelay(3);
- //duszek frame 1
- set_sprite_tile(0,24);
- duszekchar.spritids[0] = 0;
- set_sprite_tile(1,25);
- duszekchar.spritids[1] = 1;
- set_sprite_tile(2,26);
- duszekchar.spritids[2] = 2;
- set_sprite_tile(3,27);
- duszekchar.spritids[3] = 3;
- performantdelay(3);
- }
- void main(){
- playerlocation[0] = 80;
- playerlocation[1] = 72;
- set_sprite_data(0,72,duszek);
- set_sprite_data(72,25,flare);
- set_sprite_data(97,4,dummkopf);
- setupduszek();
- setupflare();
- setupdummkopf();
- SHOW_SPRITES;
- DISPLAY_ON;
- while(1){
- idleduszek();
- switch(joypad()){
- case J_B:
- attackduszek();
- flareatk.hitbox = 1;
- if(checkhit(&flareatk,&dummkopffoe) == 1){
- printf("Hit!");
- }
- flareatk.hitbox==0;
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment