Sign in to follow this  
GameC++Expert93

Struggling a little

Recommended Posts

So yes i know my title has the word expert in it i honestly was just making up a name so don't poke fun please lol. Anyways ive coded c++ for quite awhile now and have c++ pretty much grasped but for the lights of me im really having a hard time in the game programming aspect because i do come from a web development background of programming in PHP for over 5 years but i really wanna dig deeper into game development with c++ and allegro. any ideas as to how to master programming games using the c++ language? i mean i have the basics down and can create small games like pong etc.. but its the bigger games id like some advice on how to plan and code thanks in advance.

Share this post


Link to post
Share on other sites
Hi GameC++Expert93. I would say, first check to be sure it you got all basics done.
Here is a pdf, have a look at the introduction and see if you have learned all the 'days'. [url="http://www.angelfire.com/art2/ebooks/teachyourselfcplusplusin21days.pdf"]http://www.angelfire...lusin21days.pdf[/url]

My first game(school project) was: supersonic warrions 2: Dragonball
We had 2 months for it. So you can already make pong, try to make a game like this as well in a deadline of 2 months.
If you accept the challenge post your progress on this site. I gladly help you with any problem! [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]


~EngineProgrammer

Share this post


Link to post
Share on other sites
[quote name='EngineProgrammer' timestamp='1349023324' post='4985397']
Hi GameC++Expert93. I would say, first check to be sure it you got all basics done.
Here is a pdf, have a look at the introduction and see if you have learned all the 'days'. [url="http://www.angelfire.com/art2/ebooks/teachyourselfcplusplusin21days.pdf"]http://www.angelfire...lusin21days.pdf[/url]

My first game(school project) was: supersonic warrions 2: Dragonball
We had 2 months for it. So you can already make pong, try to make a game like this as well in a deadline of 2 months.
If you accept the challenge post your progress on this site. I gladly help you with any problem! [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]


~EngineProgrammer
[/quote]

Thanks for the link ive looked over it and can say i do have a pretty good understanding of all the days :) idk if it list vectors in their also but i have an understanding of that has well. Mmm i dont guess u could take the time and message me the code to your dragonball game id love to look at it and hopefully use it as a guide if possible :) thanks again for the offer of helping me its just weird cause i know c++ but am having trouble applying it to programming games.

Share this post


Link to post
Share on other sites
I'm sorry but I can't give my code away. Our game has been supported with a Game Engine from our docent Programming.

I assume allegro has matrices?
Check this game: [url="http://www.rocksolidarcade.com/games/robokill2/"]http://www.rocksolid...ames/robokill2/[/url]

Play a few missions, but not to "play" but to observe.
Look how the robot is moved. Look from where the bullets are fired. Look what happens when a bullet has touched a wall. Look how many bullets a breakable box can take. Look at your inventory, map, checkpoints, items you can buy. You can drag and drop items, figure out(on paper) how you should make that work.
For all the things I said: use a piece of paper! Writing down is very important when you want to create a game.

If you aren't interested in this game find a game yourself and do the same thing. Look how the game mechanics work. Write it down, and figure out how you will code those mechanics.
You have trouble with applying it to programming games because you don't have a diagram/sketch. So make one after you got all the game mechanics.

You have game-logic, and game-creation-logic. And they are almost exact the same.
When you play a game for example COD, Your weapon has 40 bullets, you've shot 28 and you are in a safe area, you know you need to reload that moment.
So when you program the class Weapon and class Bullet, you know you need a method: Reload();
When you program a game it's important to find a structure through the game-logic.

