Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Im a beginner needing help! xD

This thread is locked; no one can reply to it. rss feed Print
Im a beginner needing help! xD
Thiago Lazier
Member #10,219
September 2008

well... i'm starting with allegro now and i'm having a lot of troubles...
I'm trying to do an RPG game... and it have to be done til october, 2th (as my teacher said xD)...
My question is....
when i put two bitmaps in the screen, like one for the game itself, and another for the atributes and stuff, the screen keeps blinking and then it says
"your program executed an ilegal operation and... u guys know...

So... i'm needing help... =X
i'll send an annex with a "simplified" code, in wich the same problem happens:

while (!key[KEY_ESC]) {

BITMAP *a = load_bitmap("E:\\Documents and Settings\\Servidor\\Meus documentos\\1.bmp", NULL);
BITMAP *b = load_bitmap("E:\\Documents and Settings\\Servidor\\Meus documentos\\2.bmp", NULL);
draw_sprite (screen, a, 0, 0);
draw_sprite (screen, b, 0, 0);

}

Sorry for mistakes in the writing, im from brazil and still have a lot to learn in english
xD

Sol Blast
Member #9,655
April 2008
avatar

Check the returns. Once you've called load_bitmap, test to see if it worked like so...

   BITMAP *a = load_bitmap("E:\\Documents and Settings\\Servidor\\Meus documentos\\1.bmp", NULL);
   BITMAP *b = load_bitmap("E:\\Documents and Settings\\Servidor\\Meus documentos\\2.bmp", NULL);

   if (!a)
   {
      allegro_message("Could not load bitmap a!";
      allegro_exit();
   }

   if (!b)
   {
      allegro_message("Could not load bitmap b!";
      allegro_exit();
   }

If you get either of those message popping up then you've probably set the wrong path for the bitmap or allegro doesn't like them for some reason.
If not then... i don't know :P.
Hope it helps :).

bamccaig
Member #7,536
July 2006
avatar

@Thiago Lazier: Just a note: on the forums you can surround code with BBCode tags (i.e. [code]text[/code]) and it will maintain white-space, attempt to highlight the source, and even provides links to the Allegro manual and AFAIK a C standard library reference. :) You can see the rest of the BBCode syntax if you click the "Help" option in the toolbar above the post textarea (IMO it's hard to spot until you know it's there though)...

Thiago Lazier said:

while (!key[KEY_ESC]) {

BITMAP *a = load_bitmap("E:\\Documents and Settings\\Servidor\\Meus documentos\\1.bmp", NULL);
BITMAP *b = load_bitmap("E:\\Documents and Settings\\Servidor\\Meus documentos\\2.bmp", NULL);
draw_sprite (screen, a, 0, 0);
draw_sprite (screen, b, 0, 0);

}

Assuming the above code is working, it repeatedly loads 1.bmp and 2.bmp before drawing them (technically leaking the memory consumed by the past iterations' loaded BITMAPs). So first of all, you're going to want to move the load_bitmap calls outside of the while loop.

Secondly, I've heard of two solutions for eliminating the "flickering" screen problem. Double buffering and using Allegro's vsync routine. Double buffering is a technique where you create an empty BITMAP structure (i.e. your buffer) with the same dimensions as the screen and draw everything to it. Then, when your game loop / frame ends you draw the buffer to the screen. System memory is much faster than video memory, IIRC, so this results in the whole operation being much faster, eliminating the visible flickering.

1#include <allegro.h>
2 
3const char * const BMP_1 = "E:\\Documents and Settings\\Servidor\\Meus documentos\\1.bmp";
4const char * const BMP_2 = "E:\\Documents and Settings\\Servidor\\Meus documentos\\2.bmp";
5 
6int main(int argc, char *argv[])
7{
8 BITMAP *buffer = NULL, *a = NULL, *b = NULL;
9 
10 /* ... Initialization Of Allegro Goes Here ...*/
11 
12 // Once Allegro is successfully initialized we create our screen buffer.
13 if((buffer = create_bitmap(screen->w, screen->h)) == NULL)
14 {
15 allegro_message("Failed to create screen buffer.");
16 exit(-1);
17 }
18 
19 // Now we load bitmaps from disk.
20 if((a = load_bitmap(BMP_1, NULL)) == NULL
21 || (b = load_bitmap(BMP_2, NULL)) == NULL)
22 {
23 allegro_message("Failed to load one or more bitmaps.");
24 exit(-1);
25 }
26 
27 // Begin the main loop.
28 while(!key[KEY_ESC])
29 {
30 // Draw everything to the buffer instead of the screen.
31 draw_sprite(buffer, a, 0, 0);
32 draw_sprite(buffer, b, 0, 0);
33 
34 /*
35 * Then when you're finished drawing everything, draw the buffer onto the
36 * screen.
37 */
38 blit(buffer, screen, 0, 0, 0, 0, screen->w, screen->h);
39 
40 // And, depending on the technique used, clear the buffer.
41 clear_bitmap(buffer);
42 }
43 
44 // Clean-up.
45 if(buffer)
46 {
47 destroy_bitmap(buffer);
48 buffer = NULL;
49 }
50 
51 if(a)
52 {
53 destroy_bitmap(a);
54 a = NULL;
55 }
56 
57 if(b)
58 {
59 destroy_bitmap(b);
60 b = NULL;
61 }
62 
63 return(0);
64}
65END_OF_MAIN()

I've never used vsync before so I can't be sure on the syntax, but if you're still having problems after double buffering then you can give it a try too.

If you're able to show us more code then we can probably help you correct some other common mistakes before you get very far. A lot of people neglect return values, which leads to unexpected errors. If a routine returns a value indicating success or failure make sure to check that it was successful and react accordingly. Timing is another common problem.

IMHO, attempting to write an RPG before Oct 2 when you're this new is unlikely to succeed. You might want to negotiate with your teacher/professor either on the project or the deadline.

Albin Engström
Member #8,110
December 2006
avatar

Hello Thiago Lazier, you probably won't appreciate what I'm about to say.

Even if you had "the skills" you probably won't finish a full fledged RPG in a week, unless it's very small. So in case you're aiming that high you should reconsider.

You could however make the engine in a week, and maybe even throw in an editor. I'm not sure how new you are to game programming but you should aim at a simple engine to begin with.

I'm sure your programming teacher will be impressed with that.

Just a tip, you do whatever you think is best.

Oh, and good luck with leveling your ragnarok characters. ;)

Dario ff
Member #10,065
August 2008
avatar

RPG in a week? Your teacher must play speedhack :P. Don´t even try an RPG in a week. Making a battle system, datbase, and... well, you got the idea.

anyways, My best solution for you would be that you just copy some of the examples on the allegro folder to get a page-flipping system or a simple double buffer.

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

Matthew Leverton
Supreme Loser
January 1999
avatar

These MP3's should help: Verse 1, Verse 2.

Sorry for the rough quality. We started them on Monday, and aren't done yet, despite it being Wednesday. Hopefully we have the final mix ready by the second though. :-/

Don Freeman
Member #5,110
October 2004
avatar

Matthew that was awesome!:D;D8-)

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

Albin Engström
Member #8,110
December 2006
avatar

Nice Matthew! :D

Schyfis
Member #9,752
May 2008
avatar

That made my day.

________________________________________________________________________________________________________
[freedwill.us]
[unTied Games]

Tobias Dammers
Member #2,604
August 2002
avatar

The song itself is one of the most successful monday projects ever.:D

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Don Freeman
Member #5,110
October 2004
avatar

Or Tuesday, for that matter!:P

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

OnlineCop
Member #7,919
October 2006
avatar

Don Freeman said:

Or Tuesday, for that matter!:P

No, no. Tuesday is the other group's Group Project. As I recall, there were three groups: Monday, Tuesday and Duke Nukem Forever.

Neil Black
Member #7,867
October 2006
avatar

Quote:

As I recall, there were three groups: Monday, Tuesday and Duke Nukem Forever.

Sigged.

Go to: