Advertisement

Simple Game for Beginner

Started by September 13, 2006 04:16 PM
10 comments, last by Wysardry 18 years, 4 months ago
Hello Everyone, I'm a novice when it comes to C++ programming, being a JAVA programmer for a number of years. I'm interested in designing a game, a very simple game, that I know can be done in JAVA, abut id like to have a go in C++. All i want to do is, create a football game: 2 teams (initially controlled by humans) circles for players smaller circle for ball screen scrolls left and right with camera shot of player always in middle of screen Basically a bog standard and extremely simple football game .exe that can be run full screen. Now where do I start? Who can offer some advice? Any pointers will be very handy. Many Thanks, Nigel Jones
Well, I don't know C++. But what I would do, is first I would learn the basics of C++, and make some extremely simple games that take a day or less to make, to make sure I knew how to deal with graphics, however you are going to use them. Then, to start out with the project, I would first make just a single player on the screen that you could control with the arrow keys, then add scrolling, then more players, AI etc. Just build up the game until I had everything I wanted.
God is not all-powerful, as he cannot build a wall he cannot jump.Stelimar Website: eddy999999.ed.funpic.org/Stelimar/index.html
Advertisement
If you want to do that program in c++, I highly recommend using SDL for your graphics. Its a really easy to use, cross platform graphics API.

Other than that I would just recommend making a few console based c++ programs first just to get used to some of the things that are quite different from Java to c++.
Nice one cheers, I'll start having a go at these. Let you know how i get on....
I have no experience with SDL but I know Allegro (link 1 link 2) is also designed to be easy to use, and is also cross-platform.

Just to give you an example, these few lines of code (taken from the tutorial mentioned in the next code block) initialize everything, load a picture, display it, wait for a key, and exit the program.

#include <allegro.h> // You must include the Allegro Header fileint main(int argc, char *argv[]) {	allegro_init(); // Initialize Allegro 	install_keyboard(); // Initialize keyboard routines	set_color_depth(16); // Set the color depth	set_gfx_mode(GFX_AUTODETECT, 640,480,0,0); // Change our graphics mode to 640x480	BITMAP *my_pic = NULL; // Declare a BITMAP called my_pic, setting it's initial value to NULL	my_pic = load_bitmap("picture.bmp", NULL); // Load our picture	blit(my_pic, screen, 0,0,0,0,480,360); //Draw the whole bitmap to the screen at (0,0)	readkey();// Wait untill a key is pressed	destroy_bitmap(my_pic); //Release the bitmap data	return 0; // Exit with no errors }END_OF_MAIN()


And here's everything with detailed comments.

/*******************Allegro Newbie TutorialbyLoomSofthttp://loomsoft.netemail: jay@loomsoft.net*******************//* Allegro Newbie Tutorial : Lesson 2 - Bitmaps  * This lesson will initialize allegro, set up keyboard support,  * show a single bitmap, then wait for a keypress. Upon the keypress  * the program will then quit. */// Here is your first line. You must include the allegro header file or else nothing will work!#include <allegro.h> // You must include the Allegro Header file/* Our generic main function. */int main(int argc, char *argv[]) {		// Now we want to initialize allegro just as we did in our last lesson.	allegro_init(); // Initialize Allegro 	// Now we want to install the keyboard just as we did in our last lesson.		install_keyboard(); // Initialize keyboard routines		/* This next step is something new. When you actually draw bitmaps to the screen you must 	 * specify a color depth that the screen will have.	 * 	 * set_color_depth will change the current color depth. 	 * 	 * Available depths are 8,15,16, 24, and 32. 	 * A color depth of 8 requires a pallete to be loaded with each bitmap, so we will not use it. 	 * A color depth of 32 can use a lot of resources, so we will either use 15 or 16 in order to ensure 	 * maximum compatabiliy between machines.	 *	 * Make sure that you change the color depth before you change the screen resolution. 	 * If you fail to do so, your bitmaps will not display with the correct colors!	 */	set_color_depth(16); // Set the color depth	set_gfx_mode(GFX_AUTODETECT, 640,480,0,0); // Change our graphics mode to 640x480		/* This is the BITMAP structure. 	 * Every time you want to create an image to display, or to draw to, 	 * you must declare it with BITMAP, just like when you want an integer, 	 * you declare it with int. Since BITMAP in the allegro libarary is a pointer, 	 * every instance of a bitmap you create must be preceded by a *	 */	BITMAP *my_pic = NULL; // Declare a BITMAP called my_pic, setting it's initial value to NULL		/* Now, the bitmap my_pic is "empty". In order to load a picture into it, 	 * you must call the function load_bitmap(); 	 *	 * Next, we will load a bitmap image from the hard disk into the bitmap my_pic.	 *	 * Here are what the parameters mean:     *	load_bitmap("Location of the bitmap", pallete);	 *	 * In place of the pallete, we will pass NULL - meaning that no pallete is used/needed. 	 *	 * We can't just call the function load_bitmap by itself, however. 	 * We must specify that we are loading the bitmap into the memory of my_pic. It is done like so: 	 * (note, the bitmap must actually exist at this location. If not, the program will crash when 	 * trying to load it. Functions exist to check for such errors, but they will be left out for 	 * now to keep this lesson ultra-simple)	 */	my_pic = load_bitmap("picture.bmp", NULL); // Load our picture	 	 	/* Now that our bitmap is loaded into memory, we want to display it onto the screen. 	 * To do this we use a function called blit. Here are the parameters: 	 *	 * blit(bitmap to draw, destination bitmap (usually the screen), clip x, clip y, x position, y position, width, height); 	 *	 * As you can see, blit offers a lot of functionality. 	 * The clipx and clipy will be the upper left hand corner of the bitmap that you want to copy. 	 * For instance, if you use 0,0 - you will get the bitmap from the top left corner exactly. 	 * However, if you use 50,50 - you will get the bitmap using the position 50,50 as the upper left hand 	 * corner. You also need to specity the width and height. This will allow you to clip the image from the 	 * other sides. Don't worry, we will demonstrate all the capabilities of blitting in the upcoming lessons.	 * 	 * Now, lets just display the entire bitmap in the upper left hand corner of the screen	 */	blit(my_pic, screen, 0,0,0,0,480,360); //Draw the whole bitmap to the screen at (0,0)		/* We now want to wait for a keypress before we exit the program. */	readkey();// Wait untill a key is pressed		/* The next step is critical before exiting the program.	 * The destroy_bitmap function is used to clear out the space in memory that a bitmap was utilizing. 	 * Make sure you destroy all bitmaps that you used in your program, so garbage data doesn't stay behind in memory.	 */	destroy_bitmap(my_pic); //Release the bitmap data		/* Return 0 at the end of main, indicating a exit without errors */	return 0; // Exit with no errors }/* Add the allegro specific END_OF_MAIN() */END_OF_MAIN() // This must be called right after the closing bracket of your MAIN function. 			  // It is Allegro specific.
Quote:
Original post by nigel_jones
All i want to do is, create a football game


Seeing that you are from Sheffield, I take it you mean soccer (just to make it clear for any American readers?)

As you know how to do it in Java already and have known it for a number of years, I would start off with you are going to be least familiar with - the graphics. The engine, the structure... it all can be pretty much the same in C++ as it is in Java.

rip-off already suggested the SDL - I guess I would concur. That has loads and loads of documentation and tutorials kicking around for it.

The biggest difference is that in C++ is the way the memory is handled. Things declared on the stack clean up themselves. Things declared dynamically with new have to be delete'd. Pointers are just that, they are like a sign redirecting where to look for something rather then actually being that thing. And destroying that sign doesn't get rid of what it's pointing at. Same as making a sign to something that isn't there doesn't mean it will magically come in to existance. new and delete actually create and destroy the stuff that's being pointed at.

It'll all become clearer once you get in to it.
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
Advertisement
Hey all, thanks for taking the time to reply to this! It's very much appreciated!
Quote:
Original post by nigel_jonesI'm interested in designing a game, a very simple game, that I know can be done in JAVA, abut id like to have a go in C++.


Stolen from elsewhere on the forum:
Quote:
For those of you that wanna learn C++: http://cplusplus.com/doc/tutorial/

sites that will help you learn directx:

http://www.pieterg.com/Tutorials.php
http://www.codesampler.com/dx9src.htm
http://www.c-unit.com/tutorials/
http://www.drunkenhyena.com/cgi-bin/directx.pl
http://msdn.microsoft.com/directx/
http://www.gamedev.net/reference/list.asp?categoryid=24

sites that will help you learn open gl :

http://www.lighthouse3d.com/opengl/tutorials.shtml
http://fly.cc.fer.hr/~unreal/theredbook/
http://nehe.gamedev.net/
http://192.48.159.181/resources/tutorials/
http://www.eecs.tulane.edu/www/Terry/OpenGL/Introduction.html
http://www.codecolony.de/opengl.htm
http://www.lighthouse3d.com/opengl/
http://www.gamedev.net/reference/list.asp?categoryid=31

sites that will help you learn game design:

http://www.gamedev.net/reference/list.asp?categoryid=23
(about the only good one i could find)

general sites:

www.devmaster.net
http://www.gamedev.net/reference/list.asp?categoryid=23
http://www.gamasutra.com/



http://www.gamedev.net/community/forums/topic.asp?topic_id=392994

http://gpwiki.org/index.php/C:SDL_tutorials

http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/index

http://sol.gfxile.net/gp/

And probably the best one: http://lazyfooproductions.com/SDL_tutorials/index.php

-----------------"Building a game is the fine art of crafting an elegant, sophisticated machine and then carefully calculating exactly how to throw explosive, tar-covered wrenches into the machine to botch-up the works."http://www.ishpeck.net/

Quote:
Original post by nigel_jones
2 teams (initially controlled by humans)
circles for players
smaller circle for ball
screen scrolls left and right with camera shot of player always in middle of screen

How about simplifying it even more and only having one person per team? Basically, it would be the same as air hockey.

This topic is closed to new replies.

Advertisement