Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GameBoyFixVal.h>
- extern byte I_Block_0[4][4];
- extern byte I_Block_90[4][4];
- extern byte I_Block_180[4][4];
- extern byte I_Block_270[4][4];
- extern byte L_Block_0[4][4];
- extern byte L_Block_90[4][4];
- extern byte L_Block_180[4][4];
- extern byte L_Block_270[4][4];
- extern byte J_Block_0[4][4];
- extern byte J_Block_90[4][4];
- extern byte J_Block_180[4][4];
- extern byte J_Block_270[4][4];
- extern byte Z_Block_0[4][4];
- extern byte Z_Block_90[4][4];
- extern byte Z_Block_180[4][4];
- extern byte Z_Block_270[4][4];
- extern byte S_Block_0[4][4];
- extern byte S_Block_90[4][4];
- extern byte S_Block_180[4][4];
- extern byte S_Block_270[4][4];
- extern byte T_Block_0[4][4];
- extern byte T_Block_90[4][4];
- extern byte T_Block_180[4][4];
- extern byte T_Block_270[4][4];
- extern byte O_Block_0[4][4];
- extern byte O_Block_90[4][4];
- extern byte O_Block_180[4][4];
- extern byte O_Block_270[4][4];
- GameBoy gb;
- int x = 2, y = -1;
- int rot = 0;
- int acc = 1;
- int speed = 200;
- int score = 0;
- int level = 0;
- void setup() {
- gb.begin(8);
- randomSeed(analogRead(A5));
- createBlock(random(0, 7));
- }
- void drawBlock(byte arr[4][4], int x, int y) {
- for(int i = 0; i < 4; i++) {
- for(int j = 0; j < 4; j++) {
- if(arr[i][j] == 1) {
- gb.drawPoint(x + i, y + j);
- }
- }
- }
- }
- void createBlock(int num) {
- x = 2;
- y = -1;
- rot = random(0, 4);
- if(num == 0) gb.generateBlock(gb.block, I_Block_0, I_Block_90, I_Block_180, I_Block_270);
- if(num == 1) gb.generateBlock(gb.block, Z_Block_0, Z_Block_90, Z_Block_180, Z_Block_270);
- if(num == 2) gb.generateBlock(gb.block, S_Block_0, S_Block_90, S_Block_180, S_Block_270);
- if(num == 3) gb.generateBlock(gb.block, L_Block_0, L_Block_90, L_Block_180, L_Block_270);
- if(num == 4) gb.generateBlock(gb.block, J_Block_0, J_Block_90, J_Block_180, J_Block_270);
- if(num == 5) gb.generateBlock(gb.block, T_Block_0, T_Block_90, T_Block_180, T_Block_270);
- if(num == 6) gb.generateBlock(gb.block, O_Block_0, O_Block_90, O_Block_180, O_Block_270);
- }
- void makeMove(){
- if(gb.getKey() == 4) {
- if(!gb.checkBlockCollision(gb.block[rot], x - 1, y)) {
- x--;
- }
- }
- if(gb.getKey() == 5) {
- if(!gb.checkBlockCollision(gb.block[rot], x + 1, y)) {
- x++;
- }
- }
- if(gb.getKey() == 1) {
- if(!gb.checkBlockCollision(gb.block[rot + 1], x + 1, y)) {
- if(rot == 3) {
- rot = 0;
- }
- else {
- rot++;
- }
- }
- }
- if(gb.getKey() == 6) {
- acc = 4;
- }
- else {
- acc = 1;
- }
- }
- void loop() {
- makeMove();
- if(gb.checkBlockCollision(gb.block[rot], x, y + 1)) {
- gb.memBlock(gb.block[rot], x, y);
- int lines = gb.fullLine();
- if(lines != 0) {
- score += lines;
- level += lines;
- }
- if(level >= 4) {
- gb.sound(SCORE);
- acc += 1;
- level = 0;
- }
- createBlock(random(0, 7));
- }
- else {
- y++;
- }
- gb.drawDisplay();
- drawBlock(gb.block[rot], x, y);
- delay(speed / acc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement