|
« on: April 12, 2008, 04:06:27 am »
|
|
Create Event: //Instance ID variables //self_ID already exists ai_ID[0] = 0; //variable to store instance IDs of other ai_goku instances inst_count = 0; //how many other ai_goku instances are being tracked dir="d" follow_hero=true image_speed=0.2 movespeed=2 near_hero=false holdd=0 holdr=0 holdl=0 holdu=0 movestep=0 Step Event: //Move away from other ai_goku instances inst = 0 while (inst < inst_count) { inst += 1; if (point_distance(self.x,self.y,ai_ID[inst].x,ai_ID[inst].y) < 8) //if closer than 16 { opposite_x = (2 * self.x) - ai_ID[inst].x; //the other's x in the opposite direction opposite_y = (2 * self.y) - ai_ID[inst].y; //the other's y in the opposite direction move_towards_point(opposite_x,opposite_y,0.5); //move away from other ai_goku } } if distance_to_object(obj_hero) > 10 { follow_hero=true } if follow_hero=true { if obj_hero.y<y{follow_hero=true;dir="u";if place_free(x,y-1){y-=1}}; if obj_hero.y>y{follow_hero=true;dir="d";if place_free(x,y+1){y+=1}}; if obj_hero.x<x{follow_hero=true;dir="l";if place_free(x-1,y){x-=1}}; if obj_hero.x>x{follow_hero=true;dir="r";if place_free(x+1,y){x+=1}}; else { y-=0 y+=0 x-=0 x+=0 } if point_distance(x,y,obj_hero.x,obj_hero.y ) < 14 { hspeed = 0 vspeed = 0 follow_hero=false }} switch dir { case "d": sprite_index=spr_goku_d; break; case "r": sprite_index=spr_goku_r; break; case "u": sprite_index=spr_goku_u; break; case "l": sprite_index=spr_goku_l; break; } if follow_hero=false { switch dir { case "d": sprite_index=spr_goku_s_d; break; case "r": sprite_index=spr_goku_s_r; break; case "u": sprite_index=spr_goku_s_u; break; case "l": sprite_index=spr_goku_s_l; break;
}} depth = -y Collision ai_goku Event: //Keep track of other ai_goku instance IDs if (ai_ID[inst_count] = other.self_ID) //if other's ID already stored { //nothing } else //if other's ID not yet stored { inst_count += 1; ai_ID[inst_count] = other.self_ID; } When the ai's touch the direction is constant between the directions of "l" and "r" the ai will not appear in "d" or "u" it only appears in 2 directions while it should be 4. Here's the complete code for reference. http://www.megaupload.com/?d=WY7IZ0Z0
Logged
|