if (playerenters && !isweapon)
  toweapons -Zulite-Boots;
if (created && isweapon) {
  sethead zulite.gif;
  setani zulite_still,;

  this.on = true;
  this.speed = 0.6;
  this.key = {0,0,0,0,0,0,0,0,0,0,0};
  this.dirgo = {0,-1, -1,0, 0,1, 1,0};

  this.Cwalltest = {
    0.525,1, 1.475,1, 1.525,1, 2.475,1, 2.525,1, 0.475,1,
    0.5,1.025, 0.5,1.975, 0.5,2.025, 0.5,2.975, 0.5,3.025, 0.5,0.975,
    0.525,3, 1.475,3, 1.525,3, 2.475,3, 2.525,3, 0.475,3,
    2.5,1.025, 2.5,1.975, 2.5,2.025, 2.5,2.975, 2.5,3.025, 2.5,0.975
    };
  this.sidemove = {
    0.1,0, -0.1,0,
    0,0.1, 0,-0.1,
    0.1,0, -0.1,0,
    0,0.1, 0,-0.1
    };

  this.Csittiles = {
    0x2a9,0x2aa,0x2b9,0x2ba,
    0x2e1,0x2e2,0x2f1,0x2f2,
    0x676,0x677,0x678,0x686,0x687,0x688,
    0xa04,0xa05,0xa06,0xa07,0xa14,0xa15,0xa16,0xa17,0xa24,
    0xa25,0xa26,0xa27,0xa34,0xa35,0xa36,0xa37,
    0xd97,0xd98,0xda7,0xda8,
    0xf37,0xf38,0xf39,0xf47,0xf48,0xf49
    };
  this.Gsitcheck = {1.25,2,1.75,2};

  this.bush = {0x2,0x3,0x12,0x13};
  this.bushreplace = {0x2a5,0x2a6,0x2b5,0x2b6};
  this.bushleaps = {0};

  timeout = 0.05;
}
if (timeout && this.on==true) {
  this.x = playerx;
  this.y = playery;
  this.dir = playerdir;
  disabledefmovement;

  if (playerfreezetime<0) {
    Cgetkey();
    Cmove();
    Gsetsprite();
  }
  timeout = 0.05;
}

// --- Control ---
function Cgetkey() {
  this.oldkey = this.key;
  for (i=0; i<11; i++) this.key[i] = keydown(i);
}

function Cmove() {
  playermoved = false;
  Cwalkmove();
  CcheckASD();

  playerx = this.x;
  playery = this.y;
  playerdir = this.dir;
}
function Ccheckbushes() {
/*
  px = int(this.x + 1.5 + this.dirgo[this.dir*2  ]*2);
  py = int(this.y + 2   + this.dirgo[this.dir*2+1]*2);
  num = board[px+py*64];
  for (i=0; i<arraylen(this.bush); i++) if (num==this.bush[i]) {
    px -= (i%2);
    py -= int(i/2)%2;
    bushnum = int(i/4);
    for (tx=0; tx<2; tx++) for (ty=0; ty<2; ty++)
      board[px+tx+(py+ty)*64] = this.bushreplace[bushnum*4+tx+ty*2];
    updateboard px,py,2,2;
    putleaps this.bushleaps[bushnum],px,py;
    break;
  }
*/
}
function Cwalkmove() {
  for (i=0; i<4; i++) if (this.key[i]==true) {
    playermoved = true;
    this.dir = i;
    newx = this.x + this.dirgo[i*2]*this.speed;
    newy = this.y + this.dirgo[i*2+1]*this.speed;

    // Check for walls
    setarray wall,6;
    for (j=0; j<6; j++)
      wall[j] = onwall(newx+this.Cwalltest[i*12+j*2],
        newy+this.Cwalltest[i*12+j*2+1]);

    // Test for walls in front;
    if (wall[0]==true || wall[1]==true || wall[2]==true || wall[3]==true) {

      // Move the player outside of the wall
      if (i==0) this.y = int(this.y);
      else if (i==1) this.x = int(this.x+0.5)-0.5;
      else if (i==2) {
        if (this.y!=int(this.y)) this.y = int(this.y+1);
      } else if (i==3) {
        if (this.x+0.5!=int(this.x+0.5)) this.x = int(this.x+1.5)-0.5;
      }

    } else {
      // Apply new position
      this.x = newx;
      this.y = newy;
    }

    // Test 'sidemoves'
    if (wall[0]==true && wall[2]==false && wall[3]==false && wall[4]==false) {
      this.x += this.sidemove[i*4];
      this.y += this.sidemove[i*4+1];
    } else if (wall[0]==false && wall[1]==false && wall[3]==true && wall[5]==false) {
      this.x += this.sidemove[i*4+2];
      this.y += this.sidemove[i*4+3];
    }
  }

  // Fix for 1-field-bug (move to wall when near)
  ry = this.y-int(this.y);
  if (ry<1/16 || ry>15/16)
    this.y = int(this.y+1/16);
  alignx = this.x+0.5;
  rx = alignx-int(alignx);
  if (rx<1/16 || rx>15/16)
    this.x = int(alignx+1/16)-0.5;
}

function CcheckASD() {
  if (!weaponsenabled) return;

  if (this.key[6]==true)
    Ccheckbushes();
  else if (this.key[5]==true)
    Cattack();
  else if (this.key[4]==true)
    Cweapon();
}

function Cattack() {
  hitobjects 0.5,
    this.x+1.5+this.dirgo[this.dir*2]*1.5,
    this.y+2+this.dirgo[this.dir*2+1]*1.5;
}
function Cweapon() {
  if (selectedweapon>=0) {
    callweapon selectedweapon,bomyweaponfired;
  }
}

// --- Graphical ---
function Gsetsprite() {
  isonchair = false;
  for (i=0; i<arraylen(this.Gsitcheck)/2; i++) {
    if (board[int(this.x+this.Gsitcheck[i*2])+int(this.y+this.Gsitcheck[i*2+1])*64] in this.Csittiles) {
      isonchair = true;
      break;
    }
  }
/*  if (isonchair==true)
    setani bomy_sit,;
  else */
  if (playermoved==true)
    setani zulite_walk,;
  else
    setani zulite_still,;
}