This is sort of how my Weapon class of a COD game will look like: ( and I'm not even thinking at the game-creation-logic, just thinking how the weapon should work when I play the game. so at game-logic level )
[CODE]
class Weapon() // You know there are more than 1 type of weapon so I make this class a virtual class
{
Weapon();
virtual ~Weapon();

virtual void SetFireRate(int fireRate); // Maybe you can buff your character with faster firepower.
virtual void SetBulletDamage(int damage); // When you got a death-streak your character can be buffer with more damage the first kill.

static const int DEFAULT_FIRE_RATE = 4;
static const int DEFAULT_DAMAGE = 20;

virtual void Fire();
virtual void Reload();
virtual bool IsActive();
virtual bool IsPrimary();
virtual bool IsSecondary();
virtual bool IsOutOfAmmo();

virtual int GetMagazine(); // returns the size of how many bullets I have left in my magazine(arsenal)
virtual int GetAmmo(); // returns the size of how many bullets I have left in my ammo(so the total amount)
}
[/CODE]

This is how I do it. just writing down the class + the methods. So I don't think at linking classes yet, or data members. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
After I got the methods ready of how I think my game will work. I create a diagram, sketch, structure, plan of how I will program that game.
Thereafter I just start programming class by class, method by method.
Sorry for the long post. [img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img]


~EngineProgrammer

Share this post


Link to post
Share on other sites
[quote name='EngineProgrammer' timestamp='1349027351' post='4985419']
I'm sorry but I can't give my code away. Our game has been supported with a Game Engine from our docent Programming.

I assume allegro has matrices?
Check this game: [url="http://www.rocksolidarcade.com/games/robokill2/"]http://www.rocksolid...ames/robokill2/[/url]

Play a few missions, but not to "play" but to observe.
Look how the robot is moved. Look from where the bullets are fired. Look what happens when a bullet has touched a wall. Look how many bullets a breakable box can take. Look at your inventory, map, checkpoints, items you can buy. You can drag and drop items, figure out(on paper) how you should make that work.
For all the things I said: use a piece of paper! Writing down is very important when you want to create a game.

If you aren't interested in this game find a game yourself and do the same thing. Look how the game mechanics work. Write it down, and figure out how you will code those mechanics.
You have trouble with applying it to programming games because you don't have a diagram/sketch. So make one after you got all the game mechanics.

You have game-logic, and game-creation-logic. And they are almost exact the same.
When you play a game for example COD, Your weapon has 40 bullets, you've shot 28 and you are in a safe area, you know you need to reload that moment.
So when you program the class Weapon and class Bullet, you know you need a method: Reload();
When you program a game it's important to find a structure through the game-logic.

This is sort of how my Weapon class of a COD game will look like: ( and I'm not even thinking at the game-creation-logic, just thinking how the weapon should work when I play the game. so at game-logic level )
[CODE]
class Weapon() // You know there are more than 1 type of weapon so I make this class a virtual class
{
Weapon();
virtual ~Weapon();

virtual void SetFireRate(int fireRate); // Maybe you can buff your character with faster firepower.
virtual void SetBulletDamage(int damage); // When you got a death-streak your character can be buffer with more damage the first kill.

static const int DEFAULT_FIRE_RATE = 4;
static const int DEFAULT_DAMAGE = 20;

virtual void Fire();
virtual void Reload();
virtual bool IsActive();
virtual bool IsPrimary();
virtual bool IsSecondary();
virtual bool IsOutOfAmmo();

virtual int GetMagazine(); // returns the size of how many bullets I have left in my magazine(arsenal)
virtual int GetAmmo(); // returns the size of how many bullets I have left in my ammo(so the total amount)
}
[/CODE]

This is how I do it. just writing down the class + the methods. So I don't think at linking classes yet, or data members. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
After I got the methods ready of how I think my game will work. I create a diagram, sketch, structure, plan of how I will program that game.
Thereafter I just start programming class by class, method by method.
Sorry for the long post. [img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img]


~EngineProgrammer
[/quote]

Aww that helps put it into better perspective , maybe ill start by rewriting the game pong using a more organized way like you did above then send u the code and let you tell me how i did haha call me old fashion but i really get into building some of the older arcade games adding my own twist to them so maybe ill stick with things like pong,breakout, asteroids etc.. for now to get more into game programming then move onto things like RPGS

Share this post


Link to post
Share on other sites
Heres what i have so far and i do find it a lot easier writing out your methods etc.. first then adding functionality to them later

[source lang="cpp"]#include <allegro.h>
/**
*Our class that handles paddle 1 and paddle 2
**/
class Paddles{

};
/**
*Our class that handles the pong ball
**/
class Ball: public Paddles{
public:
int x;
int y;
int direction;
int tmpX;
int tmpY;
void BallMoveRandom();
void DrawBall();

};

void Ball::BallMoveRandom(){
x = 330;
y = 240;
direction = 1;
tmpX = x;
tmpY = y;
/**
*Set up a switch statement to handle 4 different directions
**/
switch(direction){
case 1:
//Code for direction 1
break;
case 2:
//Code for direction 2
break;
case 3:
//Code for direction 3
break;
case 4:
//Code for direction 4
break;

default:
direction = rand() % 4 + 1;
}


}



int main()
{
//Initialize Allegro
allegro_init();

//Set the resolution to 640 x 480 with SAFE autodetection.
set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);

//Install the keyboard handler
install_keyboard();

//Loop until escape is pressed
while(! key[KEY_ESC])
poll_keyboard();

//Exit program
allegro_exit();
return 0;
}

END_OF_MAIN();[/source]

Share this post


Link to post
Share on other sites
This is how my Ball class should look like:
[CODE]
#include "GameTypes" // this will create a struct Position and Velocity
#include "Paddle.h"

class Ball
{
public:
Ball(Position pos, Velocity vel, int radius); // Create a ball with an initial position and velocity. Is not necessarily. radius: how big is the ball.
~Ball();

void Update();
void Draw();

void SetPosition(Position pos);
void SetVelocity(Velocity vel);
void IncreaseVelocity(Velocity velDelta);
void DecreaseVelocity(Velocity velDelta);

void Disable(bool draw); // You can use this when you make a countdown after a point has made. The Boolean will tell to to keep the ball drawn of hided from the screen.
void Enable(bool left); // This will create a random velocity for your ball. The Boolean will tell you what direction you want the random velocity go to.
void CollisionDetection(Paddle& paddle); // This will reserve the X-velocity when you hit a paddle.

private:
Position m_Position;
Velocity m_Velocity;
int m_Radius;
Hitregion* m_pHitRegion; // create new Hitregion.
bool m_bIsEnabled; // init of false
};[/CODE]

And this is how my Paddle class should look like:
[CODE]
#include "GameTypes" // this will create a struct Position and Velocity

class Paddle
{
public:
Paddle(Position pos, Velocity vel); // Create a ball with an initial position and speed. Is not necessarily.
~Paddle();

void Update();
void Draw();

void SetPosition(Position pos);
void SetVelocity(Velocity vel);
void IncreaseVelocity(Velocityve velDelta);
void DecreaseVelocity(Velocity velDelta);

HitRegion* GetHitregion(); // return the hitregion of the paddle. This can also be a RECT if you like to.

private:
Position m_Position;
Velocity m_Velocity;
RECT m_Bounds; // how big the brick will be
HitRegion* m_pHitRegion;
};[/CODE]

All methods will be handled in the main message loop. I'm not familiar with Allegro so I don't know how your keyboard will function to move your paddles. I also don't know how those messages are handled. So with using the methods of the class I can't really help you. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

In the main you need to say something like:
ball.CollisionDetection(paddlePlayer1);
ball.CollisionDetection(paddlePlayer2);

The structs aren't hard to make:
[CODE]struct Position
{
int x, y;
};

struct Velocity
{
int x, y;
};
[/CODE]
Each gamecycle you say: m_Position += m_Velocity;
So maybe you need to put an operator += in your struct ;)


