This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-04-16 12:04:02

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

A simple C++ Game of Pong

Here i share with u how to make a game on C++ Using the most simple algorithms etc

to make it jst cpy and paste it to a compiler and Make sure u have egavga.bgi file in the INCLUDE Directory and the Bin Directory then u are DONE  big_smile

-------------------------------------------------------------------------------------------------------------------------
Currently Doing  : Rhy's Line Racing on C++  big_smile

you can also ask me to make a remake of your 1s1s scratch projects on C++ as C++ isnt able to do multithreading 1s1s is the best solution. Also 1s1s projects get a huge Speed boost on C++
-------------------------------------------------------------------------------------------------------------------------


PONG:

Code:

#include<iostream.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<graphics.h>
void ball(int x,int y) // a function that prints the ball everytime :D
{circle(x,y,15);
}
void bat(int y) // the function that prints the bat everytime :D
{ line(5,y+30,5,y-30);
}
void score(int x)// to print the score
{ x=10-x;
outtextxy(400,400,"Miss:");
}
void main()
{
clrscr();
cout<<"Welcome to PONG ";
cout<<"press key to begin";

cout<<"\t\tRules of game\n1.U cannot win so its a survival game\n 2.Ur time will count so try to survive the most time \n 3.U have 10 misses to survive";
getch();

float xvel,yvel;
xvel=2;

yvel=1;

int ballx=200,bally=200;

float ypos=200;// board u reader or editor or Dark
float acc=0;
 /* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)  /* an error occurred */
{
   printf("Graphics error: %s\n", grapherrormsg(errorcode));
   printf("Press any key to halt:");
   getch();
   exit(1); /* terminate with an error code */
}

for(int miss=0;miss<=10;)
{ char key;
if(kbhit()) // this checks if keyboard has an input
  {   key = getche();   // this feeds the system with the key value
  }else
{key = 0;
}
if(key=='q') // Now if u press Q anywhere the program will Quit
exit(0);
if(key=='w'&&ypos>0)
{
acc=acc-30;
}
else if(key=='s'&&ypos<400)
{
acc=acc+30;
}
else
{acc=-(acc/2);
}
ypos=ypos+acc;
ballx=ballx+xvel;
bally=bally+yvel;
if(ballx<10)
{miss--;
 ballx=200;
}
if(ballx>600)
{xvel=xvel*-1;
yvel=yvel*-1;
}
if(bally<0||bally>400)
yvel=yvel*-1;

if(ballx<15&&abs(bally-ypos)<20)
{yvel=(yvel*(bally-ypos)/10);
xvel = xvel*-1;
}
cleardevice();// clears the screen
ball(ballx,bally);// draws the ball
bat(ypos);// this draws the bat at the desired position
score(miss);
delay(4);
}
}

I will load a version with b8r comments soon   big_smile

Last edited by fanofcena (2010-04-19 02:26:59)


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#2 2010-04-17 03:33:19

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: A simple C++ Game of Pong

um no1 intrested ???????? ?(scratches head) oh its a bit tooo complex for u guyz


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#3 2010-04-17 11:28:25

Stickman704
Scratcher
Registered: 2009-01-31
Posts: 1000+

Re: A simple C++ Game of Pong

Ya.

Um where do you get the programe for c++


Dun dun dun dun dun dun.... dun dun dun dun dun dun...  tongue

Offline

 

#4 2010-04-17 23:58:52

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: A simple C++ Game of Pong

well to get a program for C++ which is called a compiler u need softwares like

VS2008 or TC3.1 or DevC++ or something related to it  big_smile

all are free to get so its easy i suggest TC3.1 by borland for begginers cause its very supportive  big_smile  to get it u need to do extensive search on the internet  tongue  I got it from ma skools CPU


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#5 2010-04-18 00:54:32

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: A simple C++ Game of Pong

here is the TC 3.1 IDE  big_smile  http://www.4shared.com/file/mK_io5Yp/TC_online.html plz make sure u extract all the files in c: / and to run the ide use

C: /TC/bin/tc.exe

Last edited by fanofcena (2010-04-18 00:55:54)


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#6 2010-04-18 08:06:17

floatingmagictree
Scratcher
Registered: 2008-10-21
Posts: 1000+

Re: A simple C++ Game of Pong

fanofcena wrote:

here is the TC 3.1 IDE  big_smile  http://www.4shared.com/file/mK_io5Yp/TC_online.html plz make sure u extract all the files in c: / and to run the ide use

C: /TC/bin/tc.exe

Uh... fanofcena? Can you kindly, just for one day, use proper grammar? Every time you speak I have to try and decode it and it takes way too long.

Offline

 

#7 2010-04-18 13:12:38

banana500
Scratcher
Registered: 2009-09-06
Posts: 1000+

Re: A simple C++ Game of Pong

Wow, that code is sooo complicated for me. XD

Did you write that yourself?


http://i.imgur.com/jrCyB2r.gif
'Cause I'm NUMBER ONE.

Offline

 

#8 2010-04-18 13:31:33

cruelty247
Scratcher
Registered: 2009-07-22
Posts: 100+

Re: A simple C++ Game of Pong

i know how to print on python XD
i know how to mov memory add memory to memory on assembler
i can print something on assembler
one problem with assembler you can't just say like import x
you have to do loads of stuff and you never see output  smile
wow that is pretty good before you know it you'll have written quaqe lol  smile

Offline

 

#9 2010-04-18 13:33:20

cruelty247
Scratcher
Registered: 2009-07-22
Posts: 100+

Re: A simple C++ Game of Pong

if you break it down into.....
(mind melts trying to figure out how it works!)

Offline

 

#10 2010-04-18 19:42:03

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: A simple C++ Game of Pong

floatingmagictree wrote:

fanofcena wrote:

here is the TC 3.1 IDE  big_smile  http://www.4shared.com/file/mK_io5Yp/TC_online.html plz make sure u extract all the files in c: / and to run the ide use

C: /TC/bin/tc.exe

Uh... fanofcena? Can you kindly, just for one day, use proper grammar? Every time you speak I have to try and decode it and it takes way too long.

WHAT !!!!!!!!! Ok well that meant that the link contains the IDE for C++ . Plz make sure u extract all the files in the package in the c drive . and to run the ide the standard executable is in Cdrive> >TC> >BIN> >TC.exe


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#11 2010-04-18 19:46:07

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: A simple C++ Game of Pong

banana500 wrote:

Wow, that code is sooo complicated for me. XD

Did you write that yourself?

yes i write it my self  tongue  cuz i am a C programmer  tongue  and actually after learning c++ for an year it was as easy as making something on scratch . i think of making rhys and canthairs projects on C++ cause they are nearly 1s1s and run toooooooooo slow on Scratch

Last edited by fanofcena (2010-04-18 19:53:22)


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#12 2010-04-19 02:29:01

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: A simple C++ Game of Pong

cruelty247 wrote:

i know how to print on python XD
i know how to mov memory add memory to memory on assembler
i can print something on assembler
one problem with assembler you can't just say like import x
you have to do loads of stuff and you never see output  smile
wow that is pretty good before you know it you'll have written quaqe lol  smile

aw yes i agree with you C++ can cause brain meltdown . take a tip : use scratch to visualise the code . I generally write the code on Scratch ( in brain ofcourse) then visualise it and then convert it to C++


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

Board footer