Example #1
0
void CPanel::Draw(BITMAP *buffer)
{
	rect(buffer,x,y,x + w,y + h,border_color);
	drawing_mode(DRAW_MODE_TRANS,NULL,0,0);
	set_trans_blender(0,0,0,alpha);
	rectfill(buffer,x + 1,y + 1,x + w - 1,y + h - 1,color);
	solid_mode();
	alfont_textout_centre_aa_ex(buffer,font,caption,x + w/2,y,caption_color,-1);
}
Example #2
0
void Alleg4Surface::fillRect(gfx::Color color, const gfx::Rect& rc)
{
  if (gfx::geta(color) < 255) {
    set_trans_blender(0, 0, 0, gfx::geta(color));
    drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
  }

  rectfill(m_bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, to_allegro(bitmap_color_depth(m_bmp), color));
  solid_mode();
}
Example #3
0
void Alleg4Surface::drawLine(gfx::Color color, const gfx::Point& a, const gfx::Point& b)
{
  if (gfx::geta(color) < 255) {
    set_trans_blender(0, 0, 0, gfx::geta(color));
    drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
  }

  line(m_bmp, a.x, a.y, b.x, b.y, to_allegro(bitmap_color_depth(m_bmp), color));
  solid_mode();
}
Example #4
0
void Alleg4Surface::drawVLine(gfx::Color color, int x, int y, int h)
{
  if (gfx::geta(color) < 255) {
    set_trans_blender(0, 0, 0, gfx::geta(color));
    drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
  }

  vline(m_bmp, x, y, y+h-1, to_allegro(bitmap_color_depth(m_bmp), color));
  solid_mode();
}
Example #5
0
void EditboxVScrollView::drawExtraComponents()
{
    int textheight = text_height(textfont);
    //draw the scrollbar
    draw_arrow_button(dbuf, toparrow_x-host->x, toparrow_y-host->y, 16, 16, true, toparrow_state*3);
    draw_arrow_button(dbuf, bottomarrow_x-host->x, bottomarrow_y-host->y, 16, 16, false, bottomarrow_state*3);
    
    if(!sbarpattern)
    {
        sbarpattern = create_bitmap_ex(bitmap_color_depth(screen),2,2);
        putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]);
        putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]);
        putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]);
        putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]);
    }
    
    drawing_mode(DRAW_MODE_COPY_PATTERN, sbarpattern, 0, 0);
    int barstart = toparrow_y + 16 - host->y;
    int barend = bottomarrow_y - host->y-1;
    
    if(barstart < barend)
        rectfill(dbuf, toparrow_x-host->x, barstart, toparrow_x-host->x+15, barend, 0);
        
    solid_mode();
    //compute the bar button, based on view_y
    int totallen = (int)model->getLines().size()*textheight;
    int available = bottomarrow_y-(toparrow_y+16);
    
    if(available < 0)
    {
        baroff=barlen=0;
    }
    
    else
    {
        //area_height:totallen = barlen:available
        barlen = (available*area_height)/zc_max(totallen,area_height)+1;
        //clip to reasonable values
        barlen = zc_max(barlen, 8);
        baroff = zc_min(baroff, available-barlen);
        
        //view_y:(totallen-area_height) = baroff:(available-barlen)
        if(totallen <= area_height)
            baroff=0;
        else
            baroff = ((available-barlen)*view_y)/(totallen-area_height);
            
    }
    
    if(barlen > 0)
    {
        jwin_draw_button(dbuf, toparrow_x-host->x, toparrow_y+16-host->y+baroff, 16, barlen, false, 1);
    }
}
Example #6
0
void tur_draw_turret(BITMAP *dest, turret_t *turret)
{
	int x, y;
	float bx, by;
	int i;
	
	x = turret->x * 32;
	y = turret->y * 32;
		
	/* XXX/DEBUG: SHOW ANGLE */
 	bx = x + turret->bitmap->w/2;
	by = y + turret->bitmap->h/2;
	drawing_mode(DRAW_MODE_TRANS,NULL,0,0);
    set_trans_blender(0,0,0,100);
	for (i = 0; i < turret->range; i += 10) {
		float result;
		result = fixtof(fixcos(turret->angle));
		by -= result * 10;
		result = fixtof(fixsin(turret->angle));
		bx += result * 10;			
		//putpixel(dest, bx, by, makecol(255,255,0));
		//putpixel(dest, bx+1, by, makecol(255,255,0));
	}
	solid_mode();
	/* ---- */

	/* range */
	drawing_mode(DRAW_MODE_TRANS,NULL,0,0);
    set_trans_blender(0,0,0,60);
	//circle(dest, turret->x * 32 + 16, turret->y * 32 + 16, turret->range, makecol(200,200,200));
	/*circlefill(dest, turret->x * 32 + 16, turret->y * 32 + 16, turret->range, makecol(200,200,200));*/
	solid_mode();


	/* turret */
	rotate_sprite(dest, turret->bitmap, turret->x * 32, turret->y * 32, turret->angle);
	
}
Example #7
0
    void AllegroGraphics::setColor(const Color& color)
    {
        mColor = color;
        mAllegroColor = makecol(color.r, color.g, color.b);

        if (color.a != 255)
        {
            set_trans_blender(255, 255, 255, color.a);
            drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
        }
        else
        {
            solid_mode();
        }
    }
