[CODIGO] Juego y editor y mas
bue es simple esto ,lo hice hace mucho
asi que si algo esta mal o otra cosa , no se quejen XD
bue Esta Echo para DOS y en Borland Turbo C++
bue lo primero
seria una "Base" para hacer jueguitos
el segundo
El editor
el tercero
bue espero que les sirva a los que estan aprendiendo C/C++
pero creo que los BGI que use no estan en el comun :S
por que me acurdo que habia echo uno en 1024
bue es simple esto ,lo hice hace mucho
asi que si algo esta mal o otra cosa , no se quejen XD
bue Esta Echo para DOS y en Borland Turbo C++
bue lo primero
seria una "Base" para hacer jueguitos
C++:
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
const MAXX=15;
const MAXY=30;
const TT=2000;
const SP=5;
int te;
int tm;
int x;
int y;
int x2;
int ju;
int y2;
char main(){
int graphdriver = DETECT, graphmode;
initgraph(&graphdriver, &graphmode, "..<span style="color: #666666; font-weight: bold;">\\bgi"</span>);
setgraphmode(0);
x = 10;
y = 80;
y2 = 80;
x2 = 600;
ju = 1;
tm = 0;
while(ju>0){
tm++;
if (tm>=TT){
tm=0;
if (kbhit>0){
cleardevice();
setcolor(5);
rectangle(0,0,630,190);
setcolor(1);
rectangle(x,y,x+MAXX,y+MAXY);
setcolor(2);
rectangle(x2,y2,x2+MAXX,y2+MAXY);
te = getch();
switch (te){
case 27: ju=0;
break;
case 100: x+=SP;
break;
case 97: x-=SP;
break;
case 115 : y+=SP;
break;
case 119: y-=SP;
break;
/* }
getch();
te = getch();
switch (te){*/
case 108: x2+=SP ;
break;
case 106: x2-=SP;
break;
case 107 : y2+=SP;
break;
case 105: y2-=SP;
break;
}
}
}
}
closegraph();
return 0;
}
el segundo
El editor
C++:
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
const MAXX=15;
const MAXY=30;
const GRM=5;
const TT=500;
const TT2=500;
const SP=12;
const GP=15;
int te;
char fil[80];
char er[50];
unsigned int tm2;
unsigned int tm;
int dat[32][32];
int co;
char d1;
char d2;
int x;
int y;
int ju;
int gx;
int gy;
int tgx;
int tgy;
/* fun grilla */
void grilla(int px,int py){
for(gx=0;gx<=tgx;gx++){
setcolor(4);
line(gx*GP,GP,gx*GP,tgx*GP);
}
for(gy=0;gy<=tgy;gy++){
setcolor(4);
line(GP,gy*GP,tgy*GP,gy*GP);
}
setcolor(1);
rectangle(px*GP,py*GP,(px*GP)+GP,(py*GP)+GP);
rectangle(400,50,450,90);
for(gx=0;gx<=tgx;gx++){
for(gy=0;gy<=tgy;gy++)putpixel(gx+410,gy+60,dat[gx][gy]);}
}
/* didat */
void dbdat() {
gx=0;
gy=0;
for(gx=0;gx<=tgx;gx++){
for(gy=0;gy<=tgy;gy++){
if (dat[gx][gy]>0){
setcolor(dat[gx][gy]);
setfillstyle(2,dat[gx][gy]);
rectangle((gx*GP)+1,(gy*GP)+1,(gx*GP)+GP-1,(gy*GP)+GP-1);
}
}
}
}
/* main */
void main(){
int graphdriver = DETECT, graphmode;
initgraph(&graphdriver, &graphmode, "..<span style="color: #666666; font-weight: bold;">\\bgi"</span>);
setgraphmode(GRM);
tgy=20;
tgx=20;
co=14;
x = 5;
y = 5;
ju = 1;
tm = 1000;
tm2= 1000;
/*
*/
while(ju>0){
/* tm++;
if (tm>=TT){
tm=0;
tm2++;}
if (tm2>=TT2){
tm2=0;
tm=0; */
if (kbhit()) {
te = getch();
switch (te){
case 27: ju=0;
break;
case 72 : if(y>=2) y--;
break;
case 80: if(y<=tgy-2) y++;
break;
case 77 : if(x<=tgx-2) x++;
break;
case 75: if(x>=2) x--;
break;
case 32: dat[x][y]=co;
break;
case 97:co=getch();
break;
case 83:dat[x][y]=0;
setcolor(0);
rectangle((x*GP)+1,(y*GP)+1,(x*GP)+GP-1,(y*GP)+GP-1);
break;
}
/*printf("%d",co);*/
te = 1;
/* cleardevice();*/
grilla(x,y);
dbdat();
}
}
closegraph();
}
el tercero
C++:
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
const MAXX=15;
const MAXY=30;
const TT=29500;
const BT=15000;
const SP=12;
char bl;
char be;
unsigned char gol;
unsigned char gol2;
int tm2;
int bx;
int by;
int te;
long unsigned int tm;
int x;
int y;
int x2;
int ju;
int y2;
char main(){
int graphdriver = DETECT, graphmode;
initgraph(&graphdriver, &graphmode, "..<span style="color: #666666; font-weight: bold;">\\bgi"</span>);
setgraphmode(0);
bx = 320;
by = 100;
x = 10;
y = 80;
y2 = 80;
x2 = 600;
bl = 0;
be = 1;
ju = 1;
tm = 1000;
tm2=100;
gol=0;
gol2=0;
/*
*/
while(ju>0){
tm++;
tm2++;
if (bx>=x2 && by>= y2 && by<= y2 + MAXY) be = 0;
if (bx<=x+MAXX && by>= y && by<= y + MAXY) be = 1;
if (by<=5) bl=1;
if (bx<=0){
bx=320;
by=100;
gol++;}
if (by>=187) bl=0;
if (bx>=630){
bx=320;
by=100;
gol2++;}
if (tm2>BT){
switch(be){
case 1:bx++;
break;
case 0:bx--;
break;
}
switch(bl){
case 1:by++;
break;
case 0:by--;
break;
}
tm2 = 0;
}
if (tm>=TT){
tm=0;
if (kbhit()) te = getch();
cleardevice();
setcolor(5);
line(305,3,305,187);
rectangle(0,3,630,187);
setcolor(1);
rectangle(x,y,x+MAXX,y+MAXY);
setcolor(2);
rectangle(x2,y2,x2+MAXX,y2+MAXY);
circle(bx,by,5);
switch (te){
case 27: ju=0;
break;
case 115 : if(y<=150) y+=SP;
break;
case 119: if(y>=10) y-=SP;
break;
case 107 : if(y2<=150)y2+=SP;
break;
case 105: if(y2>=10) y2-=SP;
break;
}
te = 1;
/* if (kbhit){
setcolor(5);
line(305,3,305,187);
rectangle(0,3,630,187);
setcolor(1);
rectangle(x,y,x+MAXX,y+MAXY);
setcolor(2);
rectangle(x2,y2,x2+MAXX,y2+MAXY);
switch (te){
case 27: ju=0;
break;
case 115 : if(y<=150) y+=SP;
break;
case 119: if(y>=10) y-=SP;
break;
case 107 : if(y2<=150)y2+=SP;
break;
case 105: if(y2>=10) y2-=SP;
break;
}
} */
}
}
closegraph();
printf("goles j1 %d j2 %d",gol,gol2);
return 0;
}
bue espero que les sirva a los que estan aprendiendo C/C++
pero creo que los BGI que use no estan en el comun :S
por que me acurdo que habia echo uno en 1024