objectType max ("Max") {
	speechColour 255, 255, 255;
        speechGap 16;
	event lookAt {
                faceMax ();
		Say (sam, "Hey, it's Max!");
	}
	event pickUp {
                faceMax ();
		Say (sam, "No, he can walk just fine.");
	}
        event talkTo {
                faceMax ();
                Say (sam, "Hey Max...");
                faceSam ();
                Say (max, "What?");
                Say (sam, "Uh...nothing.");
        }
}

var maxActivate = FALSE;

sub makeMaxAnim () {
	return costume (
		# STANDING STILL...
		anim ('max/max.duc', 0),
		anim ('max/max.duc', 13),
		anim ('max/max.duc', 27),
		anim ('max/max.duc', 39),
		# WALKING...
		anim ('max/max.duc', 5,5,6,6,7,7,8,8,9,10,10,11,12,12),
		anim ('max/max.duc', 19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26),
		anim ('max/max.duc', 31,31,32,32,33,33,34,34,35,35,36,36,37,37,38,38),
		anim ('max/max.duc', 45,45,46,46,47,47,48,48,49,49,50,51,52,52),
		# TALKING...
		anim ('max/max.duc', 1,1,2,2,3,3,4,4,2,2,3,3),
		anim ('max/max.duc', 13,13,14,14,15,15,16,16,13,13,17,17,18,18),
		anim ('max/max.duc', 27,27,28,28,29,29,30,30),
		anim ('max/max.duc', 39,39,40,40,41,41,42,42,39,39,43,43,44,44)
	)
}

# Moves the max character (invoked by leftClick in interface.slu)
sub maxMove () {
	if (isCharacter (max)) {
		var a = getObjectX (sam) - getObjectX (max);
		if (a >= 0) {
			moveCharacter (max, getObjectX (sam) - 75, getObjectY (sam));
			turnCharacter (max, EAST);
		} else if (a < 0) {
			moveCharacter (max, getObjectX (sam) + 75, getObjectY (sam));
			turnCharacter (max, WEST);
		}
	}
}

sub faceMax () {
	var a = getObjectX (sam) - getObjectX (max);
	if (a >= 0) turnCharacter (sam, WEST);
	else if (a < 0) turnCharacter (sam, EAST);
}

sub faceSam () {
	var a = getObjectX (sam) - getObjectX (max);
	if (a >= 0) turnCharacter (max, EAST);
	else if (a < 0) turnCharacter (max, WEST);
}

var idleMax = 0;

sub maxIdle () {
    loop {
       if (idleMax < 30) {
           idleMax += 1;
           pause (2);
       }
       else {
           maxMove ();
           idleMax = 0;
       }
       pause (1);
    }
}