Beispiel #1
0
bool PARTICLE_DATA::set_data(int d) {

    int tmp, i;

	switch(field) {
		case 1 : speed = d;
			break;
        case 2 :
            particle_type = d;
            break;
        case 3 :
            num_frames = d > 0 ? d : sprite->w/sprite->h;
            tmp = sprite->w/num_frames;
            frames.reserve(num_frames);
            for (i=0; i<num_frames; i++) {
                frames.push_back(create_sub_bitmap(sprite, i*tmp, 0, tmp, sprite->h));
            }
            radius = max(tmp, sprite->h);
			break;
        case 4 : frame_rate = d * 1.0/GOAL_FPS;
			break;
        case 5 : type = d;
            break;
		default: puts("warning: bad particle_data config block");
            return false;
			break;
	}
	field++;
	return true;
}
Beispiel #2
0
void initialize_oneplayer_screen()
{
   clear(screen_buffer);
   clear(screen);
   for (int i=0;i< NR_OF_LAYERS;i++)
       playfield->draw(screen_buffer,i);
   if (screen_buffer->w == SCREEN_W)
   {
      blit(screen_buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H- 96);
   }
   else
   {
      stretch_blit(screen_buffer,screen,0,0, screen_buffer->w, screen_buffer->h,0,0,SCREEN_W,SCREEN_H- 96);
   }

   BITMAP *frame;
   for (int i=0; i<SCREEN_W;i+=640)
   {
      blit(board, screen, 0, 0 ,i , SCREEN_H - 96, 640, 96);
   }

   draw_rle_sprite(screen, (RLE_SPRITE *)(objects[GFXDATA_OBJECTS_GOUD].dat), 10, SCREEN_H - 86);
   draw_rle_sprite(screen, (RLE_SPRITE *)(objects[GFXDATA_OBJECTS_ENERG].dat),10, SCREEN_H - 44);
   draw_rle_sprite(screen, (RLE_SPRITE *)(objects[GFXDATA_OBJECTS_STER].dat),200, SCREEN_H - 86);
   draw_rle_sprite(screen, (RLE_SPRITE *)(objects[GFXDATA_OBJECTS_STUT].dat),200, SCREEN_H - 44);
   frame = create_sub_bitmap((BITMAP *)(anims[GFXDATA_ANIMS_MANS].dat), 0,0,32,32);
   masked_blit(frame,screen,0,0,400,SCREEN_H - 86,32,32);
   destroy_bitmap(frame);
   draw_rle_sprite(screen, (RLE_SPRITE *)(objects[GFXDATA_OBJECTS_HOUWEEL].dat),400, SCREEN_H - 44);
   
}
bool Bitmap::CreateSubBitmap(Bitmap *src, const Rect &rc)
{
    Destroy();
    _alBitmap = create_sub_bitmap(src->_alBitmap, rc.Left, rc.Top, rc.GetWidth(), rc.GetHeight());
    _isDataOwner = true;
    return _alBitmap != nullptr;
}
Beispiel #4
0
void SuperEagle(ALLEGRO_BITMAP * src, ALLEGRO_BITMAP * dest, int s_x, int s_y, int d_x, int d_y, int w, int h)
{
	int sbpp, dbpp;

	ALLEGRO_BITMAP *dst2 = NULL;

	if (!src || !dest)
		return;

	sbpp = bitmap_color_depth(src);
	dbpp = bitmap_color_depth(dest);

	if ((sbpp != xsai_depth) || (sbpp != dbpp))	/* Must be same color depth */
		return;

	BLIT_CLIP2(src, dest, s_x, s_y, d_x, d_y, w, h, 2, 2);	
		
	if (w < 4 || h < 4) {  /* Image is too small to be 2xSaI'ed. */
		stretch_blit(src, dest, s_x, s_y, w, h, d_x, d_y, w * 2, h * 2);
		return;
	}	
	
	sbpp = BYTES_PER_PIXEL(sbpp);
	if (d_x || d_y)
		dst2 = create_sub_bitmap(dest, d_x, d_y, w * 2, h * 2);
	
	SuperEagle_ex(src->line[s_y] + s_x * sbpp, (unsigned int)(src->line[1] - src->line[0]), NULL, dst2 ? dst2 : dest, w, h);
	
	if (dst2)
		destroy_bitmap(dst2);
	
	return;
}
Beispiel #5
0
/* add_vram_block:
 *  Creates a video memory bitmap out of the specified region
 *  of the larger screen surface, returning a pointer to it.
 */
static BITMAP *add_vram_block(int x, int y, int w, int h)
{
   VRAM_BITMAP *b, *new_b;
   VRAM_BITMAP **last_p;

   new_b = _AL_MALLOC(sizeof(VRAM_BITMAP));
   if (!new_b)
      return NULL;

   new_b->x = x;
   new_b->y = y;
   new_b->w = w;
   new_b->h = h;

   new_b->bmp = create_sub_bitmap(screen, x, y, w, h);
   if (!new_b->bmp) {
      _AL_FREE(new_b);
      return NULL;
   }

   /* find sorted y-position */
   last_p = &vram_bitmap_list;
   for (b = vram_bitmap_list; b && (b->y < new_b->y); b = b->next_y)
      last_p = &b->next_y;

   /* insert */
   *last_p = new_b;
   new_b->next_y = b;

   return new_b->bmp;
}
/*
 * call-seq:
 *   create_sub_bitmap(parent, x, y, width, height) -> a_bmp or nil
 *
 * Creates a sub-bitmap, ie. a bitmap sharing drawing memory with a pre-existing
 * bitmap, but possibly with a different size and clipping settings. When
 * creating a sub-bitmap of the mode-X screen, the x position must be a multiple
 * of four. The sub-bitmap width and height can extend beyond the right and
 * bottom edges of the parent (they will be clipped), but the origin point must
 * lie within the parent region.
 *
 * Return value: Returns a reference to the created sub bitmap, or nil if the
 * sub bitmap could not be created. Remember to free the sub bitmap before
 * freeing the parent bitmap to avoid memory leaks and potential crashes
 * accessing memory which has been freed.
 */
VALUE a4r_API_create_sub_bitmap(VALUE self, VALUE parent, VALUE x, VALUE y, VALUE width, VALUE height)
{
  BITMAP *bmp;
  Data_Get_Struct(parent, BITMAP, bmp);
  BITMAP *ret = create_sub_bitmap(bmp, FIX2INT(x), FIX2INT(y), FIX2INT(width), FIX2INT(height));
  if (ret == NULL)
    return Qnil;
  VALUE obj = Data_Wrap_Struct(cAPI_BITMAP, 0, 0, ret);
  return obj;
}
void Animation::fillFramesList(BITMAP *allFrames, int count)
{
	mFrames.reserve(count);
	
	int i;
	for (i = 0; i < count; i++) {
		BITMAP *frame = create_sub_bitmap(allFrames, i * mFrameWidth, 0, mFrameWidth, mFrameHeight);
		mFrames.push_back(frame);
	}
}
Beispiel #8
0
Plane::Plane(BITMAP* image, int spriteX, int spriteY, int frame_width, int frame_height, float x, float y, int type)
{
    this->frame_width = frame_width;
    this->frame_height = frame_height;
    this->image = create_sub_bitmap(image, spriteX, spriteY, frame_width, frame_height);
    this->position.x = x;
    this->position.y = y;
    this->type = type;
    health = 100;
    alive = true;
}
Beispiel #9
0
void Alleg4Surface::drawRgbaSurface(const Surface* src, int srcx, int srcy, int dstx, int dsty, int w, int h)
{
  if (w < 1 || h < 1)
    return;

  set_alpha_blender();

  BITMAP* tmp = create_sub_bitmap(
    static_cast<const Alleg4Surface*>(src)->m_bmp,
    srcx, srcy, w, h);
  draw_trans_sprite(m_bmp, tmp, dstx, dsty);
  destroy_bitmap(tmp);
}
Beispiel #10
0
static void intro_screen(void)
{
   BITMAP *bmp;
   play_sample(data[INTRO_SPL].dat, 255, 128, 1000, FALSE);

   bmp =
       create_sub_bitmap(screen, SCREEN_W / 2 - 160, SCREEN_H / 2 - 100,
                         320, 200);
   play_memory_fli(data[INTRO_ANIM].dat, bmp, FALSE, NULL);
   destroy_bitmap(bmp);

   rest(1000);
   fade_out(1);
}
Beispiel #11
0
void Font::privInit(BITMAP *aGlyphImage, const std::string& aGlyphs)
{
	BITMAP *glyphImage = aGlyphImage;
	int separatingColor = getpixel(glyphImage, 0, 0);
	
	int x = 0;
	int scanLine = 0;
	unsigned int currGlyphIndex = 0;
	int lastRowHeight = 0;
	char specialGlyph = (char)200;

	while(scanLine < glyphImage->h)
	{
		x = 0;
		while(x < glyphImage->w)
		{
			int color = getpixel(glyphImage, x, scanLine);
			
			if(color != separatingColor) //glyph found!
			{
				int y1 = scanLine;
				while((y1 < glyphImage->h) && getpixel(glyphImage, x, y1) != separatingColor) //find bottom of glyph
				{
					y1++;
				}
				int x1 = x;
				while((x1 < glyphImage->w) && getpixel(glyphImage, x1, scanLine) != separatingColor) //find right edge of glyph
				{
					x1++;
				}
				
				int width = x1-x;
				int height = y1-scanLine;
				lastRowHeight = height;
				
				char currGlyph = aGlyphs.size() < currGlyphIndex ? specialGlyph++ : aGlyphs[currGlyphIndex++];
				BITMAP* bitmap = create_sub_bitmap(glyphImage, x, scanLine, width, height);
				myGlyphToBitmap[currGlyph] = bitmap;

				x = x1;
			}
			x += 1;
		}
		scanLine += lastRowHeight+1;
	}
	if(myGlyphToBitmap['\n'] == 0 && myGlyphToBitmap[' '] != 0) myGlyphToBitmap['\n'] = myGlyphToBitmap[' ']; //have something to draw when newline

	myHeight = lastRowHeight;
}
Beispiel #12
0
EOF_WINDOW * eof_window_create(int x, int y, int w, int h, BITMAP * bp)
{
    EOF_WINDOW * wp = NULL;
    if(bp == NULL)
        return NULL;

    eof_log("eof_window_create() entered", 1);

    wp = malloc(sizeof(EOF_WINDOW));
    if(wp)
    {
        wp->x = x;
        wp->y = y;
        wp->w = w;
        wp->h = h;
        wp->screen = create_sub_bitmap(bp, x, y, w, h);
    }
    return wp;
}
Beispiel #13
0
void PARTICLE::draw(DISPLAY& disp)
{
    int drawX = disp.toScreenX((int) x);
	int drawY = disp.toScreenY((int) y);
	BITMAP * fsprite = data.frames[(int)frame_index];

	// create subsprite
	if ((data.particle_type == 1 || data.particle_type == 2) && start_len < fsprite->w*2) {
		if ((int)frame_index != prev_frameindex) {
			prev_frameindex = (int)frame_index;
			if (sprite && is_subimg) destroy_bitmap(sprite);
			sprite = create_sub_bitmap(fsprite, fsprite->w/2 - start_len/2, 0, (start_len > 20) ? start_len : 20, fsprite->h);
		}
	} else {
		sprite = fsprite;
		is_subimg = false;
	}

	// draw
	if (data.particle_type == 0 || data.particle_type == 3) pivot_sprite(disp.buffer, sprite, drawX, drawY, sprite->w / 2, sprite->h / 2, itofix( (int) (theta / M_PI * 256/2) ));
	else if (data.particle_type == 1 || data.particle_type == 2) pivot_scaled_sprite(disp.buffer, sprite, drawX, drawY, 0, sprite->h / 2, itofix( (int) (theta / M_PI * 256/2) ), ftofix(expansion * (double)starting_life/(double)sprite->w));
}
Beispiel #14
0
void handle_key(void){
	if (NeedsPoll) poll_keyboard();


	if (key[syskeys[0]] || key[KEY_ESC]) {
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[0]] || key[KEY_ESC]);
		key_done=1;
	}

