int main() { PSX_Init(); GsInit(); GsSetList(prim_list); GsClearMem(); GsSetVideoMode(320, 240, VMODE_PAL); GsLoadFont(768, 0, 768, 256); SetVBlankHandler(prog_vblank_handler); while(1) { if(display_is_old) { dbuf=!dbuf; GsSetDispEnvSimple(0, dbuf ? 0 : 256); GsSetDrawEnvSimple(0, dbuf ? 256 : 0, 320, 240); GsSortCls(0,0,0); GsPrintFont(70, 120, "Hello World"); GsDrawList(); while(GsIsDrawing()); display_is_old=0; } } return 0; }
int pal_or_ntsc_selection() { unsigned short padbuf; int x; game_drawenv.draw_on_display = 1; x = game_drawenv.y; game_drawenv.y = game_dispenv.y; GsSetDrawEnv(&game_drawenv); game_rect.x = 0; game_rect.y = 0; game_rect.w = 320; game_rect.h = 240; game_rect.r = 0; game_rect.g = 0; game_rect.b = 0; game_rect.attribute = 0; GsSortRectangle(&game_rect); game_print("PAL/NTSC SELECTION", 128, 64); game_print("X - PAL", 128, 80); game_print("O - NTSC", 128, 88); GsDrawList(); while(GsIsDrawing()); game_drawenv.draw_on_display = 0; game_drawenv.y = x; GsSetDrawEnv(&game_drawenv); while(1) { PSX_ReadPad(&padbuf, NULL); if((padbuf & PAD_CROSS) && !cross_pressed) return VMODE_PAL; // PAL if((padbuf & PAD_CIRCLE) && !circle_pressed) { //printf("circle_pressed = %d\n", circle_pressed); return VMODE_NTSC; // NTSC } if(!(padbuf & PAD_CROSS)) cross_pressed = 0; if(!(padbuf & PAD_CIRCLE)) circle_pressed = 0; } }
int main() { PSX_Init(); GsInit(); GsSetList(prim_list); GsClearMem(); GsSetVideoMode(320, 240, COMPILE_VMODE); GsLoadFont(768, 0, 768, 256); SetVBlankHandler(prog_vblank_handler); volatile int player1_score = 0; volatile int player2_score = 0; volatile int weapon1 = 0; volatile int weapon2 = 0; volatile int pause = 0; volatile int newround = 0; while(1) { if(display_is_old) { dbuf=!dbuf; GsSetDispEnvSimple(0, dbuf ? 0 : 256); GsSetDrawEnvSimple(0, dbuf ? 256 : 0, 320, 240); if(newround == 1) { while((pause + 240) > time_counter) { }; newround = 0; }; GsSortCls(0,0,255); if(player1_score == 10) { GsPrintFont(5, 100, " Player 1 wins. Take that, Player 2."); player1_score = 0; player2_score = 0; newround = 1; } else if(player2_score == 10) { GsPrintFont(5, 100, " Player 2 wins. Hah, Player 1 fails."); player1_score = 0; player2_score = 0; newround = 1; } else { GsPrintFont(5, 100, " Take 10 paces and draw your weapons!"); }; GsPrintFont(5, 15, " Rock, Paper, Scissors by Moonlit"); GsPrintFont(5, 22, " ----------------------------------"); GsPrintFont(5, 45, " Choose your weapon: Scores: "); GsPrintFont(5, 52, "--------------------- ---------"); GsPrintFont(5, 60, " SQUARE = Rock P1: %d", player1_score); GsPrintFont(5, 70, " CROSS = Paper P2: %d", player2_score); GsPrintFont(5, 80, " CIRCLE = Scissors "); PSX_ReadPad(&pad1, &pad2); if(pad1 & PAD_SQUARE) { //P1 ROCK weapon1 = 1; } else if(pad1 & PAD_CROSS) { //P1 PAPER weapon1 = 2; } else if(pad1 & PAD_CIRCLE) { //P1 SCISSORS weapon1 = 3; }; if(pad2 & PAD_SQUARE) { //P2 ROCK weapon2 = 1; } else if(pad2 & PAD_CROSS) { //P2 PAPER weapon2 = 2; } else if(pad2 & PAD_CIRCLE) { //P2 SCISSORS weapon2 = 3; }; pause = time_counter; if(weapon1 > 0 && weapon2 > 0) { if(weapon1 == 1) GsPrintFont(5, 130, " Player 1 chose rock...");; if(weapon1 == 2) GsPrintFont(5, 130, " Player 1 chose paper...");; if(weapon1 == 3) GsPrintFont(5, 130, " Player 1 chose scissors...");; if(weapon2 == 1) GsPrintFont(5, 140, " Player 2 chose rock...");; if(weapon2 == 2) GsPrintFont(5, 140, " Player 2 chose paper...");; if(weapon2 == 3) GsPrintFont(5, 140, " Player 2 chose scissors...");; // It's a draw. if(weapon1 == 1 && weapon2 == 1) { GsPrintFont(5, 170, " Thick as two bricks."); GsPrintFont(5, 180, " Surely there's mortar life..?"); }; if(weapon1 == 2 && weapon2 == 2) { GsPrintFont(5, 170, " Two sheets to the wind."); GsPrintFont(5, 180, " It's blowing up in here."); }; if(weapon1 == 3 && weapon2 == 3) { GsPrintFont(5, 170, " Neither of you are the "); GsPrintFont(5, 180, " sharpest in the drawer, are you?"); }; // Player 1 wins. if(weapon1 == 1 && weapon2 == 3) { GsPrintFont(5, 160, " Careful Player 2... "); GsPrintFont(5, 170, " You'll ruin those scissors."); GsPrintFont(5, 180, " That's a point for Player 1."); player1_score++; }; if(weapon1 == 2 && weapon2 == 1) { GsPrintFont(5, 160, " Aw, gift wrapped rocks."); GsPrintFont(5, 170, " Really, Player 2."); GsPrintFont(5, 180, " You shouldn't have."); player1_score++; }; if(weapon1 == 3 && weapon2 == 2) { GsPrintFont(5, 160, " Player 2 gets the chop."); GsPrintFont(5, 170, " A ticker tape parade for Player 1."); GsPrintFont(5, 180, " What other use for shredded paper?"); player1_score++; }; // Player 2 wins. if(weapon2 == 1 && weapon1 == 3) { GsPrintFont(5, 160, " Stab in the back for Player 1."); GsPrintFont(5, 170, " At least those blades"); GsPrintFont(5, 180, " are safer now."); player2_score++; }; if(weapon2 == 2 && weapon1 == 1) { GsPrintFont(5, 160, " +1 for Player 2."); GsPrintFont(5, 170, " Player 1 gets stoned."); GsPrintFont(5, 180, " Too wrapped up in the game."); player2_score++; }; if(weapon2 == 3 && weapon1 == 2) { GsPrintFont(5, 160, " Player 1's all cut up."); GsPrintFont(5, 170, " It's twice as nice when "); GsPrintFont(5, 180, " the paper's sliced."); player2_score++; }; newround = 1; weapon1 = 0; weapon2 = 0; }; GsDrawList(); while(GsIsDrawing()); display_is_old=1; } } return 0; }
int main() { GsDispEnv my_dispenv; GsDrawEnv my_drawenv; GsLine my_line; GsSprite my_sprite; GsRectangle colorbox; GsDot my_dot; unsigned short pad1; unsigned int WasL2=0, WasR2=0, WasL1=0, WasR1=0, WasSelect = 0; int x, y; PSX_InitEx(PSX_INIT_NOBIOS); GsInit(); GsClearMem(); SetVBlankHandler(my_vblank_handler); // This has to be interlaced GsSetVideoModeEx(640, 480, EXAMPLES_VMODE, 0, 1, 0); my_dispenv.x = 0; my_dispenv.y = 0; GsSetDispEnv(&my_dispenv); my_drawenv.dither = 0; my_drawenv.draw_on_display = 1; my_drawenv.x = 0; my_drawenv.y = 0; my_drawenv.w = 640; my_drawenv.h = 512; my_drawenv.ignore_mask = 0; my_drawenv.set_mask = 0; GsSetDrawEnv(&my_drawenv); GsSetList(primitive_list); load_ui_graphics(); while(GsIsDrawing()); colorbox.x = 0; colorbox.y = 0; colorbox.w = 640; colorbox.h = 511; colorbox.r = 255; colorbox.g = 255; colorbox.b = 255; colorbox.attribute = 0; GsSortRectangle(&colorbox); sort_color_boxes(); my_sprite.x = 0; my_sprite.y = 0; my_sprite.tpage = 10; my_sprite.u = 0; my_sprite.v = 0; my_sprite.attribute = 0; my_sprite.cx = 640; my_sprite.cy = 480; my_sprite.r = my_sprite.g = my_sprite.b = NORMAL_LUMINOSITY; my_sprite.scalex = my_sprite.scaley = 0; my_sprite.w = 16; my_sprite.h = 24; GsDrawList(); while(GsIsDrawing()); // Backup 32x32 area MoveImage(cursor_x, cursor_y, 992, 0, 32, 32); my_dot.attribute = 0; while(1) { while(speed_counter) { old_cursor_x = cursor_x; old_cursor_y = cursor_y; // Restore 32x32 area MoveImage(992, 0, old_cursor_x, old_cursor_y, 32, 32); while(GsIsDrawing()); PSX_ReadPad(&pad1, NULL); if(pad1 & PAD_LEFT) cursor_x-=cursor_speed; if(pad1 & PAD_RIGHT) cursor_x+=cursor_speed; if(pad1 & PAD_UP) cursor_y-=cursor_speed; if(pad1 & PAD_DOWN) cursor_y+=cursor_speed; if(cursor_x <= 0) cursor_x = 0; if(pad1 & PAD_CROSS) { if(cursor_y >= 384) { y = (cursor_y - 384) >> 4; x = cursor_x >> 6; current_color[0] = paint_colors[(y * 10)+x][0]; current_color[1] = paint_colors[(y * 10)+x][1]; current_color[2] = paint_colors[(y * 10)+x][2]; } else { switch(brush_type) { case 0: if(cursor_y >= 384) { break; } my_dot.r = current_color[0]; my_dot.g = current_color[1]; my_dot.b = current_color[2]; my_dot.x = cursor_x; my_dot.y = cursor_y; GsSortDot(&my_dot); break; case 1: if(cursor_y >= 380) { break; } my_dot.r = current_color[0]; my_dot.g = current_color[1]; my_dot.b = current_color[2]; my_dot.x = cursor_x + 1; my_dot.y = cursor_y; GsSortDot(&my_dot); my_dot.x++; GsSortDot(&my_dot); my_dot.y++; my_dot.x-=2; GsSortDot(&my_dot); my_dot.x++; GsSortDot(&my_dot); my_dot.x++; GsSortDot(&my_dot); my_dot.x++; GsSortDot(&my_dot); my_dot.y++; my_dot.x-=2; GsSortDot(&my_dot); my_dot.x++; GsSortDot(&my_dot); break; } } GsDrawList(); while(GsIsDrawing()); } if((pad1 & PAD_R2) && !WasR2) { cursor_speed++; WasR2 = 1; } if((pad1 & PAD_L2) && !WasL2) { cursor_speed--; WasL2 = 1; } if(!(pad1 & PAD_R2)) WasR2 = 0; if(!(pad1 & PAD_L2)) WasL2 = 0; if((pad1 & PAD_R1) && !WasR1) { brush_type++; WasR1 = 1; } if((pad1 & PAD_L1) && !WasL1) { brush_type--; WasL1 = 1; } if((pad1 & PAD_SELECT) && !WasSelect) { my_sprite.attribute ^= (ENABLE_TRANS | TRANS_MODE(0)); my_dot.attribute ^= (ENABLE_TRANS | TRANS_MODE(0)); WasSelect = 1; } if(!(pad1 & PAD_SELECT)) WasSelect = 0; if(!(pad1 & PAD_R1)) WasR1 = 0; if(!(pad1 & PAD_L1)) WasL1 = 0; if(cursor_speed <= 0) cursor_speed = 1; if(cursor_speed >= 8) cursor_speed = 7; if(brush_type <= 0) brush_type = 0; if(brush_type > 1) brush_type = 1; // Backup 32x32 area MoveImage(cursor_x, cursor_y, 992, 0, 32, 32); while(GsIsDrawing()); // if(cursor_x != old_cursor_x || cursor_y != old_cursor_y) // { // printf("cx = %d, cy = %d, cursor_speed = %d, brush_type = %d\n", // cursor_x, cursor_y, cursor_speed, brush_type); my_sprite.x = cursor_x; my_sprite.y = cursor_y; GsSortSimpleSprite(&my_sprite); GsDrawList(); while(GsIsDrawing()); // } speed_counter--; }
void game_run() { int x, y, a, b, c; unsigned short padbuf; while(speed_counter > 0) { scc++; if(vibration_cntdown > 0) { printf("vibration = %d\n", vibration_cntdown); pad_enable_vibration(0); pad_set_vibration(0, 0xFF, 0x80); vibration_cntdown--; if(vibration_cntdown == 0) pad_set_vibration(0, 0, 0); } PSX_ReadPad(&padbuf, NULL); if(scc == 5 && !game_over) { if(snake_dir <= SNAKE_DIR_RIGHT) { if(padbuf & PAD_UP) snake_dir = SNAKE_DIR_UP; if(padbuf & PAD_DOWN) snake_dir = SNAKE_DIR_DOWN; } else { if(padbuf & PAD_LEFT) snake_dir = SNAKE_DIR_LEFT; if(padbuf & PAD_RIGHT) snake_dir = SNAKE_DIR_RIGHT; } for(y = 0; y < 29; y++) for(x = 0; x < 40; x++) { if(snake_array[y][x] == snake_size) { switch(snake_dir) { case SNAKE_DIR_LEFT: b = y; a = x-1; break; case SNAKE_DIR_RIGHT: b = y; a = x+1; break; case SNAKE_DIR_UP: b = y-1; a = x; break; case SNAKE_DIR_DOWN: b = y+1; a = x; break; } c = check_snake_collision(a,b); if(c) { snake_array[b][a] = snake_size+1; if(c==2) { snake_size++; score+=100; //printf("%d\n", score); SsKeyOn(2); new_apple(); } } else { vibration_cntdown = 10; game_over = 1; SsKeyOff(0); SsKeyOn(1); scc = 0; } if(snake_array[y][x] == 1 && c!=2) snake_array[y][x] = 0; goto out_of_collision_checking; } } out_of_collision_checking: for(y = 0; y < 29; y++) for(x = 0; x < 40; x++) if(snake_array[y][x]&&snake_array[y][x]<0x80&&c!=2) snake_array[y][x]--; scc = 0; } else if(game_over) { scc++; if(scc >= 510) { if((padbuf & PAD_CROSS) && !cross_pressed) { game_setup(); cross_pressed = 1; } else if((padbuf & PAD_CIRCLE) && !circle_pressed) { circle_pressed = 1; GsSetVideoMode(320, 240, pal_or_ntsc_selection()); game_setup(); } if(!(padbuf & PAD_CROSS)) cross_pressed = 0; if(!(padbuf & PAD_CIRCLE)) circle_pressed = 0; } } speed_counter--; } if(screen_old) { game_rect.x = 0; game_rect.y = 0; game_rect.w = 320; game_rect.h = 240; game_rect.r = 0; game_rect.g = 0; game_rect.b = 0; game_rect.attribute = 0; GsSortRectangle(&game_rect); game_sprite.x = 0; game_sprite.y = 0; game_sprite.w = 256; game_sprite.h = 240; game_sprite.u = 0; game_sprite.v = 0; game_sprite.r = NORMAL_LUMINOSITY; game_sprite.g = NORMAL_LUMINOSITY; game_sprite.b = NORMAL_LUMINOSITY; game_sprite.tpage = 5; game_sprite.attribute = COLORMODE(COLORMODE_16BPP); GsSortSimpleSprite(&game_sprite); game_sprite.x += 256; game_sprite.w = 64; game_sprite.tpage = 9; GsSortSimpleSprite(&game_sprite); game_rect.w = 8; game_rect.h = 8; game_rect.attribute = ENABLE_TRANS | TRANS_MODE(0); for(y = 0; y < 29; y++) { for(x = 0; x < 40; x++) { game_rect.x = x * 8; game_rect.y = y * 8; if(snake_array[y][x] >= 1 && snake_array[y][x] <= 0x7F) { game_rect.r = 0; game_rect.g = 255; game_rect.b = 0; GsSortRectangle(&game_rect); } else if(snake_array[y][x] == 0x80) { game_rect.r = 255; game_rect.g = 0; game_rect.b = 255; GsSortRectangle(&game_rect); } else if(snake_array[y][x] == 0x81) { game_rect.r = 0; game_rect.g = 0; game_rect.b = 128; GsSortRectangle(&game_rect); } } } sprintf(string_buf, "SCORE: %d", score); game_print(string_buf, 0, 232); if(game_over) { game_rect.w = 320; game_rect.h = 240; game_rect.x = 0; game_rect.y = 0; if(scc<=255)x=scc;else x=255; game_rect.r = x; game_rect.g = x; game_rect.b = x; game_rect.attribute = ENABLE_TRANS|TRANS_MODE(2); GsSortRectangle(&game_rect); if(scc>=300) { game_center_print("GAME OVER!", 160, 120); } if(scc>=420) game_center_print("WHAT DO YOU WANT TO DO NOW?", 160, 136); if(scc>=450) game_center_print("PRESS X TO RESTART THE GAME.",160, 152); if(scc>=480) game_center_print("PRESS O FOR PAL/NTSC SELECTION SCREEN.",160,168); if(scc>=510) game_center_print("MADE WITH PSXSDK BY GIUSEPPE GATTA, 2010", 160, 200); } GsDrawList(); // While the graphic synthesizer (video card) is drawing // just sleep. while(GsIsDrawing()); // Swap drawing and display Y position, and swap list array // to use. In this way we achieve a double buffer. if(game_dispenv.y == 0) { game_dispenv.y = 256; game_drawenv.y = 0; } else { game_dispenv.y = 0; game_drawenv.y = 256; } GsSetDispEnv(&game_dispenv); GsSetDrawEnv(&game_drawenv); screen_old = 0; } }