Пример #1
0
//draw with scaling
void sprite::drawframe(BITMAP *dest, int dest_w, int dest_h)  {
    if (!this->image) return;

    int fx = this->animstartx + (this->curframe % this->animcolumns) * this->width;
    int fy = this->animstarty + (this->curframe / this->animcolumns) * this->height;
    masked_stretch_blit(this->image, dest, fx, fy, this->width, this->height, (int)this->x, (int)this->y, dest_w, dest_h);
}
Пример #2
0
void cTitantron::CaptureBuffer(ImgData *out)
{
   Int32 x = m_focus->GetX() - m_focus->GetW();
   Int32 y = m_focus->GetZ() - m_focus->GetH();

   // prevent crashing
   if(x < 0) x = 0;
   if(y < 0) y = 0;
   if(x > out->w) x = out->w;
   if(y > (out->h - m_buffer->h/2)) y = out->h - m_buffer->h/2;

   // capture new titantron from screen buffer
   masked_stretch_blit(out, m_buffer, 
      x, y, 
      m_buffer->w/2, m_buffer->h/2, 
      0, 0,
      m_buffer->w, m_buffer->h
   );
   //

   /*
   rectfill(out, 
             x, y,
             x + m_buffer->w/2, y + m_buffer->h/2,
             COLOR_GRAY);
   */
}
Пример #3
0
//the final score screen
void CGame::ShowResults() {

	int i;
	int finalscore;
	WINDOWS_BITMAP *text;

	text = create_bitmap(220, 130);
	clear_to_color(text,makecol(255,0,255));
	

	scare_mouse();

	//background image
	blit((WINDOWS_BITMAP *)data[ZSCORE_BMP].dat, background,0,0,0,0,SCREEN_W,SCREEN_H);
	
	//print text on temp image and resize
	text_mode(-1);

	for (i=0;i<numplayers;i++) {
		
		finalscore = players[i].CalcFinalScore();
		textprintf_centre(text,font,110,(i*40),players[i].color,"%d - %s",finalscore,players[i].name);
	}
	
	masked_stretch_blit(text,background,0,0,220,130,210,190,390,250);

	blit(background,screen,0,0,0,0,SCREEN_W,SCREEN_H);

	clear_keybuf();
	readkey();

	destroy_bitmap(text);

}
Пример #4
0
void SplashScreen::onDraw(BITMAP* aBuffer)
{
    clear_to_color(aBuffer, makecol(255,255,255));

    float stretch = std::cos(mFrameCounter*0.4f) / (mFrameCounter * 0.2f);

    if (mFrameCounter > 150)
    {
        stretch = 0;
    }

    int w = mDarkbitsLogoBitmap->w * std::pow(2.0f, stretch);

    if (w <= 0)
    {
        w = 1;
    }

    int h = (mDarkbitsLogoBitmap->h * mDarkbitsLogoBitmap->w) / w;


    masked_stretch_blit(mDarkbitsLogoBitmap,
                        aBuffer,
                        0,
                        0,
                        mDarkbitsLogoBitmap->w,
                        mDarkbitsLogoBitmap->h,
                        160 - w / 2,
                        120 - h / 2,
                        w,
                        h);
}
Пример #5
0
void DrawOptions()
{
    if(Running)
    {
        clear_to_color(buffer,makecol(200,180,200));

        masked_blit(button,buffer,0,0,backButt.x,backButt.y,backButt.w,backButt.h);
        textout_ex(buffer,font,"BACK",backButt.x+48,backButt.y+28,makecol(0,0,0),-1);
        masked_blit(button,buffer,0,0,fxPlus.x,fxPlus.y,fxPlus.w,fxPlus.h);
        textout_ex(buffer,font,"+",fxPlus.x+fxPlus.w/2-4,fxPlus.y+fxPlus.h/2-4,makecol(0,0,0),-1);
        masked_blit(button,buffer,0,0,fxMinus.x,fxMinus.y,fxMinus.w,fxMinus.h);
        textout_ex(buffer,font,"-",fxMinus.x+fxMinus.w/2-4,fxMinus.y+fxMinus.h/2-4,makecol(0,0,0),-1);
        masked_blit(button,buffer,0,0,musPlus.x,musPlus.y,musPlus.w,musPlus.h);
        textout_ex(buffer,font,"+",musPlus.x+musPlus.w/2-4,musPlus.y+musPlus.h/2-4,makecol(0,0,0),-1);
        masked_blit(button,buffer,0,0,musMinus.x,musMinus.y,musMinus.w,musMinus.h);
        textout_ex(buffer,font,"-",musMinus.x+musMinus.w/2-4,musMinus.y+musMinus.h/2-4,makecol(0,0,0),-1);
        masked_blit(button,buffer,0,0,zombieNext.x,zombieNext.y,zombieNext.w,zombieNext.h);
        textout_ex(buffer,font,">",zombieNext.x+zombieNext.w/2-4,zombieNext.y+zombieNext.h/2-4,makecol(0,0,0),-1);
        masked_blit(button,buffer,0,0,zombiePrev.x,zombiePrev.y,zombiePrev.w,zombiePrev.h);
        textout_ex(buffer,font,"<",zombiePrev.x+zombiePrev.w/2-4,zombiePrev.y+zombiePrev.h/2-4,makecol(0,0,0),-1);
        masked_blit(button,buffer,0,0,heroNext.x,heroNext.y,heroNext.w,heroNext.h);
        textout_ex(buffer,font,">",heroNext.x+heroNext.w/2-4,heroNext.y+heroNext.h/2-4,makecol(0,0,0),-1);
        masked_blit(button,buffer,0,0,heroPrev.x,heroPrev.y,heroPrev.w,heroPrev.h);
        textout_ex(buffer,font,"<",heroPrev.x+heroPrev.w/2-4,heroPrev.y+heroPrev.h/2-4,makecol(0,0,0),-1);

        masked_stretch_blit(button,buffer,0,0,128,64,fxAm.x,fxAm.y,fxAm.w,fxAm.h);
        masked_stretch_blit(button,buffer,0,0,128,64,musAm.x,musAm.y,musAm.w,musAm.h);

        char tx[512] = "FX VOLUME : ";
        char temp[10];
        strcat(tx,itoa(fxVol,temp,10));
        textout_ex(buffer,font,tx,fxAm.x + 10,fxAm.y+10,makecol(255,220,255),-1);
        strcpy(tx,"MUSIC VOLUME : ");
        strcpy(temp,"");
        strcat(tx,itoa(musicVol,temp,10));
        textout_ex(buffer,font,tx,musAm.x + 10,musAm.y+10,makecol(255,220,255),-1);

        textout_ex(buffer,font,HeroF->str,heroPath.x,heroPath.y,makecol(10,20,10),-1);
        textout_ex(buffer,font,ZombieF->str,zombiePath.x,zombiePath.y,makecol(10,20,10),-1);

        masked_blit(mouseSprite,buffer,0,0,mouse.x,mouse.y,32,32);

        blit(buffer,screen,0,0,0,0,Resolution.x,Resolution.y);
    }
}
Пример #6
0
void MatrixIcons::subanimate()
{
	STACKTRACE;

	int i, j;
	int ix, iy;

	for (iy = scroll.y; iy < scroll.y + Nyshow && iy < Ny; ++iy ) {

		for (ix = scroll.x; ix < scroll.x + Nxshow && ix < Nx; ++ix ) {

			int xoverlay, yoverlay;
			int xicon, yicon, k;

			k = iy*Nx + ix;

			if (k >= maxitems)	 // if you've run out of bitmaps that you can plot...
				break;

			xoverlay = (ix - scroll.x) * Wicon;
			yoverlay = (iy - scroll.y) * Hicon;

			int w0, h0;
			w0 = iround(listIcon[k]->w * mainwindow->scale * extrascale);
			h0 = iround(listIcon[k]->h * mainwindow->scale * extrascale);

			// create a intermediate icon
			xicon =  (Wicon - w0) / 2;
			yicon =  (Hicon - h0) / 2;

			clear_to_color(tmp, makecol(255,0,255));

			if (listIcon[k] && (itemproperty[k] & ENABLE) ) {

				masked_stretch_blit(listIcon[k], tmp,
					0, 0, listIcon[k]->w, listIcon[k]->h,
					xicon, yicon, w0, h0 );
			}

			masked_blit(overlay, tmp, 0, 0, 0, 0, overlay->w, overlay->h );

			// blit the combined image onto the panel area
			masked_blit(tmp, drawarea, 0, 0, xoverlay, yoverlay, overlay->w, overlay->h );
		}
	}

	// one of them is highlighted ... the one which the mouse is pointed at: draw
	// a box around it ?
								 //mx / Wicon;
	i = scroll.xselect - scroll.x;
								 //my / Hicon;
	j = scroll.yselect - scroll.y;
	double a;
	//a = 0.5 + 0.5 * sin(areareserve->menu_time * 1E-3 * 2*PI / 10);
	a = 0.5;
	rect(drawarea, i*Wicon, j*Hicon, (i+1)*Wicon-1, (j+1)*Hicon-1, makecol(20*a,100*a,200*a));
}
Пример #7
0
 void CharPC::draw()
 {
       ScreenPanel* _panel = myProg->get_world()->get_screen();
       //clear_to_color(buffer, makecol(255,255,255));
       _panel->draw_to_screen(this->x - dx, this->y - dy, 
      (this->x) + 20, (this->y) + 20);
      //myProg->get_world()->get_screen()->draw_to_screen();
      
      if (key[KEY_SPACE]) //draw_sprite(buffer, this->char_sheet, this->x, this->y);
      {
          BITMAP* eatmyshorts = create_bitmap(20, 25);
          clear_to_color(eatmyshorts, makecol(255, 0, 255));
          masked_stretch_blit(this->char_sheet, eatmyshorts, 0, 96, 20, 24, 0, 0,  20, 25);
          
      }
      masked_stretch_blit(this->char_sheet, buffer, s_x, s_y, 20, 25, this->x, this->y,  20, 25);
      
      updated = false;
 }
Пример #8
0
    void SplashScreen::draw(BITMAP* dest)
    {
        clear_to_color(dest, makecol(255,255,255));
        
        if (mFrameCounter > 50 && mFrameCounter <= 100)
        {
			float l = ((100 - mFrameCounter) * (100 - mFrameCounter)) / (50.0 * 50.0);
			int w = mDarkbitsLogoBitmap->w * (1 + 20 * l);
			int h = (mDarkbitsLogoBitmap->h * mDarkbitsLogoBitmap->w) / w;

            masked_stretch_blit(mDarkbitsLogoBitmap, 
                                dest, 
                                0, 
                                0, 
                                mDarkbitsLogoBitmap->w,
                                mDarkbitsLogoBitmap->h,
                                160 - w / 2, 
                                120 - h / 2,
                                w,
                                h);
        }

		if (mFrameCounter > 100)
        {
			int w = mDarkbitsLogoBitmap->w;
			int h = (mDarkbitsLogoBitmap->h * mDarkbitsLogoBitmap->w) / w;
            masked_stretch_blit(mDarkbitsLogoBitmap, 
                                dest, 
                                0, 
                                0, 
                                mDarkbitsLogoBitmap->w,
                                mDarkbitsLogoBitmap->h,
                                160 - w / 2, 
                                120 - h / 2,
                                w,
                                h);
        }
    }
