Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 01-15-2011, 07:43 AM   #1
stilianos
Registered User
 
Join Date: Nov 2010
Posts: 16
Default Simple Multi Directional Shooting

I'm having a little trouble coding in multi-directional shooting in my game:

Basically I have:

Code:
if (left)
			{
				player.x -=  player.agility;
			boltDir = 270;
			}
			if (down)
			{
				player.y +=  player.agility;
			boltDir = 180;
			}
			if (right)
			{
				player.x +=  player.agility;
			boltDir = 90;
			}
			if (up)
			{
				player.y -=  player.agility;
			boltDir = 0;
			}
			
			if (up && right)
			{
				boltDir = 45;
			}
			if (up && left)
			{
				boltDir = 315;
			}
			if (down && right)
			{
				boltDir = 135;
			}
			if (down && left)
			{
				boltDir = 225;
			}
boltDir is the direction of the fired object, the above code works great, the only problem is 50% of the time if you are trying to do a diagonal shot for example up-left, it will get stuck and go left or up not diagonally.

Anyone know how to improve this?

Thanks
stilianos is offline   Reply With Quote
Old 01-16-2011, 04:48 PM   #2
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

How are the down, left, up, right values set?
rrh is offline   Reply With Quote
Old 01-18-2011, 05:44 AM   #3
stilianos
Registered User
 
Join Date: Nov 2010
Posts: 16
Default

event listener of keyDown and keyUp for the arrow keys.
stilianos is offline   Reply With Quote
Old 01-18-2011, 01:15 PM   #4
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

Okay, that sounds like it *should* work.

Throw some traces in there to see if the values of them are right, and if the "if" statements are executing when you'd expect them to.
Code:
trace('values=',up,right);
if (up && right)
{
	trace('up + right');
	boltDir = 45;
}
If these are all working as you'd expect, look next at what it does with boltDir. If the values aren't right, double-check the keyDown and keyUp listeners.
rrh is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:56 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.