Advertisement
pleasedontcode

"Block Control" rev_01

Mar 6th, 2025
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Block Control"
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2025-03-06 09:38:41
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* code should let block reach edges when roatated, */
  21.     /* should display score when game ends and when a row */
  22.     /* is complete it should be deleted and everything */
  23.     /* else moved down */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs();
  35. void rotateBlock();
  36. void checkForCompleteRows();
  37. void displayScore();
  38.  
  39. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  40. const uint8_t buttonleft_PushButton_PIN_D2      = 2;
  41. const uint8_t buttonright_PushButton_PIN_D3     = 3;
  42. const uint8_t buttonrotate_PushButton_PIN_D4        = 4;
  43.  
  44. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  45. const uint8_t myLED_LED_PIN_D5      = 5;
  46.  
  47. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  48. /***** used to store raw data *****/
  49. bool    myLED_LED_PIN_D5_rawData        = 0;
  50.  
  51. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  52. /***** used to store data after characteristic curve transformation *****/
  53. float   myLED_LED_PIN_D5_phyData        = 0.0;
  54.  
  55. /****** DEFINITION OF GAME VARIABLES *****/
  56. int score = 0; // Variable to keep track of the score
  57. bool block[4][4]; // 2D array to represent the block (4x4 for simplicity)
  58.  
  59. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  60. // Instantiate EasyButton objects
  61. EasyButton buttonLeft(buttonleft_PushButton_PIN_D2);
  62. EasyButton buttonRight(buttonright_PushButton_PIN_D3);
  63. EasyButton buttonRotate(buttonrotate_PushButton_PIN_D4);
  64.  
  65. void setup(void)
  66. {
  67.     // put your setup code here, to run once:
  68.     pinMode(myLED_LED_PIN_D5, OUTPUT);
  69.  
  70.     // Initialize buttons
  71.     buttonLeft.begin();
  72.     buttonRight.begin();
  73.     buttonRotate.begin();
  74.  
  75.     // Attach button press events
  76.     buttonLeft.onPressed([]() { /* Move block left */ });
  77.     buttonRight.onPressed([]() { /* Move block right */ });
  78.     buttonRotate.onPressed(rotateBlock); // Rotate block on button press
  79. }
  80.  
  81. void loop(void)
  82. {
  83.     // put your main code here, to run repeatedly:
  84.     buttonLeft.read();
  85.     buttonRight.read();
  86.     buttonRotate.read();
  87.  
  88.     updateOutputs(); // Refresh output data
  89.     checkForCompleteRows(); // Check for completed rows
  90. }
  91.  
  92. void updateOutputs()
  93. {
  94.     digitalWrite(myLED_LED_PIN_D5, myLED_LED_PIN_D5_rawData);
  95. }
  96.  
  97. void rotateBlock()
  98. {
  99.     // Logic to rotate the block
  100.     // Ensure block can reach edges when rotated
  101.     // Implement rotation logic here
  102. }
  103.  
  104. void checkForCompleteRows()
  105. {
  106.     // Logic to check for complete rows
  107.     // If a row is complete, delete it and move everything down
  108.     // Update score accordingly
  109. }
  110.  
  111. void displayScore()
  112. {
  113.     // Logic to display the score when the game ends
  114. }
  115.  
  116. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement