Exemplo n.º 1
0
Options::~Options() {
    if (options)
        destroy_bitmap(options);
}
Exemplo n.º 2
0
/*****************************************************************************

    Function: edit_ram

    Description: view or edit the RAM
    Parameters: none
    Return: nothing

*****************************************************************************/
void
edit_ram ()
{

#ifdef ALLEGRO

  BITMAP *bg;
  unsigned char line, col;
  char *tmp_buf = (char *) alloca (100);
  unsigned short dum;

  bg = create_bitmap (vheight, vwidth);
  blit (screen, bg, 0, 0, 0, 0, vheight, vwidth);

  selected_byte = 0;
  out = 0;
  frame_up = 0;
  frame_down = frame_up + NB_LINE * NB_BYTE_LINE;

  while (!out)
    {
      clear (screen);
      for (line = 0; line < NB_LINE; line++)
	{
	  sprintf (tmp_buf, "%04X", frame_up + line * NB_BYTE_LINE);
	  textoutshadow (screen, font, tmp_buf, blit_x, blit_y + 10 * line,
			 -15, 2, 1, 1);
	  for (col = 0; col < NB_BYTE_LINE / 2; col++)
	    {
	      if ((dum = frame_up + line * NB_BYTE_LINE + col) ==
		  selected_byte)
		rectfill (screen, blit_x + (6 + col * 3) * 8,
			  blit_y + 10 * line - 1, blit_x + (8 + col * 3) * 8,
			  blit_y + 10 * (line + 1) - 2, -15);
	      sprintf (tmp_buf, "%02X", RAM[dum]);
	      textoutshadow (screen, font, tmp_buf,
			     blit_x + (6 + col * 3) * 8, blit_y + 10 * line,
			     -1, 2, 1, 1);
	    }
	  for (; col < NB_BYTE_LINE; col++)
	    {
	      if ((dum = frame_up + line * NB_BYTE_LINE + col) ==
		  selected_byte)
		rectfill (screen, blit_x + (8 + col * 3) * 8,
			  blit_y + 10 * line - 1, blit_x + (10 + col * 3) * 8,
			  blit_y + 10 * (line + 1) - 2, -15);
	      sprintf (tmp_buf, "%02X",
		       RAM[frame_up + line * NB_BYTE_LINE + col]);
	      textoutshadow (screen, font, tmp_buf,
			     blit_x + (8 + col * 3) * 8, blit_y + 10 * line,
			     -1, 2, 1, 1);
	    }

	}

      ram_key ();
      vsync ();
    }

  blit (bg, screen, 0, 0, 0, 0, vheight, vwidth);
  destroy_bitmap (bg);
  return;

#endif

}
Exemplo n.º 3
0
void mexFunction(int nout, mxArray *pout[], int nin, const mxArray *pin[]) {
  FILE *f = fopen("log.txt", "wt");
  fclose(f);

  if (nin < 2) { mexErrMsgTxt("nnmex called with < 2 input arguments"); }

  const mxArray *A = pin[0], *B = pin[1];
  const mxArray *ANN_PREV = NULL, *ANN_WINDOW = NULL, *AWINSIZE = NULL;
  int aw = -1, ah = -1, bw = -1, bh = -1;
  BITMAP *a = NULL, *b = NULL, *ann_prev = NULL, *ann_window = NULL, *awinsize = NULL;
  VECBITMAP<unsigned char> *ab = NULL, *bb = NULL;
  VECBITMAP<float> *af = NULL, *bf = NULL;

  if (mxGetNumberOfDimensions(A) != 3 || mxGetNumberOfDimensions(B) != 3) { mexErrMsgTxt("dims != 3"); }
  if (mxGetDimensions(A)[2] != mxGetDimensions(B)[2]) { mexErrMsgTxt("3rd dimension not same size"); }

  int mode = MODE_IMAGE;
  if (mxGetDimensions(A)[2] != 3) { // a discriptor rather than rgb
    if (mxIsUint8(A) && mxIsUint8(B)) { mode = MODE_VECB; } 
    else if (is_float(A) && is_float(B)) { mode = MODE_VECF; } 
    else { mexErrMsgTxt("input not uint8, single, or double"); }
  }

  Params *p = new Params();
  RecomposeParams *rp = new RecomposeParams();
  BITMAP *borig = NULL;
  if (mode == MODE_IMAGE) {
    a = convert_bitmap(A);
    b = convert_bitmap(B);
	borig = b;
    aw = a->w; ah = a->h;
    bw = b->w; bh = b->h;
  } 
  else if (mode == MODE_VECB) {
    ab = convert_vecbitmap<unsigned char>(A);
    bb = convert_vecbitmap<unsigned char>(B);
    if (ab->n != bb->n) { mexErrMsgTxt("3rd dimension differs"); }
    aw = ab->w; ah = ab->h;
    bw = bb->w; bh = bb->h;
    p->vec_len = ab->n;
  } 
  else if (mode == MODE_VECF) {
    af = convert_vecbitmap<float>(A);
    bf = convert_vecbitmap<float>(B);
    if (af->n != bf->n) { mexErrMsgTxt("3rd dimension differs"); }
    aw = af->w; ah = af->h;
    bw = bf->w; bh = bf->h;
    p->vec_len = af->n;
  }

  double *win_size = NULL;
  BITMAP *amask = NULL, *bmask = NULL;

  double scalemin = 0.5, scalemax = 2.0;  // The product of these must be one.
  /* parse parameters */
  int i = 2;
  int sim_mode = 0;
  int knn_chosen = -1;
  p->algo = ALGO_CPU;
  int enrich_mode = 0;
  if (nin > i && !mxIsEmpty(pin[i])) {
    if (mxStringEquals(pin[i], "cpu")) { p->algo = ALGO_CPU; }
    else if (mxStringEquals(pin[i], "gpucpu")) { p->algo = ALGO_GPUCPU; }
    else if (mxStringEquals(pin[i], "cputiled")) { p->algo = ALGO_CPUTILED; }
    else if (mxStringEquals(pin[i], "rotscale")) { sim_mode = 1; }
    else if (mxStringEquals(pin[i], "enrich")) { p->algo = ALGO_CPUTILED; enrich_mode = 1; }
    else { mexErrMsgTxt("Unknown algorithm"); }
  } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->patch_w = int(mxGetScalar(pin[i])); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->nn_iters = int(mxGetScalar(pin[i])); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->rs_max = int(mxGetScalar(pin[i])); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->rs_min = int(mxGetScalar(pin[i])); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->rs_ratio = mxGetScalar(pin[i]); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->rs_iters = mxGetScalar(pin[i]); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->cores = int(mxGetScalar(pin[i])); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { bmask = convert_bitmap(pin[i]); } i++; // XC+
  if (nin > i && !mxIsEmpty(pin[i])) { 
    if (!mxIsDouble(pin[i])) { mexErrMsgTxt("\nwin_size should be of type double."); }
    win_size = (double*)mxGetData(pin[i]);
    if (mxGetNumberOfElements(pin[i])==1) { p->window_h = p->window_w = int(win_size[0]); }
    else if (mxGetNumberOfElements(pin[i])==2) { p->window_h = int(win_size[0]); p->window_w = int(win_size[1]); }
    else { mexErrMsgTxt("\nwin_size should be a scalar for square window or [h w] for a rectangular one."); }
  } i++;
  /* continue parsing parameters */
  // [ann_prev=NULL], [ann_window=NULL], [awinsize=NULL], 
  if (nin > i && !mxIsEmpty(pin[i])) { 
    ANN_PREV = pin[i];
    int clip_count = 0;
    ann_prev = convert_field(p, ANN_PREV, bw, bh, clip_count);       // Bug fixed by Connelly
  } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { 
    ANN_WINDOW = pin[i];
    int clip_count = 0;
    ann_window = convert_field(p, ANN_WINDOW, bw, bh, clip_count);      
  } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { 
    AWINSIZE = pin[i];
    awinsize = convert_winsize_field(p, AWINSIZE, aw, ah);  
    if (p->window_w==INT_MAX||p->window_h==INT_MAX) { p->window_w = -1; p->window_h = -1; }
  } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { 
    knn_chosen = int(mxGetScalar(pin[i]));
    if (knn_chosen == 1) { knn_chosen = -1; }
    if (knn_chosen <= 0) { mexErrMsgTxt("\nknn is less than zero"); }
  } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { 
    scalemax = mxGetScalar(pin[i]);
    if (scalemax <= 0) { mexErrMsgTxt("\nscalerange is less than zero"); }
    scalemin = 1.0/scalemax;
    if (scalemax < scalemin) {
      double temp = scalemax;
      scalemax = scalemin;
      scalemin = temp;
    }
  } i++;

  if (ann_window&&!awinsize&&!win_size) {
    mexErrMsgTxt("\nUsing ann_window - either awinsize or win_size should be defined.\n");
  }

  if (enrich_mode) {
	int nn_iters = p->nn_iters;
    p->enrich_iters = nn_iters/2;
	p->nn_iters = 2;
	if (A != B) { mexErrMsgTxt("\nOur implementation of enrichment requires that image A = image B.\n"); }
	if (mode == MODE_IMAGE) {
	  b = a;
	} else {
	  mexErrMsgTxt("\nEnrichment only implemented for 3 channel uint8 inputs.\n");
	}
  }

  init_params(p);
  if (sim_mode) {
    init_xform_tables(scalemin, scalemax, 1);
  }
  
  RegionMasks *amaskm = amask ? new RegionMasks(p, amask): NULL;

  BITMAP *ann = NULL; // NN field
  BITMAP *annd_final = NULL; // NN patch distance field
  BITMAP *ann_sim_final = NULL;

  VBMP *vann_sim = NULL;
  VBMP *vann = NULL;
  VBMP *vannd = NULL;

  if (mode == MODE_IMAGE) {
    // input as RGB image
    if (!a || !b) { mexErrMsgTxt("internal error: no a or b image"); }
    if (knn_chosen > 1) {
      p->knn = knn_chosen;
      if (sim_mode) { mexErrMsgTxt("rotating+scaling patches not implemented with knn (actually it is implemented it is not exposed by the wrapper)"); }
      PRINCIPAL_ANGLE *pa = NULL;
      vann_sim = NULL;
      vann = knn_init_nn(p, a, b, vann_sim, pa);
      vannd = knn_init_dist(p, a, b, vann, vann_sim);
      knn(p, a, b, vann, vann_sim, vannd, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, pa);
//      sort_knn(p, vann, vann_sim, vannd);
    } else if (sim_mode) {
      BITMAP *ann_sim = NULL;
      ann = sim_init_nn(p, a, b, ann_sim);
      BITMAP *annd = sim_init_dist(p, a, b, ann, ann_sim);
      sim_nn(p, a, b, ann, ann_sim, annd);
      if (ann_prev) { mexErrMsgTxt("when searching over rotations+scales, previous guess is not supported"); }
      annd_final = annd;
      ann_sim_final = ann_sim;
    } else {
      ann = init_nn(p, a, b, bmask, NULL, amaskm, 1, ann_window, awinsize);
      BITMAP *annd = init_dist(p, a, b, ann, bmask, NULL, amaskm);
      nn(p, a, b, ann, annd, amaskm, bmask, 0, 0, rp, 0, 0, 0, NULL, p->cores, ann_window, awinsize); 
      if (ann_prev) minnn(p, a, b, ann, annd, ann_prev, bmask, 0, 0, rp, NULL, amaskm, p->cores);  
      annd_final = annd;
    }
  } 
/*
  else if (mode == MODE_VECB) {
//    mexPrintf("mode vecb %dx%dx%d, %dx%dx%d\n", ab->w, ab->h, ab->n, bb->w, bb->h, bb->n);
//    mexPrintf("  %d %d %d %d\n", ab->get(0,0)[0], ab->get(1,0)[0], ab->get(0,1)[0], ab->get(0,0)[1]);
    if (!ab || !bb) { mexErrMsgTxt("internal error: no a or b image"); }
    ann = vec_init_nn<unsigned char>(p, ab, bb, bmask, NULL, amaskm);
    VECBITMAP<int> *annd = vec_init_dist<unsigned char, int>(p, ab, bb, ann, bmask, NULL, amaskm);
//    mexPrintf("  %d %d %d %p %p\n", annd->get(0,0)[0], annd->get(1,0)[0], annd->get(0,1)[0], amaskm, bmask);
    vec_nn<unsigned char, int>(p, ab, bb, ann, annd, amaskm, bmask, 0, 0, rp, 0, 0, 0, NULL, p->cores); 
    if (ann_prev) vec_minnn<unsigned char, int>(p, ab, bb, ann, annd, ann_prev, bmask, 0, 0, rp, NULL, amaskm, p->cores);  
    annd_final = vecbitmap_to_bitmap(annd);
    delete annd;
  } 
  else if (mode == MODE_VECF) {
//    mexPrintf("mode vecf %dx%dx%d, %dx%dx%d\n", af->w, af->h, af->n, bf->w, bf->h, bf->n);
//    mexPrintf("  %f %f %f %f\n", af->get(0,0)[0], af->get(1,0)[0], af->get(0,1)[0], af->get(0,0)[1]);
    if (!af || !bf) { mexErrMsgTxt("internal error: no a or b image"); }
    ann = vec_init_nn<float>(p, af, bf, bmask, NULL, amaskm);
    VECBITMAP<float> *annd = vec_init_dist<float, float>(p, af, bf, ann, bmask, NULL, amaskm);
    vec_nn<float, float>(p, af, bf, ann, annd, amaskm, bmask, 0, 0, rp, 0, 0, 0, NULL, p->cores); 
    if (ann_prev) vec_minnn<float, float>(p, af, bf, ann, annd, ann_prev, bmask, 0, 0, rp, NULL, amaskm, p->cores);  
    annd_final = create_bitmap(annd->w, annd->h);
    clear(annd_final);
    delete annd;
  }
*/
  else if(mode == MODE_VECB) {
    if (sim_mode) { mexErrMsgTxt("internal error: rotation+scales not implemented with descriptor mode"); }
    if (knn_chosen > 1) { mexErrMsgTxt("internal error: kNN not implemented with descriptor mode"); }
//    mexPrintf("mode vecb_xc %dx%dx%d, %dx%dx%d\n", ab->w, ab->h, ab->n, bb->w, bb->h, bb->n);
    // input as uint8 discriptors per pixel
    if (!ab || !bb) { mexErrMsgTxt("internal error: no a or b image"); }
    ann = XCvec_init_nn<unsigned char>(p, ab, bb, bmask, NULL, amaskm);
    VECBITMAP<int> *annd = XCvec_init_dist<unsigned char, int>(p, ab, bb, ann, bmask, NULL, amaskm);
    XCvec_nn<unsigned char, int>(p, ab, bb, ann, annd, amaskm, bmask, 0, 0, rp, 0, 0, 0, NULL, p->cores); 
    if (ann_prev) XCvec_minnn<unsigned char, int>(p, ab, bb, ann, annd, ann_prev, bmask, 0, 0, rp, NULL, amaskm, p->cores);  
    annd_final = vecbitmap_to_bitmap(annd);
    delete annd;
  } else if(mode == MODE_VECF) {
    if (sim_mode) { mexErrMsgTxt("internal error: rotation+scales not implemented with descriptor mode"); }
    if (knn_chosen > 1) { mexErrMsgTxt("internal error: kNN not implemented with descriptor mode"); }
    // input as float/double discriptors per pixel
    if (!af || !bf) { mexErrMsgTxt("internal error: no a or b image"); }
    ann = XCvec_init_nn<float>(p, af, bf, bmask, NULL, amaskm);
    VECBITMAP<float> *annd = XCvec_init_dist<float, float>(p, af, bf, ann, bmask, NULL, amaskm);
    XCvec_nn<float, float>(p, af, bf, ann, annd, amaskm, bmask, 0, 0, rp, 0, 0, 0, NULL, p->cores); 
    if (ann_prev) XCvec_minnn<float, float>(p, af, bf, ann, annd, ann_prev, bmask, 0, 0, rp, NULL, amaskm, p->cores);  
    annd_final = create_bitmap(annd->w, annd->h);
    clear(annd_final);
    delete annd;	
  }

  destroy_region_masks(amaskm);

  // output ann: x | y | patch_distance
  if(nout >= 1) {
    mxArray *ans = NULL;
    if (knn_chosen > 1) {
      if (sim_mode) { mexErrMsgTxt("rotating+scaling patches return value not implemented with knn"); }
      mwSize dims[4] = { ah, aw, 3, knn_chosen };
      ans = mxCreateNumericArray(4, dims, mxINT32_CLASS, mxREAL);
      int *data = (int *) mxGetData(ans);
      for (int kval = 0; kval < knn_chosen; kval++) {
        int *xchan = &data[aw*ah*3*kval+0];
        int *ychan = &data[aw*ah*3*kval+aw*ah];
        int *dchan = &data[aw*ah*3*kval+2*aw*ah];
        for (int y = 0; y < ah; y++) {
//          int *ann_row = (int *) ann->line[y];
//          int *annd_row = (int *) annd_final->line[y];
          for (int x = 0; x < aw; x++) {
//            int pp = ann_row[x];
            int pp = vann->get(x, y)[kval];
            int pos = y + x * ah;
            xchan[pos] = INT_TO_X(pp);
            ychan[pos] = INT_TO_Y(pp);
            dchan[pos] = vannd->get(x, y)[kval];
          }
        }
      }
    } else if (ann_sim_final) {
      mwSize dims[3] = { ah, aw, 5 };
      ans = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL);
      float *data = (float *) mxGetData(ans);
      float *xchan = &data[0];
      float *ychan = &data[aw*ah];
      float *dchan = &data[2*aw*ah];
      float *tchan = &data[3*aw*ah];
      float *schan = &data[4*aw*ah];
      double angle_scale = 2.0*M_PI/NUM_ANGLES;
      for (int y = 0; y < ah; y++) {
        int *ann_row = (int *) ann->line[y];
        int *annd_row = (int *) annd_final->line[y];
        int *ann_sim_row = ann_sim_final ? (int *) ann_sim_final->line[y]: NULL;
        for (int x = 0; x < aw; x++) {
          int pp = ann_row[x];
          int pos = y + x * ah;
          xchan[pos] = INT_TO_X(pp);
          ychan[pos] = INT_TO_Y(pp);
          dchan[pos] = annd_row[x];
          if (ann_sim_final) {
            int v = ann_sim_row[x];
            int tval = INT_TO_Y(v)&(NUM_ANGLES-1);
            int sval = INT_TO_X(v);

            tchan[pos] = tval*angle_scale;
            schan[pos] = xform_scale_table[sval]*(1.0/65536.0);
          }
        }
      }
    } else {
      mwSize dims[3] = { ah, aw, 3 };
      ans = mxCreateNumericArray(3, dims, mxINT32_CLASS, mxREAL);
      int *data = (int *) mxGetData(ans);
      int *xchan = &data[0];
      int *ychan = &data[aw*ah];
      int *dchan = &data[2*aw*ah];
      for (int y = 0; y < ah; y++) {
        int *ann_row = (int *) ann->line[y];
        int *annd_row = (int *) annd_final->line[y];
        for (int x = 0; x < aw; x++) {
          int pp = ann_row[x];
          int pos = y + x * ah;
          xchan[pos] = INT_TO_X(pp);
          ychan[pos] = INT_TO_Y(pp);
          dchan[pos] = annd_row[x];
        }
      }
    }
    pout[0] = ans;
  }

  // clean up
  delete vann;
  delete vann_sim;
  delete vannd;
  delete p;
  delete rp;
  destroy_bitmap(a);
  destroy_bitmap(borig);
  delete ab;
  delete bb;
  delete af;
  delete bf;
  destroy_bitmap(ann);
  destroy_bitmap(annd_final);
  destroy_bitmap(ann_sim_final);
  if (ann_prev) destroy_bitmap(ann_prev);
  if (ann_window) destroy_bitmap(ann_window);
  if (awinsize) destroy_bitmap(awinsize);
}
Exemplo n.º 4
0
Snapshot::~Snapshot() {
  destroy_bitmap(canvas);

}
Exemplo n.º 5
0
void main(void) {
    
    int xy,i,j,c,x,y,front,back,n,minc,maxc;
    int ix,iy,k,address,jx,jy,kx,ky;
    float dzdx,dzdy,a,b,dot,norm;
    float rx,ry,sx,sy,px,py;
    long p,q;
    RGB rgb;

    for (x=0;x<scrwid;x++) {
    for (y=0;y<scrhei;y++) {
        rx=(float)x/scrwid*2-1;
        ry=(float)y/scrhei*2-1;
        sx=rx*.8;
        sy=ry*.8;
        px=(sx+1)/2*scrwid;
        py=(sy+1)/2*scrhei;
        ix=(int)px;
        iy=(int)py;
        amount[x][y][0][0]=((float)ix+1-(float)px)*((float)(iy+1)-(float)py);
        amount[x][y][1][0]=((float)px-(float)ix)*((float)(iy+1)-(float)py);
        amount[x][y][0][1]=((float)ix+1-(float)px)*((float)py-(float)iy);
        amount[x][y][1][1]=((float)px-(float)ix)*((float)py-(float)iy);
        pix[x][y]=ix;
        piy[x][y]=iy;
//        printf("%f",amount[x][y][0][0]+amount[x][y][1][0]+amount[x][y][0][1]+amount[x][y][1][1]);
        if (mysquare(amount[x][y][0][0]+amount[x][y][1][0]+amount[x][y][0][1]+amount[x][y][1][1]-1)>0.00001) {
            printf("%d %d %f %f ",ix,iy,px,py);
            printf("%f+%f(%f*%f)+%f+%f=%f? \n",amount[x][y][0][0],amount[x][y][1][0],(float)px-(float)ix,(float)(iy+1)-(float)py,amount[x][y][0][1],amount[x][y][1][1],amount[x][y][0][0]+amount[x][y][1][0]+amount[x][y][0][1]+amount[x][y][1][1]);
        }
    }
    }

//    srand(456789);
        srand((int)time(NULL));
        //printf("%d\n",(int)time(NULL));


  allegro_init ();
  install_keyboard ();
  install_timer ();
  set_gfx_mode (GFX_AUTODETECT, scrwid, scrhei, 0, 0);
  set_pallete (desktop_palette);
  buffer = create_bitmap (scrwid, scrhei);
      clear (buffer);

//      textout_centre (buffer, font, "Press SPACE!", 60, 220, 4);


    // Set up grayscale colours
    for (c=0;c<=255;c++) {
        i=0;
        rgb.r=c*63/255;
        rgb.g=0;
        rgb.b=0;
        set_color(c,&rgb);
//        colors[c]=GrAllocColor(c,i,i);
    }
    
        for (x=0; x<scrwid; x++) {
        for (y=0; y<scrhei; y++) {
            putpixel(buffer,x,y,128);
        }
        }

      blit (buffer, screen, 0, 0, 0, 0, scrwid, scrhei);

   _farsetsel(screen->seg);

    while(!key[KEY_ESC]) {
        for (y=0; y<scrhei; y++) {
     movedata(screen->seg, bmp_read_line(screen,y), _my_ds(), tmp[y], scrwid);
     }
        for (x=0; x<scrwid; x++) {
        for (y=0; y<scrhei; y++) {
        c=0;
        kx=x-scrwid/2;
        ky=y-scrhei/2;
        jx=kx*cos(ang)+ky*sin(ang);
        jy=-kx*sin(ang)+ky*cos(ang);
        ix=scrwid/2+0.9*jx;
        iy=scrhei/2+0.9*jy;
        k=0;
        i=0;j=0;
//        for (i=-1;i<=1;i++) {
//        for (j=-1;j<=1;j++) {
//            c=c+getpixel(screen, ix+i, iy+j);
//     address = bmp_read_line(screen, iy)+ix;
            c=c+tmp[iy][ix];
            k++;
//        }
//        }
        c=c/k;
        c--;
//     address = bmp_write_line(buffer, y)+x;
//        _farnspokeb(address, c);
        tmp2[y][x]=c;
//        putpixel(buffer, x, y, c);
        }
        }
        for (y=0; y<scrhei; y++) {
     movedata(_my_ds(), tmp2[y], screen->seg, bmp_write_line(screen,y), scrwid);
     }
for (i=1;i<=10;i++)
        circlefill(screen,myrnd()*scrwid,myrnd()*scrhei,8,myrnd()*255);
//        putpixel(buffer,scrwid/2,scrhei/2,255);

//      blit (buffer, screen, 0, 0, 0, 0, scrwid, scrhei);
    }

destroy_bitmap(buffer);
exit(0);
    getch();

//    GrSetMode(GR_default_text);
    printf("max col %d\n",maxc);
    printf("min col %d\n",minc);
  
}
Exemplo n.º 6
0
void
unload_kid_sword_walkb (void)
{
  destroy_bitmap (kid_sword_walkb_00);
  destroy_bitmap (kid_sword_walkb_01);
}
Exemplo n.º 7
0
TileType::~TileType()
{
	destroy_bitmap(bitmap);
	free(name);
}
Exemplo n.º 8
0
void main(int argc, char **argv) {
  int i, done = 0;

  pl_MaterialType mat[NUM_ITERS]; // Materials
  pl_ObjectType *obj;             // Head object
  pl_LightType *light;
  pl_CameraType *cam;

  int vWidth = 320, vHeight = 200; // For allegro
  pl_FloatType ar;          // Aspect ratio
  char cpal[768];
  PALETTE pal; // Allegro palette

  if (argc > 1) sscanf(argv[1],"%dx%d",&vWidth,&vHeight);

  printf("Flurry v1.0\n"
         "Copyright (c) 1996, Justin Frankel\n");
  printf("Using:\n"
         "  %s\n",plVersionString);

  allegro_init();
  if (set_gfx_mode(GFX_AUTODETECT,vWidth,vHeight,0,0)) {
    allegro_exit();
    printf("Mode not supported\n");
    exit(1);
  }
  DIB = create_bitmap(vWidth,vHeight);
  ar = (vWidth/(pl_FloatType) vHeight) * (3.0/4.0); // Calc aspect ratio

  cam = plNewCamera(vWidth,vHeight,ar,90.0,0,DIB->dat,0);
  cam->Sort = 1;
  cam->Zp = -350;

  // Initialize materials
  memset(&mat,0,sizeof(pl_MaterialType)*NUM_ITERS);
  for (i = 0; i < NUM_ITERS; i ++) {
    mat[i].NumGradients = 200;
    mat[i].Transparent = 2;
    mat[i].AmbientLight = 20;
    mat[i].Shininess = 3;
    mat[i].ShadeType = PL_SHADE_GOURAUD;
    mat[i].Priority = i;
  }
  mat[0].Red = 190; mat[0].Green = 190;  mat[0].Blue = 0;
  mat[0].RedSpec = 240; mat[0].GreenSpec = 240; mat[0].BlueSpec = 0;
  mat[1].Red = 0; mat[1].Green = 0;  mat[1].Blue = 100;
  mat[1].RedSpec = 0; mat[1].GreenSpec = 0; mat[1].BlueSpec = 100;
  mat[2].Red = 0; mat[2].Green = 130;  mat[2].Blue = 0;
  mat[2].RedSpec = 0; mat[2].GreenSpec = 130; mat[2].BlueSpec = 0;
  mat[3].Red = 100; mat[3].Green = 0;  mat[3].Blue = 0;
  mat[3].RedSpec = 100; mat[3].GreenSpec = 0; mat[3].BlueSpec = 0;

  memset(cpal,0,768);
  plPMBegin(cpal,1,255);
  for (i = 0; i < NUM_ITERS; i ++) plPMAddMaterial(mat + i);
  plPMEnd();
  cpal[0] = cpal[1] = cpal[2] = 0;
  for (i = 0; i < 256; i ++) {
    pal[i].r = cpal[i*3] >> 2;
    pal[i].g = cpal[i*3+1] >> 2;
    pal[i].b = cpal[i*3+2] >> 2;
  }
  set_palette(pal); // Set the new palette via allegro

  // Make objects
  obj = plMakeBox(100,100,100,mat);
  makeBoxes(obj,100.0,mat+1,NUM_ITERS-1);

  // Setup light
  light = plNewLight();
  plSetLight(light,PL_LIGHT_VECTOR,0,0,0,1.0);

  while (!done) {
    rotateBoxes(obj,1.0);
    clear(DIB); // clear framebuffer & zbuffer
    plRenderBegin(cam);
    plRenderLight(light);
    plRenderObject(obj);
    plRenderEnd();
    vsync();         // Allegro wait for vsync
    blit(DIB,screen,0,0,0,0,cam->ScreenWidth,cam->ScreenHeight);
    while (kbhit()) switch(getch()) {
      case 27: done = 1; break;
      case '-': cam->Fov += 1.0; if (cam->Fov > 170) cam->Fov = 170; break;
      case '=': cam->Fov -= 1.0; if (cam->Fov < 10) cam->Fov = 10; break;
    }
  }
  destroy_bitmap(DIB);
  plFreeObject(obj);
  plFreeLight(light);
  plFreeCamera(cam);
  set_gfx_mode(GFX_TEXT,0,0,0,0);
  allegro_exit();
  printf("Try \"flurry 640x480\"\n");
}
Exemplo n.º 9
0
int main(void)
{

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

	//int cursorx=0,cursory=0;

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

	//byte terrancont=0,solidcont=0;

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

	int nlevel;

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

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


	T_Map mappa;


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

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

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

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

	nlevel=mappa.RetNLevel();

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

	GameInit();

	textures=create_bitmap(128,128);

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

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


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

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

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

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

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

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

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


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

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

	//show_mouse(buffer);

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

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

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

	while(!key[KEY_ESC]){

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

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

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

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

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

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

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

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

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

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

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

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

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

			}

			moved=true;
		}

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

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

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

			fp=fopen(nomefile,"wb");

			//mappa.SaveLevel(fp);

			fclose(fp);
		}

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

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

			moved=true;
		}

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

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

		}

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

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

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

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

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

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

			}
		}

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


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

				// Rettangoli dello schema

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

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

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

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

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

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

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

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

			moved=false;
		}

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

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

		/// Distruzione Bitmap

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

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

	readkey();
	GameExit();

	printf("Programmed with DJGPP RHIDE Allegro");

	puts(errmess);

	getch();


	return 0;

}
Exemplo n.º 10
0
int main() {
	
	BITMAP *mysha = NULL, *buffer = NULL;
	PARTICLE *particle[NUM_PARTICLES];
	int old_time = 0, old_time2 = 0;
	int i;
	int count = 0;
	int use_alleg = FALSE;
	int depth = 16;
	
	allegro_init();
	
	install_keyboard();
	install_timer();
	
	set_config_file("examples.cfg");
	depth = get_config_int("examples", "depth", 16);

	set_color_depth(depth);	
	if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
		set_color_depth(16);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
			set_color_depth(15);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
				set_color_depth(32);
				if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
					allegro_message("Unable to set 640x480 screen mode!\n");
					return -1;
				}
			}
		}
	}
	
	mysha = load_bitmap("mysha.pcx", NULL);
	
	if (!mysha) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to load mysha.pcx. Copy it from the allegro examples directory.\n");
		return -2;
	}
	
	TRACE("Got here!\n");
	
	for (i = 0; i < NUM_PARTICLES; i++)
		particle[i] = NULL;
		
	TRACE("Still here!\n");
	
	for (i = 0; i < NUM_PARTICLES; i++) {
		int j;
		int r, g, b;
		
		TRACE("Going for particle: %i\n", i);
	
		particle[i] = malloc(sizeof(PARTICLE));		
		if (!particle[i]) {
			TRACE("Out of memory while creating particle!\n");
			goto Error;
		}
		
		TRACE("Clearing particle\n");
		
		memset(particle[i], 0, sizeof(PARTICLE));
		
		TRACE("Creating bitmap\n");
		
		particle[i]->bmp = create_bitmap(64, 64);		
		if (!particle[i]->bmp) {
			TRACE("Out of memory while creating particle bitmap!\n");
			goto Error;
		}
		
		TRACE("Clearing bitmap\n");
			
		clear(particle[i]->bmp);
			
		TRACE("Setting up coordinates\n");
			
		particle[i]->x = rand() % SCREEN_W;
		particle[i]->y = rand() % SCREEN_H;
		particle[i]->vx = rand() % 10 - 5;
		particle[i]->vy = rand() % 10 - 5;
		particle[i]->a = rand() & 255;
		particle[i]->a_dir = 1;
		
		TRACE("Setting up colors\n");
		hsv_to_rgb(rand() % 360, 1, 1, &r, &g, &b);
		
		TRACE("Drawing circles\n");
		
		for (j = 1; j < 31; j++) {
			circle(particle[i]->bmp, 31, 32, j, makecol(r*2/(j+1), g*2/(j+1), b*2/(j+1)));
			circle(particle[i]->bmp, 32, 32, j, makecol(r*2/(j+1), g*2/(j+1), b*2/(j+1)));
		}
	}
	
	LOCK_FUNCTION(the_timer);
	LOCK_VARIABLE(chrono);
		
	buffer = create_bitmap(SCREEN_W, SCREEN_H);
	
	if (!buffer) {
		TRACE("Out of memory while creating back buffer!\n");
		goto Error;
	}
	
	clear(buffer);

	TRACE("Starting...\n");
	
	install_int(the_timer, 1);
	old_time = chrono;
	
	text_mode(0);
	
	do {
		int chrono2;
	
		/* Tile mysha over the screen */
		#ifndef COMPARE_WITH_ALLEGRO
		blit(mysha, buffer, 0, 0, 0, 0, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 320, 0, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 0, 200, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 320, 200, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 0, 400, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 320, 400, mysha->w, mysha->h);
		#endif
		
		if (use_alleg) {		
			for (i = 0; i < NUM_PARTICLES; i++) {
				set_difference_blender(0, 0, 0, particle[i]->a);
				draw_trans_sprite(buffer, particle[i]->bmp, particle[i]->x - particle[i]->bmp->w/2, particle[i]->y - particle[i]->bmp->h/2);
			}
		}
		else {
			for (i = 0; i < NUM_PARTICLES; i++)
				fblend_sub(particle[i]->bmp, buffer, particle[i]->x - particle[i]->bmp->w/2, particle[i]->y - particle[i]->bmp->h/2, particle[i]->a);
		}
		
		if (key[KEY_SPACE]) {
			use_alleg = !use_alleg;
			key[KEY_SPACE] = 0;
			chrono = 0;
			count = 0;
			old_time = 0;
			old_time2 = 0;
		}
		count++;			

		#ifdef COMPARE_WITH_ALLEGRO			
		textprintf(screen, font, 0, 0, makecol(255, 255, 255), "%s  %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using new", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono);
		#else
		textprintf(buffer, font, 0, 0, makecol(255, 255, 255), "%s  %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using new", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono);
		#endif
							
		old_time2 = chrono;
	
		
		#ifndef COMPARE_WITH_ALLEGRO
		
		/* Draw the buffer */
		blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		
		#endif

		chrono2 = chrono / 40;		
		for (i = old_time/40; i < chrono2; i++) {
			int j;
			for (j = 0; j < NUM_PARTICLES; j++) {
				particle[j]->x += particle[j]->vx;
				particle[j]->y += particle[j]->vy;
				
				if (particle[j]->x <= 0 || particle[j]->x >= SCREEN_W)
					particle[j]->vx = -particle[j]->vx;
				if (particle[j]->y <= 0 || particle[j]->y >= SCREEN_H)
					particle[j]->vy = -particle[j]->vy;
		
				if (particle[j]->a <= 0 || particle[j]->a >= 256)
					particle[j]->a_dir = -particle[j]->a_dir;
					
				particle[j]->a += particle[j]->a_dir;
			}
		}
		old_time = chrono;
		
	} while (!key[KEY_ESC]);
	
	Error:
	
	TRACE("Shutting down.\n");
	
	if (mysha)
		destroy_bitmap(mysha);
	if (buffer)
		destroy_bitmap(buffer);
	
	for (i = 0; i < NUM_PARTICLES; i++) {
		if (particle[i]) {
			if (particle[i]->bmp)
				destroy_bitmap(particle[i]->bmp);
			free(particle[i]);
		}
	}

	set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	
	return 0;	
	
} END_OF_MAIN();
Exemplo n.º 11
0
void main()
{
    allegro_init();
    install_keyboard();
    install_mouse();
    install_timer();
    set_color_depth(32);
    set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);
    srand(time(NULL)+clock());
    text_mode(-1);

    buffer = create_bitmap(WIDTH, HEIGHT);

    textprintf_centre(screen, font, 320, 200, WHITE, "-Endless Tower-");

    textprintf_centre(screen, font, 320, 240, WHITE, "press enter to start");

    while (!key[KEY_ENTER])
    {}

    for(int i = 0; i < 13; i++)
    {
        land[i].y = rand() % HEIGHT;
        land[i].x = ((rand()%300)*2) + 20;
        land[i].w = (rand()%20) + 20;
    }
    land[13].y = y + 10;
    land[13].x = x;
    land[13].w = 45;

    rest(50);

    while (!key[KEY_ESC])
    {
        start_time = clock();

        /*game goes here*/
        //move left
        if (key[KEY_LEFT])
                x -= 10;

        //move right
        if (key[KEY_RIGHT])
                x += 10;

        //jump
        if ((!jump)&&(key[KEY_SPACE]))
        {
                jump = true;
                jumpforce = 60;
        }

        if ((jump)&&(key[KEY_SPACE]))
        {
                jumpforce += 1;
        }

        //speed up!
        speed = 3 + (game_time/20000);

        //fall
        if (jump)
        {
                jumpforce -= 3;
        }
        if (!jump)
                jumpforce = -12;
        y -= jumpforce/4;

        //drop platforms down
        add_platform();
        for (int i = 0; i < 14; i++)
        {
                land[i].y += speed;
        }

        //collision
        on_land = 0;
        for (int i = 0; i < 14; i++)
        {
                if ((y > land[i].y - 20)&&(y < land[i].y))
                {
                                if ((x < land[i].x + land[i].w)&&(x > land[i].x - land[i].w))
                                {
                                        if (jumpforce < 5)
                                        {
                                                jump = false;
                                        }
                                        jumpforce = -speed*3;
                                        on_land += 1;
                                }
                }
        }
        if (on_land == 0)
                jump = true;
        //warp
        if (x < 0)
            x = 0;
        if (x > WIDTH)
            x = WIDTH;

        //die
        if (y > HEIGHT)
            return;

        /*drawing goes here*/
        rectfill(buffer, 0, 0, WIDTH, HEIGHT, BLACK);
        circlefill(buffer, x, y, 10, WHITE);
        textprintf(buffer, font, 320, 20, WHITE, "%i'%i", game_time/60000, (game_time/1000)%60);

        for (int i = 0; i < 14; i++)
        {
                hline(buffer, land[i].x - land[i].w, land[i].y, land[i].x + land[i].w, WHITE);
        }

        blit(buffer, screen, 0, 0, 0, 0, WIDTH, HEIGHT);

        game_time += 20;
        while (clock() < start_time + 20)
        {}
    }
    destroy_bitmap(buffer);
    return;
}
Exemplo n.º 12
0
c_al_bitmap::~c_al_bitmap() {
	if (m_bitmap) {
		destroy_bitmap(m_bitmap);
		m_bitmap=nullptr;
	}
}
Exemplo n.º 13
0
int main() {
	const int spd = 16;
	for (int x=0;x<41;++x) {
		angles_y[x] = (spd*cos(PI/180*(x-20+90)));
		angles_x[x] = (spd*sin(PI/180*(x-20+90)));
	}
	
    allegro_init();
    install_keyboard();
    install_timer();
   
    LOCK_VARIABLE(speed_counter);
    LOCK_FUNCTION(increment_speed_counter);
    install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));
   
    const int width = 1024;
    const int height = 768;
   
    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, width, height, 0, 0);
    set_alpha_blender();
	
    BITMAP* buffer = create_bitmap(width, height);
    
    //BITMAP* image3 = load_bitmap("./sprites/chopper3.tga", 0);
    BITMAP* image2 = load_bitmap("./sprites/chopper.tga", 0);
    BITMAP* image = load_bitmap("./sprites/chopper2.tga", 0);
    
    BITMAP* background = load_bitmap("./sprites/background.bmp", 0);
    
    BITMAP* image_sphere = load_bitmap("./sprites/sphere1.tga", 0);
    BITMAP* image_sphere2 = load_bitmap("./sprites/sphere2.tga", 0);
    
    BITMAP* image_shot = load_bitmap("./sprites/shot.tga", 0);
    
    BITMAP* image_explosion[17];
    
    image_explosion[0] = load_bitmap("./sprites/exp_frame_0.tga", 0);
    image_explosion[1] = load_bitmap("./sprites/exp_frame_1.tga", 0);
    image_explosion[2] = load_bitmap("./sprites/exp_frame_2.tga", 0);
    image_explosion[3] = load_bitmap("./sprites/exp_frame_3.tga", 0);
    image_explosion[4] = load_bitmap("./sprites/exp_frame_4.tga", 0);
    image_explosion[5] = load_bitmap("./sprites/exp_frame_5.tga", 0);
    image_explosion[6] = load_bitmap("./sprites/exp_frame_6.tga", 0);
    image_explosion[7] = load_bitmap("./sprites/exp_frame_7.tga", 0);
    image_explosion[8] = load_bitmap("./sprites/exp_frame_8.tga", 0);
    image_explosion[9] = load_bitmap("./sprites/exp_frame_9.tga", 0);
    image_explosion[10] = load_bitmap("./sprites/exp_frame_10.tga", 0);
    image_explosion[11] = load_bitmap("./sprites/exp_frame_11.tga", 0);
    image_explosion[12] = load_bitmap("./sprites/exp_frame_12.tga", 0);
    image_explosion[13] = load_bitmap("./sprites/exp_frame_13.tga", 0);
    image_explosion[14] = load_bitmap("./sprites/exp_frame_14.tga", 0);
    image_explosion[15] = load_bitmap("./sprites/exp_frame_15.tga", 0);
    image_explosion[16] = load_bitmap("./sprites/exp_frame_16.tga", 0);
	
	std::vector<helicopter> heli;
    heli.push_back(helicopter(image_explosion, 17,image->w,  image->h,  40,  40, 0, 0,   0, gravity / 2, 0.8, 0.5));
    heli.push_back(helicopter(image_explosion, 17,image2->w, image2->h, 720, 40, 0, 0,   0, gravity / 2, 0.8, 0.5));
    //heli.push_back(helicopter(image_explosion, 17,image3->w, image3->h, 350, 200, 0, 100, 0, gravity / 2, 0.8, 0.5));
    heli[0].flip = !heli[0].flip;
    
    srand(time(NULL));
    
    std::vector<ball> spheres;
	for (int x=0;x<10;++x) 
		spheres.push_back(
			ball(
				image_sphere->w,
				image_sphere->h,
				(double)((int)rand()%(SCREEN_W-image_sphere->w)),
				(double)((int)rand()%(SCREEN_H-image_sphere->h)),
				(double)((int)rand()%60),
				(double)((int)rand()%60),
				0.0,
				gravity * 2,
				0.95,
				0.95));
	
	std::vector<explosion> explosions;
	
    while (!key[KEY_ESC]) {
        while (speed_counter > 0) {
        	heli[1].get_input(key[KEY_UP], key[KEY_DOWN], key[KEY_LEFT], key[KEY_RIGHT], true);
        	heli[0].get_input(key[KEY_W], key[KEY_S], key[KEY_A], key[KEY_D], true);
        	//heli[2].get_input(key[KEY_Y], key[KEY_H], key[KEY_G], key[KEY_J], true);
        	
        	for (unsigned int x=0;x<heli.size();++x) {
            	if (!(heli[x].health>0))explosions.push_back(explosion(image_explosion, 17, (int)heli[x].pos_x, (int)heli[x].pos_y, rand()%(heli[x].size_x*2), rand()%(heli[x].size_y*2)));
        		heli[x].update_phys();
        	}
            
            for (unsigned int x=0;x<spheres.size();++x) {
            	spheres[x].update_phys();
            }
            	
            for (unsigned int x=0;x<explosions.size();++x)
            	if (explosions[x].alive)
            		explosions[x].update_frame();
            	else
            		explosions.erase(explosions.begin()+x);
            
            for (unsigned int x=0;x<heli.size();++x)
				for (unsigned int y=0;y<spheres.size();++y)
					if (check_collision(spheres[y], heli[x])) {
						heli[x].explode((heli[x].pos_x - spheres[y].pos_x)+heli[x].speed_x, (heli[x].pos_y - spheres[y].pos_y)+heli[x].speed_y, 1);
						spheres[y].explode((spheres[y].pos_x - heli[x].pos_x)+spheres[y].speed_x, (spheres[y].pos_y - heli[x].pos_y)+spheres[y].speed_y);
						if (heli[x].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[x].pos_x, (int)heli[x].pos_y, heli[x].size_x, heli[x].size_y));
						explosions.push_back(explosion(image_explosion, 17, (int)spheres[y].pos_x, (int)spheres[y].pos_y));
					}
            
            for (unsigned int x=0;x<spheres.size();++x)
            	for (unsigned int y=x+1;y<spheres.size();++y)
					if (check_collision(spheres[x], spheres[y])) {
						spheres[x].explode((spheres[x].pos_x - spheres[y].pos_x)+spheres[x].speed_x, (spheres[x].pos_y - spheres[y].pos_y)+spheres[x].speed_y);
						spheres[y].explode((spheres[y].pos_x - spheres[x].pos_x)+spheres[y].speed_x, (spheres[y].pos_y - spheres[x].pos_y)+spheres[y].speed_y);
						explosions.push_back(explosion(image_explosion, 17, (int)spheres[x].pos_x, (int)spheres[x].pos_y));
						explosions.push_back(explosion(image_explosion, 17, (int)spheres[y].pos_x, (int)spheres[y].pos_y));
					}
            
            if (check_collision(heli[0], heli[1])) {
            	heli[0].explode((heli[0].pos_x - heli[1].pos_x)+heli[0].speed_x, (heli[0].pos_y - heli[1].pos_y)+heli[0].speed_y, 5);
            	heli[1].explode((heli[1].pos_x - heli[0].pos_x)+heli[1].speed_x, (heli[1].pos_y - heli[0].pos_y)+heli[1].speed_y, 5);
            	if (heli[0].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[0].pos_x, (int)heli[0].pos_y, heli[0].size_x, heli[0].size_y));
            	if (heli[1].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[1].pos_x, (int)heli[1].pos_y, heli[1].size_x, heli[1].size_y));
            }
            
            for (unsigned int x=0;x<heli.size();++x) {
            	for (unsigned int y=0;y<heli[x].shots.size();++y) {
            		for (unsigned int z=0;z<heli.size();++z)
            			if (z!=x)
            				if (check_collision(heli[x].shots[y], heli[z])) {
            					heli[z].explode((heli[z].pos_x - heli[x].shots[y].pos_x)+heli[z].speed_x, (heli[z].pos_y - heli[x].shots[y].pos_y)+heli[z].speed_y,10);
            					if (heli[z].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[z].pos_x, (int)heli[z].pos_y));
            				}
            		for (unsigned int z=0;z<spheres.size();++z)
            			if (check_collision(heli[x].shots[y], spheres[z])) {
							spheres[z].explode((spheres[z].pos_x - heli[x].shots[y].pos_x)+spheres[z].speed_x, (spheres[z].pos_y - heli[x].shots[y].pos_y)+spheres[z].speed_y);
							explosions.push_back(explosion(image_explosion, 17, (int)spheres[z].pos_x, (int)spheres[z].pos_y));
							if (z==0) {
								spheres.erase(spheres.begin());
								spheres.push_back(ball(image_sphere->w,image_sphere->h,(double)((int)rand()%(SCREEN_W-image_sphere->w)),(double)((int)rand()%(SCREEN_H-image_sphere->h)),(double)((int)rand()%60),(double)((int)rand()%60),0.0,gravity * 2,0.95,0.95));
								heli[x].health += 50;
							}
						}
            	}
            	for (unsigned int y=x+1;y<heli.size();++y)
            		if (check_collision(heli[x], heli[y])) {
            			heli[x].explode((heli[x].pos_x - heli[y].pos_x)+heli[x].speed_x, (heli[x].pos_y - heli[y].pos_y)+heli[x].speed_y,10);
            			if (heli[x].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[x].pos_x, (int)heli[x].pos_y));
            			heli[y].explode((heli[y].pos_x - heli[x].pos_x)+heli[y].speed_x, (heli[y].pos_y - heli[x].pos_y)+heli[y].speed_y,10);
            			if (heli[y].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[y].pos_x, (int)heli[y].pos_y));
            		}
            }
            
            speed_counter--;
        }
        
		blit(background, buffer, 0, 0, 0, 0, width, height);
		
		for (unsigned int x=0;x<spheres.size();++x) {
			if (x==0)
				spheres[x].draw(buffer, image_sphere2);
			else
				spheres[x].draw(buffer, image_sphere);
		}
			
        heli[0].draw(buffer, image, image_shot);
        heli[1].draw(buffer, image2, image_shot);
        //heli[2].draw(buffer, image3, image_shot);
        
        draw_health(buffer, 10, 10, heli[0].health);
        draw_health(buffer, SCREEN_W-110, 10, heli[1].health);
        //draw_health(buffer, SCREEN_W/2, 10, heli[2].health);
        
        for (unsigned int x=0;x<explosions.size();++x)
        	explosions[x].draw(buffer);
		
        blit(buffer, screen, 0, 0, 0, 0, width, height);
        clear_bitmap(buffer);
    }
   
    destroy_bitmap(buffer);
    
   
    return 0;
}
Exemplo n.º 14
0
static void destroy_datafile_png(void *data)
{
    if (data) {
	destroy_bitmap((BITMAP *)data);
    }
}
Exemplo n.º 15
0
void showIntro(void)
{
	allegro_gl_begin();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, 800, 0, 600, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClearColor(0, 0, 0, 0);
	glShadeModel(GL_SMOOTH);
	glDepthFunc(GL_LEQUAL);
	glClearDepth(1.0);
	glEnable(GL_DEPTH_TEST);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glEnable(GL_TEXTURE_2D);
	allegro_gl_end();

	GLuint machineballtex;
	allegro_gl_set_texture_format(GL_RGBA);
	BITMAP *bmp = create_bitmap_ex(32, 256, 64);
	blit(&mb_machineball_bmp, bmp, 0, 0, 0, 0, 256, 64);
	machineballtex = allegro_gl_make_masked_texture(bmp);
	destroy_bitmap(bmp);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	dp = al_start_duh(menuduh, 2, 0, (float)options.musicvol/255.0, 2048, 22050);
	menumusicisplaying=1;

	timer.install();
	double time;
	time=0;
	while(!(key[KEY_ESC] || time>23))
	{
		rest(1);
		time=timer.seconds();

		al_poll_duh(dp);

		allegro_gl_begin();
		
		glLoadIdentity();
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		if(time<4)
		{
			glColor3f(time/4, time/4, time/4);
			text.print(120, 280, "BENNY KRAMEK PRESENTS");
			glBindTexture(GL_TEXTURE_2D, bennykramekwebtex);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(242, 180);
			glTexCoord2f(1, 0);
			glVertex2i(498, 180);
			glTexCoord2f(1, 1);
			glVertex2i(498, 212);
			glTexCoord2f(0, 1);
			glVertex2i(242, 212);
			glEnd();
		}
		else if(time<8)
		{
			glColor3f(1-((time-4)/4), 1-((time-4)/4), 1-((time-4)/4));
			text.print(120, 280, "BENNY KRAMEK PRESENTS");
			glBindTexture(GL_TEXTURE_2D, bennykramekwebtex);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(242, 180);
			glTexCoord2f(1, 0);
			glVertex2i(498, 180);
			glTexCoord2f(1, 1);
			glVertex2i(498, 212);
			glTexCoord2f(0, 1);
			glVertex2i(242, 212);
			glEnd();
		}

		glColor3f(0.5, 0.5, 0.5);
		text.begin();
		text.print(20, (int)(60*(time-8.7)),     "THIS IS THE FUTURE.");
		text.print(20, (int)(60*(time-8.7))-50,  "A FUTURE WHERE PRIMITIVE SPORTS");
		text.print(20, (int)(60*(time-8.7))-100, "NO LONGER EXIST. IN THIS WORLD,");
		text.print(20, (int)(60*(time-8.7))-150, "THERE IS ONLY ONE SPORT.");
		text.print(20, (int)(60*(time-8.7))-200, "THERE IS ONLY...");
		text.end();

		if(time>22 && time<=22.5)
		{
			glColor3f(1, 1, 1);
			glBindTexture(GL_TEXTURE_2D, machineballtex);
			glTranslatef(400, 300, 0);
			glScalef((time-22)*200, (time-22)*200, (time-22)*200);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(-4, -1);
			glTexCoord2f(1, 0);
			glVertex2i(4, -1);
			glTexCoord2f(1, 1);
			glVertex2i(4, 1);
			glTexCoord2f(0, 1);
			glVertex2i(-4, 1);
			glEnd();

		}
		if(time>22.5)
		{
			glColor3f(1, 1, 1);
			glBindTexture(GL_TEXTURE_2D, machineballtex);
			glTranslatef(400, 300+(time-22.5)*240, 0);
			glScalef(100-(time-22.5)*50, 100-(time-22.5)*50, 100-(time-22.5)*50);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(-4, -1);
			glTexCoord2f(1, 0);
			glVertex2i(4, -1);
			glTexCoord2f(1, 1);
			glVertex2i(4, 1);
			glTexCoord2f(0, 1);
			glVertex2i(-4, 1);
			glEnd();
			glColor4f(1, 1, 1, 1-((time-22.5)));
			glLoadIdentity();
			glDisable(GL_TEXTURE_2D);
			glBegin(GL_QUADS);
			glVertex2i(0, 0);
			glVertex2i(800, 0);
			glVertex2i(800, 600);
			glVertex2i(0, 600);
			glEnd();
			glEnable(GL_TEXTURE_2D);
		}
		
		glFlush();
		allegro_gl_flip();
		allegro_gl_end();
	}

	glDeleteTextures(1, &machineballtex);
}
int main(int argc, char *argv[])
{
    int ret = 0;
    int i;

    allegro_init();
    install_keyboard();
    install_mouse();
    install_timer();

    srand(time(NULL));

    for (i=1; i<argc; i++) {

        if (stricmp(argv[i], "-bpp") == 0) {
            if ((i >= argc-1) || (bpp > 0)) {
                usage();
                return 1;
            }

            bpp = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-frames") == 0) {
            if ((i >= argc-1) || (frames > 0)) {
                usage();
                return 1;
            }

            frames = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-size") == 0) {
            if ((i >= argc-2) || (size_x > 0) || (size_y > 0)) {
                usage();
                return 1;
            }

            size_x = atoi(argv[++i]);
            size_y = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-mode") == 0) {
            if ((i >= argc-2) || (mode_x > 0) || (mode_y > 0)) {
                usage();
                return 1;
            }

            mode_x = atoi(argv[++i]);
            mode_y = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-step") == 0) {
            step = TRUE;
        }
        else if (stricmp(argv[i], "-modesel") == 0) {
            modesel = TRUE;
        }
        else if (stricmp(argv[i], "-pregen") == 0) {
            pregen = TRUE;
        }
        else if (stricmp(argv[i], "-o") == 0) {
            if ((i >= argc-1) || (out_file)) {
                usage();
                return 1;
            }

            out_file = argv[++i];
        }
        else if (stricmp(argv[i], "-pal") == 0) {
            if ((i >= argc-1) || (pal_file)) {
                usage();
                return 1;
            }

            pal_file = argv[++i];
        }
        else {
            if ((*argv[i] == '-') || (in_file)) {
                usage();
                return 1;
            }

            in_file = argv[i];
        }
    }

    if (!in_file) {
        usage();
        return 1;
    }

    if ((pregen) && ((frames <= 0) || (step))) {
        allegro_message("The '-pregen' option requires '-frames num' to be specified,\nand cannot be used at the same time as '-step'\n");
        return 1;
    }

    if (!set_video_mode()) {
        ret = 1;
        goto getout;
    }

    the_egg = load_egg(in_file, error);

    if (!the_egg) {
        set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
        allegro_message("%s", error);
        return 1;
    }

    if (size_x <= 0)
        size_x = 128;

    if (size_y <= 0)
        size_y = 128;

    if (pal_file) {
        BITMAP *tmp = load_bitmap(pal_file, pal);

        if (!tmp) {
            set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
            allegro_message("Error reading palette from '%s'\n", pal_file);
            ret = 1;
            goto getout;
        }

        destroy_bitmap(tmp);
    }
    else
        generate_332_palette(pal);

    clear(screen);

    set_palette(pal);

    text_mode(0);

    do {
        if (pregen) {
            textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2-24, makecol(128, 128, 128), "Rendering frame %d/%d", the_egg->frame+1, frames);
            textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2+24, makecol(128, 128, 128), "Please Wait");
        }

        if (update_egg(the_egg, error) != 0) {
            allegro_exit();
            printf("Error running EGG script:\n%s\n\n", error);
            ret = 1;
            goto getout;
        }

        bmp[frame] = create_bitmap(size_x, size_y);

        lay_egg(the_egg, bmp[frame]);

        if (!pregen) {
            vsync();
            blit(bmp[frame], screen, 0, 0, (SCREEN_W-size_x)/2, (SCREEN_H-size_y)/2, size_x, size_y);
            textprintf(screen, font, 0, 0, makecol(128, 128, 128), "Frame %d, %d particles        ", the_egg->frame, the_egg->part_count);
        }

        if ((!pregen) && (!out_file)) {
            destroy_bitmap(bmp[frame]);
            bmp[frame] = NULL;
        }

        frame++;

        if ((step) || (keypressed())) {
            if ((readkey()&0xFF) == 27)
                break;

            clear_keybuf();
        }

    } while (((frames <= 0) || (frame < frames)) && (frame < 4096));

    if (pregen)
        view_animation();

    if (out_file)
        save_animation();

