
Simple tetris game to show usage of C12832 LCD.
Diff: main.cpp
- Revision:
- 0:644f70b470b5
- Child:
- 1:cdd5880742fc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Mar 17 19:47:49 2014 +0000 @@ -0,0 +1,74 @@ +#include "mbed.h" +#include "C12832_lcd.h" +#include "mtrix.h" + +MBEDtrisTheGame<char> game; + +C12832_LCD lcd; +BusIn joy(p15,p12,p13,p16); +DigitalIn fire(p14); +BusOut leds(LED1,LED2,LED3,LED4); + +#define KEY_LEFT 2 +#define KEY_RIGHT 1 +#define KEY_UP 4 +#define KEY_DOWN 8 + +#define BOUNCER_SIZE 2 + +int main() +{ + // Welcome message + lcd.cls(); + + while(1) { + int joy_key = joy.read(); + switch (joy_key) { + case KEY_LEFT: { game.try_rotate(); break; } + case KEY_RIGHT: { game.try_move_right(); break; } + case KEY_UP: { game.try_rotate(); break; } + case KEY_DOWN: { game.move_brick_down(); break; } + } + + // PRINT MATRIX + for (int x = 0; x < LCD_W; x++) + { + for (int y = 0; y < LCD_H; y++) + { + // This should be replaces with just 'putpixel on LCD' + int draw_pix_x = x*BOUNCER_SIZE; + int draw_pix_y = y*BOUNCER_SIZE; + + if (game.get_matrix_cell(x, y)) + { + lcd.rect(draw_pix_x, draw_pix_y, draw_pix_x+BOUNCER_SIZE-1, draw_pix_y+BOUNCER_SIZE-1, 1); + } + else + { + lcd.rect(draw_pix_x, draw_pix_y, draw_pix_x+BOUNCER_SIZE-1, draw_pix_y+BOUNCER_SIZE-1, 0); + } + } + } + + // PRINT BRICK + for (int x = 0; x < BRICK_SIZE_X; x++) + { + for (int y = 0; y < BRICK_SIZE_Y; y++) + { + if (game.get_brick_cell(x, y)) + { + std::pair<int, int> brick_pos = game.get_brick_pos(); + + int draw_pix_x = (brick_pos.first + x) * BOUNCER_SIZE; + int draw_pix_y = (brick_pos.second + y) * BOUNCER_SIZE; + lcd.rect(draw_pix_x, draw_pix_y, draw_pix_x+BOUNCER_SIZE-1, draw_pix_y+BOUNCER_SIZE-1, 1); + } + } + } + + + lcd.copy_to_lcd(); + wait(1.0); + game.move_brick_down(); + } +}