Advertisement
Hirsw0w

asdsads

Oct 16th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Adafruit_FT6206.h>
  3. #include <Adafruit_ILI9341.h>
  4. #include <Adafruit_GFX.h>
  5.  
  6. /* Defines */
  7. #define TFT_CS 10
  8. #define TFT_DC 9
  9.  
  10. Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
  11.  
  12. extern uint8_t SmallFont[];
  13. extern uint8_t BigFont[];
  14. /*
  15.  
  16. short pageId = 0;
  17.  
  18. int buttons[MAX_BUTTONS][5];
  19. short bCount = 0;
  20. short startGameButton = -1;
  21. */
  22.  
  23. /* Global Vars */
  24. float last = 0;
  25. const float Pi = 3.14159;
  26. const int gameSpeed = 25;
  27.  
  28. enum sides {
  29. none,
  30. left,
  31. right
  32. };
  33.  
  34. /* Player Vars */
  35. bool ingame[4] {false,false,false,false};
  36. float x[4];
  37. float y[4];
  38. int omega[4] = {180,180,180,180};
  39. float theta[4] = {180,180,180,180};
  40. sides side[4];
  41.  
  42. void setup() {
  43. Serial.begin(9600);
  44. tft.begin();
  45. tft.fillScreen(ILI9341_BLACK);
  46. last = millis();
  47.  
  48. tft.fillRect(235,315,5,5,0xffff);
  49. //ingame[0] = true;
  50. x[0] = 50.0;
  51. y[0] = 50.0;
  52. }
  53.  
  54. void loop() {
  55. float mod = millis() - last;
  56. last = millis();
  57. mod /= 1000;
  58. for(byte i=0;i <4;i++) {
  59. if(ingame[i] != true)
  60. continue;
  61.  
  62. RenderPlayer(mod,i);
  63. if(side[i] != none) MovePlayer(side[i],mod,i);
  64. }
  65. if (Serial.available() > 0) {
  66.  
  67. // read the incoming byte:
  68. byte incomingByte = Serial.read();
  69. if(incomingByte == 'a'){
  70. if(side[0] == left) side[0] = none;
  71. else side[0] = left;
  72.  
  73. }
  74. else if(incomingByte == 'd') {
  75. if(side[0] == right) side[0] = none;
  76. else side[0] = right;
  77. }
  78. }
  79. delay(1000/gameSpeed);
  80. }
  81.  
  82. void MovePlayer(sides sidess,float mod,int id) {
  83. if(sidess == left)
  84. theta[id] = theta[id] - omega[id]*mod;
  85. else if(sidess == right)
  86. theta[id] = theta[id] + omega[id]*mod;
  87. }
  88.  
  89. void RenderPlayer(float mod,byte id) {
  90. tft.fillRect(x[id],y[id],1,1,0xffff);
  91.  
  92. x[id] += gameSpeed*cos(Pi*theta[id]/omega[id])*mod;
  93. y[id] += gameSpeed*sin(Pi*theta[id]/omega[id])*mod;
  94. }
  95.  
  96. void PrintText(int x,int y) {
  97. tft.setCursor(x,y);
  98. tft.setTextColor(ILI9341_WHITE);
  99. tft.setTextSize(3);
  100. tft.println("Blue Wins");
  101. }
  102.  
  103. /*
  104.  
  105. void drawHomeScreen() {
  106. pageId = 1;
  107. myGLCD.setBackColor(0,0,0);
  108. PrintText("CatchMe",CENTER, 10,255,255,255,BigFont);
  109. startGameButton = CreateButton("Start Game",25,25,100,50, 255,255,255 , 0,0,0);
  110. }
  111.  
  112. void PrintText(text[], x,y,r = 255,g = 255,b = 255, font[] = SmallFont) {
  113. myGLCD.setColor(r,g,b);
  114. myGLCD.setFont(font);
  115. myGLCD.print(text,x,y);
  116. }
  117.  
  118. short CreateButton(text[], x,y, width,height, boxr = 255, boxg = 255,boxb = 255, r = 255, g = 255, b = 255) {
  119. myGLCD.setColor(boxr, boxg, boxb);
  120. myGLCD.fillRoundRect (x, y, width, height);
  121. myGLCD.setFont(BigFont);
  122. myGLCD.setBackColor(r, g, b);
  123. myGLCD.print(text, x, y);
  124. buttons[bCount][0] = x;
  125. buttons[bCount][1] = y;
  126. buttons[bCount][2] = width;
  127. buttons[bCount][3] = height;
  128. buttons[bCount][4] = pageId;
  129. return bCount++;
  130. }
  131.  
  132. void loop() {
  133. if (myTouch.dataAvailable()) {
  134. myTouch.read();
  135. x=myTouch.getX(); // X coordinate where the screen has been pressed
  136. y=myTouch.getY(); // Y coordinates where the screen has been pressed
  137.  
  138. short pressedButton = -1;
  139. for(short i = 0;i < MAX_BUTTONS;i++) {
  140. if(buttons[i][4] != pageId)
  141. continue;
  142.  
  143. if(x >= buttons[i][0] && x <= (buttons[i][0] + buttons[i][2]) && y >= buttons[i][1] && y <= (buttons[i][1] + buttons[i][3])) {
  144. pressedButton = i;
  145. break;
  146. }
  147. }
  148.  
  149. switch(pressedButton) {
  150. case startGameButton: {
  151. // Start Game
  152. }
  153. }
  154. }
  155. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement