02-04-2004, 12:45 AM
02-04-2004, 07:24 AM
Okay, so I coded a program to animate a circle bouncing around:
Two problems:
1) For some reason, it's delaying way way more than .02 seconds...but I googled delays, and it said to use the time() function, and the time_t struct...I think the problem is that when comparing the time(NULL)-seconds <= .2, it's comparing all members of the struct...but the website I saw said to do that. I dunno.
2) Every other iteration of the loop, it doesn't draw the complete circle, which I just can't understand.
Code:
/* Compiled with Mingw32 */
#include <allegro.h>
#include <time.h>
#define RADIUS 5
#define CLR 2
int main()
{
allegro_init();
set_gfx_mode(GFX_AUTODETECT_FULLSCREEN,320,200,0,0);
install_keyboard();
int x=10;
int y=10;
int velocity=1;
time_t seconds;
while (!key[KEY_X])
{
circle(screen,x,y,RADIUS,0);
seconds=time(NULL);
x += velocity;
y += velocity;
circle(screen,x,y,RADIUS,CLR);
if (x==314 || y==194)
velocity *= -1;
int i;
while ((time(NULL)-seconds) <= .2);
}
return 0;
}
END_OF_MAIN()
1) For some reason, it's delaying way way more than .02 seconds...but I googled delays, and it said to use the time() function, and the time_t struct...I think the problem is that when comparing the time(NULL)-seconds <= .2, it's comparing all members of the struct...but the website I saw said to do that. I dunno.
2) Every other iteration of the loop, it doesn't draw the complete circle, which I just can't understand.
02-04-2004, 08:12 AM
You know allegro comes with timing routines, its in the manual
I dont like how your doing the while loop a {} would be clearer, and is probably better coding practice. Second why int i here?
Also try adding a vsync() after the drawing instead of a timer.
Code:
int i;
while ((time(NULL)-seconds) <= .2);
Also try adding a vsync() after the drawing instead of a timer.
02-04-2004, 08:52 AM
Oops, forget the init i; - it's a typo.
Nath pointed it out...
Or
Or
The very first example is what I use. Since ";" alone is a valid statement...it works: while(condition);.
I'll look up vsync();
Nath pointed it out...
Code:
while (condition) do_something();
Code:
while (condition)
do_something();
Code:
while (condition)
{
do_something();
}
I'll look up vsync();
02-05-2004, 02:09 AM
Okay, I got vsync() down.
Now, for my expiriment with loading BMPs!
WARNING - don't run the following code, it crashed my computer.
It crashed my computer. I've saved the BMP with MSPAINT, in 256 color format...so what's wrong?
Now, for my expiriment with loading BMPs!
WARNING - don't run the following code, it crashed my computer.
Code:
#include <allegro.h>
int main()
{
allegro_init();
set_gfx_mode(GFX_AUTODETECT_FULLSCREEN,320,200,0,0);
BITMAP *sprite;
RGB pal;
sprite=load_bmp("spr.bmp",&pal);
blit(sprite,screen,0,0,10,10,10,10);
while (!key[KEY_X]);
return 0;
}
END_OF_MAIN()
02-05-2004, 02:30 AM
um, pal takes an array of RGB's (256 of em to be exact).
Your only suplying one.
Really read the documentation, all these questions are covered there. Print it out if neccessesary.
Your only suplying one.
Really read the documentation, all these questions are covered there. Print it out if neccessesary.
02-05-2004, 03:09 AM
Er..I'm really bad at this graphics stuff.
So I would declare an array of Pals, 256 elements, and pass the address of the first element?
[edit]
Would this code work?
So I would declare an array of Pals, 256 elements, and pass the address of the first element?
[edit]
Would this code work?
Code:
#include <allegro.h>
int main()
{
allegro_init();
install_keyboard();
set_gfx_mode(GFX_AUTODETECT_FULLSCREEN,320,200,0,0);
BITMAP *sprite;
RGB pal[256];
sprite=load_bmp("spr.bmp",pal);
blit(sprite,screen,0,0,10,10,10,10);
while (!key[KEY_X]);
return 0;
}
END_OF_MAIN()
02-05-2004, 06:20 PM
You have a predefined type:
Will allocate a 256 colour palete made up of RGBs
Code:
PALETTE my_pal;
Will allocate a 256 colour palete made up of RGBs
02-05-2004, 07:25 PM
Okaaay...But will the RGB pal[PAL_SIZE] work too?
02-05-2004, 09:00 PM
yes.