breakout lives

Started by
20 comments, last by phil67rpg 11 years ago

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.

Advertisement
thanks for all the help
are there any tutorials I can look at that might help

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)

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.

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.

Feel free to ask for any more information,

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

well what new project should I work on.
*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.
well I really want to finish this game I am so close.

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.

This topic is closed to new replies.

Advertisement