Пример #9
0
void GuiFrame::drawFrameImage(BITMAP *bmp, short frame_id) {
    FRAME_MASK *thisFrame = getFrameByID(frame_id);

    string title;
    if (thisFrame->state == FRAME_ACTIVE) title = thisFrame->label;
    else title = thisFrame->label;

    masked_stretch_blit((BITMAP*)resources.data[TOP].dat, bmp, 0, 0, 116, 4, thisFrame->x, thisFrame->y, thisFrame->w, 4);
    masked_stretch_blit((BITMAP*)resources.data[BOTTOM].dat, bmp, 0, 0, 116, 4, thisFrame->x, thisFrame->y+thisFrame->h-4, thisFrame->w, 4);
    masked_stretch_blit((BITMAP*)resources.data[LEFT].dat, bmp, 0, 0, 4, 120, thisFrame->x, thisFrame->y, 4, thisFrame->h);
    masked_stretch_blit((BITMAP*)resources.data[RIGHT].dat, bmp, 0, 0, 4, 120, thisFrame->x + thisFrame->w-4, thisFrame->y, 4, thisFrame->h);

    masked_blit((BITMAP*)resources.data[UP_LEFT].dat, bmp, 0, 0, thisFrame->x, thisFrame->y, 5, 5);
    masked_blit((BITMAP*)resources.data[UP_RIGHT].dat, bmp, 0, 0, thisFrame->x+thisFrame->w-5, thisFrame->y, 5, 5);
    masked_blit((BITMAP*)resources.data[DOWN_LEFT].dat, bmp, 0, 0, thisFrame->x, thisFrame->y+thisFrame->h-5, 5, 5);
    masked_blit((BITMAP*)resources.data[DOWN_RIGHT].dat, bmp, 0, 0, thisFrame->x+thisFrame->w-5, thisFrame->y+thisFrame->h-5, 5, 5);
    masked_stretch_blit((BITMAP*)resources.data[BAR].dat, bmp, 0, 0, 285, 14, thisFrame->x+4, thisFrame->y+4, thisFrame->w-8, 16);
/*
    drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
    rectfill(bmp, thisFrame->x+4, thisFrame->y+20, thisFrame->w-8, thisFrame->y+thisFrame->h-5, makecol(180,180,180));
    drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
*/
    textprintf_ex(bmp, font, thisFrame->x+10, thisFrame->y+8, makecol(255, 255, 255), -1, "%s", title.c_str());
}
Пример #10
0
void RenderingManager::renderWipeAnim(int frame)
{
	if ( frame < 0 || frame > 14 )
	{
		TRACE("Don't do that.");
		return;
	}

	char filename[] = "DATA/wipe/wipe_0000.tga";
	filename[17] = (frame/10) + '0';
	filename[18] = (frame%10) + '0';

	BITMAP* temp = loadImage(filename);
	masked_stretch_blit(temp, m_backbuf, 0, 0, 320, 240, 0, 0, 640, 480);
	destroy_bitmap(temp);
}
Пример #11
0
void Bitmap::StretchBlt(Bitmap *src, const Rect &src_rc, const Rect &dst_rc, BitmapMaskOption mask)
{
	BITMAP *al_src_bmp = src->_alBitmap;
	if (mask == kBitmap_Transparency)
	{
		masked_stretch_blit(al_src_bmp, _alBitmap,
			src_rc.Left, src_rc.Top, src_rc.GetWidth(), src_rc.GetHeight(),
			dst_rc.Left, dst_rc.Top, dst_rc.GetWidth(), dst_rc.GetHeight());
	}
	else
	{
		stretch_blit(al_src_bmp, _alBitmap,
			src_rc.Left, src_rc.Top, src_rc.GetWidth(), src_rc.GetHeight(),
			dst_rc.Left, dst_rc.Top, dst_rc.GetWidth(), dst_rc.GetHeight());
	}
}
Пример #12
0
void DrawHero(Hero h)
{
    if(inited)
    {
        if(levelUp) masked_blit(lvlUp->bitmap,buffer,(lvlUp->frame*player.position.w)+lvlUp->frame+1,(lvlUp->row*player.position.h)+lvlUp->row+1,player.position.x,player.position.y+8,player.position.w,player.position.h);
        masked_blit(player.a->bitmap,buffer,(player.a->frame*player.position.w)+player.a->frame+1,(player.a->row*player.position.h)+player.a->row+1,player.position.x,player.position.y,player.position.w,player.position.h);
        int percent = (player.maxHp > 0) ? (int)(48 * (player.hp / player.maxHp)) : 0;
        masked_stretch_blit(hpBar,buffer,0,0,32,32,player.position.x-9,player.position.y - 9, percent , 6);
        if(UpTimer) textout_ex(buffer,font,"LEVEL UP",UpPos.x,UpPos.y,makecol(0,0,0),-1);

        if(player.hp > 0 && player.maxHp > 0)
        {
            char *t = malloc(32 * sizeof(char));
            itoa((int)player.hp,t,10);
            textout_ex(buffer,font,t,player.position.x,player.position.y+35,makecol(0,0,0),-1);
        }
    }
}
Пример #13
0
void SplashScreen::draw(BITMAP* dest)
{
    clear_to_color(dest, makecol(255,255,255));
    
    //if (mFrameCounter > 50 && mFrameCounter <= 100)
    //{
		
		//float l = ((100 - mFrameCounter) * (100 - mFrameCounter)) / (50.0 * 50.0);
		//float l2 = (160 - mFrameCounter) / (160.0);

		//if(mFrameCounter > 100) l = 0;
		//if(mFrameCounter > 160) l2 = 0;
		//std::cout << l << std::endl;
		float stretch = std::cos(mFrameCounter*0.4f) / (mFrameCounter * 0.2f);

		if (mFrameCounter > 150)
		{
			stretch = 0;
		}

		int w = mDarkbitsLogoBitmap->w * std::pow(2.0f, stretch);//(1 + 20 * l);
		//w = mDarkbitsLogoBitmap->w * std::sin(mFrameCounter/1.2)*(40.0*(l2));

		if (w <= 0)
		{
			w = 1;
		}

		int h = (mDarkbitsLogoBitmap->h * mDarkbitsLogoBitmap->w) / w;
		
//		w += std::sin(mFrameCounter/2.0)*(100.0*(l2));

        masked_stretch_blit(mDarkbitsLogoBitmap, 
                            dest, 
                            0, 
                            0, 
                            mDarkbitsLogoBitmap->w,
                            mDarkbitsLogoBitmap->h,
                            160 - w / 2, 
                            120 - h / 2,
                            w,
                            h);
    //}
}
Пример #14
0
void draw_text(BITMAP *bmp, int x, int y, int w, int h, int color, const char *format, ...)
{
  if (w > 0 && h > 0) {
    char buf[512];
    va_list ap;

    va_start(ap, format);
    uvszprintf(buf, sizeof(buf), format, ap);
    va_end(ap);

    BITMAP *tmp = create_bitmap(text_length(gamefont, buf),
				text_height(gamefont)+1);

    clear_to_color(tmp, bitmap_mask_color(tmp));
    textout_ex(tmp, gamefont, buf, 0, 1, blend_color(color, makecol(0, 0, 0), 0.5), -1);
    textout_ex(tmp, gamefont, buf, 0, 0, color, -1);

    masked_stretch_blit(tmp, bmp, 0, 0, tmp->w, tmp->h, x, y, w, h);
    destroy_bitmap(tmp);
  }
}
Пример #15
0
void renderBatteryLivesDMX(int player)
{
	int xpos = getLeftmostColumnX_DMX(player) - 20;
	int ypos = DMX_STEP_ZONE_Y + 10;
	int direction = 1;
	if ( gs.player[player].isColumnReversed(0) )
	{
		ypos = DMX_STEP_ZONE_REV_Y - 28;
		direction = -1;
	}

	for ( int i = 0; i < gs.player[player].lifebarLives; i++ )
	{
		int frame = getValueFromRange(0, 7, (gs.player[player].stepZoneBeatTimer*100 / gs.player[player].stepZoneTimePerBeat));
		if ( frame < 0 || frame > 7 )
		{
			frame = 7;
		}
		masked_stretch_blit(m_notesDMX[2], rm.m_backbuf, 0, frame*40, 40, 40, xpos, ypos, 20, 20);
		ypos += 20*direction;
	}
}
Пример #16
0
void draw_blockers( BITMAP *targ, BITMAP *stamp, int x1, int y1, int x2, int y2 ) 
{
	int num;
	int dx, dy, ndx;	
	dx = x2-x1; dy = y2-y1;

	num = sqrt( dx*dx + dy*dy ) / 6;

	for (int i=0; i < num; i++) {
		float t = frandom();
		ndx = random(6);
		int sz = random( -10, 20 );

		masked_stretch_blit( stamp, targ, 
					 16*ndx, 0,    // stamp start
					 16, 15, 

					 ((x1 + dx*t) - (8+sz/2)) + random(-10, 10), // random along line (jittered)
					 ((y1 + dy*t) - (8+sz/2)) + random(-10, 10),  
					 16 + sz, 16 + sz );
		
	}
}
Пример #17
0
void render_health(int atX,int atY,int sizeX,int sizeY,int draw_health, int max) {
    masked_stretch_blit(healthbar,buffer,0,0,128,16,atX,atY,sizeX,sizeY);
    stretch_blit(healthbar,buffer,0,16,floor(((float)draw_health / (float)max) * 128.0f),16,atX,atY,floor(((float)draw_health / (float)max) * sizeX),sizeY);
}
Пример #18
0
int main (void) {
    allegro_init();
    install_keyboard();
    install_timer();

    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, SCREENX*SCALE, SCREENY*SCALE, 0, 0);
    set_window_title("Ultra Tank Destruction Battle Game");
    BITMAP * buffer = create_bitmap(SCREEN_W, SCREEN_H);

    install_int_ex(ticker, BPS_TO_TIMER(30));


    int tankx = 0, tanky = 0;
    int speed = 1;
    int tanksizex = 16, tanksizey = 16;
    int tankframe = 0, tankdir = 0;
    int walking = 0, shooting = 0;

    int xoffset = 0, yoffset = 0;

    int bullet = 0, bulletspeed = 3;
    int bulleton[BULLETS], bulletx[BULLETS], bullety[BULLETS], bulletspeedx[BULLETS], bulletspeedy[BULLETS];
    int shot = 0;

    int level[LEVELSIZEX*LEVELSIZEY] =
        {   2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,3,2,2,2,2,2,2,5,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            3,3,3,3,3,3,3,3,3,3,3,2,4,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,5,2,2,2,2,3,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,

            2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,3,2,2,2,2,2,2,5,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            3,3,3,3,3,3,3,3,3,3,3,2,4,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,5,2,2,2,2,3,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,

            2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,3,2,2,2,2,2,2,5,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            3,3,3,3,3,3,3,3,3,3,3,2,4,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,5,2,2,2,2,3,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,

            2,2,2,2,5,4,2,2,2,2,3,2,2,5,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            5,2,2,2,4,2,2,2,2,2,3,2,2,4,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            4,2,2,2,2,2,2,2,5,2,3,3,3,3,3,3,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,2,2,2,4,2,3,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,     };

    for (int i = 0; i < BULLETS; i++) {
        bulleton[i] = 0;
        bulletx[i] = 0;
        bullety[i] = 0;
        bulletspeedx[i] = 0;
        bulletspeedy[i] = 0;
    }


    BITMAP * tank = load_bitmap("mechtest/extremetankn.bmp", NULL);
    BITMAP * bulletimg = load_bitmap("mechtest/bullet.bmp", NULL);
    BITMAP * tilemap = load_bitmap("mechtest/tilemap.bmp", NULL);


    int running = 1;
    while (running) {

        rectfill(buffer, 0, 0, SCREEN_W-1, SCREEN_H-1, WHITE);

        poll_keyboard();
        if (key[KEY_ESC]) running = 0;

// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
        walking = 0;
        if (key[KEY_LEFT])  {tankdir = 0;   tankx-=speed;   walking=1;}
        if (key[KEY_RIGHT]) {tankdir = 1;   tankx+=speed;   walking=1;}
        if (key[KEY_UP])    {tankdir = 2;   tanky-=speed;   walking=1;}
        if (key[KEY_DOWN])  {tankdir = 3;   tanky+=speed;   walking=1;}

        if (key[KEY_S]) {
            if (!shot) {
                shot = 1;
                shooting = 1;
                bulleton[bullet] = 1;

                bulletspeedx[bullet] = 0;
                bulletspeedy[bullet] = 0;


                if (tankdir == 0) {
                    bulletx[bullet] = tankx - bulletimg->w;
                    bullety[bullet] = tanky + tanksizey/2 - bulletimg->h/2;
                    bulletspeedx[bullet] -= bulletspeed;

                }
                if (tankdir == 1) {
                    bulletx[bullet] = tankx + tanksizex;
                    bullety[bullet] = tanky + tanksizey/2 - bulletimg->h/2;
                    bulletspeedx[bullet] += bulletspeed;
                }
                if (tankdir == 2) {
                    bulletx[bullet] = tankx + tanksizex/2 - bulletimg->w/2;
                    bullety[bullet] = tanky - bulletimg->w/2;
                    bulletspeedy[bullet] -= bulletspeed;
                }
                if (tankdir == 3) {
                    bulletx[bullet] = tankx + tanksizex/2 - bulletimg->w/2;
                    bullety[bullet] = tanky + tanksizey;
                    bulletspeedy[bullet] += bulletspeed;
                }

                bullet++;
                if (bullet >= BULLETS) bullet = 0;
            }
        } else {
            shot = 0;
            shooting = 0;
        }


        xoffset = tankx - SCREENX/2 + tanksizex/2;
        yoffset = tanky - SCREENY/2 + tanksizey/2;

        if (xoffset > LEVELSIZEX*TILESIZE - SCREENX - 1) xoffset = LEVELSIZEX*TILESIZE - SCREENX - 1;
        if (yoffset > LEVELSIZEY*TILESIZE - SCREENY - 1) yoffset = LEVELSIZEY*TILESIZE - SCREENY - 1;

        if (xoffset < 0) xoffset = 0;
        if (yoffset < 0) yoffset = 0;




        int tilenum = 0;
        int destx1 = (xoffset)/TILESIZE, destx2 = (xoffset + SCREENX)/TILESIZE + 1;
        int desty1 = (yoffset)/TILESIZE, desty2 = (yoffset + SCREENY)/TILESIZE + 1;

        if (destx1 < 0) destx1 = 0;
        if (desty1 < 0) desty1 = 0;
        if (destx2 > LEVELSIZEX) destx2 = LEVELSIZEX;
        if (desty2 > LEVELSIZEY) desty2 = LEVELSIZEY;


        for (int y = desty1; y < desty2; y++) {
            for (int x = destx1; x < destx2; x++) {

                tilenum = level[y*LEVELSIZEX + x];
                stretch_blit(tilemap, buffer, (tilenum%MAPSIZEX)*TILESIZE, (tilenum/MAPSIZEX)*TILESIZE, TILESIZE, TILESIZE, (x*TILESIZE-xoffset)*SCALE, (y*TILESIZE-yoffset)*SCALE, TILESIZE*SCALE, TILESIZE*SCALE);


            }
        }



        if (walking) {
            if (tankframe == 1) {
                tankframe = 0;
            } else {
                tankframe = 1;
            }
        }
        masked_stretch_blit(tank, buffer, tankframe*tanksizex, tankdir*tanksizey, tanksizex, tanksizey, (tankx-xoffset)*SCALE, (tanky-yoffset)*SCALE, tanksizex*SCALE, tanksizey*SCALE);


        for (int i = 0; i < BULLETS; i++) {
            if (bulleton[i]) {
                bulletx[i] += bulletspeedx[i];
                bullety[i] += bulletspeedy[i];

                masked_stretch_blit(bulletimg, buffer, 0, 0, bulletimg->w, bulletimg->h, (bulletx[i]-xoffset)*SCALE, (bullety[i]-yoffset)*SCALE, bulletimg->w*SCALE, bulletimg->h*SCALE);
            }
        }




        //vsync();
        blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);

        while (ticks<1) {
            yield_timeslice();
            rest(10);
        }
        ticks=0;
    }

// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
    destroy_bitmap(tank);
    destroy_bitmap(bulletimg);
    destroy_bitmap(tilemap);

    destroy_bitmap(buffer);
    allegro_exit();
    return 0;
}
Пример #19
0
///////////////////////////////////////////////////////////////////
//
// Function Name:	paintNumDests()
// Description:		Paints the router with the number of its numDests
//
///////////////////////////////////////////////////////////////////
void Router::paintNumDests(int n) {
  int black = makecol(0, 0, 0);
  int number = 5;  // whatever
  double quotient;

  if (n <=
      0)  // in this case, total active wks are passed in as a negative number
  {
    if (n == 0)
      quotient = 100.0;
    else {
      quotient = 100.0 * double(numWorkstations) / double(-1 * n);
    }
    setRadius(quotient);
    number = routerIndex;
  } else if (n == 1)  // 1 Paints percentage of connection attempts which fail
                      // in reaching each router
  {
    if (connAttemptsToThis != 0)
      quotient =
          100 -
          (100.0 * ((double)connSuccessesToThis / (double)connAttemptsToThis));
    else
      quotient = 0;
    setRadius(quotient);
    number = quotient;
  } else if (n == 2) {
    if (connAttemptsFromThis != 0)
      quotient = 100 - (100.0 * ((double)connSuccessesFromThis /
                                 (double)connAttemptsFromThis));
    else
      quotient = 0;
    setRadius(quotient);
    number = quotient;
  } else if (n == 3) {
    quotient = 100.0 * double(numWorkstations) /
               double(threadZero->getCurrentActiveWorkstations());
    setRadius(quotient);
    number = numWorkstations;
  } else if (n == 4)  // 0 means paint indexes
  {
    quotient = 100.0 * double(numWorkstations) /
               double(threadZero->getCurrentActiveWorkstations());
    setRadius(quotient);
    number = routerIndex;
  }

  char bmpFile[40];
  sprintf(bmpFile, "bitmaps");

  switch (radius) {
    case 10:
      sprintf(bmpFile, "%s/router0_1", bmpFile);
      // routerpic = load_bitmap("bitmaps/router0_1plain.bmp",nullptr);
      break;
    case 11:
      sprintf(bmpFile, "%s/router0_5", bmpFile);
      // routerpic = load_bitmap("bitmaps/router0_5plain.bmp",nullptr);
      break;
    case 12:
      sprintf(bmpFile, "%s/router1_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router1_0plain.bmp",nullptr);
      break;
    case 13:
      sprintf(bmpFile, "%s/router5_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router5_0plain.bmp",nullptr);
      break;
    case 15:
      sprintf(bmpFile, "%s/router10_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router10_0plain.bmp",nullptr);
      break;
    case 17:
      sprintf(bmpFile, "%s/router20_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router20_0plain.bmp",nullptr);
      break;
    case 21:
      sprintf(bmpFile, "%s/router30_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router30_0plain.bmp",nullptr);
      break;
    case 25:
      sprintf(bmpFile, "%s/router40_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router40_0plain.bmp",nullptr);
      break;
    case 29:
      sprintf(bmpFile, "%s/router50_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router50_0plain.bmp",nullptr);
      break;
    case 33:
      sprintf(bmpFile, "%s/router60_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router60_0plain.bmp",nullptr);
      break;
    case 37:
      sprintf(bmpFile, "%s/router70_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router70_0plain.bmp",nullptr);
      break;
    case 41:
      sprintf(bmpFile, "%s/router80_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router80_0plain.bmp",nullptr);
      break;
    case 45:
      sprintf(bmpFile, "%s/router90_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router90_0plain.bmp",nullptr);
      break;
    case 50:
      sprintf(bmpFile, "%s/router100_0", bmpFile);
      // routerpic = load_bitmap("bitmaps/router100_0plain.bmp",nullptr);
      break;
  }
  if (isSelected) {
    sprintf(bmpFile, "%sselected.bmp", bmpFile);
    selectScreen();
  } else {
    sprintf(bmpFile, "%splain.bmp", bmpFile);
  }

  routerpic = load_bitmap(bmpFile, nullptr);

  masked_stretch_blit(routerpic, routersbmp, 0, 0, routerpic->w, routerpic->h,
                      xPixel - (radius), yPixel - (radius), radius * 2,
                      radius * 2);
  textprintf_centre_ex(routersbmp, font, xPixel, yPixel - 3, black, -1, "%d",
                       number);
}
Пример #20
0
/* Draw a column of pattern pat into the bitmap bmp inside the given rectangle.
 */
