Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
2 registered members (steyr, alibaba), 534 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Function overload??? [Re: Rei_Ayanami] #282361
07/31/09 14:10
07/31/09 14:10
Joined: Aug 2008
Posts: 482
B
bart_the_13th Offline
Senior Member
bart_the_13th  Offline
Senior Member
B

Joined: Aug 2008
Posts: 482
Hmmm... I see too many
Code:
while(something==1)
{
   ....
   wait(1);
}
while(something==2)
{
   ....
   wait(1);
}
while(something==3)
{
   ....
   wait(1);
}



That's not bad but can lead to many confussion when you want to add or modify the code...

I suggest to do like
Code:
if(something==1)
{
   ....
}
if(something==2)
{
   ....
}
if(something==3)
{
   ....
}
wait(1);



Maybe it just me, but it help a lot when I want to change, modify the code...

Re: Function overload??? [Re: bart_the_13th] #282362
07/31/09 14:31
07/31/09 14:31
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline OP
Expert
Rei_Ayanami  Offline OP
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
You mean at the turning, right? If yes: How I should make this else , because he must turn as long as he isn´t at the right point. So what else?

Re: Function overload??? [Re: Rei_Ayanami] #282418
07/31/09 22:23
07/31/09 22:23
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Is it OK for me to take your code and "chop it up" a bit?
I want to make 3 functions out of the one big one.

At least so you can see that it does makes a difference.
I really dont think its an overloading issue though.

