Example #1
0
int tur_target_within_sight(turret_t *turret, int target_x, int target_y)
{
	int x, y;
	int map_x, map_y;
	turret_t *tp;
	game_data_t *gd;
	fixed angle, dx, dy;
	float bx, by;
	int i;
	int px, py, pc;
	
	dx = itofix((turret->x * 32 + 16) - target_x);
    dy = itofix((turret->y * 32 + 16) - target_y);    
    angle = fatan2(dy, dx) - itofix(64);
	
	x = turret->x * 32;
	y = turret->y * 32;
		
 	bx = x + turret->bitmap->w/2;
	by = y + turret->bitmap->h/2;

	gd = get_game_data_pointer();

	for (i = 0; i < turret->range / 15; i++) {
		float result;
		result = fixtof(fixcos(angle));
		by -= result * 15;
		result = fixtof(fixsin(angle));
		bx += result * 15;
		
		map_x = (int) bx / 32;
		map_y = (int) by / 32;
		
		if (map_x == target_x/32 && map_y == target_y/32)
			return 1;

		//putpixel(screen, bx, by, makecol(255,255,255));		
		
		tp = gd->turret;
		for (;;) {
			if (tp == NULL)
				break;
			if (tp != turret && (tp->x == map_x && tp->y == map_y)) {
				/* found a turret in this tile, check for pixel value */
				px = (int)bx - (map_x * 32);
				py = (int)by - (map_y * 32);
				pc = getpixel(tp->bitmap, px, py);
				if (pc != makecol(255, 0, 255)) {
					return 0;
				}
				
			}
			tp = tp->next;
		}				

	}	
	
	
	return 1;
}
Example #2
0
void Bullet::move(int to_x, int to_y)
{
    x += fixtof(fixcos(theta)) * speed;
    y += fixtof(fixsin(theta)) * speed;


    set_boundaries();
}
Example #3
0
void worm::shootrope() 
{
	ropex=x;
	ropey=y-4000; 
	ropexspd=fixtof(fixsin(ftofix(aim/1000.)))*3500*dir;
	ropeyspd=fixtof(fixcos(ftofix(aim/1000.)))*3500;
	rope_length=*game->ROPE_LENGHT;
	ropestate=1;
};
Example #4
0
static t_int *print_perform(t_int *w)
{
    t_print *x = (t_print *)(w[1]);
    t_sample *in = (t_sample *)(w[2]);
    int n = (int)(w[3]);
    if (x->x_count)
    {
    	post("%s:", x->x_sym->s_name);
    	if (n == 1) post("%8g", in[0]);
    	else if (n == 2) post("%8g %8g", in[0], in[1]);
    	else if (n == 4) post("%8g %8g %8g %8g",
    	    in[0], in[1], in[2], in[3]);
    	else while (n > 0)
    	{
    	    post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
    	    	fixtof(in[0]), 
		 fixtof(in[1]), 
		 fixtof(in[2]), 
		 fixtof(in[3]), 
		 fixtof(in[4]), 
		 fixtof(in[5]), 
		 fixtof(in[6]), 
		 fixtof(in[7]));
    	    n -= 8;
    	    in += 8;
    	}
    	x->x_count--;
    }
    return (w+4);
}
Example #5
0
/* get_vector_rotation_matrix:
 *  Constructs a 3d transformation matrix, which will rotate points around
 *  the specified x,y,z vector by the specified angle (given in the Allegro 
 *  fixed point, 256 degrees to a circle format), in a clockwise direction.
 */
void get_vector_rotation_matrix(MATRIX *m, fixed x, fixed y, fixed z, fixed a)
{
   MATRIX_f rotation;
   int i, j;
   ASSERT(m);

   get_vector_rotation_matrix_f(&rotation, fixtof(x), fixtof(y), fixtof(z), fixtof(a));

   for (i=0; i<3; i++)
      for (j=0; j<3; j++)
	 m->v[i][j] = ftofix(rotation.v[i][j]);

   m->t[0] = m->t[1] = m->t[2] = 0;
}
Example #6
0
const MATRIX_4x4 MATRIX_4x4::operator=(const MATRIX& b)
{
    int i,e;
    for(i = 0; i < 3; ++i)
    {
        for(e = 0;e < 3; ++e)
            E[i][e] = fixtof(b.v[e][i]);
    }
    E[3][0] = E[3][1] = E[3][2] = 0.0f;
    E[3][3] = 1.0f;

    for(i = 0;i < 3; ++i)
        E[i][3] = fixtof(b.t[i]);

    return (*this);
}
Example #7
0
int main(void)
{
   /* declare three 32 bit (16.16) fixed point variables */
   fixed x, y, z;

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

   /* convert integers to fixed point like this */
   x = itofix(10);

   /* convert floating point to fixed point like this */
   y = ftofix(3.14);

   /* fixed point variables can be assigned, added, subtracted, negated,
    * and compared just like integers, eg: 
    */
   z = x + y;
   allegro_message("%f + %f = %f\n", fixtof(x), fixtof(y), fixtof(z));

   /* you can't add integers or floating point to fixed point, though:
    *    z = x + 3;
    * would give the wrong result.
    */

   /* fixed point variables can be multiplied or divided by integers or
    * floating point numbers, eg:
    */
   z = y * 2;
   allegro_message("%f * 2 = %f\n", fixtof(y), fixtof(z));

   /* you can't multiply or divide two fixed point numbers, though:
    *    z = x * y;
    * would give the wrong result. Use fixmul() and fixdiv() instead, eg:
    */
   z = fixmul(x, y);
   allegro_message("%f * %f = %f\n", fixtof(x), fixtof(y), fixtof(z));

   /* fixed point trig and square root are also available, eg: */
   z = fixsqrt(x);
   allegro_message("fixsqrt(%f) = %f\n", fixtof(x), fixtof(z));

   return 0;
}
Example #8
0
/* fsqrt:
 *  Fixed point square root routine for non-i386.
 */
