Advertisement
Hirsw0w

Untitled

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