getout:

    if (the_egg)
        destroy_egg(the_egg);

    for (i=0; i<frame; i++)
        if (bmp[frame])
            destroy_bitmap(bmp[frame]);

    return ret;
}
Exemplo n.º 17
0
void fin(){
	clear_keybuf();
	destroy_bitmap(im_tortuga);
	destroy_bitmap(buffer);
	destroy_bitmap(buffer2);
}
Exemplo n.º 18
0
ZRadar::~ZRadar()
{
	destroy_bitmap(Painted);
}
Exemplo n.º 19
0
void deinit() 
{
	clear_keybuf();
	destroy_bitmap(buffer);
	/* add other deinitializations here */
}
Exemplo n.º 20
0
/* Check user interface keys */
void check_ui_keys(void)
{
    if(check_key(KEY_TILDE))
    {
        static const char *msg[] = {"EMU2413", "YM2413"};

        if(snd.fm_which == SND_EMU2413)
            snd.fm_which = SND_YM2413;
        else
            snd.fm_which = SND_EMU2413;

        add_msg("Using %s FM sound emulator.", msg[snd.fm_which]);
        sound_init();
    }

    /* Frame skip keys */
    if(check_key(KEY_F1)) { frame_skip = 1; add_msg("Frame skip disabled"); };
    if(check_key(KEY_F2)) { frame_skip = 2; add_msg("Frame skip set to 1"); };
    if(check_key(KEY_F3)) { frame_skip = 3; add_msg("Frame skip set to 2"); };
    if(check_key(KEY_F4)) { frame_skip = 4; add_msg("Frame skip set to 3"); };

    /* State save/load keys */
    if(check_key(KEY_F5)) { if(save_state()) add_msg("State saved to slot %d", state_slot); };
    if(check_key(KEY_F6)) { state_slot = (state_slot + 1) % 10; add_msg("Slot %d", state_slot); };
    if(check_key(KEY_F7)) { if(load_state()) add_msg("State loaded from slot %d", state_slot); };

    /* Screen snapshot */
    if(check_key(KEY_F8))
    {
        char name[PATH_MAX];
        PALETTE snap_pal;
        BITMAP *snap_bmp = create_bitmap_ex(option.video_depth, bitmap.viewport.w, bitmap.viewport.h);
        if(snap_bmp)
        {
            int i;

            /* Get current palette */
            get_palette(snap_pal);

            /* Remove unused palette entries */
            for(i = 0x20; i < 0xFE; i++)
                snap_pal[i].r = snap_pal[i].g = snap_pal[i].b = 0x00;
            
            /* Clip image */
            blit(sms_bmp, snap_bmp, bitmap.viewport.x, bitmap.viewport.y, 0, 0, bitmap.viewport.w, bitmap.viewport.h);

            /* Generate file name */
            sprintf(name, "snap%04d.pcx", snap_count);

            /* Remove unused bits */
            if(option.video_depth == 8)
            {
                int x, y;
                for(y = 0; y < bitmap.viewport.h; y++)
                for(x = 0; x < bitmap.viewport.w; x++)
                    putpixel(snap_bmp, x, y, getpixel(snap_bmp, bitmap.viewport.x + x, bitmap.viewport.y + y) & PIXEL_MASK);
            }

            /* Save snapshot in PCX format */
            save_pcx(name, snap_bmp, snap_pal);

            /* Deallocate temporary bitmap */
            destroy_bitmap(snap_bmp);

            /* Bump snapshot counter */
            snap_count = (snap_count + 1) & 0xFFFF;

            /* Display results */
            add_msg("Saved screen to %s", name);
        }
    }


    /* FPS meter toggle */
    if(check_key(KEY_F9))
    {
        option.fps ^= 1;
        add_msg("FPS meter %s", option.fps ? "on" : "off");
    }

    /* Speed throttling */
    if(check_key(KEY_F10))
    {
        if(!option.sound)
        {
            option.throttle ^= 1;
            add_msg("Speed throttling %s", option.throttle ? "on" : "off");
        }
    }

    /* Speed throttling */
    if(check_key(KEY_F11))
    {
        option.vsync ^= 1;
        add_msg("VSync %s", option.vsync ? "on" : "off");
    }

    /* Exit keys */
    if(key[KEY_ESC] || key[KEY_END]) running = 0;
}
Exemplo n.º 21
0
GraphicBG::~GraphicBG()
{
    if (drawn) undraw();
    destroy_bitmap(bg);
}
Exemplo n.º 22
0
int Manual(int argc, unsigned char **argv)
{
  /* Serial port initialization */

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

  initport(fd);

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

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


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

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

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

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

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

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

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

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

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

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

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

  destroy_rle_sprite(rle0);  
  destroy_rle_sprite(rle1);    
  destroy_bitmap(Screen2);
  destroy_bitmap(Screen3);
  destroy_bitmap(Clean);
  destroy_bitmap(Disconnected);
  release_screen();
  Close();
  exit(0);
} 
Exemplo n.º 24
0
void fnt_ttf_print_string(BITMAP *b, int x, int y, char *text, int fg, int bg, int sd) {
   // Refined Version from tutorial
   FT_GlyphSlot slot = face->glyph; /* a small shortcut */  
   FT_Error error;
   fnt_t* cfont;
   BITMAP* line1,line0;

   int pen_x, pen_y, n; 
#ifdef USESDL
   Uint32 rmask,gmask,bmask,amask;
#else
   int rmask,gmask,bmask,amask;
#endif
   // ... initialize library ... 
   //  ... create face object ... 

   // printf("fnt_ttf_print_string\n");
   cfont=fnt_getactive();
   // printf("scale_h=%d\n",cfont->scale_w);
   error = FT_Set_Pixel_Sizes(face, /* handle to face object */  
			      cfont->scale_w,    /* pixel_width */
			     cfont->scale_h );  /* pixel_height */
   pen_x = x; pen_y = y+cfont->scale_h-1;
   pen_x = 0; pen_y = cfont->scale_h-1;

   if(fnt_render==RENDER_NATIVE) {
      // for SDL, you can use this
#ifdef USESDL	
# if SDL_BYTEORDER == SDL_BIG_ENDIAN
      rmask=0xff000000; gmask=0x00ff0000; bmask=0x0000ff00; amask=0x000000ff;
# else
      rmask=0x000000ff; gmask=0x0000ff00; bmask=0x00ff0000; amask=0xff000000;
# endif
      line1=SDL_CreateRGBSurface(SDL_SWSURFACE,640,cfont->scale_h*2,32,rmask,gmask,bmask,amask);
#endif
      rectfill(line1,0,0,640,cfont->scale_h*2,makeacol(0,0,0,0));
   } else {
      // For generic sdl/allegro, use this:
      line1=create_bitmap(640,cfont->scale_h*2);
      if(bg==-1) 
	blit(screen,line1,x,y,0,0,640-x,y+cfont->scale_h*2);
      else
	rectfill(line1,0,0,640,cfont->scale_h*2,bg);
   }

//   printf ("x4\n");
//   printf("rendering: %s\n",text);
   for ( n = 0; n < strlen(text); n++ ) {
      if(text[n] != 10 ) {
	 error = FT_Load_Char( face, text[n], FT_LOAD_RENDER ); 
	 if ( error ) continue; /* ignore errors */

	 if(fnt_render==RENDER_SIMPLE) {
	    if(sd>-1)
	      fnt_ttf_draw_bitmap_simple( &slot->bitmap, line1, pen_x + slot->bitmap_left+1, pen_y - slot->bitmap_top+1, sd ); /* increment pen position */   
	    fnt_ttf_draw_bitmap_simple( &slot->bitmap, line1, pen_x + slot->bitmap_left, pen_y - slot->bitmap_top, fg ); /* increment pen position */   
	 }
	 if(fnt_render==RENDER_BLEND) {
	    if(sd>-1)
	      fnt_ttf_draw_bitmap_blend( &slot->bitmap, line1, pen_x + slot->bitmap_left+1, pen_y - slot->bitmap_top+1, sd ); /* increment pen position */   
	    fnt_ttf_draw_bitmap_blend( &slot->bitmap, line1, pen_x + slot->bitmap_left, pen_y - slot->bitmap_top, fg ); /* increment pen position */   
	 }
	 if(fnt_render==RENDER_NATIVE) {
#ifdef USESDL
	    if(sd>-1)
	      fnt_ttf_draw_bitmap_sdl( &slot->bitmap, line1, pen_x + slot->bitmap_left+1, pen_y - slot->bitmap_top+1, sd ); /* increment pen position */   
	    fnt_ttf_draw_bitmap_sdl( &slot->bitmap, line1, pen_x + slot->bitmap_left, pen_y - slot->bitmap_top, fg ); /* increment pen position */   
#endif
	 }
      }
      pen_x += slot->advance.x >> 6; pen_y += slot->advance.y >> 6; /* not useful for now */  
   }
//   printf ("x5\n");
if(fnt_render==RENDER_NATIVE && bg>-1)
     rectfill(screen,x,y,pen_x+x,pen_y+y,bg);
   masked_blit(line1,screen,0,0,x,y,pen_x,cfont->scale_h+4);
   destroy_bitmap(line1);
//   destroy_bitmap(line0);
//   printf("%s\n",text);
}
Background::~ Background()
{
	if (texture) destroy_bitmap (texture);
	texture = NULL;
}
Exemplo n.º 26
0
int init_screen(screen_t* my_screen, int width, int height, char* images_folder){
	int i;
	char str[5][256];
	BITMAP	*buff0;
	BITMAP	*buff1;
	BITMAP	*buff2;
	BITMAP	*buff3;
	BITMAP	*buff4;

	my_screen-> w = width;
	my_screen-> h = height;
	my_screen-> images_folder= images_folder;
	my_screen-> bg_col = makecol(0,0,0);
	my_screen-> status = MENU;
	my_screen->scene = 0 ;
	allegro_init();
	printf("allegro initialized\n");
	set_window_title("Car Race");
	set_color_depth(16);
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, my_screen->w, my_screen->h, 0, 0);
	install_keyboard();
	strcpy(str[0], images_folder);
	strcpy(str[1], images_folder);
	strcpy(str[2], images_folder);
	strcpy(str[3], images_folder);
	strcpy(str[4], images_folder);
	strcat(str[0], "dash_texture.tga");
	strcat(str[1], "speedmeter.tga");
	strcat(str[2], "needle.tga");
	strcat(str[3], "reddash.tga");
	strcat(str[4], "needle.tga");

	/*init map */
	init_screen_map(my_screen);

	/*init user interface*/
	init_screen_ui(my_screen);
	buff0 = load_bitmap(str[0], NULL);
	if(!buff0)
		printf("problems loading texture bmp!\n");
	stretch_blit(buff0, my_screen->ui.if_bmp, 0, 0, buff0->w - 1, buff0->h - 1, 0, 0, UI_W - 1, UI_H -1);
	destroy_bitmap(buff0);
	buff1 = load_bitmap(str[1], NULL);
	if(!buff1)
		printf("problems loading speedmeter bmp!\n");
	stretch_blit(buff1, my_screen->ui.speedmeter, 0, 0, buff1->w, buff1->h , 0, 0, my_screen->ui.speedmeter->w , my_screen->ui.speedmeter->h);
	destroy_bitmap(buff1);
	buff2 = load_bitmap(str[2], NULL);
	if(!buff2)
		printf("problems loading needle bmp!\n");
	stretch_blit(buff2, my_screen->ui.needle, 0, 0, buff2->w, buff2->h, 0, 0, my_screen->ui.needle->w, my_screen->ui.needle->h);
	destroy_bitmap(buff2);
	buff3 = load_bitmap(str[3], NULL);
	if(!buff3)
		printf("problems loading speedmeter bmp!\n");
	stretch_blit(buff3, my_screen->ui.redspeedmeter, 0, 0, buff3->w, buff3->h , 0, 0, my_screen->ui.redspeedmeter->w , my_screen->ui.redspeedmeter->h);
	destroy_bitmap(buff3);
	buff4 = load_bitmap(str[4], NULL);
	if(!buff4)
		printf("problems loading little needle bmp!\n");
	stretch_blit(buff4, my_screen->ui.little_needle, 0, 0, buff4->w, buff4->h, 0, 0, my_screen->ui.little_needle->w, my_screen->ui.little_needle->h);
	destroy_bitmap(buff4);

	/*init thread data*/
	init_screen_td(my_screen);

	/*Generate Cars*/
	new_car(&my_screen->vw.player, PLAYER_ID, my_screen->images_folder);
	for(i=0; i<CPUCARS; i++)
		new_car(&my_screen->vw.cpu[i], i, my_screen->images_folder);

	blit(my_screen->map.background, screen, 0, 0, 0, 0, my_screen->map.w - 1, my_screen->map.h - 1);
	blit(my_screen->td.td_bmp, screen, 0, 0, MAP_W, 0, my_screen->td.w - 1, my_screen->td.h - 1);
	printf("screen initialized\n");
	return 0;
}
Exemplo n.º 27
0
SwapScreen::~SwapScreen(){
	destroy_bitmap(targetBuffer);
	destroy_bitmap(sourceBuffer);
	destroy_bitmap(buffer);
}
Exemplo n.º 28
0
int main(void)
{

	// Nastavíme pozici ètvercù 
	//int pos_x = 10;
	//int pos_y = 10;
	//int pos_x2 = 100;
	//int pos_y2 = 100;
	//------------------------

	// Nastavíme barvu ètvercù r,g,b
	//int r = 0;
	//int g = 255;
	//int b = 0;
	//-------------------------

	allegro_init();	 // inicializace allegra
	install_keyboard(); // inicializace klavesnice
	obr = load_bitmap("obr.bmp",NULL);
	//obr2 = load_bitmap("obr2.bmp",NULL);

	set_color_depth(8); // Nastavíme hloubku , Grafický mod ,a výšku a šíøku obrazovky
	if (set_gfx_mode(GFX_AUTODETECT|GFX_AUTODETECT_WINDOWED, SCR_W ,SCR_H, 0, 0)) 
	{
		set_color_depth(24);
		if (set_gfx_mode(GFX_AUTODETECT|GFX_AUTODETECT_WINDOWED, SCR_W , SCR_H, 0, 0)) 
		{
			set_color_depth(16);
			if (set_gfx_mode(GFX_AUTODETECT|GFX_AUTODETECT_WINDOWED, SCR_W , SCR_H , 0, 0)) 
			{
				set_color_depth(15);
				if (set_gfx_mode(GFX_AUTODETECT|GFX_AUTODETECT_WINDOWED, SCR_W , SCR_H, 0, 0)) 
				{
					allegro_message("Video Error: %s.\n", allegro_error);
					return 1;
				}
			}
		}
	}
	InitDoubleBuffering();
	Init();              

	while (!key[KEY_ESC])
	{

       /* if(key[KEY_UP])
		{ pos_y -= 1;}
		if(key[KEY_DOWN])
		{ pos_y += 1;}
		if(key[KEY_RIGHT])
		{ pos_x += 1;}
		if(key[KEY_LEFT])
		{ pos_x -= 1;}

		if(key[KEY_W])
		{ pos_y2 -= 1;}
		if(key[KEY_S])
		{ pos_y2 += 1;}
		if(key[KEY_D])
		{ pos_x2 += 1;}
		if(key[KEY_A])
		{ pos_x2 -= 1;}

		if((pos_x > pos_x2 - 20) && ( pos_x < pos_x2 + 20) && (pos_y > pos_y2 - 20 ) && (pos_y < pos_y2 + 20)){}
		else{}
		*/
		
		Posun();
		DrawEnemy();
//		Draw();
		DrawBuffer();
		Colision();
		clear_bitmap(buffer);
		rest(10); //jinak tez wait()

	}
	destroy_bitmap(obr);
	return 0;
}
Exemplo n.º 29
0
/*! \brief Main menu screen
 *
 * This is the main menu... just display the opening and then the menu and
 * then wait for input.  Also handles loading a saved game, and the config menu.
 *
 * \param   c zero if the splash (the bit with the staff and the eight heroes)
 *            should be displayed.
 * \returns 1 if new game, 0 if continuing, 2 if exit
 */
int start_menu (int skip_splash)
{
   int stop = 0, ptr = 0, redraw = 1, a, b;
   DATAFILE *bg;
   BITMAP *staff, *dudes, *tdudes;

#ifdef DEBUGMODE
   if (debugging == 0) {
#endif
      play_music ("oxford.s3m", 0);
      /* Play splash (with the staff and the heroes in circle */
      if (skip_splash == 0) {
         bg = load_datafile_object (PCX_DATAFILE, "KQT_PCX");
         staff = create_bitmap_ex (8, 72, 226);
         dudes = create_bitmap_ex (8, 112, 112);
         tdudes = create_bitmap_ex (8, 112, 112);
         blit ((BITMAP *) bg->dat, staff, 0, 7, 0, 0, 72, 226);
         blit ((BITMAP *) bg->dat, dudes, 80, 0, 0, 0, 112, 112);
         clear_bitmap (double_buffer);
         blit (staff, double_buffer, 0, 0, 124, 22, 72, 226);
         blit2screen (0, 0);

         kq_wait (1000);
         for (a = 0; a < 42; a++) {
            stretch_blit (staff, double_buffer, 0, 0, 72, 226, 124 - (a * 32),
                          22 - (a * 96), 72 + (a * 64), 226 + (a * 192));
            blit2screen (0, 0);
            kq_wait (100);
         }
         for (a = 0; a < 5; a++) {
            color_scale (dudes, tdudes, 53 - a, 53 + a);
            draw_sprite (double_buffer, tdudes, 106, 64);
            blit2screen (0, 0);
            kq_wait (100);
         }
         draw_sprite (double_buffer, dudes, 106, 64);
         blit2screen (0, 0);
         kq_wait (1000);
         destroy_bitmap (staff);
         destroy_bitmap (dudes);
         destroy_bitmap (tdudes);
		 unload_datafile_object(bg);
         /*
            TODO: this fade should actually be to white
            if (_color_depth == 8)
            fade_from (pal, whp, 1);
            else
          */
         do_transition (TRANS_FADE_WHITE, 1);
      }
      clear_to_color (double_buffer, 15);
      blit2screen (0, 0);
      set_palette (pal);
      bg = load_datafile_object (PCX_DATAFILE, "TITLE_PCX");
      for (a = 0; a < 16; a++) {
         clear_to_color (double_buffer, 15 - a);
         masked_blit ((BITMAP *) bg->dat, double_buffer, 0, 0, 0, 60 - (a * 4),
                      320, 124);
         blit2screen (0, 0);
         kq_wait (a == 0 ? 500 : 100);
      }
      if (skip_splash == 0)
         kq_wait (500);
#ifdef DEBUGMODE
   } else {
      set_palette (pal);
      bg = load_datafile_object (PCX_DATAFILE, "TITLE_PCX");
   }
#endif

   reset_world ();

   /* Draw menu and handle menu selection */
   while (!stop) {
      if (redraw) {
         clear_bitmap (double_buffer);
         masked_blit ((BITMAP *) bg->dat, double_buffer, 0, 0, 0, 0, 320, 124);
         menubox (double_buffer, 112, 116, 10, 4, BLUE);
         print_font (double_buffer, 128, 124, _("Continue"), FNORMAL);
         print_font (double_buffer, 128, 132, _("New Game"), FNORMAL);
         print_font (double_buffer, 136, 140, _("Config"), FNORMAL);
         print_font (double_buffer, 144, 148, _("Exit"), FNORMAL);
         draw_sprite (double_buffer, menuptr, 112, ptr * 8 + 124);
         redraw = 0;
      }
      display_credits ();
      blit2screen (0, 0);
      readcontrols ();
      if (bhelp) {
         unpress ();
         show_help ();
         redraw = 1;
      }
      if (up) {
         unpress ();
         if (ptr > 0)
            ptr--;
         else
            ptr = 3;
         play_effect (SND_CLICK, 128);
         redraw = 1;
      }
      if (down) {
         unpress ();
         if (ptr < 3)
            ptr++;
         else
            ptr = 0;
         play_effect (SND_CLICK, 128);
         redraw = 1;
      }
      if (balt) {
         unpress ();
         if (ptr == 0) {        /* User selected "Continue" */
            if (snc[0] == 0 && snc[1] == 0 && snc[2] == 0 && snc[3] == 0
                && snc[4] == 0)
               stop = 2;
            else if (saveload (0) == 1)
               stop = 1;
            redraw = 1;
         } else if (ptr == 1) { /* User selected "New Game" */
            stop = 2;
         } else if (ptr == 2) { /* Config */
            clear (double_buffer);
            config_menu ();
            redraw = 1;

            /* TODO: Save Global Settings Here */
         } else if (ptr == 3) { /* Exit */
            unload_datafile_object (bg);
            klog (_("Then exit you shall!"));
            return 2;
         }
      }
   }
   unload_datafile_object (bg);
   if (stop == 2) {
      /* New game init */
      for (a = 0; a < MAXCHRS; a++)
         memcpy (&party[a], &players[a].plr, sizeof (s_player));
      init_players ();
      memset (progress, 0, SIZE_PROGRESS);
      memset (treasure, 0, SIZE_TREASURE);
      numchrs = 0;
      for (a = 0; a < NUMSHOPS; a++) {
         for (b = 0; b < SHOPITEMS; b++)
            shops[a].items_current[b] = shops[a].items_max[b];
      }
      for (b = 0; b < 2; b++) {
         for (a = 0; a < MAX_INV; a++)
            g_inv[a][b] = 0;
      }
   }
   return stop - 1;
}
Exemplo n.º 30
0
int main()
{
 int exit_flag = 0, i;
 MAT16F tmat, modelmat;
 VEC3F pos = vec3f(0.0, 0.0, 0.5), ang = vec3f(0.0, 0.0, 0.0);

 int vnum, snum;
 VEC2F *map_vec2f;
 WALL_SEGMENT *map_segment;
 VERTEX *map_vertex;

 MD2_MODEL mdl;
 VERTEX *model_verts;
 TRI *model_tris;

 VERTEX floor[4];
 floor[0].local = vec3f(-200.0, 0.0, 200.0);
 floor[1].local = vec3f(200.0, 0.0, 200.0);
 floor[2].local = vec3f(200.0, 0.0, -200.0);
 floor[3].local = vec3f(-200.0, 0.0, -200.0);
 
  NODE *head = NULL;

 init();
 
 
  if(load_md2("data/babe.md2", &mdl))
  {
   allegro_message("Error: I need the MD2 model, stupid!");
   exit(1);
  }

 convert_md2_to_base(&model_verts, &model_tris, &mdl, 0.2);

 load_map("map.txt", &map_vec2f, &map_segment, &vnum, &snum, 1.0);

 head = (NODE *)malloc(sizeof(NODE));
 head->val = val;
 head->a = map_segment[0].a;
 head->b = map_segment[0].b;
 head->n = NORMALIZED_NORMAL_VEC2F(map_vec2f[map_segment[0].a], map_vec2f[map_segment[0].b]);
 head->parent = NULL;
 head->left = NULL;
 head->right = NULL;
 val++;
 
 for(i = 1; i < snum; i++)
  {
   add_node(head, &val, map_segment[i].a, map_segment[i].b, &map_vec2f, &vnum);
   val++;
  }
  
  map_vertex = (VERTEX *)malloc(vnum * 2 * sizeof(VERTEX));

 for(i = 0; i < vnum; i++)
  {
   map_vertex[i * 2].local = USCALE_VEC3F(vec3f(map_vec2f[i].x, 0.0, map_vec2f[i].y), 0.2);
   map_vertex[i * 2 + 1].local = USCALE_VEC3F(vec3f(map_vec2f[i].x, WALL_HEIGHT, map_vec2f[i].y), 0.2);
   map_vec2f[i] = USCALE_VEC2F(map_vec2f[i], 0.2);
  }

 LOCK_VARIABLE(fps);
 LOCK_VARIABLE(frame_count);
 LOCK_FUNCTION(update_fps);
 install_int(update_fps, 1000);

 float frame = 0.0;

 VEC3F cam_pos = vec3f(0.0, 3.0, 0.0), cam_dir, cam_dir_normal, cam_ang = vec3f(0.0, 0.0, 0.0);

 while(!exit_flag)
  {              
   set_texture_mapping_mode(0);

   int mx, my;
   get_mouse_mickeys(&mx, &my);
   position_mouse(SCREEN_W / 2, SCREEN_H / 2);

   cam_ang.x += my * 0.001;
   cam_ang.y -= mx * 0.001;
   cam_dir.x = SPEED * cos(0.5 * M_PI + cam_ang.y);
   cam_dir.y = 0.0;
   cam_dir.z = SPEED * sin(0.5 * M_PI + cam_ang.y);
   cam_dir_normal = vec3f(-cam_dir.z, 0.0, cam_dir.x);

   if(key[KEY_ESC]) { exit_flag = 1; }
   if(key[KEY_W]) { cam_pos = VEC3F_SUM(cam_pos, cam_dir); }
   if(key[KEY_S]) { cam_pos = VEC3F_DIFF(cam_pos, cam_dir); }
   if(key[KEY_A]) { cam_pos = VEC3F_SUM(cam_pos, cam_dir_normal); }
   if(key[KEY_D]) { cam_pos = VEC3F_DIFF(cam_pos, cam_dir_normal); }
   //if(key[KEY_SPACE]) { set_texture_mapping_mode(1); }

   reset_mat16f(tmat);
   translate_mat16f(tmat, -cam_pos.x, -cam_pos.y, -cam_pos.z);
   rotate_mat16f(tmat, -cam_ang.x, -cam_ang.y, 0.0);

   convert_md2_frame_to_base(model_verts, &mdl, frame, 0.2);
   frame += 0.1;
   reset_mat16f(modelmat);
   rotate_mat16f(modelmat, M_PI * 1.5, 0.0, 0.0);
   translate_mat16f(modelmat, 0.0, 5.0, 0.0);
   translate_mat16f(modelmat, -cam_pos.x, -cam_pos.y, -cam_pos.z);
   rotate_mat16f(modelmat, -cam_ang.x, -cam_ang.y, 0.0);

   for(i = 0; i < vnum * 2; i++)
    transform_vec3f(&map_vertex[i].world, map_vertex[i].local, tmat);
   for(i = 0; i < 4; i++)
    transform_vec3f(&floor[i].world, floor[i].local, tmat);
   for(i = 0; i < mdl.header.num_vertices; i++)
    transform_vec3f(&model_verts[i].world, model_verts[i].local, modelmat);

   clear_bitmap(buffer);
   clear_to_color(zbuffer, ZBUFFER_PRECISION);

   bind_texture(texture);

   VEC2F p = vec2f(cam_pos.x, cam_pos.z);
   VEC2F v = vec2f(cam_dir.x, cam_dir.z);
   traverse_tree(head, p, v, map_vec2f, map_vertex);

   bind_texture(skin);
   for(i = 0; i < mdl.header.num_tris; i++)
    {
     update_tri_normal(&model_tris[i], model_verts);
     model_tris[i].n = NORMALIZED_VEC3F(model_tris[i].n);
     if(cull_backface(&model_tris[i], model_verts))
      render_tri(&model_tris[i], model_verts);
    }
    
   bind_texture(texture2);
   TRI temp;
   temp.a = 0; temp.b = 1; temp.c = 2;
   temp.tex[0] = vec2f(0.0, 0.0); temp.tex[1] = vec2f(20.0, 0.0); temp.tex[2] = vec2f(20.0, 20.0);
   render_tri(&temp, floor);
   temp.a = 2; temp.b = 3; temp.c = 0;
   temp.tex[0] = vec2f(20.0, 20.0); temp.tex[1] = vec2f(20.0, 0.0); temp.tex[2] = vec2f(0.0, 0.0);
   render_tri(&temp, floor);

   textprintf_ex(buffer, font, 10, 10, makecol(255, 255, 255), 0, "FPS: %d", fps);
   blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
   frame_count++;
  }

 destroy_bitmap(texture2);
 destroy_tree(head);
 free_md2(&mdl);
 free(model_tris);
 free(model_verts);
 free(map_vertex);
 free(map_vec2f);
 free(map_segment);
 destroy_bitmap(skin);
 destroy_bitmap(texture);
 destroy_bitmap(zbuffer);
 destroy_bitmap(buffer);
 deinit_renderer();

 return 0;
}