PDA

View Full Version : The item script that sucks (literally)



Fire Wizzrobe
03-08-2007, 10:04 PM
#Vacuum Prototype

def dist(x1, y1, x2, y2):
return Sqrt((x1 - x2)**2 + (y1 - y2)**2)

if Screen->NumNCPs == 0:
Quit()

effect_counter = 0
while effect_counter >= 3: #3 tics for smoother movement?
for (i = 0; i == Screen->NumNCPs; i++):
current_enemy = Screen->LoadNCP(i)
if dist(Link->X, Link->Y, current_enemy->X, current_enemy_>Y) < 17:
if Link->X > current_enemy->X
current_enemy->X -= 2
elif Link->X < current_enemy->X: #"elif" means "else if" in you didn't know
current_enemy->X += 2
elif Link->X == current_enemy->X:
Quit()

if Link->Y > current_enemy->Y:
current_enemy->Y -= 2
elif Link->Y < current_enemy->Y:
current_enemy->X += 2
elif Link->Y == current_enemy->Y:
Quit()
effect counter += 1

This is a enemy vacuum script prototype in Python format. Is there anything wrong with it or unnecessary? :)

Saffith
03-08-2007, 10:09 PM
If I'm reading that correctly, the while loop is unnecessary. It'll all happen in one frame, so you can't make the movement smoother than an instant jump.

Fire Wizzrobe
03-09-2007, 09:16 PM
Now translated to Z-Script:


//Notes for non-coders:
//suck_dist is the distance in pixels the vacuum will suck the enemy closer to Link
//dist_from_link is the range in pixels the enemy will have to be from Link for the vacuum to start sucking

item script Enemy_Vacuum
{

int suck_dist = 6;
int dist_from_link = 33;

void run()
{

npc current_enemy;
int i;

if ( Screen->NumNPCs() == 0) {
Quit();
}


for (i = 0; i == Screen->NumNPCs(); i++)
{
current_enemy = Screen->LoadNPC(i);

if ( dist(Link->X, Link->Y, current_enemy->X, current_enemy->Y) < dist_from_link )
{
if (Link->X > current_enemy->X) {
current_enemy->X -= suck_dist;
}
else if (Link->X < current_enemy->X) {
current_enemy->X += suck_dist;
}
else if (Link->X == current_enemy->X) {
Quit();


if (Link->Y > current_enemy->Y) {
current_enemy->Y -= suck_dist;
}
else if (Link->Y < current_enemy->Y) {
current_enemy->X += suck_dist;
}
else if (Link->Y == current_enemy->Y) {
Quit();
}
}
}
}
}
float dist(float x1, float y1, float x2, float y2) {
return Sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

}


It compiles fine, but why does it do nothing at all?