Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Looking for a Game Tutorial

This thread is locked; no one can reply to it. rss feed Print
 1   2   3   4 
Looking for a Game Tutorial
Gabriel Campos
Member #12,034
June 2010
avatar

Hi everybody...
I am looking for a tutorial on how to make a game...not the programing...I looking for the concepts...for example..
I make the scroll of my game creating a variable CameraX and then adding each time you press the right button...
Then all I draw..tilemaps, enemy, etc... I subtract they x value from CameraX..

#SelectExpand
1if(key[KEY_RIGHT]) 2 CameraX+=Speed; 3 4 5Draw(BITMAP *Buffer){ 6 masked_blit(Sprite, Buffer, Frame*W, Stance*H, x - CameraX, y, W, H); 7}

It works..but when i start to put enemies to stage it becomes dificult and my program become a really mess...:P
All I want is some concepts of things like...To scroll I create a object Camera or make the variables in the player object....There is another way better to scroll??
Things like that would help me a lot...

bamccaig
Member #7,536
July 2006
avatar

It sounds to me like your problem is just organizing data and code. Perhaps what you are looking for is object-oriented programming? Perhaps you're looking for something like this to clean the code up:

renderer.render(player, camera);
renderer.render(enemy1, camera);
renderer.render(enemy2, camera);

???

Otherwise, I'm afraid that I don't understand what you're asking. :)

Arthur Kalliokoski
Second in Command
February 2005
avatar

I think what she's (?) asking is how to make a game, she's got the C/C++ language and Allegro API down, but what's next?

@Gabriel Campos:
It would help if you told us what kind of game you're making, I'm guessing a side scroller of some type? Do you have some commercial game in mind to emulate?

They all watch too much MSNBC... they get ideas.

Dario ff
Member #10,065
August 2008
avatar

Gabriel is a male name. :-/

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Arthur Kalliokoski
Second in Command
February 2005
avatar

So why did he pick a hot chick for his avatar?

[EDIT]

Upon zooming way in to the image, I guess it could be a guy... a great big ODARN echos through the trailer park!

They all watch too much MSNBC... they get ideas.

Dario ff
Member #10,065
August 2008
avatar

If you think that's a hot chick, then so be it. I'm not going to question your tastes. ;)

On-topic: Gabriel, there are quite a lot of tutorials on the net depending on the genre you're looking for. I remember finding once a tutorial for a 2D map style like the old JRPGs(think SNES), and it was specific to Allegro as well. These are quite helpful in opening up more room for thinking and creating new, different engines. In the end, it all comes down to your creativity in doing an engine that can be maintained, that is efficient, and flexible. And that it doesn't give you a headache when coding.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

gnolam
Member #2,030
March 2002
avatar

Dario ff said:

If you think that's a hot chick, then so be it.

Hot is debatable, but it's definitely a chick.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Matthew Leverton
Supreme Loser
January 1999
avatar

Looks like a male FF character to me. :P

It works..but when i start to put enemies to stage it becomes dificult and my program become a really mess...:P

What is a mess? The code? Or does the game not render correctly?

Dario ff
Member #10,065
August 2008
avatar

Here's the article I was talking about.

The Beginners Guide to RPG's in Allegro and C/C++

gnolam said:

Hot is debatable, but it's definitely a chick.

The size of the head seems to steer it into the "chick" side, though with the FF style, you never know. ;)

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Neil Walker
Member #210
April 2000
avatar

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Arthur Kalliokoski
Second in Command
February 2005
avatar

ah, yes

