这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界» 论坛首页» 企业专区» Renesas» 基于RL78的俄罗斯方块

共9条 1/1 1 跳转至

基于RL78的俄罗斯方块

菜鸟
2013-05-11 01:52:40 打赏

对不起EEPW了!

上一次的RL78活动由于个人原因,未能及时上传资料抱歉,深感抱歉!

当时做了一下UCOS-ii的移植,这几天我RL78平台上做了一个游戏机,时间关系,只做了一个游戏,名字叫俄罗斯方块!

先看一下我的游戏机实物吧!















关键词: 游戏机 俄罗斯 方块 基于

菜鸟
2013-05-11 02:02:10 打赏
2楼

这里给出源代码:算法功能单元


#define Screen_Width 8

#define Screen_Heighth 16

#define Tetris_Width 4
#define Tetris_Heighth 4

#define TetrisTypeNum 7


//#define TETRIS_TEST


/*
0: --------------------------


.
.
.


n: --------------------------
*/




/*
--------->X
|
|
|
Y
*/




uchar TetrisLayout[Screen_Heighth*Screen_Width];
uchar TetrisImage[Screen_Heighth*Screen_Width];


uchar TempImage[Screen_Heighth*Screen_Width];




uchar leftcol[Tetris_Heighth];
uchar rightcol[Tetris_Heighth];
uchar buttomline[Tetris_Width];




bool CanL=false,CanR=false,CanD=false;


bool LbuttonDown=false,LbuttonUp=false;
bool RbuttonDown=false,RbuttonUp=false;
bool DbuttonDown=false,DbuttonUp=false;








typedef struct TetrisEntity
{
uchar type;
uchar revolve;


uchar posX;
uchar posY;


} TetrisEntity,*pTetrisEntity;




TetrisEntity CurrentTetris;
pTetrisEntity pCurrentTetris= null;




bool IsProducing = false;




enum TetrisType
{
I = 0,
O = 1,
J = 2,
L = 3,
Z = 4,
S = 5,
T = 6
};


uchar TetrisData_Backup_I[Tetris_Width*Tetris_Heighth*4] =
{
0,1,0,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,


0,0,0,0,
1,1,1,1,
0,0,0,0,
0,0,0,0,


0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,


0,0,0,0,
0,0,0,0,
1,1,1,1,
0,0,0,0
};
uchar TetrisData_I[Tetris_Width*Tetris_Heighth*4];




uchar TetrisData_Backup_O[Tetris_Width*Tetris_Heighth*4] =
{
0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,


0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,


0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,


0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0
};
uchar TetrisData_O[Tetris_Width*Tetris_Heighth*4];




uchar TetrisData_Backup_J[Tetris_Width*Tetris_Heighth*4] =
{
0,0,0,0,
0,0,1,0,
0,0,1,0,
0,1,1,0,


0,0,0,0,
1,0,0,0,
1,1,1,0,
0,0,0,0,


0,1,1,0,
0,1,0,0,
0,1,0,0,
0,0,0,0,


0,0,0,0,
0,1,1,1,
0,0,0,1,
0,0,0,0


};
uchar TetrisData_J[Tetris_Width*Tetris_Heighth*4];




uchar TetrisData_Backup_L[Tetris_Width*Tetris_Heighth*4] =
{
0,0,0,0,
0,1,0,0,
0,1,0,0,
0,1,1,0,


0,0,0,0,
1,1,1,0,
1,0,0,0,
0,0,0,0,


0,1,1,0,
0,0,1,0,
0,0,1,0,
0,0,0,0,


0,0,0,0,
0,0,0,1,
0,1,1,1,
0,0,0,0


};
uchar TetrisData_L[Tetris_Width*Tetris_Heighth*4];




uchar TetrisData_Backup_Z[Tetris_Width*Tetris_Heighth*4] =
{
0,0,0,0,
1,1,0,0,
0,1,1,0,
0,0,0,0,


0,0,1,0,
0,1,1,0,
0,1,0,0,
0,0,0,0,


0,0,0,0,
0,1,1,0,
0,0,1,1,
0,0,0,0,


0,0,0,0,
0,0,1,0,
0,1,1,0,
0,1,0,0


};
uchar TetrisData_Z[Tetris_Width*Tetris_Heighth*4];




uchar TetrisData_Backup_S[Tetris_Width*Tetris_Heighth*4] =
{
0,0,0,0,
0,0,1,1,
0,1,1,0,
0,0,0,0,


0,0,0,0,
0,1,0,0,
0,1,1,0,
0,0,1,0,


0,0,0,0,
0,1,1,0,
1,1,0,0,
0,0,0,0,


0,1,0,0,
0,1,1,0,
0,0,1,0,
0,0,0,0


};
uchar TetrisData_S[Tetris_Width*Tetris_Heighth*4];




uchar TetrisData_Backup_T[Tetris_Width*Tetris_Heighth*4] =
{
1,1,1,0,
0,1,0,0,
0,0,0,0,
0,0,0,0,


0,0,0,1,
0,0,1,1,
0,0,0,1,
0,0,0,0,


0,0,0,0,
0,0,0,0,
0,0,1,0,
0,1,1,1,


0,0,0,0,
1,0,0,0,
1,1,0,0,
1,0,0,0


};
uchar TetrisData_T[Tetris_Width*Tetris_Heighth*4];


uchar* pTetrisData_Backup[TetrisTypeNum] = {
TetrisData_Backup_I,TetrisData_Backup_O,
TetrisData_Backup_J,TetrisData_Backup_L,
TetrisData_Backup_Z,TetrisData_Backup_S,
TetrisData_Backup_T
};
uchar* pTetrisData[TetrisTypeNum] = {
TetrisData_I,TetrisData_O,
TetrisData_J,TetrisData_L,
TetrisData_Z,TetrisData_S,
TetrisData_T
};




