|
Looking for a Game Tutorial |
Gabriel Campos
Member #12,034
June 2010
|
Hi everybody... 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
|
bamccaig
Member #7,536
July 2006
|
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. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Arthur Kalliokoski
Second in Command
February 2005
|
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: They all watch too much MSNBC... they get ideas. |
Dario ff
Member #10,065
August 2008
|
Gabriel is a male name. TranslatorHack 2010, a human translation chain in a.cc. |
Arthur Kalliokoski
Second in Command
February 2005
|
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
|
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. |
gnolam
Member #2,030
March 2002
|
Dario ff said: If you think that's a hot chick, then so be it. Hot is debatable, but it's definitely a chick. -- |
Matthew Leverton
Supreme Loser
January 1999
|
Looks like a male FF character to me. Gabriel Campos said: 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
|
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. |
Neil Walker
Member #210
April 2000
|
it's a bloke, I think: Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Arthur Kalliokoski
Second in Command
February 2005
|
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"} They all watch too much MSNBC... they get ideas. |
Dario ff
Member #10,065
August 2008
|
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"} EDIT: Ninjad! EDIT: Ok, so what does this tell us regarding gnolam and Arthur? TranslatorHack 2010, a human translation chain in a.cc. |
Neil Walker
Member #210
April 2000
|
I must state that I know nothing of Final Fantasy, I just found it here, which was really quite good I thought: and pointed it at the forum static image. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Arthur Kalliokoski
Second in Command
February 2005
|
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
|
-- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
gnolam
Member #2,030
March 2002
|
Dario ff said: Ok, so what does this tell us regarding gnolam and Arthur? That we're not anime-damaged enough to view ladyboys as male? -- |
Dario ff
Member #10,065
August 2008
|
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. |
Gabriel Campos
Member #12,034
June 2010
|
Well...Its Sephiroth from Final Fantasy...I will change later:P;D I have a good knowledge in c++ and allegro... This is some codes from my game... 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... Its better to create on cPlayer a variable CameraX or create a object / class called cCamera? 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??
|
Dario ff
Member #10,065
August 2008
|
Gabriel Campos said: 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. 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. |
Gabriel Campos
Member #12,034
June 2010
|
Hmmm.... 1
2Renderer.Render(&Player, &Camera);
But how I define the Renderer class?? 1class cRenderer{
2
3 void Render( /* what parameters here??? */);
|
J-Gamer
Member #12,491
January 2011
|
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(); 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 |
bamccaig
Member #7,536
July 2006
|
Gabriel Campos said: Well...Its Sephiroth from Final Fantasy...I will change later:P;D No need to change it. Gabriel Campos said: (*thinking* They program games and dont know final fantasy?::)) <------ Ahem. Gabriel Campos said: 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. Gabriel Campos said: 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. Gabriel Campos said: 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: 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
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. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Dizzy Egg
Member #10,824
March 2009
|
That picture of Sephiroth isn't from the game of FF7...thank Yevon for that.
---------------------------------------------------- |
bamccaig
Member #7,536
July 2006
|
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... 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 -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Gabriel Campos
Member #12,034
June 2010
|
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. 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??
|
|
|