Ejemplo n.º 1
0
bool Blotter::make_granulate(
    const int base_r,
    const int base_g,
    const int base_b,
    const int granularity
) {
    if (granularity < 0) return false;

    if (texture) ::destroy_bitmap(texture);
    texture = create_bitmap(640, 640);
    if (!texture) return false;

    for  (int x = 0; x < texture->w; ++x)
     for (int y = 0; y < texture->h; ++y) {
        const int rd = 2 * granularity + 1;
        int rr = base_r + granularity - (::rand() % rd);
        int rg = base_g + granularity - (::rand() % rd);
        int rb = base_b + granularity - (::rand() % rd);
        if (rr > 255) rr = 255; else if (rr < 0) rr = 0;
        if (rg > 255) rg = 255; else if (rg < 0) rg = 0;
        if (rb > 255) rb = 255; else if (rb < 0) rb = 0;
        ::_putpixel32(texture, x, y, makecol32(rr, rg, rb));
    }
    return true;
}
Ejemplo n.º 2
0
void draw_back(BITMAP *bmp)
{
	int x, y;
	float h[16][21];
	for (y = 0; y < 16; y++) {
		for (x = 0; x < 21; x++) {
			h[y][x] = rnd();
		}
	}
	for (y = 0; y < bmp->h; y++) {
		for (x = 0; x < bmp->w; x++) {
			int my = y / 32;
			int mx = x / 32;
			float hx = (x - mx * 32) / 32.0;
			float hy = (y - my * 32) / 32.0;
			float h1 = h[my + 0][mx + 0];
			float h2 = h[my + 1][mx + 0];
			float h3 = h[my + 1][mx + 1];
			float h4 = h[my + 0][mx + 1];
			float a;
			int r, g, b;
			h1 = h1 * (1 - hx) * (1 - hy);
			h2 = h2 * (1 - hx) * (hy);
			h3 = h3 * (hx) * (hy);
			h4 = h4 * (hx) * (1 - hy);
			a = h1 + h2 + h3 + h4;
			r = 200 * a;
			g = 150 * a;
			b = 50 * a;
			putpixel(bmp, x, y, makecol32(M(r), M(g), M(b)));
		}
	}
}
Ejemplo n.º 3
0
bool Blotter::make_voronoi_shaded(
    const color cl,
    const color cd,
    const int amount,
    const pos size,
    const int thinness,
    const double norm
) {
    if (norm <= 0) return false;
    if (amount <= 2) return false;

    if (texture) ::destroy_bitmap(texture);
    texture = create_bitmap(size.x, size.y);
    if (!texture) return false;

    std::vector<std::vector<std::pair<double,double> > > matrix
        = make_voronoi_table(amount, size, thinness, norm);

    for (int x = 0; x < texture->w; ++x)
        for (int y = 0; y < texture->h; ++y) {
            color cm = interpolate(cl, cd, 0.5);
            double angl = matrix[x][y].second - PI/4;
            double shade = cos(angl)/2 + 0.5;
            color ci = interpolate(cl, cd, shade);
            ci = interpolate(ci, cm, matrix[x][y].first);
            ::_putpixel32(texture, x, y, makecol32(ci));
        }
    return true;
}
Ejemplo n.º 4
0
void ati68860_set_ramdac_type(ati68860_ramdac_t *ramdac, int type)
{
        int c;
        
        if (ramdac->ramdac_type != type)
        {
                ramdac->ramdac_type = type;
                        
                for (c = 0; c < 2; c++)
                {
                        if (ramdac->ramdac_type == RAMDAC_8BIT)
                                ramdac->pallook[c] = makecol32(ramdac->pal[c].r, ramdac->pal[c].g, ramdac->pal[c].b);
                        else
                                ramdac->pallook[c] = makecol32((ramdac->pal[c].r & 0x3f) * 4, (ramdac->pal[c].g & 0x3f) * 4, (ramdac->pal[c].b & 0x3f) * 4); 
                }
        }
}
bool Panel::hit( int x, int y )
{
	// inside bbox?
	if ( (x < m_x) || (y < m_y) ||
		 (x >= m_x + m_w) || ( y >= m_y + m_h ) ) return false;
	
	// check the colorkey for the image
	int p = getpixel( m_surf, x - m_x, y - m_y );
	if (p==makecol32(0xff, 0, 0xff)) return false;
	

	// otherwise
	return true;
}
Ejemplo n.º 6
0
/* worker function for changing the type of an image */
static int do_changetype(DATAFILE *dat, int *param, int type)
{
   BITMAP *bmp;
   RLE_SPRITE *spr;
   int x, y, c, r, g, b;

   if ((dat->type != DAT_BITMAP) && (dat->type != DAT_RLE_SPRITE) &&
       (dat->type != DAT_C_SPRITE) && (dat->type != DAT_XC_SPRITE)) {
      (*param)++;
      return D_O_K;
   }

   if (dat->type == type)
      return D_O_K;

   if (dat->type == DAT_RLE_SPRITE) {
      spr = (RLE_SPRITE *)dat->dat;
      bmp = create_bitmap_ex(spr->color_depth, spr->w, spr->h);
      clear_to_color(bmp, bmp->vtable->mask_color);
      draw_rle_sprite(bmp, spr, 0, 0);
      dat->dat = bmp;
      destroy_rle_sprite(spr);
   }
   else if (type == DAT_RLE_SPRITE) {
      bmp = (BITMAP *)dat->dat;
      spr = get_rle_sprite(bmp);
      dat->dat = spr;
      destroy_bitmap(bmp);
   }
   else if ((type == DAT_C_SPRITE) || (type == DAT_XC_SPRITE)) {
      bmp = (BITMAP *)dat->dat;
      if (bitmap_color_depth(bmp) == 32) {
	 for (y=0; y<bmp->h; y++) {
	    for (x=0; x<bmp->w; x++) {
	       c = getpixel(bmp, x, y);
	       r = getr32(c);
	       g = getg32(c);
	       b = getb32(c);
	       putpixel(bmp, x, y, makecol32(r, g, b));
	    }
	 }
      }
   }

   dat->type = type;

   return D_REDRAW;
}
Ejemplo n.º 7
0
/* makecol_depth:
 *  Converts R, G, and B values (ranging 0-255) to whatever pixel format
 *  is required by the specified color depth.
 */
int makecol_depth(int color_depth, int r, int g, int b)
{
   switch (color_depth) {

      case 8:
	 return makecol8(r, g, b);

      case 15:
	 return makecol15(r, g, b);

      case 16:
	 return makecol16(r, g, b);

      case 24:
	 return makecol24(r, g, b);

      case 32:
	 return makecol32(r, g, b);
   }

   return 0;
}
// resets cols and updates news Image and
// fills data
void NewsLayout::setNCols( int cols )
{
	m_ncols = cols;
	m_dirty = true;
	
	if (m_newsImg)
	{
		destroy_bitmap( m_newsImg );		
	}

	if (m_newsImg2)
	{
		destroy_bitmap( m_newsImg2 );
	}

	// create blank page
	m_newsImg = create_bitmap( m_ncols * COL_SZ, m_h );
	m_newsImg2 = create_bitmap( m_ncols * COL_SZ, m_h );
	rectfill( m_newsImg, 0, 0, m_newsImg->w, m_newsImg->h, makecol32( 235,223,195 ) );

	// draw masthead and bottom margin
	stretch_blit( m_masthead, m_newsImg, 0, 0,250, 30, 0, 0, m_ncols*COL_SZ, 30 );
	rectfill( m_newsImg, 0, 238, m_ncols*COL_SZ, 250, makecol32( 250, 250, 255 ) );

	// draw column dividers
	for (int i = 1; i < m_ncols; i++)
	{
		vline( m_newsImg, i*COL_SZ, MAST_HITE, m_h - 3, makecol32( 205,193,165 ) );
	}

	// Init layout
	for (int i=0; i < m_ncols; i++)
		for (int j=0; j < YCOLS; j++)
			m_layout[i][j] = 0;

	int avgStoriesPerCol = 1;
	int numStories = avgStoriesPerCol * m_ncols;
	int snum = 1;
	for (int i=0; i < numStories; i++)
	{
		int si, sj;
		si = ((float)rand() / (float)RAND_MAX) * m_ncols;
		sj = ((float)rand() / (float)RAND_MAX) * YCOLS;
		m_layout[si][sj] = snum++;
	}

	// spacial case, always put a story at 0,0
	m_layout[0][0] = snum++;

	
	// only let each story grow once per iteration	
	bool storyGrown[200]; // hack

	// Now grow the stories to the right and down
	bool somethingChanged = false;
	do {
		// init
		somethingChanged = false;
		for (int i=0; i < snum; i++)
		{
			storyGrown[ i ] = false;
		}

		// growth
		for (int i=0; i < m_ncols; i++)
		{
			for (int j=0; j < YCOLS; j++)
			{
				// no story yet?
				if (m_layout[i][j] == 0)
				{
					// try to grow from the left first
					if ((i>0)&&(m_layout[i-1][j] != 0)&&
						(!storyGrown[m_layout[i-1][j]]) )
					{
						m_layout[i][j] = m_layout[i-1][j];
						storyGrown[m_layout[i-1][j]] = true;
						somethingChanged = true;
					}

					// otherwise try to grow from above
					if ((j>0)&&(m_layout[i][j-1] != 0) &&
						(!storyGrown[m_layout[i][j-1]])) 
					{
						m_layout[i][j] = m_layout[i][j-1];
						storyGrown[m_layout[i][j-1]] = true;
						somethingChanged = true;
					}
				}
			}
		}
	} while(somethingChanged);

	// Count the number of unique stories
	m_storiesLeft.clear();
	
	// reuse storygrown as "story seen" :)
	for (int i=0; i < snum; i++)		
		storyGrown[ i ] = false;	

	// check for unique stories
	for (int i=0; i < m_ncols; i++)		
		for (int j=0; j < YCOLS; j++)
			if (!storyGrown[ m_layout[i][j] ])
			{
				m_storiesLeft.push_back( m_layout[i][j] );
				storyGrown[ m_layout[i][j] ] = true;
			}

	// scramble the storiesLeft so they show up in
	// random order
	for (int i=0; i < m_storiesLeft.size(); i++)
	{
		int tmp = m_storiesLeft[i];
		int ndx = rand() % m_storiesLeft.size();
		m_storiesLeft[i] = m_storiesLeft[ndx];
		m_storiesLeft[ndx] = tmp;
	}
	
	int yChunkSz = ( (m_newsImg->h - MAST_HITE) - 3 ) / YCOLS;
#if 0
	// DBG: draw layout IDs
	static int colors[] = {
		makecol32( 0,0,0 ),
		makecol32( 0,0,128 ),
		makecol32( 0,128, 0 ),
		makecol32( 0,128, 128 ),
		makecol32( 128, 0,0 ),
		makecol32( 128, 0,128 ),
		makecol32( 128, 128, 0 ),
		makecol32( 128, 128, 128 ),
	};
	for (int i=0; i < m_ncols; i++)
	{
		for (int j=0; j < YCOLS; j++)
		{
			rect( m_newsImg, 
				i*COL_SZ, MAST_HITE + j*yChunkSz,
				(i+1)*COL_SZ - 3, (MAST_HITE + (j+1)*yChunkSz) - 3,
				colors[ m_layout[i][j] % 8 ] );

			char buff[10];
			sprintf( buff, "%c", m_layout[i][j] + 'A' );
			textout_ex( m_newsImg, font, buff,
				i*COL_SZ + 5, MAST_HITE + j*yChunkSz + 5,
				colors[ m_layout[i][j] % 8 ], -1 );
		}
	}
#endif

}
// Woot! Print a story!
void NewsLayout::printStory( std::string &headline, int *pSX, int *pSY )
{
	// check if we're out of stories
	if (!m_storiesLeft.size()) return;

	// Get the headline width
	int storyId = m_storiesLeft.back();
	m_storiesLeft.pop_back();

	// find the upper left corner of the story
	int sx = -1, sy = -1;
	for (int i=0; i < m_ncols; i++)
	{
		for (int j=0; j < YCOLS; j++)
		{
			if (m_layout[i][j] == storyId) 
			{
				sx = i; sy = j;
				break;
			}
		}
		if (sx>=0) break;
	}
	printf("Found story at %d %d\n", sx, sy );

	int yChunkSz = ( (m_newsImg->h - MAST_HITE) - 3 ) / YCOLS;

	// return story location to app
	if ((pSX)&&(pSY))
	{
		*pSX = sx*COL_SZ + 12;
		*pSY = MAST_HITE + sy*yChunkSz + 12;
	}
	
	// Fill the story with pseudo-text
	int colw = 0;
	for (int c=sx; (c < m_ncols) && (m_layout[c][sy] == storyId); c++)
	{
		// find height of column
		int colh=0;
		for (int r=sy; (r < YCOLS) && (m_layout[c][r] == storyId); r++) colh++;		

		// Draw story text in column
		int hite = sy*yChunkSz;
		int offs = ((float)rand() / (float)RAND_MAX) * (m_bodyText->h - (colh*yChunkSz));
		if (offs < 0) offs = 0;
		blit( m_bodyText, m_newsImg, 
			  0, offs,
			  c*COL_SZ, MAST_HITE + sy*yChunkSz,
			  m_bodyText->w, colh * yChunkSz );		

		colw++;
	}
	
	// TODO: draw real headline
	for (int i=0; i < 5; i++ )
	{
		hline( m_newsImg, 
				sx*COL_SZ+3, MAST_HITE + sy*yChunkSz + i, (sx+colw)*COL_SZ-3, 
				makecol32( 0,0,0 ) );
	}

	
	// set dirty
	// TOTAL HACK -- don't set dirty, but always set
	// dirty in dropClip so new story doesn't show up 
	// until clips reach us
	//m_dirty = true;
}
Ejemplo n.º 10
0
void ati68860_ramdac_out(uint16_t addr, uint8_t val, ati68860_ramdac_t *ramdac, svga_t *svga)
{
        switch (addr)
        {
                case 0: 
                svga_out(0x3c8, val, svga);
                break;
                case 1: 
                svga_out(0x3c9, val, svga); 
                break;
                case 2: 
                svga_out(0x3c6, val, svga); 
                break;
                case 3: 
                svga_out(0x3c7, val, svga); 
                break;
                default:
                ramdac->regs[addr & 0xf] = val;
                switch (addr & 0xf)
                {
                        case 0x4:
                        ramdac->dac_write = val;
                        ramdac->dac_pos = 0;
                        break;
                        case 0x5:
                        switch (ramdac->dac_pos)
                        {
                                case 0: 
                                ramdac->dac_r = val;
                                ramdac->dac_pos++; 
                                break;
                                case 1: 
                                ramdac->dac_g = val;
                                ramdac->dac_pos++; 
                                break;
                                case 2: 
                                if (ramdac->dac_write > 1)
                                        break;
                                ramdac->pal[ramdac->dac_write].r = ramdac->dac_r; 
                                ramdac->pal[ramdac->dac_write].g = ramdac->dac_g;
                                ramdac->pal[ramdac->dac_write].b = val; 
                                if (ramdac->ramdac_type == RAMDAC_8BIT)
                                        ramdac->pallook[ramdac->dac_write] = makecol32(ramdac->pal[ramdac->dac_write].r, ramdac->pal[ramdac->dac_write].g, ramdac->pal[ramdac->dac_write].b);
                                else
                                        ramdac->pallook[ramdac->dac_write] = makecol32((ramdac->pal[ramdac->dac_write].r & 0x3f) * 4, (ramdac->pal[ramdac->dac_write].g & 0x3f) * 4, (ramdac->pal[ramdac->dac_write].b & 0x3f) * 4); 
                                ramdac->dac_pos = 0; 
                                ramdac->dac_write = (ramdac->dac_write + 1) & 255; 
                                break;
                        }
                        break;
                        
                        case 0xb:
                        switch (val)
                        {
                                case 0x82:
                                ramdac->render = svga_render_4bpp_highres;
                                break;
                                case 0x83:
                                ramdac->render = svga_render_8bpp_highres;
                                break;
                                case 0xa0: case 0xb0:
                                ramdac->render = svga_render_15bpp_highres;
                                break;
                                case 0xa1: case 0xb1:
                                ramdac->render = svga_render_16bpp_highres;
                                break;
                                case 0xc0: case 0xd0:
                                ramdac->render = svga_render_24bpp_highres;
                                break;
                                case 0xe2: case 0xf7:
                                ramdac->render = svga_render_32bpp_highres;
                                break;
                                case 0xe3:
                                ramdac->render = svga_render_ABGR8888_highres;
                                break;
                                case 0xf2:
                                ramdac->render = svga_render_RGBA8888_highres;
                                break;
                                default:
                                ramdac->render = svga_render_8bpp_highres;
                                break;
                        }
                        break;
                        case 0xc:
                        svga_set_ramdac_type(svga, (val & 1) ? RAMDAC_6BIT : RAMDAC_8BIT);
                        break;
                }
                break;
        }
}
Ejemplo n.º 11
0
void game_init(int ai)
{
	static int once = 1;
	int x, y;
	BITMAP *tmp;
	int bc = makecol(200, 150, 50);
	
	clear_to_color(screen, makecol(0, 0, 0));
	textout_centre(screen, font, "Generating&Caching Data", SCREEN_W / 2, 0, -1);
	textout_centre(screen, font, "May take a while", SCREEN_W / 2, SCREEN_H / 2, -1);
	textout_centre(screen, font, "(about 10 minutes for first run,", SCREEN_W / 2, SCREEN_H / 2 + 20, -1);
	textout_centre(screen, font, "about 1 minute every first game,", SCREEN_W / 2, SCREEN_H / 2 + 40, -1);
	textout_centre(screen, font, "few seconds else)", SCREEN_W / 2, SCREEN_H / 2 + 60, -1);
		
	if (once) {
		once = 0;
		
		animdata[0] = load_gfx("gravburn", 48);
		animdata[1] = load_gfx("shock", 48);
		animdata[2] = load_gfx("fireball", 48);
		animdata[3] = load_gfx("wheel", 48);
		animdata[4] = load_gfx("glow", 32);
		{
			int a;
			for (a = 0; a < ANIMS; a++) {
				anim[a] = 0;
				animlen[a] = dat_length(animdata[a]);
			}
		}
		
		tower = dat[TOWER_BMP].dat;
		explosion = dat[EXPLOSION_WAV].dat;
		radiating =  dat[RADIATING_WAV].dat;
		teleport =  dat[TELEPORT_WAV].dat;
		bonus =  dat[BONUS_WAV].dat;
		nuclearegg =  dat[NUCLEAREGG_BMP].dat;
		launcher =  dat[LAUNCHER_BMP].dat;
	
		bonuspic[0] = dat[BONUS0_BMP].dat;
		bonuspic[1] = dat[BONUS1_BMP].dat;
		bonuspic[2] = dat[BONUS2_BMP].dat;
	
		map = create_bitmap(SCREEN_W, SCREEN_H);
	}

	ignore[0] = 0;
	ignore[1] = 0;	
	think[0] = 0;
	think[1] = 0;
	memorized[0] = 0;
	memorized[1] = 0;
	AI[0] = 0;
	if (ai) AI[1] = 1; else AI[1] = 0;
	power[0] = 0;
	power[1] = 0;
	bonusnum = 0;
	life[0] = 100;
	life[1] = 100;
	go = 0;
	
	turn = 0;
	
	tmp = create_bitmap_ex(32, SCREEN_W, SCREEN_H);
	draw_back(tmp);
	for (y = 0; y < 16; y++) {
		for (x = 0; x < 16; x++) {
			hills[y][x] = rnd();
		}
	}

	basex[0] = 4 * TW + TW / 2;
	basey[0] = 4 * TH + TH / 2;

	basex[1] = 12 * TW + TW / 2;
	basey[1] = 12 * TH + TH / 2;

	hills[4][4] = 1;
	hills[5][4] = 1;
	hills[5][5] = 1;
	hills[4][5] = 1;

	hills[12][12] = 1;
	hills[13][12] = 1;
	hills[13][13] = 1;
	hills[12][13] = 1;

	x = rnd() * 16;
	y = rnd() * 16;

	for (y = 0; y < MH; y++) {
		for (x = 0; x < MW; x++) {
			int c = 0;
			int t;
			float height = get_height(x, y);
			float h = 0, z = height * ZZZ;
			for (h = height, t = 0; z > 0 && t < 2; z--, h -= 1.0 / (float)ZZZ, t++) {
				int r, g, b;
				float l;
				if (h < 0.2) {
					float p = h / 0.2;
					r = 0;
					g = 100 * p;
					b = 155 + 100 * p;
				} else if (h < 0.5) {
					float p = (h - 0.2) / 0.3;
					r = 0;
					g = 100 + 155 * p;
					b = 255 - 155 * p;
				} else if (h < 0.8) {
					float p = (h - 0.5) / 0.3;
					r = 200 * p;
					g = 255 - 155 * p;
					b = 100;
				} else {
					float p = (h - 0.8) / 0.2;
					r = 200;
					g = 100 + 100 * p;
					b = 100 + 100 * p;
				}
				l = get_height(x + 1, y) - get_height(x, y + 1);
				r = r + l * 2000 + (rnd() - 0.5) * 20;
				g = g + l * 2000 + (rnd() - 0.5) * 20;
				b = b + l * 2000 + (rnd() - 0.5) * 20;
				c = makecol32(M(r), M(g), M(b));
				if (y == MH - 1 && h < height) c = bc;
				putpixel(tmp, 88 + x, y + WINT - z, c);
			}
		}
	}
	{
		float filter[3][3] = {
			{0.025, 0.145, 0.025},
			{0.145, 0.320, 0.145},
			{0.025, 0.145, 0.025}
		};
		for (y = 0; y < SCREEN_H; y++) {
			for (x = 0; x < SCREEN_W; x++) {
				int i = 0, j = 0;
				float r = 0, g = 0, b = 0;
				for (i = -1; i <= 1; i++) {
					for (j = -1; j <= 1; j++) {
						int c = getpixel(tmp, x + j, y + i);
						if (c < 0) c = makecol32(0, 0, 0);
						r += getr32(c) * filter[1 + i][1 + j];
						g += getg32(c) * filter[1 + i][1 + j];
						b += getb32(c) * filter[1 + i][1 + j];
					}
				}
				putpixel(map, x, y, makecol(r, g, b));
			}
		}
	}
	destroy_bitmap(tmp);
	ballx = 240;
	bally = 240;
	balldx = 0;
	balldy = 0;
}
void WireNews::update( float dt )
{
	Panel::update( dt );
	
	if (m_nextHeadlineTime > dt)
	{
		m_nextHeadlineTime -= dt;
	}
	else
	{
		// time for a new headline (if we're not already full
		if (m_heads.size() < 5 )
		{
			Headline *h = new Headline();

			// copy the headline info over
			*h = m_hpool->m_headlines[ rand() % m_hpool->m_headlines.size() ];

			// make a headling image
			h->m_wirePic = create_bitmap( 250, 50 );
			//rectfill( h->m_wirePic, 0, 0, 250, 50, makecol32( 0, 0, 200 ) );
			blit( m_hblank, h->m_wirePic, 0, 0, 0, 0, 250, 50 );
			h->m_currY =-50;

			std::string hs = h->m_text;
			int txty = 5;			

			alfont_set_font_size( g_fontWireHeadline, 12 );
			std::vector<std::string> sline;
			boost::algorithm::split( sline, h->m_text, boost::algorithm::is_any_of(" \t"), 
									 boost::algorithm::token_compress_on );
			
			for (int i = 0; i < sline.size(); i++ )
			{
				std::cout << i << " -- " << sline[i] << std::endl;
			}
			
			int sndx = 0;
			bool firstline = true;
			while( sndx < sline.size() )
			{
				std::string ln;
				
				std::string sWord = sline[ sndx ];
				while ( alfont_text_length( g_fontWireHeadline, 
					(ln + " " + sWord).c_str() ) < ( 240 - (firstline?15:0) ) ) 
				{					
					ln += " ";
					ln += sWord;					
					sndx++;

					if (sndx < sline.size() )
					{
						sWord = sline[ sndx ];
					}
				}
				firstline = false;
				alfont_textout( h->m_wirePic, g_fontWireHeadline,
								 ln.c_str(), 7, txty +2, makecol( 44, 122, 176 ) );

				alfont_textout( h->m_wirePic, g_fontWireHeadline,
								 ln.c_str(), 5, txty, makecol( 255, 255, 255 ) );
				
				txty += 12;				
			}

			alfont_set_font_size( g_fontWireTiny, 10 );
			alfont_textout( h->m_wirePic, g_fontWireTiny,
							h->m_src.c_str(), 8, 35, makecol32( 158, 210, 244 ) );

			alfont_textout_right( h->m_wirePic, g_fontWireTiny,
							h->m_mediaSrc.c_str(), 250-8, 35, makecol32( 158, 210, 244 ) );

			//rect( h->m_wirePic, 0, 0, 249, 49, makecol32( 0, 255, 255 ) );

			// add to list
			m_heads.push_back( h );	

			m_nextHeadlineTime = 10.0f;
		}
	}

	// update yvals
	for (int i=0; i < m_heads.size(); i++)
	{
		int targY = 200-(i*50);
		if (m_heads[i]->m_currY > targY) m_heads[i]->m_currY--;
		if (m_heads[i]->m_currY < targY) m_heads[i]->m_currY++;
	}
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
int makecol32(color c) {
    return makecol32(c.r, c.g, c.b);
}