NXC Talk spot :D

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
i-fixed-it-44
Posts: 106
Joined: 01 Oct 2010, 19:32
Location: The Dark Side Of The Moon
Contact:

NXC Talk spot :D

Post by i-fixed-it-44 »

This is a Topic restrictly for talk about NXC 8-)

Talk about your NXC programs,ideas,problems,and etc. ;)
Some projects are good others aren't,but everybody's a critic.
Vincent,On Lego.com known as MindstormsMonster
..::..:::I_Fixed_It_44:::..::..
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: NXC Talk spot :D

Post by nxtboyiii »

I am making a zombie game.
It is going well, but I don't know what else to add.
Please help.

Code: Select all

int x=50;
int y=50;
long t2;
long t3;
int life=500;
bool pr=1;
struct zombie
{
 int x;
 int y;
 long t;
 int lp;
 int life;
};
zombie z1;
zombie z2;
zombie z3;

bool move_torward_point(int &xin, int &yin, int xe, int ye, int waittime)
{
if(xin < xe)
xin++;
if(xin > xe)
xin--;
if(yin < ye)
yin++;
if(yin > ye)
yin--;
Wait(waittime);
return(xin == xe && yin == ye);
}
void Zombie(zombie &zomt)
{
  if(zomt.x == x && zomt.y == y)
  {
  PlayToneEx(Random(1000),30,Volume(),0);
  life--;
  }
  if(zomt.t >= zomt.lp)
  {
   move_torward_point(zomt.x,zomt.y,x,y,0);
   zomt.t=0;
   LineOut(zomt.x,zomt.y-1,zomt.x+10,zomt.y,DRAW_OPT_CLEAR);
  }
    GraphicOut(zomt.x,zomt.y,"zombie.ric");
    zomt.t++;
    PointOut(Random((zomt.x+10)- zomt.x)+zomt.x,zomt.y-1);
}

task coll()
{
while(1)
{
 if(pr)
 {
 if(SENSOR_1)
 {
 until(!SENSOR_1);
 PlayToneEx(600,200,Volume(),0);
 if(z1.x == x && z1.y == y)
 {
  z1.life--;
 }
  if(z2.x == x && z2.y == y)
 {
  z2.life--;
 }
  if(z3.x == x && z3.y == y)
 {
  z3.life--;
 }
 }
 if(z1.life <= 0)
 {
 PlayFileEx("EAH!.rso",Volume(),0);
  z1.x=Random(110--20)+-20;
  z1.x=Random(70--20)+-20;
  z1.life=3;
  ClearScreen();
 }
  if(z2.life <= 0)
 {
 PlayFileEx("EAH!.rso",Volume(),0);
  z2.x=Random(110--20)+-20;
  z2.x=Random(70--20)+-20;
  z2.life=3;
  ClearScreen();
 }
  if(z3.life <= 0)
 {
 PlayFileEx("EAH!.rso",Volume(),0);
  z3.x=Random(110--20)+-20;
  z3.x=Random(70--20)+-20;
  z3.life=3;
  ClearScreen();
 }
 }
}
}

task zombies()
{
while(1)
{
  if(pr)
  {
   Zombie(z1);
  Zombie(z2);
  Zombie(z3);
  }
}
}
task task1()
{
 while(1)
 {
   if(t2 >= 10)
   {
  if(ButtonPressed(BTNLEFT,0))
  {
  PlayToneEx(300,5,Volume(),0);
   x--;
  }
    if(ButtonPressed(BTNRIGHT,0))
  {
  PlayToneEx(200,5,Volume(),0);
   x++;
  }
    if(ButtonPressed(BTNEXIT,0))
  {
  PlayToneEx(100,5,Volume(),0);
   y--;
  }
    if(ButtonPressed(BTNCENTER,0))
  {
  PlayToneEx(400,5,Volume(),0);
   y++;
  }
      if(ButtonPressed(BTNCENTER,0) && ButtonPressed(BTNEXIT,0))
  {
   StopAllTasks();
  }
  t2=0;
  }
  if(life <= 0)
  {
  pr=0;
  Wait(1000);
   StopSound();
  PlayToneEx(400,1000,Volume(),0);
  Wait(1000);
  StopAllTasks();
  }
  if(t3 >= 10)
  {
//   PlayToneEx(300,20,Volume(),0);
   t3=0;
  }
  CircleOut(x,y,1);
  RectOut(x-2,y-2,4,4,DRAW_OPT_CLEAR);
  NumOut(0,0,life);
  RectOut(0,0,16,8,DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE);
  GraphicOut(0,0,"background.ric");
  t2++;
  t3++;
 }
}
task main()
{
 SetSensorTouch(S1);
 z1.lp=1;
 z2.lp=6;
 z3.lp=3;
 z1.life=3;
 z2.life=3;
 z3.life=3;
 SetAbortFlag(BTNSTATE_NONE);
 Precedes(task1,coll,zombies);
}
Thanks, and have a nice day,
nxtboy III

