• 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.
Sign in to follow this  
Followers 0
phil67rpg

breakout lives

21 posts in this topic

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();
paddle();
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();
	}
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
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
1

Share this post


Link to post
Share on other sites
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);	
	}

0

Share this post


Link to post
Share on other sites

Can you explain why you are calling:

 

brick();

paddle();

ball();

 

inside your drawBitmapText function.

 

 

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.

1

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

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

1

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites

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

Edited by stitchs
1

Share this post


Link to post
Share on other sites
*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.
1

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

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

No you're not. Your code still exhibits major flaws that stand in the way of it ever being a finished and bug-free game. Trying to "finish" it as it stands would require a major overhaul anyway, so I'd say you shouldn't waste any more time on it.
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0