Advertisement
LeventeDaradici

Arduino Game on TV - Plane

Jul 5th, 2023 (edited)
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.51 KB | Source Code | 0 0
  1. //
  2. // https://youtu.be/oyisl88HAxE
  3. // https://www.youtube.com/@LeventeDaradici/videos
  4. // This file belongs to code called ARDUINO GAME ON TV - PLANE
  5. // file name: PlaneTvOUT.ino
  6. //
  7. #include <TVout.h>
  8. #include <fontALL.h>
  9. #include "plane.h"
  10. #include "plane4.h"
  11. #include "cloud.h"
  12. #include "level1.h"
  13. #include "level2.h"
  14. #include "level3.h"
  15. #include "level4.h"
  16. #include "level5.h"
  17. #include "level6.h"
  18. #include "level7.h"
  19. #include "level8.h"
  20. #include "level9.h"
  21. #include "level10.h"
  22. #include "planelogo.h"
  23. #include "arduinologo.h"
  24. #include "youwin.h"
  25. #include "yourlose.h"
  26. #include "explozie.h"
  27.  
  28. int Up = 5;
  29. int Down = 2;
  30. int Left = 4;
  31. int Right = 3;
  32. int Push = 6;
  33. int Start = 8;
  34.  
  35. int PlaneX =0;
  36. int PlaneY = 20;
  37.  
  38. int CloudX =80;
  39. int CloudY = 66;
  40.  
  41. int Cloud2X =80;
  42. int Cloud2Y = 66;
  43.  
  44. int RezX = 0;
  45. int RezY = 50;
  46.  
  47. int VitezaNori = 1;
  48. int Nivel = 1;
  49. int NumaratoareNivel = 0;
  50. int Scor = 0;
  51. int LevelX = 4;
  52. int LevelY = 0;
  53.  
  54. bool AfisareCloud1 = true;
  55. bool AfisareCloud2 = false;
  56.  
  57. TVout TV;
  58.  
  59. void setup()
  60.     {
  61.       Serial.begin(9600);
  62.       pinMode(Up, INPUT);
  63.       pinMode(Down, INPUT);
  64.       pinMode(Left, INPUT);
  65.       pinMode(Right, INPUT);
  66.       pinMode(Push, INPUT);
  67.       pinMode(Start, INPUT);
  68.       pinMode(11, OUTPUT);
  69.       TV.begin(NTSC, 128, 96 );
  70.       TV.select_font(font6x8);
  71.       for (RezX = 0; RezX < 50; RezX++)
  72.           {
  73.               RezY = RezY - 1;    
  74.               if (RezY < 1) RezY = 1;
  75.               TV.bitmap(RezX, RezY, plane);  
  76.               delay(60);
  77.               if (RezY > 1 )
  78.                  {
  79.                      TV.clear_screen();
  80.                  }
  81.           }
  82.  
  83.           TV.bitmap(0, 58, arduinologo);
  84.           TV.bitmap(0, 38, planelogo);      
  85.           delay(3000);
  86.    
  87.           TV.clear_screen();
  88.           AfiseazaNivelul();            
  89.           TV.bitmap(PlaneX, PlaneY, plane4);
  90.     }
  91.  
  92. void loop()
  93.     {    
  94.          TV.print("SCORE: ");
  95.          TV.println(Scor);
  96.          TV.bitmap(PlaneX, PlaneY, plane4);    
  97.          if(digitalRead(Up) == 0)
  98.             {
  99.                PlaneY-=5;
  100.                if (PlaneY < 1) PlaneY = 1;
  101.             }
  102.          if(digitalRead(Down) == 0)
  103.             {
  104.                PlaneY+=5;
  105.                if (PlaneY > 81) PlaneY = 81;
  106.             }
  107.  
  108.         if (AfisareCloud1)
  109.            {
  110.                CloudX = CloudX-VitezaNori;
  111.                if (CloudX > 0)
  112.                   {
  113.                      TV.bitmap(CloudX, CloudY, cloud);
  114.                   }
  115.                   if (CloudX < 0)
  116.                      {
  117.                         CloudX = 93;            
  118.                         AfisareCloud1 = false;
  119.                         NumaratoareNivel = NumaratoareNivel + 1;
  120.                         Scor = Scor + 1;
  121.                      }
  122.                   if (!AfisareCloud2)
  123.                       {
  124.                          if (CloudX < 10)
  125.                             {
  126.                                AfisareCloud2 = true;
  127.                                Cloud2Y = random(0,34);
  128.                             }
  129.                       }      
  130.            }
  131.  
  132.  
  133.         if (AfisareCloud2)
  134.            {
  135.                Cloud2X = Cloud2X-VitezaNori;
  136.                if (Cloud2X > 0)
  137.                   {
  138.                      TV.bitmap(Cloud2X, Cloud2Y, cloud);
  139.                   }
  140.                   if (Cloud2X < 0)
  141.                      {
  142.                         Cloud2X = 93;            
  143.                         AfisareCloud2 = false;
  144.                         NumaratoareNivel = NumaratoareNivel + 1;
  145.                         Scor = Scor + 1;
  146.                      }
  147.                   if (!AfisareCloud1)
  148.                       {
  149.                          if (Cloud2X < 10)
  150.                             {
  151.                                AfisareCloud1 = true;
  152.                                CloudY = random(36,75);
  153.                             }
  154.                       }              
  155.            }
  156.         if (NumaratoareNivel == 10)
  157.            {
  158.               Nivel = Nivel + 1;
  159.               VitezaNori = VitezaNori + 1;
  160.               NumaratoareNivel = 0;
  161.               if (Nivel > 10) YouWin();
  162.               if (Nivel > 10) Nivel = 1;
  163.               if (VitezaNori > 10) VitezaNori = 1;
  164.               if (Scor == 100) Scor =0;
  165.               TV.clear_screen();
  166.               AfiseazaNivelul();
  167.            }
  168.  
  169.               if(PlaneX+14 >= CloudX)
  170.               {
  171.                 if(PlaneY <= CloudY && PlaneY+14 >= CloudY)
  172.                 {
  173.                   YourLose();
  174.                   CloudX = 93;
  175.                   Cloud2X = 93;
  176.                    CloudY = random(36,75);
  177.                     Cloud2Y = random(36,75);
  178.                     PlaneY = 20;
  179.                 }
  180.                  
  181.               }
  182.               if(PlaneX+14 >= Cloud2X)
  183.               {
  184.                 if(PlaneY <= Cloud2Y && PlaneY+14 >= Cloud2Y)
  185.                 {
  186.                   YourLose();
  187.                   CloudX = 93;
  188.                   Cloud2X = 93;
  189.                    CloudY = random(36,75);
  190.                     Cloud2Y = random(36,75);
  191.                     PlaneY = 20;
  192.                 }
  193.                  
  194.               }
  195.              
  196.  
  197.         delay(60);
  198.         TV.clear_screen();
  199.     }
  200.  
  201.     void AfiseazaNivelul()
  202.         {
  203.          for (LevelY = 0; LevelY < 53; LevelY++)
  204.              {
  205.                  if (Nivel == 1)
  206.                     {
  207.                        TV.bitmap(LevelX, LevelY, level1);
  208.                     }
  209.                  if (Nivel == 2)
  210.                     {
  211.                        TV.bitmap(LevelX, LevelY, level2);
  212.                     }
  213.                  if (Nivel == 3)
  214.                     {
  215.                        TV.bitmap(LevelX, LevelY, level3);
  216.                     }
  217.                  if (Nivel == 4)
  218.                     {
  219.                        TV.bitmap(LevelX, LevelY, level4);
  220.                     }
  221.                  if (Nivel == 5)
  222.                     {
  223.                        TV.bitmap(LevelX, LevelY, level5);
  224.                     }
  225.                  if (Nivel == 6)
  226.                     {
  227.                        TV.bitmap(LevelX, LevelY, level6);
  228.                     }
  229.                  if (Nivel == 7)
  230.                     {
  231.                        TV.bitmap(LevelX, LevelY, level7);
  232.                     }
  233.                  if (Nivel == 8)
  234.                     {
  235.                        TV.bitmap(LevelX, LevelY, level8);
  236.                     }
  237.                  if (Nivel == 9)
  238.                     {
  239.                        TV.bitmap(LevelX, LevelY, level9);
  240.                     }
  241.                  if (Nivel == 10)
  242.                     {
  243.                        TV.bitmap(LevelX, LevelY, level10);
  244.                     }
  245.                 delay(20);    
  246.              }
  247.              delay(1000);
  248.         }
  249.  
  250.     void YouWin()
  251.         {
  252.          TV.clear_screen();
  253.          for (LevelY = 0; LevelY < 53; LevelY++)
  254.              {
  255.                   TV.bitmap(LevelX, LevelY, youwin);
  256.              }
  257.            delay(5000);
  258.         }
  259.     void YourLose()
  260.         {
  261.          Explozie();
  262.          TV.clear_screen();
  263.          for (LevelY = 0; LevelY < 53; LevelY++)
  264.              {
  265.                   TV.bitmap(LevelX, LevelY, yourlose);
  266.              }
  267.              Nivel = 1;
  268.              Scor = 0;
  269.              VitezaNori = 1;
  270.              NumaratoareNivel = 0;
  271.            delay(5000);
  272.         }
  273.     void Explozie()
  274.       {
  275.           TV.clear_screen();
  276.           TV.bitmap(0, 0, explozie);
  277.           delay(3000);          
  278.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement