is it possible to create a bouncing text using a loop(any loop(for, while, or do while)) in c++..if so, the problem is to create a program that accept a text then the text will bounce on the screen.. i already have an idea on how to start the program.. but my problem is how to start bouncing the text and how to end... any help will do.. im not asking for a code but a psuedocode will do... many thnx to your help.. :)

Recommended Answers

All 4 Replies

In what way do you want it to bounce? Up-and-down or around the screen, or some other implementation?

If it's just around the screen, you can give the object velocity (some dx and some dy) where dx is the rate at which it travels along the horizontal (and its horizontal direction), and dy is the rate at which it travels along the vertical (and its vertical direction).

If you're just outputting this to the console screen, you're going to probably need to call some windows functions or lots (and I mean lots) of formatting functions if you plan to do this without windows.h and no GUI library. You need to find a way to determine a position on the console window and then calculate its new position per increment of the text moving.

If you're using a GUI library, this will be a lot easier.

In either case, you're going to have to have some bounds. You want the text to bounce as it hits the edges of the screen. Basically when the text "hits" the left side of the screen or right side be sure to reverse the direction of dx, and likewise if the text "hits" the top or bottom reserve the direction of dy.

If its up and down you'll have to determine its initial height, gravity (downward acceleration), mass (can be dummy mass like 1), its upward acceleration from bouncing off the ground, and its desired final return height on its way up from bouncing off of the ground. You might need some more info but these concepts are a start... for example...

Let's say you have text "Hello World!" You want to emulate dropping it, then when it reaches the bottom of the screen it bounces up, and you want its upward acceleration on impact to be much less than its downward acceleration so its final upward height decreases. The formula--

distance = initialVelocity * time + .5 * acceleration * time^2

--might be useful because each _pausetime call, you need to know what the object's velocity is and the distance it has covered (because if it has reached the bottom we need to make it bounce up). You know how much time has elapsed, and you can have ideal deceleration and diminishing acceleration per bounce (initial upward acceleration is 7.6, then 5.5 then 3.4, or whatever diminishing factor you would prefer).

http://www.physicsclassroom.com/class/1dkin/u1l6c.cfm

i want it to bounce around the screen...
hmmm haven't tried the GUI in C, im just new in programming thats why im not familiar in the libraries... i get your idea on the vertical and horizontal directions, but how will i get the maximum vertical and horizontal value of the screen...? or is there a defined size for the height and width of the screen....?

one more thing im sorry for the wrong post this is not a C++ program im doing it in Turbo C... :)

Turbo C has conio.h, which you should include, for gotoxy(), so it's easy to put the text chars, wherever you want it to go. This works fine in Windows XP. (For other Windows user's, it's also easy, just include <windows.h> and use the API SetConsoleCursorPosition().)

You have to decide what kind of bounce you want --> and do that FIRST. Then people here can give you specific advice that is really useful.

ok thnx sir... ill post again.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.