So, I coded this test swf. Please give it a short play. Use the arrow keys to navigate and the spacebar to build up a short bash.
One thing you should notice while playing is that you can enter 'state 2' while moving up, down, left, right, up+right, or down+left.
BUT if you move up+left or down+right you can't enter 'state 2' at all unless you're still holding space as you let go of the keys necessary to propel yourself in those directions, which (to me) feels awkward to do in contrast to how the other directions work. I'd like to fix it, but I don't know what's causing the problem.
The code to maneuver the 'ghost' looks like this:
//use LEFT & RIGHT to move if(Key.isDown(Key.LEFT)) { ghosty.xSpeed -= ghosty.xAccel; ghosty.xDecel = 0; ghosty.drctMe._rotation = 180; } if(Key.isDown(Key.RIGHT)) { ghosty.xSpeed += ghosty.xAccel; ghosty.xDecel = 0; ghosty.drctMe._rotation = 0; } //use LEFT & RIGHT to move //use UP & DOWN to move if(Key.isDown(Key.UP)) { ghosty.ySpeed -= ghosty.yAccel; ghosty.yDecel = 0; ghosty.drctMe._rotation = 270; } if(Key.isDown(Key.DOWN)) { ghosty.ySpeed += ghosty.yAccel; ghosty.yDecel = 0; ghosty.drctMe._rotation = 90; } //use UP & DOWN to move //more rotation stuff if(Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN)) { ghosty.drctMe._rotation = 135; } if(Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) { ghosty.drctMe._rotation = 225; } if(Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) { ghosty.drctMe._rotation = 315; } if(Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN)) { ghosty.drctMe._rotation = 45; } //more rotation stuff
The code that switches between states looks like this:
//changes the state of ghost if(Key.isDown(Key.SPACE)) { twobular = true; }else { twobular = false; } if(twobular == true) { ghosty.st = 2; ghosty.invul += 4; if(ghosty.invul >= 12) { ghosty.invul = 12; } } if(twobular == false && ghosty.invul > 0 && ghosty.st == 2) { ghosty.st = 0; } if(twobular == false && ghosty.invul <= 6 && ghosty.st == 0) { ghosty.st = 1; }
Could someone please offer an explanation as to why this is happening to the directions for up+left and down+right specifically? Is it just too many if statements? I'm so confused.