void Background::init()
{
	texture = create_bitmap (TILEW, TILEH);
	assert (texture);

	int c1 = WHITE;
	int c2 = GREY;
	clear_to_color (texture, c1);
	circlefill(texture, TILEW / 2, TILEW / 2, 60, c2);
	circlefill (texture, TILEW / 2, TILEH / 2, 30, c1);
	
	drawing_mode (DRAW_MODE_TRANS, NULL, 0, 0);
	set_trans_blender (0, 0, 0, 160);
	rectfill (texture, 0, 0, TILEW, TILEH, BROWN);
	solid_mode();
}
Example #9
0
//checkbox paint
void awe_checkbox_paint(AWE_WIDGET *wgt, AWE_CANVAS *canvas, const AWE_RECT *clip)
{
    AWE_PUSH_BUTTON *btn = (AWE_PUSH_BUTTON *)wgt;
    int state = 0;
    int tx = ((AWE_CHECKBOX *)wgt)->text_dir ? wgt->height + 5 : wgt->width - wgt->height - text_length(btn->font, btn->text) - 5;
    int ty = (wgt->height - text_height(btn->font)) >> 1;
    int cx = ((AWE_CHECKBOX *)wgt)->text_dir ? 0 : wgt->width - wgt->height;

    solid_mode();
    
    if(!awe_is_enabled_widget_tree(wgt))
        state = AWE_PUSH_BUTTON_TEXTURE_DISABLED;
    else if(btn->pressed)
        state = AWE_PUSH_BUTTON_TEXTURE_PRESSED;
    else if(awe_widget_has_mouse(wgt))
        state = AWE_PUSH_BUTTON_TEXTURE_HIGHLIGHTED;
    else
        state = AWE_PUSH_BUTTON_TEXTURE_ENABLED;

    awe_fill_gradient_s(canvas, cx + 2, 2, wgt->height - 4, wgt->height - 4, 
        AWE_MAKE_COLOR(btn->texture[state].face_col[AWE_PUSH_BUTTON_FACE_TOP_LEFT]),
        AWE_MAKE_COLOR(btn->texture[state].face_col[AWE_PUSH_BUTTON_FACE_BOTTOM_LEFT]),
        AWE_MAKE_COLOR(btn->texture[state].face_col[AWE_PUSH_BUTTON_FACE_BOTTOM_RIGHT]),
        AWE_MAKE_COLOR(btn->texture[state].face_col[AWE_PUSH_BUTTON_FACE_TOP_RIGHT]));

    awe_draw_3d_rect_s(canvas, cx, 0, wgt->height, wgt->height, 
        AWE_MAKE_COLOR(btn->texture[state].edge_col[AWE_PUSH_BUTTON_EDGE_TOP_LEFT]),
        AWE_MAKE_COLOR(btn->texture[state].edge_col[AWE_PUSH_BUTTON_EDGE_BOTTOM_RIGHT]), 
        2);

    awe_fill_rect_s(canvas, ((AWE_CHECKBOX *)wgt)->text_dir ? wgt->height + 3 : 0, 
        0, wgt->width - wgt->height - 3, wgt->height, AWE_MAKE_COLOR(((AWE_CHECKBOX *)wgt)->bg));

    if(((AWE_TOGGLE_BUTTON *)wgt)->toggle)
        awe_draw_tick_icon(canvas, cx + (wgt->height >> 1), wgt->height >> 1, (wgt->height >> 1) - 3, AWE_MAKE_COLOR(btn->texture[state].font_col), 3);

    if(AWE_MAKE_COLOR(btn->texture[state].font_sdw) != makecol(255, 0, 255))
        awe_draw_gui_text(canvas, btn->font, btn->text, tx + 1, ty + 1, AWE_MAKE_COLOR(btn->texture[state].font_sdw), -1);

    awe_draw_gui_text(canvas, btn->font, btn->text, tx, ty, AWE_MAKE_COLOR(btn->texture[state].font_col), -1);

    if (awe_get_focus_widget() == wgt && state != AWE_PUSH_BUTTON_TEXTURE_DISABLED)
        awe_draw_rect_pattern_s(canvas, ((AWE_CHECKBOX *)wgt)->text_dir ? wgt->height + 3 : 0, 
            0, wgt->width - wgt->height - 3, wgt->height, AWE_MAKE_COLOR(btn->texture[state].font_col), AWE_PATTERN_DOT_DOT);
}
Example #10
0
void EditboxNoWrapView::drawExtraComponents()
{
    EditboxVScrollView::drawExtraComponents();
    int textheight;
    textheight = text_height(textfont);
    //draw the scrollbar
    draw_arrow_button_horiz(dbuf, leftarrow_x-host->x, leftarrow_y-host->y, 16, 16, true, leftarrow_state*3);
    draw_arrow_button_horiz(dbuf, rightarrow_x-host->x, rightarrow_y-host->y, 16, 16, false, rightarrow_state*3);
    drawing_mode(DRAW_MODE_COPY_PATTERN, sbarpattern, 0, 0);
    int hbarstart = leftarrow_x + 16 - host->x;
    int hbarend = rightarrow_x - host->x-1;
    
    if(hbarstart < hbarend)
        rectfill(dbuf, hbarstart, leftarrow_y-host->y, hbarend, leftarrow_y-host->y+15, 0);
        
    solid_mode();
    //compute the bar button, based on view_y
    int totallen = view_width;
    int available = rightarrow_x-(leftarrow_x+16);
    
    if(available < 0)
    {
        hbaroff=hbarlen=0;
    }
    
    else
    {
        //area_width:totallen = barlen:available
        hbarlen = (available*area_width)/zc_max(totallen,area_width)+1;
        //clip to reasonable values
        hbarlen = zc_max(hbarlen, 8);
        hbaroff = zc_min(hbaroff, available-hbarlen);
        
        //view_x:(totallen-area_width) = baroff:(available-hbarlen)
        if(totallen <= area_width)
            hbaroff = 0;
        else
            hbaroff = ((available-hbarlen)*view_x)/(totallen-area_width);
    }
    
    if(hbarlen > 0)
    {
        jwin_draw_button(dbuf, leftarrow_x-host->x+hbaroff+16, leftarrow_y-host->y, hbarlen, 16, false, 1);
    }
}
Example #11
0
File: bgfx.c Project: rofl0r/GfxRip
void tdbox(BITMAP *b, int x, int y, int w, int h, int stl) {
 BITMAP *pattern;
 int tempRGB;
 if (w > 0)
 {
  if (h > 0)
  {
  //Draw the frame
   if(stl & STL_OUT)
   {
    tempRGB = get_bill_color(bill_hlight);    // Only one call to get_bill_color
    hline(b, x, y, x+w-1, tempRGB);
    vline(b, x, y, y+h-1, tempRGB);

    tempRGB = get_bill_color(bill_light);  
    hline(b, x+1, y+1, x+w-2, tempRGB);
    vline(b, x+1, y+1, y+h-2, tempRGB);
  
    tempRGB = get_bill_color(bill_dkshadow);
    hline(b, x, y+h, x+w, tempRGB);
    vline(b, x+w, y, y+h, tempRGB);

    tempRGB = get_bill_color(bill_shadow);
    hline(b, x+1, y+h-1, x+w-1, tempRGB);
    vline(b, x+w-1, y+1, y+h-2, tempRGB);
   }
   else if(stl & STL_IN)
   {
    if (!(stl & STL_BUTTONDOWN))
    {
     tempRGB = get_bill_color(bill_hlight);
     hline(b, x, y+h, x+w, tempRGB);
     vline(b, x+w, y, y+h, tempRGB);

     tempRGB = get_bill_color(bill_light);
     hline(b, x+1, y+h-1, x+w-1, tempRGB);
     vline(b, x+w-1, y+1, y+h-2, tempRGB);
   
     if (stl & STL_FRAME)
     {
      tempRGB = get_bill_color(bill_dkshadow);
      hline(b, x+1, y+1, x+w-1, tempRGB);
      vline(b, x+1, y+1, y+h-1, tempRGB);

      tempRGB = get_bill_color(bill_shadow);
      hline(b, x, y, x+w, tempRGB);
      vline(b, x, y, y+h, tempRGB);
     }
     else {
      tempRGB = get_bill_color(bill_dkshadow);
      hline(b, x, y, x+w, tempRGB);
      vline(b, x, y, y+h, tempRGB);
      tempRGB = get_bill_color(bill_shadow);
      hline(b, x+1, y+1, x+w-1, tempRGB);
      vline(b, x+1, y+1, y+h-1, tempRGB);
     }
    }
    else {
     rect(b, x, y, x+w, y+h, get_bill_color(bill_dkshadow));
     rect(b, x+1, y+1, x+w-1, y+h-1, get_bill_color(bill_shadow));
    }
   }
  
   //The following HAS to be done AFTER THE FRAME!
   if ((stl & STL_DOWN) || (stl & STL_UP))
   {
    x+=2;
    y+=2;
    if(w > 0)
     w-=4;
    else
     w+=4;
    if(h>0)
     h-=4;
    else
     h+=4;
   }
   //Draw the BackGround
   if (stl & STL_FLAT)
    rectfill(b, x, y, x+w, y+h, get_bill_color(bill_face));
   else if(stl & STL_FRAMEFILLED) 
    rectfill(b, x, y, x+w, y+h, get_bill_color(bill_framebg));
   else if(stl & STL_DITHERED)
   {
    pattern = create_bitmap(2, 2);

    tempRGB = get_bill_color(bill_light);
    putpixel(pattern, 0, 1, tempRGB);
    putpixel(pattern, 1, 0, tempRGB);
    tempRGB = get_bill_color(bill_hlight);
    putpixel(pattern, 0, 0, tempRGB);
    putpixel(pattern, 1, 1, tempRGB);
 
    drawing_mode(DRAW_MODE_COPY_PATTERN, pattern, 0, 0);
    rectfill(b, x, y, x+w, y+h, 0);
    solid_mode();
    /*JW: Fixed as per author's site*/
    destroy_bitmap(pattern);
   }
   else if(stl & STL_TITLEBAR)
   {
    rectfill(b, x, y, x+w, y+h, get_bill_color(bill_activetitle));
   }
  }
 }
}
/*
 * call-seq:
 *   solid_mode -> nil
 *
 * This is a shortcut for selecting solid drawing mode. It is equivalent to
 * calling drawing_mode(DRAW_MODE_SOLID, nil, 0, 0).
 */
