To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 02-17-2007, 02:46 PM   #1
sora72
Member
 
Join Date: Sep 2006
Posts: 70
[F8] Making a shooting game

Hello, i have a quick question.

I'm making a shooting game where you play as a man with a gun and the view is an eagle-eye view (you can only see the man's head). The gun has 8 angles (up, down, left, right and diagonals) and the 'bullet' which I want the gun to shoot is a straight line. I made it so the bullet is the same angle as the gun, but what I can't do is make it move in the right way i want it to move (ex. Move up when the gun is pointing up). Is there a code for this?
sora72 is offline   Reply With Quote
Old 02-17-2007, 06:09 PM   #2
sora72
Member
 
Join Date: Sep 2006
Posts: 70
please help!! ive been wondering about this for a very long time
sora72 is offline   Reply With Quote
Old 02-17-2007, 06:11 PM   #3
jAQUAN
Total Universe Man
 
jAQUAN's Avatar
 
Join Date: Jul 2000
Location: NaN
Posts: 2,061
Just make a gun clip and attach the bullet inside the clip. That way you only have to move the bullet forward on its local space. Then you can just rotate your gun clip to change the direction.
__________________
I approve this message.
AS3SOURCE: @ @ @ @
SD | fk css | Believe the HYPE | I tweet.
I hate it when I sit down to play a game of Monopoly and later realize that I have just lost $400 playing pai gow poker. - creativeinsomnia
jAQUAN is offline   Reply With Quote
Old 02-17-2007, 06:42 PM   #4
sora72
Member
 
Join Date: Sep 2006
Posts: 70
that would work, but lets say you point left and shoot. If you turn to the right, the bullet will turn too.
sora72 is offline   Reply With Quote
Old 02-17-2007, 08:36 PM   #5
sora72
Member
 
Join Date: Sep 2006
Posts: 70
please help!!!
sora72 is offline   Reply With Quote
Old 02-19-2007, 12:30 AM   #6
sora72
Member
 
Join Date: Sep 2006
Posts: 70
Can anyone help!??
sora72 is offline   Reply With Quote
Old 02-19-2007, 04:27 AM   #7
Katnap Kaos
Modulator
 
Katnap Kaos's Avatar
 
Join Date: Nov 2003
Location: A shoebox outside of SM Megamall
Posts: 149
Since your Bullet is moving, I'm assuming you've put in an element of speed. So lets see here:

Code:
vel = the speed you want the bullet to travel
if it's going:

Code:
UP
speedY = -vel;
speedX = 0;

DOWN
speedY = vel;
speedX = 0;

LEFT
speedY = 0;
speedX = -vel;

RIGHT
speedY = 0;
speedX = vel;
and so on and so forth (I hope you don't need me to explain the other 4 directions)

So, all you need to do is get the direction the man is facing:

Code:
function getFacing(){
	you should be able to
	figure something out
	here, otherwise just email
	me, or just say so.
	
	return x, y; /*tell us whether x is going to be positive,
	negative or zero, and do the same for y. That should send
	our projectiles in the right direction.
	*/
}
Now that you know which direction the man is facing, you should know what the x and y components of speed are going to be (in other words, is the bullet going left, right or neither. Is it going up, down or neither).

Now all you need to do is shoot the bullet in that direction e.g.

Actions for an MC named bullet_034, where vel = 5 or whatever, and the man is facing LEFT:
Code:
onClipEvent(load){//You don't really need this onClipEvent(load).
	speedX = -vel;//When you create your bullet using attachMovie(),
	speedY = 0;//You can tell it these properties anyways.
}
onClipEvent(enterFrame){
	this._x += speedX;
	this._y += speedY;
}
Hope this helps.
__________________
As a Gamer, you play by the rules.
As a Programmer, you play as God.
Katnap Kaos is offline   Reply With Quote
Old 02-20-2007, 10:18 PM   #8
sora72
Member
 
Join Date: Sep 2006
Posts: 70
thanks it did!
sora72 is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 -4. The time now is 07:19 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.