fixed fsqrt(fixed x)
{
   if (x > 0)
      return ftofix(sqrt(fixtof(x)));

   if (x < 0)
      errno = EDOM;

   return 0;
}
Example #9
0
/* fixsqrt:
 *  Fixed point square root routine for non-i386.
 */
fixed fixsqrt(fixed x)
{
   if (x > 0)
      return ftofix(sqrt(fixtof(x)));

   if (x < 0)
      *allegro_errno = EDOM;

   return 0;
}
Example #10
0
void C4Sky::Draw(C4TargetFacet &cgo)
{
	// background color?
	if (BackClrEnabled) pDraw->DrawBoxDw(cgo.Surface, cgo.X, cgo.Y, cgo.X+cgo.Wdt, cgo.Y+cgo.Hgt, BackClr);
	// sky surface?
	if (Modulation != 0xffffffff) pDraw->ActivateBlitModulation(Modulation);
	C4ShaderCall call(pDraw->GetFoW() ? &ShaderLight : &Shader); // call is started in C4Draw
	if (Surface)
	{
		// blit parallax sky
		float zoom = cgo.Zoom;
		float targetx = cgo.TargetX; float targety = cgo.TargetY;

		float parx = 10.0f / ParX; float pary = 10.0f / ParY;
		float par = parx; //todo: pary?

		// Step 1: project to landscape coordinates
		float resultzoom = 1.0 / (1.0 - (par - par/zoom));

		float rx = ((1 - parx) * targetx) * resultzoom + fixtof(x) / (parx + zoom - parx * zoom);
		float ry = ((1 - pary) * targety) * resultzoom + fixtof(y) / (pary + zoom - pary * zoom);

		// Step 2: convert to screen coordinates
		float resultx = (rx - targetx) * zoom / resultzoom;
		float resulty = (ry - targety) * zoom / resultzoom;

		ZoomDataStackItem zdsi(resultzoom);

		pDraw->BlitSurfaceTile(Surface, cgo.Surface, cgo.X, cgo.Y, cgo.Wdt * zoom / resultzoom, cgo.Hgt * zoom / resultzoom, -resultx, -resulty, &call);
	}
	else
	{
		// no sky surface: blit sky fade
		DWORD dwClr1=GetSkyFadeClr(cgo.TargetY);
		DWORD dwClr2=GetSkyFadeClr(cgo.TargetY+cgo.Hgt);
		pDraw->DrawBoxFade(cgo.Surface, cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt, dwClr1, dwClr1, dwClr2, dwClr2, &call);
	}
	if (Modulation != 0xffffffff) pDraw->DeactivateBlitModulation();
	// done
}
Example #11
0
void tur_draw_turret(BITMAP *dest, turret_t *turret)
{
	int x, y;
	float bx, by;
	int i;
	
	x = turret->x * 32;
	y = turret->y * 32;
		
	/* XXX/DEBUG: SHOW ANGLE */
 	bx = x + turret->bitmap->w/2;
	by = y + turret->bitmap->h/2;
	drawing_mode(DRAW_MODE_TRANS,NULL,0,0);
    set_trans_blender(0,0,0,100);
	for (i = 0; i < turret->range; i += 10) {
		float result;
		result = fixtof(fixcos(turret->angle));
		by -= result * 10;
		result = fixtof(fixsin(turret->angle));
		bx += result * 10;			
		//putpixel(dest, bx, by, makecol(255,255,0));
		//putpixel(dest, bx+1, by, makecol(255,255,0));
	}
	solid_mode();
	/* ---- */

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


	/* turret */
	rotate_sprite(dest, turret->bitmap, turret->x * 32, turret->y * 32, turret->angle);
	
}
Example #12
0
void cmd_syntax(){
    // SYNTAX command.
    int i,got=-1;

    // Make sure we are checking the syntax of something.
    for(i=0;i<max_cmds;i++){
        if(strcmp(parse_words[1],con_cmds[i].name)==0){got=i;}
    }

    // Now display the syntax.
    if(got>=0){
        if(con_cmds[got].type=='C'){
            con_printf("  type : console command");
            sprintf(saybuf,"  args : %d",con_cmds[got].max);
            con_printf(saybuf);
        }
        if(con_cmds[got].type=='I'){
            con_printf("  type : integer variable");
            sprintf(saybuf,"  min  : %d",con_cmds[got].min);
            con_printf(saybuf);
            sprintf(saybuf,"  max  : %d",con_cmds[got].max);
            con_printf(saybuf);
        }
        if(con_cmds[got].type=='F'){
            con_printf("  type : fixed point variable");
            sprintf(saybuf,"  min  : %f",fixtof(con_cmds[got].min));
            con_printf(saybuf);
            sprintf(saybuf,"  max  : %f",fixtof(con_cmds[got].max));
            con_printf(saybuf);
        }
        if(con_cmds[got].type=='S'){
            con_printf("  type : string variable");
        }
        con_printf(" ");
    }
}
Example #13
0
bullet *create_bullet(int x, int y, fixed angle) {
    bullet *ret;
    ret = malloc(sizeof(bullet));
    
    memset(ret, 0, sizeof(bullet));
    ret->x = x;
    ret->y = y;
    ret->rad = 1;
    ret->tr = 30;
    ret->f = M_PI*2;
    ret->c = 0.;
    ret->angle = fixtof(angle);
    
    
    return ret;
}    
Example #14
0
void view_variable(int n){
    // Displays the contents of a variable to the console.
    if(con_cmds[n].type=='F'){
        // It's a FIXED variable.
        sprintf(saybuf,"%s is %c%f%c",con_cmds[n].name,34,fixtof(con_cmds[n].mirror),34);
    }
    if(con_cmds[n].type=='I'){
        // It's an INT.
        sprintf(saybuf,"%s is %c%d%c",con_cmds[n].name,34,con_cmds[n].mirror,34);
    }
    if(con_cmds[n].type=='S'){
        // It's a string.
        sprintf(saybuf,"%s is %c%s%c",con_cmds[n].name,34,con_cmds[n].s_mirror,34);
    }
    con_printf(saybuf);
}
Example #15
0
/* draws the spline paths */
void draw_splines(void)
{
   int i;

   acquire_screen();

   clear_to_color(screen, makecol(255, 255, 255));

   textout_centre_ex(screen, font, "Spline curve path", SCREEN_W/2, 8,
		     palette_color[255], palette_color[0]);
   textprintf_centre_ex(screen, font, SCREEN_W/2, 32, palette_color[255],
			palette_color[0], "Curviness = %.2f",
			fixtof(curviness));
   textout_centre_ex(screen, font, "Up/down keys to alter", SCREEN_W/2, 44,
		     palette_color[255], palette_color[0]);
   textout_centre_ex(screen, font, "Space to walk", SCREEN_W/2, 68,
		     palette_color[255], palette_color[0]);
   textout_centre_ex(screen, font, "C to display control points", SCREEN_W/2,
		     92, palette_color[255], palette_color[0]);
   textout_centre_ex(screen, font, "T to display tangents", SCREEN_W/2, 104,
		     palette_color[255], palette_color[0]);

   for (i=1; i<node_count-2; i++)
      draw_spline(nodes[i], nodes[i+1]);

   for (i=1; i<node_count-1; i++) {
      draw_node(i);

      if (show_tangents) {
	 line(screen, nodes[i].x - fixtoi(fixcos(nodes[i].tangent) * 24),
		      nodes[i].y - fixtoi(fixsin(nodes[i].tangent) * 24),
		      nodes[i].x + fixtoi(fixcos(nodes[i].tangent) * 24),
		      nodes[i].y + fixtoi(fixsin(nodes[i].tangent) * 24),
		      palette_color[1]);
      }
   }

   release_screen();
}
Example #16
0
void cmd_gamma(){
    // Builds GAMMA_PAL from BASE_PAL and GAMMA.
    // DEBUG: The gamma correction formula could be improved.
    int i;
    float r,g,b,delta;

    // Initiate.
    delta=128.0/(fixtof(player_gamma)+1.0)-64.0;

    // Convert each color.
    for(i=0;i<256;i++){
        // Fetch the base colors.
        r=base_pal[i].r;
        g=base_pal[i].g;
        b=base_pal[i].b;

        // Apply the gamma fix to each color-component.
        r+=delta;
        g+=delta;
        b+=delta;

        // Make sure that we're in range.
        if(r<0){r=0;}
        if(g<0){g=0;}
        if(b<0){b=0;}
        if(r>63){r=63;}
        if(g>63){g=63;}
        if(b>63){b=63;}

        // Store the new gamma colors.
        gamma_pal[i].r=r;
        gamma_pal[i].g=g;
        gamma_pal[i].b=b;
    }

    // Now set the new palette.
    set_palette(gamma_pal);
}
Example #17
0
void internal_writeconfig(){
    // Writes a config file.
    struct date d;
    FILE *fp;
    int i;

    // Open the file.
    fp=fopen("DJDOOM.CFG","wt");

    // Write the standard header.
    getdate(&d);
    fprintf(fp,"// FILE         : DJDOOM.CFG\n");
    fprintf(fp,"// COMMENT      : DJDOOM v1.0 startup config file\n");
    fprintf(fp,"// DATE CREATED : %d.%d.%d\n",d.da_day,d.da_mon,d.da_year);
    fprintf(fp,"\n");

    // Write out all the console variables.
    fprintf(fp,"// VARIABLES:\n");
    fprintf(fp,"\n");
    for(i=0;i<max_cmds;i++){
        if(con_cmds[i].type=='F'){
            // It's a FIXED variable.
            fprintf(fp,"%s %c%f%c\n",con_cmds[i].name,34,fixtof(con_cmds[i].mirror),34);
        }
        if(con_cmds[i].type=='I'){
            // It's an INT.
            fprintf(fp,"%s %c%d%c\n",con_cmds[i].name,34,con_cmds[i].mirror,34);
        }
        if(con_cmds[i].type=='S'){
            // It's a string.
            fprintf(fp,"%s %c%s%c\n",con_cmds[i].name,34,con_cmds[i].s_mirror,34);
        }
    }
    fprintf(fp,"\n");

    // Close the file.
    fclose(fp);
}
Example #18
0
int exec_parsed(){
    // Execs a parsed command line.
    int error=0,i,got=-1,n;

    // Now execute the command.
    if(parse_nwords!=0){
         // Search for a matching known command.
         for(i=0;i<max_cmds;i++){
             if(strcmp(con_cmds[i].name,parse_words[0])==0){
                got=i;
             }
         }

         if(got>=0){
             // Make sure that we have the correct number of arguments for a command.
             if(con_cmds[got].type=='C'){
                 if(parse_nwords!=con_cmds[got].max+1){
                     got=-2;
                 }
             }
             // If we have a variable, deal with it here.
             else{
                 // No arguments means view the variable.
                 if(parse_nwords==1){
                     view_variable(got);
                     got=1000;
                 }

                 // One argument means set the variable.
                 if(parse_nwords==2){

                     // Find the value to set the variable to.
                     if(con_cmds[got].type=='F'){
                         // It's a FIXED variable.
                         n=ftofix(atof(parse_words[1]));
                     }
                     if(con_cmds[got].type=='I'){
                         // It's an INT.
                         n=atoi(parse_words[1]);
                     }
                     if(con_cmds[got].type=='S'){
                         // It's a string.
                         internal_setstring(con_cmds[got].s_mirror,parse_words[1]);
                     }
                     else{
                         // Put the value within limits.
                         if(n<con_cmds[got].min){n=con_cmds[got].min;}
                         if(n>con_cmds[got].max){n=con_cmds[got].max;}

                         // Set the mirror to the value.
                         con_cmds[got].mirror=n;
                     }
                 }

                 // If we don't have one or two arguments, then its an error.
                 if(parse_nwords>2){
                     got=-2;
                 }
             }
         }

         // Execute an actual command, or set a given variable.
         switch(got){
             case -1: internal_error();break;
             case  0: cmd_clear();break;
             case  1: player_crosshair=n;break;
             case  2: player_crosshair_color=n;break;
             case  3: cmd_dir();break;
             case  4: cmd_disconnect();break;
             case  5: cmd_exec();break;
             case  6: player_floors=n;break;
             case  7: player_fov_degrees=fixtof(n);break;
             case  8: player_fps=n;break;
             case  9: player_gamma=n;cmd_gamma();break;
             case 10: player_gfx_mode=n;cmd_gfx_mode();break;
             case 11: cmd_gfx_modes();break;
             case 12: player_heightfix=n;break;
             case 13: player_invert=n;break;
             case 14: light_con=n;break;
             case 15: light_depth=fixtof(n);break;
             case 16: cmd_loopdemo();break;
             case 17: cmd_map();break;
             case 18: cmd_mapinfo();break;
             case 19: player_map_rotate=n;break;
             case 20: player_map=n;break;
             case 21: player_map_size=n;break;
             case 22: cmd_mem();break;
             case 23: internal_setstring(player_pic_con,parse_words[1]);
                      cmd_pic_con();break;
             case 24: cmd_playdemo();break;
             case 25: cmd_pwad();break;
             case 26: cmd_quit();break;
             case 27: cmd_recdemo();break;
             case 28: player_r_grad=n;break;
             case 29: player_r_gun=n;break;
             case 30: cmd_stop();break;
             case 31: cmd_syntax();break;
             case 32: cmd_time();break;
             case 33: cmd_timerefresh();break;
             case 34: player_trace=1;break;
             case 35: cmd_viewpic();break;
             case 36: cmd_viewtex();break;
             case 37: player_vsync=n;break;
             case 38: cmd_wads();break;
             case 39: player_walls=n;break;
             case 40: player_windowsize=n;break;
         }
    }

    // Return the error value. DEBUG: Do we use this?
    return(error);
}
Example #19
0
/* fixhypot:
 *  Fixed point sqrt (x*x+y*y) for non-i386.
 */