VALUE a4r_API_solid_mode(VALUE self)
{
  solid_mode();
  return Qnil;
}
Example #13
0
/* draws the entire view */
void draw_view()
{
   int SCREEN_W = al_get_display_width();
   int SCREEN_H = al_get_display_height();
   int (*project)(float *f, int *i, int c);
   int r, g, b;
   ALLEGRO_COLOR c;
   int i, n, x, y;
   float point[6];
   int ipoint[6];

   al_clear_to_color(makecol(0, 0, 0));

   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE, al_map_rgba_f(1, 1, 1, 1));

   for (i=0; i<4; i++) {

      view_left   = viewinfo[i].pos[0] * SCREEN_W;
      view_top    = viewinfo[i].pos[1] * SCREEN_H;
      view_right  = viewinfo[i].pos[2] * SCREEN_W;
      view_bottom = viewinfo[i].pos[3] * SCREEN_H;

      if ((view_right > view_left) && (view_bottom > view_top) && 
	  (view_right > 0) && (view_bottom > 0) &&
	  (view_left < SCREEN_W) && (view_top < SCREEN_H)) {

	 switch (i) {

	    case 0:
	       /* flat projection, green */
	       project = project_flat;

	       r = 0;
	       g = 255;
	       b = 0;
	       break;

	    case 1:
	       /* spherical coordinates, yellow */
	       project = project_spherical;

	       r = 255;
	       g = 255;
	       b = 0;
	       break;

	    case 2:
	       /* inside a tube, blue */
	       project = project_tube;

	       r = 0;
	       g = 0;
	       b = 255;
	       break;

	    case 3:
	       /* surface of cylinder, red */
	       project = project_cylinder;

	       r = 255;
	       g = 0;
	       b = 0;
	       break;

	    default:
	       /* oops! */
	       assert(FALSE);
	       return;
	 }

	 if (!no_grid) {
	    c = makecol(r/5, g/5, b/5);

	    n = (low_detail) ? 8 : 16;

	    for (x=0; x<=n; x++) {
	       for (y=0; y<=n; y++) {
		  point[0] = (float)x / n;
		  point[1] = (float)y / n;
		  point[2] = (float)(x+1) / n;
		  point[3] = (float)y / n;
		  point[4] = (float)x / n;
		  point[5] = (float)(y+1) / n;

		  if (project(point, ipoint, 6)) {
		     if (x < n)
			line(ipoint[0], ipoint[1], ipoint[2], ipoint[3], c);

		     if ((y < n) && ((x < n) || (i == 0)))
			line(ipoint[0], ipoint[1], ipoint[4], ipoint[5], c);
		  }
	       }
	    }
	 }

	 draw_player(r, g, b, project);
	 draw_badguys(r, g, b, project);
	 draw_bullets(r, g, b, project);
	 draw_explode(r, g, b, project);
      }
   }

   solid_mode();

   draw_message();

   textprintf(font, 4, 4, makecol(128, 128, 128), "Lives: %d", lives);
   textprintf(font, 4, 16, makecol(128, 128, 128), "Score: %d", score);
   textprintf(font, 4, 28, makecol(128, 128, 128), "Hiscore: %d", get_hiscore());

   al_flip_display();
}
int main( int argc, char *argv[] )
{
    BITMAP *lobuf;
    BITMAP *backbuf;    

#ifndef NDEBUG
    // Create a win32 console for printfing
	AllocConsole();

	freopen("CONIN$","rb",stdin);   // reopen stdin handle as console window input
	freopen("CONOUT$","wb",stdout);  // reopen stout handle as console window output
	freopen("CONOUT$","wb",stderr); // reopen stderr handle as console window output
#endif

    //----- Game stuff ---------------

	// the map of the world
    TileMap map( 300 );

	// the chunks of land
	std::vector<TileMap*> landChunks;

    set_color_depth( 32 );

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

	// install ticker
	LOCK_VARIABLE( ticks );
	LOCK_FUNCTION( ticker );
	install_int_ex( ticker, BPS_TO_TIMER( UPDATES_PER_SEC ) );
    
    if (set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 ) != 0)
    {
        set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
        allegro_message( "Unable to set graphics mode:\n%s\n", 
                         allegro_error );
        return 1;
    }

	enable_hardware_cursor();
	select_mouse_cursor( MOUSE_CURSOR_ARROW );
	

    lobuf = create_bitmap( 320, 240 );    
    backbuf = create_bitmap( SCREEN_W, SCREEN_H );
	show_mouse( backbuf );

//    printf("lobuf %p backbuf %p\n", lobuf, backbuf );    
        
	

    // init gameplay stuff
	srand( time(0));

    //printf("init map...\n" );    
    map.init();
    map.reset();    
	map.do_water = true;

	message( "I woke near the ocean. I didn't even know my own name." );
	message( "So I started exploring (drag RMB to scroll)");

	// load chunks
	loadLandChunks( "gamedata/land.txt", landChunks );
	map.paste( landChunks[0], 148, 148 );

    map.enableSelect( lobuf );   

	// make player
	BITMAP *npcCodeMask = load_bitmap( "gamedata/code_npc.bmp", NULL );
	BITMAP *critterCodeMask = load_bitmap( "gamedata/code_critter.bmp", NULL );
	BITMAP *playerBmp = make_pixbot( npcCodeMask );		

	// Init game objects
	std::vector<GameObj*> gameObjs;

	Player *player = new Player();
	player->m_bmp = playerBmp;
	player->m_x = 150;
	player->m_y = 148;
	gameObjs.push_back( player );
	int currTool = Tool_WALK;	

    //printf("--- mainloop\n" );   
    bool done = false;
	bool dbgShowSelects = false;

	// near center on a 300x300 map
	int view_x = -1644, 
		view_y = -800;
	bool dragging = false;
	int drag_x, drag_y; 	
	int view_drag_x, view_drag_y; 
	int mouse_x2, mouse_y2; // in lobuf coords	
	int last_b = 0;
	int px, py;
	bool doGenerate = true;

    while (!done)
    {
		// handle ticks -- give the ticker a chance to start
		while( ticks==0)
		{
			rest(100 / UPDATES_PER_SEC );
		}
		while ( ticks > 0)
		{
			int old_ticks = ticks;			
			
			//=== Update ====
			map.m_wave_offs++;
						
			if (messageTime>0)
			{
				messageTime--;
				if (messageTime==0)
				{
					strcpy( messageText, "" );					
				}
			} else {
				if (!messageQueue.empty())
				{
					strcpy( messageText, messageQueue.front().c_str() );
					messageQueue.pop_front();
					messageTime = MSG_TIME;
				}
			}

			for (int i=0; i < gameObjs.size(); ++i )
			{
				if (gameObjs[i])
				{
					gameObjs[i]->update( map, gameObjs );				
				}
			}

			// update may have NULL'd objects
			std::vector<GameObj*>::iterator removed;
			removed = std::remove( gameObjs.begin(), gameObjs.end(), (GameObj*)NULL );
			gameObjs.erase( removed, gameObjs.end() );
			

			// update bubbles
			for (int i=0; i < bubbles.size(); i++)
			{
				bubbles[i]->bub_age += 1.0 / (float)UPDATES_PER_SEC;
			}

			ticks--;
			if (old_ticks <= ticks) break;
		}

		int dropBubble = -1;

		// keyboard input
        if (keypressed())
        {
			int k = readkey();
			
			if (cheatsEnabled)
			{
				switch(k>>8) 
				{
					//---- debug keys
					case KEY_F5:
						dbgShowSelects = !dbgShowSelects;
						break;
					case KEY_F6:
						playerBmp = make_pixbot( npcCodeMask );	
						player->m_bmp = playerBmp;
						break;
					case KEY_F7:
						bubbles.push_back( create_bubble( landChunks ) );
						break;
				}				
			}

			switch(k>>8) {			            
				
				case KEY_F11:
					cheatsEnabled = true;
					message("Cheats enabled.");
					break;
				
				//---- game keys
				case KEY_1: dropBubble = 0; break;				
				case KEY_2: dropBubble = 1; break;
				case KEY_3: dropBubble = 2; break;
				case KEY_4: dropBubble = 3; break;
				case KEY_5: dropBubble = 4; break;

				// hack -- on keydown, clear walk wait counter
				case KEY_LEFT:
				case KEY_RIGHT:
				case KEY_UP:
				case KEY_DOWN:
					player->walk_c = 0;
					break;

			}
        }

		if ((dropBubble >= 0) && (dropBubble < bubbles.size()) )
		{
			TileMap *bub = bubbles[dropBubble];
			bubbles[dropBubble] = bubbles[ bubbles.size() -1 ];
			bubbles.pop_back();

			map.paste( bub, 
					   player->m_x - bub->m_size/2, 
					   player->m_y - bub->m_size/2 );
			doGenerate = true;
			delete bub;
		}

		// generate entities
		if (doGenerate)
		{
			doGenerate = false;			

			for (int i=0; i < map.m_size; i++)
			{
				for (int j=0; j < map.m_size; j++)
				{
					if (map.map(i,j).m_gen != Gen_NONE )
					{						
						if (map.map(i,j).m_gen == Gen_BUBBLE)
						{							
							BubbleObj *bubObj = new BubbleObj();
							bubObj->m_x = i;
							bubObj->m_y = j;
							bubObj->m_bub = create_bubble( landChunks );
							bubObj->m_bmp = create_bitmap( 15, 15 );
							BITMAP *bubBmp = bubObj->m_bub->bub_bmp;
							stretch_blit( bubBmp, bubObj->m_bmp, 0,0, bubBmp->w, bubBmp->h, 0,0, 15, 15 );

							gameObjs.push_back( bubObj );
						} else if (map.map(i,j).m_gen == Gen_CRITTER) {
							CritterObj *critObj = new CritterObj();
							critObj->m_x = i;
							critObj->m_y = j;				

							BITMAP *critpic;
							int critNdx = rand() % (critterBmps.size()+1);
							if (critNdx == critterBmps.size())
							{
								// yay new critter
								critpic = make_pixbot( critterCodeMask );
								critterBmps.push_back( critpic );
							}
							else
							{
								critpic = critterBmps[ critNdx ];
							}

							critObj->m_bmp = critpic;

							gameObjs.push_back( critObj );

						} else if (map.map(i,j).m_gen == Gen_NPC) {
							NpcObj *npc = new NpcObj();
							npc->m_x = i;
							npc->m_y = j;							
							npc->m_bmp = make_pixbot( npcCodeMask );							

							gameObjs.push_back( npc );
						}

						map.map(i,j).m_gen = Gen_NONE;
					}
				}
			}
		}
		
		// check for quit
		if (key[KEY_ESC]) {
			exit(0);
			break;
		}

		player->walk_x = 0; player->walk_y = 0;
		if (key[KEY_UP] && !key[KEY_DOWN])
		{
			player->walk_x = 0; player->walk_y = 1;
		}
		else if (!key[KEY_UP] && key[KEY_DOWN])
		{
			player->walk_x = 0; player->walk_y = -1;
		}
		else if (!key[KEY_LEFT] && key[KEY_RIGHT])
		{
			player->walk_x = -1; player->walk_y = 0;
		}
		else if (key[KEY_LEFT] && !key[KEY_RIGHT])
		{
			player->walk_x = 1; player->walk_y = 0;
		}
				
        // Map cursor
		char buff[246];
		int mapX, mapY;
		map.clearSelected();

		mouse_x2 = mouse_x/2;
		mouse_y2 = mouse_y/2;
		if (map.screenToMap( mouse_x2, mouse_y2, mapX, mapY ))
		{
			sprintf( buff, "V %d %d x y %d %d [%d]  -- map %d %d", 
					view_x, view_y, mouse_x, mouse_y, mouse_b, mapX, mapY );

			// NOTE: Don't use mouse selection anymore -- just use selection
			// to mark player
			//map.map( mapX, mapY ).m_selected = true;
		}
		else
		{
			sprintf( buff, "V %d %d x y %d %d  NO TILE", 
					view_x, view_y, mouse_x, mouse_y );
		}

		map.map( player->m_x, player->m_y ).m_selected = true;

		

		// Mouse button 2 -- drag
		if (mouse_b & 0x2)
		{
			if (!dragging)
			{
				dragging = true;
				drag_x = mouse_x2;
				drag_y = mouse_y2;
				view_drag_x = view_x;
				view_drag_y = view_y;
			}
			else
			{
				int dx = mouse_x2 - drag_x;
				int dy = mouse_y2 - drag_y;
				view_x = view_drag_x + dx;
				view_y = view_drag_y + dy;

			}
		}
		else
		{
			dragging = false;
		}

		// button 1 -- use tool (or walk)		
		if (mouse_b & 0x1)
		{
			switch( currTool)
			{
			case Tool_WALK:
				{
					MapCell &cell = map.map(player->m_x, player->m_y );					
					px = cell.sx + 4;
					py = cell.sy + 10;
					
					if ((px < mouse_x2) && (py < mouse_y2 ))
					{
						player->walk_x = -1; player->walk_y = 0;
					}
					else if ((px > mouse_x2) && (py > mouse_y2 ))
					{
						player->walk_x = 1; player->walk_y = 0;
					}
					else if ((px > mouse_x2) && (py < mouse_y2 ))
					{
						player->walk_x = 0; player->walk_y = -1;
					}
					else if ((px < mouse_x2) && (py > mouse_y2 ))
					{
						player->walk_x = 0; player->walk_y = 1;
					}
				}
				break;
			}
		}
		else
		{
			switch( currTool )
			{
			case Tool_WALK:
				if (last_b & 0x01)
				{
					player->walk_x = 0;
					player->walk_y = 0;
				}
				break;
			}
		}
		last_b = mouse_b;

		// ==== draw =====
		rectfill( lobuf, 0, 0, 320, 240, makecol( 135, 171, 189 ) );
        //map.draw( lobuf, 10, 30 );
        map.draw( lobuf, view_x, view_y, gameObjs );        

		// draw bubbles
		int bx = 160 - (bubbles.size() * 12);
		char buf[10];
		for (int i=0; i < bubbles.size(); i++)
		{
			TileMap *b = bubbles[i];
			draw_sprite( lobuf, b->bub_bmp, 
				bx,  215 - (int)(sin(b->bub_age * M_PI)*3) );

			sprintf( buf,"%d", i+1 );
			textout_centre_ex( lobuf, font, buf, bx + 13, 231, makecol( 0x44, 0x66, 0x77 ), -1);
			textout_centre_ex( lobuf, font, buf, bx + 12, 230, makecol( 0xff, 0xff, 0xff ), -1);

			bx += 24;
		}

		//DBG draw player
		//masked_stretch_blit( playerBmp, lobuf, 0, 0, playerBmp->w, playerBmp->h,
		//								10, 20, playerBmp->w * 4, playerBmp->h * 4 );				

        // scale buffer to screen
		stretch_blit( dbgShowSelects?map.m_selectMap:lobuf, backbuf, 
                      0, 0, lobuf->w, lobuf->h,
                      0, 0, SCREEN_W, SCREEN_H );        
        
        
		// Draw text and stuff at full res
		//masked_blit( bubbles[0]->bub_bmp, backbuf, 0, 0, 50, 20, 
		//			 bubbles[0]->bub_bmp->w, bubbles[0]->bub_bmp->h );

		//textout( backbuf, font, buff, 10, 10, makecol( 0xff, 0xff, 0xff ) );

		drawing_mode( DRAW_MODE_TRANS, NULL, 0, 0 );
		set_trans_blender( 0, 0, 0, 128 );
		rectfill( backbuf, 0, 7, 640, 75, makecol( 0xff, 0xff, 0xff ) );
		solid_mode();
		hline( backbuf, 0, 7, 640, makecol( 0, 0, 0x77 ) );
		hline( backbuf, 0, 75, 640, makecol( 0, 0, 0x77 ) );

		// player icon
		masked_stretch_blit( playerBmp, backbuf, 0, 0, playerBmp->w, playerBmp->h,
												10, 10, playerBmp->w * 4, playerBmp->h * 4 );

		//party icons
		for (int i=0; i < npcs.size(); i++)
		{
			BITMAP *npcBmp = npcs[i]->m_bmp;
			masked_stretch_blit( npcBmp, backbuf, 0, 0, npcBmp->w, npcBmp->h,
													70 + 45*i, 10, npcBmp->w * 4, npcBmp->h * 4 );
		}

		if (strlen(messageText))
		{
			float t = (float)messageTime / MSG_TIME;			

			//textout_centre_ex( backbuf, font, messageText, 322, 62, makecol( 0x44, 0x66, 0x77 ), -1 );
			textout_centre_ex( backbuf, font, messageText, 320, 60, 
									makecol( lerp( t, 0x00, 0xcc ), 
											 lerp( t, 0x00, 0xcc ), 
											 lerp( t, 0x00, 0xcc ) ), -1 );
				//makecol( 0x44, 0x66, 0x77 ),
				//makecol( 0xff, 0xff, 0xff ), -1 );
		}

        // flip screen
		vsync();
		acquire_screen();		
        blit( backbuf, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H );        
		release_screen();

		yield_timeslice();
    }

    return 0;
    
}
Example #15
0
void play_intro(void)
{
#define COL(index,red,green,blue) \
  if ((index>=min) && (index<=max)) { \
    pal[index].r = (red);             \
    pal[index].g = (green);           \
    pal[index].b = (blue);            \
  }

#define FADE(speed) \
  fade_from(source, pal, speed); \
  get_palette(source)

#define NORMAL() \
  min = 0;         \
  max = PAL_SIZE-1

  BITMAP *bg = (BITMAP *)datafile[MYLOGO_BMP].dat;
  PALETTE source, pal;
  int n, n2;
  int min, max;

  /* play the introduction theme */
  qtetris_music(MUSIC_INTRO, FALSE);

  n = 0;
  NORMAL();

  set_palette(black_palette);
  get_palette(source);
  get_palette(pal);

  /* DAC *********************************/
  clear(virtual);
  blit(bg, virtual, 0, 0,
    QTETRIS_SCREEN_W/2 - bg->w/2,
    QTETRIS_SCREEN_H/2 - bg->h/2, bg->w, bg->h);
  qtetris_blit(virtual);
  FADE(1);

  /* David A. Capello */
  /* fg */
  min = 1;
  max = 28;
  for (n2=0, n=min; n<=max+2; n2=n, n+=2) {
    COL(n2,  0,  0,  0);
    COL(n,   32, 32, 63);
    COL(n+1, 63, 63, 63);
    FADE(32);
  }

  /* bg */
  min = 32;
  max = 45;
  for (n=max; n>=min-4; n--) {
    NORMAL();
    for (n2=1; n2<=28; n2+=2) {
      COL(n2+1, 63-(-63*(n-45)/(45-32+4)),
                63-(-63*(n-45)/(45-32+4)),
                63-(-63*(n-45)/(45-32+4)));
      COL(n2, -63*(n-45)/(45-32+4), 0, 0);
    }

    min = 32;
    max = 45;
    COL(n+4, 63, 63, 63);
    COL(n+2, 63,  0,  0);
    COL(n,   63, 63,  0);

    FADE(64);
  }

  /* Present */
  NORMAL();
  COL(253, 63, 63, 63);
  COL(254, 32, 32, 32);
  COL(255, 16, 16, 16);
  FADE(4);

  /* fin de la primer etapa **************/
  fade_out(2);

  /* QUEEN LOGO **************************/
  fade_out(2);

  clear(virtual);
  blit(datafile[QUEENLOG_BMP].dat, virtual, 0, 0,
    QTETRIS_SCREEN_W/2-((BITMAP *)datafile[QUEENLOG_BMP].dat)->w/2,
    QTETRIS_SCREEN_H/2-((BITMAP *)datafile[QUEENLOG_BMP].dat)->h/2,
    ((BITMAP *)datafile[QUEENLOG_BMP].dat)->w,
    ((BITMAP *)datafile[QUEENLOG_BMP].dat)->h);
  qtetris_blit(virtual);

  fade_in(datafile[PALETTE_BMP].dat, 1);
  get_palette(pal);
  get_palette(source);
  FADE(2);
  fade_out(2);

  /* TETRIS ******************************/
  set_palette(black_palette);

  get_palette(source);
  get_palette(pal);

  NORMAL();
  for (n=0; n<PAL_SIZE; n++) {
    COL(n, 63, 63, 63);
  }
  FADE(2);

  /* mainscreen */
  clear(virtual);
  drawing_mode(DRAW_MODE_COPY_PATTERN, datafile[TETRISBG_BMP].dat, 0, 0);
  rectfill(virtual, 0, 0, QTETRIS_SCREEN_W, QTETRIS_SCREEN_H, -1);

  color_map = shadow_map;
  drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
  draw_trans_sprite(virtual, datafile[TETRIS_BMP].dat,
    QTETRIS_SCREEN_W/2 - ((BITMAP *)datafile[TETRIS_BMP].dat)->w/2 + 6,
    QTETRIS_SCREEN_H/2 - ((BITMAP *)datafile[TETRIS_BMP].dat)->h/2 + 12);
  solid_mode();

  draw_sprite(virtual, datafile[TETRIS_BMP].dat,
    QTETRIS_SCREEN_W/2 - ((BITMAP *)datafile[TETRIS_BMP].dat)->w/2,
    QTETRIS_SCREEN_H/2 - ((BITMAP *)datafile[TETRIS_BMP].dat)->h/2);
  qtetris_blit(virtual);

  for (n=15; n<112; n++) {
    COL(n, 0, 0, 0);
  }
  FADE(2);
  FADE(2);

  fade_from(pal, datafile[PALETTE_BMP].dat, 2);
}
Example #16
0
/* spline:
 *  Draws a bezier spline onto the specified bitmap in the specified color.
 */
