Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //
  2. // Code by Andras Daradici
  3. //
  4. // Hardware Levente Daradici
  5. //
  6. // https://www.youtube.com/@LeventeDaradici/videos
  7. //
  8.  
  9. #include "TVout.h"
  10. #include "Duck.h"
  11. #include <fontALL.h>
  12.  
  13. TVout TV;
  14. int width = 120;
  15. int height = 96;
  16.  
  17. int scene = 0;
  18.  
  19. bool DidPrint = false;
  20. bool Show;
  21.  
  22. int PlayerX = 58;
  23. int PlayerY = 48;
  24. int BallX = 58;
  25. int BallY = 48;
  26.  
  27. bool MovingUp = true;
  28. bool MovingLeft = false;
  29.  
  30. int Up = 5;
  31. int Down = 2;
  32. int Left = 4;
  33. int Right = 3;
  34. int Push = 6;
  35. int Start = 8;
  36.  
  37. int game = 1;
  38. int gamed = 1;
  39.  
  40. int bounces = 0;
  41.  
  42. bool Pressed = false;
  43.  
  44. void setup() {
  45.  
  46.   pinMode(Up, INPUT);
  47.   pinMode(Down, INPUT);
  48.   pinMode(Left, INPUT);
  49.   pinMode(Right, INPUT);
  50.   pinMode(Push, INPUT);
  51.   pinMode(Start, INPUT);
  52.   pinMode(11, OUTPUT);
  53.   Serial.begin(9600);
  54.   // put your setup code here, to run once:
  55.   TV.begin(NTSC,width,height);
  56.   //TV.draw_line(0,0,120,96,INVERT);
  57.   //TV.draw_line(120,0,0,96,INVERT);
  58.  
  59.    TV.select_font(font6x8);
  60.       TV.println("\n\n   Select the game");
  61.       TV.print("      Game: ");
  62.       TV.print(gamed);
  63.       TV.select_font(font4x6);
  64.       TV.println("\n\n\n\n     PRESS BUTTON TO PLAY");
  65.       TV.draw_line(0,0,120,0, WHITE);
  66.       TV.draw_line(0,94,120,94, WHITE);
  67.       TV.draw_line(0,95,120,95, WHITE);
  68.       TV.draw_line(0,96,120,96, WHITE);
  69.       TV.draw_line(0,0,0,94, WHITE);
  70.       TV.draw_line(119,0,119,94, WHITE);
  71. }
  72.  
  73. void loop()
  74. {
  75.   while(scene == 0 && game == 0)
  76.   {
  77.      
  78.       if(digitalRead(Left) == 0 && !Pressed)
  79.       {
  80.         TV.tone(1750, 125);
  81.         delay(250);
  82.         TV.tone(1950, 125);
  83.         delay(250);
  84.         TV.tone(1550, 125);
  85.         gamed--;
  86.         Pressed = true;
  87.  
  88.  
  89.          TV.select_font(font6x8);
  90.       TV.println("\n\n   Select the game");
  91.       TV.print("      Game: ");
  92.       TV.print(gamed);
  93.       TV.select_font(font4x6);
  94.       TV.println("\n\n\n\n     PRESS BUTTON TO PLAY");
  95.       TV.draw_line(0,0,120,0, WHITE);
  96.       TV.draw_line(0,94,120,94, WHITE);
  97.       TV.draw_line(0,95,120,95, WHITE);
  98.       TV.draw_line(0,96,120,96, WHITE);
  99.       TV.draw_line(0,0,0,94, WHITE);
  100.       TV.draw_line(119,0,119,94, WHITE);
  101.  
  102.       }
  103.       if(digitalRead(Right) == 0 && !Pressed)
  104.       {
  105.         TV.tone(1750, 125);
  106.         delay(250);
  107.         TV.tone(1950, 125);
  108.         delay(250);
  109.         TV.tone(1550, 125);
  110.         gamed++;
  111.         Pressed = true;
  112.         TV.clear_screen();
  113.  
  114.         TV.select_font(font6x8);
  115.       TV.println("\n\n   Select the game");
  116.       TV.print("      Game: ");
  117.       TV.print(gamed);
  118.       TV.select_font(font4x6);
  119.       TV.println("\n\n\n\n     PRESS BUTTON TO PLAY");
  120.       TV.draw_line(0,0,120,0, WHITE);
  121.       TV.draw_line(0,94,120,94, WHITE);
  122.       TV.draw_line(0,95,120,95, WHITE);
  123.       TV.draw_line(0,96,120,96, WHITE);
  124.       TV.draw_line(0,0,0,94, WHITE);
  125.       TV.draw_line(119,0,119,94, WHITE);
  126.  
  127.       }
  128.       if(digitalRead(Right) == 1 && digitalRead(Left) == 1)
  129.       {
  130.         Pressed = false;
  131.       }
  132.       if(gamed > 2)
  133.       {
  134.         gamed = 1;
  135.       }
  136.       if(gamed < 1)
  137.       {
  138.         gamed = 2;
  139.       }
  140.       if(digitalRead(Start) == 0 && !Pressed)
  141.       {
  142.         TV.tone(750, 125);
  143.         delay(250);
  144.         TV.tone(950, 125);
  145.         delay(250);
  146.         TV.tone(550, 125);
  147.         game = gamed;
  148.         Pressed = true;
  149.       }
  150.       //delay(10000);
  151.       //TV.clear_screen();
  152.   }
  153.  
  154.   while(scene == 0 && game == 1)
  155.   {
  156.     if(Show)
  157.     {
  158.       TV.select_font(font6x8);
  159.       TV.println("\n\n   IM-PONG-SIBBLE\n     TV EDITION");
  160.       TV.select_font(font4x6);
  161.       TV.println("\n        Andras Daradici");
  162.       TV.select_font(font4x6);
  163.       TV.println("\n\n\n\n\n\n     PRESS BUTTON TO PLAY");
  164.     }
  165.     else
  166.     {
  167.       TV.select_font(font6x8);
  168.       TV.println("\n\n   IM-PONG-SIBBLE\n     TV EDITION");
  169.       TV.select_font(font4x6);
  170.       TV.println("\n        Andras Daradici");
  171.       TV.select_font(font4x6);
  172.       TV.println("\n\n\n\n\n\n");
  173.     }
  174.     TV.draw_line(0,0,120,0, WHITE);
  175.     TV.draw_line(0,94,120,94, WHITE);
  176.     TV.draw_line(0,95,120,95, WHITE);
  177.     TV.draw_line(0,96,120,96, WHITE);
  178.     TV.draw_line(0,0,0,94, WHITE);
  179.     TV.draw_line(119,0,119,94, WHITE);
  180.     delay(25000);
  181.     TV.clear_screen();
  182.     Show = !Show;
  183.     if(digitalRead(Start) == 1)
  184.     {
  185.       Pressed = false;
  186.     }
  187.     if(digitalRead(Start) == 0 && !Pressed)
  188.     {
  189.       Pressed = true;
  190.       TV.tone(750, 125);
  191.       delay(250);
  192.       TV.tone(950, 125);
  193.       delay(250);
  194.       TV.tone(550, 125);
  195.       scene = 1;
  196.     }
  197.   }
  198.   while(scene == 1 && game == 1)
  199.   {
  200.     Pressed = false;
  201.     TV.draw_line(60,0,60,10,WHITE);
  202.     TV.draw_line(60,20,60,30,WHITE);
  203.     TV.draw_line(60,40,60,50,WHITE);
  204.     TV.draw_line(60,60,60,70,WHITE);
  205.     TV.draw_line(60,80,60,90,WHITE);
  206.     //TV.draw_line(60,0,60,10,WHITE);
  207.     PlayerControl();
  208.     MoveBall();
  209.  
  210.     if(PlayerY <= 6)
  211.     {
  212.       PlayerY = 6;
  213.     }
  214.     if(PlayerY >= 89)
  215.     {
  216.       PlayerY = 89;
  217.     }
  218.  
  219.     TV.draw_circle(BallX,BallY,1,WHITE, INVERT);
  220.    
  221.     //Player
  222.     TV.draw_line(2,PlayerY-5,2,PlayerY+5,INVERT);
  223.     TV.draw_line(3,PlayerY-5,3,PlayerY+5,INVERT);
  224.  
  225.     TV.draw_line(117,BallY-5,117,BallY+5,INVERT);
  226.     TV.draw_line(116,BallY-5,116,BallY+5,INVERT);
  227.  
  228.     TV.draw_line(0,0,120,0, WHITE);
  229.     TV.draw_line(0,94,120,94, WHITE);
  230.     TV.draw_line(0,95,120,95, WHITE);
  231.     TV.draw_line(0,96,120,96, WHITE);
  232.     TV.draw_line(0,0,0,94, WHITE);
  233.     TV.draw_line(119,0,119,94, WHITE);
  234.     TV.println(bounces);
  235.     delay(10);
  236.     TV.clear_screen();
  237.    
  238.   }
  239.   while(scene == 2 && game == 1)
  240.   {
  241.     if(Show)
  242.     {
  243.       TV.select_font(font6x8);
  244.       TV.println("\n\n   IM-PONG-SIBBLE\n     TV EDITION");
  245.       TV.print("      Score: ");
  246.       TV.print(bounces);
  247.       TV.select_font(font4x6);
  248.       TV.println("\n\n        Andras Daradici");
  249.       TV.select_font(font4x6);
  250.       TV.println("\n\n\n\n     PRESS BUTTON TO PLAY");
  251.     }
  252.     else
  253.     {
  254.       TV.select_font(font6x8);
  255.       TV.println("\n\n   IM-PONG-SIBBLE\n     TV EDITION");
  256.       TV.print("      Score: ");
  257.       TV.print(bounces);
  258.       TV.select_font(font4x6);
  259.       TV.println("\n\n        Andras Daradici");
  260.       TV.select_font(font4x6);
  261.       TV.println("\n\n\n\n");
  262.     }
  263.     TV.draw_line(0,0,120,0, WHITE);
  264.     TV.draw_line(0,94,120,94, WHITE);
  265.     TV.draw_line(0,95,120,95, WHITE);
  266.     TV.draw_line(0,96,120,96, WHITE);
  267.     TV.draw_line(0,0,0,94, WHITE);
  268.     TV.draw_line(119,0,119,94, WHITE);
  269.     delay(25000);
  270.     TV.clear_screen();
  271.     Show = !Show;
  272.     if(digitalRead(Start) == 0 && !Pressed)
  273.     {
  274.       TV.tone(750, 125);
  275.       delay(250);
  276.       TV.tone(950, 125);
  277.       delay(250);
  278.       TV.tone(550, 125);
  279.       scene = 1;
  280.       bounces = 0;
  281.       BallX = 58;
  282.       BallY = 48;
  283.       PlayerX = 58;
  284.       PlayerY = 48;
  285.       MovingLeft = false;
  286.       MovingUp = false;
  287.     }
  288.   }
  289.   while(scene == 0 && game == 2)
  290.   {
  291.     if(Show)
  292.     {
  293.       TV.select_font(font6x8);
  294.       TV.println("\n\n      DUCK HUNT\n     ");
  295.       TV.select_font(font4x6);
  296.       TV.println("\n        Andras Daradici");
  297.       TV.select_font(font4x6);
  298.       TV.println("\n\n\n\n\n\n     PRESS BUTTON TO PLAY");
  299.     }
  300.     else
  301.     {
  302.       TV.select_font(font6x8);
  303.       TV.println("\n\n      DUCK HUNT\n     ");
  304.       TV.select_font(font4x6);
  305.       TV.println("\n        Andras Daradici");
  306.       TV.select_font(font4x6);
  307.       TV.println("\n\n\n\n\n\n");
  308.     }
  309.     TV.draw_line(0,0,120,0, WHITE);
  310.     TV.draw_line(0,94,120,94, WHITE);
  311.     TV.draw_line(0,95,120,95, WHITE);
  312.     TV.draw_line(0,96,120,96, WHITE);
  313.     TV.draw_line(0,0,0,94, WHITE);
  314.     TV.draw_line(119,0,119,94, WHITE);
  315.     delay(25000);
  316.     TV.clear_screen();
  317.     Show = !Show;
  318.     if(digitalRead(Start) == 1)
  319.     {
  320.       Pressed = false;
  321.     }
  322.     if(digitalRead(Start) == 0 && !Pressed)
  323.     {
  324.       Pressed = true;
  325.       TV.tone(750, 125);
  326.       delay(250);
  327.       TV.tone(950, 125);
  328.       delay(250);
  329.       TV.tone(550, 125);
  330.       scene = 1;
  331.     }
  332.   }
  333.   while(scene == 1 && game == 2)
  334.   {
  335.     for(int x = 10; x < 90; x++)
  336.     {
  337.       TV.bitmap(x,   10, duck);
  338.     }
  339.    
  340.  
  341.     PlayerControl();
  342.     TV.draw_circle(PlayerX,PlayerY,2,INVERT);
  343.     TV.draw_line(0,0,120,0, WHITE);
  344.     TV.draw_line(0,94,120,94, WHITE);
  345.     TV.draw_line(0,95,120,95, WHITE);
  346.     TV.draw_line(0,96,120,96, WHITE);
  347.     TV.draw_line(0,0,0,94, WHITE);
  348.     TV.draw_line(119,0,119,94, WHITE);
  349.  
  350.     if(PlayerX <= 5)
  351.     {
  352.       PlayerX = 5;
  353.     }
  354.     if(PlayerX >= 114)
  355.     {
  356.       PlayerX = 114;
  357.     }
  358.     if(PlayerY <= 5)
  359.     {
  360.       PlayerY = 5;
  361.     }
  362.     if(PlayerY >= 89)
  363.     {
  364.       PlayerY = 89;
  365.     }
  366.  
  367.     delay(10);
  368.     TV.clear_screen();
  369.   }
  370.   if(digitalRead(Push) == 0)
  371.   {
  372.     game = 0;
  373.   }
  374. }
  375.  
  376. void MoveBall()
  377. {
  378.   if(MovingLeft)
  379.   {
  380.     BallX--;
  381.   }
  382.   else
  383.   {
  384.     BallX++;
  385.   }
  386.   if(MovingUp)
  387.   {
  388.     BallY--;
  389.   }
  390.   else
  391.   {
  392.     BallY++;
  393.   }
  394.   if(BallX == 114)
  395.   {
  396.     TV.tone(750, 125);
  397.     MovingLeft = true;
  398.     bounces++;
  399.   }
  400.   if(BallX == 5)
  401.   {
  402.     if(BallY >= PlayerY-7 && BallY <= PlayerY+7)
  403.     {
  404.       TV.tone(750, 125);
  405.       MovingLeft = false;
  406.       bounces++;
  407.     }
  408.     else
  409.     {
  410.       TV.tone(1750, 125);
  411.       delay(125);
  412.       TV.tone(1750, 125);
  413.       delay(125);
  414.       TV.tone(1750, 125);
  415.       delay(125);
  416.       scene = 2;
  417.     }
  418.   }
  419.   if(BallY == 92)
  420.   {
  421.     TV.tone(250, 125);
  422.     MovingUp = true;
  423.   }
  424.   if(BallY == 4)
  425.   {
  426.     TV.tone(250, 125);
  427.     MovingUp = false;
  428.   }
  429. }
  430.  
  431. void PlayerControl()
  432. {
  433.   if(digitalRead(Up) == 0 && game == 1)
  434.   {
  435.     PlayerY-=2;
  436.     //Serial.println("UP");
  437.   }
  438.   if(digitalRead(Down) == 0 && game == 1)
  439.   {
  440.     PlayerY+=2;
  441.     //Serial.println("DOWN");
  442.   }
  443.   if(digitalRead(Up) == 0 && game == 2)
  444.   {
  445.     PlayerY-=2;
  446.     //Serial.println("UP");
  447.   }
  448.   if(digitalRead(Down) == 0 && game == 2)
  449.   {
  450.     PlayerY+=2;
  451.     //Serial.println("DOWN");
  452.   }
  453.   if(digitalRead(Left) == 0 && game == 2)
  454.   {
  455.     PlayerX-=2;
  456.     //Serial.println("LEFT");
  457.   }
  458.   if(digitalRead(Right) == 0&& game == 2)
  459.   {
  460.     PlayerX+=2;
  461.     //Serial.println("RIGHT");
  462.   }
  463. }