void RestoreData(uchar* src,uchar* dst)
{
for(int i=0;i{
dst[i]=src[i];
}
}
void RestoreDataAll()
{
for(int j=0;j{
RestoreData(pTetrisData_Backup[j],pTetrisData[j]);
}
}



void CopyLayout(uchar* src,uchar* dst)
{
for(int i=0;i{
dst[i]=src[i];
}
}


void ClearLayout(uchar* image)
{
for(int i=0;i{
image[i]=0;
}
}


/*
void PrintLayout(const uchar* image)
{
for(int i=0;i{
printf("%c ",image[i]+48);
if(i%Screen_Width==(Screen_Width-1))
{
printf("\n\n");
}
}
}
*/


void FillLayout(uchar* image,const uchar* curTetrisData,uchar posX,uchar posY)
{
int startImageline = 0;
int startTetrisline = 0;
int fillnums = Tetris_Heighth;
if(posY>=(Tetris_Heighth-1))
{
startImageline=posY-(Tetris_Heighth-1);
}
else
{
startTetrisline=(Tetris_Heighth-1)-posY;
fillnums=Tetris_Heighth-startTetrisline;




}
for(int i=0;i{
for(int j=0;j{
if(curTetrisData[(startTetrisline+i)*Tetris_Width+j])
{
image[(startImageline+i)*Screen_Width+posX+j]=curTetrisData[(startTetrisline+i)*Tetris_Width+j];
}
}
}
}



bool VerifyMoveL(const uchar* curTetrisData,uchar posX,uchar posY)
{
int i=0;int j=0;
while(i{
for(j=0;j{
if(curTetrisData[j*Tetris_Width+i]!=0)
break;
}
if(j{
for(j=0;j{
leftcol[j]=curTetrisData[j*Tetris_Width+i];
}
break;
}
i++;
}


if((posX+i)==0)
{
return false;
}
uchar tempdata[Tetris_Heighth*Tetris_Width];


if(posX==0)
{
for(int tempx=0;tempx{
for(int tempy=0;tempy{
if(tempy!=(Tetris_Width-1))
tempdata[tempx*Tetris_Width+tempy]=curTetrisData[tempx*Tetris_Width+tempy+1];
else
tempdata[tempx*Tetris_Width+tempy]=0;
}
}
ClearLayout(TempImage);
FillLayout(TempImage,tempdata,0,posY);
return !VerifyMix(TempImage,TetrisLayout);
}
else
{
ClearLayout(TempImage);
FillLayout(TempImage,curTetrisData,posX-1,posY);
return !VerifyMix(TempImage,TetrisLayout);
}
}


bool VerifyMoveR(const uchar* curTetrisData,uchar posX,uchar posY)
{
int i=Tetris_Width;int j=0;


while(i!=0)
{
i--;
for(j=0;j{
if(curTetrisData[j*Tetris_Width+i]!=0)
break;
}
if(j{
for(j=0;j{
rightcol[j]=curTetrisData[j*Tetris_Width+i];
}
break;
}
}


if((posX+i)==(Screen_Width-1))
{
return false;
}




//if(posX==(Screen_Width-1)


uchar tempdata[Tetris_Heighth*Tetris_Width];


if(posX==(Screen_Width-1-(Tetris_Width-1)))
{
for(int tempx=0;tempx{
for(int tempy=0;tempy{
if(tempy!=0)
tempdata[tempx*Tetris_Width+tempy]=curTetrisData[tempx*Tetris_Width+tempy-1];
else
tempdata[tempx*Tetris_Width+tempy]=0;
}
}
ClearLayout(TempImage);
FillLayout(TempImage,tempdata,posX,posY);
return !VerifyMix(TempImage,TetrisLayout);
}
else
{
ClearLayout(TempImage);
FillLayout(TempImage,curTetrisData,posX+1,posY);
return !VerifyMix(TempImage,TetrisLayout);
}
}


bool VerifyMoveD(const uchar* curTetrisData,uchar posX,uchar posY)
{
int i=0;int j=Tetris_Heighth;
while(j!=0)
{
j--;
for(i=0;i{
if(curTetrisData[j*Tetris_Width+i]!=0)
break;
}
if(i{
for(i=0;i{
buttomline[i]=curTetrisData[j*Tetris_Width+i];
}
break;
}
}
if((posY-(Tetris_Heighth-1-j))==(Screen_Heighth-1))
{
return false;
}


uchar tempdata[Tetris_Heighth*Tetris_Width];


if(posY==(Screen_Heighth-1))
{
for(int tempx=0;tempx{
for(int tempy=0;tempy{
if(tempx!=0)
tempdata[tempx*Tetris_Width+tempy]=curTetrisData[(tempx-1)*Tetris_Width+tempy];
else
tempdata[tempx*Tetris_Width+tempy]=0;
}
}
ClearLayout(TempImage);
FillLayout(TempImage,tempdata,posX,posY);
return !VerifyMix(TempImage,TetrisLayout);
}
else
{
ClearLayout(TempImage);
FillLayout(TempImage,curTetrisData,posX,posY+1);
return !VerifyMix(TempImage,TetrisLayout);
}
}





高工
2013-05-11 10:03:13 打赏
3楼

这个有意思,光看这些不过瘾哦


院士
2013-05-11 10:48:03 打赏
4楼
这个还真挺有意思的。

菜鸟
2013-05-11 12:57:50 打赏
5楼

好玩!


专家
2013-05-11 15:25:44 打赏
6楼
俄罗斯方块 不错~!

高工
2013-05-16 15:21:28 打赏
7楼
给力。

菜鸟
2013-09-01 14:09:15 打赏
8楼

厉害


菜鸟
2013-12-17 20:35:02 打赏
9楼
大神啊,感觉板子都是自己制作的

共9条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]