Click to reveal..
Code:
action opponent_ninja_C()
{
	//	my.material = mtl_toon;								//füge im den Toon Shader zu
	VECTOR temp;												//3 lokale vectoren
	VECTOR my_speed;
	VECTOR new_point;
	var turn[3];												//5 lokale variablen
	var turn_help;
	var move_lenght = 0;
	////
	c_setminmax(me);											//setzt die kollision
	set(me, POLYGON | CAST);								//setzt in auf Poligon genau erkennung - und das Cast flag
	my.alpha = 100;											//setzt die Tranzperent auf 0
	my.emask |= ENABLE_IMPACT;								//Empfindlich für berührung
	my.event = loose_health;
	my.health = 100;											//meine helath points auf 100
	while(player == NULL) wait(1);						//warte bis der spieler erstellt wurde
	wait(1);													
	while(my.health > 50)															//solange der Spieler lebt

//here begins enemys 1 action

	{
		if((move_lenght <= 0)&&(vec_dist(my.x, player.x) < 300))		//wenn die Distanz zum Spieler kleiner als 300 quants ist und er sich ich twohin bewegen soll
		{
			var stand_per;															//lokale Variable
			ent_animate(my, "stand", stand_per, ANM_CYCLE);				//spiele stand anomation
			stand_per += 7 * time_step;										
			vec_set(temp, player.x);											//berechne den Winkél zum spieler
			vec_sub(temp, my.x);
			vec_to_angle(turn, temp);
			if(turn[0] < 0) turn[0] += 360;												//die nächsten zeilen sind für das drehen des Spieler (es ist so lang da es immer den kürzesten weg dreht)
			turn[1] = my.pan;
			if(turn[1] < 0) turn[1] += 360;
			if(turn[0] > turn[1] && turn[0] < turn[1] + 180)
			{
				while(turn[0] > turn[1])
				{
					my.pan += 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			if(turn[0] < turn[1] - 180 && turn[0] < 180 && turn[1] > 180)
			{
				while(turn[0] > turn[1] || turn_help == 0)
				{
					if(my.pan > 360) my.pan -= 360;
					if(my.pan < 179 && my.pan > 0) turn_help = 1;
					my.pan += 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			turn_help = 0;
			if(turn[0] > turn[1] + 180 && turn[0] > 180 && turn[1] < 180)
			{
				while(turn[1] > turn[0] || turn_help == 0)
				{
					if(my.pan < 0) my.pan += 360;
					if(my.pan > 181 && my.pan < 360) turn_help = 1;
					my.pan -= 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] > 360) turn[1] -= 360;
					wait(1);
				}
			}
			if(turn[0] < turn[1] && turn[0] > turn[1] - 180)
			{
				while(turn[0] < turn[1])
				{
					my.pan -= 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			turn_help = 0;																												//hilfvariable zurücksetzen
			my.tilt = 0;																												//setze die drehungen der anderen winkel wieder auf 0
			my.roll = 0;
			ent_create("blaster_ball.mdl", vec_for_vertex(temp, me, 957), enemy_blaster_shoot);					//erstelle eine Kugel
			new_point.x = my.x + random(500)-250;																				//setze irgendwo in Abstand von 250 quants einen Punkt
			new_point.y = my.y + random(500)-250;
			new_point.z = my.z;
			if(c_content(new_point, 0) != 3)																						//wenn der neue Punkt in nicht drin ist
			{
				move_lenght = vec_dist(new_point, my.x);																		//setze die distanz auf den Abstand zwischen dem Punkt und meiner Positoin
			}
			else																															//wiederhole es wenn nciht
			{
				new_point.x = my.x + random(500)-250;
				new_point.y = my.y + random(500)-250;
				new_point.z = my.z;
				if(c_content(new_point, 0) != 3)
				{
					move_lenght = vec_dist(new_point, my.x);
				}
			}
			ent_animate(my, "stand", stand_per, ANM_CYCLE);									//animiere in Stand animation
			stand_per += 7 * time_step;
			vec_set(temp, new_point);																//finde winkel zum neuen punkt
			vec_sub(temp, my.x);
			vec_to_angle(turn, temp);
			if(turn[0] < 0) turn[0] += 360;															//die drehung(beschreibung oben)
			turn[1] = my.pan;
			if(turn[1] < 0) turn[1] += 360;
			if(turn[0] > turn[1] && turn[0] < turn[1] + 180)
			{
				while(turn[0] > turn[1])
				{
					my.pan += 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			if(turn[0] < turn[1] - 180 && turn[0] < 180 && turn[1] > 180)
			{
				while(turn[0] > turn[1] || turn_help == 0)
				{
					if(my.pan > 360) my.pan -= 360;
					if(my.pan < 179 && my.pan > 0) turn_help = 1;
					my.pan += 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			turn_help = 0;
			if(turn[0] > turn[1] + 180 && turn[0] > 180 && turn[1] < 180)
			{
				while(turn[1] > turn[0] || turn_help == 0)
				{
					if(my.pan < 0) my.pan += 360;
					if(my.pan > 181 && my.pan < 360) turn_help = 1;
					my.pan -= 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] > 360) turn[1] -= 360;
					wait(1);
				}
			}
			if(turn[0] < turn[1] && turn[0] > turn[1] - 180)
			{
				while(turn[0] < turn[1])
				{
					my.pan -= 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			turn_help = 0;
			my.tilt = 0;
			my.roll = 0;
			wait(-0.1);
		}
		if(move_lenght > 0)																	//wenn er sich bewegen soll
		{
			var walk_per;
			my_speed.x = 6 * time_step;	
			c_move(me, my_speed, nullvector, GLIDE | IGNORE_PASSABLE);			//bewegt ihn
			move_lenght -= my_speed.x;
			ent_animate(my, "walk", walk_per, ANM_CYCLE);							//und animiert ihn in seiner Walk animation
			walk_per += 12 * time_step;
		}
		else
		{
			var stand_per;																		//sonst stand animation
			ent_animate(my, "stand", stand_per, ANM_CYCLE);
			stand_per += 7 * time_step;
		}
		result = c_trace(my.x, vector(my.x, my.y, my.z - 500), IGNORE_ME | IGNORE_YOU | IGNORE_SPRITES | IGNORE_MODELS | USE_BOX);		//graviation
		vec_set(temp, nullvector);
		temp.z = result*(-1);
		c_move(me, temp, nullvector, GLIDE);
		wait(1);
	}
	opponent_ninja_C_wounded();
}
/////
function opponent_ninja_C_wounded()
{
	VECTOR temp;												//3 lokale vectoren
	VECTOR my_speed;
	VECTOR new_point;
	VECTOR sword_start, sword_end;
	var turn[3];												//5 lokale variablen
	var attack_per;
	var turn_help;
	var move_lenght = 0;
	////
	set(me, TRANSLUCENT);
	my.alpha = 100;
	ent_create("cell_bumm01.pcx", vec_for_vertex(temp, my, 2358), explode);
	wait(-0.1);
	ent_create("cell_bumm01.pcx", vec_for_vertex(temp, my, 334), explode);
	wait(-0.05);
	ent_create("cell_bumm01.pcx", vec_for_vertex(temp, my, 2721), explode);
	ent_morph(me, "ninja.mdl");
	reset(my, TRANSLUCENT);
	wait(-1);
	my.scale_x = 1.5;
	my.scale_y = 1.5;
	my.scale_z = 1.5;
	c_setminmax(me);
	
	while(my.health > 0)

//here begins enemys 2 action

	{
		if((move_lenght <= 0)&&(vec_dist(my.x, player.x) < 300))
		{
			var stand_per;
			ent_animate(my, "stand", stand_per, ANM_CYCLE);
			stand_per += 7 * time_step;
			vec_set(temp, player.x);
			vec_sub(temp, my.x);
			vec_to_angle(turn, temp);
			if(turn[0] < 0) turn[0] += 360;
			turn[1] = my.pan;
			if(turn[1] < 0) turn[1] += 360;
			if(turn[0] > turn[1] && turn[0] < turn[1] + 180)
			{
				while(turn[0] > turn[1])
				{
					my.pan += 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			if(turn[0] < turn[1] - 180 && turn[0] < 180 && turn[1] > 180)
			{
				while(turn[0] > turn[1] || turn_help == 0)
				{
					if(my.pan > 360) my.pan -= 360;
					if(my.pan < 179 && my.pan > 0) turn_help = 1;
					my.pan += 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			turn_help = 0;
			if(turn[0] > turn[1] + 180 && turn[0] > 180 && turn[1] < 180)
			{
				while(turn[1] > turn[0] || turn_help == 0)
				{
					if(my.pan < 0) my.pan += 360;
					if(my.pan > 181 && my.pan < 360) turn_help = 1;
					my.pan -= 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] > 360) turn[1] -= 360;
					wait(1);
				}
			}
			if(turn[0] < turn[1] && turn[0] > turn[1] - 180)
			{
				while(turn[0] < turn[1])
				{
					my.pan -= 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			turn_help = 0;
			my.tilt = 0;
			my.roll = 0;
			var walk_per = 0;
			while(vec_dist(my.x, player.x) > 50)
			{
				c_move(me, vector(5 * time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE);
				ent_animate(my, "walk", walk_per, ANM_CYCLE);
				walk_per += 12 * time_step;
				vec_set(temp, player.x);
				vec_sub(temp, my.x);
				vec_to_angle(my.pan, temp);
				wait(1);
			}
			vec_zero(temp);
			attack_per = 0;
			while(attack_per < 98)
			{
				vec_for_vertex(sword_start, my, 509);
				vec_for_vertex(sword_end, my, 510);
				ent_animate(me, "attack_sword_up", attack_per, ANM_CYCLE);
				attack_per += 5 * time_step;
				if((c_trace(sword_start, sword_end, IGNORE_ME | IGNORE_PASSABLE) > 0)&&(attack_per > 60))
				{
					if(you == player)
					{
						printf("Wuhu, i hit you! xD ^^ ROFL", NULL);
					}
				}
				wait(1);
			}
			new_point.x = my.x + random(500)-250;
			new_point.y = my.y + random(500)-250;
			new_point.z = my.z;
			if(c_content(new_point, 0) != 3)
			{
				move_lenght = vec_dist(new_point, my.x);
			}
			ent_animate(my, "stand", stand_per, ANM_CYCLE);
			stand_per += 7 * time_step;
			vec_set(temp, new_point);
			vec_sub(temp, my.x);
			vec_to_angle(turn, temp);
			if(turn[0] < 0) turn[0] += 360;
			turn[1] = my.pan;
			if(turn[1] < 0) turn[1] += 360;
			if(turn[0] > turn[1] && turn[0] < turn[1] + 180)
			{
				while(turn[0] > turn[1])
				{
					my.pan += 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			if(turn[0] < turn[1] - 180 && turn[0] < 180 && turn[1] > 180)
			{
				while(turn[0] > turn[1] || turn_help == 0)
				{
					if(my.pan > 360) my.pan -= 360;
					if(my.pan < 179 && my.pan > 0) turn_help = 1;
					my.pan += 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			turn_help = 0;
			if(turn[0] > turn[1] + 180 && turn[0] > 180 && turn[1] < 180)
			{
				while(turn[1] > turn[0] || turn_help == 0)
				{
					if(my.pan < 0) my.pan += 360;
					if(my.pan > 181 && my.pan < 360) turn_help = 1;
					my.pan -= 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] > 360) turn[1] -= 360;
					wait(1);
				}
			}
			if(turn[0] < turn[1] && turn[0] > turn[1] - 180)
			{
				while(turn[0] < turn[1])
				{
					my.pan -= 8 * time_step;
					turn[1] = my.pan;
					if(turn[1] < 0) turn[1] += 360;
					wait(1);
				}
			}
			turn_help = 0;
			my.tilt = 0;
			my.roll = 0;
			wait(-0.1);
		}
		if(move_lenght > 0)
		{
			var walk_per;
			my_speed.x = 6 * time_step;
			c_move(me, my_speed, nullvector, GLIDE | IGNORE_PASSABLE);
			move_lenght -= my_speed.x;
			ent_animate(my, "walk", walk_per, ANM_CYCLE);
			walk_per += 8 * time_step;
		}
		else
		{
			var stand_per;
			ent_animate(my, "stand", stand_per, ANM_CYCLE);
			stand_per += 7 * time_step;
		}
		result = c_trace(my.x, vector(my.x, my.y, my.z - 500), IGNORE_ME | IGNORE_YOU | IGNORE_SPRITES | IGNORE_MODELS | USE_BOX);
		vec_set(temp, nullvector);
		temp.z = result*(-1);
		c_move(me, vector(0,0,temp.z), nullvector, GLIDE);
		wait(1);
	}
	opponent_ninja_C_dying();
}
/////
function opponent_ninja_C_dying()
{
	var dead_per = 0;
	////
	while(dead_per < 98)
	{
		ent_animate(me, "death", dead_per, ANM_ADD);
		dead_per += 5 * time_step;
		wait(1);
	}
	set(me, PASSABLE | TRANSLUCENT);
	wait(-1);
	while(my.alpha > 10)
	{
		my.alpha -= 10 * time_step;
		wait(1);
	}
	ptr_remove(me);
}





"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1