Hey anyone know c++...i am starting to learn it now and wondered if I could get any pointers....
C++
Collapse
X
-
Tags: None
-
Comment
-
i think c++ is easy; devlop a personal style and stick with it, that will help alot; you could ask vxdx he wrote snake and pong in c++, probably the best at c++ that i knowOriginally posted by VxDxStick it in her butt and pee.Comment
-
C++ isn't that hard to learn.. in my opinion Java is better, C++ is too lenient in the things you can do sometimes (which can be good or bad).
If you have any general questions about C++, i can help you out there.Comment
-
When your learning c++ it's good to look at the code in the book and understand whats happening for example
Some C++ books are heavy n useless information so when you get the basic idea of what something does I recommend you right it down so you don't forget with all the other stuff in the book.
cout and cin are important for beginners. it's not that hard to learn if your in algebra or above thats all i have to sayAnime, DDR, and a coke.Comment
-
that's an early version of pong I wrote.Code:#include<conio.h> #include<iostream.h> #include<dos.h> #include<mem.h> #include<stdlib.h> #include<math.h> //--------------------------------- //video unsigned char *vga = (unsigned char *) MK_FP(0xA000, 0); void setTEXT() { _AX= 0x0003; geninterrupt(0x10); } void setMCGA() { _AX = 0x0013; geninterrupt (0x10); } void MEMPutpixel (int x, int y, unsigned char Col) { memset(vga+x+(y*320),Col,1); } //video //------------------------------ void menu(); int igmenu(); void drawball(); void drawpaddle1(int); void drawpaddle2(int); void drawtable(); void hitproj(); void supar(); void calcbpos(); const int xboardlimleft=40, xboardlimright=280, yboardlimtop=40, yboardlimbottom=160, paddlewalldist=10, paddlemovedist=4; int color, randcolor = 0, speed, bx=160, by=100, p1y=100, p2y=100, quit=0, dir=-1, x=0, y=0; float proj=1, tempx=160, tempy=100; //////////////////////////////////////////////////////////////////////////////// //MAIN////////////////////////////////////////////////////////////////////////// void main() { int key=72; while(igmenu()) { bx=160; by=100; p1y=100; p2y=100; quit=0; dir=-1; x=0; y=0; proj=1; tempx=160; tempy=100; menu(); setMCGA(); drawtable(); drawpaddle1(2); drawpaddle2(2); delay(2000); bx=160; x=160; by=100; y=100; while(bx!=xboardlimleft && bx!=xboardlimright) { if(randcolor==1)color=random(16); drawball(); if(kbhit()) { key = getch(); } switch(key) { case 72:p2y-=paddlemovedist; drawpaddle2(1); break; case 80:p2y+=paddlemovedist; drawpaddle2(0); break; case 97:p1y-=paddlemovedist; drawpaddle1(1); break; case 122:p1y+=paddlemovedist; drawpaddle1(0); break; case 27:igmenu(); } key=0; hitproj(); delay(3*speed); calcbpos(); } randcolor=0; } getch(); } //END MAIN////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// void menu() { cout<<"Color 1 - 16..."; cin>>color; if(color ==0){randcolor=1;color = 15;} color-=1; cout<<"\n\nSpeed 1-15 (15 = slow)..."; cin>>speed; } void supar() { int c=0 , x=160 , y=100 , vect=0 , colo=10 , key; randomize(); while(key != 27) { switch(vect) { case 0: x=x+1; break; case 1: y=y-1; break; case 2: x=x-1; break; case 3: y=y+1; break; } if(c==0)colo=10; if(c==30000)colo=0; MEMPutpixel(x,y,colo); c++; switch(random(7)) { case 0: vect=random(4); } if(kbhit())key = getch(); } } int igmenu() { int ch; setTEXT(); cout<<"1: Continue\n"; cout<<"2: Quit\n"; cout<<"666: FOR A SUPAR TIME\n\n"; cin>>ch; if(ch==2)exit(0); setMCGA(); if(ch==666)supar(); return 1; } void drawball() { MEMPutpixel(bx,by,color); //for(int xx=bx-10;xx<=bx+10;xx++){ //for(int yy=by-10;yy<=by+10;yy++){ //MEMPutpixel(xx,yy,color);}} //for(int xx=x-10;xx<=x+10;xx++){ //for(int yy=y-10;yy<=x+10;yy++){ //MEMPutpixel(xx,yy,0);}} MEMPutpixel(x,y,0); } void drawpaddle1(int ud) { int e; if(p1y>yboardlimtop && p1y<(yboardlimbottom-16)) for(e=0 ; e<16 ; e++){MEMPutpixel((xboardlimleft+paddlewalldist),(p1y+e),color);} if(ud==1 && p1y>yboardlimtop && p1y<(yboardlimbottom-16)) for( int jig=1;jig<5;jig++)MEMPutpixel((xboardlimleft+paddlewalldist),p1y+16+jig,0); if(ud==0 && p1y>yboardlimtop && p1y<(yboardlimbottom-16)) for( int jig=1;jig<5;jig++)MEMPutpixel((xboardlimleft+paddlewalldist),p1y-jig,0); } void drawpaddle2(int ud) { int e; if(p2y>yboardlimtop && p2y<(yboardlimbottom-16)) for(e=0 ; e<16 ; e++){MEMPutpixel((xboardlimright-paddlewalldist),(p2y+e),color);} if(ud==1 && p2y>yboardlimtop && p2y<(yboardlimbottom-16)) for( int jig=1;jig<5;jig++)MEMPutpixel((xboardlimright-paddlewalldist),p2y+16+jig,0); if(ud==0 && p2y>yboardlimtop && p2y<(yboardlimbottom-16)) for( int jig=1;jig<5;jig++)MEMPutpixel((xboardlimright-paddlewalldist),p2y-jig,0); } void drawtable() { for(int y=yboardlimtop ; y<yboardlimbottom ; y++) {MEMPutpixel(xboardlimleft,y,color); MEMPutpixel(xboardlimright,y,color);} for(int x=xboardlimleft ; x<xboardlimright ; x++) {MEMPutpixel(x,yboardlimtop,color); MEMPutpixel(x,yboardlimbottom,color);} } void hitproj() { // | add 2 // | add 2 // | add 2 // | add 1 // | add 1 // | add .5 // | add .5 // | add 0 // | add 0 // | sub .5 // | sub .5 // | sub 1 // | sub 1 // | sub 2 // | sub 2 // | sub 2 //dir <- = -1 1 = -> //when hit, ball changes direction and slope to the opposites x=bx; y=by; if(by == (yboardlimtop+1) || by == (yboardlimbottom-1)) proj = -proj; if(bx == (xboardlimleft+1+paddlewalldist) && dir == -1) switch(by-p1y) { case 0: case 1:dir=1; proj+=2; break; case 2: case 3:dir=1; proj+=1; break; case 4: case 5:dir=1; proj+=.5; break; case 6: case 7:dir=1; proj+=.2; break; case 8: case 9:dir=1; proj-=.2; break; case 10: case 11:dir=1; proj-=.5; break; case 12: case 13:dir=1; proj-=1; break; case 14: case 15:dir=1; proj-=2; break; } if(bx == (xboardlimright-1-paddlewalldist) && dir == 1) switch(by-p2y) { case 0: case 1:dir=-1; proj-=2; break; case 2: case 3:dir=-1; proj-=1; break; case 4: case 5:dir=-1; proj-=.5; break; case 6: case 7:dir=-1; proj+=.2; break; case 8: case 9:dir=-1; proj-=.2; break; case 10: case 11:dir=-1; proj+=.5; break; case 12: case 13:dir=-1; proj+=1; break; case 14: case 15:dir=-1; proj+=2; break; } } void calcbpos() { /* if(dir == 1) { if(proj==1){bx++;by--;} else{bx++;by++;} }else{ if(proj==1){bx--;by++;} else{bx--;by--;} } */ if(dir == 1) { if(proj>0) { if(proj>=1) {tempx+=1/proj;tempy-=1;} else {tempx+=proj;tempy-=1;} } if(proj<0) { if(proj<=-1) {tempx-=1/proj;tempy+=1;} else {tempx-=proj;tempy+=1;} } if(proj==0)tempx+=1; } if(dir == -1) { if(proj>0) { if(proj>=1) {tempx-=1/proj;tempy+=1;} else {tempx-=proj;tempy+=1;} } if(proj<0) { if(proj<=-1) {tempx+=1/proj;tempy-=1;} else {tempx+=proj;tempy-=1;} } if(proj==0)tempx--; } bx=tempx; by=tempy; }
As for tips, make sure you know why what you write works, it will help in the long run. Also, if you ever think of a problem that you wish could go faster (lets say for a math class or something) write a program for it. It will help you get comfortable with the basic ideas.[/code]Comment
-
Wow, nice job on the Pong program. You say that's an earlier version of it.. does that mean you have a more efficient way or what?
Out of curiosity, how old are you?Comment
-
-
Later versions were more efficient, had more features, more accurate ball physics and such.Originally posted by flipmaster99Wow, nice job on the Pong program. You say that's an earlier version of it.. does that mean you have a more efficient way or what?
Out of curiosity, how old are you?
I'm 16.
I have a pretty good snake too. I just don't know where it is.Comment
-

209

Comment