欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
基于LPC1768的俄羅斯方塊源代碼,配合3.2寸TFT屏幕
[打印本頁(yè)]
作者:
途觀
時(shí)間:
2018-5-7 20:48
標(biāo)題:
基于LPC1768的俄羅斯方塊源代碼,配合3.2寸TFT屏幕
程序運(yùn)行后,用板子上的五向按鍵控制。
單片機(jī)源程序如下:
#include <stdlib.h>
#include <stdint.h>
#include "lcd_api.h"
#include "ili_lcd_general.h"
#include "LPC17xx.h"
typedef struct //方塊結(jié)構(gòu)體,包括類(lèi)型,狀態(tài),坐標(biāo),顏色
{
uint8_t type; //方塊的類(lèi)型(LJITOSZ)
uint8_t state; //方塊的狀態(tài)(0、90、180、270°旋轉(zhuǎn))
int16_t x,y; //方塊的坐標(biāo)
uint8_t colorType; //顏色類(lèi)型
}BOX;
const uint8_t box[56]= //方塊數(shù)組,包括七種方塊,每種四種狀態(tài)
{
0x80,0x0e,0x46,0x04,0x70,0x01,0x20,0x62,/*J*/
0x20,0x0e,0x44,0x06,0x70,0x04,0x60,0x22,/*L*/
0x60,0x0c,0x64,0x02,0x30,0x06,0x40,0x26,/*s*/
0xc0,0x06,0x62,0x04,0x60,0x03,0x20,0x46,/*z*/
0x40,0x0e,0x64,0x04,0x70,0x02,0x20,0x26,/*T*/
0x44,0x44,0xf0,0x00,0x22,0x22,0x00,0x0f,/*I*/
0xc0,0x0c,0x66,0x00,0x30,0x03,0x00,0x66,/*O*/
};
uint8_t map[10][20]; //地圖數(shù)組,包括二十行十列,存方塊的顏色類(lèi)型
const int colors[]={0,Blue,Red,Magenta,Green,Yellow}; //顏色數(shù)組,聲明要用到的顏色
BOX this,next; // 定義兩個(gè)結(jié)構(gòu)變量,當(dāng)前方塊和下個(gè)方塊
uint16_t score=0; //全局變量總分
uint8_t toButtom,downTimes; //標(biāo)記是否落到底
void mapInit(){ //初始化地圖
lcd_Initializtion();
DrawYLine(161,0,319,Red);
WriteChineseString(176,32,0,3,White,Black);
WriteChineseString(176,160,3,3,White,Black);
WriteEnglishString(176,192,"00000",White,Black);
}
void showScore(){ //顯示總分函數(shù)
WriteEnglishWord(176,192,score/10000+48,White,Black);
WriteEnglishWord(184,192,(score/1000)%10+48,White,Black);
WriteEnglishWord(192,192,(score/100)%10+48,White,Black);
WriteEnglishWord(200,192,(score/10)%10+48,White,Black);
WriteEnglishWord(208,192,score%10+48,White,Black);
}
void delay(uint8_t k){ //延時(shí)函數(shù)
int i,j;
for(j=0;j<k;j++){
for(i=0;i<900000;i++);
}
}
void disBox(BOX b){ //顯示方塊函數(shù),參數(shù)是一個(gè)BOX
uint8_t i,j,k,l;
i=b.type*8+b.state*2;
l=box[i];
for(j=0;j<2;j++){
for(k=0;k<4;k++){
if(l&0x01){
DrawBox(b.x+k,b.y+j,colors[b.colorType]);
if(b.x!=11){
map[b.x+k][b.y+j]=b.colorType;
}
}
l>>=1;
}
}
l=box[i+1];
for(j=0;j<2;j++){
for(k=0;k<4;k++){
if(l&0x01){
DrawBox(b.x+k,b.y+j+2,colors[b.colorType]);
if(b.x!=11){
map[b.x+k][b.y+j+2]=b.colorType;
}
}
l>>=1;
}
}
}
void clearBox(){ //清除方塊函數(shù)
uint8_t i,j,k,l;
i=this.type*8+this.state*2;
l=box[i];
for(j=0;j<2;j++){
for(k=0;k<4;k++){
if(l&0x01){
CoverBox(this.x+k,this.y+j);
map[this.x+k][this.y+j]=0;
}
l>>=1;
}
}
l=box[i+1];
for(j=0;j<2;j++){
for(k=0;k<4;k++){
if(l&0x01){
CoverBox(this.x+k,this.y+j+2);
map[this.x+k][this.y+j+2]=0;
}
l>>=1;
}
}
}
void clearNext(){ //清除下一個(gè)函數(shù)
uint8_t x,y;
for(x=11;x<15;x++){
for(y=5;y<9;y++){
CoverBox(x,y);
}
}
}
void createNext(){ //創(chuàng)建下一個(gè)函數(shù)
clearNext();
next.x=11;
next.y=5;
next.colorType=rand()%5+1; //隨機(jī)顏色
next.type=rand()%7; //隨機(jī)種類(lèi)
next.state=rand()%4; //隨機(jī)狀態(tài)
disBox(next);
}
int16_t checkCrack(){ //檢測(cè)是否碰撞
uint8_t isCrack = 0;
uint8_t i,j,k,l;
int16_t x,y;
i=this.type*8+this.state*2;
l=box[i];
for(j=0;j<2;j++){
for(k=0;k<4;k++){
if(l&0x01){
x=this.x+k;
y=this.y+j;
if(x<0||x>9||y>19||map[x][y]!=0){ // 方塊越過(guò)邊界或者已經(jīng)被占即為已碰撞
isCrack = 1;
break;
}
}
l>>=1;
}
}
if(!isCrack){
l=box[i+1];
for(j=0;j<2;j++){
for(k=0;k<4;k++){
if(l&0x01){
x=this.x+k;
y=this.y+j+2;
if(x<0||x>9||y>19||map[x][y]!=0){
isCrack = 1;
break;
}
}
l>>=1;
}
}
}
return isCrack;
}
void putIntoMap(){ //把方塊放入地圖
this=next;
this.x=3;
this.y=0;
}
void moveLeft(){ //向左移動(dòng)
clearBox();
this.x--;
if(checkCrack()){
this.x++;
}
disBox(this);
}
void moveRight(){ //向右移動(dòng)
clearBox();
this.x++;
if(checkCrack()){
this.x--;
}
disBox(this);
}
void refreshMap(){ //刷新地圖
uint8_t i,j;
FillRect(0,0,159,319,Black);
for(i=0;i<20;i++){
for(j=0;j<10;j++){
if(map[j][i]!=0){
DrawBox(j,i,colors[map[j][i]]);
}
}
}
}
void checkMap(){ //檢查是否需要消行
int8_t i,j,k;
for(i=19;i>=0;i--){
k=0;
for(j=0;j<10;j++){
if(map[j][i]!=0){
k++;
}
}
if(k==10){ //如果一行上全部被占位即為需要消行
score++;
showScore();
for(j=i;j>0;j--){
for(k=0;k<10;k++){
map[k][j]=map[k][j-1];
}
}
for(k=0;k<10;k++){
map[k][0]=0;
}
i++;
refreshMap();
}
}
}
void moveDown(){ //下移方塊
clearBox();
this.y++;
if(checkCrack()){
toButtom = 1;
this.y--;
disBox(this);
checkMap();
}else{
disBox(this);
}
downTimes=0;
}
void moveTurn(){ //翻轉(zhuǎn)方塊
clearBox();
this.state=(++this.state)%4;
if(checkCrack()){
this.state=(--this.state)%4;
}
disBox(this);
delay(5);
}
void showMap(){ //顯示地圖函數(shù)
uint16_t key;
createNext();
while(1){
putIntoMap();
createNext();
if(!checkCrack()){
disBox(this);
}else{
WriteEnglishString(50,150,"GAME OVER!",White,Black);
break;
}
while(1){
key = ((LPC_GPIO1->FIOPIN >> 26)&0x0f);
switch(key){
case 0x07: //上
moveTurn();
break;
case 0x0e: //下
moveDown();
break;
……………………
…………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
【02】寶馬1768_LCD俄羅斯方塊(2014.05.28).rar
(96.9 KB, 下載次數(shù): 31)
2018-5-7 20:45 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
zy說(shuō)你好
時(shí)間:
2019-4-9 14:09
打開(kāi)程序怎么在keil中不能運(yùn)行啊
作者:
hxf520
時(shí)間:
2019-4-11 18:00
頂一下
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1