Beispiel #1
0
bool RockAI::BoundingSphereIntersection(float sqrdist, class Node *caller){

// fixme: caller was f****d here once.

	if(exploding) return false;

	//char *name = caller->GetName();

	if( caller->GetName()==String("Fireball")||	// fixme: Optimize!
		caller->GetName()==String("Flare")){	// fixme: Optimize!
		//Kill=true;
//printf("%s\n",caller->GetName());

		if(rand()%0xff<10){
			Geometry *Pickup = new Geometry();
			Pickup->Node::Apply(0,new FirePickup(camera,Pickup));
			Pickup->SetPosition(0,Vector(GetPosition()));
			GetParent()->Apply(0,Pickup);
		}

		if(size>100.0f){
			for(int n=0; n<2; n++){
				Geometry *Rock = new Geometry();
				Rock->Node::Apply(0,new RockAI(camera,/*scr,*/Rock,size/2));
				Rock->SetPosition(0,Vector(GetPosition()));
				GetParent()->Apply(0,Rock);
			}
		}else{
			deadrocks++;
			while(deadrocks>=4){
				deadrocks-=4;
				Geometry *Rock = new Geometry();
				Rock->Node::Apply(0,new RockAI(camera,/*scr,*/Rock,400.0f));
				Rock->SetPosition(0,Vector(GetPosition()));
				GetParent()->Apply(0,Rock);
			}
		}
		SetName("DeadRock");
		explotion = rand()%3;
		Apply(ExplotionMaterial[explotion]);
		Geometry *geo = GetCreatorGeometry();
		geo->SetVector(0,Vector(geo->GetVector(0))*3);
		geo->SetVector(1,Vector(geo->GetVector(1))*3);
		geo->SetVector(2,Vector(geo->GetVector(2))*3);
		geo->SetVector(3,Vector(geo->GetVector(3))*3);
		exploding = true;

//		caller->Kill();
//		Kill();

	}//else
	//	if(strcmp(caller->GetName(),"Background"))
	//	if(strcmp(caller->GetName(),"Rock"))
	//	printf("%s\n",caller->GetName());
	return false;
}
Beispiel #2
0
bool RockAI::Tick(double time){
	if(OldTime<0) OldTime = time;
	float pulse=float(time-OldTime);
	SetPosition(Vector(GetPosition())+(PositionStep*pulse));
	Vector pos = Vector(GetPosition());
	//Node *n = GetNode("Camera");
	pos-=Vector(camera->GetPosition());	// fixme: bug! geo is 0 sometimes
	if(pos.X> 6400*2) SetPosition(Vector(GetPosition())-Vector(6400*2*2,0,0));
	if(pos.X<-6400*2) SetPosition(Vector(GetPosition())+Vector(6400*2*2,0,0));
	if(pos.Y> 6400*2) SetPosition(Vector(GetPosition())-Vector(0,6400*2*2,0));
	if(pos.Y<-6400*2) SetPosition(Vector(GetPosition())+Vector(0,6400*2*2,0));

#if 0
	if(Kill){
		if(ExpTime==0){
			ExpTime = time;

			if(!strcmp(GetCreatorGeometry()->GetName(),"Rock_sub")){
				status = 1;
				for(int n=0; n<3; n++){
					/*
					Geometry *Rock = (Geometry*)scr->Rocks_sub_sub->GetItem(scr->Rocks_sub_sub_item++);
					Rock->Tick(time);
						 if(GetParentCamera())		GetParentCamera()->Apply(Rock);		// Fireball removes it self
					else if(GetParentGeometry())	GetParentGeometry()->Node::Apply(Rock);	// Fireball removes it self
					else if(GetParentLightPoint())	GetParentLightPoint()->Apply(Rock);	// Fireball removes it self
					Rock->SetPosition(Vector(GetPosition()));
					*/
					Geometry *Rock = new Geometry();
					Rock->Node::Apply(new RockAI(scr,Rock));
					GetParent()->Apply(Rock);
				}
			}else if(!strcmp(GetCreatorGeometry()->GetName(),"Rock")){
				status = 0;
				for(int n=0; n<3; n++){
					/*
					Geometry *Rock = (Geometry*)scr->Rocks_sub->GetItem(scr->Rocks_sub_item++);
					Rock->Tick(time);
						 if(GetParentCamera())		GetParentCamera()->Apply(Rock);		// Fireball removes it self
					else if(GetParentGeometry())	GetParentGeometry()->Node::Apply(Rock);	// Fireball removes it self
					else if(GetParentLightPoint())	GetParentLightPoint()->Apply(Rock);	// Fireball removes it self
					Rock->SetPosition(Vector(GetPosition()));
					*/
					Geometry *Rock = new Geometry();
					Rock->Node::Apply(new RockAI(scr,Rock));
					GetParent()->Apply(Rock);
				}
			}else status=2;

			GetCreatorGeometry()->SetName("Explotion");
//			GetCreatorGeometry()->Apply(ExplotionMaterial);
			//GetCreatorGeometry()->SetPosition(Vector(GetPosition())-Vector(0,0,10000));
			if(rand()<0x2ff){
				// Add pickup
				Geometry *Pickup = new Geometry();
				FirePickup *AI = new FirePickup(Pickup);
				Pickup->Node::Apply(AI);
				Pickup->SetPosition(Vector(GetPosition()));
				GetParentGeometry()->Node::Apply(Pickup);
			}
		}
		int framecount = GetCreatorGeometry()->GetMaterial()->GetTexture()->GetFrameCount();
		if(framecount) GetCreatorGeometry()->GetMaterial()->GetTexture()->SetFrame((int)((time-ExpTime)*framecount/0.5f)%framecount);
		OldTime=time;
		if((time-ExpTime)>0.5f){
			scr->RockCount--;
			//KillOwner();
			switch(status){
			case 0:
				GetCreatorGeometry()->SetName("Rock");
			break;
			case 1:
				GetCreatorGeometry()->SetName("Rock_sub");
			break;
			case 2:
				GetCreatorGeometry()->SetName("Rock_sub_sub");
			break;
			}
			GetCreatorGeometry()->Apply(RockMaterial);
			Disconnect();
			return false;
		}else return true;
	}else{
		int framecount = /*GetCreatorGeometry()->GetMaterial()*/RockMaterial->GetTexture()->GetFrameCount();
		if(framecount) /*GetCreatorGeometry()->GetMaterial()->*/RockMaterial->GetTexture()->SetFrame(((int)(time*framecount/2.0f)+startframe)%framecount);
		OldTime=time;
		return true;
	}
#endif
	if(exploding){
//printf("%f\n",ImpactTime);
		if(ImpactTime<0) ImpactTime = time;
		int framecount = ExplotionMaterial[explotion]->GetTexture()->GetFrameCount();
		int frame = int((time-ImpactTime)*framecount);///.5f);
//printf("%d/%d(%f)\n",frame,framecount,time-ImpactTime);
		if(frame>=framecount) Kill();
		if(framecount) ExplotionMaterial[explotion]->GetTexture()->SetFrame(frame>=framecount?framecount-1:frame);
		OldTime=time;
	}else{
// fixme: 16/11/1998 - GetTexture() returned bullshit.
		int framecount = RockMaterial->GetTexture()->GetFrameCount();
		if(framecount) RockMaterial->GetTexture()->SetFrame(int((time*framecount/2.0f)+startframe)%framecount);
		OldTime=time;
	}
	return true;
}