Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Struggling a little


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.

  • You cannot reply to this topic
10 replies to this topic

#1 GameC++Expert93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 30 September 2012 - 10:27 AM

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.

Ad:

#2 EngineProgrammer   Members   -  Reputation: 291

Like
0Likes
Like

Posted 30 September 2012 - 10:42 AM

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'. http://www.angelfire...lusin21days.pdf

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! Posted Image


~EngineProgrammer

#3 GameC++Expert93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 30 September 2012 - 10:49 AM

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'. http://www.angelfire...lusin21days.pdf

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! Posted Image


~EngineProgrammer


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.

#4 EngineProgrammer   Members   -  Reputation: 291

Like
1Likes
Like

Posted 30 September 2012 - 11:49 AM

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: http://www.rocksolid...ames/robokill2/

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 )
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)
}

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. Posted Image
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. Posted Image


~EngineProgrammer

#5 GameC++Expert93   Members   -  Reputation: 121

Like
1Likes
Like

Posted 30 September 2012 - 12:05 PM

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: http://www.rocksolid...ames/robokill2/

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 )

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)
}

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. Posted Image
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. Posted Image


~EngineProgrammer


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

#6 GameC++Expert93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 30 September 2012 - 12:29 PM

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 1break;case 2://Code for direction 2break;case 3://Code for direction 3break;case 4://Code for direction 4break;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]

#7 EngineProgrammer   Members   -  Reputation: 291

Like
0Likes
Like

Posted 30 September 2012 - 01:00 PM

This is how my Ball class should look like:
#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
};

And this is how my Paddle class should look like:
#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;
};

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. Posted Image

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

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

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


~EngineProgrammer

Edited by EngineProgrammer, 30 September 2012 - 01:02 PM.


#8 superman3275   Crossbones+   -  Reputation: 1373

Like
0Likes
Like

Posted 30 September 2012 - 01:30 PM

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!
I'm a game programmer and photo editor.

Here's Breakout:
Breakout!

If you need some photo editing done, contact me:
superman3275@gmail.com
if you want some programming help, or are recruiting for a game development team, either PM me on here or email me up there Posted Image!

#9 EngineProgrammer   Members   -  Reputation: 291

Like
0Likes
Like

Posted 30 September 2012 - 01:39 PM

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. Posted Image
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

#10 GameC++Expert93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 30 September 2012 - 01:42 PM

This is how my Ball class should look like:

#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
};

And this is how my Paddle class should look like:
#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;
};

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. Posted Image

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

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

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


~EngineProgrammer


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

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

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


#11 AlexWalters22   Members   -  Reputation: 115

Like
0Likes
Like

Posted 30 September 2012 - 04:10 PM

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.




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.



PARTNERS