{"name":"sephiroth.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/e\/fe29d8fa7ec9d9abc59a03c66f76c1a8.jpg","w":432,"h":405,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/e\/fe29d8fa7ec9d9abc59a03c66f76c1a8"}sephiroth.jpg

They all watch too much MSNBC... they get ideas.

Dario ff
Member #10,065
August 2008
avatar

Indeed, it's Sephiroth:

{"name":"sugg-sephiroth.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/9\/198ef57c0d7ca8c9fef293bfe8769391.jpg","w":400,"h":665,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/9\/198ef57c0d7ca8c9fef293bfe8769391"}sugg-sephiroth.jpg

EDIT: Ninjad!

EDIT: Ok, so what does this tell us regarding gnolam and Arthur? :P

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Neil Walker
Member #210
April 2000
avatar

I must state that I know nothing of Final Fantasy, I just found it here, which was really quite good I thought:

http://www.tineye.com/

and pointed it at the forum static image.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Arthur Kalliokoski
Second in Command
February 2005
avatar

And I selected the Sephiroth string and right-clicked to "Search Google" then selected Images.

They all watch too much MSNBC... they get ideas.

bamccaig
Member #7,536
July 2006
avatar

gnolam
Member #2,030
March 2002
avatar

Dario ff said:

Ok, so what does this tell us regarding gnolam and Arthur? :P

That we're not anime-damaged enough to view ladyboys as male?

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Dario ff
Member #10,065
August 2008
avatar

Swift escape. At least you didn't call him hot. ;) Though in my defense, I based myself on the fact that the name is common for males on Latin America. ;)

Ok, enough off-topic for now.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Gabriel Campos
Member #12,034
June 2010
avatar

Well...Its Sephiroth from Final Fantasy...I will change later:P;D
(*thinking* They program games and dont know final fantasy?::))
I will try to be more clear . . .
I am making a platform game...a megaman game..
the link for my game. . .
http://www.4shared.com/file/jfK0vjFo/MEGAMAN.html
A = shoot (hold to charge)
Z = jump
ESC = exit game

I have a good knowledge in c++ and allegro... This is some codes from my game...

#SelectExpand
1//I create a Header file for each class 2 3class cPlayer : public cRect{ // cRect is a class to check collision 4private: 5 int x, y...etc 6 int CameraX, CameraY; 7public: 8 cPlayer(int, int); // Initializate the variables 9 ~cPlayer(); // dont need to comment 10 void Input(); 11 void Update(); 12 void Draw(BITMAP); 13}; 14 15int main(){ 16 while(!GameManager.Done){ 17 clear(Buffer); 18 Player.Input(); 19 Player.Update(); 20 Player.Draw(Buffer); 21 draw_sprite(screen, Buffer, 0, 0); 22}

Basiclly this is my code and I use in this manner for the other objects like enemies, etc...

My problems starts here when I start to put more objects in the game...
Because I have to check the position of the objects adding (enemy.x - Player.CameraX) . its become a mess . .
I know I need to learn more OOP so i am asking a light in this point . .
I want to know things like:

??? Its better to create on cPlayer a variable CameraX or create a object / class called cCamera?
??? If create a object Camera how to make the other objects like player to recognize it?? I tryed to create a pointer in the constructor of the player but doesnt work

#SelectExpand
1class cPlayer{ 2 cCamera *Camera; 3}; 4 5cPlayer::cPlayer(cCamera *iCamera){ 6 Camera = iCamera; 7} // this doesnt work for me...

??? Whats the better way to scroll??
Well, things like that ...Will help a lot me and begginers too..

Dario ff
Member #10,065
August 2008
avatar

Its better to create on cPlayer a variable CameraX or create a object / class called cCamera

Certainly a Camera should be a single object IMO.

Quote:

If create a object Camera how to make the other objects like player to recognize it?? I tryed to create a pointer in the constructor of the player but doesnt work

Your code snippet doesn't look wrong there, I'd say that you're not passing the pointer properly.

But IMO, the key is that maybe the objects shouldn't render themselves to the screen, but actually let a "Renderer" object handle it. That way, you can make different "displays" based on the same world.

Quote:

Whats the better way to scroll??

I guess your camera class should handle that.

EDIT:

Quote:

They program games and dont know final fantasy?

FF7, no. 8-) I know about the character, but I couldn't recognize it at first sight on your avatar.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Gabriel Campos
Member #12,034
June 2010
avatar

Hmmm....
But I will pass the objects in parameters??

#SelectExpand
1 2Renderer.Render(&Player, &Camera);

But how I define the Renderer class??

#SelectExpand
1class cRenderer{ 2 3 void Render( /* what parameters here??? */);

???

J-Gamer
Member #12,491
January 2011
avatar

I always have a class Object as a base class for every object that has to be drawn, and have it have at least one virtual function: virtual void draw();
Then, I have a vector of Object pointers to all objects. The drawing code looks like this:

for(int i = 0; i<objectsvector.length(); i++)
{
    Renderer.render(objectsvector[i],&Camera);
}

And in the render function:

void cRenderer::render(Object* object, cCamera* camera)
{
    masked_blit(object->getSprite(), Buffer, object->getFrame()*object->getW(), object->getStance()*object->getH(), object->getX - camera->getX, object->getY - camera->getY(), object->getW(), object->getH());
};

you will have to make getW,getH,getY,getX,getSprite,... virtual members of Object as well.

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

bamccaig
Member #7,536
July 2006
avatar

Well...Its Sephiroth from Final Fantasy...I will change later:P;D

No need to change it. :)

