コード例 #1
0
ファイル: turret.c プロジェクト: tomrf/turretz
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;
}
コード例 #2
0
ファイル: exspline.c プロジェクト: AntonLanghoff/whitecatlib
/* calculates the control points for a spline segment */
void get_control_points(NODE n1, NODE n2, int points[8])
{
   fixed dist = fixmul(node_dist(n1, n2), curviness);

   points[0] = n1.x;
   points[1] = n1.y;

   points[2] = n1.x + fixtoi(fixmul(fixcos(n1.tangent), dist));
   points[3] = n1.y + fixtoi(fixmul(fixsin(n1.tangent), dist));

   points[4] = n2.x - fixtoi(fixmul(fixcos(n2.tangent), dist));
   points[5] = n2.y - fixtoi(fixmul(fixsin(n2.tangent), dist));

   points[6] = n2.x;
   points[7] = n2.y;
}
コード例 #3
0
ファイル: bullet.cpp プロジェクト: ian-howell/Zombies
void Bullet::move(int to_x, int to_y)
{
    x += fixtof(fixcos(theta)) * speed;
    y += fixtof(fixsin(theta)) * speed;


    set_boundaries();
}
コード例 #4
0
ファイル: SH_Vector.c プロジェクト: aeTIos/SHNspire
// Meant to be used only with SH_VectorSpace's vectors
// ie screen-centered unit vectors
SH_Vector extendToScreenEdge(SH_Vector *u)
{
    int a = u->a & 0xff;
    SH_Vector result;
    result.a = a;
	// The screen is a 320*240 rectangle, not a square
    if(a < 27 || a >= 229)
		result.r = fixdiv(itofix(160), fixcos(a));
	else if(a < 101)
		result.r = fixdiv(itofix(120), fixsin(a));
	else if(a < 155)
		result.r = fixdiv(itofix(-160), fixcos(a));
	else
		result.r = fixdiv(itofix(-120), fixsin(a));
	
	return result;
}
コード例 #5
0
ファイル: player.cpp プロジェクト: a-sf-mirror/gusanos
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;
};
コード例 #6
0
ファイル: SH_Vector.c プロジェクト: aeTIos/SHNspire
void drawVectorSpace(SH_VectorSpace *s, uint16_t c)
{
	int i;
	SH_Vector cv;
	// TODO : background
	for(i = 0; i < 6; i++)
	{
		cv = extendToScreenEdge(&s->vectors[i]);
		drawLine(160, 120, fixtoi(fixmul(cv.r, fixcos(cv.a))) + 160, fixtoi(fixmul(cv.r, fixsin(cv.a))) + 120, c);
	}
}
コード例 #7
0
void CODE_IN_IWRAM matrix_rotate_object(matrx_t m, int alp, int bet, int gam)
{
  int cosalp = fixcos(alp);
  int sinalp = fixsin(alp);
  int cosbet = fixcos(bet);
  int sinbet = fixsin(bet);
  int cosgam = fixcos(gam);
  int singam = fixsin(gam);

  m[0][0] =  fixmul(cosalp, cosgam) - fixmul(sinalp, fixmul(sinbet, singam));
  m[0][1] =  fixmul(sinalp, cosgam) + fixmul(cosalp, fixmul(sinbet, singam));
  m[0][2] =  fixmul(cosbet, singam);

  m[1][0] = -fixmul(sinalp, cosbet);
  m[1][1] =  fixmul(cosalp, cosbet);
  m[1][2] = -sinbet;

  m[2][0] = -fixmul(cosalp, singam) - fixmul(sinalp, fixmul(sinbet, cosgam));
  m[2][1] =  fixmul(cosalp, fixmul(sinbet, cosgam)) - fixmul(sinalp, singam);
  m[2][2] =  fixmul(cosbet, cosgam);
}
コード例 #8
0
ファイル: Particles.cpp プロジェクト: matrefeytontias/nKaruga
void Particles::add(Fixed _x, Fixed _y, Fixed _a, Fixed _r, bool _p, int lifetime)
{
	int ratio = (rand() % 256) - 128 + _r;
	x[counter] = _x;
	y[counter] = _y;
	dx[counter] = fixmul(fixcos(_a), ratio);
	dy[counter] = fixmul(fixsin(_a), ratio);
	polarity[counter] = _p;
	time[counter] = lifetime;
	dt[counter] = lifetime / PARTICLE_RADIUS;
	counter = (counter + 1) % MAX_PARTICLE;
}
コード例 #9
0
ファイル: exspline.c プロジェクト: AntonLanghoff/whitecatlib
/* 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();
}
コード例 #10
0
ファイル: math3d.c プロジェクト: Skiles/aseprite
/* get_z_rotate_matrix:
 *  Constructs a 3d transformation matrix, which will rotate points around 
 *  the z axis by the specified amount (given in the Allegro fixed point, 
 *  256 degrees to a circle format).
 */