fixed fixhypot(fixed x, fixed y)
{
   return ftofix(hypot(fixtof(x), fixtof(y)));
}
Example #20
0
int32_t FnFxFireTimer(C4AulContext *ctx, C4Object *pObj, int32_t iNumber,
                      int32_t iTime) {
  // safety
  if (!pObj)
    return C4Fx_Execute_Kill;

  // get cause
  int32_t iCausedByPlr = NO_OWNER;
  C4Effect *pEffect;
  if (pEffect = pObj->pEffects)
    if (pEffect = pEffect->Get(iNumber, true)) {
      iCausedByPlr = FxFireVarCausedBy(pEffect).getInt();
      if (!ValidPlr(iCausedByPlr))
        iCausedByPlr = NO_OWNER;
    }

  // causes on object
  pObj->ExecFire(iNumber, iCausedByPlr);

  // special effects only if loaded
  if (!Game.Particles.IsFireParticleLoaded())
    return C4Fx_OK;

  // get effect: May be NULL after object fire execution, in which case the fire
  // has been extinguished
  if (!pObj->GetOnFire())
    return C4Fx_Execute_Kill;
  if (!(pEffect = pObj->pEffects))
    return C4Fx_Execute_Kill;
  if (!(pEffect = pEffect->Get(iNumber, true)))
    return C4Fx_Execute_Kill;

  /* Fire execution behaviour transferred from script (FIRE) */

  // get fire mode
  int32_t iFireMode = FxFireVarMode(pEffect).getInt();

  // special effects only each four frames, except for objects (e.g.:
  // Projectiles)
  if (iTime % 4 && iFireMode != C4Fx_FireMode_Object)
    return C4Fx_OK;

  // no gfx for contained
  if (pObj->Contained)
    return C4Fx_OK;

  // some constant effect parameters for this object
  int32_t iWidth = Max<int32_t>(pObj->Def->Shape.Wdt, 1),
          iHeight = pObj->Def->Shape.Hgt,
          iYOff = iHeight / 2 - pObj->Def->Shape.FireTop;

  int32_t iCount = int32_t(sqrt(double(iWidth * iHeight)) /
                           4); // Number of particles per execution
  const int32_t iBaseParticleSize =
      30; // With of particles in pixels/10, w/o add of values below
  const int32_t iParticleSizeDiff = 10; // Size variation among particles
  const int32_t iRelParticleSize =
      12; // Influence of object size on particle size

  // some varying effect parameters
  int32_t iX = pObj->x, iY = pObj->y;
  int32_t iXDir, iYDir, iCon, iWdtCon, iA, iSize;

  // get remainign size (%)
  iCon = iWdtCon = Max<int32_t>((100 * pObj->GetCon()) / FullCon, 1);
  if (!pObj->Def->GrowthType)
    // fixed width for not-stretched-objects
    if (iWdtCon < 100)
      iWdtCon = 100;

  // regard non-center object offsets
  iX += pObj->Shape.x + pObj->Shape.Wdt / 2;
  iY += pObj->Shape.y + pObj->Shape.Hgt / 2;

  // apply rotation
  float fRot[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
  if (pObj->r && pObj->Def->Rotateable) {
    fRot[0] = (float)cosf((float)(pObj->r * pi / 180.0));
    fRot[1] = (float)-sinf((float)(pObj->r * pi / 180.0));
    fRot[2] = -fRot[1];
    fRot[3] = fRot[0];
    // rotated objects usually better burn from the center
    if (iYOff > 0)
      iYOff = 0;
  }

  // Adjust particle number by con
  iCount = Max(2, iCount * iWdtCon / 100);

  // calc base for particle size parameter
  iA = (int32_t)(sqrt(sqrt(double(iWidth * iHeight)) * (iCon + 20) / 120) *
                 iRelParticleSize);

  // create a double set of particles; first quarter normal (Fire); remaining
  // three quarters additive (Fire2)
  for (int32_t i = 0; i < iCount * 2; ++i) {
    // calc actual size to be used in this frame
    // Using Random instead of SafeRandom would be safe here
    // However, since it's just affecting particles there's no need to use
    // synchronized random values
    iSize = SafeRandom(iParticleSizeDiff + 1) + iBaseParticleSize -
            iParticleSizeDiff / 2 - 1 + iA;

    // get particle target list
    C4ParticleList *pParticleList =
        SafeRandom(4) ? &(pObj->BackParticles) : &(pObj->FrontParticles);

    // get particle def and color
    C4ParticleDef *pPartDef;
    DWORD dwClr;
    if (i < iCount / 2) {
      dwClr = 0x32004000 + ((SafeRandom(59) + 196) << 16);
      pPartDef = Game.Particles.pFire1;
    } else {
      dwClr = 0xffffff;
      pPartDef = Game.Particles.pFire2;
    }
    if (iFireMode == C4Fx_FireMode_Object)
      dwClr += 0x62000000;

    // get particle creation pos...
    int32_t iRandX = SafeRandom(iWidth + 1) - iWidth / 2 - 1;

    int32_t iPx = iRandX * iWdtCon / 100;
    int32_t iPy = iYOff * iCon / 100;
    if (iFireMode == C4Fx_FireMode_LivingVeg)
      iPy -= iPx * iPx * 100 / iWidth /
             iWdtCon; // parable form particle pos on livings

    // ...and movement speed
    if (iFireMode != C4Fx_FireMode_Object) {
      // ...for normal fire proc
      iXDir = iRandX * iCon / 400 - int32_t(iPx / 3) -
              int32_t(fixtof(pObj->xdir) * 3);
      iYDir = -SafeRandom(15 + iHeight * iCon / 300) - 1 -
              int32_t(fixtof(pObj->ydir) * 3);
    } else {
      // ...for objects
      iXDir = -int32_t(fixtof(pObj->xdir) * 3);
      iYDir = -int32_t(fixtof(pObj->ydir) * 3);
      if (!iYDir)
        iYDir = -SafeRandom(13 + iHeight / 4) - 1;
    }

    // OK; create it!
    Game.Particles.Create(pPartDef, float(iX) + fRot[0] * iPx + fRot[1] * iPy,
                          float(iY) + fRot[2] * iPx + fRot[3] * iPy,
                          (float)iXDir / 10.0f, (float)iYDir / 10.0f,
                          (float)iSize / 10.0f, dwClr, pParticleList, pObj);
  }

  return C4Fx_OK;
}
Example #21
0
void worm::checkevents()
{
  while (node->checkEventWaiting()) 
  {
    ZCom_Node::eEvent type;            // event type
    eZCom_NodeRole    remote_role;     // role of remote sender
    ZCom_ConnID       conn_id;         // connection id of sender
    int event;
  
    ZCom_BitStream *data = node->getNextEvent(&type, &remote_role, &conn_id);
    if (type == ZCom_Node::eEvent_AuthorityRemoved)
		{
			con->log.create_msg("PLAYER REMOVED");
			deleteme = true;
		} else
    if (type == ZCom_Node::eEvent_User)
    {
      event=data->getInt(8);
      if(event==4)
      {
        strcpy(name,data->getStringStatic());
      }else if(event==3)
      {
        char msg[1024],msg2[1024];
        strcpy(msg,data->getStringStatic());
        sprintf(msg2,"[%s] %s",name,msg);
        //strcat(msg2,msg);
        con->log.create_msg(msg2);
        con->echolist.add_echo(msg2);
        if (node->getRole()==eZCom_RoleAuthority)
        {
          sendmsg(msg);
        };
        play_sample(game->menu_select->snd, *game->VOLUME, 127, 1300, 0);
      }else if(event==2)
      {
        int o;
        int _x=data->getInt(32);
        int _y=data->getInt(32);
        int _xspd=data->getInt(32);
        int _yspd=data->getInt(32);
        int _t=data->getInt(32);
        srand(_t);
        for (o=0;o<14;o++)
          partlist.shoot_part(rand()%1000*255,(rand()%200)+600,1,_x,_y-4000,_xspd/2,_yspd/2,this,game->gore);
        play_sample(game->death->snd, *game->VOLUME, 127, 1000, 0);
        deaths++;
        health=0;
        if (*game->RESPAWN_RELOAD==1)
        recharge_weapons(this);
      }else if(event==1)
      {
        int _x=data->getInt(32);
        int _y=data->getInt(32);
        int _xspd=data->getInt(32);
        int _yspd=data->getInt(32);
        int _ang=data->getInt(32);
        int _dir=data->getSignedInt(8);
        int _weap=data->getInt(16);
        int _t=data->getInt(32);
            srand(_t);
            fireing=true;
            weap[curr_weap].ammo--;
              if (weaps->num[_weap]->shoot_num!=0)
              {
                int dist,spd_rnd,xof,yof,h;
                
                for (h=0;h<weaps->num[_weap]->shoot_num;h++)
                {
                  dist=((rand()%1000)*weaps->num[_weap]->distribution)-weaps->num[_weap]->distribution/2*1000;
                  if (weaps->num[_weap]->shoot_spd_rnd!=0)
                    spd_rnd=(rand()%weaps->num[_weap]->shoot_spd_rnd)-weaps->num[_weap]->shoot_spd_rnd/2;
                  else spd_rnd=0;
                  xof=fixtof(fixsin(ftofix((_ang-dist)/1000.)))*(int)(weaps->num[_weap]->shoot_obj->detect_range+1000)*_dir;
                  yof=fixtof(fixcos(ftofix((_ang-dist)/1000.)))*(int)(weaps->num[_weap]->shoot_obj->detect_range+1000);
                  partlist.shoot_part(_ang-dist,weaps->num[_weap]->shoot_spd-spd_rnd,_dir,_x+xof,_y-4000+yof,_xspd*(weaps->num[_weap]->affected_motion/1000.),_yspd*(weaps->num[_weap]->affected_motion/1000.),this,weaps->num[_weap]->shoot_obj);
                };
                if (weaps->num[_weap]->aim_recoil!=0)
                  aim_recoil_speed+=(100*weaps->num[_weap]->aim_recoil);/*-weap[curr_weap].weap->aim_recoil/2*1000;*/
                if (weaps->num[_weap]->recoil!=0)
                {
                  xspd = xspd + -fixtof(fixsin(ftofix(_ang/1000.)))*weaps->num[_weap]->recoil*_dir;
                  yspd = yspd + -fixtof(fixcos(ftofix(_ang/1000.)))*weaps->num[_weap]->recoil;
                };
              };
              weap[curr_weap].shoot_time=0;
              firecone_time=weaps->num[_weap]->firecone_timeout;
              curr_firecone=weaps->num[_weap]->firecone;
              if (weaps->num[_weap]->shoot_sound!=NULL)
              {
                //if (weap->loop_sound!=1)
                play_sample(weaps->num[_weap]->shoot_sound->snd, *game->VOLUME, 127, 1000, 0);
                /*else if (!sound_loop)
                {
                play_sample(weap->shoot_sound->snd, 255, 127, 1000, 1);
                sound_loop=true;
                };*/
              };
            };
      };
    }
};
Example #22
0
static void snapshot_tilde_bang(t_snapshot *x)
{
    outlet_float(x->x_obj.ob_outlet, fixtof(x->x_value));
}
Example #23
0
void evaluatePhysics()
{
   if (theShip.x > MAPWIDTH)
	{
      theShip.x = MAPWIDTH;
      theShip.velX *= -1;
	}
   if (theShip.x < 0)
	{
      theShip.x = 0;
      theShip.velX *= -1;
	}
   if (theShip.y > 768)
	{
      theShip.y = 768;
      theShip.velY *= -1;
	}
   if (theShip.y < 0)
	{
      theShip.y = 0;
      theShip.velY *= -1;
	}
   theShip.rotation += theShip.velRotation;
	theShip.velX += fixtof(fixsin(ftofix(theShip.rotation))) * (theShip.rocketPower/theShip.mass) * 0.99;
	theShip.velY -= fixtof(fixcos(ftofix(theShip.rotation))) * (theShip.rocketPower/theShip.mass) * 0.99;
	theShip.x += theShip.velX;
	theShip.y += theShip.velY;


	OBJECT *theRock = rockHeader;
	static float distance;
	static float diffX;
	static float diffY;
	static float fG;
	static float fGX;
	static float fGY;
	static float rockX;
	static float rockY;
	static float shipX;
	static float shipY;
	shipX = theShip.x + (theShip.width / 2);
	shipY = theShip.y + (theShip.height / 2);
	while (theRock != NULL)
	{
		rockX = theRock->x + (theRock->width) / 2;
	   rockY = theRock->y + (theRock->height) / 2;
		diffX = (shipX - rockX);
		diffY = (shipY - rockY);
		distance = (pow(pow(diffX, 2)+ pow(diffY, 2), 0.5));
		fG = 25 * theShip.mass * theRock->mass / pow(distance, 2);
		fGX = fixtof(fixcos(fixatan(ftofix(diffY/diffX)))) * fG / theShip.mass;
		fGY = fixtof(fixsin(fixatan(ftofix(diffY/diffX)))) * fG / theShip.mass;
		theShip.velX += ((shipX > rockX) ? -fGX : fGX);
		theShip.velY += ((shipX > rockX) ? -fGY : fGY);

	   putpixel(screenBuffer, (int)shipX, (int)shipY, makecol(255, 255, 255));

		if (shipX > theRock->x && shipX < theRock->x + theRock->width)
		{
   		if (shipY > theRock->y && shipY < theRock->y + theRock->height)
			{
				theShip.x = 462;
				theShip.y = 359;
				theShip.rotation = 0;
				theShip.velRotation = 0;
				theShip.velX = 0;
				theShip.velY = 0;
				theShip.fuel = theShip.maxFuel;
				if (currentTime > highTime)
				{
					highTime = currentTime;
				}
				currentTime = 0;
			}
		}

		theRock = theRock->next;
	}

}
Example #24
0
void C4PXSSystem::Draw(C4TargetFacet &cgo)
{
	// Draw PXS in this region
	C4Rect VisibleRect(cgo.TargetX, cgo.TargetY, cgo.Wdt, cgo.Hgt);
	VisibleRect.Enlarge(20);

	// Go through all PXS and build vertex arrays. The vertex arrays are
	// then submitted to the GL in one go.
	std::vector<C4BltVertex> pixVtx;
	std::vector<C4BltVertex> lineVtx;
	std::map<int, std::vector<C4BltVertex> > bltVtx;
	// TODO: reserve some space to avoid too many allocations
	// TODO: keep vertex mem allocated between draw invocations

	float cgox = cgo.X - cgo.TargetX, cgoy = cgo.Y - cgo.TargetY;
	// First pass: draw simple PXS (lines/pixels)
	unsigned int cnt;
	for (cnt=0; cnt < PXSMaxChunk; cnt++)
	{
		if (Chunk[cnt] && iChunkPXS[cnt])
		{
			C4PXS *pxp = Chunk[cnt];
			for (unsigned int cnt2 = 0; cnt2 < PXSChunkSize; cnt2++, pxp++)
				if (pxp->Mat != MNone && VisibleRect.Contains(fixtoi(pxp->x), fixtoi(pxp->y)))
				{
					C4Material *pMat = &::MaterialMap.Map[pxp->Mat];
					const DWORD dwMatClr = ::Landscape.GetPal()->GetClr((BYTE) (Mat2PixColDefault(pxp->Mat)));
					if(pMat->PXSFace.Surface)
					{
						int32_t pnx, pny;
						pMat->PXSFace.GetPhaseNum(pnx, pny);
						int32_t fcWdt = pMat->PXSFace.Wdt;
						int32_t fcHgt = pMat->PXSFace.Hgt;
						// calculate draw width and tile to use (random-ish)
						uint32_t size = (1103515245 * (cnt * PXSChunkSize + cnt2) + 12345) >> 3;
						float z = pMat->PXSGfxSize * (0.625f + 0.05f * int(size % 16));
						pny = (cnt2 / pnx) % pny; pnx = cnt2 % pnx;

						const float w = z;
						const float h = z * fcHgt / fcWdt;
						const float x1 = fixtof(pxp->x) + cgox + z * pMat->PXSGfxRt.tx / fcWdt;
						const float y1 = fixtof(pxp->y) + cgoy + z * pMat->PXSGfxRt.ty / fcHgt;
						const float x2 = x1 + w;
						const float y2 = y1 + h;

						const float sfcWdt = pMat->PXSFace.Surface->Wdt;
						const float sfcHgt = pMat->PXSFace.Surface->Hgt;

						C4BltVertex vtx[6];
						vtx[0].tx = (pnx + 0.f) * fcWdt / sfcWdt; vtx[0].ty = (pny + 0.f) * fcHgt / sfcHgt;
						vtx[0].ftx = x1; vtx[0].fty = y1;
						vtx[1].tx = (pnx + 1.f) * fcWdt / sfcWdt; vtx[1].ty = (pny + 0.f) * fcHgt / sfcHgt;
						vtx[1].ftx = x2; vtx[1].fty = y1;
						vtx[2].tx = (pnx + 1.f) * fcWdt / sfcWdt; vtx[2].ty = (pny + 1.f) * fcHgt / sfcHgt;
						vtx[2].ftx = x2; vtx[2].fty = y2;
						vtx[3].tx = (pnx + 0.f) * fcWdt / sfcWdt; vtx[3].ty = (pny + 1.f) * fcHgt / sfcHgt;
						vtx[3].ftx = x1; vtx[3].fty = y2;
						DwTo4UB(0xFFFFFFFF, vtx[0].color);
						DwTo4UB(0xFFFFFFFF, vtx[1].color);
						DwTo4UB(0xFFFFFFFF, vtx[2].color);
						DwTo4UB(0xFFFFFFFF, vtx[3].color);
						vtx[4] = vtx[2];
						vtx[5] = vtx[0];

						std::vector<C4BltVertex>& vec = bltVtx[pxp->Mat];
						vec.push_back(vtx[0]);
						vec.push_back(vtx[1]);
						vec.push_back(vtx[2]);
						vec.push_back(vtx[3]);
						vec.push_back(vtx[4]);
						vec.push_back(vtx[5]);
					}
					else
					{
						// old-style: unicolored pixels or lines
						if (fixtoi(pxp->xdir) || fixtoi(pxp->ydir))
Example #25
0
						vec.push_back(vtx[1]);
						vec.push_back(vtx[2]);
						vec.push_back(vtx[3]);
						vec.push_back(vtx[4]);
						vec.push_back(vtx[5]);
					}
					else
					{
						// old-style: unicolored pixels or lines
						if (fixtoi(pxp->xdir) || fixtoi(pxp->ydir))
						{
							// lines for stuff that goes whooosh!
							int len = fixtoi(Abs(pxp->xdir) + Abs(pxp->ydir));
							const DWORD dwMatClrLen = uint32_t(std::max<int>(dwMatClr >> 24, 195 - (195 - (dwMatClr >> 24)) / len)) << 24 | (dwMatClr & 0xffffff);
							C4BltVertex begin, end;
							begin.ftx = fixtof(pxp->x - pxp->xdir) + cgox; begin.fty = fixtof(pxp->y - pxp->ydir) + cgoy;
							end.ftx = fixtof(pxp->x) + cgox; end.fty = fixtof(pxp->y) + cgoy;
							DwTo4UB(dwMatClrLen, begin.color);
							DwTo4UB(dwMatClrLen, end.color);
							lineVtx.push_back(begin);
							lineVtx.push_back(end);
						}
						else
						{
							// single pixels for slow stuff
							C4BltVertex vtx;
							vtx.ftx = fixtof(pxp->x) + cgox;
							vtx.fty = fixtof(pxp->y) + cgoy;
							DwTo4UB(dwMatClr, vtx.color);
							pixVtx.push_back(vtx);
						}
Example #26
0
void C4ParticleChunk::Draw(C4TargetFacet cgo, C4Object *obj, C4ShaderCall& call, int texUnit, const StdProjectionMatrix& modelview)
{
	if (particleCount == 0) return;
	const int stride = sizeof(C4Particle::DrawingData::Vertex);
	assert(sourceDefinition && "No source definition assigned to particle chunk.");
	C4TexRef *textureRef = &sourceDefinition->Gfx.GetFace().textures[0];
	assert(textureRef != 0 && "Particle definition had no texture assigned.");

	// use a relative offset?
	// (note the normal matrix is unaffected by this)
	if ((attachment & C4ATTACH_MoveRelative) && (obj != 0))
	{
		StdProjectionMatrix new_modelview(modelview);
		Translate(new_modelview, fixtof(obj->GetFixedX()), fixtof(obj->GetFixedY()), 0.0f);
		call.SetUniformMatrix4x4(C4SSU_ModelViewMatrix, new_modelview);
	}
	else
	{
		call.SetUniformMatrix4x4(C4SSU_ModelViewMatrix, modelview);
	}

	// enable additive blending for particles with that blit mode
	glBlendFunc(GL_SRC_ALPHA, (blitMode & C4GFXBLIT_ADDITIVE) ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA);

	glActiveTexture(texUnit);
	glBindTexture(GL_TEXTURE_2D, textureRef->texName);

	// generate the buffer as necessary
	if (drawingDataVertexBufferObject == 0)
	{
		// clear up old data
		ClearBufferObjects();
		// generate new buffer objects
		glGenBuffers(1, &drawingDataVertexBufferObject);
		assert (drawingDataVertexBufferObject != 0 && "Could not generate OpenGL buffer object.");
		// Immediately bind the buffer.
		// glVertexAttribPointer requires a valid GL_ARRAY_BUFFER to be bound and we need the buffer to be created for glObjectLabel.
		glBindBuffer(GL_ARRAY_BUFFER, drawingDataVertexBufferObject);

#ifdef GL_KHR_debug
		if (glObjectLabel)
			glObjectLabel(GL_BUFFER, drawingDataVertexBufferObject, -1, "<particles>/VBO");
#endif

		// generate new VAO ID
		drawingDataVertexArraysObject = pGL->GenVAOID();
		assert (drawingDataVertexArraysObject != 0 && "Could not generate a VAO ID.");
	}


	// Push the new vertex data
	glBindBuffer(GL_ARRAY_BUFFER, drawingDataVertexBufferObject);
	glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(C4Particle::DrawingData::Vertex) * particleCount, &vertexCoordinates[0], GL_DYNAMIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	// set up the vertex array structure
	GLuint vao;
	const bool has_vao = pGL->GetVAO(drawingDataVertexArraysObject, vao);
	glBindVertexArray(vao);

	assert ((drawingDataVertexBufferObject != 0) && "No buffer object has been created yet.");
	assert ((drawingDataVertexArraysObject != 0) && "No vertex arrays object has been created yet.");

	if (!has_vao)
	{
		glBindBuffer(GL_ARRAY_BUFFER, drawingDataVertexBufferObject);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ::Particles.GetIBO());
#ifdef GL_KHR_debug
		if (glObjectLabel)
			glObjectLabel(GL_VERTEX_ARRAY, vao, -1, "<particles>/VAO");
#endif

		glEnableVertexAttribArray(call.GetAttribute(C4SSA_Position));
		glEnableVertexAttribArray(call.GetAttribute(C4SSA_Color));
		glEnableVertexAttribArray(call.GetAttribute(C4SSA_TexCoord));
		glVertexAttribPointer(call.GetAttribute(C4SSA_Position), 2, GL_FLOAT, GL_FALSE, stride, reinterpret_cast<GLvoid*>(offsetof(C4Particle::DrawingData::Vertex, x)));
		glVertexAttribPointer(call.GetAttribute(C4SSA_TexCoord), 2, GL_FLOAT, GL_FALSE, stride, reinterpret_cast<GLvoid*>(offsetof(C4Particle::DrawingData::Vertex, u)));
		glVertexAttribPointer(call.GetAttribute(C4SSA_Color), 4, GL_FLOAT, GL_FALSE, stride, reinterpret_cast<GLvoid*>(offsetof(C4Particle::DrawingData::Vertex, r)));
	}

	glDrawElements(GL_TRIANGLE_STRIP, static_cast<GLsizei> (5 * particleCount), GL_UNSIGNED_INT, 0);

	// reset buffer data
	glBindVertexArray(0);
}
Example #27
0
void getInput()
{
	if (theShip.fuel > 0)
	{
		if (key[KEY_W])
		{
			theShip.rocketPower = 400;
	      theShip.fuel--;
	 	}
	   else if (key[KEY_S])
		{
			theShip.rocketPower = -150;
	      theShip.fuel--;
		}
		else
		{
	   	theShip.rocketPower = 0;
		}
		if (key[KEY_A])
		{
			theShip.velRotation -= 0.05;
	      theShip.fuel--;
		}
	   if (key[KEY_D])
		{
			theShip.velRotation += 0.05;
	      theShip.fuel--;
		}
	}
	else
	{
      theShip.rocketPower = 0;
	}

	if (theShip.rotation < -255)
	{
      theShip.rotation = 255;
	}
	if (theShip.rotation > 255)
	{
      theShip.rotation = -255;
	}

	if (key[KEY_LCONTROL])
	{
		theShip.velX = 0;
		theShip.velY = 0;
		theShip.velRotation = 0;
	}
	if (key[KEY_C])
	{
		pointHeader = NULL;
	}
	if (key[KEY_R])
	{
		randomizeMap();
	}
	if (key[KEY_P])
	{
		readkey();
	}

   createPoint(makecol(255, 255, 255), theShip.x + 0.5 * theShip.width, theShip.y + 0.5 * theShip.height);
   createPoint(makecol(255, 0, 0), theShip.x + 0.5 * theShip.width + (fixtof(fixcos(ftofix(theShip.rotation))) * 10), theShip.y + 0.5 * theShip.height + (fixtof(fixsin(ftofix(theShip.rotation))) * 10));
}
Example #28
0
/* get_camera_matrix: 
 *  Constructs a camera matrix for translating world-space objects into
 *  a normalised view space, ready for the perspective projection. The
 *  x, y, and z parameters specify the camera position, xfront, yfront,
 *  and zfront is an 'in front' vector specifying which way the camera
 *  is facing (this can be any length: normalisation is not required),
 *  and xup, yup, and zup is the 'up' direction vector. Up is really only
 *  a 1.5d vector, since the front vector only leaves one degree of freedom
 *  for which way up to put the image, but it is simplest to specify it
 *  as a full 3d direction even though a lot of the information in it is
 *  discarded. The fov parameter specifies the field of view (ie. width
 *  of the camera focus) in fixed point, 256 degrees to the circle format.
 *  For typical projections, a field of view in the region 32-48 will work
 *  well. Finally, the aspect ratio is used to scale the Y dimensions of
 *  the image relative to the X axis, so you can use it to correct for
 *  the proportions of the output image (set it to 1 for no scaling).
 */
void get_camera_matrix(MATRIX *m, fixed x, fixed y, fixed z, fixed xfront, fixed yfront, fixed zfront, fixed xup, fixed yup, fixed zup, fixed fov, fixed aspect)
{
   MATRIX_f camera;
   int i, j;
   ASSERT(m);

   get_camera_matrix_f(&camera,
		       fixtof(x), fixtof(y), fixtof(z), 
		       fixtof(xfront), fixtof(yfront), fixtof(zfront), 
		       fixtof(xup), fixtof(yup), fixtof(zup), 
		       fixtof(fov), fixtof(aspect));

   for (i=0; i<3; i++) {
      for (j=0; j<3; j++)
	 m->v[i][j] = ftofix(camera.v[i][j]);

      m->t[i] = ftofix(camera.t[i]);
   }
}