home *** CD-ROM | disk | FTP | other *** search
- function choosestate()
- {
- statecounter += 1;
- if(statecounter >= statelength)
- {
- changestate();
- statecounter = 0;
- statelength = random(100);
- }
- }
- function changestate()
- {
- chance = random(10);
- if(chance >= 6)
- {
- state = "attack";
- }
- else if(chance >= 2)
- {
- state = "defend";
- }
- else if(chance >= 0)
- {
- state = "idle";
- }
- }
- function fight()
- {
- if(state == "attack")
- {
- attack();
- }
- else if(state == "defend")
- {
- defend();
- }
- else if(state == "idle")
- {
- idle();
- }
- }
- function idle()
- {
- enemyslowdown();
- }
- function attack()
- {
- enemyleftturn();
- enemyfire();
- }
- function defend()
- {
- enemyforward();
- }
-