//
// Code by Andras Daradici
//
// Hardware Levente Daradici
//
// https://www.youtube.com/@LeventeDaradici/videos
//
#include "TVout.h"
#include "Duck.h"
#include <fontALL.h>
TVout TV;
int width = 120;
int height = 96;
int scene = 0;
bool DidPrint = false;
bool Show;
int PlayerX = 58;
int PlayerY = 48;
int BallX = 58;
int BallY = 48;
bool MovingUp = true;
bool MovingLeft = false;
int Up = 5;
int Down = 2;
int Left = 4;
int Right = 3;
int Push = 6;
int Start = 8;
int game = 1;
int gamed = 1;
int bounces = 0;
bool Pressed = false;
void setup() {
pinMode(Up, INPUT);
pinMode(Down, INPUT);
pinMode(Left, INPUT);
pinMode(Right, INPUT);
pinMode(Push, INPUT);
pinMode(Start, INPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
// put your setup code here, to run once:
TV.begin(NTSC,width,height);
//TV.draw_line(0,0,120,96,INVERT);
//TV.draw_line(120,0,0,96,INVERT);
TV.select_font(font6x8);
TV.println("\n\n Select the game");
TV.print(" Game: ");
TV.print(gamed);
TV.select_font(font4x6);
TV.println("\n\n\n\n PRESS BUTTON TO PLAY");
TV.draw_line(0,0,120,0, WHITE);
TV.draw_line(0,94,120,94, WHITE);
TV.draw_line(0,95,120,95, WHITE);
TV.draw_line(0,96,120,96, WHITE);
TV.draw_line(0,0,0,94, WHITE);
TV.draw_line(119,0,119,94, WHITE);
}
void loop()
{
while(scene == 0 && game == 0)
{
if(digitalRead(Left) == 0 && !Pressed)
{
TV.tone(1750, 125);
delay(250);
TV.tone(1950, 125);
delay(250);
TV.tone(1550, 125);
gamed--;
Pressed = true;
TV.select_font(font6x8);
TV.println("\n\n Select the game");
TV.print(" Game: ");
TV.print(gamed);
TV.select_font(font4x6);
TV.println("\n\n\n\n PRESS BUTTON TO PLAY");
TV.draw_line(0,0,120,0, WHITE);
TV.draw_line(0,94,120,94, WHITE);
TV.draw_line(0,95,120,95, WHITE);
TV.draw_line(0,96,120,96, WHITE);
TV.draw_line(0,0,0,94, WHITE);
TV.draw_line(119,0,119,94, WHITE);
}
if(digitalRead(Right) == 0 && !Pressed)
{
TV.tone(1750, 125);
delay(250);
TV.tone(1950, 125);
delay(250);
TV.tone(1550, 125);
gamed++;
Pressed = true;
TV.clear_screen();
TV.select_font(font6x8);
TV.println("\n\n Select the game");
TV.print(" Game: ");
TV.print(gamed);
TV.select_font(font4x6);
TV.println("\n\n\n\n PRESS BUTTON TO PLAY");
TV.draw_line(0,0,120,0, WHITE);
TV.draw_line(0,94,120,94, WHITE);
TV.draw_line(0,95,120,95, WHITE);
TV.draw_line(0,96,120,96, WHITE);
TV.draw_line(0,0,0,94, WHITE);
TV.draw_line(119,0,119,94, WHITE);
}
if(digitalRead(Right) == 1 && digitalRead(Left) == 1)
{
Pressed = false;
}
if(gamed > 2)
{
gamed = 1;
}
if(gamed < 1)
{
gamed = 2;
}
if(digitalRead(Start) == 0 && !Pressed)
{
TV.tone(750, 125);
delay(250);
TV.tone(950, 125);
delay(250);
TV.tone(550, 125);
game = gamed;
Pressed = true;
}
//delay(10000);
//TV.clear_screen();
}
while(scene == 0 && game == 1)
{
if(Show)
{
TV.select_font(font6x8);
TV.println("\n\n IM-PONG-SIBBLE\n TV EDITION");
TV.select_font(font4x6);
TV.println("\n Andras Daradici");
TV.select_font(font4x6);
TV.println("\n\n\n\n\n\n PRESS BUTTON TO PLAY");
}
else
{
TV.select_font(font6x8);
TV.println("\n\n IM-PONG-SIBBLE\n TV EDITION");
TV.select_font(font4x6);
TV.println("\n Andras Daradici");
TV.select_font(font4x6);
TV.println("\n\n\n\n\n\n");
}
TV.draw_line(0,0,120,0, WHITE);
TV.draw_line(0,94,120,94, WHITE);
TV.draw_line(0,95,120,95, WHITE);
TV.draw_line(0,96,120,96, WHITE);
TV.draw_line(0,0,0,94, WHITE);
TV.draw_line(119,0,119,94, WHITE);
delay(25000);
TV.clear_screen();
Show = !Show;
if(digitalRead(Start) == 1)
{
Pressed = false;
}
if(digitalRead(Start) == 0 && !Pressed)
{
Pressed = true;
TV.tone(750, 125);
delay(250);
TV.tone(950, 125);
delay(250);
TV.tone(550, 125);
scene = 1;
}
}
while(scene == 1 && game == 1)
{
Pressed = false;
TV.draw_line(60,0,60,10,WHITE);
TV.draw_line(60,20,60,30,WHITE);
TV.draw_line(60,40,60,50,WHITE);
TV.draw_line(60,60,60,70,WHITE);
TV.draw_line(60,80,60,90,WHITE);
//TV.draw_line(60,0,60,10,WHITE);
PlayerControl();
MoveBall();
if(PlayerY <= 6)
{
PlayerY = 6;
}
if(PlayerY >= 89)
{
PlayerY = 89;
}
TV.draw_circle(BallX,BallY,1,WHITE, INVERT);
//Player
TV.draw_line(2,PlayerY-5,2,PlayerY+5,INVERT);
TV.draw_line(3,PlayerY-5,3,PlayerY+5,INVERT);
TV.draw_line(117,BallY-5,117,BallY+5,INVERT);
TV.draw_line(116,BallY-5,116,BallY+5,INVERT);
TV.draw_line(0,0,120,0, WHITE);
TV.draw_line(0,94,120,94, WHITE);
TV.draw_line(0,95,120,95, WHITE);
TV.draw_line(0,96,120,96, WHITE);
TV.draw_line(0,0,0,94, WHITE);
TV.draw_line(119,0,119,94, WHITE);
TV.println(bounces);
delay(10);
TV.clear_screen();
}
while(scene == 2 && game == 1)
{
if(Show)
{
TV.select_font(font6x8);
TV.println("\n\n IM-PONG-SIBBLE\n TV EDITION");
TV.print(" Score: ");
TV.print(bounces);
TV.select_font(font4x6);
TV.println("\n\n Andras Daradici");
TV.select_font(font4x6);
TV.println("\n\n\n\n PRESS BUTTON TO PLAY");
}
else
{
TV.select_font(font6x8);
TV.println("\n\n IM-PONG-SIBBLE\n TV EDITION");
TV.print(" Score: ");
TV.print(bounces);
TV.select_font(font4x6);
TV.println("\n\n Andras Daradici");
TV.select_font(font4x6);
TV.println("\n\n\n\n");
}
TV.draw_line(0,0,120,0, WHITE);
TV.draw_line(0,94,120,94, WHITE);
TV.draw_line(0,95,120,95, WHITE);
TV.draw_line(0,96,120,96, WHITE);
TV.draw_line(0,0,0,94, WHITE);
TV.draw_line(119,0,119,94, WHITE);
delay(25000);
TV.clear_screen();
Show = !Show;
if(digitalRead(Start) == 0 && !Pressed)
{
TV.tone(750, 125);
delay(250);
TV.tone(950, 125);
delay(250);
TV.tone(550, 125);
scene = 1;
bounces = 0;
BallX = 58;
BallY = 48;
PlayerX = 58;
PlayerY = 48;
MovingLeft = false;
MovingUp = false;
}
}
while(scene == 0 && game == 2)
{
if(Show)
{
TV.select_font(font6x8);
TV.println("\n\n DUCK HUNT\n ");
TV.select_font(font4x6);
TV.println("\n Andras Daradici");
TV.select_font(font4x6);
TV.println("\n\n\n\n\n\n PRESS BUTTON TO PLAY");
}
else
{
TV.select_font(font6x8);
TV.println("\n\n DUCK HUNT\n ");
TV.select_font(font4x6);
TV.println("\n Andras Daradici");
TV.select_font(font4x6);
TV.println("\n\n\n\n\n\n");
}
TV.draw_line(0,0,120,0, WHITE);
TV.draw_line(0,94,120,94, WHITE);
TV.draw_line(0,95,120,95, WHITE);
TV.draw_line(0,96,120,96, WHITE);
TV.draw_line(0,0,0,94, WHITE);
TV.draw_line(119,0,119,94, WHITE);
delay(25000);
TV.clear_screen();
Show = !Show;
if(digitalRead(Start) == 1)
{
Pressed = false;
}
if(digitalRead(Start) == 0 && !Pressed)
{
Pressed = true;
TV.tone(750, 125);
delay(250);
TV.tone(950, 125);
delay(250);
TV.tone(550, 125);
scene = 1;
}
}
while(scene == 1 && game == 2)
{
for(int x = 10; x < 90; x++)
{
TV.bitmap(x, 10, duck);
}
PlayerControl();
TV.draw_circle(PlayerX,PlayerY,2,INVERT);
TV.draw_line(0,0,120,0, WHITE);
TV.draw_line(0,94,120,94, WHITE);
TV.draw_line(0,95,120,95, WHITE);
TV.draw_line(0,96,120,96, WHITE);
TV.draw_line(0,0,0,94, WHITE);
TV.draw_line(119,0,119,94, WHITE);
if(PlayerX <= 5)
{
PlayerX = 5;
}
if(PlayerX >= 114)
{
PlayerX = 114;
}
if(PlayerY <= 5)
{
PlayerY = 5;
}
if(PlayerY >= 89)
{
PlayerY = 89;
}
delay(10);
TV.clear_screen();
}
if(digitalRead(Push) == 0)
{
game = 0;
}
}
void MoveBall()
{
if(MovingLeft)
{
BallX--;
}
else
{
BallX++;
}
if(MovingUp)
{
BallY--;
}
else
{
BallY++;
}
if(BallX == 114)
{
TV.tone(750, 125);
MovingLeft = true;
bounces++;
}
if(BallX == 5)
{
if(BallY >= PlayerY-7 && BallY <= PlayerY+7)
{
TV.tone(750, 125);
MovingLeft = false;
bounces++;
}
else
{
TV.tone(1750, 125);
delay(125);
TV.tone(1750, 125);
delay(125);
TV.tone(1750, 125);
delay(125);
scene = 2;
}
}
if(BallY == 92)
{
TV.tone(250, 125);
MovingUp = true;
}
if(BallY == 4)
{
TV.tone(250, 125);
MovingUp = false;
}
}
void PlayerControl()
{
if(digitalRead(Up) == 0 && game == 1)
{
PlayerY-=2;
//Serial.println("UP");
}
if(digitalRead(Down) == 0 && game == 1)
{
PlayerY+=2;
//Serial.println("DOWN");
}
if(digitalRead(Up) == 0 && game == 2)
{
PlayerY-=2;
//Serial.println("UP");
}
if(digitalRead(Down) == 0 && game == 2)
{
PlayerY+=2;
//Serial.println("DOWN");
}
if(digitalRead(Left) == 0 && game == 2)
{
PlayerX-=2;
//Serial.println("LEFT");
}
if(digitalRead(Right) == 0&& game == 2)
{
PlayerX+=2;
//Serial.println("RIGHT");
}
}