\$10

Image of the Day Submit

IOTD | Top Screenshots

breakout lives

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

21 replies to this topic

#1phil67rpg  Members

Posted 27 March 2013 - 04:39 PM

I am trying to print out the number of lives left to the screen,
void drawBitmapText(char *string,float x,float y,float z)
{
char *c;
glPushAttrib(GL_CURRENT_BIT);
glClear(GL_COLOR_BUFFER_BIT);
brick();
ball();
glColor3f(1.0f,1.0f,1.0f);
glRasterPos3f(x, y, z);
for (c=string; *c != '\0'; c++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c);
}
glPopAttrib();
}

void lives()
{
num--;
strng=itoa(num,buffer_two,10);
drawBitmapText(strng,0.0f,2.0f,0.0f);
}

void Timer(int value)
{
if(x > windowWidth)
{
xstep = -xstep;
}

if( x < -windowWidth)
{
xstep=-xstep;
}

if(y > windowHeight)
{
ystep=-ystep;
}

if(y < -windowHeight)
{
x=0.0f;
y=0.0f;
lives();
ball();
}


#2incertia  Members

Posted 27 March 2013 - 08:26 PM

It would help if we could know what the problem actually was
what

#3phil67rpg  Members

Posted 27 March 2013 - 08:40 PM

well I am trying to print to the screen the number of lives left in my game. I am using the lives() function to print out to the screen but I don't get anything. When the ball goes off the bottom of the screen I want the lives counter to decrement by one. Let me know if you need any more code or information.

#4incertia  Members

Posted 27 March 2013 - 09:24 PM

I'm not particularly familiar with OpenGL, but here are some good questions to consider. Are you sure (0, 2, 0) is actually within the window? Is your window background white (you're printing white text)? Does the current raster position refer to the bottom left or top left of a character? Try outputting the text at (100, 100, 0) and see what happens.
what

#5phil67rpg  Members

Posted 27 March 2013 - 09:27 PM

my background is black and outputting the text as (100,100,0) does not work either.

#6incertia  Members

Posted 27 March 2013 - 09:37 PM

try setting all your matrices to identity matrices right before you draw the text. You might be translating the text without your knowing.

EDIT: Also, it appears as if glColor and glRasterPos are not OpenGL 4 compliant. They may have been deprecated because I can't seem to find them here.

EDIT2: Lighting and texturing may also effect the color of your text because it seems when lighting is on, a lighting equation is used to compute a new primary color for the rasterized pixel.

Edited by incertia, 27 March 2013 - 09:48 PM.

what

#7phil67rpg  Members

Posted 27 March 2013 - 09:50 PM

I am using glut 3.7.6 which works with glColor and glRasterPos. Actually this piece of code works.
void brick_collision()
{
GLint n=0;

if(bricks[2][4]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText(str,4.0f,2.0f,0.0f);
}

if(bricks[2][3]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText(str,4.0f,2.0f,0.0f);
}

if(bricks[2][2]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText(str,4.0f,2.0f,0.0f);
}

if(bricks[2][1]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText(str,4.0f,2.0f,0.0f);
}

if(bricks[2][0]==true)
{
n+=100;
str=itoa(n,buffer,10);
drawBitmapText(str,4.0f,2.0f,0.0f);
}



#8phil67rpg  Members

Posted 28 March 2013 - 04:50 PM

I am still stuck, my code looks right but for some reason it does not work properly. I just need a little hint.

#9stannic  Members

Posted 28 March 2013 - 11:26 PM

Can you explain why you are calling:

brick();

ball();

Also can you explain what brick_collision() does?

Though my guess is that you are clearing the screen every frame, however you are only drawing the "num" for one frame when the "y" leaves the screen.

#10JTippetts  Moderators

Posted 29 March 2013 - 07:40 AM

POPULAR

lives() is incorrect. Every time you call lives() to draw, num is decremented.

You clearly haven't bothered to read the many numerous posts that people have posted in your other threads to try to help you understand how to correctly construct a game loop.

Drawing code and collision code do not belong in the same method together.

Drawing code and state/data altering code (such as num--) do not belong in the same method together.

Drawing code does not belong in any kind of Timer method.

phil67rpg, before you post any more questions on this board, please go back through and read the many useful posts I can see in your posting history. You are still encountering the same problems, stemming from the same mistakes, that you have been for months without any evidence that you have even attempted to understand or even read the posted advice.

To reiterate:

At the heart of a game (any game, from breakout to Call of Duty) lies a loop. In this loop, many basic tasks are repeated over and over and over at a very high rate of speed. These tasks may vary somewhat in detail from game to game, but essentially are basically the same for each game. The basic tasks are:

Handle input from the user (and input from the network, if multiplayer)
Advance timers based on frame time or some other means of calculating time
Advance animations, update physics, move objects, update AI etc... based on elapsed time
Detect, handle, respond to and resolve collisions and other object interactions
Clear the screen
Draw the scene
Draw the UI elements
Swap buffers to present the view to the screen

The exact implementation details of this loop may vary. Some loops, for example, might fix physics/logic updates to a specific fixed rate. However, the basic gist of it is the same. Repeat that loop over and over and over until the game exits.

If you find yourself blurring the line between the basic tasks of the game loop, you are probably making an error. ie, if you are calling drawing code from a collision routine, or from a timer routine, then you are doing it wrong. This is where your errors and problems are coming from. You just don't have a clear idea of the core game loop, and until you do you are going to continue having problems.

#11stitchs  Members

Posted 29 March 2013 - 11:44 AM

In addition to JTippetts post, it seems that there are some vague naming conventions. Now these may seem okay to you however, people trying to contribute in assisting you (like myself) will have a hard time navigating the "what does this function do?" minefield.

The method lives() to me should be renamed to something along the line of 'handle lives', 'do lives' etc. At its basic level it should check to see if some lives altering event occurred, such as the ball going off screen or you make contact with a power-up that increases them. Then you increment/decrement 'num' (should also be renamed, paddle_lives would suffice) by the appropriate amount. This would then be included in the portion of the loop JTippetts describes as:

Detect, handle, respond to and resolve collisions and other object interactions

DrawBitmapText would then occur when you Draw the UI Elements. Can I ask, what do the 3 methods brick(), paddle(), ball() do? Are these the same as lives in that they handle the logic for those objects? Does this mean that in your code you effectively repeat their actions more than once per loop? Or, do you remove them for where they were and put them in the new method you think they should be? Either way, it will start to become messy, un-organised and can actually do more damage when problems like this occur.

Remove these methods from you DrawText function, have the function do what it says on the tin, and perform any action related to drawing text. Keep it simple.

Back on topic, I have to agree with stannic. What probably happens is that, when the ball goes off screen, the lives gets drawn for a split-second and then disappears. If you remove the DrawText from lives and move it to the correct position in the loop, untying it from any sort of 'if' clause, it should show the text constantly. I assume that it works for the Bricks code you posted because 'brick[N][N] == true' refers to the brick existing?

Regards,

Stitchs.

#12phil67rpg  Members

Posted 29 March 2013 - 01:27 PM

thanks for all the help

#13phil67rpg  Members

Posted 29 March 2013 - 01:47 PM

are there any tutorials I can look at that might help

#14BeerNutts  Members

Posted 29 March 2013 - 02:06 PM

I still can't believe phil, with all his struggles to get normal coding principles down, insists on using OpenGL directly with it's 3D interface.  Instead, he could be using one of the many multimedia API's that make drawing, writing text, etc SO EASY (like SFML or SDL) in 2D.

He's just stubborn, and doesn't listen to advise.  Hard to help someone when they do that

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#15phil67rpg  Members

Posted 29 March 2013 - 02:13 PM

sorry for being stubborn, but I have done a lot of work using opengl and c++.I have actually finished my game,I am just adding some finishing touches.

#16stitchs  Members

Posted 29 March 2013 - 02:15 PM

Here is a short article on Naming Conventions, it doesn't take too long to read and should be enough information for you to make effective changes:

http://www.cprogramming.com/tutorial/style_naming_conventions.html

Regarding responsibility, you should really take a step back from your code, and probably this project. It might take too long to modify with different naming conventions and changing all the responsibilities however, what you can do is take away the lessons you've learnt into a new project. One where you can start from the ground up, get your names correct, decide on the responsibilities of each class and method. Ask yourself as you code, using the current problem as an example; "I have named this method XXX (DrawText) however, I am processing YYY (brick logic) in here, is it correct?" Of course the two will link in a small way, how can you display text about the number of bricks on screen, if you don't examine the list of active bricks to see which are alive? But is DrawText, a general helper function probably used multiple times, specific to brick logic?

This is a very specific example, but if you generalise as I did with XXX and YYY, then it is applicable to most areas. I would like to point you to an article on this very site about the subject of pre-visualisation, which touches on Responsibilities in a light way that should be easy to understand:

http://www.gamedev.net/page/resources/_/technical/general-programming/pre-visualization-is-important-r2969

Read these two articles in conjunction with what I have given you, and you should be off to a better start with your next project. Aim to resolve this issue, try and get the text to display, then write down what you did wrong, how you fixed it, and you can use this to identify early issues in your next game.

A final thought; you have been working on Breakout for a long time, and I admire the perseverance, but it might be time to start a fresh. Build your game design with Responsibility and good Naming conventions, and you have an easier time when it comes to coding.

Regards,

Stitchs.

P.S. I agree with BeerNutts here, make life easier on yourself and use SFML or Allegro instead for your next project. It's a bit of a minefield getting into programming without using a hardware accelerated graphics library such as OpenGL. It's a good step-up once you have the principles of an API such as SFML down, but right now, focus on something simpler. There are a lot of videos on these sorts of libraries such as this YouTube channel: http://www.youtube.com/user/CodingMadeEasy?feature=watch

Edited by stitchs, 29 March 2013 - 02:21 PM.

#17phil67rpg  Members

Posted 29 March 2013 - 02:19 PM

well what new project should I work on.

#18FLeBlanc  Members

Posted 29 March 2013 - 02:20 PM

*sigh* I promised myself I wouldn't respond to any more phil threads, but I'm an old softie...

phil, i think part of your problem might be that you are still using GLUT. GLUT, in my experience, is okay for quick one-off prototypes and small demos, but is not really suitable for actual games. The problem with GLUT is that it takes control of the main loop away from you, forcing you to act through callbacks to get anything done. This isn't really appropriate for the main loop structure that games look for. There are other libraries that are far more appropriate for game development. SDL, SFML, GLFW, Allegro, etc... I highly recommend you switch to one of them, and make your life a little bit easier. Once you are working with a library where you control the actual loop, then I recommend the article Fix Your Timestep! It offers an excellent introduction to the way a main loop is structured, and offers justification for switching to a fixed timestep loop. Read it, study it, ask specific questions about it and maybe we can help you finally make some progress.

But please, for the love of God, abandon what you are doing right now. Toss out your lives() method, throw away your drawBitmapText() method, get rid of it all and start clean. It's just not working, man. Let it go. You're just running around in the same old circles, asking the same old questions, and you haven't made any meaningful changes to your code from what it was months and months ago.

#19phil67rpg  Members

Posted 29 March 2013 - 02:27 PM

well I really want to finish this game I am so close.

#20stitchs  Members

Posted 29 March 2013 - 02:27 PM

I would recommend Pong. Key reasons being:

1. It is not dissimilar to the project you just worked on, meaning you can take away the concepts you used to move the ball, move the paddle etc.
2. You can learn your new API in relative safety; you're not having to learn entirely new game mechanics as well as all the functionality of said API.
3. It is different enough that it feels fresh.

Good luck!

Stitchs.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.