void WinGame(){ while(GetMasterVolume()){ if(GetMasterVolume() > 4) SetMasterVolume(GetMasterVolume()-4); else{ StopSong(); break; } WaitVsync(1); } FadeOut(9,true); SetTileTable(font_tiles); ClearVram(); WaitVsync(45); SetMasterVolume(BB_MASTER_VOLUME); //TriggerNote(4,24,8,255);//StartSong(main_song); FadeIn(2,false); TextWriter(1,0,epilogue_string); while(1){ WaitVsync(1); if(padState & BTN_START && !(oldPadState & BTN_START)) break; } FadeOut(7,true); }
//Callback invoked by UzeboxCore.Initialize() void DisplayLogo(){ #if INTRO_LOGO !=0 #define LOGO_X_POS 18 InitMusicPlayer(logoInitPatches); SetTileTable(uzeboxlogo); //draw logo ClearVram(); WaitVsync(15); #if INTRO_LOGO == 1 TriggerFx(0,0xff,true); #endif DrawMap2(LOGO_X_POS,12,map_uzeboxlogo); WaitVsync(6); DrawMap2(LOGO_X_POS,12,map_uzeboxlogo2); WaitVsync(4); DrawMap2(LOGO_X_POS,12,map_uzeboxlogo); #if INTRO_LOGO == 2 SetMasterVolume(0xc0); TriggerNote(3,0,16,0xff); #endif WaitVsync(64); ClearVram(); WaitVsync(20); #endif }
//Callback invoked by UzeboxCore.Initialize() void DisplayLogo(){ #if INTRO_LOGO !=0 #define LOGO_X_POS 8 InitMusicPlayer(logoInitPatches); screenSections[0].tileTableAdress=uzeboxlogo; //draw logo ClearVram(); WaitVsync(15); #if INTRO_LOGO == 1 TriggerFx(0,0xff,true); #endif DrawMap(LOGO_X_POS,12,map_uzeboxlogo); WaitVsync(3); DrawMap(LOGO_X_POS,12,map_uzeboxlogo2); WaitVsync(2); DrawMap(LOGO_X_POS,12,map_uzeboxlogo); #if INTRO_LOGO == 2 SetMasterVolume(0xc0); TriggerNote(3,0,16,0xff); #endif WaitVsync(65); ClearVram(); WaitVsync(20); #endif }
// intro screen void DoIntro() { // random number generator seed int rndSeed = 0; SetTileTable(tiles_mammoth); DrawMap2(0, 0, map_mammoth); // game loop char quit = 0; while(!quit) { // wait for v sync WaitVsync(1); // update the seed rndSeed += 7; if(ReadJoypad(0) & BTN_START) quit = 1; } // seed the prng srand(rndSeed); }
int main() { ClearVram(); SetTileTable(graphicsTiles); Screen.overlayTileTable = overlayTiles; for(int y=0;y<32;y++){ for(int x=0;x<32;x++){ SetTile(x,y,0); } } Screen.scrollHeight = SCREEN_SCROLL_HEIGHT; Screen.overlayHeight = SCREEN_OVERLAY_HEIGHT; Map_Init(); int cameraSpeed = 1; while(1) { uint16_t joypad = ReadJoypad(0); if((joypad & BTN_A)) { cameraSpeed = 4; } else { cameraSpeed = 1; } if((joypad & BTN_LEFT) && Camera_Position.x > cameraSpeed) { Camera_Position.x -= cameraSpeed; } if((joypad & BTN_RIGHT) && Camera_Position.x < (Map_Header.width - MAP_TILE_SCROLL_WRAP_X - 1) * MAP_TILE_PIXEL_SIZE - cameraSpeed) { Camera_Position.x += cameraSpeed; } if((joypad & BTN_UP) && Camera_Position.y > cameraSpeed) { Camera_Position.y -= cameraSpeed; } if((joypad & BTN_DOWN) && Camera_Position.y < (Map_Header.height - MAP_TILE_SCROLL_WRAP_Y - 1) * MAP_TILE_PIXEL_SIZE - cameraSpeed) { Camera_Position.y += cameraSpeed; } Map_Update(); // Screen.scrollX = Camera_Position.x; // Screen.scrollY = Camera_Position.y; WaitVsync(1); } return 0; }
void GameLoop(){ InGui = false; //if(!Demo) // StartSong(TitleSong); FadeIn(3,false); ResetLogic(); SetTileTable(StageTiles); DrawMap2(0,0,StageMap); Time = GAMETIME; //Time = 1;//for fast EEPROM debugging, I'm about 30% sure that 90% of the EEPRom bugs are gone :) //Frogs[0].Score = 39; ColorTime = 11*60L;//COLORTIMELENGTH; ColorIndex = 0; LastAction = 0; while (1){ WaitVsync(1); //DrawNumber(ColorTime>>8,3,SCREEN_TILES_V-1,0); //DrawNumber(ColorTime,8,SCREEN_TILES_V-1,0); //DrawNumber(ColorIndex,19,SCREEN_TILES_V-1,0); if(!ColorTime){ if(ColorIndex < NUMCOLORSHADES){ ColorTime = 11*60L;//COLORTIMELENGTH; DDRC = pgm_read_byte(&CustomFadeTable[++ColorIndex]); } } ColorTime--; UpdateFrogs(); CheckFlies(); UpdateFlies(); Render(); if(!Time && !(Frogs[0].State & (JUMPING)) && !(Frogs[1].State & (JUMPING))){//let each frog finish jumping if they were in the middle of it break; } else if(Time) Time--; if(Demo == 255) break; for(uint8_t i=0;i<MAXPLAYERS;i++){ if((JoyVal[i] & BTN_START) && !(OldJoyVal[i] & BTN_START)){ PauseMenu(); break; } } } }
/** * Called by the assembler initialization routines, should not be called directly. */ void InitConsole(void){ #if INTRO_LOGO ==1 InitMusicPlayer(initPatches); SetTileTable(uzeboxlogo); SetFontTable(uzeboxlogo); //draw logo ClearVram(); WaitVsync(15); TriggerFx(0,0xff,true); DrawMap(LOGO_X_POS,12,map_uzeboxlogo); WaitVsync(3); DrawMap(LOGO_X_POS,12,map_uzeboxlogo2); WaitVsync(2); DrawMap(LOGO_X_POS,12,map_uzeboxlogo); WaitVsync(40); ClearVram(); WaitVsync(20); #endif }
void LevelIntro(){ #ifdef FASTDEBUG FadeIn(2,true); return; #endif FadeIn(2,false); ResetSprites(); uint8_t xpos = 48-16; uint8_t soff; for(uint8_t i=0;i<8;i++){//"LEVEL XX" xpos += 16; if(i == 5)//space between level and numbers continue; soff = 0; while(soff < sizeof(sine_table)){ WaitVsync(1); sprite_count = 4*i; if(i > 5) sprite_count -= 4;//don't lose sprite indices because of space uint8_t t0 = pgm_read_byte(&sine_table[soff++]); uint8_t t1; if(i < 5) t1 = pgm_read_byte(&lvl_sprite_string[i]); else if(i == 6)//tens t1 = FIRST_NUMERAL_SPRITE_FRAME+(p.level/10); else//ones t1 = FIRST_NUMERAL_SPRITE_FRAME+(p.level%10); DrawMetaSprite(xpos,t0,t1); WaitVsync(1); } } WaitVsync(80); }
int main(){ unsigned char i,c,x,y,spr; ClearVram(); //initialize stuff InitMusicPlayer(patches); SetMasterVolume(0xc0); //crank up the volume a bit since the sample is not too loud SetSpritesTileTable(cubes_tileset); SetSpritesOptions(SPR_OVERFLOW_CLIP); //To allocate/deallocate a player's voice //tracks[0].allocated=false; //tracks[1].allocated=false; //tracks[2].allocated=false; //start the beat loop TriggerNote(3,1,23,0xff); //Define the screen sections. for(i=0;i<9;i++){ screenSections[i].tileTableAdress=spritedemo_tileset; } screenSections[0].height=76; screenSections[0].flags=SCT_PRIORITY_SPR; screenSections[1].height=2; screenSections[1].vramBaseAdress=vram+(32*37); screenSections[1].flags=SCT_PRIORITY_BG; screenSections[2].height=3; screenSections[2].vramBaseAdress=vram+(32*37); screenSections[2].flags=SCT_PRIORITY_BG; screenSections[2].scrollY=2; screenSections[3].height=3; screenSections[3].vramBaseAdress=vram+(32*37); screenSections[3].flags=SCT_PRIORITY_BG; screenSections[3].scrollY=5; screenSections[4].height=40; screenSections[4].vramBaseAdress=vram+(32*32); screenSections[4].flags=SCT_PRIORITY_SPR; screenSections[5].height=3; screenSections[5].vramBaseAdress=vram+(32*38); screenSections[5].flags=SCT_PRIORITY_BG; screenSections[6].height=3; screenSections[6].vramBaseAdress=vram+(32*38); screenSections[6].flags=SCT_PRIORITY_BG; screenSections[6].scrollY=3; screenSections[7].height=2; screenSections[7].vramBaseAdress=vram+(32*38); screenSections[7].flags=SCT_PRIORITY_BG; screenSections[7].scrollY=6; screenSections[8].height=76; screenSections[8].flags=SCT_PRIORITY_SPR; screenSections[8].scrollY=132; Fill(0,37,32,1,1); Fill(0,38,32,1,2); for(y=0;y<30;y+=4){ for(x=0;x<30;x+=5){ DrawMap2(x,y,map_bg); } } DrawMap2(0,32,map_logo); for(i=22;i<32;i++){ DrawMap2(i,32,map_bar); } srand(18); c=1; spr=1; for(i=0;i<7;i++){ //randomize positions cubes[i].x=((unsigned char)(rand() % 110))+2; cubes[i].y=((unsigned char)(rand() % 180))+2; cubes[i].rotation=((unsigned char)(rand() % 7)); if((unsigned char)(rand() % 16)<10){ cubes[i].xdir=1; }else{ cubes[i].xdir=-1; } if((unsigned char)(rand() % 16)<8){ cubes[i].ydir=1; }else{ cubes[i].ydir=-1; } } c=0; char w1=0,w2=0; while(1){ //syncronize gameplay on vsync (30 hz) WaitVsync(1); w2++; if(w2==3){ sx3++; if(sx3>X_SCROLL_WRAP) sx3=0; screenSections[1].scrollX=sx3; screenSections[7].scrollX=sx3; w2=0; } w1++; if(w1==2){ sx2++; if(sx2>=X_SCROLL_WRAP) sx2=0; screenSections[2].scrollX=sx2; screenSections[6].scrollX=sx2; w1=0; } sx++; if(sx>=X_SCROLL_WRAP) sx=0; screenSections[3].scrollX=sx; screenSections[4].scrollX=sx; screenSections[5].scrollX=sx; screenSections[0].scrollY++; screenSections[8].scrollY++; spr=1; for(i=0;i<7;i++){ cubes[i].x+=cubes[i].xdir; cubes[i].y+=cubes[i].ydir; if(cubes[i].x>123 && cubes[i].xdir==1){ cubes[i].xdir=-1; } if(cubes[i].x<9 && cubes[i].xdir==-1){ cubes[i].xdir=1; } cubes[i].y+=cubes[i].ydir; if(cubes[i].y>=196 && cubes[i].ydir==1){ cubes[i].ydir=-1; } if(cubes[i].y<10 && cubes[i].ydir==-1){ cubes[i].ydir=1; } if(c==0){ cubes[i].rotation++; if(cubes[i].rotation==14)cubes[i].rotation=0; sprites[spr+0].tileIndex=(cubes[i].rotation*2)+1; sprites[spr+1].tileIndex=(cubes[i].rotation*2)+1+1; sprites[spr+2].tileIndex=(cubes[i].rotation*2)+1+29; sprites[spr+3].tileIndex=(cubes[i].rotation*2)+1+30; } sprites[spr+0].x=cubes[i].x; sprites[spr+0].y=cubes[i].y; sprites[spr+1].x=cubes[i].x+6; sprites[spr+1].y=cubes[i].y; sprites[spr+2].x=cubes[i].x; sprites[spr+2].y=cubes[i].y+8; sprites[spr+3].x=cubes[i].x+6; sprites[spr+3].y=cubes[i].y+8; spr+=4; c+=128; } processControls(); } }
u8 Title(){ ClearTextVram(); SetTileTable(tiles); SetFontTilesIndex(TILES_SIZE); DrawMap2(8,3,map_title1); DrawMap2(4,6,map_title2); DrawMap2(24,13,map_title3); Print(8,15,PSTR("PLAY")); Print(8,16,PSTR("HOW TO PLAY")); // Print(8,17,PSTR("OPTIONS")); Print(13,26,PSTR("V1.1 \\ 2013 Uze")); u8 option=0; u8 animFrame=0,animDelay=0; u8 x=6,y=15; u16 joy,prevJoy=0; while(1){ WaitVsync(1); joy=ReadJoypad(0); AnimateCursor(x,y+option); /* if(animDelay==15){ //clear othercursor location SetTile(x,y+(option^1),0); SetTile(x+1,y+(option^1),0); animDelay=0; animFrame++; if(animFrame==4)animFrame=0; switch(animFrame){ case 0: SetTile(x,y+option,1); SetTile(x+1,y+option,2); break; case 1: SetTile(x,y+option,3); SetTile(x+1,y+option,4); break; case 2: SetTile(x,y+option,5); SetTile(x+1,y+option,6); break; default: SetTile(x,y+option,7); SetTile(x+1,y+option,8); break; } } animDelay++; */ if(prevJoy==0){ if (joy==BTN_SELECT || joy==BTN_UP || joy==BTN_DOWN){ option^=1; animDelay=15; }else if(joy==BTN_START){ while(ReadJoypad(0)!=0); return option; } } prevJoy=joy; } }
int main(){ SetUserPostVsyncCallback(&VsyncCallBack); while(1){ vmode=0; vmode_text_lines=SCREEN_TILES_V; paused=true; u8 option=0; do{ option=Title(); if(option==1){ DisplayHowToPlay(); } }while(option!=0); ClearVram(); SetTileTable(font); SetFontTilesIndex(0); CreateStatusBar(); //SetTile(0,0,91); //SetTile(1,0,92); //Print(1,0,PSTR("Started Generation: SELECT=Menu")); vmode_text_lines=1; //vmode=1; vmode_grid_col=9;//82; vmode_page=0; cursor_x=44; cursor_y=25; //R-pentamino //PutPixel(40,30,1,0); //PutPixel(41,30,1,0); //PutPixel(39,31,1,0); //PutPixel(40,31,1,0); //PutPixel(40,32,1,0); //u16 joy; inMainLoop=true; bool gameEnd=false; while(1){ WaitVsync(1); if(!paused){ ComputeNextStep(); vmode_page^=1; gen++; } if(keyAction!=ACTION_NONE){ switch(keyAction){ case ACTION_STARTSTOP: paused=!paused; keyAction=ACTION_NONE; break; case ACTION_OPENMENU: if(OpenMenu()==1){ gameEnd=true; inMainLoop=false; } keyAction=ACTION_NONE; break; } } UpdateStatusBar(); if(gameEnd)break; } } }
char multiloop(GameStruct* game) { PlayerStruct players[2]; MainStruct mains; ItemStruct zombie[MAX_ZOMBIES]; ItemStruct shots[2][2]; init(&mains, players, 2, game, zombie, shots); for(;;game->frames++) { WaitVsync(1); multidrawoverlay(game, players); gameflags(game); for(int p = 0; p < 2; p++) { playerflags(&players[p]); players[p].joypad = ReadJoypad(p); } if(players[0].life <= 0 && players[1].life <= 0) { switch(gameovermenu(game, &players[0])) { case 1: return 2; case 2: return 0; default: break; } } else if((players[0].joypad&BTN_SELECT || players[1].joypad&BTN_SELECT) && game->flagcount >= DEBOUNCE_DELAY) { game->flagcount = 0; if(game->flags & GAMEPAUSED) game->flags &= ~GAMEPAUSED; else game->flags |= GAMEPAUSED; } if(game->flags & GAMEPAUSED) continue; rendermap(&mains, 2); screenSections[1].scrollX = mains.x.s; screenSections[1].scrollY = mains.y.s; if(players[0].life > 0 && players[1].life > 0) multimove(players, &mains, shots); else if(players[0].life <= 0) singlemove(&(players[1]), &mains, shots[1]); else if(players[1].life <= 0) singlemove(&(players[0]), &mains, shots[0]); necromancer(zombie, &mains, game, players, 2); for(int p = 0; p < 2; p++) { inputanim(&(players[p])); players[p].gundelay++; for(int i = 0; i < 2; i++) handleshot(&mains, game, &players[p], &shots[p][i], zombie); if(!(players[p].flags & PLAYERHURT) || game->frames&2) { sprites[1 + p * 4].x = sprites[2 + p * 4].x = players[p].x; sprites[1 + p * 4].y = players[p].y; sprites[2 + p * 4].y = players[p].y + TILE_HEIGHT; } else { sprites[1 + p * 4].x = sprites[2 + p * 4].x = DISABLED_SPRITE; sprites[2 + p * 4].y = sprites[1 + p * 4].y = DISABLED_SPRITE; } } } }
/** * Game loop */ void game() { while (level < LEVEL_COUNT) { level++; MENU: menu(); load_level(); refresh_game_screen(); while (!is_level_done()) { int buttons = ReadJoypad(0); char* cursor_field_ptr = &(level_field[cursor_x + cursor_y * LEVEL_FIELD_WIDTH]); if (holding_atom) { if ((buttons & (BTN_A | BTN_B | BTN_X | BTN_Y))) { while (ReadJoypad(0) & (BTN_A | BTN_B | BTN_X | BTN_Y)) {}; *cursor_field_ptr = holding_atom; holding_atom = false; draw_field(); play_sound(SOUND_LEVEL_RELEASE); } if (buttons & BTN_LEFT) { draw_field(); if (level_field[(cursor_x - 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) { moves++; while (level_field[(cursor_x - 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) { play_sound(SOUND_LEVEL_MOVE); for (uint8_t i = 0; i < TILE_WIDTH; i++) { sprites[SPRITE_CURSOR].x--; draw_statistics(); WaitVsync(1); } cursor_x--; distance++; } } else { play_sound(SOUND_LEVEL_CANT_MOVE); } } if (buttons & BTN_RIGHT) { draw_field(); if (level_field[(cursor_x + 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) { moves++; while (level_field[(cursor_x + 1) + cursor_y * LEVEL_FIELD_WIDTH] == TILE_FLOOR) { play_sound(SOUND_LEVEL_MOVE); for (uint8_t i = 0; i < TILE_WIDTH; i++) { sprites[SPRITE_CURSOR].x++; draw_statistics(); WaitVsync(1); } cursor_x++; distance++; } } else { play_sound(SOUND_LEVEL_CANT_MOVE); } } if (buttons & BTN_UP) { draw_field(); if (level_field[cursor_x + (cursor_y - 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) { moves++; while (level_field[cursor_x + (cursor_y - 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) { play_sound(SOUND_LEVEL_MOVE); for (uint8_t i = 0; i < TILE_WIDTH; i++) { sprites[SPRITE_CURSOR].y--; draw_statistics(); WaitVsync(1); } cursor_y--; distance++; } } else { play_sound(SOUND_LEVEL_CANT_MOVE); } } if (buttons & BTN_DOWN) { draw_field(); if (level_field[cursor_x + (cursor_y + 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) { moves++; while (level_field[cursor_x + (cursor_y + 1) * LEVEL_FIELD_WIDTH] == TILE_FLOOR) { play_sound(SOUND_LEVEL_MOVE); for (uint8_t i = 0; i < TILE_WIDTH; i++) { sprites[SPRITE_CURSOR].y++; draw_statistics(); WaitVsync(1); } cursor_y++; distance++; } } else { play_sound(SOUND_LEVEL_CANT_MOVE); } } } else { if ((buttons & (BTN_A | BTN_B | BTN_X | BTN_Y))) { if ((*cursor_field_ptr >= TILE_FIRST_ATOM) && (*cursor_field_ptr <= TILE_LAST_ATOM)) { while (ReadJoypad(0) & (BTN_A | BTN_B | BTN_X | BTN_Y)) {}; holding_atom = *cursor_field_ptr; *cursor_field_ptr = TILE_FLOOR; draw_field(); play_sound(SOUND_LEVEL_CATCH); } else { play_sound(SOUND_LEVEL_CANT_MOVE); } } if (buttons & BTN_LEFT) { if (cursor_x > 0) { for (uint8_t i = 0; i < TILE_WIDTH; i++) { sprites[SPRITE_CURSOR].x--; WaitVsync(1); } cursor_x--; } else { play_sound(SOUND_LEVEL_CANT_MOVE); } } if (buttons & BTN_RIGHT) { if (cursor_x < LEVEL_FIELD_WIDTH - 1) { for (uint8_t i = 0; i < TILE_WIDTH; i++) { sprites[SPRITE_CURSOR].x++; WaitVsync(1); } cursor_x++; } else { play_sound(SOUND_LEVEL_CANT_MOVE); } } if (buttons & BTN_UP) { if (cursor_y > 0) { for (uint8_t i = 0; i < TILE_WIDTH; i++) { sprites[SPRITE_CURSOR].y--; WaitVsync(1); } cursor_y--; } else { play_sound(SOUND_LEVEL_CANT_MOVE); } } if (buttons & BTN_DOWN) { if (cursor_y < LEVEL_FIELD_HEIGHT - 1) { for (uint8_t i = 0; i < TILE_WIDTH; i++) { sprites[SPRITE_CURSOR].y++; WaitVsync(1); } cursor_y++; } else { play_sound(1); } } } if (buttons & BTN_SELECT) { play_sound(SOUND_MENU_SELECT); goto MENU; } if (buttons & BTN_START) { play_sound(SOUND_MENU_SELECT); while (ReadJoypad(0) & BTN_START); load_level(); refresh_game_screen(); } draw_cursor(); draw_statistics(); WaitVsync(5); } hide_sprites(); play_sound(SOUND_LEVEL_CLEARED); WaitVsync(60); // mark level as cleared eeprom_data.data[level / 8] |= 1 << (level % 8); EepromWriteBlock(&eeprom_data); } }
int main() { // clear the video ClearVram(); // init the music InitMusicPlayer(patches); // show the intro screen DoIntro(); // joystick previous states int padPrev[2] = {0,0}; // now the game loop while(1) { // wait for v sync WaitVsync(1); // load the next state if we need to if(nextState > 0) { // set the new game state and reset the next state gameState = nextState; nextState = 0; // fade out FadeOut(1, true); // init the state if(gameState == STATE_MAINMENU) InitState_MainMenu(); else if(gameState == STATE_PLAYING) InitState_Playing(); else if(gameState == STATE_HOWTOPLAY) InitState_HowToPlay(); else if(gameState == STATE_CREDITS) InitState_Credits(); else if(gameState == STATE_PLAYERSTART) InitState_PlayerStart(); else if(gameState == STATE_GAMEOVER) InitState_GameOver(); } // handle the input padHeld[0] = ReadJoypad(0); padPressed[0] = padHeld[0] & (padHeld[0] ^ padPrev[0]); padReleased[0] = padPrev[0] & (padHeld[0] ^ padPrev[0]); padPrev[0] = padHeld[0]; padHeld[1] = ReadJoypad(0);//1); padPressed[1] = padHeld[1] & (padHeld[1] ^ padPrev[1]); padReleased[1] = padPrev[1] & (padHeld[1] ^ padPrev[1]); padPrev[1] = padHeld[1]; // handle the states if(gameState == STATE_MAINMENU) DoState_MainMenu(); else if(gameState == STATE_PLAYING) DoState_Playing(); else if(gameState == STATE_HOWTOPLAY) DoState_HowToPlay(); else if(gameState == STATE_CREDITS) DoState_Credits(); else if(gameState == STATE_PLAYERSTART) DoState_PlayerStart(); else if(gameState == STATE_GAMEOVER) DoState_GameOver(); } }
int main(){ SetTileTable(cTesterTiles); SetSpritesTileTable(cursor); ClearVram(); EnableSnesMouse(0,map_cursor); //Print the basic stuff on the screen DrawMap2(5,26,map_copyright); DrawMap2(0,13,map_divider); //Detect controller types cType[0] = 255; cType[1] = 255; //The controller vars int btnHeld[2] = {0,0}; int btnPressed[2] = {0,0}; int btnReleased[2] = {0,0}; int btnPrev[2] = {0,0}; //Main loop while(1){ //20fps WaitVsync(1); //Update the controller vars btnHeld[0] = ReadJoypad(0); btnHeld[1] = ReadJoypad(1); btnPressed[0] = btnHeld[0] & (btnHeld[0] ^ btnPrev[0]); btnPressed[1] = btnHeld[1] & (btnHeld[1] ^ btnPrev[1]); btnReleased[0] = btnPrev[0] & (btnHeld[0] ^ btnPrev[0]); btnReleased[1] = btnPrev[1] & (btnHeld[1] ^ btnPrev[1]); //Check if controllers changed if((DetectControllers() & 3) != cType[0]){ cType[0] = DetectControllers() & 3; Fill(0,0,30,13,0); if(cType[0] == GAMEPAD){ DrawMap2(9,2,map_gamepad); } else if(cType[0] == MOUSE){ DrawMap2(12,2,map_mouse); DrawMap2(1,4,map_warning); } else if(cType[0] == NOTHING){ DrawMap2(9,6,map_nocontroller); } } if((DetectControllers() & 12) / 4 != cType[1]){ cType[1] = (DetectControllers() & 12) / 4; Fill(0,14,30,12,0); if(cType[1] == GAMEPAD){ DrawMap2(9,15,map_gamepad); SetSpriteVisibility(false); } else if(cType[1] == MOUSE){ DrawMap2(12,15,map_mouse); SetSpriteVisibility(true); EnableSnesMouse(0,map_cursor); } else if(cType[1] == NOTHING){ DrawMap2(9,19,map_nocontroller); SetSpriteVisibility(false); } } //Update the buttons for(unsigned int i = 0; i < 2; i++){ if(cType[i] == MOUSE){ //Check pressed buttons if(btnPressed[i] & BTN_MOUSE_LEFT){ DrawMap2(14,4 + 13*i,map_pmouseb); } if(btnPressed[i] & BTN_MOUSE_RIGHT){ DrawMap2(16,4 + 13*i,map_pmouseb); } //Check released if(btnReleased[i] & BTN_MOUSE_LEFT){ DrawMap2(14,4 + 13*i,map_mouseb); } if(btnReleased[i] & BTN_MOUSE_RIGHT){ DrawMap2(16,4 + 13*i,map_mouseb); } } else if(cType[i] == GAMEPAD){ //Check pressed if(btnPressed[i] & BTN_UP){ DrawMap2(11,6 + 13*i,map_pdpad); } if(btnPressed[i] & BTN_DOWN){ DrawMap2(11,8 + 13*i,map_pdpad); } if(btnPressed[i] & BTN_LEFT){ DrawMap2(10,7 + 13*i,map_pdpad); } if(btnPressed[i] & BTN_RIGHT){ DrawMap2(12,7 + 13*i,map_pdpad); } if(btnPressed[i] & BTN_START){ DrawMap2(16,6 + 13*i,map_pstart); } if(btnPressed[i] & BTN_SELECT){ DrawMap2(14,6 + 13*i,map_pstart); } if(btnPressed[i] & BTN_A){ DrawMap2(20,7 + 13*i,map_pbutton); } if(btnPressed[i] & BTN_B){ DrawMap2(19,8 + 13*i,map_pbutton); } if(btnPressed[i] & BTN_X){ DrawMap2(19,6 + 13*i,map_pbutton); } if(btnPressed[i] & BTN_Y){ DrawMap2(18,7 + 13*i,map_pbutton); } if(btnPressed[i] & BTN_SL){ DrawMap2(10,4 + 13*i,map_pbumper); } if(btnPressed[i] & BTN_SR){ DrawMap2(18,4 + 13*i,map_pbumper); } if(btnReleased[i] & BTN_UP){ DrawMap2(11,6 + 13*i,map_dpad); } if(btnReleased[i] & BTN_DOWN){ DrawMap2(11,8 + 13*i,map_dpad); } if(btnReleased[i] & BTN_LEFT){ DrawMap2(10,7 + 13*i,map_dpad); } if(btnReleased[i] & BTN_RIGHT){ DrawMap2(12,7 + 13*i,map_dpad); } if(btnReleased[i] & BTN_START){ DrawMap2(16,6 + 13*i,map_start); } if(btnReleased[i] & BTN_SELECT){ DrawMap2(14,6 + 13*i,map_start); } if(btnReleased[i] & BTN_A){ DrawMap2(20,7 + 13*i,map_button); } if(btnReleased[i] & BTN_B){ DrawMap2(19,8 + 13*i,map_button); } if(btnReleased[i] & BTN_X){ DrawMap2(19,6 + 13*i,map_button); } if(btnReleased[i] & BTN_Y){ DrawMap2(18,7 + 13*i,map_button); } if(btnReleased[i] & BTN_SL){ DrawMap2(10,4 + 13*i,map_bumper); } if(btnReleased[i] & BTN_SR){ DrawMap2(18,4 + 13*i,map_bumper); } } } btnPrev[0] = btnHeld[0]; btnPrev[1] = btnHeld[1]; } }
/** * \brief The main game loop. This just cycles endlessly, it uses the game's 'state' to determine which screen to show and what to do. */ int main(){ //looping back and forth forever (cards against humanity reference) while(1) { //some basic prep work performed once before our custom intro if(game_state == INTRO) { initialSetup(); initIntro(); } //perform custom intro while(game_state == INTRO) { //wait until the next frame WaitVsync(1); drawIntro(); processIntro(); } //prep the main menu if(game_state == MAIN_MENU) { FadeOut(0,true); ClearVram(); SetTileTable(title_tiles); SetFontTilesIndex(TITLE_TILES_SIZE); drawMainMenu(); FadeIn(0,false); } //draw menu and handle input while(game_state == MAIN_MENU) { WaitVsync(1); drawMenuCursor(); processMainMenu(); } if(game_state== GAME) { //run our setup for the main game ClearVram(); FadeOut(0,true); gameSetup(); FadeIn(0,false); } //when we're in the gameplay portion, draw and accept input for the game while(game_state == GAME) { WaitVsync(1); processScrollSpeed(); //scrolls screen as appropriate updateCity(); //offsets city for parallax processControls(); //accepts and processes controller input processPlayerMotion(); //update player position processSprites(); //updates and moves player image to player position } if(game_state == HIGH_SCORES) { FadeOut(0,true); SetTileTable(title_tiles); SetFontTilesIndex(TITLE_TILES_SIZE); drawLocalHighScoreMenu(); //draw up the high score screen FadeIn(0,false); deathclock=120; //reset death timer to 2 seconds if(score > topscores[9]) { LoadScore(0, 9); //load top 10 saved high scores SaveScore(score); //save our current score if it's high enough drawLocalHighScoreMenu(); //draw up the high score screen } } //draw and accepts input for the local high score screen while(game_state == HIGH_SCORES) { WaitVsync(1); processHighScoreMenu(); } } }
/** * Main menu (level selection) */ void menu() { uint8_t scroll = 0; uint8_t delay = false; uint8_t e_traj_offset1 = 0; uint8_t e_traj_offset2 = ELECTRON_TRAJECTORY_LAST_STEP / 2; unsigned int joypad; ClearVram(); hide_sprites(); for (uint8_t sprite_id = 0; sprite_id < 6; sprite_id++) { sprites[sprite_id].tileIndex = TILE_FIRST_ELECTRON + sprite_id; } DrawMap2(2, 2, logo_logo_map); // credits Print(2, 23, PSTR("2011 UZEBOX ATOMIX")); Print(2, 24, PSTR("PROGRAM: MARTIN SUSTEK")); Print(2, 25, PSTR("LEVEL DESIGN: ANDREAS WUEST")); // initial scroll position scroll = (level - 1); if ((level - 1) < SCREEN_MENU_LEVEL_LINES) { scroll = 0; } if ((level - 1) > LEVEL_COUNT - SCREEN_MENU_LEVEL_LINES) { scroll = LEVEL_COUNT - SCREEN_MENU_LEVEL_LINES; } while (true) { WaitVsync(1); // electrons animation e_traj_offset1++; if (e_traj_offset1 > ELECTRON_TRAJECTORY_LAST_STEP) { e_traj_offset1 = 0; } e_traj_offset2++; if (e_traj_offset2 > ELECTRON_TRAJECTORY_LAST_STEP) { e_traj_offset2 = 0; } sprites[0].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_1x + e_traj_offset1)); sprites[0].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_1y + e_traj_offset1)); sprites[1].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_2x + e_traj_offset2)); sprites[1].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_2y + e_traj_offset2)); sprites[2].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_3x + e_traj_offset1)); sprites[2].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_3y + e_traj_offset1)); sprites[3].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_1x + e_traj_offset2)); sprites[3].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_1y + e_traj_offset2)); sprites[4].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_2x + e_traj_offset1)); sprites[4].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_2y + e_traj_offset1)); sprites[5].x = (SCREEN_ELECTRON_X + pgm_read_byte(e_traj_3x + e_traj_offset2)); sprites[5].y = (SCREEN_ELECTRON_Y + pgm_read_byte(e_traj_3y + e_traj_offset2)); for (uint8_t i = 0; i < SCREEN_MENU_LEVEL_LINES; i++) { uint8_t current_level = (i + 1 + scroll); if ((current_level > 0) && (current_level <= 50)) { uint8_t y = 11 + i; // level number PrintByte(3, y, current_level, false); // level name (shorten and pad with spaces) for (uint8_t j = 0; j < 24; j++) { char ch = pgm_read_byte(levels + (current_level - 1) * LEVEL_BYTE_SIZE + j); if (ch == '\0') { ch = ' '; } PrintChar(6 + j, y, ch); } // level done yet symbol if (eeprom_data.data[current_level / 8] & 1 << (current_level % 8)) { PrintChar(4, y, FONT_TICK); } else { PrintChar(4, y, ' '); } // cursor symbol if (current_level == level) { PrintChar(5, y, FONT_CURSOR); } else { PrintChar(5, y, ' '); } } } // molecule thumbnail draw_molecule(21, 2); // controls if (delay) { WaitVsync(4); delay = false; } joypad = ReadJoypad(0); if (joypad & BTN_UP) { if (level > 1) { play_sound(SOUND_MENU_MOVE); level--; if (scroll + 1 > level) { scroll--; } delay = true; } else { play_sound(SOUND_MENU_CANT_MOVE); } } if (joypad & BTN_DOWN) { if (level < LEVEL_COUNT) { play_sound(SOUND_MENU_MOVE); level++; if (scroll + SCREEN_MENU_LEVEL_LINES < level) { scroll++; } delay = true; } else { play_sound(SOUND_MENU_CANT_MOVE); } } if (joypad & BTN_START) { hide_sprites(); play_sound(SOUND_MENU_SELECT); return; } } }
int main(){ TriggerFx(0,0,0); ClearVram(); InitMusicPlayer(patches); SetMasterVolume(0x40); StartSong(midisong); SetSpritesTileTable(mario_sprites_tileset); SetFontTilesIndex(SMB_TILESET_SIZE); SetTileTable(smb_tileset); Screen.scrollHeight = 23; Screen.overlayHeight=4; Screen.overlayTileTable=smb_tileset; DrawMap2(0,Screen.scrollHeight,map_hud); unsigned char c; for(int y=0;y<22;y++){ for(int x=0;x<30;x++){ c=pgm_read_byte(&(map_main[(y*MAP_MAIN_WIDTH)+x+2])); SetTile(x,y+1,c); } } dx=0; sx=50; sy=169-32+8; sprDir=1; goombaX[0]=17; //159; goombaDir[0]=-1; goombaAnim[0]=0; goombaSpr[0]=0; goombaSprIndex[0]=6; goombaX[1]=65 ;//201; goombaDir[1]=1; goombaAnim[1]=0; goombaSpr[1]=0; goombaSprIndex[1]=10; MapSprite2(0,map_rwalk1,0); MapSprite2(6,map_rgoomba1,SPRITE_FLIP_X); MapSprite2(10,map_rgoomba2,0); g=0; MoveSprite(0,sx,sy,2,3); Scroll(0,-1); MoveSprite(goombaSprIndex[0],goombaX[0],176,2,2); MoveSprite(goombaSprIndex[1],goombaX[1],176,2,2); Screen.scrollY=0; Screen.overlayHeight=4;//OVERLAY_LINES; while(1){ WaitVsync(1); processControls(); if((active&1)!=0){ PerformActions(); MoveSprite(0,sx,sy+dy,2,3); }else{ MoveSprite(0,sx,230,2,3); } //animate goombas for(g=0;g<2;g++){ if(goombaX[g]<=0 && goombaDir[g]==-1){ goombaDir[g]=1; } if(goombaX[g] >= (215+15) && goombaDir[g]==1){ goombaDir[g]=-1; } goombaX[g]+=goombaDir[g]; goombaAnim[g]++; if(goombaAnim[g]==8){ goombaSpr[g]^=1; goombaAnim[g]=0; } if(goombaSpr[g]==0){ MapSprite2(goombaSprIndex[g],map_rgoomba1,goombaDir[g]!=1?SPRITE_FLIP_X:0); }else{ MapSprite2(goombaSprIndex[g],map_rgoomba2,goombaDir[g]!=1?SPRITE_FLIP_X:0); } MoveSprite(goombaSprIndex[g],goombaX[g],176-32+8,2,2); } } }
char singleloop(GameStruct* game) { PlayerStruct singlep; MainStruct mains; ItemStruct zombie[MAX_ZOMBIES]; ItemStruct shots[2]; init(&mains, &singlep, 1, game, zombie, shots); for(;; game->frames++) { WaitVsync(1); drawoverlay(game, &singlep); gameflags(game); playerflags(&singlep); singlep.joypad = ReadJoypad(0); if(singlep.life <= 0) { switch(gameovermenu(game, &singlep)) { case 1: return 1; case 2: return 0; default: break; } } else if(singlep.joypad&BTN_SELECT && game->flagcount >= DEBOUNCE_DELAY) { game->flagcount = 0; if(game->flags & GAMEPAUSED) game->flags &= ~GAMEPAUSED; else game->flags |= GAMEPAUSED; } if(game->flags & GAMEPAUSED) continue; rendermap(&mains, 1); screenSections[1].scrollX = mains.x.s; screenSections[1].scrollY = mains.y.s; singlemove(&singlep, &mains, shots); inputanim(&singlep); singlep.gundelay++; for(int i = 0; i < 2; i++) handleshot(&mains, game, &singlep, &shots[i], zombie); necromancer(zombie, &mains, game, &singlep, 1); if(!(singlep.flags & PLAYERHURT) || game->frames&2) { sprites[1].x = sprites[2].x = singlep.x; sprites[1].y = singlep.y; sprites[2].y = singlep.y + TILE_HEIGHT; } else { sprites[1].x = sprites[2].x = DISABLED_SPRITE; sprites[2].y = sprites[1].y = DISABLED_SPRITE; } } }
u8 OpenMenu(){ ClearTextVram(); SetTileTable(tiles); SetFontTilesIndex(TILES_SIZE); //Show object types Print(6,2,PSTR("Select life object to insert")); Print(5,3,PSTR("at the current cursor position")); Print(7,7,PSTR("Glider")); Print(7,8,PSTR("Lightweight spaceship (LWSS)")) ; Print(7,9,PSTR("R-Pentamino")); Print(7,10,PSTR("Gosper glider gun")); Print(7,11,PSTR("Clear field")); Print(7,12,PSTR("Exit game")); //slide in menu WaitVsync(1); Fill(0,0,40,1,0); for(u8 i=1;i<29;i++){ WaitVsync(1); vmode_text_lines=i; } s8 option=0,x=5,y=7; u16 joy,prevJoy=0; while(1){ WaitVsync(1); joy=ReadJoypad(0); if(prevJoy==0){ if (joy==BTN_UP){ if(option>0) option--; }else if (joy==BTN_DOWN){ if(option<5)option++; }else if(joy==BTN_SELECT){ break; }else if(joy==BTN_START){ switch(option){ case 0: glider(cursor_x,cursor_y); break; case 1: lwss(cursor_x,cursor_y); break; case 2: rPentamino(cursor_x,cursor_y); break; case 3: gliderGun(cursor_x,cursor_y); break; case 4: ClearVram(); break; default: while(ReadJoypad(0)!=0); return 1; //signal game end, back to main menu } break; } } prevJoy=joy; AnimateCursor(x,y+option); } while(ReadJoypad(0)!=0); //close menu for(u8 i=29;i>0;i--){ WaitVsync(1); vmode_text_lines=i; } ClearTextVram(); SetTileTable(font); SetFontTilesIndex(0); CreateStatusBar(); return 0; }
char introscreen(GameStruct* game) { unsigned char counter; unsigned int joypad; ClearVram(); memset(sprites, 0, sizeof(struct SpriteStruct)*32); SetFontTilesIndex(49); screenSections[1].flags = SCT_PRIORITY_BG; screenSections[0].tileTableAdress = zombienator_title; screenSections[1].scrollX = screenSections[1].scrollY = 0; setoverlay(0); game->menupos = counter = 0; DrawMap2(0,6, title_map); for(int i = 0; i < 22; i++) SetTile(i, 10, 27 + i); for(;;) { WaitVsync(1); Fill(0,13, SCREEN_TILES_H, SCREEN_TILES_V - 13, 0); Print(5, 14, singlestr); Print(5, 15, multistr); Print(5, 16, highstr); Print(3, 14 + game->menupos, selectstr); joypad = 0; counter++; game->frames++; if(counter >= 15) { counter = 0; while(!(joypad&(BTN_START|BTN_SELECT|BTN_UP|BTN_DOWN))) { joypad = ReadJoypad(0); switch(joypad&(BTN_START|BTN_SELECT|BTN_UP|BTN_DOWN)) { case BTN_START: case BTN_SELECT: if(game->menupos == 0) return 1; else if(game->menupos == 1) return 2; break; case BTN_UP: if(game->menupos > 0 ) game->menupos--; else game->menupos = 2; break; case BTN_DOWN: if(game->menupos < 2) game->menupos++; else game->menupos = 0; break; } } } } return 0; }
int main() { unsigned char x,corner; unsigned char frames; unsigned int joypad; unsigned char player_x, player_y; unsigned char exit_x=0, exit_y=0; unsigned int z=0; int ay,ax,j; SetFontTable(fonts); // this tells Print___() commands what font to use ClearVram(); // clears out display memory (like a 'clear screen') //DDRD &= 0xF7; // These are used by the "power" switch and LED on the "Gamer" baseboard that //PORTD|= 0x08; // is paired with the AVCore. The 'power' button is used to switch mazes for now. new_maze: for(ay=0; ay<Y_SIZE; ay++) { for(ax=0; ax<X_SIZE; ax++) if(ax>0 && ay>0 && ax<X_SIZE-1 && ay<Y_SIZE-1) // fills the maze with walls, that are then 'drilled' out maze[ay][ax]=WALL; else maze[ay][ax]=BLANK; } ay=2; // 2,2 is the top left corner of the maze ax=2; maze[ay][ax]=4; // starting state for the maze generator do { while(drill(&ay,&ax,(int)(rand()&0x03))) {} // start drilling things out (using random) j=maze[ay][ax]; // note that the first time the game runs, the maze will always be maze[ay][ax]=BLANK; // the same because of the random number generator always starting if(j<4) // in the same state. (Normally I will 'sum' the contents of RAM { // on power-up to make a random seed, but I don't know how to mess /* back-track */ // with WinAVR's C-startup yet.) ax=ax-2*dx[j]; ay=ay-2*dy[j]; } } while(j<4); do{ // This generates a random position inside the maze to start the do player_x=rand(); // player. Seems more interesting than a corner. while ((player_x>=X_SIZE-1)||(player_x<=1)); do player_y=rand(); while ((player_y>=Y_SIZE-1)||(player_y<=1)); } while (maze[player_y][player_x]==WALL); // (repeats until it picks a random spot that's not a wall) maze[player_y][player_x]=PLAYER; // place the player in the maze do // here we choose a random number from 0-3, representing one of the { // four corners of the maze. corner=rand()&0x03; switch (corner) { case 0: exit_x=2; exit_y=2; break; case 1: exit_x=X_SIZE-3; exit_y=2; break; case 2: exit_x=X_SIZE-3; exit_y=Y_SIZE-3;break; case 3: exit_x=2; exit_y=Y_SIZE-3; break; } } while (abs(player_x-exit_x)<16); // we compare the distance from the player to the exit (horizontally) // and only accept the corner if it's relatively far away from the player // (could use both x and y distance for better effect) maze[exit_y][exit_x]=EXIT; // place the exit in the maze redraw(); // draw the screen for the player // This is what happens when you turn a static demo into a 'game' // For a real game, you probably don't want to do this, but it works here and is simple... //while(PIND&0x04) // if the button on the Gamer Baseboard isn't pressed while(ReadPowerSwitch()==0) // if the button on the Gamer Baseboard isn't pressed {z++; // the z counter is used later on for a seed for the random number generator (user interaction = randomness) joypad=ReadJoypad(0); // get the joypad state WaitVsync(1); // this waits a frame and essentially slows the gameplay down frames++; // frame counter can be used for animations (later) if (joypad&0xff) // if the D-pad has a bit or more pressed { maze[player_y][player_x]=BLANK; // erase the old player position if (joypad&BTN_DOWN) // down? if (maze[player_y+1][player_x]!=WALL) // don't move if a wall is blocking your path player_y++; // you could 'switch/case' these with breaks to easily disable diagonal moves... if (joypad&BTN_UP) // up? if (maze[player_y-1][player_x]!=WALL) player_y--; if (joypad&BTN_LEFT) // left? if (maze[player_y][player_x-1]!=WALL) player_x--; if (joypad&BTN_RIGHT) // right if (maze[player_y][player_x+1]!=WALL) player_x++; if (maze[player_y][player_x]==EXIT) // if the new position is the EXIT, you just won { maze[exit_y][exit_x]=PLAYER; // place the player on top of the exit redraw(); // draw the screen for the user Print(14,25,strWin); // prints the "YOU ESCAPED!" message WaitVsync(30); // and waits for a while. for (x=14;x<26;x++) // this loops over the "YOU ESCAPED!" message SetTile(x,25,11); // and erases it. break; // this breaks out of the while(PIND...) loop, causing a new maze to be generated } maze[player_y][player_x]=PLAYER; // after the movement calculations, put the player in the new spot } else { // check for idle time // use the frame counter to make the player graphic change if you wait around. ;-) } srand(z); // our player-influenced 'z' value is now used to reseed the random number generator, resulting in a 'new' maze redraw(); // redraw the screen to update new player position } goto new_maze; // this is just a hack to go do everything over again. Before anyone lectures me about using GOTO, think about // why every CPU has a 'jump/goto' instruction in its assembly language and uses it-- frequently. :-) }