if (key[syskeys[1]]) {
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[1]]);

		mute_audio();
		mute_voice();
		abaut();

		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();

			if (key[KEY_ALT] && key[KEY_ENTER]) {
				app_data.fullscreen = app_data.fullscreen ? 0 : 1;
				grmode();
				abaut();
				do {
					rest(5);
					if (NeedsPoll) poll_keyboard();
				} while (key[KEY_ENTER]);
			}		

		} while ((!key[syskeys[1]]) && (!key[KEY_ESC]) && (!key[syskeys[0]]));
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[1]]);
		
		init_sound_stream();
	}		

if (key[syskeys[5]])
	{
		if (savestate(app_data.statefile)==0)
		{
			display_msg("Savefile saved.",5);
		}
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[5]]);

	}

	/* LOAD STATE */
	if (key[syskeys[6]])
	{
		int stateError;
		if ((stateError=loadstate(app_data.statefile))==0)
		{
			display_msg("Savefile loaded.",5);
		}
		else if (stateError>=199)
		{
			if (stateError==199) display_msg("Wrong ROM-File for Savefile.",5);
			else if (stateError==200+ROM_O2) display_msg("Wrong BIOS for Savefile: O2ROM needed.",5);
			else if (stateError==200+ROM_G7400) display_msg("Wrong BIOS for Savefile: G7400 ROM needed.",5);
			else if (stateError==200+ROM_C52) display_msg("Wrong BIOS for Savefile: C52 ROM needed.",5);
			else if (stateError==200+ROM_JOPAC) display_msg("Wrong BIOS for Savefile: JOPAC ROM needed.",5);
			else display_msg("Wrong BIOS for Savefile: UNKNOWN ROM needed.",5);
		}
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[6]]);
	}

	if (key[syskeys[2]]) key_debug=1;

	if (key[syskeys[3]]) {
		init_cpu();
		init_roms();
		init_vpp();
		clearscr();
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[3]]);
	}

    /* SET HIGHSCORE */
	if (key[syskeys[7]])
	{
		set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore);
	}


	if (key[syskeys[4]]) {
		BITMAP *bmp;
		PALETTE pal;
		char *p;
		static char name[1024];
		static int scshot_counter = 0;

		if (strlen(app_data.scshot)>0){
			if ((p=strchr(app_data.scshot,'@'))) {
				*p = 0;
				sprintf(name, "%s%02d%s", app_data.scshot, scshot_counter++, p+1);
				*p = '@';
			} else {
				strcpy(name, app_data.scshot);
			}
			get_palette(pal);
			bmp = create_sub_bitmap(screen, 0, 0, SCREEN_W, SCREEN_H);
			save_bitmap(name, bmp, pal);
			destroy_bitmap(bmp);
			do {
				rest(5);
				if (NeedsPoll) poll_keyboard();
			} while (key[syskeys[4]]);
		}
	}

	// switch joystick
	if (key[syskeys[8]]) {
		joyswitch = joyswitch ? 0 : 1;

		set_defjoykeys(0,joyswitch);
		set_defjoykeys(1,joyswitch ? 0 : 1);
		int tmp = app_data.stick[0];
		app_data.stick[0] = app_data.stick[1];
		app_data.stick[1] = tmp;

		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[8]]);

	}

	if (key[KEY_ALT] && key[KEY_ENTER]) {
		app_data.fullscreen = app_data.fullscreen ? 0 : 1;
		grmode();
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[KEY_ENTER]);
	}		

}
Beispiel #15
0
int main(void)
{
   BITMAP *scroller;
   RGB black = { 0, 0, 0, 0 };
   int x = 0;
   int next_x;
   int h = 100;

   if (allegro_init() != 0)
      return 1;
   install_keyboard();

   if (set_gfx_mode(GFX_AUTODETECT, 320, 240, 640, 240) != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set a 320x240 mode with 640x240 "
		      "virtual dimensions\n");
      return 1;
   }

   /* the scrolling area is twice the width of the screen (640x240) */
   scroller = create_sub_bitmap(screen, 0, 0, SCREEN_W*2, SCREEN_H);

   set_palette(desktop_palette);
   set_color(0, &black);

   rectfill(scroller, 0, 0, SCREEN_W, 100, 6);
   rectfill(scroller, 0, 100, SCREEN_W, SCREEN_H, 2);

   do {
      /* advance the scroller, wrapping every 320 pixels */
      next_x = x + 1;
      if (next_x >= 320)
	 next_x = 0;

      /* draw another column of the landscape */
      acquire_bitmap(scroller);
      vline(scroller, next_x+SCREEN_W-1, 0, h, 6);
      vline(scroller, next_x+SCREEN_W-1, h+1, SCREEN_H, 2);
      release_bitmap(scroller);

      /* scroll the screen */
      scroll_screen(next_x, 0);

      /* duplicate the landscape column so we can wrap the scroller */
      if (next_x > 0) {
	 acquire_bitmap(scroller);
	 vline(scroller, x, 0, h, 6);
	 vline(scroller, x, h+1, SCREEN_H, 2);
	 release_bitmap(scroller);
      }

      /* randomly alter the landscape position */
      if (AL_RAND()&1) {
	 if (h > 5)
	    h--;
      }
      else {
	 if (h < 195)
	    h++;
      }

      x = next_x;

      rest(0);
   } while (!keypressed());

   destroy_bitmap(scroller);

   clear_keybuf();

   return 0;
}
Beispiel #16
0
int main() {

	BITMAP *backbuffer = NULL, *mysha;
	int count = 0;
	int old_time = 0, old_time2 = 0;
	int depth;
	int i;
	int use_alleg = 0;
	
	allegro_init();
	
	install_keyboard();
	install_timer();
	
	set_config_file("examples.cfg");
	depth = get_config_int("examples", "depth", 16);

	set_color_depth(depth);	
	if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
		set_color_depth(16);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
			set_color_depth(15);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
				set_color_depth(32);
				if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
					allegro_message("Unable to set 640x480 screen mode!\n");
					return -1;
				}
			}
		}
	}
	
	mysha = load_bitmap("mysha.pcx", NULL);
	
	if (!mysha) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to load mysha.pcx. Copy it from the allegro examples directory.\n");
		return -2;
	}
	
	backbuffer = create_bitmap(SCREEN_W, SCREEN_H);
	
	if (!backbuffer) {
		destroy_bitmap(mysha);
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Not enough memory to create backbuffer.\n");
		return -3;
	}
	
	LOCK_FUNCTION(the_timer);
	LOCK_VARIABLE(chrono);

	stretch_blit(mysha, backbuffer, 0, 0, mysha->w, mysha->h, 0, 0, SCREEN_W, SCREEN_H);
	
	for (i = 0; i < 4; i++) {
		fade[i].x = (SCREEN_W/2) * (i & 1);
		fade[i].y = (SCREEN_H/2) * (i & 2) >> 1;
		fade[i].fact = rand() & 255;
		fade[i].dir = (rand() & 1) ? 1 : -1;
		fade[i].src = create_sub_bitmap(backbuffer, fade[i].x, fade[i].y, SCREEN_W/2, SCREEN_H/2);
		fade[i].color = makecol((i & 1) * 255, ((i & 2) >> 1) * 255, 0);
	}
		

	install_int(the_timer, 1);
	old_time = chrono;

	while (!key[KEY_ESC]) {
		if (use_alleg) {
			stretch_blit(mysha, backbuffer, 0, 0, mysha->w, mysha->h, 0, 0, SCREEN_W, SCREEN_H);
		}
		textprintf(backbuffer, font, 0, 0, makecol(255, 255, 255), "%s  %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using FBlend", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono);

		if (use_alleg) {
			drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
			for (i = 0; i < 4; i++) {
				set_trans_blender(0, 0, 0, 255 - fade[i].fact);
				rectfill(fade[i].src, 0, 0, fade[i].src->w - 1, fade[i].src->h - 1, fade[i].color);
			}
			drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
		}
		else {
			for (i = 0; i < 4; i++) {
				fblend_fade_to_color(fade[i].src, screen, fade[i].x, fade[i].y, fade[i].color, fade[i].fact);
			}
		}

		if (key[KEY_SPACE]) {
			use_alleg = !use_alleg;
			key[KEY_SPACE] = 0;
			chrono = 0;
			count = 0;
			old_time = 0;
			old_time2 = 0;
		}
		count++;

		old_time2 = chrono;

		
		/* Draw the buffer */
		if (use_alleg) {
			blit(backbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		}
		
		for (i = 0; i < 4; i++) {
			fade[i].fact += fade[i].dir;
			if (fade[i].fact >= 255 || fade[i].fact <= 0)
				fade[i].dir = -fade[i].dir;
			fade[i].fact = MID(0, fade[i].fact, 255);
		}
	}
	for (i = 0; i < 4; i++) {
		destroy_bitmap(fade[i].src);
	}
	
	destroy_bitmap(backbuffer);
	destroy_bitmap(mysha);
	
	return 0;
}
Beispiel #17
0
int main(int argc, char *argv[])
{
  {
    int i;

    if((argc - 1) % 2)
      goto help;

    for(i = 1; i < argc - 1; i += 2)
      if(!editing && (!strcmp(argv[i], "-e") || !strcmp(argv[i], "--edit")))
	editing = argv[i+1];
      else if(!layout_title[0] && (!strcmp(argv[i], "-t") || !strcmp(argv[i], "--title")))
      {
	bzero(layout_title, 55);
	strncpy(layout_title, argv[i+1], 54);
      }
      else
      {
help:
	printf("usage: mahjong [--edit <layout> [--title <layout title>]]\n");
	return 0;
      }
  }

  srand(time(NULL));
  allegro_init();

  {
    int x, y, z;
    for(x = 16; x--;)
    for(y =  9; y--;)
    for(z =  3; z--;)
      pieceInit(board[x][y][z], x, y, z);
  }

  set_color_depth(SCREEN_DEPTH);

  if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,
      SCREEN_WIDTH,   SCREEN_HEIGHT,
      SCREEN_WIDTH*2, SCREEN_HEIGHT) < 0)
  {
    fprintf(stderr, "fatal: %s\n", allegro_error);
    exit(1);
  }

