Game of life in allegro
francisco diogo

HI. I have made a simulation of the game of life in C, but I wanted to make it in Allegro language.
The question is the following: my original program makes a board of 300*150 of aleatory 0 and 1, and then everytime i press enter the board transforms into another one of 0 and 1, according to preset rules.
How can i make, for example, that each 1 appears as a white square and every 0 as a black square? I know it is probably very basic by i've read many tutorials and i haven't seen it explained anywhere.
If seeing the program in C would help answer the question i can post it, its not very big.
Thank you.

CursedTyrant

I'll post what I can, based on the info you posted (just the drawing bit, tough it's not tested and can be buggy like hell):

1#include "allegro.h"
2 
3#define MAPW 300
4#define MAPH 150
5#define RECTSIZE 16
6 
7int map[MAPW][MAPH];
8 
9BITMAP *buffer;
10 
11int main()
12{
13 //init
14 //populate the map array
15
16 buffer = create_bitmap(SCREEN_W, SCREEN_H);
17
18 while (!key[KEY_ESC)
19 {
20 clear(buffer);
21
22 for (int y=0; y<MAPH; y++)
23 {
24 for (int x=0; x<MAPW; x++)
25 {
26 //I'm assuming you have a non-black background
27 if (map[x][y]==0)
28 { rectfill(buffer, x*RECTSIZE, y*RECTSIZE, (x+1)*RECTSIZE, (y+1)*RECTSIZE, makecol(0, 0, 0)); }
29 else if (map[x][y]==1)
30 { rectfill(buffer, x*RECTSIZE, y*RECTSIZE, (x+1)*RECTSIZE, (y+1)*RECTSIZE, makecol(255, 255, 255)); }
31 }
32 }
33
34 blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
35 }
36 destroy_bitmap(buffer); buffer = 0;
37 //exit
38}
39END_OF_MAIN()

francisco diogo

Well, the program wasn't very buggy, but i tried to run it two times and both of them the windows said there was an error and the window had to close. Anyway thanks for your post.
I'll just post now the program i have made and if someone has got the pacience, i would appreciate if he/she could give a little help, cause i have to make this as a college project: (just the main)

int main()
{
int i, j, h;
char x;

board_init();

for(h=1; h <= MAX_GEN; h++) {
board_out(h);

for (i=0; i<=N; i++) {
for (j=0; j<=M; j++) {
stone(i, j);
}
}

c = getchar();
}
return 0;
}

CursedTyrant

Yes, well... I did put //init and such in the code since I thought you knew how to init all the allegro stuff.

allegro_init();
set_color_depth(desktop_color_depth());
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
install_keyboard();

GullRaDriel

Since when allegro is a language ? I always thought it was a library :p

Edited

Jonatan Hedborg

COUNTER NITPICK ATTACK FOR MASSIVE DAMAGE!
tough = thought

LennyLen
Quote:

tough = thought

Super Nitpick Combo Breaker: tough != thought.

Jonatan Hedborg

There is no defense :(

GullRaDriel

No need to defend when I see no attack :p

LennyLen
Quote:

No need to defend when I see no attack

It appears you need glasses. :)

GullRaDriel

I am a good guy with positive mind ;-p

LennyLen

It was a good natured and friendly attack (as contradictory as that sounds). :)

GullRaDriel

Héhé. We made the thread going mad.

So, do the OP is happy with the stuff and knowledge CursedTyrant gaves to him ?

Richard Phipps

I think The Game of Life has been run on a GPU as well. 8-)

Johan Halmén
Quote:

Quote:

Quote:

tough = thought

Super Nitpick Combo Breaker: tough != thought.

No. Writing "tough = thought" means assigning thought to tough. After that one can write tough.

Onewing
Quote:

No. Writing "tough = thought" means assigning thought to tough. After that one can write tough.

Good, that's what I tough.

Arthur Kalliokoski

I'd do it as:

1//8 bit version
2 
3#include <allegro.h>
4 
5RGB white = { 63, 63, 63, 0 };
6RGB black;
7 
8int color;
9 
10int main(void)
11{
12 allegro_init();
13 install_keyboard();
14 if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0))
15 {
16 set_gfx_mode(GFX_TEXT,0,0,0,0);
17 allegro_message("Bad graphic mode");
18 return -1;
19 }
20 
21 set_color(0,&black);
22 set_color(1,&white);
23 //loop would start here
24 color = some_arcane_calculation;
25 circlefill(screen,10,10,20,color);
26 readkey();
27 return 0;
28}
29END_OF_MAIN()
30 
31 
32//Truecolor version
33#include <allegro.h>
34 
35int colorvals[2];
36 
37int color;
38 
39int main(void)
40{
41 allegro_init();
42 install_keyboard();
43 set_color_depth(24);
44 
45 if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0))
46 {
47 set_gfx_mode(GFX_TEXT,0,0,0,0);
48 allegro_message("Bad graphic mode");
49 return -1;
50 }
51 
52 colorvals[0] = 0;
53 colorvals[1] = makecol(255,255,255);
54 //loop would start here
55 color = some_arcane_calculation();
56 circlefill(screen,10,10,20,colorvals[color]);
57 readkey();
58 return 0;
59}
60END_OF_MAIN()

[EDIT] I did have "putpixel()" where circlefill is but they were too small to see when quick testing that it'd actually work.

Thread #589572. Printed from Allegro.cc