Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualPlayswithSquirrels

Posted 27 February 2013 - 09:05 PM

I'm relatively new at programming and am I'm making a 16-puzzle on allegro, and got a little stuck as to the tiles. I got as far as creating the structure, but as for the fitting the matrix in the loop I'm stumped. My goal is to break the image into 16 separate squares, with 1bit of distance between each, so I can see each of them defined. This is what I have so far.

#include <allegro.h>


void init();
void deinit();


typedef struct{
	BITMAP *piece;  //this would be a piece of the picture (1 of the 16 squares)
	int position;
}Block;

int main() {
	init();
	
	BITMAP *buffer;
	BITMAP *my_pic;
	PALETTE palette;
	clear_to_color(screen, makecol(255, 255, 255));

	buffer = create_bitmap(404,404);
	my_pic = load_bitmap("chihuahua2.bmp", palette);
		
	
	if(my_pic==NULL)
	{
		set_gfx_mode(GFX_TEXT, 0,0,0,0);
		allegro_message("Can't load chihuahua.bmp");
		return 1;
	}

	while (!key[KEY_ESC]) {
		blit(my_pic, screen, 0,0,106,48,404,404);
		show_mouse(my_pic);
		int i, t;
		for (i = 0; i <= 640; i++)
			for(t = 0; t <= 480; t++)
	//stuck on this area, don't know where to go from here			
		blit(my_pic, buffer, 0, 0, i, t, SCREEN_W, SCREEN_H);
	}
	destroy_bitmap(my_pic);
	deinit();
	return 0;
}
END_OF_MAIN()

void init() {
	int depth, res;
	allegro_init();
	depth = desktop_color_depth();
	if (depth == 0) depth = 32;
	set_color_depth(depth);
	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	if (res != 0) {
		allegro_message(allegro_error);
		exit(-1);
	}

	install_timer();
	install_keyboard();
	install_mouse();
}

void deinit() {
	clear_keybuf();
}

Any and all feedback is welcome.


#1PlayswithSquirrels

Posted 27 February 2013 - 09:03 PM

I'm relatively new at programming and am I'm making a 16-puzzle on allegro, and got a little stuck as to the tiles. I got as far as creating the structure, but as for the fitting the matrix in the loop I'm stumped. My goal is to break the image into 16 separate squares, with 1bit of distance between each, so I can see each of them defined. This is what I have so far.

#include <allegro.h>
#include <string.h>

void init();
void deinit();


typedef struct{
	BITMAP *piece;  //this would be a piece of the picture (1 of the 16 squares)
	int position;
}Block;

int main() {
	init();
	
	BITMAP *buffer;
	BITMAP *my_pic;
	PALETTE palette;
	clear_to_color(screen, makecol(255, 255, 255));

	buffer = create_bitmap(404,404);
	my_pic = load_bitmap("chihuahua2.bmp", palette);
		
	
	if(my_pic==NULL)
	{
		set_gfx_mode(GFX_TEXT, 0,0,0,0);
		allegro_message("Can't load chihuahua.bmp");
		return 1;
	}

	while (!key[KEY_ESC]) {
		blit(my_pic, screen, 0,0,106,48,404,404);
		show_mouse(my_pic);
		int i, t;
		for (i = 0; i <= 640; i++)
			for(t = 0; t <= 480; t++)
	//stuck on this area, don't know where to go from here			
		blit(my_pic, buffer, 0, 0, i, t, SCREEN_W, SCREEN_H);
	}
	destroy_bitmap(my_pic);
	deinit();
	return 0;
}
END_OF_MAIN()

void init() {
	int depth, res;
	allegro_init();
	depth = desktop_color_depth();
	if (depth == 0) depth = 32;
	set_color_depth(depth);
	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	if (res != 0) {
		allegro_message(allegro_error);
		exit(-1);
	}

	install_timer();
	install_keyboard();
	install_mouse();
}

void deinit() {
	clear_keybuf();
}

Any and all feedback is welcome.


PARTNERS