void _soft_spline(BITMAP *bmp, AL_CONST int points[8], int color)
{
   #define MAX_POINTS   64

   int xpts[MAX_POINTS], ypts[MAX_POINTS];
   int i;
   int num_points;
   int c;
   int old_drawing_mode, old_drawing_x_anchor, old_drawing_y_anchor;
   BITMAP *old_drawing_pattern;
   ASSERT(bmp);

   /* Calculate the number of points to draw. We want to draw as few as
      possible without loosing image quality. This algorithm is rather
      random; I have no motivation for it at all except that it seems to work
      quite well. The length of the spline is approximated by the sum of
      distances from first to second to third to last point. The number of
      points to draw is then the square root of this distance. I first tried
      to make the number of points proportional to this distance without
      taking the square root of it, but then short splines kind of had too
      few points and long splines had too many. Since sqrt() increases more
      for small input than for large, it seems in a way logical to use it,
      but I don't precisely have any mathematical proof for it. So if someone
      has a better idea of how this could be done, don't hesitate to let us
      know...
   */

   #undef DIST
   #define DIST(x, y) (sqrt((x) * (x) + (y) * (y)))
   num_points = (int)(sqrt(DIST(points[2]-points[0], points[3]-points[1]) +
                           DIST(points[4]-points[2], points[5]-points[3]) +
                           DIST(points[6]-points[4], points[7]-points[5])) *
                      1.2);

   if (num_points > MAX_POINTS)
      num_points = MAX_POINTS;

   calc_spline(points, num_points, xpts, ypts);

   acquire_bitmap(bmp);

   if ((_drawing_mode == DRAW_MODE_XOR) ||
       (_drawing_mode == DRAW_MODE_TRANS)) {
      /* Must compensate for the end pixel being drawn twice,
         hence the mess. */
      old_drawing_mode = _drawing_mode;
      old_drawing_pattern = _drawing_pattern;
      old_drawing_x_anchor = _drawing_x_anchor;
      old_drawing_y_anchor = _drawing_y_anchor;
      for (i=1; i<num_points-1; i++) {
         c = getpixel(bmp, xpts[i], ypts[i]);
         line(bmp, xpts[i-1], ypts[i-1], xpts[i], ypts[i], color);
         solid_mode();
         putpixel(bmp, xpts[i], ypts[i], c);
         drawing_mode(old_drawing_mode, old_drawing_pattern,
                      old_drawing_x_anchor, old_drawing_y_anchor);
      }
      line(bmp, xpts[i-1], ypts[i-1], xpts[i], ypts[i], color);
   }
   else {
      for (i=1; i<num_points; i++)
         line(bmp, xpts[i-1], ypts[i-1], xpts[i], ypts[i], color);
   }

   release_bitmap(bmp);
}
Example #17
0
// prepares the person_bmp
BITMAP *Person::prepare_sprite()
{
  static BITMAP *person_bmp = NULL;
  if (person_bmp == NULL)
    person_bmp = create_bitmap(TILE_W, TILE_H);

  int ani_frame = -1;

  switch (m_state) {

    case STAND_PERSON:
      ani_frame = ANI_FRAME_STAND;
      break;

    case WALKING_PERSON:
      ani_frame = ((GAME_T - m_state_time) % (BPS/4)) < (BPS/8) ?
	ANI_FRAME_WALK1: ANI_FRAME_WALK2;
      break;

    case LOOKING_PERSON:
      ani_frame = ANI_FRAME_LOOK;
      break;

    case CALLING_PERSON: {
      if (GAME_T - m_state_time < CALLING_DURATION*1/6)
	ani_frame = ANI_FRAME_HELP1;
      else if (GAME_T - m_state_time < CALLING_DURATION*2/6)
	ani_frame = ANI_FRAME_HELP2;
      else if (GAME_T - m_state_time < CALLING_DURATION*3/6)
	ani_frame = ANI_FRAME_HELP3;
      else if (GAME_T - m_state_time < CALLING_DURATION*4/6)
	ani_frame = ANI_FRAME_HELP3;
      else if (GAME_T - m_state_time < CALLING_DURATION*5/6)
	ani_frame = ANI_FRAME_HELP3;
      else
	ani_frame = ANI_FRAME_HELP1;
      break;
    }

    case ABDUCTING_PERSON:
      ani_frame = ANI_FRAME_HELP3;
      break;

    case FALLING_PERSON:
      ani_frame = ANI_FRAME_HELP2;
      break;

    case DEAD_PERSON:
      // impossible to be here
      break;
  }

  if (ani_frame < -1) {
    clear_to_color(person_bmp, bitmap_mask_color(person_bmp));
    return person_bmp;
  }

  blit(MEDIA_BITMAP(PEOPLE_PCX), person_bmp,
       ani_frame*TILE_W, m_type*TILE_H,
       0, 0, TILE_W, TILE_H);

  lit_mode(0, 0, 0);
  draw_lit_sprite(person_bmp, person_bmp, 0, 0,
		  static_cast<int>(255 * m_toast_factor));
  solid_mode();

  return person_bmp;
}