(*thinking* They program games and dont know final fantasy?::))

<------ Ahem.

??? Its better to create on cPlayer a variable CameraX or create a object / class called cCamera?

I would create a camera class. I would probably just name it Camera though. Assuming the 'c' stands for "class", it is a useless prefix that won't add anything useful to the game. If you need more than one camera type then use namespaces to organize them or give them more descriptive names.

??? If create a object Camera how to make the other objects like player to recognize it?? I tryed to create a pointer in the constructor of the player but doesnt work

As Dario ff pointed out, I would probably not let the player class know about the camera class. Let the camera be managed separately.

But how I define the Renderer class??

class cRenderer{
     
   void Render( /* what parameters here??? */);

Rather than passing pointers, you might as well pass references. You might do something like this:

renderer.hpp#SelectExpand
1#ifndef RENDERER_HPP 2 #define RENDERER_HPP 3 4class Renderer 5{ 6private: 7 BITMAP * buffer; 8 BITMAP * screen; 9 10 int getScreenX(const Camera &, const Player &) const; 11 int getScreenY(const Camera &, const Player &) const; 12public: 13 Renderer(BITMAP *); 14 15 void paint(void); 16 void render(const GameTime &, const Camera &, const Player &); 17}; 18 19#endif

renderer.cpp#SelectExpand
1#include "renderer.hpp" 2 3Renderer::Renderer(BITMAP * screen) 4{ 5 assert(screen); 6 7 this->screen = screen; 8 this->buffer = create_bitmap(screen->w, screen->h); 9 10 if(!this->buffer) 11 { 12 throw new std::runtime_error( 13 "Failed to create screen buffer."); 14 } 15} 16 17int Renderer::getScreenX( 18 const Camera & camera, 19 const Player & player) const 20{ 21 return player.getX() - camera.getX(); 22} 23 24int Renderer::getScreenY( 25 const Camera & camera, 26 const Player & player) const 27{ 28 return player.getY() - camera.getY(); 29} 30 31void Renderer::render( 32 const GameTime & time, 33 const Camera & camera, 34 const Player & player) 35{ 36 int x = this->getScreenX(camera, player); 37 int y = this->getScreenY(camera, player); 38 BITMAP * frame = player->getFrame(time); 39 40 blit(frame, this->buffer, x, y, 0, 0, frame->w, frame->h); 41} 42 43void Render::paint(void) 44{ 45 blit( 46 this->buffer, 47 this->screen, 48 0, 49 0, 50 0, 51 0, 52 this->buffer->w, 53 this->buffer->h); 54}

If you're comfortable with inheritance and polymorphism then you could do as J-Gamer suggested and create an IDrawable interface and just make your Player class and Enemy class and other drawable classes implement that interface. That way you should be able to easily draw anything that supports the drawing logic implemented.

Dizzy Egg
Member #10,824
March 2009
avatar

That picture of Sephiroth isn't from the game of FF7...thank Yevon for that.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

bamccaig
Member #7,536
July 2006
avatar

It's from the FFVII: Advent Children promotional materials. :) IIRC, I think that I used that very picture of Sephiroth as my A.cc avatar back when I joined in 2006... :P Prior to switching to Cloud for long forgotten reasons. :)

Here's a direct link to the original wallpaper from the official [English] site: http://na.square-enix.com/dvd/ff7ac/wallpapers/wp1-1.jpg

Gabriel Campos
Member #12,034
June 2010
avatar

I think the way of J-Gamer show the solution is very good . . .and will help me with other things too..like drawing by the Depth.
So, lets see...

#SelectExpand
1class cObject{ // Create a cObject class that will manager all drawable objects 2}; 3 4class cRenderer{ // Renderer class 5 BITMAP *Buffer; 6 7void Render(cObject * object, cCamera *camera){ 8 masked_blit(object->getSprite(), Buffer, object->getFrame()*object->getW(), Object->getStance()*object->getH(), object->getX - camera->getX, object->getY - camera->getY(), object->getW(), object->getH()); 9} 10}; 11 12 13int main(){ 14 std::vector<cObject *>Objects; 15 for(int i = 0; i < Objects.length(); i++){ 16 Renderer.Render(Objects[i], &Camera); 17 } 18}; 19END_OF_MAIN();

Is this the way correct??
I dont understood why J-Gamer said to use a virtual void draw();
Is really necessary??

 1   2   3   4 


Go to: