api for drawing snake on a uVGA II
draw.cpp@1:2e528b145987, 2012-10-11 (annotated)
- Committer:
- lucoby
- Date:
- Thu Oct 11 20:23:28 2012 +0000
- Revision:
- 1:2e528b145987
- Parent:
- 0:06f3e47afa60
updated draw apple
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lucoby | 0:06f3e47afa60 | 1 | #include "mbed.h" |
lucoby | 0:06f3e47afa60 | 2 | #include "TFT_4DGL.h" |
lucoby | 0:06f3e47afa60 | 3 | #include "draw.h" |
lucoby | 0:06f3e47afa60 | 4 | |
lucoby | 0:06f3e47afa60 | 5 | |
lucoby | 0:06f3e47afa60 | 6 | TFT_4DGL ecran(p28,p27,p23); // serial tx, serial rx, reset pin; |
lucoby | 0:06f3e47afa60 | 7 | |
lucoby | 0:06f3e47afa60 | 8 | void drawSetup() { |
lucoby | 0:06f3e47afa60 | 9 | ecran.baudrate(115200); |
lucoby | 0:06f3e47afa60 | 10 | ecran.cls(); |
lucoby | 0:06f3e47afa60 | 11 | // added - Set Display to 640 by 480 mode |
lucoby | 0:06f3e47afa60 | 12 | ecran.display_control(0x0c, 0x01); |
lucoby | 0:06f3e47afa60 | 13 | // |
lucoby | 0:06f3e47afa60 | 14 | ecran.background_color(DGREY); |
lucoby | 0:06f3e47afa60 | 15 | } |
lucoby | 0:06f3e47afa60 | 16 | |
lucoby | 0:06f3e47afa60 | 17 | void clearscr() { |
lucoby | 0:06f3e47afa60 | 18 | ecran.cls(); |
lucoby | 0:06f3e47afa60 | 19 | } |
lucoby | 0:06f3e47afa60 | 20 | |
lucoby | 0:06f3e47afa60 | 21 | void drawPixel(int row, int col, int color) { |
lucoby | 0:06f3e47afa60 | 22 | ecran.rectangle(col*15+135, row*15+80, col*15+149, row*15+94, color); |
lucoby | 0:06f3e47afa60 | 23 | } |
lucoby | 0:06f3e47afa60 | 24 | |
lucoby | 0:06f3e47afa60 | 25 | void drawSnake(int row, int col) { |
lucoby | 0:06f3e47afa60 | 26 | drawPixel(row, col, 0x00FF00); |
lucoby | 0:06f3e47afa60 | 27 | } |
lucoby | 0:06f3e47afa60 | 28 | |
lucoby | 0:06f3e47afa60 | 29 | void drawApple(int row, int col) { |
lucoby | 1:2e528b145987 | 30 | //drawPixel(row, col, 0xFF0000); |
lucoby | 1:2e528b145987 | 31 | ecran.rectangle(col*15 + 138, row*15 + 85, col*15 + 145, row*15 + 91, RED); |
lucoby | 1:2e528b145987 | 32 | ecran.rectangle(col*15 + 137, row*15 + 87, col*15 + 146, row*15 + 89, RED); |
lucoby | 1:2e528b145987 | 33 | ecran.rectangle(col*15 + 139, row*15 + 92, col*15 + 144, row*15 + 92, RED); |
lucoby | 1:2e528b145987 | 34 | ecran.rectangle(col*15 + 137, row*15 + 84, col*15 + 143, row*15 + 84, GREEN); |
lucoby | 1:2e528b145987 | 35 | ecran.rectangle(col*15 + 141, row*15 + 83, col*15 + 146, row*15 + 83, GREEN); |
lucoby | 0:06f3e47afa60 | 36 | } |
lucoby | 0:06f3e47afa60 | 37 | |
lucoby | 0:06f3e47afa60 | 38 | void drawBlank(int row, int col) { |
lucoby | 0:06f3e47afa60 | 39 | drawPixel(row, col, DGREY); |
lucoby | 0:06f3e47afa60 | 40 | } |
lucoby | 0:06f3e47afa60 | 41 | |
lucoby | 0:06f3e47afa60 | 42 | void drawScore(int score) { |
lucoby | 1:2e528b145987 | 43 | char scr[15]; |
lucoby | 1:2e528b145987 | 44 | sprintf(scr, "Score: %d", score); |
lucoby | 1:2e528b145987 | 45 | ecran.text_string(scr, 285, 302, FONT_8X8, WHITE); |
lucoby | 0:06f3e47afa60 | 46 | } |