static inline void
blit_column (BITMAP *bmp, struct ABMAP *pat, int x, int y, int w, int h, enum COLUMN_TYPE f)
{
	int ct = bmp->ct, cb = bmp->cb;
	int oy;
	int j;
	int pat_h = pat->bmp->h - pat->bt - pat->bb;

	void (*bfunc) (BITMAP *, BITMAP *, int, int, int, int, int, int, int,
		int) = masked_non_stretched_blit;
	int bx = 0;
	int bw = pat->bmp->w;
	int x2 = x;
	int w2;

	if (pat->flags & ABMAP_ALIGN_V)
		oy = (y / pat_h) * pat_h - y;
	else
		oy = centered_offset (h, pat_h);

	if (pat_h < 1)
		return;

	if (f == COLUMN_MIDDLE)
		bx = pat->bl;
	if (f == COLUMN_RIGHT)
		bx = pat->bmp->w - pat->br;

	if (f == COLUMN_LEFT)
		bw = pat->bl;
	if (f == COLUMN_MIDDLE)
		bw = w;
	if (f == COLUMN_RIGHT)
		bw = pat->br;

	if (f == COLUMN_CENTER)
		x2 = x + w / 2 - pat->bmp->w / 2;
	if (f == COLUMN_RIGHT)
		x2 = x + w - pat->br;

	w2 = bw;

	if (f == COLUMN_STRETCH) {
		w2 = w;
		bfunc = masked_stretch_blit;
	}

	if (pat->flags & ABMAP_CENTER_V) {
		bfunc (pat->bmp, bmp, bx, 0, bw, pat->bmp->h, x2,
			y + h / 2 - pat->bmp->h / 2, w2, pat->bmp->h);
	}
	else if (pat->flags & ABMAP_STRETCH_V) {
		masked_stretch_blit (pat->bmp, bmp, bx, 0, bw, pat->bmp->h, x2, y, w2,
			h);
	} else {
		/* top */
		if (pat->bt) {
			bmp->ct = MAX (ct, y);
			bmp->cb = MIN (cb, MIN (y + h, y + pat->bt));
			bfunc (pat->bmp, bmp, bx, 0, bw, pat->bt, x2, y, w2, pat->bt);
		}
		/* middle */
		bmp->ct = MAX (ct, MIN (y + h, y + pat->bt));
		bmp->cb = MIN (cb, MAX (y, y + h - pat->bb));
		for (j = oy + y; j < y + h; j += pat->bmp->h - pat->bt - pat->bb) {
			bfunc (pat->bmp, bmp, bx, pat->bt, bw, pat_h, x2, j, w2, pat_h);
		}
		/* bottom */
		if (pat->bt) {
			bmp->ct = MAX (ct, MAX (y, y + h - pat->bb));
			bmp->cb = MIN (cb, y + h);
			bfunc (pat->bmp, bmp, bx, pat->bmp->h - pat->bb, bw, pat->bb, x2,
				y + h - pat->bb, w2, pat->bb);
		}
	}
	bmp->ct = ct;
	bmp->cb = cb;
}
Пример #21
0
void renderBoldString(const unsigned char* string, int x, int y, int maxWidth, bool fixedWidth, int color)
{
	int left = x;
	bool smallermode = false;

	// loop through each character in the string, find it, render it, advance
	for ( int i = 0; string[i] != 0; i++ )
	{
		int row = 0, col = 0; // default to a space
		int yoff = 0; // for lowercase letters and some punctuation

		// find the glyph on the sprite sheet
		unsigned char temp = string[i];
		if ( temp == 199 ) // alt-128 Ç
		{
			temp = 128; // heart
		}
		if ( temp >= 32 && temp <= 128 )
		{
			int ascii = temp - 32;
			row = (ascii/10) % 10;
			col = ascii % 10;
		}

		// some characters such as 'g' 'y' 'p' and 'q' hang below the line
		if ( string[i] == 'g' || string[i] == 'q' || string[i] == 'j' || string[i] == 'Q' )
		{
			yoff = +3;
		}
		if ( string[i] == 'y' || string[i] == 'p' )
		{
			yoff = +2;
		}

		if ( string[i] == '|' ) // a convention I saw used in the original DMX to note a subtitle
		{
			smallermode = !smallermode;
			continue;
		}

		// render it!
		if ( smallermode )
		{
			if ( yoff > 0 )
			{
				yoff -= 1;
			}
			masked_stretch_blit(rm.m_boldFont[color], rm.m_backbuf, 24*row, 24*col, 24, 24, x, y+yoff+6, 18, 18);
		}
		else
		{
			masked_blit(rm.m_boldFont[color], rm.m_backbuf, 24*row, 24*col, x, y+yoff, 24, 24);
		}

		// find the width of this glyph
		int width = 24;
		if ( !fixedWidth )
		{
			width = boldTextWidths[row*10 + col];
		}
		if ( smallermode )
		{
			width = (width * 3/4) + 1;
		}

		// if row is full then end early.
		x += width;
		if ( x-left >= maxWidth )
		{
			return;
		}
	}
}
Пример #22
0
void Level::draw(BITMAP *buffer, float zoom_factor, float screenX, float screenY, 
				 int offsetX, int offsetY) 
{
	// determine the rectangle of the level we are to draw
	int x1 = (int)(screenX + 0.5f);
	int y1 = (int)(screenY + 0.5f);
	int w = (int)(bmpField->w/zoom_factor + 0.5f);
	int h = (int)(bmpField->h/zoom_factor + 0.5f);
	
	// Variables used to store label positions
	int lx1, ly1, lw, lh;
	
	// Draw the main level bitmap
	masked_stretch_blit(bmpField, buffer, 
		x1, y1, w, h,
		offsetX, offsetY,
		bmpField->w, bmpField->h);

	// Draw the labels
	BITMAP *l2 = (BITMAP*)data[B_LABEL2]->dat;
	lx1 = (int)((label2x - screenX) * zoom_factor);
	ly1 = (int)((label2y - screenY) * zoom_factor);
	lw = (int)(l2->w * zoom_factor);
	lh = (int)(l2->h * zoom_factor);
	if(bb_col(0, 0, bmpField->w, bmpField->h, lx1, ly1, lx1+lw, ly1+lh)) {
		masked_stretch_blit(l2, buffer, 0, 0, l2->w, l2->h,
			lx1 + offsetX, ly1 + offsetY, lw, lh);
		
		//textprintf_ex(buffer, font, 250, 15, makecol(255,255,255), -1, "L2");
	}

	BITMAP *l5 = (BITMAP*)data[B_LABEL5]->dat;
	lx1 = (int)((label5x - screenX) * zoom_factor);
	ly1 = (int)((label5y - screenY) * zoom_factor);
	lw = (int)(l5->w * zoom_factor);
	lh = (int)(l5->h * zoom_factor);
	if(bb_col(0, 0, bmpField->w, bmpField->h, lx1, ly1, lx1+lw, ly1+lh)) {
		masked_stretch_blit(l5, buffer, 0, 0, l5->w, l5->h,
			lx1 + offsetX, ly1 + offsetY, lw, lh);
		
		//textprintf_ex(buffer, font, 270, 15, makecol(255,255,255), -1, "L5");
	}

	BITMAP *l10 = (BITMAP*)data[B_LABEL10]->dat;
	lx1 = (int)((label10x - screenX) * zoom_factor);
	ly1 = (int)((label10y - screenY) * zoom_factor);
	lw = (int)(l10->w * zoom_factor);
	lh = (int)(l10->h * zoom_factor);
	if(bb_col(0, 0, bmpField->w, bmpField->h, lx1, ly1, lx1+lw, ly1+lh)) {
		masked_stretch_blit(l10, buffer, 0, 0, l10->w, l10->h,
			lx1 + offsetX, ly1 + offsetY, lw, lh);

		//textprintf_ex(buffer, font, 290, 15, makecol(255,255,255), -1, "L10");
	}


	// Draw the brand
	BITMAP *br = (BITMAP*)data[B_BRAND]->dat;
	lx1 = (int)((brandx - screenX) * zoom_factor);
	ly1 = (int)((brandy - screenY) * zoom_factor);
	lw = (int)(br->w * zoom_factor);
	lh = (int)(br->h * zoom_factor);
	if(bb_col(0, 0, bmpField->w, bmpField->h, lx1, ly1, lx1+lw, ly1+lh)) {
		masked_stretch_blit(br, buffer, 0, 0, br->w, br->h,
			lx1 + offsetX, ly1 + offsetY, lw, lh);
		
		//textprintf_ex(buffer, font, 310, 15, makecol(255,255,255), -1, "BR");
	}
}
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;
    
}