void get_z_rotate_matrix(MATRIX *m, fixed r)
{
   fixed c = fixcos(r);
   fixed s = fixsin(r);
   ASSERT(m);

   *m = identity_matrix;

   m->v[0][0] = c;
   m->v[0][1] = -s;

   m->v[1][0] = s;
   m->v[1][1] = c;
}
コード例 #11
0
ファイル: db-04_untangle.c プロジェクト: olofn/db_public
+=j!=I&&i!=J&&i!=I&&j!=J&&*c(I,J)&&q(p(i),p(j),p(I),p(J));return f;}main(){int i
,I,j,J,f,F,a,b,s=-1,X,Y,H,h;BITMAP*B;SAMPLE*S;allegro_init();*c(0,1)=*c(0,2)=*c(
0,3)=1;set_gfx_mode(GFX_AUTODETECT_WINDOWED,w,w,0,0);install_sound(DIGI_DIRECTX(
0),MIDI_NONE,0);B=create_bitmap(w,w);install_keyboard();install_mouse();*c(2,3)=
*c(1,2)=*c(1,3)=1;text_mode(-1);S=create_sample(8,0,9999,9999);for(i=0;i<9999;i
++){((unsigned char*)S->data)[i]=(((i+(fixsin(i<<13)>>13))%100+(i)%152)*i)/9000;
}for(l=4;l<99;l++){play_sample(S,255,55,1600,0);play_sample(S,255,200,1604,0);
for(i=0;i<l;i++){x[i]=((fixcos((i<<24)/l)*w/3)>>16)+w/2;y[i]=((fixsin((i<<24)/l)
*w/3)>>16)+w/2;}do{F=0;key[KEY_ESC]?exit(0):0;clear_to_color(B,15);for(i=0;i<l;i
++){for(j=0;j<l;j++){f=0;if(*c(j,i)){f=M(i,j);for(a=-1;a<2;a++)for(b=-1;b<2;b++)
line(B,a+p(i)+b,a+p(j)+b,f?12:10);}F|=f;}}for(i=0;i<l;i++){circlefill(B,p(i),8,0
);circlefill(B,p(i),6,s==i?7:8);s=mouse_b?s:-1;if(mouse_b&&s<0&&_(mouse_x-x[i],-
7,7)&&_(mouse_y-y[i],-7,7))s=i;}if(s>=0){x[s]=mouse_x;y[s]=mouse_y;}textprintf(B
,font,10,10,0,"Level %d",l-3);draw_sprite(B,mouse_sprite,mouse_x,mouse_y);blit(B
,screen,0,0,0,0,w,w);}while(F||mouse_b);H=0;for(j=0;j<2000;j++){h=0;x[l]=rand()%
w*2-w/2;y[l]=rand()%w*2-w/2;for(i=0;i<l;i++){h+=M(i,l)==0;}if(h>H){H=h;X=x[l];Y=
y[l];}}x[l]=X;y[l]=Y;for(i=0;i<l;i++){*c(i,l)=M(i,l)==0;*c(rand()%l,rand()%l)=0;
}}}END_OF_MAIN();///////////////////////////////////////////////////////////////
コード例 #12
0
void initExplosionEffect(int x, int y, int coef, Fixed g)
{
	int am = clamp(coef, 0, MAX_EXPLOSION_PARTICLE);
	// Empty explosion buffer
	for(int j = 0; j < 240; j++)
		for(int i = 0; i < 320; i++)
			explosionBuffer[i][j] = 0;
	
	for(int i = 0; i < MAX_EXPLOSION_PARTICLE; i++)
		explosionArray[i]->deactivate();
	
	// Activate particles
	for(int i = 0; i < am; i++)
	{
		Fixed a = rand() % 256;
		Fixed r = fixmul((rand() % itofix(5)) - itofix(3), coef / 2);
		explosionArray[i]->activate(x, y, fixmul(fixcos(a), r), fixmul(fixsin(a), r), g);
	}
	explosionGoing = false;
}
コード例 #13
0
ファイル: turret.c プロジェクト: tomrf/turretz
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);
	
}
コード例 #14
0
ファイル: player.cpp プロジェクト: a-sf-mirror/gusanos
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;
                };*/
              };
            };
      };
    }
};
コード例 #15
0
ファイル: matrix.c プロジェクト: fanzyflani/mld62
GLvoid glRotatex(GLfixed theta, GLfixed x, GLfixed y, GLfixed z) // p35 2.9.2
{
	int i, j, k;

	// Ensure we have an axis of rotation!
	if(x == 0 && y == 0 && z == 0)
		return;

	// Mark dirty
	gl_mat_gte_isdirty = GL_TRUE;

	// OPTIMISATION: If on a single axis we don't need to tweak as much
	int zeros = 0;
	if(x == 0) zeros++;
	if(y == 0) zeros++;
	if(z == 0) zeros++;

	//if(0)
	if(zeros == 2)
	{
		// Rotate around an axis
		// FIXME: get correct rotation orders
		int a, b;
		if(x != 0) { a = 1; b = 2; }
		else if(y != 0) { a = 2; b = 0; }
		else { a = 0; b = 1; }

		// Get matrix pointer
		GLint stackidx = gl_mat_stack[gl_mat_cur];
		GLfixed *rot = gl_mat_rot[gl_mat_cur][stackidx];

		// Get sin/cos
		//theta /= 360; // dropping the "degrees" requirement, using direct angles instead
		GLfixed tsin = fixsin(theta);
		GLfixed tcos = fixcos(theta);

		// Get old values
		GLfixed ta0 = rot[a*3 + 0];
		GLfixed ta1 = rot[a*3 + 1];
		GLfixed ta2 = rot[a*3 + 2];
		GLfixed tb0 = rot[b*3 + 0];
		GLfixed tb1 = rot[b*3 + 1];
		GLfixed tb2 = rot[b*3 + 2];

		// Write new values
		// TODO: get this to behave
		rot[a*3 + 0] = fixmulf(ta0, tcos) - fixmulf(tb0, tsin);
		rot[a*3 + 1] = fixmulf(ta1, tcos) - fixmulf(tb1, tsin);
		rot[a*3 + 2] = fixmulf(ta2, tcos) - fixmulf(tb2, tsin);
		rot[b*3 + 0] = fixmulf(ta0, tsin) + fixmulf(tb0, tcos);
		rot[b*3 + 1] = fixmulf(ta1, tsin) + fixmulf(tb1, tcos);
		rot[b*3 + 2] = fixmulf(ta2, tsin) + fixmulf(tb2, tcos);

		return;
	}

	//
	// GENERIC OPENGL ROTATION
	//

	// Normalise x,y,z
	GLfixed vlen2 = fixmul(x,x) + fixmul(y,y) + fixmul(z,z);
	if(vlen2 >= 0x100)
	{
		GLfixed vlen = fixsqrt(vlen2);
		x = fixdiv(x, vlen);
		y = fixdiv(y, vlen);
		z = fixdiv(z, vlen);
	} else {
		// Length is too small to get a sane result
		// Use int multiplies instead and shift later

		// FIXME get this working correctly
		vlen2 = x*x + y*y + z*z;

		// Skip if we get 0
		if(vlen2 == 0)
			return;

		GLfixed vlen = fixsqrt(vlen2)<<8;
		x = fixdiv(x, vlen);
		y = fixdiv(y, vlen);
		z = fixdiv(z, vlen);

	}

	// Get sin/cos
	theta /= 360;
	GLfixed tsin = fixsin(theta);
	GLfixed tcos = fixcos(theta);

	// Generate rotation matrix
	GLfixed itcos = 0x10000-tcos;
	GLfixed base_rot[3][3] = {
		{
			fixmulf(itcos, fixmulf(x, x))+tcos,
			fixmulf(itcos, fixmulf(x, y))-fixmulf(tsin, z),
			fixmulf(itcos, fixmulf(x, z))+fixmulf(tsin, y),
		},
		{
			fixmulf(itcos, fixmulf(y, x))+fixmulf(tsin, z),
			fixmulf(itcos, fixmulf(y, y))+tcos,
			fixmulf(itcos, fixmulf(y, z))-fixmulf(tsin, x),
		},
		{
			fixmulf(itcos, fixmulf(z, x))-fixmulf(tsin, y),
			fixmulf(itcos, fixmulf(z, y))+fixmulf(tsin, x),
			fixmulf(itcos, fixmulf(z, z))+tcos,
		},
	};

	// Apply rotation matrix
	GLint stackidx = gl_mat_stack[gl_mat_cur];
	GLfixed *rot = gl_mat_rot[gl_mat_cur][stackidx];
	//GLfixed *trn = gl_mat_trn[gl_mat_cur][stackidx];
	GLfixed oldrot[9];
	//GLfixed oldtrn[3];
	memcpy(oldrot, rot, sizeof(GLfixed)*9);
	//memcpy(oldtrn, trn, sizeof(GLfixed)*3);

	// FIXME: translate properly
	// FIXME: ensure correct order
	for(i = 0; i < 3; i++)
	for(j = 0; j < 3; j++)
	{
		GLfixed sum = 0;
		for(k = 0; k < 3; k++)
			//sum += fixmulf(oldrot[3*i + k], base_rot[k][j]);
			sum += fixmulf(oldrot[3*k + j], base_rot[i][k]);

		rot[3*i + j] = sum;
	}

	/*
	for(i = 0; i < 3; i++)
	{
		GLfixed sum = 0;
		for(k = 0; k < 3; k++)
			sum += fixmulf(oldtrn[k], rot[k*3 + i]);
			//sum += fixmulf(oldtrn[k], rot[i*3 + k]);
			//sum += fixmulf(oldtrn[k], base_rot[k][i]);
			//sum += fixmulf(oldtrn[k], base_rot[i][k]);

		//trn[i] = sum;
	}
	*/
}
コード例 #16
0
void CFX_PathGenerator::AddArc(FX_FLOAT x,
                               FX_FLOAT y,
                               FX_FLOAT width,
                               FX_FLOAT height,
                               FX_FLOAT start_angle,
                               FX_FLOAT sweep_angle) {
#if 0
    FX_FIXFLOAT32 sweep = sweep_angle;
    while (sweep > FIXFLOAT32_PI * 2) {
        sweep -= FIXFLOAT32_PI * 2;
    }
    if (sweep == 0) {
        return;
    }
    m_pPathData->AddPointCount(1);
    m_pPathData->SetPoint(m_pPathData->GetPointCount() - 1,
                          x + fixmul_8_32_to_8(width, fixcos(start_angle)),
                          y + fixmul_8_32_to_8(height, fixsin(start_angle)), FXPT_MOVETO);
    FX_FIXFLOAT32 angle1 = 0, angle2;
    FX_BOOL bDone = FALSE;
    do {
        angle2 = angle1 + FIXFLOAT32_PI / 2;
        if (angle2 >= sweep) {
            angle2 = sweep;
            bDone = TRUE;
        }
        ArcTo(x, y, width, height, start_angle + angle1, angle2 - angle1);
        angle1 = angle2;
    } while (!bDone);
#else
  if (sweep_angle == 0) {
    return;
  }
  static const FX_FLOAT bezier_arc_angle_epsilon = (FX_FLOAT)(0.01f);
  while (start_angle > FX_PI * 2) {
    start_angle -= FX_PI * 2;
  }
  while (start_angle < 0) {
    start_angle += FX_PI * 2;
  }
  if (sweep_angle >= FX_PI * 2) {
    sweep_angle = FX_PI * 2;
  }
  if (sweep_angle <= -FX_PI * 2) {
    sweep_angle = -FX_PI * 2;
  }
  m_pPathData->AddPointCount(1);
  m_pPathData->SetPoint(m_pPathData->GetPointCount() - 1,
                        x + FXSYS_Mul(width, FXSYS_cos(start_angle)),
                        y + FXSYS_Mul(height, FXSYS_sin(start_angle)),
                        FXPT_MOVETO);
  FX_FLOAT total_sweep = 0, local_sweep = 0, prev_sweep = 0;
  FX_BOOL done = FALSE;
  do {
    if (sweep_angle < 0) {
      prev_sweep = total_sweep;
      local_sweep = -FX_PI / 2;
      total_sweep -= FX_PI / 2;
      if (total_sweep <= sweep_angle + bezier_arc_angle_epsilon) {
        local_sweep = sweep_angle - prev_sweep;
        done = TRUE;
      }
    } else {
      prev_sweep = total_sweep;
      local_sweep = FX_PI / 2;
      total_sweep += FX_PI / 2;
      if (total_sweep >= sweep_angle - bezier_arc_angle_epsilon) {
        local_sweep = sweep_angle - prev_sweep;
        done = TRUE;
      }
    }
    ArcTo(x, y, width, height, start_angle, local_sweep);
    start_angle += local_sweep;
  } while (!done);
#endif
}
コード例 #17
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;
	}

}
コード例 #18
0
ファイル: BulletArray.cpp プロジェクト: QuanticPotato/nKaruga
void BulletArray::handle(Player *p)
{
	bool destroyBullet;
	
	// Bullets
	for(int i = 0; i < MAX_BULLET; i++)
	{
		Bullet *cb = &data[i];
		destroyBullet = false;
		if(cb->isActive())
		{
			if(cb->hurtsPlayer() && !p->isDying())
			{
				// Check collisions with player if he's not dead already
				if(cb->getPolarity() != p->getPolarity())
				{
					// the player has a 1px hitbox (for now) (but that actually seems to be enough)
					if(p->x >= cb->x - itofix(cb->img[0] / 2) && p->x < cb->x + itofix(cb->img[0] / 2)
					&& p->y >= cb->y - itofix(cb->img[1] / 2) && p->y < cb->y + itofix(cb->img[1] / 2))
					{
						p->hurt();
						destroyBullet = true;
					}
				}
				else
				{
					if(sq(fixtoi(cb->x - p->x)) + sq(fixtoi(cb->y - p->y)) < sq(19)) // sqrt(player.w/2 ^2 + player.h/2 ^2)
					{
						destroyBullet = true;
						G_score += 100;
						G_power += G_power < MAX_POWER;
					}
				}
			}
			else
			{
				// Check collisions with enemies (there are much more enemies than players)
				for(int j = 0; j < MAX_ENEMY; j++)
				{
					if(G_enemiesArray[j]->isActive())
					{
						if(cb->x - itofix(cb->img[0] / 2) <= G_enemiesArray[j]->getx() + itofix(G_enemiesArray[j]->img[0] / 2) &&
						cb->x + itofix(cb->img[0] / 2) >= G_enemiesArray[j]->getx() - itofix(G_enemiesArray[j]->img[0] / 2) &&
						cb->y - itofix(cb->img[1] / 2) <= G_enemiesArray[j]->gety() + itofix(G_enemiesArray[j]->img[1] / 2) &&
						cb->y + itofix(cb->img[1] / 2) >= G_enemiesArray[j]->gety() - itofix(G_enemiesArray[j]->img[1] / 2))
						{
							G_enemiesArray[j]->damage(p, cb->getPolarity(), 1, this);
							G_score += 20;
							if(cb->getPolarity() != G_enemiesArray[j]->getPolarity()) G_score += 20;
							destroyBullet = true;
							// The same bullet can destroy several enemies if it hits them in the same frame !
						}
					}
				}
			}
			if(destroyBullet)
				deactivate(i);
			else
			{
				if(cb->handle())
					deactivate(i);
				else if(!G_skipFrame)
					cb->draw();
			}
		}
		else break;
	}	
	
	// Power fragments
	for(int i = 0; i < MAX_FRAGMENT; i++)
	{
		PowerFragment *cf = &data_fragment[i];
		destroyBullet = false;
		if(cf->isActive())
		{
			if(cf->hurtsPlayer() && !p->isDying())
			{
				// Check collisions with player
				if(cf->getPolarity() != p->getPolarity())
				{
					// the player has a 1px hitbox (for now) (but that actually seems to be enough)
					// power fragments have a 8*8 hitbox
					if(p->x >= cf->x - itofix(4) && p->x < cf->x + itofix(4)
					&& p->y >= cf->y - itofix(4) && p->y < cf->y + itofix(4))
					{
						p->hurt();
						destroyBullet = true;
					}
				}
				else
				{
					if(sq(fixtoi(cf->x - p->x)) + sq(fixtoi(cf->y - p->y)) < sq(p->img[0][0] / 2))
					{
						destroyBullet = true;
						G_score += 100;
						G_power = min(G_power + 10, MAX_POWER);
					}
				}
			}
			else
			{
				// Check collisions with enemies
				// A power fragment can only hit its registered target
				if(cf->targetE)
				{
					if(cf->targetE->isActive())
					{
						if(cf->x - itofix(4) <= cf->targetE->getx() + itofix(cf->targetE->img[0] / 2) &&
						cf->x + itofix(4) >= cf->targetE->getx() - itofix(cf->targetE->img[0] / 2) &&
						cf->y - itofix(4) <= cf->targetE->gety() + itofix(cf->targetE->img[1] / 2) &&
						cf->y + itofix(4) >= cf->targetE->gety() - itofix(cf->targetE->img[1] / 2))
						{
							cf->targetE->damage(p, cf->getPolarity(), 10, this);
							G_score += 20;
							if(cf->getPolarity() != cf->targetE->getPolarity()) G_score += 20;
							destroyBullet = true;
						}
					}
				}
			}
			if(destroyBullet)
				deactivate_fragment(i);
			else
			{
				if(cf->handle())
					deactivate_fragment(i);
				else if(!G_skipFrame)
					cf->draw();
			}
		}
		else break;
	}
	
	// Homings
	for(int i = 0; i < MAX_HOMING; i++)
	{
		Homing* ch = &data_homing[i];
		destroyBullet = false;
		if(ch->isActive())
		{
			if(!p->isDying())
			{
				// Check collisions with player
				if(ch->getPolarity() != p->getPolarity())
				{
					// the player has a 1px hitbox (for now) (but that actually seems to be enough)
					// homings have a 16*16 hitbox
					if(p->x >= ch->x - itofix(8) && p->x < ch->x + itofix(8)
					&& p->y >= ch->y - itofix(8) && p->y < ch->y + itofix(8))
					{
						p->hurt();
						destroyBullet = true;
					}
				}
				else
				{
					if(sq(fixtoi(ch->x - p->x)) + sq(fixtoi(ch->y - p->y)) < sq(p->img[0][0] / 2))
					{
						destroyBullet = true;
						G_score += 100;
						G_power = min(G_power + 10, MAX_POWER);
					}
				}
			}
			if(destroyBullet)
				deactivate_homing(i);
			else
			{
				if(ch->handle())
					deactivate_homing(i);
				else if(!G_skipFrame)
					ch->draw();
			}
		}
		else break;
	}
	
	// Lasers
	for(int i = 0; i < MAX_LASER; i++)
	{
		Rect *r, r1, r2;
		Laser *cl = &data_laser[i];
		if(cl->isActive())
		{
			if(cl->origin->isActive())
			{
				r = cl->getVector();
				cl->getSides(&r1, &r2);
				
				if(!p->isDying())
				{
					// Uses cartesian hitbox for checking collision with player
					// First, see if the player is not too far
					if(sq(fixtoi(p->x) - r->x) + sq(fixtoi(p->y) - r->y) <= sq(cl->getAmplitude()))
					{
						// if we're not too far, carry on collision checking
						// calculate the laser's cartesian equation and apply it to each of its sides
						// ax + by + c = 0
						int a, b, c1, c2;
						a = r->h;
						b = -r->w;
						c1 = -(a * r1.x + b * r1.y);
						c2 = -(a * r2.x + b * r2.y);
						
						if(p->getPolarity() != cl->getPolarity())
						{
							int temp = a * fixtoi(p->x) + b * fixtoi(p->y);
							// Work the player's 1 px hitbox
							if(sign(temp + c1) != sign(temp + c2))
								// Hit !
								p->hurt();
						}
						else
						{
							int temp1 = a * (fixtoi(p->x) - p->img[0][0] / 2) + b * fixtoi(p->y);
							int temp2 = a * (fixtoi(p->x) + p->img[0][0] / 2) + b * fixtoi(p->y);
							
							if(sign(temp1 + c1) != sign(temp1 + c2) || sign(temp2 + c1) != sign(temp2 + c2))
							{
								// Hit, but doesn't hurt
								cl->setAmplitude((int)sqrt(sq(fixtoi(p->x) - r->x) + sq(fixtoi(p->y) - r->y)));
								// Using G_skipFrame as a delay
								if(!G_skipFrame)
								{
									G_power += G_power < MAX_POWER;
									G_score += 100;
								}
								// Lasers are powerful, so they push the player
								p->x += fixcos(cl->angle) / 2;
								p->y += fixsin(cl->angle) / 2;
								
								// Add particles ! Yeeee !
								int k = (rand() % 4) + 1;
								for(int j = 0; j < k; j++)
								{
									Fixed a = cl->angle + 128 + (rand() % 64) - 32;
									G_particles->add(p->x, p->y, fixcos(a) / 2, fixsin(a) / 2, cl->getPolarity());
								}
							}
						}
					}
				}
				
				cl->handle();
				if(!G_skipFrame) cl->draw();
			}
			else
				cl->deactivate();
		}
	}
}
コード例 #19
0
ファイル: exblend.c プロジェクト: AntonLanghoff/whitecatlib
int main(int argc, char *argv[])
{
   char buf[256];
   PALETTE pal;
   BITMAP *image1;
   BITMAP *image2;
   BITMAP *buffer;
   int r, g, b, a;
   int x, y, w, h;
   int x1, y1, x2, y2;
   int prevx1, prevy1, prevx2, prevy2;
   int timer;
   int bpp = -1;
   int ret = -1;

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

   /* what color depth should we use? */
   if (argc > 1) {
      if ((argv[1][0] == '-') || (argv[1][0] == '/'))
	 argv[1]++;
      bpp = atoi(argv[1]);
      if ((bpp != 15) && (bpp != 16) && (bpp != 24) && (bpp != 32)) {
	 allegro_message("Invalid color depth '%s'\n", argv[1]);
	 return 1;
      }
   }

   if (bpp > 0) {
      /* set a user-requested color depth */
      set_color_depth(bpp);
      ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
   }
   else {
      /* autodetect what color depths are available */
      static int color_depths[] = { 16, 15, 32, 24, 0 };
      for (a=0; color_depths[a]; a++) {
	 bpp = color_depths[a];
	 set_color_depth(bpp);
	 ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
	 if (ret == 0)
	    break;
      }
   }

   /* did the video mode set properly? */
   if (ret != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error setting %d bit graphics mode\n%s\n", bpp,
		      allegro_error);
      return 1;
   }

   /* specify that images should be loaded in a truecolor pixel format */
   set_color_conversion(COLORCONV_TOTAL);

   /* load the first picture */
   replace_filename(buf, argv[0], "allegro.pcx", sizeof(buf));
   image1 = load_bitmap(buf, pal);
   if (!image1) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error reading %s!\n", buf);
      return 1;
   }

   /* load the second picture */
   replace_filename(buf, argv[0], "mysha.pcx", sizeof(buf));
   image2 = load_bitmap(buf, pal);
   if (!image2) {
      destroy_bitmap(image1);
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error reading %s!\n", buf);
      return 1;
   }

   /* create a double buffer bitmap */
   buffer = create_bitmap(SCREEN_W, SCREEN_H);

   /* Note that because we loaded the images as truecolor bitmaps, we don't
    * need to bother setting the palette, and we can display both on screen
    * at the same time even though the source files use two different 256
    * color palettes...
    */

   prevx1 = prevy1 = prevx2 = prevy2 = 0;

   textprintf_ex(screen, font, 0, SCREEN_H-8, makecol(255, 255, 255), 0,
		 "%d bpp", bpp);

   while (!keypressed()) {
      timer = retrace_count;
      clear_bitmap(buffer);

      /* the first image moves in a slow circle while being tinted to 
       * different colors...
       */
      x1= 160+fixtoi(fixsin(itofix(timer)/16)*160);
      y1= 140-fixtoi(fixcos(itofix(timer)/16)*140);
      r = 127-fixtoi(fixcos(itofix(timer)/6)*127);
      g = 127-fixtoi(fixcos(itofix(timer)/7)*127);
      b = 127-fixtoi(fixcos(itofix(timer)/8)*127);
      a = 127-fixtoi(fixcos(itofix(timer)/9)*127);
      set_trans_blender(r, g, b, 0);
      draw_lit_sprite(buffer, image1, x1, y1, a);
      textprintf_ex(screen, font, 0, 0, makecol(r, g, b), 0, "light: %d ", a);

      /* the second image moves in a faster circle while the alpha value
       * fades in and out...
       */
      x2= 160+fixtoi(fixsin(itofix(timer)/10)*160);
      y2= 140-fixtoi(fixcos(itofix(timer)/10)*140);
      a = 127-fixtoi(fixcos(itofix(timer)/4)*127);
      set_trans_blender(0, 0, 0, a);
      draw_trans_sprite(buffer, image2, x2, y2);
      textprintf_ex(screen, font, 0, 8, makecol(a, a, a), 0, "alpha: %d ", a);

      /* copy the double buffer across to the screen */
      vsync();

      x = MIN(x1, prevx1);
      y = MIN(y1, prevy1);
      w = MAX(x1, prevx1) + 320 - x;
      h = MAX(y1, prevy1) + 200 - y;
      blit(buffer, screen, x, y, x, y, w, h);

      x = MIN(x2, prevx2);
      y = MIN(y2, prevy2);
      w = MAX(x2, prevx2) + 320 - x;
      h = MAX(y2, prevy2) + 200 - y;
      blit(buffer, screen, x, y, x, y, w, h);

      prevx1 = x1;
      prevy1 = y1;
      prevx2 = x2;
      prevy2 = y2;
   }

   clear_keybuf();

   destroy_bitmap(image1);
   destroy_bitmap(image2);
   destroy_bitmap(buffer);

   return 0;
}
コード例 #20
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));
}