NXC code help!!!!!

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

NXC code help!!!!!

Post by nxtboyiii »

Hi

I am trying to figure out how to make a platformer game for nxt with nxc using tiles without the character moving tile by tile.
The Knight game I made moves smoothly tile by tile, so if you press the left button your character moves left 1 tile. I want to make it so the character moves left 1 pixel, not 16(The tile size).
Thanks, and have a nice day,
nxtboy III

programnxt.com
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC code help!!!!!

Post by muntoo »

Shouldn't this be in one a thread in NXT Software?!!!!!
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: NXC code help!!!!!

Post by nxtboyiii »

Yeah, I guess(I'm afraid Mightor will take it off).
Thanks, and have a nice day,
nxtboy III

programnxt.com
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: NXC code help!!!!!

Post by nxtboyiii »

Anyone interested?
I really need help.

btw, heres the code I have now which moves tile by tile:
https://sites.google.com/site/nxtzips/posts
Thanks, and have a nice day,
nxtboy III

programnxt.com
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC code help!!!!!

Post by afanofosc »

You can draw an RIC sprite at any X,Y position. If you know how to draw it at positions that are multiples of 16 then you know how to do it at positions that are multiples of 1. Just don't increment your position by 16. If you are using a complex RIC to draw the entire screen in one GraphicOutEx call then you may need two instead - one to draw the background and another (or multiple calls) to draw the character(s) on top of the background.

It is best to post simple code that is close to what you want and ask for help to make it do more closely what you want. I don't have time to plow through a thousand line program so KISS.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: NXC code help!!!!!

Post by nxtboyiii »

here is the basic code:
note- it does not compile
if you want the working version, download it from the website I mentioned earlier

Code: Select all

short lvl;
bool done,s;
int xp,yp,c,d,xvg,oxy,money;
int cou[EMAX];
char sc[EMAX];
int iac[EMAX];
int EMYCT;
int rrx,rry;
string gstr="";
char recover;
char tostr[1];
int xguy,yguy,width,height,pm,xg,yg,yl,xn,yn,life,jumpcount,fallh;
int var[2];
int varg[1];
int emx[EMAX];
int emy[EMAX];
int epm[EMAX];
bool elive[EMAX];
int vare[1];
brk map[500];
task engine()
{
 int punchadd;
 while(1)
 {
  GraphicOutEx(xg,yl,"guy.ric",varg);
  if(ButtonPressed(BTNCENTER,0) && SENSOR_1)
  {
   until(!SENSOR_1);
   rrx=0;
   rry=height;
   xvg=width;
   s=1;
   Wait(100);
   ClearScreen();
   TextOut(70,LCD_LINE3,StrCat("$",NumToStr(money)));
   TextOut(70,LCD_LINE2,StrCat("HP:",NumToStr(life)));
    for(int xv=0; xv < ArrayLen(map); xv++)
 {
  if(xv == xvg)
	{
	 xvg+=width;
   rry--;
   rrx=0;
  }
    if(map[xv].SLD == 1)
  {
   PointOut(rrx,rry);
  }
	  rrx++;
 }
  until(SENSOR_1);
  until(!SENSOR_1);
     d=(xguy/16*-1)+width*(yguy/16*-1)+7;
   c=(xguy/16*-1)+width*(yguy/16*-1);
   xp=0;
   yp=48;
   s=0;
   until(done);
  }
  repeat(2)
  {
  if(ButtonPressed(BTNCENTER,0) && !SENSOR_1)//Jump/climb
  {
   until(!ButtonPressed(BTNCENTER,0));
   if((map[pm-width].SLD == 0 || (OnTile(pm,32,16) && map[pm-width].SLD == 0)) && jumpcount < 2 && map[pm-width].alv == 0)
   {
    jumpcount++;
    	  if(pv == rit)
	   pv=ritj;
	  else if(pv == lft)
		 pv=lftj;
    if(yl == 32)
    {
	  yn=16;
    yguy+=16;
    repeat(4)
    {
		 yn-=4;
     GraphicOutEx(xg,yl,"guy.ric",varg);
     AfterMove(25);
     DrawEMY(0,-4);
    }
     yn=0;
AfterMove(0);
DrawEMY();
     }
     else if(yl != 32)
     {
      repeat(4)
      {
   		 RectOut(xg,yl,11,11,DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE);
    	 yl+=4;
       GraphicOutEx(xg,yl,"guy.ric",varg);
       AfterMove(25);
 		  }
     }
      pm-=width;
    }
   }
   }
    if(ButtonPressed(BTNRIGHT,0))
  {
   pv=rit;
  if(map[pm+1].SLD == 0 && map[pm+1].alv == 0)
  {
   PlayFileEx("step.rso",Volume(),0);
   if(width-(xguy/16*-1) > 7)
   {
/*            for(int e=0; e < EMYCT; e++)
	{
	 emx[e]-=16;
	}*/
	 xn=16;
	 xguy-=16;
       repeat(4)
   {
		xn-=4;
      GraphicOutEx(xg,yl,"guy.ric",varg);
AfterMove(25);
DrawEMY(-4,0);
   }
       xn=0;
AfterMove(0);
   }
   else
  {
   repeat(4)
   {
   		 RectOut(xg,yl,11,11,DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE);
   xg+=4;
      GraphicOutEx(xg,yl,"guy.ric",varg);
      AfterMove(25);
   }
  }
    pm++;
  }
  }
    if(ButtonPressed(BTNLEFT,0))
  {
   pv=lft;
  if(map[pm-1].SLD == 0 && map[pm-1].alv == 0)
  {
   PlayFileEx("step.rso",Volume(),0);
   if(xg == 16)
   {
/*         for(int e=0; e < EMYCT; e++)
	{
	 emx[e]+=16;
	}*/
	xguy+=16;
	xn=-16;
       repeat(4)
   {
		xn+=4;
      GraphicOutEx(xg,yl,"guy.ric",varg);
AfterMove(25);
DrawEMY(4,0);
   }
       xn=0;
		 AfterMove(0);
   }
   else if(xg != 16)
  {
   repeat(4)
   {
   		 RectOut(xg,yl,11,11,DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE);
   xg-=4;
      GraphicOutEx(xg,yl,"guy.ric",varg);
AfterMove(25);
   }
  }
    pm--;
  }
  }
      if(map[pm+width].SLD == 0 && map[pm+width].alv == 0)//Fall down
  {
   if((OnTile(pm+width,32,16) && ButtonPressed(BTNEXIT,0)) || !OnTile(pm+width,32,16))
   {
    fallh++;
       	  if(pv == rit)
	   pv=ritj;
	  else if(pv == lft)
		 pv=lftj;
   if(height-yguy/16*-1 > 4)
   {
	yguy-=16;
 yn=-16;
       repeat(4)
   {
		yn+=4;
      GraphicOutEx(xg,yl,"guy.ric",varg);
AfterMove(25);
RectOut(0,60,100,4,DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE);
DrawEMY(0,4);
   }
       yn=0;
AfterMove(0);
   }
   else
  {
   repeat(4)
   {
   		 RectOut(xg,yl,11,11,DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE);
   yl-=4;
      GraphicOutEx(xg,yl,"guy.ric",varg);
   AfterMove(25);
   }
  }
    pm+=width;
 	  if(pv == ritj)
	   pv=rit;
	  else if(pv == lftj)
		 pv=lft;
  }
  }
 }
}


//draw the map tile by tile
task displaymap()
{
     unsigned long t0;
     while(1)
     {
      done=0;
      until(s == 0);
      d=(xguy/16*-1)+width*(yguy/16*-1)+7;
      c=(xguy/16*-1)+width*(yguy/16*-1);
      xp=0;
      yp=48;
      until(c >= ((xguy/16*-1)+width*(yguy/16*-1))+width*4) //loops until the y axis of the row is below the screen
      {
       until(c==d)
       {
        if(s == 1)
             goto end;
        var[0]=map[c].X;
        var[1]=map[c].Y;
        GraphicOutEx(xn+xp,yn+yp,"gmtilesb.ric",var);//draw a tile at the x axis of xn+xp, y axis of yn+yp
        //yn and xn are variables to make moving from tile to tile smoothly possible
       	xp+=16; //make the x axis of the next tile drawn 16 pixels to the right
       	c++;

       }
       //go to the next line
       yp-=16;
       xp=0;
       d+=width;
       c+=width-7;
			}
      done=1;
      Wait(20);
      end:
     }
}
Thanks, and have a nice day,
nxtboy III

programnxt.com
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC code help!!!!!

Post by afanofosc »

That's too much code for me to sort through. I would try fiddling around with some of those 16s to start with.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC code help!!!!!

Post by muntoo »

What problems are you having so far?
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: NXC code help!!!!!

Post by nxtboyiii »

The player currently moves 1 tile at a time, smoothly. I want it so it moves 1 pixel at a time, so if you press a direction it only moves 1 pixel total and not moving a tile.
Thanks, and have a nice day,
nxtboy III

programnxt.com
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC code help!!!!!

Post by mattallen37 »

~nxtboyiii: Didn't you program the game? You of all people should know how to do that.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests