View difference between Paste ID: LY9Gv3j2 and RZqYgCbr
SHOW: | | - or go back to the newest paste.
1
public class ZombieController extends Script {
2
	int state = 0; //0 - delay 1 - run 2 - attack
3
	MoveComponent move;
4
	SearchTargetComponent search;
5
6
	public void initialize() {
7
		move = gameObject.getScript(MoveComponent.class);
8
		search = gameObject.getScript(SearchTargetComponent.class);		
9
	}
10
11
	public void update(float delta) {
12-
		if(search.haveTarget()) {
12+
		if(!move.inMotion())
13-
			if(search.targetIsClose(0.5f)) {
13+
			if(search.haveTarget()) {
14-
				state = 2;
14+
				if(search.targetIsClose(0.5f)) {
15
					state = 2;
16-
				move.moveTo(search.getTarget());
16+
				} else {
17-
				state = 1;
17+
					move.moveTo(search.getTarget());
18
					state = 1;
19-
		} else {
19+
				}
20-
			state = 0;
20+
21
				state = 0;
22
			}
23
		}
24
		//run animation, damage on the target, etc...
25
	}
26
27
	public void move(int x, int y) {
28
		if(state == 2) return;
29
		move.moveTo(x, y);
30
	}
31
}