PDA

View Full Version : Shooting in 8 directions



geebee
June 10th, 2005, 07:06 AM
Greetings..

New problem for you guys to chew on:

In my little shooter game I control the player movement with the arrow keys, space for shooting and wasd for aiming up,down,left and right.

If the player presses the w (aim north) AND the d (aim east) keys at the same time I want the player to aim northeast.

How do I achieve that?

Right now my aiming code looks like this:

//aiming
if (Key.isDown(87)) {
this._rotation = 0;
fire();
}
if (Key.isDown(83)) {
this._rotation = 180;
fire();
}
if (Key.isDown(68)) {
this._rotation = 90;
fire();
}
if (Key.isDown(65)) {
this._rotation = 270;
fire();
}
// aiming end

ademuk
June 10th, 2005, 09:31 AM
longer than i wished, but it works a treat. I've simply nested the additional second button conditionals within the main ones.




onClipEvent (enterFrame) {
if (Key.isDown(87)) {
tmp_rotation = 0;
if (Key.isDown(68)) {
tmp_rotation = 45;
}
if (Key.isDown(65)) {
tmp_rotation = 325;
}
fire();
}

if (Key.isDown(83)) {
tmp_rotation = 180;
if (Key.isDown(68)) {
tmp_rotation = 135;
}
if (Key.isDown(65)) {
tmp_rotation = 225;
}
fire();
}

if (Key.isDown(68)) {
tmp_rotation = 90;
if (Key.isDown(83)) {
tmp_rotation = 135;
}
if (Key.isDown(87)) {
tmp_rotation = 45;
}
fire();
}

if (Key.isDown(65)) {
tmp_rotation = 270;
if (Key.isDown(83)) {
tmp_rotation = 225;
}
if (Key.isDown(87)) {
tmp_rotation = 315;
}
fire();
}

this._rotation = tmp_rotation;
}



Adem G

nathan99
June 11th, 2005, 01:59 AM
one thing adem y r u repeating iur keydowns?

nathan99
June 11th, 2005, 02:01 AM
to get diagonals you would do for example

if (Key.isDown(83) && (Key.isDown(87))) {
//diagonal angle(rotation)
}

geebee
June 14th, 2005, 10:11 AM
Thanks ademuk and Nathan

Your soulutions have brought on another problem with some true/false conditions I have set up for my shooting function, but that is something I can figure out.. until then your answers have gotten me one step further the completion of my game, thank you very much for the quick answers!

nathan99
June 14th, 2005, 05:54 PM
what problems?

dominicaninja
June 16th, 2005, 02:23 PM
I don't know if you guys have had this issue but if you try to set aim keys to the arrow keys and try to aim diagonally AND shoot, you can get a key buffer problem, meaning the third key won't count. I noticed using the 'a' or 's' keys for shooting are safe for aiming diagonally with the arrow keys. Or maybe that depends on your machine?