so i have to make a "Space invaders" like game (just a simple one though) but i dont know what codes should i use

this is the code :

void movingX()
{
   int xcol = 1, xrow = 1;
   int ycol = 40, yrow = 24;
   int xbombcol = xcol, xbombrow = xrow + 1, xbombstat = 0;
   char ch;
   clrscr();
   gotoxy(xcol, xrow); putch('X');
   gotoxy(ycol, yrow); putch('Y');
   gotoxy(ycol-3, yrow); printf("<-");
   gotoxy(ycol+2, yrow); printf("->");
   do
   {
      if (xrow % 2 !=0)
      {
     if (xcol < 80)
     {
        delay(10); gotoxy(xcol,xrow); putch(' ');
        xcol++; gotoxy(xcol, xrow); putch('X');
     }
     else
     {
        gotoxy(xcol,xrow); putch(' '); xrow++;
        gotoxy(xcol,xrow); putch('X');
     }
      }
      else if (xrow % 2 == 0)
      {
     if(xcol > 1)
     {
        delay(10); gotoxy(xcol,xrow); putch(' ');
        xcol--; gotoxy(xcol, xrow); putch('X');
     }
     else
     {
        gotoxy(xcol,xrow); putch(' '); xrow++;
        gotoxy(xcol,xrow); putch('X');
     }
      }
      if (xbombstat == 0)
        {
            xbombstat = 1;
            gotoxy(xbombcol, xbombrow); putch('*');
        }
        if (xbombstat == 1 && xbombrow <= 24)
        {
           gotoxy(xbombcol, xbombrow); putch(' '); xbombrow++;
           gotoxy(xbombcol, xbombrow); putch('*');
        }
        if (xbombrow == 24)
        {
            if (xbombcol == ycol)
            {
                gotoxy(35, 12); puts("YOU LOOSE");
                xrow = 24;
            }
            gotoxy(xbombcol, xbombrow); putch(' ');
            xbombcol = xcol; xbombrow = xrow;
            xbombstat = 0;
        }


      if (kbhit())
      {
        ch = getch();
        switch(ch)
        {
          case 75 : if (ycol > 1)
                    {
                      gotoxy(ycol, yrow); putch(' '); ycol--;
                      gotoxy(ycol, yrow); putch('Y');
                    }break;
          case 77 : if (ycol < 80)
                    {
                      gotoxy(ycol, yrow); putch(' '); ycol++;
                      gotoxy(ycol, yrow); putch('Y');
                    }break;
          }
        }

   }while (xrow <24);
   puts("END OF LOOP!!!!");
   getch();
}

so basically, the "X" is moving and shooting "bombs" i can move the Y but i cannot let it shoot..that is my problem how to shoot(or fire projectile)

Cheers!

Recommended Answers

All 3 Replies

It's basically a combination of how the X shoots and how the Y moves. You add a case to the switch for your shoot key to create a projectile, and then follow a similar algorithm as the bomb to manage the projectile.

Hm, i am a little bit confused..where should i put it?

Hm, i am a little bit confused..where should i put it?

I'm a little confused too. Is the code you posted something you actually wrote? Or did you pinch it off the web and now need help modifying it because it's beyond your ability?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.