programnxt.com
i-fixed-it-44
Posts: 106
Joined: 01 Oct 2010, 19:32
Location: The Dark Side Of The Moon
Contact:

Re: NXC Talk spot :D

Post by i-fixed-it-44 »

nxtboyiii wrote:I am making a zombie game.
It is going well, but I don't know what else to add.
Please help.

Code: Select all

int x=50;
int y=50;
long t2;
long t3;
int life=500;
bool pr=1;
struct zombie
{
 int x;
 int y;
 long t;
 int lp;
 int life;
};
zombie z1;
zombie z2;
zombie z3;

bool move_torward_point(int &xin, int &yin, int xe, int ye, int waittime)
{
if(xin < xe)
xin++;
if(xin > xe)
xin--;
if(yin < ye)
yin++;
if(yin > ye)
yin--;
Wait(waittime);
return(xin == xe && yin == ye);
}
void Zombie(zombie &zomt)
{
  if(zomt.x == x && zomt.y == y)
  {
  PlayToneEx(Random(1000),30,Volume(),0);
  life--;
  }
  if(zomt.t >= zomt.lp)
  {
   move_torward_point(zomt.x,zomt.y,x,y,0);
   zomt.t=0;
   LineOut(zomt.x,zomt.y-1,zomt.x+10,zomt.y,DRAW_OPT_CLEAR);
  }
    GraphicOut(zomt.x,zomt.y,"zombie.ric");
    zomt.t++;
    PointOut(Random((zomt.x+10)- zomt.x)+zomt.x,zomt.y-1);
}

task coll()
{
while(1)
{
 if(pr)
 {
 if(SENSOR_1)
 {
 until(!SENSOR_1);
 PlayToneEx(600,200,Volume(),0);
 if(z1.x == x && z1.y == y)
 {
  z1.life--;
 }
  if(z2.x == x && z2.y == y)
 {
  z2.life--;
 }
  if(z3.x == x && z3.y == y)
 {
  z3.life--;
 }
 }
 if(z1.life <= 0)
 {
 PlayFileEx("EAH!.rso",Volume(),0);
  z1.x=Random(110--20)+-20;
  z1.x=Random(70--20)+-20;
  z1.life=3;
  ClearScreen();
 }
  if(z2.life <= 0)
 {
 PlayFileEx("EAH!.rso",Volume(),0);
  z2.x=Random(110--20)+-20;
  z2.x=Random(70--20)+-20;
  z2.life=3;
  ClearScreen();
 }
  if(z3.life <= 0)
 {
 PlayFileEx("EAH!.rso",Volume(),0);
  z3.x=Random(110--20)+-20;
  z3.x=Random(70--20)+-20;
  z3.life=3;
  ClearScreen();
 }
 }
}
}

task zombies()
{
while(1)
{
  if(pr)
  {
   Zombie(z1);
  Zombie(z2);
  Zombie(z3);
  }
}
}
task task1()
{
 while(1)
 {
   if(t2 >= 10)
   {
  if(ButtonPressed(BTNLEFT,0))
  {
  PlayToneEx(300,5,Volume(),0);
   x--;
  }
    if(ButtonPressed(BTNRIGHT,0))
  {
  PlayToneEx(200,5,Volume(),0);
   x++;
  }
    if(ButtonPressed(BTNEXIT,0))
  {
  PlayToneEx(100,5,Volume(),0);
   y--;
  }
    if(ButtonPressed(BTNCENTER,0))
  {
  PlayToneEx(400,5,Volume(),0);
   y++;
  }
      if(ButtonPressed(BTNCENTER,0) && ButtonPressed(BTNEXIT,0))
  {
   StopAllTasks();
  }
  t2=0;
  }
  if(life <= 0)
  {
  pr=0;
  Wait(1000);
   StopSound();
  PlayToneEx(400,1000,Volume(),0);
  Wait(1000);
  StopAllTasks();
  }
  if(t3 >= 10)
  {
//   PlayToneEx(300,20,Volume(),0);
   t3=0;
  }
  CircleOut(x,y,1);
  RectOut(x-2,y-2,4,4,DRAW_OPT_CLEAR);
  NumOut(0,0,life);
  RectOut(0,0,16,8,DRAW_OPT_CLEAR | DRAW_OPT_FILL_SHAPE);
  GraphicOut(0,0,"background.ric");
  t2++;
  t3++;
 }
}
task main()
{
 SetSensorTouch(S1);
 z1.lp=1;
 z2.lp=6;
 z3.lp=3;
 z1.life=3;
 z2.life=3;
 z3.life=3;
 SetAbortFlag(BTNSTATE_NONE);
 Precedes(task1,coll,zombies);
}
Looks full proof but whats the problem with it?
Some projects are good others aren't,but everybody's a critic.
Vincent,On Lego.com known as MindstormsMonster
..::..:::I_Fixed_It_44:::..::..
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: NXC Talk spot :D

Post by nxtboyiii »

There's not a problem, I just didn't know if I should add anything else. :)
Thanks, and have a nice day,
nxtboy III

programnxt.com
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests