Su 200943147
Dependencies: Gamepad N5110 mbed
Shape/Shape.cpp
- Committer:
- GS00
- Date:
- 2017-05-03
- Revision:
- 7:31dd8865cc44
- Parent:
- 6:e919a1fd1eed
- Child:
- 8:3899d883d329
File content as of revision 7:31dd8865cc44:
#include "Shape.h" Shape::Shape() { } void Shape::Init() { New=0; ShapePicker(); } void Shape::L_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=1; ShapeInit[l+3][k+1]=0; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=0; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=0; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=1; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::O_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=0; ShapeInit[l+3][k+1]=0; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=0; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=1; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=1; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::S_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=0; ShapeInit[l+3][k+1]=0; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=0; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=1; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=1; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=0; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::Z_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=0; ShapeInit[l+3][k+1]=0; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=1; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=0; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=1; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::I_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=1; ShapeInit[l+3][k+1]=0; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=0; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=0; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=0; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=1; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::J_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=0; ShapeInit[l+3][k+1]=1; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=0; ShapeInit[l+2][k+2]=0; ShapeInit[l+3][k+2]=1; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=1; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::T_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=0; ShapeInit[l+3][k+1]=0; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=1; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=1; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=0; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::Rotate(Gamepad &pad) { for(int i=1; i<84; i++) { for(int j=1; j<48; j++) { ArrayRotate[i-1][j-1]=ShapeInit[i][j]; } } int Temp; for (int i=0; i<2; i++) { for (int j=i; j<3-i; j++) { Temp=ArrayRotate[i][j]; ArrayRotate[i][j]=ArrayRotate[j][3-i]; ArrayRotate[j][3-i]=ArrayRotate[3-i][3-j]; ArrayRotate[3-i][3-j]=ArrayRotate[3-j][i]; ArrayRotate[3-j][i]=Temp; } } for(int i=1; i<5; i++) { for(int j=1; j<5; j++) { printf("%d\n",ArrayRotate[i][j]); } } printf("x=%d\n",x); printf("y=%d\n",y); if(pad.check_event(Gamepad::A_PRESSED) == true) { for(int i=0; i<84; i++) { for(int j=0; j<48; j++) { ShapeInit[i][j]=0; ShapeArray[i][j]=0; } } printf("x1=%d\n",x); printf("y1=%d\n",y); for(int i=0; i<83; i++) { for(int j=0; j<47; j++) { ShapeInit[i+1][j+1]=ArrayRotate[i][j]; } } printf("x2=%d\n",x); printf("y2=%d\n",y); } } void Shape::Update(Gamepad &pad) { int n=14; ShapeArray[x+n][y]=0; ShapeArray[x+1+n][y]=0; ShapeArray[x+2+n][y]=0; ShapeArray[x+3+n][y]=0; ShapeArray[x+4+n][y]=0; ShapeArray[x+5+n][y]=0; ShapeArray[x+n][y+1]=0; ShapeArray[x+5+n][y+1]=0; ShapeArray[x+n][y+2]=0; ShapeArray[x+5+n][y+2]=0; ShapeArray[x+n][y+3]=0; ShapeArray[x+5+n][y+3]=0; ShapeArray[x+n][y+4]=0; ShapeArray[x+5+n][y+4]=0; ShapeArray[x+1+n][y+1]=ShapeInit[l+1][k+1]; ShapeArray[x+2+n][y+1]=ShapeInit[l+2][k+1]; ShapeArray[x+3+n][y+1]=ShapeInit[l+3][k+1]; ShapeArray[x+4+n][y+1]=ShapeInit[l+4][k+1]; ShapeArray[x+1+n][y+2]=ShapeInit[l+1][k+2]; ShapeArray[x+2+n][y+2]=ShapeInit[l+2][k+2]; ShapeArray[x+3+n][y+2]=ShapeInit[l+3][k+2]; ShapeArray[x+4+n][y+2]=ShapeInit[l+4][k+2]; ShapeArray[x+1+n][y+3]=ShapeInit[l+1][k+3]; ShapeArray[x+2+n][y+3]=ShapeInit[l+2][k+3]; ShapeArray[x+3+n][y+3]=ShapeInit[l+3][k+3]; ShapeArray[x+4+n][y+3]=ShapeInit[l+4][k+3]; ShapeArray[x+1+n][y+4]=ShapeInit[l+1][k+4]; ShapeArray[x+2+n][y+4]=ShapeInit[l+2][k+4]; ShapeArray[x+3+n][y+4]=ShapeInit[l+3][k+4]; ShapeArray[x+4+n][y+4]=ShapeInit[l+4][k+4]; } void Shape::ShapePicker() { t=time(NULL); srand(t); if(New==0) { New=1; RandomNumber=rand()%7; } if(RandomNumber==0) { T_Shape(); RandomNumber=10; } else if(RandomNumber==1) { J_Shape(); RandomNumber=10; } else if(RandomNumber==2) { L_Shape(); RandomNumber=10; } else if(RandomNumber==3) { O_Shape(); RandomNumber=10; } else if(RandomNumber==4) { I_Shape(); RandomNumber=10; } else if(RandomNumber==5) { S_Shape(); RandomNumber=10; } else if(RandomNumber==6) { Z_Shape(); RandomNumber=10; } }