• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

whereiswez

Pong in ASCII

2 posts in this topic

Hello yet again .. Using C++ Command Line ? .. and only conio.h and iostream.h .. it should be possible to write Pong in ASCII right ? kay .. in pascal there was something we used like (if not keypressed) do such .. how would i do that in c++ ? .. so that the ball bounces all over, while receiving keystrokes or not ? i am trying to keep the libraries to a minium tho, coz the more there are the more complexed it seems to get concerning repetitive definitions which it doesnt seem to like .. thanx
0

Share this post


Link to post
Share on other sites
Yup you can do pong with iostream.h and conio.h
I recall for text-based games, compilers like DJGPP and Borland work best. Here it is:

char KeyPressed;
if ( kbhit () )
KeyPressed = getch();

kbhit() checks the keyboard buffer if there is a button press waiting to be handled. getch() takes that and puts it into a char variable. kbhit () returns 1 (true) if the user hit a key, and 0 if the user didn''t (before getch() was last called).

Good luck!
0

Share this post


Link to post
Share on other sites
THANKS ! btw ! :D

>

!!! ---> K ! .. I'm stuck again !

BC++ Command Line, NO TASM MASM OR ASM .. though ..

I have looked about for posts on multiple key down handling ..
I'm not too sure on how they work, and also the posts I've read concern Direct this and that, which I'm not using ..

Can somebody give me a bit more than a hint on how to make the game so that :

Player 1 (left paddle) can continuously move up, while player 2 (right paddle) continuously moves up, without any player letting go of the "UP" keys ?

Also .. ASCII GFX wise, whats the better way to work out the whole collision, deflection thing ? ..

I've got mine to work (The whole if hit top center or low, and from direction, then reverse direction if this and that), but I think possibly if I could substitute actual calculated formulas, the game would be a bit more realistic. (Then again, I'm working ASCII *LOL*) .. I'm more after the concept, and equations ..

And YES .. my maths is lost and further more a bit off but the PONG game I've written so far doesn't use hectic maths but works, probably slower yes, but i'd like to make it work better.

If anyone needs to see my messy bit of code to try and figure out what I mean about it working, but not as well as I'd like it to, here it is :

  
/*
to do :

two players .. need simultaneous keypress function
computer ai
if ball goes to extent, then set score, regame !
prod menu system
scoring system ? ..

ball speed / game speed?

add formulas for curve balls !

random flying things to collect, exp pad, speed ball, slow ball, bigger ball ?
*/

#include <conio.h>
#include <iostream.h>
#include <time.h>
#include <stdlib.h>

struct myballpos
{
int x;
int y;
} ballpos;

struct mypaddle
{
int x;
int y;
int ex;
} lpad;

struct mypaddle rpad;

void wait (int msec)
{
clock_t endwait;
endwait = clock () + (msec * CLK_TCK/1000);
while (clock() < endwait) {}
};

void drawball(int x, int y, int maskoff)
{
gotoxy(x,y);
switch (maskoff)
{
case 0 :
cout << " ";
break;
default :
cout << "*";
};
};

void drawpad(int x, int y, int ex, int maskoff)
{
for (int i=y-ex;i<=y+ex;i++)
{
gotoxy(x,i);
switch (maskoff)
{
case 0 :
cout << " ";
break;
default :
cout << "H";
};
};
};

int main()
{
srand(time(NULL));

char ch;

int gamespeed = 50;
int ai = 1;

int strchmax = 5;
int strch = rand() % strchmax;
int strchc = strch;
int endgame = 0;
int l2r = rand() % 1; // from left to right
int b2t = rand() % 1; // from bottom to top

/*
init ball , l pad, r pad positions
*/
ballpos.x = 40;
ballpos.y = 12;

lpad.x = 15;
lpad.y = 12;
lpad.ex = 3;

rpad.x = 65;
rpad.y = 12;
rpad.ex = 3;

clrscr();

/*
begin the game loop ! :D
*/

while (endgame==0)
{
/*
if AI enabled then GAME ON WOOHOO ! :D
*/
if (ai == 1)
{
drawpad(rpad.x, rpad.y, rpad.ex, 0);
if ((ballpos.y > rpad.ex) && (ballpos.y <= 24-rpad.ex))
rpad.y = ballpos.y;
};

drawpad(lpad.x, lpad.y, lpad.ex, 1);
drawpad(rpad.x, rpad.y, rpad.ex, 1);

/*
check which keys are pressed, affect the assigned objects movement
check extents of pad movement
*/
if (kbhit())
{
ch = getch();
switch (ch)
{
case '`' :
{
endgame = 1;
};
break;
case '+' :
{
if (gamespeed > 0)
gamespeed = gamespeed -1;
};
break;
case '-' :
{
if (gamespeed < 50)
gamespeed = gamespeed +1;
};
break;
case 's' :
{
if (lpad.y-lpad.ex > 1)
{
drawpad(lpad.x, lpad.y, lpad.ex, 0);
lpad.y = lpad.y-1;
drawpad(lpad.x, lpad.y, lpad.ex, 1);
};
};
break;
case 'x' :
{
if (lpad.y+lpad.ex < 24)
{
drawpad(lpad.x, lpad.y, lpad.ex, 0);
lpad.y = lpad.y+1;
drawpad(lpad.x, lpad.y, lpad.ex, 1);
};
};
break;
case '5' :
{
if (rpad.y-rpad.ex > 1)
{
drawpad(rpad.x, rpad.y, rpad.ex, 0);
rpad.y = rpad.y-1;
drawpad(rpad.x, rpad.y, rpad.ex, 1);
};
};
break;
case '2' :
{
if (rpad.y+rpad.ex < 24)
{
drawpad(rpad.x, rpad.y, rpad.ex, 0);
rpad.y = rpad.y+1;
drawpad(rpad.x, rpad.y, rpad.ex, 1);
};
};
break;
};
};

drawball(ballpos.x,ballpos.y,0);

/*
check the stretch of the ball distance to follow
check the distance the ball has followed to the stretch
check the direction of the ball from top to bottom or reversed
reverse the direction
*/
if (strchc > 0)
{
strchc = strchc -1;
}
else
if ((strchc == 0) && (strch != 0))
{
strchc = strch;
if (ballpos.y < 2)
{
b2t = 0;
}
else
if (ballpos.y > 23)
{
b2t = 1;
};

switch (b2t)
{
case 0 :
ballpos.y = ballpos.y +1;
break;
case 1 :
ballpos.y = ballpos.y -1;
break;
};
};

/*
check if the ball reaches boundary limits
change direction from left to right
reverse the direction
*/
if (ballpos.x > 79)
{
l2r = 0;
}
else
if (ballpos.x < 2)
{
l2r = 1;
}

/*
check if ball hits LEFT paddle ! :D
*/
if ((ballpos.x == lpad.x) && (ballpos.y > lpad.y-lpad.ex-1) && (ballpos.y < lpad.y+lpad.ex+1))
{
l2r = 1;
// if hit TOP
if ( ballpos.y < (lpad.y-lpad.ex) + (((lpad.ex*2)+1)/3) )
{
// if going DOWN
if (b2t == 0)
{
if ((strch <= strchmax) && (strch > 1))
strch = strch -1;
else
if (strch < 1)
strch = strchmax;
}
else
// if going UP
if (b2t == 1)
{
if ((strch < strchmax) && (strch >= 1))
{
strch = strch +1;
b2t = 0;
}
else
if ((strch == strchmax) || (strch == 0))
{
if (strch == 0)
strch = strchmax;
b2t = 0;
};
};
}
else
// if hit BOTTOM
if ( ballpos.y > (lpad.y+lpad.ex) - (((lpad.ex*2)+1)/3) )
{
// if going DOWN
if (b2t == 0)
{
if ((strch < strchmax) && (strch >= 1))
{
strch = strch +1;
b2t = 1;
}
else
if ((strch == strchmax) || (strch == 0))
{
if (strch == 0)
strch = strchmax;
b2t = 1;
};
}
else
// if going UP
if (b2t == 1)
{
if ((strch < strchmax) && (strch > 1))
strch = strch -1;
else
if (strch < 1)
strch = strchmax;
}
};
};

/*
check if ball hits RIGHT paddle ! :D
*/
if ((ballpos.x == rpad.x) && (ballpos.y > rpad.y-rpad.ex-1) && (ballpos.y < rpad.y+rpad.ex+1))
{
l2r = 0;
// if hit TOP
if ( ballpos.y < (rpad.y-rpad.ex) + (((rpad.ex*2)+1)/3) )
{
// if going DOWN
if (b2t == 0)
{
if ((strch <= strchmax) && (strch > 1))
strch = strch -1;
else
if (strch < 1)
strch = strchmax;
}
else
// if going UP
if (b2t == 1)
{
if ((strch < strchmax) && (strch >= 1))
{
strch = strch +1;
b2t = 0;
}
else
if ((strch == strchmax) || (strch == 0))
{
if (strch == 0)
strch = strchmax;
b2t = 0;
};
};
}
else
// if hit BOTTOM
if ( ballpos.y > (rpad.y+rpad.ex) - (((rpad.ex*2)+1)/3) )
{
// if going DOWN
if (b2t == 0)
{
if ((strch < strchmax) && (strch >= 1))
{
strch = strch +1;
b2t = 1;
}
else
if ((strch == strchmax) || (strch == 0))
{
if (strch == 0)
strch = strchmax;
b2t = 1;
};
}
else
// if going UP
if (b2t == 1)
{
if ((strch < strchmax) && (strch > 1))
strch = strch -1;
else
if (strch < 1)
strch = strchmax;
}
};
};

/*
increase the ball position from left to right or reverse
*/
switch (l2r)
{
case 0 :
ballpos.x = ballpos.x -1;
break;
case 1 :
ballpos.x = ballpos.x +1;
break;
};

/*
statistics check
*/

gotoxy(1,25);
cout << "b.x:" << ballpos.x << " ";
cout << "b.y:" << ballpos.y << " ";
cout << "sc:" << strchc << " ";
cout << "s:" << strch << " ";
cout << "l.x:" << lpad.x << " ";
cout << "l.y:" << lpad.y << " ";
cout << "l.ex:" << lpad.ex << " ";
cout << "r.x:" << rpad.x << " ";
cout << "r.y:" << rpad.y << " ";
cout << "r.ex:" << rpad.ex << " ";
cout << "gs:" << gamespeed << " ";

wait(0);

drawball(ballpos.x,ballpos.y,1);
wait(gamespeed);
};

return 0;
}


Edited by - whereiswez on July 7, 2001 12:33:40 PM
0

Share this post


Link to post
Share on other sites