#ifdef ALLEGRO_WINDOWS
  set_display_switch_callback(SWITCH_IN, update);
#endif

  left_view =
    create_sub_bitmap(screen, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  right_view =
    create_sub_bitmap(screen, SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

  // init colors
    BACKGROUND_COLOR = makecol32(0x2F, 0x5F, 0x2F); // soft green
      SELECTED_COLOR = makecol32(0x00, 0xDF, 0x00); // green
  OLD_SELECTED_COLOR = makecol32(0x00, 0xBF, 0xBF); // cyan

  // load data
  {
    DATAFILE *data = load_datafile("#");
    new_game   = data[NEW_GAME_BMP].dat;
    undo       = data[UNDO_BMP].dat;
    help       = data[HELP_BMP].dat;
    quit       = data[QUIT_BMP].dat;
    tile       = data[TILE_BMP].dat;
    number[ 0] = data[BLACK1_BMP].dat;
    number[ 2] = data[BLACK2_BMP].dat;
    number[ 4] = data[BLACK3_BMP].dat;
    number[ 6] = data[BLACK4_BMP].dat;
    number[ 8] = data[BLACK5_BMP].dat;
    number[10] = data[BLACK6_BMP].dat;
    number[12] = data[BLACK7_BMP].dat;
    number[14] = data[BLACK8_BMP].dat;
    number[16] = data[BLACK9_BMP].dat;
    number[ 1] = data[RED1_BMP].dat;
    number[ 3] = data[RED2_BMP].dat;
    number[ 5] = data[RED3_BMP].dat;
    number[ 7] = data[RED4_BMP].dat;
    number[ 9] = data[RED5_BMP].dat;
    number[11] = data[RED6_BMP].dat;
    number[13] = data[RED7_BMP].dat;
    number[15] = data[RED8_BMP].dat;
    number[17] = data[RED9_BMP].dat;
    suit[0]    = data[SPADE_BMP].dat;
    suit[1]    = data[CLUB_BMP].dat;
    suit[2]    = data[DIAMOND_BMP].dat;
    suit[3]    = data[HEART_BMP].dat;
    layouts[0] = data[BLOCK_LYT].dat;
    layouts[1] = data[FLAT_LYT].dat;
    layouts[2] = data[FROGGER_LYT].dat;
    layouts[3] = data[PRECIOUS_LYT].dat;
    layouts[4] = data[PTRAD_LYT].dat;
    layouts[5] = data[PYRAMID_LYT].dat;
    layouts[6] = data[STEPS_LYT].dat;
    layouts[7] = data[THETA_LYT].dat;
  }

  scroll_screen(SCREEN_WIDTH, 0);
  current_view = right_view;

  install_timer();
  install_mouse();
  install_keyboard();
  show_mouse(current_view);

  text_mode(BACKGROUND_COLOR);

  if(!editing)
  {
    defaultLayout();

    if(alert("Our Own Version of Mahjong Solitaire, v0.1.4", NULL,
	     "Copyright (c) 2001 Eric Mulvaney, Michelle Bondy",
	     "Play", "Edit", 0, 0) == 2
	&& file_select_ex("Please select layout file to edit:", path, "lyt",
	    PATH_LENGTH-1, OLD_FILESEL_WIDTH, OLD_FILESEL_HEIGHT))
    {
      int x, y, z;

      editing = path;

      for(x = 16; x--;)
      for(y =  9; y--;)
      for(z =  3; z--;)
	board[x][y][z].value = EMPTY;
    }
  }

  mouse_callback = editing ? mouse_handler_for_editing : mouse_handler;

  if(editing)
  {
    Layout data;
    FILE *file = fopen(editing, "r");

    if(file)
    {
      if(fread(&data, sizeof(Layout), 1, file))
      {
	int x, y, z;

	if(!layout_title[0])
	  memcpy(layout_title, data.title, 55);

	for(x = 16; x--;)
	for(y =  9; y--;)
	for(z = (data.board[x][y] > 3) ? 3 : data.board[x][y]; z--;)
	{
	  board[x][y][z].value = BLANK;
	  if(!--n_pieces_left)
	    goto skip;
	}
      }
skip:
      fclose(file);
    }

    update();
  }

  click_ready = 0;
  while(1) // game loop
  {
    if(click_ready)
    {
      int x = click_x - (BOARD_XOFF - 2 * EDGE_WIDTH );
      int y = click_y - (BOARD_YOFF - 2 * EDGE_HEIGHT);
      int z;

      for(z = 3; x > 0 && y > 0 && z--; x -= EDGE_WIDTH, y -= EDGE_HEIGHT)
      {
	int i = x / FACE_WIDTH;
	int j = y / FACE_HEIGHT;

	if(i >= 16 || j >= 9)
	  continue;

	if(editing)
	{
	  if(click_ready == 1 && board[i][j][z].value == EMPTY)
	  {
	    if((z == 0 || board[i][j][z-1].value != EMPTY) && n_pieces_left)
	    {
	      n_pieces_left--;
	      board[i][j][z].value = BLANK;
	      updatePiece(&board[i][j][z]);
	      goto event_handled;
	    }
	  }
	  else if(click_ready == 2 && board[i][j][z].value != EMPTY)
	  {
	    if(z == 2 || board[i][j][z+1].value == EMPTY)
	    {
	      board[i][j][z].value = EMPTY;
	      n_pieces_left++;
	      updatePiece(&board[i][j][z]);
	      goto event_handled;
	    }
	  }
	}
	else if(selectPiece(&board[i][j][z]))
	{
	  if(!n_pairs_remaining)
	  {
	    if(current_view != left_view)
	      update();

	    if(alert("Congratulations!	You won!",
		     "Play another?",
		     NULL, "Yes", "No", 0, 0) == 1)
	      newGame();
	    else
	      return 0;
	  }

	  goto event_handled;
	}
      }

      if(click_y < BUTTON_YOFF + BUTTON_HEIGHT && click_y > BUTTON_YOFF)
      {
	if(editing)
	{
	  if(click_x > NEW_GAME_BUTTON_X1 && click_x < NEW_GAME_BUTTON_X2)
	  {
	    if(n_pieces_left == 144)
	      goto event_handled;

	    if(current_view != left_view)
	      update();

	    if(alert("Are you sure you want to clear the current Layout?",
		     NULL, NULL, "Yes", "No", 0, 0) == 1)
	    {
	      int x, y, z;
	      for(x = 16; x--;)
	      for(y =  9; y--;)
	      for(z =  3; z--;)
		board[x][y][z].value = EMPTY;
	      n_pieces_left = 144;
	      update();
	    }
	  }
	  else if(click_x > QUIT_BUTTON_X1 && click_x < QUIT_BUTTON_X2)
	  {
	    int ync;

	    if(current_view != left_view)
	      update();

	    if(n_pieces_left)
	      ync = alert3("WARNING: Layout is incomplete.",
			   NULL,
			   "Do you wish to save before exiting?",
			   "Yes", "No", "Cancel", 0, 0, 0);
	    else
	      ync = alert3("Do you wish to save before exiting?",
		    NULL, NULL, "Yes", "No", "Cancel", 0, 0, 0);

	    if(ync == 2)
	      return 0;
	    else if(ync == 1)
	    {
	      Layout data;
	      FILE *file;

	      memcpy(data.title, layout_title, 55);

	      data.complete = (n_pieces_left) ? 0 : 1;

	      if((file = fopen(editing, "w")))
	      {
		for(x = 16; x--;)
		for(y =  9; y--;)
		{
		  if	 (board[x][y][2].value == BLANK) data.board[x][y] = 3;
		  else if(board[x][y][1].value == BLANK) data.board[x][y] = 2;
		  else if(board[x][y][0].value == BLANK) data.board[x][y] = 1;
		  else					 data.board[x][y] = 0;
		}

		if(fwrite(&data, sizeof(Layout), 1, file))
		{
		  fclose(file);
		  return 0;
		}
		else
		  fclose(file);
	      }

	      if(alert("WARNING: Save failed!",
		       NULL,
		       "Do you still wish to exit?",
		       "Yes", "No", 0, 0) == 1)
		return 0;
	    }
	  }
	}
	else if(click_x > NEW_GAME_BUTTON_X1 && click_x < NEW_GAME_BUTTON_X2)
	  newGame();
	else if(click_x > UNDO_BUTTON_X1 && click_x < UNDO_BUTTON_X2)
	  undoMove();
	else if(click_x > HELP_BUTTON_X1 && click_x < HELP_BUTTON_X2)
	  giveHelp(1);
	else if(click_x > QUIT_BUTTON_X1 && click_x < QUIT_BUTTON_X2)
	{
	  if(current_view != left_view)
	    update();

	  if(alert("Are you sure you want to quit?",
	      NULL, NULL, "Yes", "No", 0, 0) == 1)
	    return 0;
	}
      }

event_handled:

      click_ready = 0;
    }
    else
      rest(100);
  }

  return 0;
}
Beispiel #18
0
/* See README for details.
 */
void
abitmap_init (char const *path, DATAFILE *datafile)
{
	int i;
	int prev[10];
	int cv;
	char str[1024];
	DATAFILE *dat;

	cv = get_color_conversion ();
	set_color_conversion (COLORCONV_TOTAL | COLORCONV_KEEP_TRANS);

	used_bitmaps_cleanup ();

	push_config_state ();
	dat = set_theme_config (path, datafile);
	if (dat != datafile)
		used_dat = dat;

	theme->fg_color = get_color_string ("fg", "0x000000");
	theme->bg_color = get_color_string ("bg", "0xffffff");
	theme->mg_color = get_color_string ("mg", "0x808080");

	theme->textpushx = get_config_int ("agup.cfg", "px", 0);
	theme->textpushy = get_config_int ("agup.cfg", "py", 0);

	for (i = 0; bload[i].name; i++) {
		int j;
		int s;

		char const *suffix[] = { "", "_hl", "_dis" };

		for (s = 0; bload[i].name[s] == ' '; s++);

		for (j = 0; j < 3; j++) {
			char **argv = NULL;
			int argc = 0;
			BITMAP *bmp = NULL;
			int got_color = 0;

			theme->bitmaps[bload[i].elem][j].bmp = NULL;
			theme->bitmaps[bload[i].elem][j].flags = 0;
			theme->bitmaps[bload[i].elem][j].bl = 0;
			theme->bitmaps[bload[i].elem][j].br = 0;
			theme->bitmaps[bload[i].elem][j].bt = 0;
			theme->bitmaps[bload[i].elem][j].bb = 0;

			sprintf (str, "%s%s", bload[i].name + s, suffix[j]);
			argv = get_config_argv ("agup.cfg", str, &argc);

			TRACE ("%s: ", str);

			if (argc) {
				bmp = find_theme_bitmap (dat, argv[0]);
			}

			if (bmp) {
				int a;

				theme->bitmaps[bload[i].elem][j].bmp = bmp;

				for (a = 1; a < argc; a++) {
					if (!strcmp (argv[a], "stretch"))
						theme->bitmaps[bload[i].elem][j].flags |=
							ABMAP_STRETCH_H | ABMAP_STRETCH_V;
					else if (!strcmp (argv[a], "center"))
						theme->bitmaps[bload[i].elem][j].flags |=
								ABMAP_CENTER_H | ABMAP_CENTER_V;
					else if (!strcmp (argv[a], "stretchh"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_STRETCH_H;
					else if (!strcmp (argv[a], "centerh"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_CENTER_H;
					else if (!strcmp (argv[a], "alignh"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_ALIGN_H;
					else if (!strcmp (argv[a], "stretchv"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_STRETCH_V;
					else if (!strcmp (argv[a], "centerv"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_CENTER_V;
					else if (!strcmp (argv[a], "alignv"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_ALIGN_V;
					else if (!strcmp (argv[a], "cut")) {
						int cx, cy, cw, ch;
						a++;
						if (a < argc) {
							cx = strtol (argv[a], NULL, 10);
							a++;
							if (a < argc) {
								cy = strtol (argv[a], NULL, 10);
								a++;
								if (a < argc) {
									cw = strtol (argv[a], NULL, 10);
									a++;
									if (a < argc) {
										BITMAP *sub;
										ch = strtol (argv[a], NULL, 10);
										if (cw <= 0)
											cw += bmp->w;
										if (ch <= 0)
											ch += bmp->h;
										sub = create_sub_bitmap (bmp, cx, cy, cw, ch);
										used_bitmap (sub, NULL);
										theme->bitmaps[bload[i].elem][j].bmp = sub;
									}
								}
							}
						}
					}
					else if (!strcmp (argv[a], "border")) {
						a++;
						if (a < argc) {
							theme->bitmaps[bload[i].elem][j].bl = strtol (argv[a], NULL, 10);
							a++;
							if (a < argc) {
								theme->bitmaps[bload[i].elem][j].br =
									strtol (argv[a], NULL, 10);
								a++;
								if (a < argc) {
									theme->bitmaps[bload[i].elem][j].bt =
										strtol (argv[a], NULL, 10);
									a++;
									if (a < argc) {
										theme->bitmaps[bload[i].elem][j].bb =
											strtol (argv[a], NULL, 10);
									}
								}
							}
						}
					}
					else if (!strcmp (argv[a], "color")) {
						a++;
						if (a < argc) {
							int rgb32 = strtol (argv[a], NULL, 0);

							theme->bitmaps[bload[i].elem][j].color =
								makecol (rgb32 >> 16, (rgb32 >> 8) & 255,
								rgb32 & 255);
							got_color = 1;
							TRACE ("color %06x ", rgb32);
						}
					}
				}
				TRACE ("loaded successfully.\n");
			} else {
				/* If everything fails, try to inherit from another bitmap. */
				if (j) {
Beispiel #19
0
int main(int argc, char *argv[])
{
    int i, idx, color_depth = -1;
    if (argc >= 2) color_depth = atoi(argv[1]);
    if (color_depth != 16 && color_depth != 24 && color_depth != 32) {
        printf("Usage: test [color_depth]\n");
        return -1;
    }

    allegro_init();
    install_keyboard();
    set_color_depth(color_depth);
    if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0) != 0) return -1;
    backbuffer = create_bitmap(SCREEN_W, SCREEN_H);
    BITMAP *backbuffer1 = create_bitmap(SCREEN_W, SCREEN_H);
    BITMAP *backbuffer2 = create_bitmap(SCREEN_W, SCREEN_H);

    // Load fire sprites (alpha transparency used)
    fire_ex = load_bitmap_alpha("fire.tga", true);
    for (int idx = 0; idx < SPRITE_COUNT; idx++) {
        i = idx % 8;
        fire_ex_bitmaps[idx] = create_sub_bitmap(fire_ex, (i % 4) * 33, (i / 4) * 41, 32, 40);
        fire_ex_rle_sprites[idx] = get_rle_sprite(fire_ex_bitmaps[i]);
        fire_ex_alpha_sprites[idx] = get_alpha_sprite(fire_ex_bitmaps[i]);
    }

    // Load fire sprites (no alpha transparency used)
    fire = load_bitmap_alpha("fire.tga", false);
    for (int idx = 0; idx < SPRITE_COUNT; idx++) {
        i = idx % 8;
        fire_bitmaps[idx] = create_sub_bitmap(fire, (i % 4) * 33, (i / 4) * 41, 32, 40);
        fire_rle_sprites[idx] = get_rle_sprite(fire_bitmaps[i]);
        fire_alpha_sprites[idx] = get_alpha_sprite(fire_bitmaps[i]);
    }

    // Load explosion sprites (alpha transparency used)
    explosion = load_bitmap_alpha("explosion.tga", true);
    for (i = 0; i < 10; i++) {
        explosion_bitmaps[i] = create_sub_bitmap(explosion, 0, 179 * i, 256, 178);
        explosion_rle_sprites[i] = get_rle_sprite(explosion_bitmaps[i]);
        explosion_alpha_sprites[i] = get_alpha_sprite(explosion_bitmaps[i]);
    }

    printf("---\n");
    printf("explosion sprites per second (spritelib)      = %.1lf\n", run_test(backbuffer1, test_explosion_spritelib));
    printf("explosion sprites per second (allegro rle)    = %.1lf\n", run_test(backbuffer2, test_explosion_allegro_rle));
    printf("explosion sprites per second (allegro bitmap) = %.1lf\n", run_test(backbuffer2, test_explosion_allegro));
    if (!compare_bitmaps(backbuffer1, backbuffer2)) printf("Error: results do not match!\n");
    TESTS_COUNT = 500000;
    printf("---\n");
    printf("normal fire sprites per second (spritelib)    = %.1lf\n", run_test(backbuffer1, test_fire_spritelib));
    printf("normal fire sprites per second (allegro rle)  = %.1lf\n", run_test(backbuffer2, test_fire_allegro_rle));
    if (!compare_bitmaps(backbuffer1, backbuffer2)) printf("Error: results do not match!\n");
    printf("---\n");
    printf("lit fire sprites per second (spritelib)       = %.1lf\n", run_test(backbuffer1, test_fire_lit_spritelib));
    printf("lit fire sprites per second (allegro rle)     = %.1lf\n", run_test(backbuffer2, test_fire_lit_allegro_rle));
    if (!compare_bitmaps(backbuffer1, backbuffer2)) printf("Error: results do not match!\n");
    printf("---\n");
    printf("alpha fire sprites per second (spritelib)     = %.1lf\n", run_test(backbuffer1, test_fire_alpha_spritelib));
    printf("alpha fire sprites per second (allegro rle)   = %.1lf\n", run_test(backbuffer2, test_fire_alpha_allegro_rle));
    if (!compare_bitmaps(backbuffer1, backbuffer2)) printf("Error: results do not match!\n");

    i = 0;
    while (true) {
        if (keypressed()) {
            int scancode;
            ureadkey(&scancode);
            if (scancode == KEY_ESC) break;
        }
        clear_to_color(backbuffer, makecol(64, 64, 64));
        int brightness = (i % 512) - 256;
        if (brightness < 0) brightness = -brightness;
        draw_alpha_sprite(backbuffer, explosion_alpha_sprites[i % 10], 0, 0, brightness);
        draw_alpha_sprite(backbuffer, fire_alpha_sprites[i % 4], 300, 0, brightness);
        draw_alpha_sprite(backbuffer, fire_alpha_sprites[(i % 4) + 4], 300, 50, 256 - brightness);
        draw_alpha_sprite(backbuffer, fire_alpha_sprites[i % 4], 300, 100, 250);
        draw_alpha_sprite(backbuffer, fire_alpha_sprites[(i % 4) + 4], 300, 150, 250);
        blit(backbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
        rest(100);
        i++;
    }

    destroy_bitmap(backbuffer);
    destroy_bitmap(backbuffer1);
    destroy_bitmap(backbuffer2);

    for (idx = 0; idx < SPRITE_COUNT; idx++) {
        destroy_bitmap(fire_ex_bitmaps[idx]);
        destroy_rle_sprite(fire_ex_rle_sprites[idx]);
        destroy_alpha_sprite(fire_ex_alpha_sprites[idx]);
        destroy_bitmap(fire_bitmaps[idx]);
        destroy_rle_sprite(fire_rle_sprites[idx]);
        destroy_alpha_sprite(fire_alpha_sprites[idx]);
    }
    destroy_bitmap(fire_ex);
    destroy_bitmap(fire);

    // Load explosion sprites (alpha transparency used)
    for (i = 0; i < 10; i++) {
        destroy_bitmap(explosion_bitmaps[i]);
        destroy_rle_sprite(explosion_rle_sprites[i]);
        destroy_alpha_sprite(explosion_alpha_sprites[i]);
    }
    destroy_bitmap(explosion);

    allegro_exit();

    return 0;
}
Beispiel #20
0
int Manual()
{
  int PVi, k;
        K= uatof(Gain);
  /* Things will be drawn more quickly if you always acquire the screen before
     trying to draw onto it. */
  acquire_screen();
  
  Graphics();	/* Call to graphics from a different function to avoid messy code */
  
  int dir = 1;   //since we are receiving data, direction should be 1
  int mode = IEEE1284_MODE_COMPAT; // parameter to set mode 'receive'
  RLE_SPRITE *rle;
  
  /* Set the direction for reception */
  ioctl(fd, PPDATADIR, &dir);
  ioctl(fd, PPWDATA, 0);
  
  PVi= 0;  k= 100;  M=0;
  while (!key[KEY_ESC])	/* Only pressing ESC can Exit */
    {
      M++;
      /* Check if user needs some help */
      if(key[KEY_F1])
	Help();

      k++;
      i= 897;
      
      Captura = create_sub_bitmap(screen, 72, 350, 898, 368);
      rle = get_rle_sprite(Captura);
      destroy_bitmap(Captura);
      draw_rle_sprite(screen, rle, 71, 350);
      destroy_rle_sprite(rle);
      
      /* This line reads data from the interfase which is
	 the process variable(measured variable) of the system */
      ioctl(fd, PPRDATA, &PVi);
      PV= PVi;
      
      if(PV<=40)
	{
	  PV= 51;
	  system("festival --tts Messages/Disconnected&");
	  blit(Disconnected, screen, 0, 0, 70, 290, 887, 52);   
	}
      
      if(PV<=48)
        PVi= 51;
      
      PV= 1.794117647*(PVi-51);
      SP= PV;
      
      if(key[KEY_RIGHT])
	{
          fd = close("/dev/parport0");	
	  Simulator();
        }
      if(key[KEY_PGUP])
	OP= (OP+46);
      
      if(key[KEY_PGDN])
	OP= (OP-46);
      
      if(key[KEY_UP])
	OP= (OP+3.66);
      
      if(key[KEY_DOWN])
	{
	  if(OP>=1)
	    OP= (OP-3.66);
	}
      
      if(key[KEY_PRTSCR])
	{
          Captura = create_sub_bitmap(screen, 0, 0, 1024, 768);
          save_bitmap("images/User/Captura.pcx", Captura, pal);
          destroy_bitmap(Captura);
        }
      
      Timer++;
      
      if(OP<=0)
	OP= 0;
      
      
      if (PV>=40)
	{
	  textprintf_ex(screen, font, 230, 297, BLACK, WHITE, "%3.1f", (PV/368)*100);	// Medición
	  textprintf_ex(screen, font, 450, 297, BLACK, WHITE, "%3.1f", (SP/368)*100);	// SP
	  textprintf_ex(screen, font, 710, 297, BLACK, WHITE, "%3.1f", (OP/368)*100);	// Controlador
	}
      
      if(k>=100)
	{
 	  k= 0;
	  vline(screen, 967, 351, 717, GRAY);
          blit(Clean, screen, 0, 0, 968, 350, 2, 368);
	}
      
      int Recorder;
      Recorder++;
      if(Recorder>=900)
	{
 	  Recorder= 0;
	  Captura = create_sub_bitmap(screen, 258, 350, 715, 368);
	}
      
      Captura = create_sub_bitmap(screen, 248, 350, 705, 368);
      
      
      if(PV>=362) PV= 365;
      if(OP>=367) OP= 365;
      
      if(PV<=0) PV= 0;
      if(OP<=0) OP= 0;
      
      /* Draw the behaviour of the PV, SP and OP over time */
      line(screen, 71+i, 717-PV, 71+i, 717-PVj, RED);	
      PVj= PV;    /* Flag for line y2 as a precedent state */
      line(screen, 71+i, 717-OP, 71+i, 717-OPj, BLUE);	
      OPj= OP;    /* Flag for line y2 as a precedent state */
      
      fprintf(outfile,"%i\t%f\t %f\t %f\n", M, ((PV/368)*100), ((SP/368)*100), ((OP/368)*100));
      rest(Delay);
    }
  int ScreenWide;
  RLE_SPRITE *rle0, *rle1;
  BITMAP *Screen3;

  Screen3 = load_bitmap("images/Close/Base.pcx", pal);
  system("mp3blaster /home/mentesuprema/Residencia/sounds/swing2.wav &");
  rest(5);

  rle0= get_rle_sprite(Screen2);
  rle1= get_rle_sprite(Screen3);
  
  for(ScreenWide=0;ScreenWide<=768;ScreenWide=ScreenWide+5)
    {
      draw_rle_sprite(screen, rle0, 0, 768);
      draw_rle_sprite(screen, rle1, 0, -768+ScreenWide);
    }

  destroy_rle_sprite(rle0);  
  destroy_rle_sprite(rle1);    
  destroy_bitmap(Screen2);
  destroy_bitmap(Screen3);
  destroy_bitmap(Clean);
  destroy_bitmap(Disconnected);
  release_screen();
  Close();
  exit(0);
} 
Beispiel #21
0
int Manual(int argc, unsigned char **argv)
{
  /* Serial port initialization */

  fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    perror("open_port: Unable to open /dev/ttyS0 - ");
    return 1;
  } else {
    fcntl(fd, F_SETFL, 0);
  }
  getbaud(fd);

  initport(fd);

  int PVi, k;
        K= uatof(Gain);
  /* Things will be drawn more quickly if you always acquire the screen before
     trying to draw onto it. */
  acquire_screen();
  
  Graphics();	/* Call to graphics from a different function to avoid messy code */
  
  RLE_SPRITE *rle;
 
            sCmd[0]= 'C';
            writeport(fd, sCmd);

  PVi= 0;  k= 100;  M=0;
  while (!key[KEY_ESC])	/* Only pressing ESC can Exit */
    {
	char ValveState;
	if(ValveState=='O')
	{
            sCmd[0]= 'A';
            writeport(fd, sCmd);
	}
	if(ValveState=='C')
	{
            sCmd[0]= 'C';
            writeport(fd, sCmd);
	}
	


      M++;
      /* Check if user needs some help */
      if(key[KEY_F1])
	Help();

      k++;
      i= 897;
      
      Captura = create_sub_bitmap(screen, 72, 350, 898, 368);
      rle = get_rle_sprite(Captura);
      destroy_bitmap(Captura);
      draw_rle_sprite(screen, rle, 71, 350);
      destroy_rle_sprite(rle);

      /* This line reads data from the interfase which is
	 the process variable(measured variable) of the system */
          fcntl(fd, F_SETFL, FNDELAY); // don't block serial read
	  readport(fd,sResult);
	  PVi= (int) *sResult;
	  PV= PVi;      
/*
      if(PVi<=40)
	{
	  PV= 51;
	  system("festival --tts Messages/Disconnected&");
	  blit(Disconnected, screen, 0, 0, 70, 290, 887, 52);   
	}
   */   
      if(PV<=48)
        PVi= 51;
      
      PV= 1.794117647*(PVi-51);
      SP= PV;
      
      if(key[KEY_RIGHT])
	{
          //fd = close("/dev/parport0");	
	  Simulator();
        }
      if(key[KEY_PGUP])
	OP= (OP+46);
      
      if(key[KEY_PGDN])
	OP= (OP-46);
      
      if(key[KEY_UP])
	{
	    OP=162; //(OP+3.66);
            sCmd[0]= 'A';
            writeport(fd, sCmd);
	    ValveState='O';
	}

      if(key[KEY_DOWN])
	{
	  if(OP>=1)
	    OP= 0;//(OP-3.66);
            sCmd[0]= 'C';
            writeport(fd, sCmd);
	    ValveState='C';
	}
      
      if(key[KEY_PRTSCR])
	{
          Captura = create_sub_bitmap(screen, 0, 0, 1024, 768);
          save_bitmap("images/User/Captura.pcx", Captura, pal);
          destroy_bitmap(Captura);
        }
      
      Timer++;
      
      if(OP<=0)
	OP= 0;
      
      
//      if (PV>=40)
//	{
	  textprintf_ex(screen, font, 230, 297, BLACK, WHITE, "%3.1f", (PV/368)*100);	// Medición
	  textprintf_ex(screen, font, 450, 297, BLACK, WHITE, "%3.1f", (SP/368)*100);	// SP
	  textprintf_ex(screen, font, 710, 297, BLACK, WHITE, "%3.1f", (OP/368)*100);	// Controlador
//	}
      
      if(k>=100)
	{
 	  k= 0;
	  vline(screen, 967, 351, 717, GRAY);
          blit(Clean, screen, 0, 0, 968, 350, 2, 368);
	}
      
      int Recorder;
      Recorder++;
      if(Recorder>=900)
	{
 	  Recorder= 0;
	  Captura = create_sub_bitmap(screen, 258, 350, 715, 368);
	}
      
      Captura = create_sub_bitmap(screen, 248, 350, 705, 368);
      
      
      if(PV>=362) PV= 365;
      if(OP>=367) OP= 365;
      
      if(PV<=0) PV= 0;
      if(OP<=0)
	 OP= 1;
/*
      OPi= fixtoi(itofix((OP*0.69234783)/255*100));
      sCmd[0]= (unsigned char)OPi+50;
      sCmd[0]= sCmd[0]+0.00;
      writeport(fd, sCmd);
*/
//     textprintf_ex(screen, font, 30, 297, BLACK, WHITE, "%i - %s - %3.1f", PVi, sResult, PV);	// Medición      

      /* Draw the behaviour of the PV, SP and OP over time */
      line(screen, 71+i, 717-PV, 71+i, 717-PVj, RED);	
      PVj= PV;    /* Flag for line y2 as a precedent state */
      line(screen, 71+i, 717-OP, 71+i, 717-OPj, BLUE);	
      OPj= OP;    /* Flag for line y2 as a precedent state */
      
      fprintf(outfile,"%i\t%f\t %f\t %f\n", M, ((PV/368)*100), ((SP/368)*100), ((OP/368)*100));
      rest(Delay);
    }
  int ScreenWide;
  RLE_SPRITE *rle0, *rle1;
  BITMAP *Screen3;

  Screen3 = load_bitmap("images/Close/Base.pcx", pal);
  system("mp3blaster /home/mentesuprema/Residencia/sounds/swing2.wav &");
  rest(5);

  rle0= get_rle_sprite(Screen2);
  rle1= get_rle_sprite(Screen3);
  
  for(ScreenWide=0;ScreenWide<=768;ScreenWide=ScreenWide+5)
    {
      draw_rle_sprite(screen, rle0, 0, 768);
      draw_rle_sprite(screen, rle1, 0, -768+ScreenWide);
    }

  destroy_rle_sprite(rle0);  
  destroy_rle_sprite(rle1);    
  destroy_bitmap(Screen2);
  destroy_bitmap(Screen3);
  destroy_bitmap(Clean);
  destroy_bitmap(Disconnected);
  release_screen();
  Close();
  exit(0);
} 
Beispiel #22
0
void Cutbit::draw(
    Torbit&      target_torbit,
    const int    x,
    const int    y,
    const int    fx,
    const int    fy,
    const bool   mirr,
    const double rot,
    const double scal,
    const Mode   mode) const
{
    BITMAP* target = target_torbit.get_al_bitmap();
    if (bitmap && fx >= 0 && fy >= 0 && fx < x_frames && fy < y_frames) {
        // Schneide zunaechst ein Subbitmap aus unter Beachtung der Framewahl
        // Hat das Bild keine Frames, entfaellt +1 fuer den aeusseren Rahmen.
        BITMAP* sprite;
        if (x_frames == 1 && y_frames == 1)
             sprite = create_sub_bitmap(bitmap, 0, 0, xl, yl);
        else sprite = create_sub_bitmap(bitmap, fx * (xl+1) + 1,
                                                fy * (yl+1) + 1, xl, yl);
        if (mode == NORMAL) {
            target_torbit.draw_from(sprite, x, y, mirr, rot, scal);
        }
        else {
            const int PINK  = color[COL_PINK];
            const int BLACK = color[COL_BLACK];
            const int GREY  = color[COL_EDITOR_DARK];
            const int size  = xl > yl ? xl : yl;
            Torbit excerpt(size, size);
            excerpt.clear_to_color(PINK);
            excerpt.draw_from(sprite, 0, 0, mirr, rot, scal);
            if (mode == NOOW) {
                target_torbit.draw     (excerpt.get_al_bitmap(), x, y);
                target_torbit.draw_from(excerpt.get_al_bitmap(), x, y);
            }
            else if (mode == NOOW_EDITOR) {
                for  (int ix = 0; ix < size; ++ix)
                 for (int iy = 0; iy < size; ++iy) {
                    const int c = target_torbit.get_pixel(x + ix, y + iy);
                    const int e = excerpt      .get_pixel(    ix,     iy);
                    if ((c == BLACK || c == PINK || c == GREY)
                     &&  e != BLACK && e != PINK)
                     target_torbit.set_pixel(x + ix, y + iy, e);
            }   }
            else if (mode == DARK
                  || mode == DARK_EDITOR) {
                for  (int ix = 0; ix < size; ++ix)
                 for (int iy = 0; iy < size; ++iy)
                 if (excerpt.get_pixel(ix, iy) != PINK)
                 target_torbit.set_pixel(x+ix, y+iy, mode==DARK ? PINK : GREY);
            }
        }
        // Fertig
        destroy_bitmap(sprite);
    }

    // Keine gueltige Frame-Angabe
    else {
        int          col_text = makecol(255, 255, 255);
        int          col_back = makecol( 64,  64,  64);
        if (!bitmap) col_back = makecol(255,  64,  64);
        std::ostringstream str;
        str << "( " << fx << " | " << fy << " )";
        textout_ex(target, font, "Frame?!?!", x, y,        col_text, col_back);
        textout_ex(target, font, str.str().c_str(), x, y+8,col_text, col_back);
    }
}
Beispiel #23
0
/*! \brief Load all enemies from disk
 *
 * Loads up enemies from the *.mon files and fills the enemies[] array.
 * \author PH
 * \date 2003????
 */
static void load_enemies (void)
{
   int i, tmp, lx, ly, p;
   FILE *edat;
   s_fighter *f;

   if (enemies != NULL) {
      /* Already done the loading */
      return;
   }
   enemy_pcx = load_datafile_object (PCX_DATAFILE, "ENEMY_PCX");
   if (enemy_pcx == NULL) {
      program_death (_("Could not load enemy sprites from datafile!"));
   }
   edat = fopen (kqres (DATA_DIR, "allstat.mon"), "r");
   if (!edat)
      program_death (_("Could not load 1st enemy datafile!"));
   enemies_n = 0;
   enemies_cap = 128;
   enemies = (s_fighter **) malloc (sizeof (s_fighter *) * enemies_cap);
   // Loop through for every monster in allstat.mon
   while (fscanf (edat, "%s", strbuf) != EOF) {
      if (enemies_n >= enemies_cap) {
         enemies_cap *= 2;
         enemies =
            (s_fighter **) realloc (enemies,
                                    sizeof (s_fighter *) * enemies_cap);
      }
      f = enemies[enemies_n++] = (s_fighter *) malloc (sizeof (s_fighter));
      memset (f, 0, sizeof (s_fighter));
      // Enemy name
      strncpy (f->name, strbuf, sizeof (f->name));
      // Index number (ignored; automatically generated)
      fscanf (edat, "%d", &tmp);
      // x-coord of image in datafile
      fscanf (edat, "%d", &tmp);
      lx = tmp;
      // y-coord of image in datafile
      fscanf (edat, "%d", &tmp);
      ly = tmp;
      // Image width
      fscanf (edat, "%d", &tmp);
      f->cw = tmp;
      // Image length (height)
      fscanf (edat, "%d", &tmp);
      f->cl = tmp;
      // Experience points earned
      fscanf (edat, "%d", &tmp);
      f->xp = tmp;
      // Gold received
      fscanf (edat, "%d", &tmp);
      f->gp = tmp;
      // Level
      fscanf (edat, "%d", &tmp);
      f->lvl = tmp;
      // Max HP
      fscanf (edat, "%d", &tmp);
      f->mhp = tmp;
      // Max MP
      fscanf (edat, "%d", &tmp);
      f->mmp = tmp;
      // Defeat Item Probability: chance of finding any items after defeat
      fscanf (edat, "%d", &tmp);
      f->dip = tmp;
      // Defeat Item Common: item found commonly of the time
      fscanf (edat, "%d", &tmp);
      f->defeat_item_common = tmp;
      // Defeat Item Rare: item found rarely
      fscanf (edat, "%d", &tmp);
      f->defeat_item_rare = tmp;
      // Steal Item Common: item found commonly from stealing
      fscanf (edat, "%d", &tmp);
      f->steal_item_common = tmp;
      // Steal Item Rare: item found rarely when stealing
      fscanf (edat, "%d", &tmp);
      f->steal_item_rare = tmp;
      // Enemy's strength (agility & vitality set to zero)
      fscanf (edat, "%d", &tmp);
      f->stats[A_STR] = tmp;
      f->stats[A_AGI] = 0;
      f->stats[A_VIT] = 0;
      // Intelligence & Sagacity (both the same)
      fscanf (edat, "%d", &tmp);
      f->stats[A_INT] = tmp;
      f->stats[A_SAG] = tmp;
      // Defense against: Speed, Spirit, Attack, Hit, Defence, Evade, Magic (in that order)
      for (p = 5; p < 13; p++) {
         fscanf (edat, "%d", &tmp);
         f->stats[p] = tmp;
      }
      // Bonus
      fscanf (edat, "%d", &tmp);
      f->bonus = tmp;
      f->bstat = 0;
      // Current weapon type
      fscanf (edat, "%d", &tmp);
      f->cwt = tmp;
      // Weapon elemental type
      fscanf (edat, "%d", &tmp);
      f->welem = tmp;
      // Undead Level (defense against Undead attacks)
      fscanf (edat, "%d", &tmp);
      f->unl = tmp;
      // Critical attacks
      fscanf (edat, "%d", &tmp);
      f->crit = tmp;
      // Temp Sag & Int for Imbued
      fscanf (edat, "%d", &tmp);
      f->imb_s = tmp;
      // Imbued stat type (Spd, Spi, Att, Hit, Def, Evd, Mag)
      fscanf (edat, "%d", &tmp);
      f->imb_a = tmp;
      f->img =
         create_sub_bitmap ((BITMAP *) enemy_pcx->dat, lx, ly, f->cw, f->cl);
      for (p = 0; p < 2; p++) {
         fscanf (edat, "%d", &tmp);
         f->imb[p] = tmp;
      }
   }
   fclose (edat);
   edat = fopen (kqres (DATA_DIR, "resabil.mon"), "r");
   if (!edat)
      program_death (_("Could not load 2nd enemy datafile!"));
   for (i = 0; i < enemies_n; i++) {
      f = enemies[i];
      fscanf (edat, "%s", strbuf);
      fscanf (edat, "%d", &tmp);
      for (p = 0; p < R_TOTAL_RES; p++) {
         fscanf (edat, "%d", &tmp);
         f->res[p] = tmp;
      }
      for (p = 0; p < 8; p++) {
         fscanf (edat, "%d", &tmp);
         f->ai[p] = tmp;
      }
      for (p = 0; p < 8; p++) {
         fscanf (edat, "%d", &tmp);
         f->aip[p] = tmp;
         f->atrack[p] = 0;
      }
      f->hp = f->mhp;
      f->mp = f->mmp;
      for (p = 0; p < 24; p++)
         f->sts[p] = 0;
      f->aux = 0;
      f->mrp = 100;
   }
   fclose (edat);
}
Beispiel #24
0
//-----------------------------------------------------------------------------
// Capture_Screen(void)
// Capture current screen to a file
//-----------------------------------------------------------------------------
static void		Capture_Screen(void)
{
    //PALETTE     pal;
    BITMAP *    bmp;
    BITMAP *    source;
    char        s1[FILENAME_LEN];
    int         x_start, x_len;
    int         y_start, y_len;

    // Get a filename
    Capture_FileName_Get(s1);
    if (Capture.id_number >= CAPTURE_ID_MAX)
    {
        Msg(MSGT_USER, Msg_Get(MSG_Capture_Error_File));
        return;
    }

	if ((Meka_State == MEKA_STATE_FULLSCREEN) || (!g_Configuration.capture_include_gui)) 
	{
		// Fullscreen
		source = screenbuffer;
		x_start = cur_drv->x_start;
		y_start = cur_drv->y_show_start;
		x_len = cur_drv->x_res;
		y_len = cur_drv->y_res;

		// Crop left column
		if (g_Configuration.capture_crop_scrolling_column)
		{
			if ((cur_drv->id == DRV_SMS) && (tsms.VDP_VideoMode > 4) && (Mask_Left_8))
			{
				x_start += 8;
				x_len -= 8;
			}
		}

		// Automatic crop on tile boundaries (for map making)
		// In total, remove 8 pixels from each axis
		if (g_Configuration.capture_crop_align_8x8)
		{
			const int scroll_x = cur_machine.VDP.scroll_x_latched;
			const int scroll_y = cur_machine.VDP.scroll_y_latched;
			x_start += scroll_x & 7;
			y_start += 8 - (scroll_y & 7);
			x_len -= 8;
			y_len -= 8;
		}
	}
	else if (Meka_State == MEKA_STATE_GUI)
	{
		// GUI mode
		x_start = 0;
		y_start = 0;
		x_len = g_Configuration.video_mode_gui_res_x;
		y_len = g_Configuration.video_mode_gui_res_y;
		source = gui_buffer;
	}
	else
	{
		// Unknown Mode
		assert(0);
		return;
	}

    acquire_bitmap(source);
    bmp = create_sub_bitmap(source, x_start, y_start, x_len, y_len);
    if (bmp == NULL)
    {
        Msg(MSGT_USER, Msg_Get(MSG_Capture_Error));
        return;
    }
    release_bitmap(source);

    //get_palette(pal);
    if (save_bitmap(s1, bmp, NULL) != 0)
    {
        Msg(MSGT_USER, Msg_Get(MSG_Capture_Error));
        destroy_bitmap(bmp);
        return;
    }

    destroy_bitmap(bmp);

    // Verbose
    killpath(s1);
    Msg(MSGT_USER, Msg_Get(MSG_Capture_Done), s1);
}
static int
preview_proc(int msg, DIALOG *d, int c)
{
	BITMAP *bmp;
	static int quality = 75, flags = JPG_SAMPLING_444;
	int new_quality, new_flags = 0;
	int size;

	(void)c;

	new_quality = settings_dialog[QUALITY_SLIDER].d2 + 1;
	if (settings_dialog[SS_444_RADIO].flags & D_SELECTED)
		new_flags = JPG_SAMPLING_444;
	if (settings_dialog[SS_422_RADIO].flags & D_SELECTED)
		new_flags = JPG_SAMPLING_422;
	if (settings_dialog[SS_411_RADIO].flags & D_SELECTED)
		new_flags = JPG_SAMPLING_411;
	if (settings_dialog[GREYSCALE_CHECK].flags & D_SELECTED)
		new_flags |= JPG_GREYSCALE;
	if (settings_dialog[OPTIMIZE_CHECK].flags & D_SELECTED)
		new_flags |= JPG_OPTIMIZE;
	
	switch (msg) {
		case MSG_START:
			d->dp2 = (void *)create_bitmap(d->w, d->h);
			bmp = (BITMAP *)d->dp;
			d->dp3 = malloc(ESTIMATED_MAX_JPG_SIZE(bmp));
			clear_to_color((BITMAP *)d->dp2, gui_mg_color);
			d->d2 = 20;
			sprintf(size_string, "Size: ?");
			break;

		case MSG_END:
			destroy_bitmap((BITMAP *)d->dp2);
			free(d->dp3);
			break;

		case MSG_DRAW:
			clear_to_color((BITMAP *)d->dp2, gui_mg_color);
			bmp = (BITMAP *)d->dp;
			bmp = create_sub_bitmap(bmp, MAX(0, (bmp->w - d->w) / 2), MAX(0, (bmp->h - d->h) / 2), d->w, d->h);
			if (!bmp)
				goto preview_error;
			size = ESTIMATED_MAX_JPG_SIZE(bmp);
			if (save_memory_jpg_ex(d->dp3, &size, bmp, NULL, quality, flags, NULL))
				goto preview_error;
			size = ESTIMATED_MAX_JPG_SIZE(bmp);
			destroy_bitmap(bmp);
			bmp = load_memory_jpg(d->dp3, size, NULL);
			if (!bmp)
				goto preview_error;
			blit(bmp, (BITMAP *)d->dp2, 0, 0, 0, 0, bmp->w, bmp->h);
			rect(screen, d->x - 1, d->y - 1, d->x + d->w, d->y + d->h, gui_fg_color);
			blit((BITMAP *)d->dp2, screen, 0, 0, d->x, d->y, d->w, d->h);
			destroy_bitmap(bmp);
			object_message(&settings_dialog[QUALITY_TEXT], MSG_DRAW, 0);
			break;

		case MSG_IDLE:
			if (d->d2 > 0) {
				d->d2--;
				if (d->d2 == 0) {
					quality = new_quality;
					flags = new_flags;
					bmp = (BITMAP *)d->dp;
					size = ESTIMATED_MAX_JPG_SIZE(bmp);
					if (save_memory_jpg_ex(d->dp3, &size, bmp, NULL, quality, flags, NULL))
						goto preview_error;
					sprintf(size_string, "Size: %dx%d, %.1f Kbytes  ", bmp->w, bmp->h, (double)size / 1024.0);
					object_message(&settings_dialog[SIZE_TEXT], MSG_DRAW, 0);
					return D_REDRAWME;
				}
			}
			if ((new_quality != quality) || (new_flags != flags)) {
				quality = new_quality;
				flags = new_flags;
				d->d2 = 20;
				if (flags & JPG_GREYSCALE) {
					settings_dialog[SS_444_RADIO].flags |= D_DISABLED;
					settings_dialog[SS_422_RADIO].flags |= D_DISABLED;
					settings_dialog[SS_411_RADIO].flags |= D_DISABLED;
				}
				else {
					settings_dialog[SS_444_RADIO].flags &= ~D_DISABLED;
					settings_dialog[SS_422_RADIO].flags &= ~D_DISABLED;
					settings_dialog[SS_411_RADIO].flags &= ~D_DISABLED;
				}
				settings_dialog[SS_444_RADIO].fg = (flags & JPG_GREYSCALE ? gui_mg_color : gui_fg_color);
				settings_dialog[SS_422_RADIO].fg = (flags & JPG_GREYSCALE ? gui_mg_color : gui_fg_color);
				settings_dialog[SS_411_RADIO].fg = (flags & JPG_GREYSCALE ? gui_mg_color : gui_fg_color);
				object_message(&settings_dialog[SS_444_RADIO], MSG_DRAW, 0);
				object_message(&settings_dialog[SS_422_RADIO], MSG_DRAW, 0);
				object_message(&settings_dialog[SS_411_RADIO], MSG_DRAW, 0);
				return D_REDRAWME;
			}
			break;
	}
	return D_O_K;

preview_error:
	line((BITMAP *)d->dp2, 0, 0, d->w - 1, d->h - 1, 0);
	line((BITMAP *)d->dp2, d->w - 1, 0, 0, d->h - 1, 0);
	blit((BITMAP *)d->dp2, screen, 0, 0, d->x, d->y, d->w, d->h);
	return D_O_K;
}
Beispiel #26
0
int main(void)
{

	int i,j,k,x,y;
	//byte bi,bj;
	//byte cursize=1;

	//int cursorx=0,cursory=0;

	//byte spritecont=10,spritecont2=10+16;
	//byte sprconmeno,sprconpiu;
	//byte sprconmeno2,sprconpiu2;

	//byte terrancont=0,solidcont=0;

	//bool speed=false;
	//bool print=false,toggleprint=false;
	//bool moved=false,pushed=false;

	int nlevel;

	BITMAP *buffer;				//	Double-buffering
	BITMAP *textures;			//	Immagine globale delle texture
	BITMAP *sprites[256];		// 	Array degli sprite
	//RGB color[256];

	//char nomefile[30],errmess[20];
	//FILE *fp;


	T_Map mappa;


	strcpy(errmess,"");		// inizializzo la stringa

	if(!mappa.InitLevel()){
		strcpy(errmess,"Impossibile allocare la mappa");
		exit(0);
	}

	/////////// INPUT NOME FILE DELLA MAPPA   ///////////////////////
	printf("\n\t Inserta il nome del file della mappa(senza est.) : ");
	gets(nomefile);
	strcat(nomefile,".map");
	/////////////////////////////////////////////////////////////////

	if(!mappa.SetMapFile){
		printf("\n\t File non trovato");
	}

	nlevel=mappa.RetNLevel();

	printf("\n\t Numero attuale di livelli: %d",nlevel);
	printf("\n\t Inserta il numero di livelli da creare nella mappa:");
	printf("\n\t (0 per non aggiungerne)");
	scanf("%d",&i);
	if(i>0){
		nlevel+=i;
		mappa.SetNLevel(nlevel);
		mappa.AllocMap();
	}

	GameInit();

	textures=create_bitmap(128,128);

	mappa.SetTextureFile("D:\\DJGPP\\Game01\\IndexTxt.txt");

/////// Gestione delle texture... s�, lo so, lo so che sono tile
	for(y=0,i=0;y<16&&i<256;y++){
		for(x=0;x<16&&i<256;x++,i++){
			sprites[i]=create_sub_bitmap(textures,x*UNITX,
								y*UNITY,UNITX,UNITY);
		}
	}


/////////// INIZIALIZZAZIONE MATRICE DELLA FINESTRELLA /////
	for(i=0;i<WIMGY;i++){
		for(j=0;j<WIMGX;j++){
			miniwmask[i][j]=0;
		}
	}

////// INIZIALIZZAZIONE MATRICE DELLA LISTA DELLE TILE/////////////

	for(i=0;i<2;i++){
		for(j=0;j<20;j++){
			spritemask1[i][j]=0;
			spritemask2[i][j]=0;
		}
	}

///////////////// BUFFER PER IL DOUBLE BUFFERING //////////////

	buffer=create_bitmap(SCREEN_W,SCREEN_H);
	//show_mouse(buffer);

	clear_to_color(buffer,DESK_COL);
	//clear_to_color(lvldis,BACKG_COL);

//////////////////////////////////////////////////////////////////


/////////////////////////// PUTTAGGIO  ///////////////////////////

	DrawMainWindow();
	DrawMiniWindow();
	DrawTileLists();

	//show_mouse(buffer);

	blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
	//rectfill(screen,0,0,100,100,5);

//////////////////////////////////////////////////////////////////

////////////////// INPUT E CONTROLLI  ////////////////////////////

	while(!key[KEY_ESC]){

		if(key[KEY_RSHIFT]||key[KEY_LSHIFT]){
			speed=true;
		}else{
			speed=false;
		}
		if(key[KEY_P]){
			cursize=2;
			moved=true;
		}
		if(key[KEY_O]){
			cursize=1;
			moved=true;
		}

		if(key[KEY_SPACE]&&!pushed){
		 	print=true;
			pushed=true;
			moved=true;
		}

		if(key[KEY_T]&&!pushed){
			pushed=true;
			moved=true;
			if(toggleprint){
				toggleprint=false;
			}else{
				toggleprint=true;
			}
		}

		if(key[KEY_LEFT]&&cursorx&&!pushed){
			if(!speed)
				pushed=true;
			cursorx--;
			if(cursize==2&&cursorx)
				cursorx--;
			relx=cursorx*MUNITX;
			moved=true;
		}
		if(key[KEY_RIGHT]&&cursorx<NSPRITEX-cursize&&!pushed){
			if(!speed)
				pushed=true;
			cursorx++;
			if(cursize==2&&cursorx<NSPRITEX-cursize)
				cursorx++;
			relx=cursorx*MUNITX;
			moved=true;
		}
		if(key[KEY_UP]&&cursory&&!pushed){
			if(!speed)
				pushed=true;
			cursory--;
			if(cursize==2&&cursory)
				cursory--;
			rely=cursory*MUNITY;
			moved=true;
		}
		if(key[KEY_DOWN]&&cursory<NSPRITEY-cursize&&!pushed){
			if(!speed)
				pushed=true;
			cursory++;
			if(cursize==2&&cursory<NSPRITEY-cursize)
				cursory++;
			rely=cursory*MUNITY;
			moved=true;
		}

		if(key[KEY_PLUS_PAD]&&!pushed){
			//if(!button[KEY_PLUS_PAD]){
			pushed=true;
			BACKG_COL++;
			moved=true;
			//button[KEY_PLUS_PAD]=true;
			//}
		//}else{
		//	button[KEY_PLUS_PAD]=false;
		}
		if(key[KEY_Z]&&!pushed){
			if(!speed)
				pushed=true;

			//spritecont--;
			//spritecont2--;
			//relx=cursorx*MUNITX;
			moved=true;
		}
		if(key[KEY_X]&&!pushed){
			if(!speed)
				pushed=true;
			//spritecont++;
			//spritecont2++;
			//relx=cursorx*MUNITX;
			moved=true;
		}

		if(key[KEY_A]&&!pushed){
			if(!speed)
				pushed=true;
			if(terrancont>0)
				terrancont--;
			else
				terrancont=MAX_TERR;
			//spritecont2++;
			//relx=cursorx*MUNITX;
			moved=true;
		}
		if(key[KEY_S]&&!pushed){
			if(!speed)
				pushed=true;

			terrancont++;
			if(terrancont>MAX_TERR)
				terrancont=0;
			//spritecont2++;
			//relx=cursorx*MUNITX;
			moved=true;
		}

		if(key[KEY_Q]&&!pushed){
			if(!speed)
				pushed=true;
			if(solidcont>0)
				solidcont--;
			else
				solidcont=MAX_SOLID;
			//spritecont2++;
			//relx=cursorx*MUNITX;
			moved=true;
		}
		if(key[KEY_W]&&!pushed){
			if(!speed)
				pushed=true;

			solidcont++;
			if(solidcont>MAX_SOLID)
				solidcont=0;
			//spritecont2++;
			//relx=cursorx*MUNITX;
			moved=true;
		}

		if(key[KEY_F3]&&!pushed){
			pushed=true;

			fp=fopen(nomefile,"rb");
			if(fp!=NULL){
				if(!mappa.LoadLevel(fp))
					strcpy(errmess,"Unable to load");
				fclose(fp);

				for(i=0,k=0;i<NSPRITEY;i++){
					for(j=0;j<NSPRITEX;j++,k++){
						livello[i][j].solid=mappa.RetSolid(k);
						livello[i][j].terran=mappa.RetTerran(k);
					}
				}

			}

			moved=true;
		}

		if(key[KEY_F2]&&!pushed){
			pushed=true;

			/*
			for(i=0,k=0;i<NSPRITEY;i++){
					for(j=0;j<NSPRITEX;j++,k++){
					mappa.SetSolid(k,livello[i][j].solid);
					mappa.SetTerran(k,livello[i][j].terran);
				}
			}

			for(i=OVER_SPACE,k=0;i<OVER_SPACE+NSPRITEY;i++){
					for(j=LEFT_SPACE;j<LEFT_SPACE+NSPRITEX;j++,k++){
					mappa.SetSprite(k,livello[i][j].sprite);
				}
			}
			*/

			fp=fopen(nomefile,"wb");

			//mappa.SaveLevel(fp);

			fclose(fp);
		}

		if(key[KEY_F7]&&!pushed){
			pushed=true;

			for(i=0,k=0;i<NSPRITEY;i++){
				for(j=0;j<NSPRITEX;j++,k++){
					//fwrite(&livello[i][j],sizeof(level),1,fp);
					livello[i][j].solid=mappa.RetSolid(k);
					livello[i][j].terran=mappa.RetTerran(k);
				}
			}

			moved=true;
		}

		if(key[KEY_F5]&&!pushed){
			pushed=true;

			for(i=0,k=0;i<NSPRITEY;i++){
					for(j=0;j<NSPRITEX;j++,k++){
					mappa.SetSolid(k,livello[i][j].solid);
					mappa.SetTerran(k,livello[i][j].terran);
				}
			}

		}

		if(key[KEY_ENTER]){
			clear_to_color(buffer,0);
			for(i=OVER_SPACE,y=0;i<NSPRITEY-BOTTOM_SPACE;i++,y+=UNITY){
				for(j=LEFT_SPACE,x=0;j<NSPRITEX-RIGHT_SPACE;j++,x+=UNITX){
					blit(sprites[livello[i][j].sprite],buffer,0,0,
							x,y,UNITX,UNITY);
				}
			}
			vsync();
			blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);

			while(!key[KEY_BACKSPACE]);
			moved=true;
		}

		if(print||toggleprint){
			livello[cursory][cursorx].sprite=spritecont;
			livello[cursory][cursorx].terran=terrancont;
			livello[cursory][cursorx].solid=solidcont;

			print=false;
			//stretch_blit(sprites[spritecont],lvldis,0,0,UNITX,UNITY,
			//				cursorx*MUNITX,cursory*MUNITY,MUNITX,MUNITY);
			if(cursize>1){
					livello[cursory][cursorx+1].sprite=spritecont+1;
					livello[cursory][cursorx+1].terran=terrancont;
					livello[cursory][cursorx+1].solid=solidcont;
			//		stretch_blit(sprites[spritecont+1],
			//					lvldis,0,0,UNITX,UNITY,(cursorx+1)*MUNITX,
			//								cursory*MUNITY,MUNITX,MUNITY);

					livello[cursory+1][cursorx].sprite=spritecont2;
					livello[cursory+1][cursorx].terran=terrancont;
					livello[cursory+1][cursorx].solid=solidcont;
			//		stretch_blit(sprites[spritecont2],
			//					lvldis,0,0,UNITX,UNITY,cursorx*MUNITX,
			//								(cursory+1)*MUNITY,MUNITX,MUNITY);

					livello[cursory+1][cursorx+1].sprite=spritecont2+1;
					livello[cursory+1][cursorx+1].terran=terrancont;
					livello[cursory+1][cursorx+1].solid=solidcont;
			//		stretch_blit(sprites[spritecont2+1],
			//					lvldis,0,0,UNITX,UNITY,(cursorx+1)*MUNITX,
			//								(cursory+1)*MUNITY,MUNITX,MUNITY);

			}
		}

		if(moved){
			clear_to_color(buffer,DESK_COL);


				// 	Puttaggio dello schema del livello : ex lvldis
			rectfill(buffer,0,0,XLAR,YLAR,BACKG_COL);
			//blit(lvldis,buffer,0,0,0,0,XLAR,YLAR);
			for(i=0,y=0;i<NSPRITEY;i++,y+=MUNITY){
				for(j=0,x=0;j<NSPRITEX;j++,x+=MUNITX){
					if(livello[i][j].sprite){
						stretch_blit(sprites[livello[i][j].sprite],
							buffer,0,0,UNITX,UNITY,x,y,MUNITX,MUNITY);
					}
				}
			}

				// Rettangoli dello schema

			//rect(buffer,LEFT_SPACE*MUNITX,OVER_SPACE*MUNITY,
			//	XLAR-(RIGHT_SPACE*MUNITX)-1,YLAR-(BOTTOM_SPACE*MUNITY)-1,
			//												CONF_COL);

			rect(buffer,relx,rely,relx+(cursize*MUNITX-1),
									rely+(cursize*MUNITY-1),CURS_COL);

				// Disegno della finestra laterale //
			for(i=cursory-2,bi=0;i<cursory+3;i++,bi++){
				for(j=cursorx-2,bj=0;j<cursorx+3;j++,bj++){
			 		if(i<0||j<0){
						windimg[bi][bj]=0;
					}else{
						windimg[bi][bj]=livello[i][j].sprite;
					}
				}
			}

			for(i=0,y=0;i<WIMGY;i++,y+=UNITY){
				for(j=0,x=SCREEN_W-(WIMGX*UNITX);j<WIMGX;j++,x+=UNITX){
					//temp=;
					blit(sprites[windimg[i][j]],buffer,0,0,x,y,UNITX,UNITY);
				}
			}

				// Se � premuto 'toggleprint' ( che � un Pokemon? )
			if(toggleprint){
				rectfill(buffer,300,110,320,130,CURS_COL);
			}else{
				rectfill(buffer,300,110,320,130,DESK_COL);
			}

			textprintf(buffer,font,250,60,255,"Sol : %d",solidcont);
			textprintf(buffer,font,250,70,255,"Terr: %d",terrancont);

				// Disegno elenco sprite
			if(spritecont>10){
				sprconmeno=spritecont-10;
			}else{
			 	sprconmeno=256-(10-spritecont);
			}
			if(spritecont<246){
				sprconpiu=spritecont+10;
			}else{
			 	sprconpiu=10-(256-spritecont);
			}
			if(spritecont2>10){
				sprconmeno2=spritecont2-10;
			}else{
			 	sprconmeno2=256-(10-spritecont2);
			}
			if(spritecont2<246){
				sprconpiu2=spritecont2+10;
			}else{
			 	sprconpiu2=10-(256-spritecont2);
			}

			for(bi=sprconmeno,bj=sprconmeno2,x=0;bi!=sprconpiu;bi++,bj++,x+=BIGUNITX){
				stretch_blit(sprites[bi],buffer,0,0,UNITX,UNITY,x,
						200,BIGUNITX,BIGUNITY);
				if(cursize>1){
					stretch_blit(sprites[bj],buffer,0,0,
						UNITX,UNITY,x,216,BIGUNITX,BIGUNITY);
				}
			}
			rect(buffer,160,199,160+(cursize*BIGUNITX),
									200+(cursize*BIGUNITY),CURS_COL);

			moved=false;
		}

		if(pushed){
			pushed=false;
			for(i=0;i<128;i++){
				if(key[i]){
					pushed=true;
					break;
				}
			}
		}

		show_mouse(buffer);
		vsync();
		blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
		show_mouse(NULL);
	}

		/// Distruzione Bitmap

	for(i=0;i<256;i++){
		destroy_bitmap(sprites[i]);
		//destroy_bitmap(texture[1][i]);
	}

	destroy_bitmap(textures);
	//destroy_bitmap(lvldis);
	destroy_bitmap(buffer);

	readkey();
	GameExit();

	printf("Programmed with DJGPP RHIDE Allegro");

	puts(errmess);

	getch();


	return 0;

}