/* =================================== * 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 link_input(TSprite *link) { link->vx= link->vy= 0; if( key_is_down(KEY_RIGHT) ) { link->vx= LINK_SPEED; link->dir= LOOK_RIGHT; } else if( key_is_down(KEY_LEFT) ) { link->vx= -LINK_SPEED; link->dir= LOOK_LEFT; } if( key_is_down(KEY_DOWN) ) { link->vy= LINK_SPEED; link->dir= LOOK_DOWN; } else if( key_is_down(KEY_UP) ) { link->vy= -LINK_SPEED; link->dir= LOOK_UP; } if( !key_is_down(KEY_DIR) ) link_set_state(link, SPR_STATE_STAND); if( key_hit(KEY_DIR) ) link_set_state(link, SPR_STATE_WALK); }
void splash() { REG_DISPCTL = MODE3 | BG2_ENABLE; drawImage3(nerdbgBitmap, 0, 0, 160, 240); int rand_seed = 42; while (state == SPLASH) { rand_seed++; key_poll(); if (key_hit(BUTTON_A)) state = INSTRUCTIONS; else if (key_hit(BUTTON_B)) state = GAME; } srand(rand_seed); }
/* ================================= * GAME OVER SCREEN * ================================= */ void gameOverScreen() { drawImage3(0,0,240,160,gameoverscreen); while(1) { key_poll(); if (key_hit(KEY_START)) break; } }
/* ================================== * TITLE SCREEN * ================================== */ void titleScreen() { drawImage3(0,0,240,160,title); while(1) { key_poll(); if (key_hit(KEY_START)) break; } }
void update_olimar(OLIMAR* o) { if(o->state & MOVE) { POINT* vel = &o->vel; vel->x += tri_bool_horz(); CLAMP(vel->x, MAX_VELX); if(vel->y != 0) vel->y += tri_bool_horz(); CLAMP(vel->y, MAX_VELY); if(vel->y == 0 && key_hit(KEY_A)) { vel->y += JUMP_VEL; } if(vel->y == 0 && key_hit(KEY_B)) { //transition to throw } } }
void menu() { memcpy(vid_mem, menuBitmap, menuBitmapLen); while(~key_released(KEY_A)) { key_poll(); vid_vsync(); if(key_hit(KEY_A)) break; } }
void title() { // int* ptr; ptr = malloc(4); *ptr = 0x11223344; DEBUG_PRINTF("ptr = %#x\n", (u32)ptr); DEBUG_PRINTF("&obj_buffer = %#x\n",(u32)obj_buffer); u8 bytes[5] = { 0x11, 0x22, 0x33, 0x44, 0x55 }; u16 halfwords[5] = { 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA }; u32 words[3] = { 0x11223344, 0x55667788, 0x99AABBCC }; DEBUG_PRINTF("&bytes = %#x\n", (u32)bytes); DEBUG_PRINTF("&halfwords = %#x\n", (u32)halfwords); DEBUG_PRINTF("&words = %#x\n", (u32)words); memcpy(vid_mem, titleBitmap, titleBitmapLen); REG_DISPCNT = DCNT_MODE3 | DCNT_BG2; char* h = "PRESS A TO CONTINUE\n"; int x = 50, y = 100; int frame = 0; while(~key_hit(KEY_A)) { key_poll(); vid_vsync(); if( frame & 1 && *h != 0) { print_ch(*h, x, y, 0x0000); x += 6; h ++; frame = 0; } frame ++; if(key_hit(KEY_A)) break; } }
void Pause_Input() { //Pushing start will push the Pause state onto the stack, starting the pause. key_poll(); if(key_hit(KEY_START)) { // Pop pause state & offload Pause_Offload(); g_StateStack->states.pop(); } }
void Menu_Input() { //Pushing start will push the Game state onto the stack, starting the game. key_poll(); if(key_hit(KEY_START)) { //Push game state on after offloading this state. Menu_Offload(); State nextState; nextState.StatePointer = Game; g_StateStack->states.push(nextState); } }
void instructions() { REG_DISPCTL = MODE3 | BG2_ENABLE; fillScreen3(COLOR(0,31,31)); drawRect3(0, 0,0,240,160); drawString(1, 1, "NERD HERDER!", COLOR(31,31,31)); drawString(21, 1, "As head TA you control the destiny of", COLOR(31,31,31)); drawString(31, 1, "scores of students. It takes dedication,", COLOR(31,31,31)); drawString(41, 1, "strength, and the ability to intimidate.", COLOR(31,31,31)); drawString(51, 1, "In this game you separate the wheat", COLOR(31,31,31)); drawString(61, 1, "from the chaff. Intimidate the nerds to", COLOR(31,31,31)); drawString(71, 1, "their dorm so they'll do their homework.", COLOR(31,31,31)); drawString(81, 1, "Send the flunkies to the M-Train so they", COLOR(31,31,31)); drawString(91, 1, "won't bother the rest of us. Also there", COLOR(31,31,31)); drawString(101, 1, "might be power ups?", COLOR(31,31,31)); drawString(121, 1, "Press A to return", COLOR(31,31,31)); while (state == INSTRUCTIONS) { key_poll(); if (key_hit(BUTTON_A)) state = SPLASH; } }
int main(int argc, char * argv[]) { input_init(); std::string path_to_exe(""); { std::string path_with_exe(argv[0]); unsigned found = path_with_exe.find_last_of("/\\"); path_to_exe = path_with_exe.substr(0,found+1); } std::cout<<path_to_exe<<std::endl; SDL_Init( SDL_INIT_EVERYTHING ); TTF_Init(); SDL_Surface * screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE); GUI_Init(screen); { std::string font_path(path_to_exe); font_path += "freefont/FreeMono.ttf"; GUI_standard_font = TTF_OpenFont( font_path.c_str(), 15 ); } std::cout<<"fontptr: "<<GUI_standard_font<<std::endl; Area * screen_widget = new Area(0, 0, 640, 480); Area * test_widget = new Area(20, 20, 200, 200, screen_widget); test_widget->set_colour(200, 100, 100); Area * another_test_widget = new Area(240, 20, 200, 200, screen_widget); another_test_widget->set_colour(100, 200, 100); Area * ultra_test_widget = new Area(20, 20, 160, 160, another_test_widget); ultra_test_widget->set_colour(100, 100, 200); Label * test_label = new Label(10, 10, 140, 20, ultra_test_widget); test_label->set_colour(120, 120, 220); test_label->set_text("Hallo Welt!"); Button * test_button = new Button(10, 40, 120, 20, ultra_test_widget); test_button->set_colour(100, 200, 200); test_button->set_text("Test!"); Button * end_button = new Button(20, 240, 120, 20, screen_widget); end_button->set_colour(255, 0, 0); end_button->set_text("Ende!"); Text_Edit * text_edit = new Text_Edit(20, 280, 160, 20, screen_widget); text_edit->set_text("aender mich!"); input_update(); while(!key_hit(SDLK_ESCAPE) && !end_button->released)// && !mouse_hit(1)) { SDL_Surface * screen_surface = screen_widget->get_sdl_surface(); SDL_BlitSurface(screen_surface, NULL, screen, NULL); screen_widget->update(); if(test_button->released) { test_label->set_text("Button geklickt!"); } SDL_Flip(screen); flush_keys(); flush_mouse(); SDL_Delay(1000/60); input_update(); } //SDL_Delay(2000); return 0; }
/* event_filter handles game events */ int event_filter() { XEvent event; XNextEvent(display, &event); switch(event.type) { case ConfigureNotify: case Expose: case MapNotify: refresh_info(); #ifdef BLIT XCopyArea(display, drawpixmap, gamewindow, ctable[CBLACK].smallgc, 0, 0, WINDOWWIDTH, WINDOWHEIGHT, 0, 0); #else refresh(); #endif return(1); break; case ButtonPress: if(!waiting) { if(event.xbutton.button == Button2) burn = 1; if(event.xbutton.button == Button1) { if(event.xbutton.state & Button3Mask) { playerdir = STOP; } else { playerdir = GOLEFT; } } if(event.xbutton.button == Button3) { if(event.xbutton.state & Button1Mask) { playerdir = STOP; } else { playerdir = GORIGHT; } } } return(1); break; case ButtonRelease: if((event.xbutton.state & Button2Mask) && (event.xbutton.button == Button2)) burn = 0; if(event.xbutton.button == Button3) { if(event.xbutton.state & Button1Mask) { playerdir = GOLEFT; } else { playerdir = STOP; } } if(event.xbutton.button == Button1) { if(event.xbutton.state & Button3Mask) { playerdir = GORIGHT; } else { playerdir = STOP; } } return(1); break; case KeyPress: key_hit(&event.xkey); return(1); break; } return(0); }
int playPuzzle(int NUR_ROWS, int NUR_COLS, int puzzle[NUR_ROWS][NUR_COLS], int puzzle_index) { int cursor_r = 0; int cursor_c = 0; // Load palette memcpy16(pal_bg_mem, SharedPal, SharedPalLen / 2); // Load tiles into CBB 0 (16x16) and 1 (8x8) // Each charblock is 0x4000, an 8x8 tile is 0x20 bytes, // so there are 512 8x8 tiles or 128 16x16 tiles in each charblock. memcpy16(tile_mem[0], tiles16Tiles, tiles16TilesLen / 2); memcpy16(tile_mem[1], tiles8Tiles, tiles8TilesLen / 2); // Load the 16x16 puzzle map into screenblocks 28-31 for (int r = 0; r < 32; r++) { for (int c = 0; c < 32; c++) { set_tile(28, r, c, OUTSIDE); } } for (int c = 0; c < NUR_COLS; c++) set_tile(28, NUR_ROWS, c, BOTTOM_EDGE); for (int r = 0; r < NUR_ROWS; r++) set_tile(28, r, NUR_COLS, RIGHT_EDGE); set_tile(28, NUR_ROWS, NUR_COLS, BOTTOM_RIGHT_CORNER); for (int r = 0; r < NUR_ROWS; r++) { for (int c = 0; c < NUR_COLS; c++) { set_tile(28, r, c, puzzle[r][c]); } } // Load the 16x16 cursor map into screenblocks 24-27 for (int r = 0; r < 32; r++) { for (int c = 0; c < 32; c++) { set_tile(24, r, c, TRANSPARENT); } } set_tile(24, cursor_r, cursor_c, CURSOR); // 8x8 tiles: // set up BG2 for a 4bpp 32x32t map, using charblock 1 and screenblock 22 (cursor) REG_BG2CNT = BG_CBB(1) | BG_SBB(22) | BG_4BPP | BG_REG_32x32; // set up BG3 for a 4bpp 32x32t map, using charblock 1 and screenblock 23 (puzzle squares) REG_BG3CNT = BG_CBB(1) | BG_SBB(23) | BG_4BPP | BG_REG_32x32; // 16x16 tiles: // set up BG0 for a 4bpp 64x64t map, using charblock 0 and screenblocks 24-27 (cursor) REG_BG0CNT = BG_CBB(0) | BG_SBB(24) | BG_4BPP | BG_REG_64x64; // set up BG1 for a 4bpp 64x64t map, using charblock 0 and screenblocks 28-31 (puzzle squares) REG_BG1CNT = BG_CBB(0) | BG_SBB(28) | BG_4BPP | BG_REG_64x64; if (small_tiles) { REG_DISPCNT = DCNT_MODE0 | DCNT_BG2 | DCNT_BG3; } else { REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1; } int max_horiz_offset_16 = NUR_COLS * 16 - 240; if (max_horiz_offset_16 < 0) max_horiz_offset_16 = 0; int max_vert_offset_16 = NUR_ROWS * 16 - 160; if (max_vert_offset_16 < 0) max_vert_offset_16 = 0; int max_horiz_offset_8 = NUR_COLS * 8 - 240; if (max_horiz_offset_8 < 0) max_horiz_offset_8 = 0; int max_vert_offset_8 = NUR_ROWS * 8 - 160; if (max_vert_offset_8 < 0) max_vert_offset_8 = 0; REG_BG0HOFS = REG_BG1HOFS = REG_BG2HOFS = REG_BG3HOFS = 0; REG_BG0VOFS = REG_BG1VOFS = REG_BG2VOFS = REG_BG3VOFS = 0; irq_init(NULL); irq_add(II_VBLANK, NULL); int key_repeat = 0; bool clearing = false; while (1) { VBlankIntrWait(); key_poll(); set_tile(24, cursor_r, cursor_c, TRANSPARENT); // remove the cursor if (key_hit(1 << KI_LEFT | 1 << KI_RIGHT | 1 << KI_UP | 1 << KI_DOWN)) { key_repeat = 0; // reset the key repeat timer } #define START_REPEAT 20 #define REPEAT_SPEED 2 if (key_is_down(1 << KI_LEFT | 1 << KI_RIGHT | 1 << KI_UP | 1 << KI_DOWN)) { if (key_repeat < START_REPEAT) key_repeat++; else key_repeat = START_REPEAT - REPEAT_SPEED; } bool virtual_left = key_hit(1 << KI_LEFT ) || (key_is_down(1 << KI_LEFT ) && key_repeat == START_REPEAT); bool virtual_right = key_hit(1 << KI_RIGHT) || (key_is_down(1 << KI_RIGHT) && key_repeat == START_REPEAT); bool virtual_up = key_hit(1 << KI_UP ) || (key_is_down(1 << KI_UP ) && key_repeat == START_REPEAT); bool virtual_down = key_hit(1 << KI_DOWN ) || (key_is_down(1 << KI_DOWN ) && key_repeat == START_REPEAT); bool moved_cursor = false; if (virtual_left && cursor_c > 0 ) { cursor_c--; REG_BG0HOFS = REG_BG1HOFS = (cursor_c * max_horiz_offset_16) / (NUR_COLS - 1); REG_BG2HOFS = REG_BG3HOFS = (cursor_c * max_horiz_offset_8 ) / (NUR_COLS - 1); moved_cursor = true; } if (virtual_right && cursor_c < NUR_COLS - 1) { cursor_c++; REG_BG0HOFS = REG_BG1HOFS = (cursor_c * max_horiz_offset_16) / (NUR_COLS - 1); REG_BG2HOFS = REG_BG3HOFS = (cursor_c * max_horiz_offset_8 ) / (NUR_COLS - 1); moved_cursor = true; } if (virtual_up && cursor_r > 0 ) { cursor_r--; REG_BG0VOFS = REG_BG1VOFS = (cursor_r * max_vert_offset_16) / (NUR_ROWS - 1); REG_BG2VOFS = REG_BG3VOFS = (cursor_r * max_vert_offset_8 ) / (NUR_ROWS - 1); moved_cursor = true; } if (virtual_down && cursor_r < NUR_ROWS - 1) { cursor_r++; REG_BG0VOFS = REG_BG1VOFS = (cursor_r * max_vert_offset_16) / (NUR_ROWS - 1); REG_BG2VOFS = REG_BG3VOFS = (cursor_r * max_vert_offset_8 ) / (NUR_ROWS - 1); moved_cursor = true; } if (key_hit(1 << KI_A)) { switch (puzzle[cursor_r][cursor_c]) { case WHITE: case BLACK: puzzle[cursor_r][cursor_c] = DOT; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = DOT; set_tile(28, cursor_r, cursor_c, DOT); clearing = false; break; case DOT: puzzle[cursor_r][cursor_c] = WHITE; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE; set_tile(28, cursor_r, cursor_c, WHITE); clearing = true; break; default: clearing = false; break; } } else if (key_is_down(1 << KI_A) && moved_cursor) { switch (puzzle[cursor_r][cursor_c]) { case WHITE: case BLACK: case DOT: if (clearing) { puzzle[cursor_r][cursor_c] = WHITE; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE; set_tile(28, cursor_r, cursor_c, WHITE); } else { puzzle[cursor_r][cursor_c] = DOT; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = DOT; set_tile(28, cursor_r, cursor_c, DOT); } break; } } if (key_hit(1 << KI_B)) { switch (puzzle[cursor_r][cursor_c]) { case WHITE: case DOT: puzzle[cursor_r][cursor_c] = BLACK; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = BLACK; set_tile(28, cursor_r, cursor_c, BLACK); clearing = false; break; case BLACK: puzzle[cursor_r][cursor_c] = WHITE; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE; set_tile(28, cursor_r, cursor_c, WHITE); clearing = true; break; default: clearing = false; break; } } else if (key_is_down(1 << KI_B) && moved_cursor) { switch (puzzle[cursor_r][cursor_c]) { case WHITE: case BLACK: case DOT: if (clearing) { puzzle[cursor_r][cursor_c] = WHITE; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE; set_tile(28, cursor_r, cursor_c, WHITE); } else { puzzle[cursor_r][cursor_c] = BLACK; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = BLACK; set_tile(28, cursor_r, cursor_c, BLACK); } break; } } if (key_hit(1 << KI_SELECT)) { small_tiles = !small_tiles; if (small_tiles) { REG_DISPCNT = DCNT_MODE0 | DCNT_BG2 | DCNT_BG3; } else { REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1; } } if (key_hit(1 << KI_L)) { return -1; // move 1 puzzle to the left } if (key_hit(1 << KI_R)) { return 1; // move 1 puzzle to the right } set_tile(24, cursor_r, cursor_c, CURSOR); // readd the cursor } }
unsigned message_read(char* msg_str, char* instr) { // display message for user dprints(0, 2, MESSAGE, msg_str) ; // fill remainder of line with input color unsigned mlen = strlen(msg_str) ; unsigned slen = 79 - mlen ; spaces[slen] = 0 ; // terminate the spaces string at required length dprints(mlen, 2, INPUT, spaces) ; spaces[slen] = ' ' ; // restore the spaces string unsigned spos = mlen ; // data position on screen // initialize cursor int curmode = 1 ; dprintc(spos, 2, INPUT, CURSOR_ON) ; clock_t clk_time = clock() + BLINK_RATE ; // get user input unsigned mpos = 0 ; // data position in instr unsigned indata ; int done = 0 ; while (!done) { if (key_hit()) { //curmode = 0 ; dprintc(spos, 2, INPUT, CURSOR_OFF) ; indata = get_key() ; switch (indata) { case Key_ESC: // turn off cursor curmode = 0 ; dprintc(spos, 2, INPUT, CURSOR_OFF) ; done = -1 ; break; case Key_ENTER: *(instr+mpos) = 0 ; // NULL-terminate the string done = 1 ; indata = 0 ; break; case Key_BSPACE: if (mpos > 0) { mpos-- ; *(instr+mpos) = 0 ; // NULL-terminate the string dprintc(--spos, 2, INPUT, ' ') ; } break; default: // this won't work for ALL characters, // but it will work for normal ASCII chars. char outchr = (char) (indata & 0x00FF) ; if (mpos < slen) { *(instr+mpos) = outchr ; mpos++ ; dprintc(spos++, 2, INPUT, outchr) ; } break; } //curmode = 1 ; dprintc(spos, 2, INPUT, CURSOR_ON) ; // clk_time = clock() + BLINK_RATE ; } // if a key was pressed, read it // If no key is pressed, update cursor else { if (clock() > clk_time) { if (curmode == 0) { curmode = 1 ; dprintc(spos, 2, INPUT, CURSOR_ON) ; clk_time = clock() + BLINK_RATE ; } else { curmode = 0 ; dprintc(spos, 2, INPUT, CURSOR_OFF) ; clk_time = clock() + BLINK_RATE ; } } } } // restore the message line to normal data dprints(0, 2, LOGO, header) ; return indata ; //lint !e644 }
int main() { int i; struct VEngine veng; struct World world; JoyState* joy; v_init(&veng); joy_init(); /* for a random seed, wait for user input */ i = 0; while (1) { vid_vsync(); key_poll(); v_putbgtile(5, 4, 37); v_putbgtile(6, 4, 48); v_putbgtile(7, 4, 51); v_putbgtile(8, 4, 51); v_putbgtile(9, 4, 51); if (key_hit(KEY_A) || key_hit(KEY_START)) { break; } i ++; } /* sqran(i); */ sqran(4); init_world(&world, &veng); /* obj_set_pos(dude, (16 * 7), (16 * 4)); */ v_draw_bg(world.map, &veng, world.map->dudex, world.map->dudey); while(1) { vid_vsync(); joy = joy_poll(); key_poll(); if (key_hit(KEY_A)) { /* v_draw_more_bg(world.map, veng.mapofsx, veng.mapofsy - 4, 15, 4, world.map->dudex - 6 - veng.dudeposx, world.map->dudey - 4 - 4 - veng.dudeposy); */ } if (key_hit(KEY_START)) { v_init(&veng); init_world(&world, &veng); /* obj_set_pos(veng.obj_buffer[veng.spr_dude], (16 * 7), (16 * 4)); */ v_draw_bg(world.map, &veng, world.map->dudex, world.map->dudey); } /* if (key_hit(KEY_LEFT)) { switch (r_move_left(&world)) { case 1: v_move_left(&veng); break; case 2: v_shake_dude(&veng, 1, 0); break; } } else if (key_hit(KEY_RIGHT)) { switch (r_move_right(&world)) { case 1: v_move_right(&veng); break; case 2: v_shake_dude(&veng, 1, 0); break; } } else if (key_hit(KEY_UP)) { switch (r_move_up(&world)) { case 1: v_move_up(&veng); break; case 2: v_shake_dude(&veng, 0, 1); break; } } else if (key_hit(KEY_DOWN)) { switch (r_move_down(&world)) { case 1: v_move_down(&veng); break; case 2: v_shake_dude(&veng, 0, 1); break; } } */ if (joy->moving) { switch (r_move(&world, joy->dx, joy->dy)) { case 1: v_move(&veng, joy->dx, joy->dy); break; case 2: v_shake_dude(&veng, 0, 1); break; } joy_handled(); } v_move_co(&veng); v_scroll_at_edge(&veng, &world); v_draw_dude(&veng); for (i = 0; i < world.monstercount; i ++) { v_draw_monster(&veng, &world, i); } oam_copy(oam_mem, veng.obj_buffer, 1 + world.monstercount); } return 0; }
void pause() { REG_DISPCTL = MODE0 | BG3_ENABLE | SPRITE_ENABLE; REG_BG3CNT = CBB(0) | SBB(28) | BG_SIZE3 | COLOR256; loadPalette(stats_screenPal); DMANow(3, (unsigned int*)stats_screenTiles, &CHARBLOCKBASE[0], stats_screenTilesLen); DMANow(3, (unsigned int*)stats_screenMap, &SCREENBLOCKBASE[28], stats_screenMapLen); //sets up selector arrow shadowOAM[127].attr0 = 56 | ATTR0_8BPP | ATTR0_SQUARE; shadowOAM[127].attr1 = 25 | ATTR1_SIZE8; shadowOAM[127].attr2 = 772; //sets up points remaining indicator shadowOAM[126].attr0 = 32 | ATTR0_8BPP | ATTR0_SQUARE; shadowOAM[126].attr1 = 106 | ATTR1_SIZE8; shadowOAM[126].attr2 = 800; //sets up vitality points indicator shadowOAM[125].attr0 = 57 | ATTR0_8BPP | ATTR0_SQUARE; shadowOAM[125].attr1 = 90 | ATTR1_SIZE8; shadowOAM[125].attr2 = 802; //sets up strength points indicator shadowOAM[124].attr0 = 73 | ATTR0_8BPP | ATTR0_SQUARE; shadowOAM[124].attr1 = 90 | ATTR1_SIZE8; shadowOAM[124].attr2 = 802; //Disable unused sprites int i; for (i=0; i<128; ++i) { OAM[i].attr0 = ATTR0_HIDE; } //This loop keeps the background from being redrawn continously int button_pushed = 0; while (!button_pushed) { OAM[127] = shadowOAM[127]; OAM[126] = shadowOAM[126]; OAM[125] = shadowOAM[125]; OAM[124] = shadowOAM[124]; shadowOAM[126].attr2 = 800 + (2 * points); key_poll(); if (key_hit(BUTTON_A) || (key_hit(BUTTON_B))) button_pushed = 1; if (key_hit(BUTTON_UP) && (selector_position > 0)) { --selector_position; shadowOAM[127].attr0 = 56 | ATTR0_8BPP | ATTR0_SQUARE; } if (key_hit(BUTTON_DOWN) && (selector_position < 1)) { ++selector_position; shadowOAM[127].attr0 = 72 | ATTR0_8BPP | ATTR0_SQUARE; } if (key_hit(BUTTON_RIGHT) && (selector_position == 0) && (points > 0)) { ++playerHealth; --points; shadowOAM[125].attr2 = 800 + (2 * playerHealth); } if (key_hit(BUTTON_LEFT) && (selector_position == 0) && (playerHealth > 1)) { --playerHealth; ++points; shadowOAM[125].attr2 = 800 + (2 * playerHealth); } if (key_hit(BUTTON_RIGHT) && (selector_position == 1) && (points > 0)) { ++player_damage; --points; shadowOAM[124].attr2 = 800 + (2 * player_damage); } if (key_hit(BUTTON_LEFT) && (selector_position == 1) && (player_damage > 1)) { --player_damage; ++points; shadowOAM[124].attr2 = 800 + (2 * player_damage); } } if (key_hit(BUTTON_A)) { int i; for (i=0; i<128; ++i) { OAM[i].attr0 = ATTR0_HIDE; } state = GAME_OVERWORLD; } }
void PlayState::checkInput() { // Start = pause game if (key_hit(KEY_START)) { gameStateMan->pushState(g_pauseState); } // R-Button = swap weapon modes if (key_hit(KEY_R)) { R_triggered = !R_triggered; R_triggered_indicator.setTileIndex(R_triggered ? g_bullet_selection2TilesPos : g_bullet_selection1TilesPos); } // Check for A button press // First block checks for an immediate button press. // Second block allows constant fire by holding a button. This is forced to a specific frequency. if (key_is_down(KEY_A)) { if (R_triggered) { player.shootLightWide(); } else { player.shootLightFocus(); } } else { player.idleLight(); } // secondary fire if (key_is_down(KEY_B)) { player.shootHeavy(); } else { player.idleHeavy(); } // L-Button = bomb the screen, destroying all enemies and bullets if (key_hit(KEY_L) && player.hasBomb()) { player.subtractBomb(); // play the bomb sound g_audioMan->playOneShot(bombNoise, bombNoiseSize); // Destroy enemies EnemyIterator itr = enemies.begin(); Enemy* curEnemy; while ((curEnemy = itr.next()) != 0) { curEnemy->setVisible(false); itr.dealloc(); g_playerScore = g_playerScore + 200; } bombAnimation = true; // Destroy enemy bullets EnemyBulletIterator enemyBulletItr = enemyBullets.begin(); Bullet* toUpdate; while ((toUpdate = enemyBulletItr.next()) != 0) { toUpdate->setVisible(false); enemyBulletItr.dealloc(); } // Destroy player bullets PlayerBulletIterator bulletItr = playerBullets.begin(); Bullet* playerToUpdate; while ((playerToUpdate = bulletItr.next()) != 0) { playerToUpdate->setVisible(false); bulletItr.dealloc(); } powerUp.setVisible(false); powerUpExists = false; } }
void game_manager::title_screen_func() { curr_game_mode = gm_title_screen; irq_init(); //irqEnable(irq_vblank); bios_wait_for_vblank(); // Use video Mode 0, use 1D object mapping, enable forced blank, // and display BG 0. reg_dispcnt = dcnt_mode0 | dcnt_obj_1d | dcnt_blank_on | dcnt_bg0_on; //// Use video Mode 0, use 1D object mapping, enable forced blank, //// and display BG 0, BG 1, BG 2, and BG 3 //reg_dispcnt = dcnt_mode0 | dcnt_obj_1d | dcnt_blank_on | dcnt_bg0_on // | dcnt_bg1_on | dcnt_bg2_on | dcnt_bg3_on | dcnt_obj_on; // Use screen base block 28 for BG0's Map reg_bg0cnt = bgcnt_sbb(bg0_sbb); reg_bg1cnt = bgcnt_sbb(bg1_sbb); reg_bg2cnt = bgcnt_sbb(bg2_sbb); reg_bg3cnt = bgcnt_sbb(bg3_sbb); // Clear bgofs_mirror for ( u32 i=0; i<3; ++i ) { gfx_manager::bgofs_mirror[i].curr.x = gfx_manager::bgofs_mirror[i].prev.x = {0}; gfx_manager::bgofs_mirror[i].curr.y = gfx_manager::bgofs_mirror[i].prev.y = {0}; } gfx_manager::copy_bgofs_mirror_to_registers(); // Copy the title screen's tiles and tilemap to VRAM bios_do_lz77_uncomp_vram( title_screenTiles, bg_tile_vram ); gfx_manager::upload_bg_palettes_to_target(bg_pal_ram); // This is sort of a hack. bios_do_lz77_uncomp_wram( title_screenMap, active_level::bg0_screenblock_mirror ); active_level_manager::copy_sublevel_from_array_2d_helper_to_vram(); // Disable forced blank clear_bits( reg_dispcnt, dcnt_blank_mask ); //memcpy8( test_sram_arr, (void *)debug_arr_u32, test_sram_arr_size ); for (;;) { bios_wait_for_vblank(); key_poll(); // Start the game if the Start button is hit if ( key_hit(key_start) ) { irqSet( irq_vblank, (u32)mmVBlank ); irqEnable(irq_vblank); // Don't call mmInitDefault more than once. It uses malloc(), // and it apparently MaxMOD doesn't ever call free(). mmInitDefault( (mm_addr)practice_17_bin, 8 ); mmSetVBlankHandler(reinterpret_cast<void*>(vblank_func)); reinit_the_game(); break; } } }
void MainMenu() { //This function brings up the main menu and has it do stuff. RegisterRamReset(RESET_GFX); REG_DISPCNT= DCNT_MODE0 | DCNT_BG0; tte_init_chr4c(0, // BG 0 BG_CBB(0)|BG_SBB(31), // Charblock 0; screenblock 31 0xF000, // Screen-entry offset bytes2word(1,2,0,0), // Color attributes. CLR_WHITE, // White text &verdana9Font, // Verdana 9 font NULL ); vid_vsync(); draw_main_menu(); while(1){ vid_vsync(); mmFrame(); key_poll(); //This code is still being worked on but it will handle what is selected on the menu. if (key_hit(KEY_DOWN)){ mainmenuselected++; if (mainmenuselected > 3){ mainmenuselected = 3; } draw_main_menu(); }else if (key_hit(KEY_UP)){ mainmenuselected = mainmenuselected - 1; if (mainmenuselected < 0){ mainmenuselected = 0; } draw_main_menu(); }else if (key_hit(KEY_B)){ }else if (key_hit(KEY_A)){ if (mainmenuselected == 0){ biosdump(); vid_vsync(); draw_main_menu(); }else if (mainmenuselected == 1){ buttontest(); vid_vsync(); draw_main_menu(); }else if (mainmenuselected == 2){ RTC_Main(); vid_vsync(); draw_main_menu(); }else if (mainmenuselected == 3){ soundtest(); vid_vsync(); draw_main_menu(); } } } }