bool Vision::isEntityInVision(Entity e)
{
	Coord point(e.getCenter()->x, e.getCenter()->y);

	VECTOR2 v1(getHeight() / 2, -(getWidth() / 4));
	rotate2Dvector(&v1, getRadians() - 1.5707f); 
	c1 = Coord(getCenter()->x + v1.x, getCenter()->y + v1.y);
	
	VECTOR2 v2(getHeight() / 2.0f, getWidth() / 4.0f);
	rotate2Dvector(&v2, getRadians() - 1.5707);
	c2 = Coord(getCenter()->x + v2.x, getCenter()->y + v2.y);

	c3 = Coord(getCenter()->x, getCenter()->y);

	/*stringstream ss;
	string s1, s2, s3, s4, s5, s6, s7, s8;
	ss.clear();
	ss << point.x << ' ' << point.y << ' ';
	ss << c1.x << ' ' << c1.y << ' ';
	ss << c2.x << ' ' << c2.y << ' ';
	ss << c3.x << ' ' << c3.y << ' ';
	ss >> s1 >> s2 >> s3 >> s4 >> s5 >> s6 >> s7 >> s8;*/

	/*text->print("testing if point (" + s1 + ", " + s2 + ") is within this triangle: \n" + 
						  "(" + s3 + ", " + s4 + ")\n" + 
						  "(" + s5 + ", " + s6 + ")\n" + 
						  "(" + s7 + ", " + s8 + ")\n", 300, 30);*/

	if (coordInsideTriangle(point, c1, c2, c3))
	{
		fire(e.getX(), e.getY());
		return true;
	}
	return false;
}
Exemplo n.º 2
0
void rotate3Dvector(D3DXVECTOR3* a_vector, float a_rot, float a_angle) {
	D3DXVECTOR2 Yaw, Pitch;
	a_rot = D3DXToRadian(a_rot);
	a_angle = D3DXToRadian(a_angle);
	Pitch.x = a_vector->z;				
	Pitch.y = a_vector->y;				// the final Y
	rotate2Dvector(&Pitch, a_angle);	// XY rotation 
	Yaw.x = a_vector->x;				// the final X
	Yaw.y = Pitch.x;					// the final Z
	rotate2Dvector(&Yaw,a_rot);			// XZ rotation

	a_vector->x = Yaw.x; // X
	a_vector->y = Pitch.y; // Y
	a_vector->z = -(Yaw.y); // Z
}
Exemplo n.º 3
0
void Player::Update(inputState& a_state, float a_dt, float &a_rot, float &a_angle,Limbase part_list,BulletVec &a_bulvec) {
	float tempfloat;

	//check alive
	tempfloat = a_state.rX;
		a_rot += (tempfloat*a_dt)*turnspeedX;
		tempfloat = a_state.rY;
		a_angle -= (tempfloat*a_dt)*turnspeedY; // minus to uninvert it
		if(a_angle >= 90)
			a_angle = 89.9f;
		else if(a_angle <=-90)
			a_angle = -89.9f;

	if(alive) {
		//do if alive
		pos.x = prospectivePos.x;
		pos.y = prospectivePos.y;
		pos.z = prospectivePos.z;


		////////////////////////////////////////
		// Takes inputs, sets prospective pos //
		////////////////////////////////////////



		tempfloat = a_state.lX;
		velocityXZ.x = tempfloat*a_dt*speed;

		tempfloat = a_state.lY;
		velocityXZ.y = tempfloat*a_dt*speed;

		velocityY -= 0.3f*a_dt;
		if(velocityY < -terminalVelocity)
			velocityY = -terminalVelocity;
		if(velocityY > terminalVelocity)
			velocityY = terminalVelocity;
		//if(pos.y <= 0 && velocityY <= 0)
		//	velocityY = 0;
		/////////////////////////////////////
		//////////PLAYER CONTROLS////////////
		/////////////////////////////////////

		// need to deal with object for bullet 
		//left attack Left Trigger
		if(a_state.buttons[binds::leftAttack]&&!a_state.buttonLast[binds::leftAttack]) { 
			if (!Limbs.getLarm()==0){
				part_list.CaseAction(Limbs.getLarm(),*this,a_state,a_bulvec,a_rot,a_angle);
			}
		}
		//right attack Right Trigger
		if(a_state.buttons[binds::rightAttack]&&!a_state.buttonLast[binds::rightAttack]) { 
			if(Limbs.getRarm()==0){
				D3DXVECTOR3 tempvec = getPos();
				tempvec.y += 1.5f;
				a_bulvec.ActivateABullet(tempvec,D3DXVECTOR3(0,0,-BulletSpeed),0,a_rot,a_angle,MeleeDefaultLifeSpan, testDamage);
			}
			else if(!Limbs.getRarm()==0){
				part_list.CaseAction(Limbs.getRarm(),*this,a_state,a_bulvec,a_rot,a_angle);
			}
		}
		// jump  A
		if(a_state.buttons[binds::jump] && onGround) {
			velocityY = 0.2f;
			onGround = false;
		}
		//leg power B
		if(a_state.buttons[binds::legPower]&&!a_state.buttonLast[binds::legPower]) {
			//get part !0 
			if (!Limbs.getLeg()==0){
				part_list.CaseAction(Limbs.getLeg(),*this,a_state,a_bulvec,a_rot,a_angle);
				// find that part 
				// execute that function
			}
		}
		if(a_state.buttons[binds::use]) {
			//if item is coliding with character
			if(getcheckItem()){
				addLimb(ProsteticTestLimb);
			}
			// make bool switch here.
			//
			//bring menue up 
			// 
		}



		facing = D3DXToRadian(a_rot);

		//D3DXMATRIX matrixlovetemptest;
		//D3DXVECTOR2 tempveloc = velocityXZ;
		//float templength = D3DXVec2Length(&velocityXZ);
		//D3DXVec2Normalize(&velocityXZ,&velocityXZ);
		//D3DXMatrixTransformation2D(&matrixlovetemptest,NULL,NULL,NULL,&D3DXVECTOR2(pos.x,pos.z),facing,&velocityXZ);
		//D3DXVECTOR4 matrixtemplove4;
		//D3DXVec2Transform(&matrixtemplove4, &velocityXZ, &matrixlovetemptest);

		//velocityXZ.x = matrixtemplove4.x;
		//velocityXZ.y = matrixtemplove4.y;
		//D3DXVECTOR2 tempveloc = velocityXZ;
		//if(D3DXVec2Length(&velocityXZ) >= maxSpeed)
		//	velocityXZ = tempveloc;
		rotate2Dvector(&velocityXZ,-facing);

		prospectivePos.x += velocityXZ.x;
		prospectivePos.y += velocityY;
		prospectivePos.z += velocityXZ.y;


		//if() {
		//	onGround = true;
		//	velocityY = 0;
		//}
		//else {
		//	onGround = false;
		//}
		if(pos.y < -200) {
			alive = false;
			timer = 3;
		}
		if(curHealth <= 0) {
			alive = false;
			timer = 3;
		}
	} else {
		//do if dead
		if(timer>=0) {
			timer -= a_dt;
		}
	}

}