Library to calculate movement and to draw the objects in the pong game

Dependencies:   RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed

Fork of MainSketch by IoT Ox

Committer:
tunagonen
Date:
Wed May 24 15:18:13 2017 +0000
Revision:
11:d812de0e5136
Parent:
9:eee503060d69
l

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mlin 9:eee503060d69 1 #include "libs.h"
mlin 9:eee503060d69 2 int f_state, f_button;
mlin 9:eee503060d69 3 bool f_alarm;
mlin 8:b9aa9fdf286b 4 DigitalIn sw_w(SW3);
cstevens 6:18c7288b5e00 5
mlin 9:eee503060d69 6 void main()
dreschpe 0:7c3b9bfd6ead 7 {
mlin 8:b9aa9fdf286b 8 // pc.baud(115200);
cstevens 7:c2bc477a07da 9 int color=0;
cstevens 7:c2bc477a07da 10 int xpos=0,ypos=0,xp=0,yp=0,sw=0;;
mlin 8:b9aa9fdf286b 11 //pwr=1;
pegcjs 3:676adf84c914 12 wait(0.2);
cstevens 6:18c7288b5e00 13
dreschpe 0:7c3b9bfd6ead 14 int i;
mlin 8:b9aa9fdf286b 15 //LCD_LED = 1; // backlight on
cstevens 6:18c7288b5e00 16
dreschpe 0:7c3b9bfd6ead 17 TFT.claim(stdout); // send stdout to the TFT display
dreschpe 0:7c3b9bfd6ead 18 TFT.set_orientation(1);
dreschpe 0:7c3b9bfd6ead 19 TFT.background(Black); // set background to black
dreschpe 0:7c3b9bfd6ead 20 TFT.foreground(White); // set chars to white
dreschpe 0:7c3b9bfd6ead 21 TFT.cls(); // clear the screen
dreschpe 0:7c3b9bfd6ead 22
mlin 9:eee503060d69 23
dreschpe 0:7c3b9bfd6ead 24 TFT.set_font((unsigned char*) Arial12x12);
cstevens 7:c2bc477a07da 25 drawbuttons();
cstevens 6:18c7288b5e00 26 while(1==1) {
mlin 9:eee503060d69 27
mlin 9:eee503060d69 28 xp=readX();
mlin 9:eee503060d69 29 yp=readY();
cstevens 7:c2bc477a07da 30 // top chunk of the screen is the button area //
cstevens 7:c2bc477a07da 31 // 0<y<50 is palette area //
cstevens 7:c2bc477a07da 32
cstevens 7:c2bc477a07da 33 //pc.printf("xpos=%d\t,\typo=%d",xpos,ypos);
mlin 9:eee503060d69 34 // xp=(240*(xpos-5800))/51200;
mlin 9:eee503060d69 35 // yp=320-(320*(ypos-3000))/58300;
cstevens 7:c2bc477a07da 36 if(touching==1) pc.printf("\txp=%d\t,\typo=%d\n\r",xp,yp);
mlin 9:eee503060d69 37 if(xp>5 && yp>50 && touching==1) TFT.fillcircle(yp,xp,2,color);
cstevens 7:c2bc477a07da 38 if(yp<50) { // color buttons
cstevens 7:c2bc477a07da 39 sw=(int)xp/50;
cstevens 7:c2bc477a07da 40 switch(sw) {
cstevens 7:c2bc477a07da 41 case 0:
cstevens 7:c2bc477a07da 42 color=0xf800;
cstevens 7:c2bc477a07da 43 break;
cstevens 7:c2bc477a07da 44 case 1:
cstevens 7:c2bc477a07da 45 color=0x07e0;
cstevens 7:c2bc477a07da 46 break;
cstevens 7:c2bc477a07da 47 case 2:
cstevens 7:c2bc477a07da 48 color=0x001f;
cstevens 7:c2bc477a07da 49 break;
cstevens 7:c2bc477a07da 50 case 3:
cstevens 7:c2bc477a07da 51 color=0xffff;
cstevens 7:c2bc477a07da 52 break;
cstevens 7:c2bc477a07da 53 case 4:
cstevens 7:c2bc477a07da 54 color=0x0000;
cstevens 7:c2bc477a07da 55 TFT.cls();
cstevens 7:c2bc477a07da 56 drawbuttons();
cstevens 7:c2bc477a07da 57 break;
cstevens 7:c2bc477a07da 58 }
cstevens 7:c2bc477a07da 59 // if(xp<50) color=0xF800;
cstevens 7:c2bc477a07da 60 // if(50<xp && xp<100) color=0x07e0;
cstevens 7:c2bc477a07da 61 // if(xp>100 && xp<150) color=0x001f;
cstevens 7:c2bc477a07da 62 }
cstevens 7:c2bc477a07da 63
mlin 9:eee503060d69 64 wait(0.01);
cstevens 6:18c7288b5e00 65
pegcjs 1:e0479f60cd48 66 }
cstevens 6:18c7288b5e00 67
dreschpe 0:7c3b9bfd6ead 68 }