Stop looking at this block of code and start looking at how often it's being hit, and when and why.
alright. while i do that, just in case any of you want to look, here's the entire code:
onClipEvent (load) {
///////////////
// constants //
///////////////
crawlSpeed = 5;
walkSpeed = 8;
jumpLimit = 18;
/////////////////////
// initializations //
/////////////////////
health = 100;
grav = 0;
jumpCount = 0;
canWalk = false;
_root.gamePaused = false;
canYMove = true;
jumpSpeedReset = 13;
jumpSpeed = jumpSpeedReset;
_root.zKey = "";
_root.xKey = "";
_root.cKey = "";
_root.vKey = "";
_root.spaceBar = "jump";
////////////////////
// Wii Remote API //
////////////////////
import com.wiicade.*;
var remote = Wii.getRemote(0);
KeyboardController.setKeyMapping(WiiRemote.BUTTON_2,Key.SPACE);
KeyboardController.setKeyMapping(WiiRemote.BUTTON_B,86);
remote.setRotated(true);
}
onClipEvent (enterFrame) {
////////////////
// health box //
////////////////
health1 = health%1;
health2 = health%2;
health3 = health%3;
if (health3>0) {
_root.hud.hundredsdigit.gotoAndStop(health3);
} else {
_root.hud.hundredsdigit.gotoAndStop(10);
}
if (health2>0) {
_root.hud.tensdigit.gotoAndStop(health2);
} else {
_root.hud.tensdigit.gotoAndStop(10);
}
if (health1>0) {
_root.hud.onesdigit.gotoAndStop(health1);
} else {
_root.hud.onesdigit.gotoAndStop(10);
}
//_root.gamePaused stops everything when game is paused
if (!(_root.gamePaused)) {
//////////////////////////
// x movement/collision //
//////////////////////////
//walking left
if ((remote.isDown(WiiRemote.BUTTON_LEFT)) && (!(_root.walls.leftWall.hitTest(_x, _y, true)) && !(_root.walls.leftWall.hitTest(_x, _y+(_height/2), true)) && !(_root.walls.leftWall.hitTest(_x, _y+_height, true)))) {
if (walk == false) {
_x -= crawlSpeed;
} else {
_x -= walkSpeed;
}
}
//walking right
if ((remote.isDown(WiiRemote.BUTTON_RIGHT)) && !(_root.walls.rightWall.hitTest(_x+_width, _y, true)) && !(_root.walls.rightWall.hitTest(_x+_width, _y+(_height/2), true)) && !(_root.walls.rightWall.hitTest(_x+_width, _y+_height, true))) {
if (walk == false) {
_x += crawlSpeed;
} else {
_x += walkSpeed;
}
}
//wall buffers
if (_root.walls.leftWall.hitTest(_x, _y+(_height/2), true)) {
while (_root.walls.leftWall.hitTest(_x-1, _y+(_height/2), true)) {
_x++;
}
}
if (_root.walls.rightWall.hitTest(_x+_width, _y+(_height/2), true)) {
while (_root.walls.rightWall.hitTest(_x+_width+1, _y+(_height/2), true)) {
_x--;
}
}
//////////////////////////
// y movement/collision //
//////////////////////////
//ceiling buffer - if too far in ceiling, pushes out
i = 0;
while (i<_width) {
if (_root.walls.ceiling.hitTest(_x+i, _y, true)) {
while (_root.walls.ceiling.hitTest(_x+i, _y-1, true)) {
canYMove = false;
_y++;
}
}
i++;
}
//mid-air falling
if (!(_root.walls.ground.hitTest(_x+(_width/2), _y+_height+1, true))) {
_y += grav;
grav += 2;
}
//ground collision/buffer, also enables jump when 2/Space is not pressed
if ((_root.walls.ground.hitTest(_x, _y+_height, true)) or (_root.walls.ground.hitTest(_x+(_width/2), _y+_height, true)) or (_root.walls.ground.hitTest(_x+_width, _y+_height, true))) {
while ((_root.walls.ground.hitTest(_x, _y+_height+1, true)) or (_root.walls.ground.hitTest(_x+(_width/2), _y+_height+1, true)) or (_root.walls.ground.hitTest(_x+_width, _y+_height+1, true))) {
_y--;
jumpCount = 0;
jumpSpeed = jumpSpeedReset;
}
if (!(remote.isDown(WiiRemote.BUTTON_2))) {
canJump = true;
canYMove = true;
}
grav = 0;
} else {
//disables jump in mid-air
canJump = false;
}
//jump from ground
if ((canJump) && (remote.isDown(WiiRemote.BUTTON_2)) && (jumpCount == 0) && !(_root.walls.ceiling.hitTest(_x+(_width/2), _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x, _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x+_width, _y-jumpSpeed, true))) {
_y -= jumpSpeed;
jumpCount += 1;
}
//continuing jump in midair
if (!(canJump) && (canYMove) && (remote.isDown(WiiRemote.BUTTON_2)) && (jumpCount>0) && (jumpCount<jumpLimit) && !(_root.walls.ceiling.hitTest(_x+(_width/2), _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x, _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x+_width, _y-jumpSpeed, true))) {
_y -= jumpSpeed;
jumpCount += 1;
//stopping jump after letting go of 2/Space
} else if (!(canJump) && (canYMove) && !(remote.isDown(WiiRemote.BUTTON_2)) && (jumpCount>0) && (jumpCount<jumpLimit) && !(_root.walls.ceiling.hitTest(_x+(_width/2), _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x, _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x+_width, _y-jumpSpeed, true))) {
_y -= jumpSpeed;
jumpSpeed -= 3;
//stopping jump when hit ceiling
} else if (((_root.walls.ceiling.hitTest(_x+(_width/2), _y-jumpSpeed, true)) or (_root.walls.ceiling.hitTest(_x, _y-jumpSpeed, true)) or (_root.walls.ceiling.hitTest(_x+_width, _y-jumpSpeed, true)))) {
canYMove = false;
jumpSpeed = 0;
}
////////////////
// walk/crawl //
////////////////
//sets walk if possible
if (remote.isDown(WiiRemote.BUTTON_B) && (canWalk)) {
if (!(_root.walls.ceiling.hitTest(_x, _y-25, true)) && !(_root.walls.ceiling.hitTest(_x+(_width/2), _y-25, true)) && !(_root.walls.ceiling.hitTest(_x+_width, _y-25, true))) {
walk = true;
}
} else {
walk = false;
}
//walking changes
if (walk) {
_xscale = 100;
_yscale = 150;
jumpSpeedReset = 20;
performOnce = true;
if (performOnce2) {
performOnce2 = false;
_y -= 25;
}
} else {
_xscale = 150;
_yscale = 100;
jumpSpeedReset = 13;
if (performOnce) {
performOnce = false;
_y += 25;
}
performOnce2 = true;
}
/////////////////
// other stuff //
/////////////////
//makes boundary movieclips invisible
_root.walls.ground._visible = false;
_root.walls.leftWall._visible = false;
_root.walls.rightWall._visible = false;
_root.walls.ceiling._visible = false;
//hud stuff
if (canWalk) {
_root.vKey = "walk";
}
}
}