~EngineProgrammer Edited by EngineProgrammer

Share this post


Link to post
Share on other sites
Well, You don't necessarilly need velocity in the Ball, Think about it like this:
Whatever angle the ball starts at, it's always bouncing at the same angle, because the walls and the paddles are rectangles. So essentially, whatever angle it starts at doesn't change. Which means all you have to do is reverse speedx whenever the ball hits a wall and reverse speedy whenever the ball hits a paddle. All of this can be handled by a Check_For_Collision function that says if (Collision) {speedx = -speedx //or speedy = -speedy}. If you set these variables to random in the constructor the games different every time!

Share this post


Link to post
Share on other sites
Yes indeed, but I like to think big.
Assume you want to write PONG REVOLUTION!..

And the features are:
- There is a boost pickup:
The pickup can boost your paddle movement speed, or increase the speed of the ball for a shorten time of for 1 hit.
- There is a a movement pickup:
This pickup will enable your paddle to move a little bit to the left or to the right for a shorten time.

I know it's only a pong game but you never know.. I always think while I create a class "What if I want that feature in that class in the Future?"
Meaning you already write the possibility of that feature. Meaning you don't need to change allot of code when you implement it. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
That's my way of thinking, I don't recommend anyone to follow my way of coding though. Because I also need to ask for help to get my coding better.


~EngineProgrammer

Share this post


Link to post
Share on other sites
[quote name='EngineProgrammer' timestamp='1349031643' post='4985440']
This is how my Ball class should look like:
[CODE]
#include "GameTypes" // this will create a struct Position and Velocity
#include "Paddle.h"

class Ball
{
public:
Ball(Position pos, Velocity vel, int radius); // Create a ball with an initial position and velocity. Is not necessarily. radius: how big is the ball.
~Ball();

void Update();
void Draw();

void SetPosition(Position pos);
void SetVelocity(Velocity vel);
void IncreaseVelocity(Velocity velDelta);
void DecreaseVelocity(Velocity velDelta);

void Disable(bool draw); // You can use this when you make a countdown after a point has made. The Boolean will tell to to keep the ball drawn of hided from the screen.
void Enable(bool left); // This will create a random velocity for your ball. The Boolean will tell you what direction you want the random velocity go to.
void CollisionDetection(Paddle& paddle); // This will reserve the X-velocity when you hit a paddle.

private:
Position m_Position;
Velocity m_Velocity;
int m_Radius;
Hitregion* m_pHitRegion; // create new Hitregion.
bool m_bIsEnabled; // init of false
};[/CODE]

And this is how my Paddle class should look like:
[CODE]
#include "GameTypes" // this will create a struct Position and Velocity

class Paddle
{
public:
Paddle(Position pos, Velocity vel); // Create a ball with an initial position and speed. Is not necessarily.
~Paddle();

void Update();
void Draw();

void SetPosition(Position pos);
void SetVelocity(Velocity vel);
void IncreaseVelocity(Velocityve velDelta);
void DecreaseVelocity(Velocity velDelta);

HitRegion* GetHitregion(); // return the hitregion of the paddle. This can also be a RECT if you like to.

private:
Position m_Position;
Velocity m_Velocity;
RECT m_Bounds; // how big the brick will be
HitRegion* m_pHitRegion;
};[/CODE]

All methods will be handled in the main message loop. I'm not familiar with Allegro so I don't know how your keyboard will function to move your paddles. I also don't know how those messages are handled. So with using the methods of the class I can't really help you. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

In the main you need to say something like:
ball.CollisionDetection(paddlePlayer1);
ball.CollisionDetection(paddlePlayer2);

The structs aren't hard to make:
[CODE]struct Position
{
int x, y;
};

struct Velocity
{
int x, y;
};
[/CODE]
Each gamecycle you say: m_Position += m_Velocity;
So maybe you need to put an operator += in your struct ;)


~EngineProgrammer
[/quote]

Haha u write some pretty advance classes :P i think u should take the expert out of my title and put it in your name :o as for allegro moving the paddle is something like this

[CODE]
if(key[KEY_UP] && paddleY > 0){
--paddleY;

}else if(key[KEY_DOWN] && paddleY < 410){
++paddleY;
}
[/CODE]

Share this post


Link to post
Share on other sites
I always find that a whole lot of prior planning helps when creating a game, even one thought to be very simple. It gives you a clear destination and direction along with a more definite number of steps to get there.

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