This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/MCU/MCU_REAL _FINAL/block.c

109 lines
No EOL
1.8 KiB
C

#include "block.h"
#include "draw.h"
Group piece;
unsigned char regenPieceFlag = 0;
unsigned char base[8][11]={0}; //x*y
void blockInit()
{
base[0][0]=1;
base[0][1]=1;
base[0][2]=1;
// genPiece();
}
void blockDestroy()
{
piece.type=none;
}
void genPiece()
{
//需要一点随机性
int random = rand() % 4;
int len = 2 + rand() % 3;
piece.mother.x=4;
piece.mother.y=8;
//当两个方块的情况
if(len == 2)
{
if(random % 2 == 0)
{
piece.type = two_v; //
} //
else
{
piece.type = two_h; ////
}
}
//当三个方块的情况
if(len == 3)
{
if(random == 0)
{
//
piece.type = three_h; //
//
}
else if(random == 1)
{
piece.type = three_v; //////
}
else if(random == 2)
{
//
piece.type = three_l; ////
}
else if (random == 3)
{
piece.type = three_r; //
} ////
}
//当四个方块的情况
if(len == 3)
{
piece.type = four; ////
} ////
}
void dropPiece()
{
piece.mother.y--;
// int i;
// for(i = 0; i < len; i++)
// {
// //触底或下有base方块
// if(piece.list[i].x == 0 || base[piece.list[i].x][piece.list[i].y - 1] == 1)
// {
// for(i = 0; i < len;i++)
// {
// //全部方块转移到base
// base[piece.list[i].x][piece.list[i].y] == 1;
// }
// //重新生成
// genPiece();
// return;
// }
// else
// //正常下落
// piece.list[i].y--;
// }
}
void drawBlock()
{
int i,j;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
if(base[i][j]==1)
placeIMG_BLOCK(i,j);
placeIMG_BLOCK(piece.mother.x,piece.mother.y);
}