Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <spaceinvaders.h>
- #include <sprites.h>
- #include <stdio.h>
- //fb[3*(10+10*240)] = fb[imageDepth*(offsetX + offsetY*imageStride)]
- //WritePixel((void*)data, int x, int y, int r, int g, int b)
- //int* myNewStartPosition = &myHugeArray[start_pos];
- struct bullet{
- int x;
- int y;
- int exist;
- int type;
- };
- struct tank{
- int x;
- int alive;
- int shotsfired;
- struct bullet shots[Max_Bullets];
- };
- int main()
- {
- // Initialize services
- srvInit();
- aptInit();
- hidInit(NULL);
- gfxInit();
- init_game();//Initialize Some Variables Used to Draw the Invaders in the Correct Locations (eg Find the middle of the screen)
- //as well as other math
- //gfxSet3D(true); // uncomment if using stereoscopic 3D
- int alternating = 1;
- int frame = 0;
- int right = 1;
- int level = 0;
- int debugval =0;
- int dtext =0;
- int i=0;
- struct tank player;
- player.x =100;
- for(i = 0;i<Max_Bullets;i++){
- player.shots[i].exist = 0;
- player.shots[i].x = 0;
- player.shots[i].y = 0;
- }
- player.shotsfired = 0;
- // Main loop
- while (aptMainLoop()){
- gspWaitForVBlank();
- hidScanInput();
- frame++;
- // Frame Counter
- if (frame>speed){
- frame = 0;
- alternate(&alternating);
- alien_movement(&right,&level);
- }
- u32 kDown = hidKeysDown();// Keys Pressed
- if (kDown & KEY_START){
- break; // break in order to return to hbmenu
- }
- if (kDown & KEY_DRIGHT){
- //if (0<0){//Keep Within border
- //player.x++;//Move Tank Right
- //}
- debugval++;
- }
- if (kDown & KEY_DLEFT){
- //if (0>0){//Keep Tank Within Border
- //player.x--;
- //}
- //Move Tank Left
- debugval--;
- }
- if (kDown & KEY_DUP){
- }
- if (kDown & KEY_DDOWN){
- }
- if (kDown & KEY_A){
- if (player.shotsfired<100){
- player.shotsfired++;
- for(i=0;i<100;i++){
- if(player.shots[i].exist != 1){
- player.shots[i].exist = 1;
- player.shots[i].x=player.x; //+half of tank so it shoots in middle
- player.shots[i].y=12; // bullet leaves barrel here
- break;
- }
- }
- }
- else{
- //Draw Animation for Jammed (little red explosion out barrel)
- }
- //Shots Fired (Player) Keep Track of and delete when offscreen
- //alien_movement(&right,&level);
- }
- u32 kHeld = hidKeysHeld();//Key is Held
- if (kHeld & KEY_CPAD_LEFT){
- if (player.x>draw_start_x[alien_Large_arraypos])
- player.x--;
- }
- if (kHeld & KEY_CPAD_RIGHT){
- if (player.x < (screen_top_width - draw_start_x[alien_Large_arraypos])){
- player.x++;
- }
- }
- // Example rendering code that displays a white pixel
- // Please note that the 3DS screens are sideways (thus 240x400 and 240x320)
- u8* fbtop = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
- u8* fbbot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
- memset(fbtop, 0, 240*400*3);
- memset(fbbot, 0, 240*320*3);
- //Create function to draw for an ammount of frames
- for(i = 0;i<Max_Bullets;i++){
- if(player.shots[i].y>=screen_top_height-10){
- player.shots[i].exist = 0;
- player.shots[i].y = 0;
- player.shotsfired--;
- }
- if(get_alien_collision(&player.shots[i],alternating)){
- player.shots[i].exist = 0;
- //Bullet Interception
- }
- if(player.shots[i].exist == 1){
- player.shots[i].y+= 1;
- WritePixel(player.shots[i].y,player.shots[i].x,255,0,0,fbtop);//Placeholder for Actual Bullets
- }
- }
- //draw_player();
- draw_aliens(0,0,255,alternating,fbtop);
- draw_border(255,255,255,5,fbtop);
- //for(dtext=0;dtext<3;dtext++){
- // sprintf(debuglines[dtext], "drawstartx[%d] = %d",dtext,draw_start_x[dtext]);
- //}
- //sprintf(debuglines[3], "right = %d",right);
- //sprintf(debuglines[4], "LeftSide_Line[%d] = %d" ,debugval,*layout_first_in_line[debugval]);
- //sprintf(debuglines[5], "Address[%d] = %p" ,debugval,layout_first_in_line[debugval]);
- //sprintf(debuglines[6], "RightSide_Line[%d] = %d" ,debugval,*layout_last_in_line[debugval]);
- //sprintf(debuglines[7], "Address[%d] = %p" ,debugval,layout_last_in_line[debugval]);
- //sprintf(debuglines[8], "Bottom_Row[%d] = %d" ,debugval,*layout_bottom_row[debugval]);
- //sprintf(debuglines[9], "Address[%d] = %p" ,debugval,layout_bottom_row[debugval]);
- //sprintf(debuglines[11], "ShotsFired = %d" ,player.shotsfired);
- //sprintf(debuglines[12], "Shot[%d].y = %d" ,debugval,player.shots[debugval].y);
- //sprintf(debuglines[13], "Shot[%d].x = %d" ,debugval,player.shots[debugval].x);
- //sprintf(debuglines[14], "ShotExist[%d] = %d" ,debugval,player.shots[debugval].exist);
- printdebug(fbbot);
- //render(50,50,fbbot,a);
- // Flush and swap framebuffers
- gfxFlushBuffers();
- gfxSwapBuffers();
- }
- // Exit services
- gfxExit();
- hidExit();
- aptExit();
- srvExit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement