void _print_screen(word y, char *buffer) { char l; unsigned int x; x = y * 0x20; l = strlen(buffer); waitForVBlank(); while (*buffer) { if (*buffer == '\n') { while (x++ < 32) { *(byte *) 0x2115 = 0x80; *(word *) 0x2116 = 0x4000 + x + (y * 0x20); *(byte *) 0x2118 = 0; } y ++; x = y * 0x20; buffer++; waitForVBlank(); continue; } *(byte *) 0x2115 = 0x80; *(word *) 0x2116 = 0x4000 + x; *(byte *) 0x2118 = *buffer - 32; x++; buffer++; #if 0 waitForVBlank(); #endif } }
void playGame() { lives = MAX_LIVES; score = 0; startLevel(); resetLevel(); int resetPressed = FALSE; // game loop while (lives > 0) { //test select button release if (KEY_DOWN_NOW(BUTTON_SELECT)) { resetPressed = TRUE; } if (resetPressed && !KEY_DOWN_NOW(BUTTON_SELECT)) { titleScreen(); } waitForVBlank(); erase(); updateVars(); checkOutsideScreen(); generateObjs(); draw(); } gameOverScreen(); }
/* =================================== * MAIN RUN LOOP * =================================== */ void mainRunLoop() { while(!gameover) { /* Get and process input */ key_poll(); if (key_hit(KEY_RIGHT)) keyRight(); else if (key_hit(KEY_LEFT)) keyLeft(); else if (key_hit(KEY_UP)) { droppedYet = 1; keyHardDrop(); } else if (key_hit(KEY_DOWN)) keySoftDrop(); else if (key_hit(KEY_A)) { rotatedYet = 1; keyRotateRight(); } else if (key_hit(KEY_B)) { rotatedYet = 1; keyRotateLeft(); } else if (key_hit(KEY_SELECT)) showMenu(); else if (key_hit(KEY_START)) pause(); waitForVBlank(); frame++; /* Calculate layout of next frame */ if ((frame % fallSpeed)==0) { placed = 0; clearTetrimino(keyLastR, keyLastC, keyLastT); if (checkBoundBottom(key) != 1) { key.r = key.r + 1; drawTetrimino(key); } else { placeKey(); placed = 1; } } if ((frame % inputSpeed)==0) { if (placed == 0) { clearTetrimino(keyLastR, keyLastC, keyLastT); drawTetrimino(key); } keyLastR = key.r; keyLastC = key.c; for (int i = 0; i < 16; i++) keyLastT[i] = key.t[i]; movedYet = 0; } if ((frame % rotateSpeed)==0) rotatedYet = 0; } }
void flipPage() { u16 *temp = videoBuffer; videoBuffer = backBuffer; backBuffer = temp; waitForVBlank(); REG_DISPCNT ^= DCNT_PAGE; }
int simTick() { if (KEY_DOWN_NOW(BUTTON_SELECT)) { while (KEY_DOWN_NOW(BUTTON_SELECT)) { } return 0; } drawScreen(); waitForVBlank(); flipPage(); return 1; }
void clears(void) { word i, y; for (y = 0; y < 20; y++) { waitForVBlank(); for (i = 0; i < 32; i++) { *(byte *) 0x2115 = 0x80; *(word *) 0x2116 = 0x4000 + i + (y * 0x20); *(byte *) 0x2118 = 0; } } }
void _print_char(word y, word x, char c) { waitForVBlank(); VRAMByteWrite((byte) (c - 32), (word) (0x4000 + x + (y * 0x20))); }
void main(void) { initInternalRegisters(); // Screen map data @ VRAM location $1000 setTileMapLocation(0x1000, (byte) 0x00, (byte) 0); //*(byte*) 0x2107 = 0x10; // Plane 0 Tile graphics @ $2000 setCharacterLocation(0x2000, (byte) 0); //*(byte*) 0x210b = 0x02; VRAMLoad((word) title_pic, 0x2000, 0x1BE0); VRAMLoad((word) title_map, 0x1000, 0x0800); CGRAMLoad((word) title_pal, (byte) 0x00, (word) 256); // TODO sitwch to mode 0 for trying *(byte*) 0x2105 = 0x01; // MODE 1 value *(byte*) 0x212c = 0x01; // Plane 0 (bit one) enable register *(byte*) 0x212d = 0x00; // All subPlane disable *(byte*) 0x2100 = 0x0f; // enable background currentScrollEvent = NULL; scrollValue = 0; initEvents(); enablePad(); addEvent(&NMIReadPad, 1); // Loop forever while(1) { waitForVBlank(); if(pad1.left) { if(currentScrollEvent == NULL) currentScrollEvent = addEvent(&scrollLeft, 1); } if(pad1.right) { if(currentScrollEvent != NULL) { removeEvent(currentScrollEvent); currentScrollEvent = NULL; } } if(pad1.up) { addEvent(&fadeOut, 1); addEvent(&mosaicIn, 1); } if(pad1.down) { addEvent(&fadeIn, 1); addEvent(&mosaicOut, 1); } if(pad1.start) { debug(); } } }
//=====================Main int main(void) { //Set Video Control REG_DISPCNT = BG2_ENABLE | BG1_ENABLE | BG0_ENABLE | MODE_0 | OBJ_ENABLE; //tells the Background 0 control register //where the screen map is, the tiles, the color, and size0=256x256 //background 1 is the collision map REG_BG0CNT= CBB(0) | SBB(8) | COLOR16 | BG_SIZE0; REG_BG1CNT= CBB(2) | SBB(10) | COLOR16 | BG_SIZE2; REG_BG2CNT= CBB(3) | SBB(12) | COLOR16 | BG_SIZE2; //sets the BG's vertical and horz offsets to 0 REG_BG0HOFS=0; REG_BG0VOFS=20; REG_BG1HOFS=0; REG_BG1VOFS=0; REG_BG2HOFS=0; REG_BG2VOFS=0; int i; int speed=3; int hoff=0; int voff=0; //loads the picture pallet //This is the same for all backgrounds for(i=0;i<background0PalLen/2;i++) PALETTE_MEM[i]=background0Pal[i]; //===========================================Sprites ObjAttr shadowOAM[128]; //defining sprites with room for more Sprite spriteArray[NUMSPRITES]={ {WALKINGROW, 16, SPRITEOFFSET16(0,0), ATTR0_TALL, ATTR1_SIZE64, 32, 64, TRUE} } typedef struct { int printRow; int printCol; int arrayLocation; int shape; int size; int height; int width; int active; } Sprite; //Loads sprite tiles for(i=0; i<characterSpritesTilesLen/2; i++) charbase[4].tileimg[i] = characterSpritesTiles[i]; //set attributes of the sprite in the duplicate mem for(i=0; i<NUMSPRITES; i++) { shadowOAM[i].attr0 = spriteArray[i].row | ATTR0_4BPP | spriteArray[i].shape; shadowOAM[i].attr1 = spriteArray[i].col | spriteArray[i].size; shadowOAM[i].attr2 = spriteArray[i].start | ATTR2_PALETTE_BANK(0); } //hides all sprites except for main guy for(i=0; i<128; i++) { if(!spriteArray[i].active) shadowOAM[i].attr0 = ATTR0_HIDE; } waitForVblank(); // Copy shadow into real for(i=0; i<128; i++) { SPRITEMEM[i] = shadowOAM[i]; } while(1) { //LOADS BACKGROUND 0 //loads all the tiles and collision map for(i=0;i<background0TilesLen/2;i++) charbase[3].tileimg[i]=background0Tiles[i]; //loads the map for(i=0;i<background0MapLen/2;i++) screenbase[12].tilemap[i]=background0Map[i]; //LOADS BACKGROUND 1 //loads all the tiles and collision map for(i=0;i<background1TilesLen/2;i++) charbase[2].tileimg[i]=background1Tiles[i]; //loads the map for(i=0;i<background1MapLen/2;i++) screenbase[10].tilemap[i]=background1Map[i]; //LOADS BACKGROUND 2 //loads all the tiles and collision map for(i=0;i<background2TilesLen/2;i++) charbase[0].tileimg[i]=background2Tiles[i]; //loads the map for(i=0;i<background2MapLen/2;i++) screenbase[8].tilemap[i]=background2Map[i]; // these keys move the background around the screen if(KEY_DOWN_NOW(BUTTON_RIGHT))hoff+=speed; if(KEY_DOWN_NOW(BUTTON_LEFT))hoff-=speed; if(KEY_DOWN_NOW(BUTTON_UP))voff-=speed; if(KEY_DOWN_NOW(BUTTON_DOWN))voff+=speed; REG_BG0HOFS=hoff; //REG_BG0VOFS=voff; REG_BG1HOFS=hoff/20; //REG_BG1VOFS=voff/20; waitForVBlank(); } return 0; }
int main(void) { int r = 5; //player positions int c = 4; int r2 = 80; //first ball positions int c2 = 120; int human_speed = 2; //guess what this is? int width = 2; //dont bother, this is the frame width int human_size = 10; //duh int size = 10; //size of computer int dr = 3; //speed of player int dc = 3; //should = dr int agression; //not being used right now int inRange = 0; //a random count variable int human_health = 100; //human starting health int comp_health = 100; //computer starting health int newgame = 1; //another count var int loopCount = 0; int numAttacks = 0; //number of times human attacks int justAttacked; //count var for computer attacks int result; //count var int death_radius = 4; //this is how many pixels the radius around the computer is that you have to be in to attack/be attacked int next_var1 = 0; int retreat = 0; int retreat_length = 100; //how long it is after going in to retreat mode that you win int next_var2 = 0; int junkVar = 0; //prebuild the binary search tree //make the data in each node be a pointer to a function, then the output of that function //decides which node is next NaryNode *root = NULL; root = createNaryNode(createIntData(0), 0); //make the root node (check health) appendChild(root, createNaryNode(createIntData(1), 0)); //make the first child (if health is ok) appendChild(root, createNaryNode(createIntData(2), 0)); //make the second child (if health is bad) appendChild(root->child[0], createNaryNode(createIntData(3), 0)); //treat the first child as the root and add another child appendChild(root->child[1], createNaryNode(createIntData(4), 0)); //treat the first child as the root and add another child appendChild(root->child[1]->child[4], createNaryNode(createIntData(5), 0)); //add another child on right parent int *tree1; int *tree2; int *tree3; tree1 = (int*)(root->child[1]); (int*)(root->child[1]) = 4; (int*)(root->child[0]) = 2; (int*)(root->child[1]->child[4]) = 1; //tree1 = root->child[1]; /* [root] / \ [child1] ----------child 2] / \ \ \ [child3] [child4] [child5] [child6] / / \ [child7] [child8] [child9] | | [child9] [child10] */ Junk first; first.margin = 40; //the margin for death for the computer first.comp_health_rate = 1; //how fast the you kill the computer first.human_health_rate = 2; //how fast the computer kills you while(keepGoing()) { waitForVBlank(ON); switch (gameState) { case START: //start mode 4 initializeGBA(MODE_4); FlipPage(ON); paintBackground(PressEnterBitmap); FlipPage(OFF); //in to mode 3 GBASetup(); initializeGBA(MODE_3); drawBackground(6); while(!keyHit(BUTTON_START)){ while(keyHit(BUTTON_START)){ break;} } //reset all the count vars and such newgame = 1; numAttacks = 0; loopCount = 0; justAttacked = 0; human_health = 100; //human starting health comp_health = 100; //computer starting health next_var1 = 0; next_var2 = 0; r = 5; //player positions c = 4; r2 = 80; //first ball positions c2 = 120; gameState = PLAY; retreat = 0; break; case PLAY: //start mode 3 FlipPage(OFF); GBASetup(); waitForVBlank(ON); loopCount++; drawRectDMA(0, 0, 160, 240, COLOR(0,0,0)); //the black background //nary tree usage tree3 = (int*)(root->child[1]); if(tree3){ junkVar++; } if(comp_health < first.margin){ gameState = WIN; } //frame drawRectDMA(1, 1, 240, 1, COLOR(0,0,31)); //left bar drawRectDMA(159, 1, 1, 240, COLOR(0,0,31));//bottom bar drawRectDMA(1, 1, 240, 1, COLOR(0,0,31));//bottom bar drawRectDMA(159, 1, 1, 240, COLOR(0,0,31));//bottom bar //draw health bars if(human_health == 100){ drawRectDMA(5, 4, 1, 1, COLOR(0,0,31)); //human starting health drawRectDMA(5, 6, 1, 1, COLOR(0,0,31)); drawRectDMA(5, 8, 1, 1, COLOR(0,0,31)); } if(comp_health == 100){ drawRectDMA(5, 230, 1, 1, COLOR(31,0,0)); //computer starting health drawRectDMA(5, 232, 1, 1, COLOR(31,0,0)); drawRectDMA(5, 234, 1, 1, COLOR(31,0,0)); //newgame = 0; } if((human_health < 100) && (human_health > 66)){ drawRectDMA(5, 4, 1, 1, COLOR(0,0,31)); //human health 2/3 drawRectDMA(5, 6, 1, 1, COLOR(0,0,31)); drawRectDMA(5, 8, 1, 1, COLOR(0,0,0)); } if((human_health < 66) && (human_health >33)){ drawRectDMA(5, 4, 1, 1, COLOR(0,0,31)); //human health 1/3 drawRectDMA(5, 6, 1, 1, COLOR(0,0,0)); drawRectDMA(5, 8, 1, 1, COLOR(0,0,0)); } if((human_health < 33) && (human_health >0)){ drawRectDMA(5, 4, 1, 1, COLOR(0,0,0)); //human health 0/3 drawRectDMA(5, 6, 1, 1, COLOR(0,0,0)); drawRectDMA(5, 8, 1, 1, COLOR(0,0,0)); } if((comp_health < 100) && (comp_health > 66)){ drawRectDMA(5, 230, 1, 1, COLOR(31,0,0)); //computer health 2/3 drawRectDMA(5, 232, 1, 1, COLOR(31,0,0)); drawRectDMA(5, 234, 1, 1, COLOR(0,0,0)); } if((comp_health < 66) && (comp_health > 33)){ drawRectDMA(5, 230, 1, 1, COLOR(31,0,0)); //computer health 1/3 drawRectDMA(5, 232, 1, 1, COLOR(0,0,0)); drawRectDMA(5, 234, 1, 1, COLOR(0,0,0)); } if((comp_health < 33) && (comp_health > 0)){ drawRectDMA(5, 230, 1, 1, COLOR(0,0,0)); //computer health 0/3 drawRectDMA(5, 232, 1, 1, COLOR(0,0,0)); drawRectDMA(5, 234, 1, 1, COLOR(0,0,0)); } waitForVBlank(ON); //player control //controls the boundries and the speed drawRectDMA( r, c, width, width, COLOR(0,0,0)); if(keyHit(BUTTON_UP)) { r = r - human_speed; if(r <= 1) r = 2; } if(keyHit(BUTTON_DOWN)) { r = r + human_speed; if(r >= 159+human_size) r = 159; } if(keyHit(BUTTON_LEFT)) { c = c - human_speed; if(c <= 1) c = 2; } if(keyHit(BUTTON_RIGHT)) { c = c + human_speed; if(c >= 239+human_size) c = 239; } //start ball code (makes ball move) drawRectDMA( r2, c2, size, size, COLOR(0,0,0) ); drawRectDMA( r2, c2, size, size, COLOR(0,0,31) ); //collision detection //walls (make ball bounce) //computer bouncing if((r2+size) > 156) dr = -dr; //top if((c2+size) > 236) dc = -dc; //bottom and right if((c2+size) < 15) dc = -dc; //left if(((r2) <= 3) || ((r2) >= 158)) dr = -dr; //top and bottom //draw player square drawRectDMA( r, c, human_size, human_size, COLOR(0,0,0)); drawRectDMA( r, c, human_size, human_size, COLOR(0,0,31) ); //the actual square //draw bouncing ball drawRectDMA( r2, c2, size, size, COLOR(31,0,0)); //right wall drawRectDMA( 1, 238, 72 , width - 1, COLOR(0,0,31) ); drawRectDMA( 87, 238, 73, width - 1, COLOR(0,0,31) ); //keep player in boundries if(r < 2) { r = 2; } if(r+size > (159)) { r = (148); } if((c+size > 239)) { c = 228; } if((c < 2)) { c = 2; } //keep computer in boundries //the computer boundry is smaller so he doesn't get stuck in corners if(r2 < 10) { r2 = 10; } if(r2+size >= (149)) { r2 = (138); } if((c2 < 10)) { c2 = 10; } if((c2+size > 229)) { c2 = 218; } //BEGIN AI //if the health is low if((retreatCheck(comp_health,(first.margin)))){ //retreat (int*)(root->child[1]) = 1; if(r < r2){ r2 = r2 + 1; } if(r > r2){ r2 = r2 - 1; } if(c < c2){ c2 = c2 + 1; } if(c > c2){ c2 = c2 - 1; } if(keyHit(BUTTON_A)){ retreat = retreat + 1; } } //nary tree usage tree2 = (int*)(root->child[1]); if(tree2){ junkVar++; } if(attackCheck(comp_health)){ //if health is ok //attack (int*)(root->child[0]) = 1; if(r < r2){ r2 = r2 - 1; } if(r > r2){ r2 = r2 + 1; } if(c < c2){ c2 = c2 - 1; } if(c > c2){ c2 = c2 + 1; } //see how aggressive the human is being agression = numAttacks/inRange; //see if the human is within striking distance if(inRadius(c2, death_radius, c, human_size, r2, r, size)){ //this function took forever to write inRange++; result = randGen(); if(result){ human_health = human_health - (first.human_health_rate); justAttacked++; } //If I ever get around to implementing this, this will allow the computer to retreat //when the human gets too aggressive /* if(agression > .15){ //retreat if(r < r2){ r2 = r2 + 1; } if(r > r2){ r2 = r2 - 1; } if(c < c2){ c2 = c2 + 1; } if(c > c2){ c2 = c2 = 1; } } */ //set up the health //computer (computer loses health under these conditions if(keyHit(BUTTON_A)){ comp_health = (comp_health - (first.comp_health_rate)); numAttacks++; } } } if(inRadius(c2, death_radius, c, human_size, r2, r, size)){ if(retreat >= retreat_length){ gameState = WIN; break;} if(human_health < 33){ gameState = DIE; next_var2 = 1; break; } } break; case WIN: //if they make it past level 5, display a win screen and reset some variables drawBackground(7); if(junkVar){ newgame = 1; } retreat = 0; if(keyHit(BUTTON_START)) { gameState = CREDITS; //next stop is the credits } while(keyHit(BUTTON_START)) { while(!keyHit(BUTTON_START)) { break; } next_var1 = 1;} break; case CREDITS: //display the Pony Shrapnel logo if(next_var1 == 1){ drawBackground(8); if(keyHit(BUTTON_START)) { gameState = START; //next stop is the start screen } while(keyHit(BUTTON_START)) { while(!keyHit(BUTTON_START)) { break; } } } case DIE: //if they die, then display a death screen, reset some variables, and go back to the start screen if(next_var2){ drawBackground(1); if(junkVar){ newgame = 0; } if(keyHit(BUTTON_START)) { gameState = CREDITS2; //next stop is the credits2 } while(keyHit(BUTTON_START)) { while(!keyHit(BUTTON_START)) { break; } } human_health = 100;} break; case CREDITS2: //display the Pony Shrapnel logo while(next_var2){ drawBackground(8); if(keyHit(BUTTON_START)) { gameState = START; //next stop is the start screen next_var2 = 0; } while(keyHit(BUTTON_START)) { while(!keyHit(BUTTON_START)) { break; } } break;} //end switch statements } } return 0; }
int main() { REG_DISPCTL = MODE4 | BG2_ENABLE; // Splash screen here setPalette(mainScreen_palette); drawImage4(0, 0, 240, 160, mainScreen); waitForVBlank(); flipPage(); int screen = 1; int currentMode = EDITMODE; const u16 colors[] = {WHITE, BLACK, RED, GREEN}; // alive = black = 1 // dead = white = 0 // alive + cursor = green = 3 // dead + cursor = red = 2 while (1) { if (screen) { setPalette(mainScreen_palette); drawImage4(0, 0, 240, 160, mainScreen); waitForVBlank(); flipPage(); if (KEY_DOWN_NOW(BUTTON_SELECT)) { screen = 0; setPalette(colors); fillScreen4(DEAD); flipPage(); copy(); while (KEY_DOWN_NOW(BUTTON_SELECT)) { } } } else { int draw = 0; // Select (backspace) = toggle between edit and simmode if (KEY_DOWN_NOW(BUTTON_SELECT)) { if (currentMode == EDITMODE) { currentMode = SIMMODE; eraseCursor(); } else { currentMode = EDITMODE; } while (KEY_DOWN_NOW(BUTTON_SELECT)) { // Won't do anything while select button is down } } // SIMMODE = 1 // EDITMODE = 0 // ***************SIM MODE******************* if (currentMode) { int paused = 0; int sim = 1; while (sim) { while (~paused & currentMode) { currentMode = simTick(); if (KEY_DOWN_NOW(BUTTON_SELECT)) { currentMode = EDITMODE; sim = 0; while (KEY_DOWN_NOW(BUTTON_SELECT)) { } } if (KEY_DOWN_NOW(BUTTON_A)) { paused = 1; while (KEY_DOWN_NOW(BUTTON_A)) { } } } //******************PAUSED**************** while (paused) { // Button B is X // This toggles next frame if (KEY_DOWN_NOW(BUTTON_B)) { simTick(); } if (KEY_DOWN_NOW(BUTTON_SELECT)) { currentMode = EDITMODE; while (KEY_DOWN_NOW(BUTTON_SELECT)) { } sim = 0; paused = 0; } if (KEY_DOWN_NOW(BUTTON_A)) { paused = 0; while (KEY_DOWN_NOW(BUTTON_A)) { } } } // end of paused } // end of sim } // end of currentMode if // ************EDIT MODE************** if (~currentMode) { copy(); drawCursor(); draw = cursorMoves(); if (KEY_DOWN_NOW(BUTTON_L)) { fillScreen4(DEAD); flipPage(); copy(); while (KEY_DOWN_NOW(BUTTON_L)) { } } } drawCursor(); if (draw) { waitForVBlank(); flipPage(); draw = 0; } } // end of else } }
int main(void) { while(1) { previousSpriteState = spriteState; pollKeys(); enableSounds(); setupInterrupts(); switch(state) { case SPLASH: { REG_DISPCNTL = BG2_ENABLE | MODE3; fillPicture((u16 *)splashBitmap); if (BUTTON_PRESSED(START_BUTTON)) { state = GAME; } if (BUTTON_PRESSED(SELECT_BUTTON)) { state = INSTRUCTIONS; } break; } case INSTRUCTIONS: { fillPicture((u16 *)instructionsBitmap); if (BUTTON_PRESSED(SELECT_BUTTON)) { state = SPLASH; } break; } case GAME: { //load tiles DMA_MEMORY[3].source = backgroundTiles; DMA_MEMORY[3].destination = &CHARBLOCK[0]; DMA_MEMORY[3].control = 12000 | DMA_ON; //load map DMA_MEMORY[3].source = backgroundMap; DMA_MEMORY[3].destination = &SCREENBLOCK[27]; DMA_MEMORY[3].control = 4096 | DMA_ON; //load pallette DMA_MEMORY[3].source = backgroundPal; DMA_MEMORY[3].destination = PAL_MEM; DMA_MEMORY[3].control = 256 | DMA_ON; //load the sprites into memory DMA_MEMORY[3].source = playerTiles; DMA_MEMORY[3].destination = &CHARBLOCK[4]; DMA_MEMORY[3].control = 16384 | DMA_ON; DMA_MEMORY[3].source = playerPal; DMA_MEMORY[3].destination = SPRITE_PALETTE; DMA_MEMORY[3].control = 256 | DMA_ON; //Hide all sprites int i; for(i=0; i<128; i++) { OAM[i].attr0 |= ATTR0_HIDE; } //Set Mode 0 BG 0 and Enable sprites. then set up the sprites REG_DISPCNTL = MODE0 | BG0_ENABLE | SPRITE_ENABLE; REG_BG0CNT = BG_8BPP | BG_REG_64x64 | CBB(0) | SBB(27); REG_TM0CNT = 0; DMA[1].cnt = 0; REG_TM0D = timerintervalA; REG_TM0CNT = TIMER_ON; DMA[1].src = bgsound; DMA[1].dst = REG_FIFO_A; DMA[1].cnt = DMA_ON | START_ON_FIFO_EMPTY | DMA_32 | DMA_REPEAT | DMA_DESTINATION_FIXED; startA = vblankcountA; while(1){ shadowOAM[0].attr0 = (playerRow & MASKROW) | ATTR0_TALL | ATTR0_REGULAR | ATTR0_8BPP; shadowOAM[0].attr1 = (playerCol & MASKCOL)| ATTR1_SIZE32; shadowOAM[0].attr2 = (SPRITEOFFSET16(0,0)); shadowOAM[1].attr0 = badguyRow | ATTR0_TALL | ATTR0_REGULAR | ATTR0_8BPP; shadowOAM[1].attr1 = badguyCol | ATTR1_SIZE32; shadowOAM[1].attr2 = (SPRITEOFFSET16(0,8)); pollKeys(); bigRow = playerRow + vOff; bigCol = playerCol + hOff; switch(spriteState) { case STILL: { shadowOAM[0].attr2 = (SPRITEOFFSET16(0,0)); break; } case MOVING: { if((walkCounter%2)==1) shadowOAM[0].attr2 = (SPRITEOFFSET16(0,4)); else if((walkCounter%2==0)) { shadowOAM[0].attr2 = (SPRITEOFFSET16(0,0)); } break; } } if(BUTTON_HELD(A_BUTTON) && BUTTON_HELD(B_BUTTON)) { //load tiles DMA_MEMORY[3].source = cheatbackgroundTiles; DMA_MEMORY[3].destination = &CHARBLOCK[0]; DMA_MEMORY[3].control = 11456 | DMA_ON; //load map DMA_MEMORY[3].source = cheatbackgroundMap; DMA_MEMORY[3].destination = &SCREENBLOCK[27]; DMA_MEMORY[3].control = 4096 | DMA_ON; //load pallette DMA_MEMORY[3].source = cheatbackgroundPal; DMA_MEMORY[3].destination = PAL_MEM; DMA_MEMORY[3].control = 256 | DMA_ON; } if (BUTTON_HELD(RIGHT_BUTTON)) { spriteState=MOVING; walkCounter++; if(collisionmapBitmap[((bigRow+playerHeight)*collMapSize)+(bigCol+playerCVel+playerWidth)]==WHITE) { if(playerCol<(SCREEN_WIDTH-(playerWidth+5))){ playerCol+=playerCVel; } else if(hOff<(collMapSize-SCREEN_WIDTH)) { hOff+=playerCVel; } } } if (BUTTON_HELD(LEFT_BUTTON)) { spriteState=MOVING; walkCounter++; if(collisionmapBitmap[((bigRow+playerHeight)*collMapSize)+(bigCol+playerCVel)]==WHITE) { if(playerCol>(0)) { playerCol-=playerCVel; } else if(hOff>(SCREEN_WIDTH-collMapSize)) { hOff-=playerCVel; } } } if (BUTTON_HELD(UP_BUTTON)) { spriteState=MOVING; walkCounter++; //Check collision and move if((collisionmapBitmap[(((bigRow-playerRVel)*collMapSize)+(bigCol+playerWidth))]==WHITE)&& (collisionmapBitmap[(((bigRow-playerRVel)*collMapSize)+(bigCol))]==WHITE)) { if(playerRow>30) { playerRow-=playerRVel; } else if(vOff>0) { vOff-=playerRVel; } } } if (BUTTON_HELD(DOWN_BUTTON)) { spriteState=MOVING; walkCounter++; //Check collision and move if((collisionmapBitmap[(((bigRow+playerHeight+playerRVel)*collMapSize)+(bigCol+playerWidth))]==WHITE)&& (collisionmapBitmap[(((bigRow+playerHeight+playerRVel)*collMapSize)+(bigCol))]==WHITE)) { if(playerRow<(SCREEN_HEIGHT-(playerHeight))) { playerRow+=playerRVel; } else if(vOff<(collMapSize-SCREEN_HEIGHT)) { vOff+=playerRVel; } if((playerRow > 440) && (playerCol > 464)) { state = WIN; } } } if (BUTTON_PRESSED(START_BUTTON)) { REG_TM1CNT = 0; DMA[2].cnt = 0; REG_TM1D = timerintervalB; REG_TM1CNT = TIMER_ON; DMA[2].src = bark; DMA[2].dst = REG_FIFO_B; DMA[2].cnt = DMA_ON | START_ON_FIFO_EMPTY | DMA_32 | DMA_REPEAT | DMA_DESTINATION_FIXED; startB = vblankcountB; } if (BUTTON_PRESSED(SELECT_BUTTON)) { //waitForNoKey(); state = PAUSE; } waitForVBlank(); OAM[0] = shadowOAM[0]; OAM[1] = shadowOAM[1]; REG_BG0HOFS = hOff; REG_BG0VOFS = vOff; } } case WIN: { while(1); } case PAUSE: { if(BUTTON_PRESSED(SELECT_BUTTON)) { state=GAME; } } } } return 0; }