Advertisement
Guest User

main.c

a guest
Dec 5th, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.37 KB | None | 0 0
  1. #include <spaceinvaders.h>
  2. #include <sprites.h>
  3. #include <stdio.h>
  4. //fb[3*(10+10*240)] = fb[imageDepth*(offsetX + offsetY*imageStride)]
  5. //WritePixel((void*)data, int x, int y, int r, int g, int b)
  6. //int* myNewStartPosition = &myHugeArray[start_pos];
  7.  
  8. struct bullet{
  9.     int x;
  10.     int y;
  11.     int exist;
  12.     int type;
  13. };
  14.  
  15. struct tank{
  16.     int x;
  17.     int alive;
  18.     int shotsfired;
  19.     struct bullet shots[Max_Bullets];
  20. };
  21. int main()
  22. {
  23.     // Initialize services
  24.     srvInit();
  25.     aptInit();
  26.     hidInit(NULL);
  27.     gfxInit();
  28.     init_game();//Initialize Some Variables Used to Draw the Invaders in the Correct Locations (eg Find the middle of the screen)
  29.                 //as well as other math
  30.     //gfxSet3D(true); // uncomment if using stereoscopic 3D
  31.     int alternating = 1;
  32.     int frame = 0;
  33.     int right = 1;
  34.     int level = 0;
  35.     int debugval =0;
  36.     int dtext =0;
  37.     int i=0;
  38.     struct tank player;
  39.     player.x =100;
  40.  
  41.     for(i = 0;i<Max_Bullets;i++){
  42.     player.shots[i].exist = 0;
  43.     player.shots[i].x = 0;
  44.     player.shots[i].y = 0;
  45.     }
  46.     player.shotsfired = 0;
  47.  
  48.     // Main loop
  49.     while (aptMainLoop()){
  50.  
  51.         gspWaitForVBlank();
  52.         hidScanInput();
  53.         frame++;
  54.         // Frame Counter
  55.         if (frame>speed){
  56.             frame = 0;
  57.             alternate(&alternating);
  58.             alien_movement(&right,&level);
  59.         }
  60.  
  61.         u32 kDown = hidKeysDown();// Keys Pressed
  62.         if (kDown & KEY_START){
  63.             break; // break in order to return to hbmenu
  64.         }
  65.         if (kDown & KEY_DRIGHT){
  66.             //if (0<0){//Keep Within border
  67.             //player.x++;//Move Tank Right
  68.             //}
  69.             debugval++;
  70.         }
  71.         if (kDown & KEY_DLEFT){
  72.             //if (0>0){//Keep Tank Within Border
  73.             //player.x--;
  74.             //}
  75.             //Move Tank Left
  76.             debugval--;
  77.         }
  78.         if (kDown & KEY_DUP){
  79.         }
  80.         if (kDown & KEY_DDOWN){
  81.         }
  82.         if (kDown & KEY_A){
  83.             if (player.shotsfired<100){
  84.                 player.shotsfired++;
  85.                 for(i=0;i<100;i++){
  86.                     if(player.shots[i].exist != 1){
  87.                     player.shots[i].exist = 1;
  88.                     player.shots[i].x=player.x; //+half of tank so it shoots in middle
  89.                     player.shots[i].y=12; // bullet leaves barrel here
  90.                     break;
  91.                     }
  92.                 }
  93.             }
  94.             else{
  95.                 //Draw Animation for Jammed (little red explosion out barrel)
  96.             }
  97.         //Shots Fired (Player) Keep Track of and delete when offscreen
  98.         //alien_movement(&right,&level);
  99.         }
  100.         u32 kHeld = hidKeysHeld();//Key is Held
  101.         if (kHeld & KEY_CPAD_LEFT){
  102.                 if (player.x>draw_start_x[alien_Large_arraypos])
  103.         player.x--;
  104.         }
  105.         if (kHeld & KEY_CPAD_RIGHT){
  106.             if (player.x < (screen_top_width - draw_start_x[alien_Large_arraypos])){
  107.                 player.x++;
  108.             }
  109.         }
  110.         // Example rendering code that displays a white pixel
  111.         // Please note that the 3DS screens are sideways (thus 240x400 and 240x320)
  112.         u8* fbtop = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
  113.         u8* fbbot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
  114.         memset(fbtop, 0, 240*400*3);
  115.         memset(fbbot, 0, 240*320*3);
  116.         //Create function to draw for an ammount of frames
  117.  
  118.         for(i = 0;i<Max_Bullets;i++){
  119.             if(player.shots[i].y>=screen_top_height-10){
  120.                 player.shots[i].exist = 0;
  121.                 player.shots[i].y = 0;
  122.                 player.shotsfired--;
  123.             }
  124.             if(get_alien_collision(&player.shots[i],alternating)){
  125.                 player.shots[i].exist = 0;
  126.             //Bullet Interception
  127.             }
  128.             if(player.shots[i].exist == 1){
  129.                 player.shots[i].y+= 1;
  130.                 WritePixel(player.shots[i].y,player.shots[i].x,255,0,0,fbtop);//Placeholder for Actual Bullets
  131.             }
  132.         }
  133.  
  134.         //draw_player();
  135.         draw_aliens(0,0,255,alternating,fbtop);
  136.         draw_border(255,255,255,5,fbtop);
  137.  
  138.         //for(dtext=0;dtext<3;dtext++){
  139.             //      sprintf(debuglines[dtext], "drawstartx[%d] = %d",dtext,draw_start_x[dtext]);
  140.         //}
  141.         //sprintf(debuglines[3], "right = %d",right);
  142.         //sprintf(debuglines[4], "LeftSide_Line[%d] = %d" ,debugval,*layout_first_in_line[debugval]);
  143.         //sprintf(debuglines[5], "Address[%d] = %p" ,debugval,layout_first_in_line[debugval]);
  144.         //sprintf(debuglines[6], "RightSide_Line[%d] = %d" ,debugval,*layout_last_in_line[debugval]);
  145.         //sprintf(debuglines[7], "Address[%d] = %p" ,debugval,layout_last_in_line[debugval]);
  146.         //sprintf(debuglines[8], "Bottom_Row[%d] = %d" ,debugval,*layout_bottom_row[debugval]);
  147.             //sprintf(debuglines[9], "Address[%d] = %p" ,debugval,layout_bottom_row[debugval]);
  148.             //sprintf(debuglines[11], "ShotsFired = %d" ,player.shotsfired);
  149.             //sprintf(debuglines[12], "Shot[%d].y = %d" ,debugval,player.shots[debugval].y);
  150.             //sprintf(debuglines[13], "Shot[%d].x = %d" ,debugval,player.shots[debugval].x);
  151.             //sprintf(debuglines[14], "ShotExist[%d] = %d" ,debugval,player.shots[debugval].exist);
  152.         printdebug(fbbot);
  153.         //render(50,50,fbbot,a);
  154.         // Flush and swap framebuffers
  155.         gfxFlushBuffers();
  156.         gfxSwapBuffers();
  157.     }
  158.  
  159.     // Exit services
  160.     gfxExit();
  161.     hidExit();
  162.     aptExit();
  163.     srvExit();
  164.     return 0;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement