Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code Dump
- #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;
- struct GameCharacter duszekcharL;
- UBYTE spritesize = 8;
- UINT8 playerlocation[2];
- UINT8 tileindexL = playerlocation[0];
- UINT8 tileindexR = playerlocation[0] + 8;
- //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 setupduszekcharL(){
- duszekchar.x = 100;
- duszekchar.y = 90;
- duszekchar.width = 16;
- duszekchar.height = 16;
- //load the sprites for duszekchar
- set_sprite_tile(4, 4);
- duszekchar.spritids[0] = 4;
- set_sprite_tile(5, 5);
- duszekchar.spritids[1] = 5;
- set_sprite_tile(6, 6);
- duszekchar.spritids[2] = 6;
- set_sprite_tile(7, 7);
- duszekchar.spritids[3] = 7;
- placegamecharacter(&duszekchar,duszekchar.x,duszekchar.y);
- }
- void main(){
- set_sprite_data(0,8,duszek);
- playerlocation[0] = 80;
- playerlocation[1] = 72;
- setupduszekchar();
- SHOW_SPRITES;
- DISPLAY_ON;
- while(1){
- if(joypad() & J_LEFT){
- if(tileindexL < tileindexR){
- //flips each of the 4 tiles of the metasprite
- set_sprite_prop(0,S_FLIPX);
- set_sprite_prop(1,S_FLIPX);
- set_sprite_prop(2,S_FLIPX);
- set_sprite_prop(3,S_FLIPX);
- performantdelay(50);
- //moves 0 -> 1
- scroll_sprite(0,8,0);
- //moves 2 -> 3
- scroll_sprite(2,8,0);
- //moves 1 -> 0
- scroll_sprite(1,-8,0);
- //moves 3 -> 2
- scroll_sprite(3,-8,0);
- //swaps the left and right tile indexes to indicate the sprite has flipped
- tileindexL += 8;
- tileindexR -= 8;
- }
- else{
- scroll_sprite(0,-8,0);
- scroll_sprite(1,-8,0);
- scroll_sprite(2,-8,0);
- scroll_sprite(3,-8,0);
- }
- performantdelay(10);
- }
- else if(joypad() & J_RIGHT){
- if(tileindexL > tileindexR){
- //flips each of the 4 tiles of the metasprite
- set_sprite_prop(0,S_FLIPX);
- set_sprite_prop(1,S_FLIPX);
- set_sprite_prop(2,S_FLIPX);
- set_sprite_prop(3,S_FLIPX);
- performantdelay(50);
- //moves 0 -> 1
- scroll_sprite(0,-8,0);
- //moves 2 -> 3
- scroll_sprite(2,-8,0);
- //moves 1 -> 0
- scroll_sprite(1,8,0);
- //moves 3 -> 2
- scroll_sprite(3,8,0);
- //swaps the left and right tile indexes to indicate the sprite has flipped
- tileindexL -= 8;
- tileindexR += 8;
- }
- else{
- scroll_sprite(0,8,0);
- scroll_sprite(1,8,0);
- scroll_sprite(2,8,0);
- scroll_sprite(3,8,0);
- }
- performantdelay(10);
- }
- else if(joypad() & J_A){
- if(tileindexL < tileindexR){
- set_sprite_prop(0,S_FLIPY);
- set_sprite_prop(1,S_FLIPY);
- set_sprite_prop(2,S_FLIPY);
- set_sprite_prop(3,S_FLIPY);
- }
- }
- }
- }
- ----------------------------------------------------------------------------------------------
- while(1){
- switch(joypad()){
- case J_LEFT:
- if(tileindexL < tileindexR){
- flipspriteL(&duszekchar);
- tileindexL += 8;
- tileindexR -= 8;
- }
- break;
- case J_RIGHT:
- if(tileindexL > tileindexR){
- flipspriteR(&duszekchar,playerlocation[0], playerlocation[1]);
- tileindexL -= 8;
- tileindexR += 8;
- }
- break;
- case J_A:
- printf("L:%d R:%d",tileindexL,tileindexR);
- wait_vbl_done();
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement