Me podrian ayudar con este juego de PONG
PS estoy haciendo uno y me he trabado, no puedo lograr hacer funcionar, tanto las dos barras como 2 pelotas que corran al miemo tiempo, me corre siempre el primero que encuentra, se que el problema esta en el MAIN pero no se como solucionarlo, aqlguna solucion, pongo el programa, estan desabilitadas las dos barras para que corran las pelotas, pero si se habilita una barra va a tomar solo la primera barra pero no se van a ver ni las pelotas ni la otra barra.
PD. Esta programado en BORLAND por eso de las librerias.
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#include <conio.h>
#include <stdlib.h>
int maxx=639, maxy=479;
int r=25;
int cx, cx2, cy, cy2;
int dx1, dx2, dy1, dy2;
int bx, by, bx2, by2;
int puntos=0;
void modografico()
{
int tarjeta=DETECT,modo,mov;
initgraph(&tarjeta, &modo, "C:\tc\bgi");
}
char detectatecla()
{ char valor;
valor=getch();
if(valor==NULL)
valor=getch();
return valor;
}
void inicializa()
{
randomize();
cx=random(maxx);
cx2=random(maxx);
cy=random(maxy);
cy2=random(maxy);
if (50<random(100)) dx1=-1; else dx1=1;
if (50<random(100)) dx2=-1; else dx2=1;
if (50<random(100)) dy1=-1; else dy1=1;
if (50<random(100)) dy2=-1; else dy2=1;
}
int verifrebotebarra()
{
if ((by-cy==r)&&(bx<=cx)&&(cx==bx+20)&&
(by2-cy==r)&&(bx2<=cx)&&(cx==bx2+20)&&
(by-cy2==r)&&(bx<=cx2)&&(cx2==bx+20)&&
(by2-cy2==r)&&(bx2<=cx2)&&(cx2==bx2+20))
{//sonido
dy1=-1;
puntos++;
return 1;
}
return 0;
}
void puntaje()
{
char texto[50];
sprintf(texto,"Marcador: %d",puntos);
outtextxy(10,20,texto);
}
int perdio()
{
if (cy==maxy)
return 1;
return 0;
}
void barraaba()
{
int bx=2,by=459,mov;
int maxx=639;
for(;;)
{
mov=detectatecla();
switch(mov)
{
case 77: bx+=5; break;
case 75: bx-=5; break;
case 13: goto salir;
}
cleardevice();
rectangle(bx,by,bx+60,by+20);
if (bx+60>maxx) bx=maxx-60;
if (bx<=5) bx=5;
}
salir:
getch();
closegraph();
}
void barraarr()
{
int bx2=2,by2=2,mov;
int maxx=639;
for(;;)
{
mov=detectatecla();
switch(mov)
{
case 'a': bx2+=5; break;
case 'd': bx2-=5; break;
case 13: goto salir;
}
cleardevice();
rectangle(bx2,by2,bx2+60,by2+20);
if (bx2+60>maxx) bx2=maxx-60;
if (bx2<=5) bx=5;
}
salir:
getch();
closegraph();
}
void main()
{
modografico();
inicializa();
//barraaba();
//barraarr();
for(;;)
{
verifrebotebarra();
puntaje();
perdio();
setcolor(RED);
circle(cx,cy,r);
// setfillstyle(SOLID_FILL,RED);
// floodfill(cx,cy,RED);
setcolor(BLUE);
circle(cx2,cy2,r);
// setfillstyle(SOLID_FILL,BLUE);
// floodfill(cx2,cy2,BLUE);
if (2*r>=sqrt(pow(cx2-cx,2)+pow(cy2-cy,2)))
{
if (dx1!=dx2)
{
dx1*=-1;
dx2*=-1;
}
if (dy1!=dy2)
{
dy1*=-1;
dy2*=-1;
}
}
//choque en x
if (cx>=maxx-r) dx1=-1;
if (cx2>=maxx-r) dx2=-1;
if (cx<=r) dx1=1;
if (cx2<=r) dx2=1;
//choque en y
if (cy>=maxy-r) dy1=-1;
if (cy2>=maxy-r) dy2=-1;
if (cy<=r) dy1=1;
if (cy2<=r) dy2=1;
cx=cx+dx1;
cx2=cx2+dx2;
cy=cy+dy1;
cy2=cy2+dy2;
delay(3);
cleardevice();
if (kbhit()) break;
}
}
}
closegraph();
}
PD. Esta programado en BORLAND por eso de las librerias.
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#include <conio.h>
#include <stdlib.h>
int maxx=639, maxy=479;
int r=25;
int cx, cx2, cy, cy2;
int dx1, dx2, dy1, dy2;
int bx, by, bx2, by2;
int puntos=0;
void modografico()
{
int tarjeta=DETECT,modo,mov;
initgraph(&tarjeta, &modo, "C:\tc\bgi");
}
char detectatecla()
{ char valor;
valor=getch();
if(valor==NULL)
valor=getch();
return valor;
}
void inicializa()
{
randomize();
cx=random(maxx);
cx2=random(maxx);
cy=random(maxy);
cy2=random(maxy);
if (50<random(100)) dx1=-1; else dx1=1;
if (50<random(100)) dx2=-1; else dx2=1;
if (50<random(100)) dy1=-1; else dy1=1;
if (50<random(100)) dy2=-1; else dy2=1;
}
int verifrebotebarra()
{
if ((by-cy==r)&&(bx<=cx)&&(cx==bx+20)&&
(by2-cy==r)&&(bx2<=cx)&&(cx==bx2+20)&&
(by-cy2==r)&&(bx<=cx2)&&(cx2==bx+20)&&
(by2-cy2==r)&&(bx2<=cx2)&&(cx2==bx2+20))
{//sonido
dy1=-1;
puntos++;
return 1;
}
return 0;
}
void puntaje()
{
char texto[50];
sprintf(texto,"Marcador: %d",puntos);
outtextxy(10,20,texto);
}
int perdio()
{
if (cy==maxy)
return 1;
return 0;
}
void barraaba()
{
int bx=2,by=459,mov;
int maxx=639;
for(;;)
{
mov=detectatecla();
switch(mov)
{
case 77: bx+=5; break;
case 75: bx-=5; break;
case 13: goto salir;
}
cleardevice();
rectangle(bx,by,bx+60,by+20);
if (bx+60>maxx) bx=maxx-60;
if (bx<=5) bx=5;
}
salir:
getch();
closegraph();
}
void barraarr()
{
int bx2=2,by2=2,mov;
int maxx=639;
for(;;)
{
mov=detectatecla();
switch(mov)
{
case 'a': bx2+=5; break;
case 'd': bx2-=5; break;
case 13: goto salir;
}
cleardevice();
rectangle(bx2,by2,bx2+60,by2+20);
if (bx2+60>maxx) bx2=maxx-60;
if (bx2<=5) bx=5;
}
salir:
getch();
closegraph();
}
void main()
{
modografico();
inicializa();
//barraaba();
//barraarr();
for(;;)
{
verifrebotebarra();
puntaje();
perdio();
setcolor(RED);
circle(cx,cy,r);
// setfillstyle(SOLID_FILL,RED);
// floodfill(cx,cy,RED);
setcolor(BLUE);
circle(cx2,cy2,r);
// setfillstyle(SOLID_FILL,BLUE);
// floodfill(cx2,cy2,BLUE);
if (2*r>=sqrt(pow(cx2-cx,2)+pow(cy2-cy,2)))
{
if (dx1!=dx2)
{
dx1*=-1;
dx2*=-1;
}
if (dy1!=dy2)
{
dy1*=-1;
dy2*=-1;
}
}
//choque en x
if (cx>=maxx-r) dx1=-1;
if (cx2>=maxx-r) dx2=-1;
if (cx<=r) dx1=1;
if (cx2<=r) dx2=1;
//choque en y
if (cy>=maxy-r) dy1=-1;
if (cy2>=maxy-r) dy2=-1;
if (cy<=r) dy1=1;
if (cy2<=r) dy2=1;
cx=cx+dx1;
cx2=cx2+dx2;
cy=cy+dy1;
cy2=cy2+dy2;
delay(3);
cleardevice();
if (kbhit()) break;
}
}
}
closegraph();
}