Advertisement
mayorBanana

Untitled

May 4th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define LED_PIN 6
  4. #define WIDTH 16
  5. #define HEIGHT 16
  6. #define NUM_LEDS (WIDTH * HEIGHT)
  7. CRGB leds[NUM_LEDS];
  8.  
  9. // https://pastebin.com/M3wi3ctj
  10. int index(int x, int y) {
  11. if (y % 2 == 0)
  12. return y * WIDTH + WIDTH - x - 1;
  13. else
  14. return y * WIDTH + x;
  15. }
  16.  
  17. float bail_x = 0;
  18. float bail_y = 0;
  19.  
  20. float bail_vx = 0;
  21. float bail_vy = 0;
  22.  
  23. int player_1 = 0;
  24. int player_2 = 0;
  25. int score_1 = 0;
  26. int score_2 = 0;
  27.  
  28.  
  29. int MAX_BR = 255;
  30. int X_pos = 1;
  31. int X_pos_2 = WIDTH - 2;
  32. int palca = 3;
  33.  
  34. #define rezistor_1 A0
  35. #define rezistor_2 A1
  36.  
  37. void setup() {
  38. Serial.begin(115200);
  39. FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
  40. FastLED.setBrightness(50);
  41. pinMode(rezistor_1, INPUT);
  42. pinMode(rezistor_2, INPUT);
  43. bail_x = WIDTH / 2;
  44. bail_y = HEIGHT / 2;
  45. bail_vx = 0.05;
  46. bail_vy = 0.05;
  47. }
  48.  
  49. void loop() {
  50. player_1 = map(analogRead(rezistor_1), 0, 1023, 0, HEIGHT - palca + 1);
  51. player_2 = map(analogRead(rezistor_2), 0, 1023, 0, HEIGHT - palca + 1);
  52.  
  53. float bail_x_new = bail_x + bail_vx;
  54. float bail_y_new = bail_y + bail_vy;
  55. if (bail_y_new < 0 || bail_y_new >= HEIGHT) {
  56. bail_vy = -bail_vy;
  57. bail_y_new = bail_y + bail_vy;
  58. }
  59. if (bail_x_new < 0){
  60. score_2 = score_2 + 1;
  61. bail_x_new = X_pos + 1;
  62. bail_y_new = player_1 + palca / 2.0;
  63. bail_vx = 0.02;
  64. bail_vy = 0;
  65. }
  66. if (bail_x_new >= WIDTH){
  67. score_1 = score_1 + 1;
  68. bail_x_new = X_pos_2 - 1;
  69. bail_y_new = player_2 + palca / 2.0;
  70. bail_vx = -0.02;
  71. bail_vy = 0;
  72. }
  73. bail_x = bail_x_new;
  74. bail_y = bail_y_new;
  75.  
  76. for (int i = 0; i < palca; i++) {
  77. leds[index(X_pos, i + player_1)].setRGB(0, 0, MAX_BR);
  78. leds[index(X_pos_2, i + player_2)].setRGB(MAX_BR, 0, 0);
  79. }
  80.  
  81. leds[index(bail_x, bail_y)].setRGB(MAX_BR, MAX_BR, MAX_BR);
  82. FastLED.show();
  83.  
  84. for (int i = 0; i < palca; i++) {
  85. leds[index(X_pos, i + player_1)].setRGB(0, 0, 0);
  86. leds[index(X_pos_2, i + player_2)].setRGB(0, 0, 0);
  87. }
  88.  
  89.  
  90. leds[index(bail_x, bail_y)].setRGB(0, 0, 0);
  91. delay(10);
  92.  
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement