Re: NXC code to NBC code
Posted: 13 Jun 2011, 12:20
by nxtboyiii
oh! thanks!
EDIT: Heres the RICS and sounds for games(attachment):
EDIT2: Here's the code for the game:
NOTE: All I did was convert the original pics from a mario website to black and white. The only ric I actually created was the boulder("T.ric"). I did not make any sounds.
For the gmtilesb.ric here is who-made-what(not updated yet!):
I need help making the for-loop at the end of task dostuff() run faster.
EDIT: Heres the RICS and sounds for games(attachment):
EDIT2: Here's the code for the game:
NOTE: All I did was convert the original pics from a mario website to black and white. The only ric I actually created was the boulder("T.ric"). I did not make any sounds.
For the gmtilesb.ric here is who-made-what(not updated yet!):
Code: Select all
stone-minecraft!!
bag of money and TNT- sidneys1 from mindboards.net
ladder- me
broken brick wall and brick wall- turiqwalrus from omnimaga.org
gravestone and both water sprites- Ashbad from omnimaga.org
fire- yunhua98 from omnimaga.org
stone wall- ZippyDee from omnimaga.org Â
I need help making the for-loop at the end of task dostuff() run faster.
Code: Select all
struct brk
{
byte x;
byte y;
bool sld;
// byte alv;
// char T;
};
#download "Platformer!!!!\gmtilesb.ric"
#download "Platformer!!!!\guy2.ric"
#download "Platformer!!!!\T.ric"
#download "Platformer!!!!\R.ric"
#download "Platformer!!!!\mjump2.rso"
#download "Platformer!!!!\ld.ric"
int EM;
const int MAXEM=15;
brk map[30][25];
float xxe[MAXEM];
float yye[MAXEM];
float fex[MAXEM];
float fey[MAXEM];
bool eli[MAXEM];
byte eat[MAXEM];
char sc[MAXEM];
int ex[MAXEM];
int ey[MAXEM];
int pex[MAXEM];
int pey[MAXEM];
int mex[MAXEM];
int mey[MAXEM];
string estr="";
float fmapx,fmapy;
int mapx,mapy;
bool gl;
int x,y;
byte paddx,paddy;
int px,py;
float xx;
float yy;
int xadd,yadd;
bool s,done,jumping;
int xpp,ypp;
byte height=11;
byte width=15;
byte var[2];
byte yj;
int life;
byte prx,pry,pw,ph;
byte vare[1];
byte gvar[1];
#define EPSILON 0.125 // Make this "as small as possible", and make sure it's a power of 2.
// Try 0.015625, but that may fail with larger numbers.
inline long myfloor(float x)
{
return(x + EPSILON);
}
bool OnTile(int pointx, int pointy, int paddx2, int paddy2, byte xtile, byte ytile)
{
return((map[pointx][pointy].x == xtile && map[pointx][pointy].y == ytile) || (map[pointx+paddx2][pointy+paddy2].x == xtile && map[pointx+paddx2][pointy+paddy2].y == ytile) || (map[pointx][pointy+paddy2].x == xtile && map[pointx][pointy+paddy2].y == ytile) || (map[pointx+paddx2][pointy].x == xtile && map[pointx+paddx2][pointy].y == ytile));
}
void Tile()
{
if(OnTile(mapx,mapy,paddx,paddy,16,16))
{
PlayToneEx(700,20,1,0);
life-=10;
}
if(map[mapx+paddx][mapy-1].sld == 3 || map[mapx][mapy-1].sld == 3 || map[mapx-1][mapy+paddy].sld == 3 || map[mapx-1][mapy].sld == 3 || map[mapx+1][mapy+paddy].sld == 3 || map[mapx+1][mapy].sld == 3)
{
life-=20;
for(int s=620; s < 700; s+=20)
{
PlayToneEx(s,10,Volume(),0);
Wait(20);
}
}
if(map[mapx][mapy].sld == 4 || map[mapx+paddx][mapy].sld == 4 || map[mapx][mapy+paddy].sld == 4 || map[mapx+paddx][mapy+paddy].sld == 4)
{
StopAllTasks();
}
if(OnTile(mapx,mapy,paddx,paddy,112,16))
{
//Display winning screen or go to next level
StopAllTasks();
}
}
bool OnTextTile(string text, char vars[], byte on)
{
char dat[3];
StrToByteArray(text,dat);
return(vars[on] == dat[0] && vars[on+1] == dat[1] && vars[on+2] == dat[2]);
}
bool OnETile(int xa,int ya,int pox,int poy)
{
return(map[pox][poy].x == xa && map[pox][poy].y == ya);
}
void DrawEMY()
{
for(int e=0; e < EM; e++)
{
if(map[mex[e]][mey[e]].sld >= 3 && eli[e])
{
if(map[mex[e]][mey[e]].sld == 3)
{
estr="T.ric";
}
if(map[mex[e]][mey[e]].sld == 4)
{
estr="R.ric";
}
GraphicOut(ex[e],ey[e],estr);
}
}
}
void amove(int xp,int yp)
{
s=0;
until(done);
xadd+=xp;
yadd+=yp;
s=1;
until(!done);
}
void LoadMap()
{
byte handle;
byte fsize=1500;
string hei="";
string wid="";
byte hon,won;
string line="";
byte data[300];
int ccx,ccy;
int con;
int eex,eey,eon;
char ch=' ';
OpenFileRead("mapt1.txt",fsize,handle);
ReadLnString(handle,hei);
height=StrToNum(hei);
ReadLnString(handle,wid);
width=StrToNum(wid);
ccy=height-1;
byte tmp[height];
ArrayInit(map,tmp,width);
for(int c=0; c < width; c++)
{
for(int d=0; d < height; d++)
{
map[c][d].x=16;
map[c][d].y=0;
map[c][d].sld=0;
}
}
eex=0;
eey=(height-1)*16;
until(hon == height)
{
ReadLnString(handle,line);
StrToByteArray(line,data);
until(won == width)
{
if(OnTextTile("SEK",data,con))
{
map[ccx][ccy].x=0;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=3;
xxe[eon]=ccx*100;
yye[eon]=ccy*100;
fex[eon]=ccx;
fey[eon]=ccy;
ex[eon]=eex;
ey[eon]=eey;
mex[eon]=ccx;
mey[eon]=ccy;
sc[eon]='N';
eli[eon]=1;
eat[eon]=3;
eon++;
EM++;
}
if(OnTextTile("ROK",data,con))
{
map[ccx][ccy].x=0;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=4;
xxe[eon]=ccx*100;
yye[eon]=ccy*100;
fex[eon]=ccx;
fey[eon]=ccy;
ex[eon]=eex;
ey[eon]=eey;
mex[eon]=ccx;
mey[eon]=ccy;
sc[eon]='N';
eli[eon]=1;
eat[eon]=4;
eon++;
EM++;
}
if(OnTextTile("BRK",data,con))
{
map[ccx][ccy].x=0;
map[ccx][ccy].y=0;
map[ccx][ccy].sld=1;
}
if(OnTextTile("LDR",data,con))
{
map[ccx][ccy].x=32;
map[ccx][ccy].y=16;
}
if(OnTextTile("STN",data,con))
{
map[ccx][ccy].x=96;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=1;
}
if(OnTextTile("FIR",data,con))
{
map[ccx][ccy].x=16;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=0;
}
if(OnTextTile("CSN",data,con))
{
map[ccx][ccy].x=96;
map[ccx][ccy].y=0;
map[ccx][ccy].sld=2;
}
if(OnTextTile("BBK",data,con))
{
map[ccx][ccy].x=32;
map[ccx][ccy].y=0;
map[ccx][ccy].sld=2;
}
if(OnTextTile("BLK",data,con))
{
map[ccx][ccy].x=48;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=0;
}
if(OnTextTile("TNT",data,con))
{
map[ccx][ccy].x=48;
map[ccx][ccy].y=0;
map[ccx][ccy].sld=2;
}
if(OnTextTile("GRV",data,con))
{
map[ccx][ccy].x=64;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=0;
}
if(OnTextTile("WTR",data,con))
{
map[ccx][ccy].x=80;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=0;
}
if(OnTextTile("WTP",data,con))
{
map[ccx][ccy].x=80;
map[ccx][ccy].y=0;
map[ccx][ccy].sld=0;
}
if(OnTextTile("END",data,con))
{
map[ccx][ccy].x=112;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=0;
}
if(OnTextTile("BAG",data,con))
{
map[ccx][ccy].x=112;
map[ccx][ccy].y=0;
map[ccx][ccy].sld=0;
}
if(OnTextTile("GRS",data,con))
{
map[ccx][ccy].x=128;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=2;
}
if(OnTextTile("DRT",data,con))
{
map[ccx][ccy].x=128;
map[ccx][ccy].y=0;
map[ccx][ccy].sld=2;
}
if(OnTextTile("LEV",data,con))
{
map[ccx][ccy].x=144;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=2;
}
if(OnTextTile("TRE",data,con))
{
map[ccx][ccy].x=144;
map[ccx][ccy].y=0;
map[ccx][ccy].sld=2;
}
if(OnTextTile("LAV",data,con))
{
map[ccx][ccy].x=160;
map[ccx][ccy].y=16;
map[ccx][ccy].sld=0;
}
if(OnTextTile("LAB",data,con))
{
map[ccx][ccy].x=160;
map[ccx][ccy].y=0;
map[ccx][ccy].sld=0;
}
con+=4;
won++;
ccx++;
eex+=16;
}
eex=0;
eey-=16;
ccx=0;
ccy--;
hon++;
won=0;
con=0;
}
CloseFile(handle);
}
task dostuff()
{
while(1)
{
if(SENSOR_2)
{
StopAllTasks();
}
if(fmapx == floor(fmapx))
{
paddx=0;
}
else
{
paddx=1;
}
if((ButtonPressed(BTNCENTER,0) && jumping == 0 && map[mapx][mapy+1].sld == 0 && map[mapx+paddx][mapy+1].sld == 0 && yj < 16) || (jumping == 1 && !OnTile(mapx,mapy,paddx,paddy,32,16)))
{
// until(!ButtonPressed(BTNCENTER,0));
if(gvar[0] == 0 && !OnTile(mapx,mapy,paddx,paddy,32,16))
{
gvar[0]=32;
}
if(gvar[0] == 16 && !OnTile(mapx,mapy,paddx,paddy,32,16))
{
gvar[0]=48;
}
if(!OnTile(mapx,mapy,paddx,paddy,32,16) && yj == 0)
{
PlayFileEx("mjump2.rso",Volume(),0);
}
yy+=25;
fmapy=yy/100;
if(yadd/-16 < height-4)
{
ypp+=-4;
}
else
{
y+=4;
ypp=0;
}
jumping=1;
yj+=4;
// amove(0,ypp);
}
if(yj >= 16)
{
jumping=0;
}
mapy=floor(fmapy);
mapx=floor(fmapx);
if(fmapy == floor(fmapy))
{
paddy=0;
}
else
{
paddy=1;
}
if(ButtonPressed(BTNLEFT,0))
{
if(jumping == 0)
{
gvar[0]=16;
}
}
if(ButtonPressed(BTNLEFT,0) && ((map[mapx-1][mapy].sld == 0 && map[mapx-1][mapy+paddy].sld == 0) || fmapx > floor(fmapx)))
{
xx-=25;
fmapx=xx/100;
if(x == 16)
{
xpp+=4;
}
else
{
x-=4;
xpp=0;
}
// amove(xpp,0);
}
mapy=floor(fmapy);
mapx=floor(fmapx);
if(fmapy == floor(fmapy))
{
paddy=0;
}
else
{
paddy=1;
}
if(ButtonPressed(BTNRIGHT,0))
{
if(jumping == 0)
{
gvar[0]=0;
}
}
if(ButtonPressed(BTNRIGHT,0) && map[mapx+1][mapy].sld == 0 && map[mapx+1][mapy+paddy].sld == 0)
{
if(jumping == 0)
{
gvar[0]=0;
}
xx+=25;
fmapx=xx/100;
if(xadd/-16 < width-6)
{
xpp+=-4;
}
else
{
x+=4;
xpp=0;
}
// amove(xpp,0);
}
mapy=floor(fmapy);
mapx=floor(fmapx);
if(fmapx == floor(fmapx))
{
paddx=0;
}
else
{
paddx=1;
}
if(SENSOR_1)
{
if(ButtonPressed(BTNEXIT,0))
{
px=0;
py=-1;
prx=x;
pry=y;
pw=2;
ph=5;
}
else if(ButtonPressed(BTNLEFT,0))
{
px=-1;
py=0;
prx=x;
pry=y;
pw=5;
ph=2;
}
else if(ButtonPressed(BTNRIGHT,0))
{
px=1;
py=0;
prx=x+11;
pry=y;
pw=5;
ph=2;
}
else if(ButtonPressed(BTNCENTER,0))
{
px=0;
py=1;
prx=x;
pry=y+11;
pw=2;
ph=5;
}
else
{
goto endp;
}
if(map[mapx+px][mapy+py].sld >= 2/* || map[mapx+px+paddx][mapy+py].sld == 2 || map[mapx+px][mapy+py+paddy].sld == 2 || map[mapx+px+paddx][mapy+py+paddy].sld == 2*/)
{
repeat(300)
{
RectOut(prx,pry,pw,ph,DRAW_OPT_FILL_SHAPE);
Wait(1);
}
if(map[mapx+px][mapy+py].sld >= 3)
{
if(map[mapx+px][mapy+py].sld == 3)
{
estr="T.ric";
}
for(vare[0]=16; vare[0] < 80; vare[0]+=16)
{
repeat(50)
{
//GraphicOutEx(xg,yl,"guy2.ric",varg);
GraphicOutEx(x+(px*16),y+(py*16),estr,vare);
Wait(1);
}
}
for(int e=0; e < EM; e++)
{
if(mex[e] == mapx+px && mey[e] == mapy+py)
{
eli[e]=0;
}
}
for(int c=mapx+px-1; c < mapx+px+2; c++)
{
for(int d=mapy+py-1; d < mapy+py+2; d++)
{
if(OnETile(0,0,c,d))
{
map[c][d].sld=1;
}
if(OnETile(32,0,c,d))
{
map[c][d].sld=2;
}
if(OnETile(16,0,c,d))
{
map[c][d].sld=0;
}
if(OnETile(48,16,c,d))
{
map[c][d].sld=0;
}
if(OnETile(64,0,c,d))
{
map[c][d].sld=0;
}
if(OnETile(16,16,c,d))
{
map[c][d].sld=0;
}
if(OnETile(192,16,c,d))
{
map[c][d].sld=0;
}
if(OnETile(48,0,c,d))
{
map[c][d].sld=2;
}
if(OnETile(32,16,c,d))
{
map[c][d].sld=0;
}
if(OnETile(64,16,c,d))
{
map[c][d].sld=0;
}
if(OnETile(80,16,c,d))
{
map[c][d].sld=0;
}
if(OnETile(80,0,c,d))
{
map[c][d].sld=0;
}
if(OnETile(96,16,c,d))
{
map[c][d].sld=1;
}
if(OnETile(96,0,c,d))
{
map[c][d].sld=2;
}
if(OnETile(112,0,c,d))
{
map[c][d].sld=0;
}
if(OnETile(112,16,c,d))
{
map[c][d].sld=0;
}
if(OnETile(128,0,c,d))
{
map[c][d].sld=2;
}
if(OnETile(128,16,c,d))
{
map[c][d].sld=2;
}
if(OnETile(144,0,c,d))
{
map[c][d].sld=2;
}
if(OnETile(144,16,c,d))
{
map[c][d].sld=2;
}
if(OnETile(160,16,c,d))
{
map[c][d].sld=0;
}
if(OnETile(160,0,c,d))
{
map[c][d].sld=0;
}
if(OnETile(176,16,c,d))
{
map[c][d].sld=0;
}
}
}
}
else
{
map[mapx+px][mapy+py].x=16;
map[mapx+px][mapy+py].y=0;
}
map[mapx+px][mapy+py].sld=0;
for(int e=0; e < EM; e++)
{
if(eli[e])
{
map[mex[e]][mey[e]].sld=eat[e];
}
}
}
}
endp:
if((jumping == 0 && (!OnTile(mapx,mapy,paddx,paddy,32,16) || (ButtonPressed(BTNEXIT,0) && OnTile(mapx,mapy,paddx,paddy,32,16)))) && ((map[mapx][mapy-1].sld == 0 && map[mapx+paddx][mapy-1].sld == 0) || fmapy > floor(fmapy)))
{
jumping=0;
yy-=25;
fmapy=yy/100;
if(y == 16)
{
ypp+=4;
}
else
{
y-=4;
ypp=0;
}
// amove(0,ypp);
}
if((map[mapx][mapy-1].sld >= 1 || map[mapx+paddx][mapy-1].sld >= 1 || OnTile(mapx,mapy,paddx,paddy,32,16)) && (paddy == 0 || OnTile(mapx,mapy,paddx,paddy,32,16)))
{
if(gvar[0] == 32)
{
gvar[0]=0;
}
if(gvar[0] == 48)
{
gvar[0]=16;
}
yj=0;
jumping=0;
}
Tile();
s=0;
mapy=floor(fmapy);
mapx=floor(fmapx);
for(int c=0; c < EM; c++)
{
ex[c]+=xpp;
ey[c]+=ypp;
if(map[mex[c]][mey[c]].sld >= 3 && ex[c] <= 60 && ex[c] >= -32 && ey[c] >= 0 && ((ey[c] <= 64 && eat[c] == 3) || (eat[c] == 4 && ey[c] <= 100)) && eli[c] == 1)
{
//eli[c]=map[mex[c]][mey[c]].sld;
if(map[mex[c]][mey[c]].sld == 3)
{
estr="T.ric";
}
if(map[mex[c]][mey[c]].sld == 4)
{
estr="R.ric";
}
if(fey[c] == floor(fey[c]))
{
pey[c]=0;
}
else
{
pey[c]=1;
}
if((mex[c] > mapx && map[mex[c]-1][mey[c]].sld == 0 && eat[c] != 4 && map[mex[c]-1][mey[c]+pey[c]].sld == 0 && sc[c] == 'N' && mex[c]-1 != mapx && mex[c]-1 != mapx+paddx) || sc[c] == 'L')
{
ex[c]-=4;
xxe[c]-=25;
fex[c]=xxe[c]/100;
sc[c]='L';
}
mex[c]=floor(fex[c]);
mey[c]=floor(fey[c]);
if(fey[c] == floor(fey[c]))
{
pey[c]=0;
}
else
{
pey[c]=1;
}
if((mex[c] < mapx && map[mex[c]+1][mey[c]].sld == 0 && eat[c] != 4 && map[mex[c]+1][mey[c]+pey[c]].sld == 0 && sc[c] == 'N' && mex[c]+1 != mapx) || sc[c] == 'R')
{
ex[c]+=4;
xxe[c]+=25;
fex[c]=xxe[c]/100;
sc[c]='R';
}
mex[c]=floor(fex[c]);
mey[c]=floor(fey[c]);
if(fex[c] == floor(fex[c]))
{
pex[c]=0;
}
else
{
pex[c]=1;
}
if((map[mex[c]][mey[c]-1].sld == 0 && map[mex[c]+pex[c]][mey[c]-1].sld == 0 && sc[c] == 'N' && ((mey[c]-1 != mapy && mey[c]-1 != mapy+paddy && eat[c] == 3) || eat[c] == 4)) || sc[c] == 'D')
{
ey[c]-=4;
yye[c]-=25;
fey[c]=yye[c]/100;
sc[c]='D';
}
mex[c]=floor(fex[c]);
mey[c]=floor(fey[c]);
if(fex[c] != floor(fex[c]) || fey[c] != floor(fey[c]))
{
map[mex[c]][mey[c]].sld=eat[c];
}
if(fex[c] == floor(fex[c]))
{
switch(sc[c])
{
case 'L':
map[mex[c]+1][mey[c]].sld=0;
map[mex[c]][mey[c]].sld=eat[c];
sc[c]='N';
break;
case 'R':
map[mex[c]-1][mey[c]].sld=0;
map[mex[c]][mey[c]].sld=eat[c];
sc[c]='N';
break;
}
}
if(fey[c] == floor(fey[c]))
{
switch(sc[c])
{
case 'U':
map[mex[c]][mey[c]-1].sld=0;
map[mex[c]][mey[c]].sld=eat[c];
sc[c]='N';
break;
case 'D':
map[mex[c]][mey[c]+1].sld=0;
map[mex[c]][mey[c]].sld=eat[c];
sc[c]='N';
break;
}
}
GraphicOut(ex[c],ey[c],estr);
if(eat[c] == 4 && (map[mex[c]][mey[c]-1].sld == 1 || map[mex[c]][mey[c]-1].sld == 2) && fey[c] == floor(fey[c]))
{
eli[c]=0;
map[mex[c]][mey[c]].sld=0;
}
// Yield();
}
}
until(done);
xadd+=xpp;
yadd+=ypp;
s=1;
until(!done);
xpp=0;
ypp=0;
}
}
task draw()
{
// Drawing stuff
DrawGraphicType dgArgs2;
DrawGraphicType dgArgs;
// This part IS necessary.
dgArgs.Filename = "gmtilesb.ric";
ArrayInit(dgArgs.Variables, 0, 2);
dgArgs.Options = 0;
dgArgs2.Filename = "guy2.ric";
ArrayInit(dgArgs2.Variables, 0, 1);
dgArgs2.Options = 0;
int cen,den;
while(1)
{
until(s);
done=0;
cen=ceil(xadd/-16)+6;
den=ceil(yadd/-16)+4;
for(int c=floor(xadd/-16); c < cen; c++)
{
dgArgs2.Location.X=x;
dgArgs2.Location.Y=y;
dgArgs2.Variables[0]=gvar[0];
SysDrawGraphic(dgArgs2);
for(int d=floor(yadd/-16); d < den; d++)
{
dgArgs.Location.X = (c << 4)+xadd;
dgArgs.Location.Y = (d << 4)+yadd;
dgArgs.Variables[0] = map[c][d].x;
dgArgs.Variables[1] = map[c][d].y;
SysDrawGraphic(dgArgs);
}
}
RectOut(96,0,4,64,DRAW_OPT_FILL_SHAPE | DRAW_OPT_CLEAR);
// DrawEMY();
done=1;
}
}
task main()
{
SetAbortFlag(BTNSTATE_NONE);
SetSensorTouch(S1);
SetSensorTouch(S2);
mapx=1;
mapy=1;
xx=100;
yy=100;
fmapx=1;
fmapy=1;
x=16;
y=16;
s=1;
GraphicOut(0,0,"ld.ric");
for(int c=0; c < width; c++)
{
for(int d=0; d < height; d++)
{
map[c][d].x=16;
map[c][d].y=0;
map[c][d].sld=0;
}
}
LoadMap();
life=300;
Precedes(draw,dostuff);
}