-
var x:Number = 1; x /= 0;
[F8] How do I set this up?
Originally Posted by ZippyDee
I am making a game called Cereal Runner 3 (if that doesn't work try this) for my website. However, it is currently really hard and I have been trying to find ways to make it easier (if you have any ideas that would be great). One idea that I had was to make a gun that pushed the cop ships back, but I don't know how to make the code for the gun...
This is the current code in the boat:
Code:
onClipEvent (load) {
//When the movie clip first loads
Speed = 0;
//Set speed variable to be zero.
}
onClipEvent (enterFrame) {
//At every frame,
Speed *= .9;
//Decrease the speed. (Keep making it 90% of what it currently is)
if (Key.isDown(Key.UP)) {
//When you press UP,
Speed = Speed + _root.sp;
//Add more speed.
}
if (Key.isDown(Key.DOWN)) {
//When you press UP,
Speed = Speed - _root.sp;
//Create negative speed.
}
if (Key.isDown(Key.RIGHT)) {
//When you press RIGHT,
_rotation += _root.s;
//Rotate RIGHT 4 Degrees
}
if (Key.isDown(Key.LEFT)) {
//When you press LEFT,
_rotation -= _root.s;
//Rotate LEFT 4 Degrees
}
Angle = _rotation*(Math.PI/180);
//Angle of rotation in radians.
_x += Math.sin(Angle)*Speed;
_y -= Math.cos(Angle)*Speed;
}
sp is a variable that I use to change speed
s is a variable i use to change the speed of rotation
I can use a getBounds to push the cops back, I just don't know how to make the gun fire in the direction the boat is facing...or even fire at all. I also need it to not go rapidfire. I need a way to make it so I can make it possible to buy upgrades at the shop to make them fire more rapidly.
This is the first full game I've made, so it would be nice if you could explain what your codes do so I can better understand actionscript!
Your help is EXTREMELY appreciated!
~Zippy Dee
Ted Newman
Please evaluate my website (well technically my website with a friend)! I know there's not much on it, but we just started it a few months ago.
P.S. I know there are some glitches in the game. Feel free to tell me about them just in case, but I probably already know them all. I'll fix them when I get everything set up.
-
This code shoots bullets in the direction the player is facing
I had the same problem ... took forever to get it right! It was a long time ago so I don't think I could explain it well, but it should help you. It fires a movie clip with the linkage name "bullet" every time you click the mouse. The player has code that makes it turn left and right.
Code:
onMouseDown = function() {
if(game_playing == true){
if (player._currentframe == 1) { /*There are times in my game the player can't fire, it gets sent to frame 2 (as a penalty) where this code won't allow it to fire. */
b++;
bullet = bullet_holder.attachMovie("bullet", "bullet_"+b, bullet_holder.getNextHighestDepth(1000, 2000));
bullet.dir = dx*-1;
bullet._x = player._x+(20*bullet.dir)/10;
bullet._y = player._y;
bullet._yscale = 32+(((bullet._y-210)/300)*40);
bullet._xscale = bullet._yscale;
bullet._yspeed = sp;
bullet._xspeed = xsp;
sp = 1;
if (bullet.dir<0) {
bullet._xscale = -Math.abs(bullet._xscale);
}
bullet.onEnterFrame = function() {
this._x += (4*this.dir)/1;
if (bullet._x>760) {
bullet_holder[name].removeMovieClip();
} else if (bullet._x<50) {
bullet_holder[name].removeMovieClip();
}
if (bullet._y>450) {
sp++;
this._y += this._yspeed;
}
};
}
}
}
-
var x:Number = 1; x /= 0;
thanks so much!
I just have a few questions.
Does this work for a free-rotating character?
what sets the speed of movement for the bullet?
Can you explain parts of the code and variables?
again, thank you
~Zippy Dee
Ted Newman
-
var x:Number = 1; x /= 0;
also, how do you use linkage names? I still don't entirely understand...
-
I'm sorry, man, I'm in the thick of an intense project under an unrealistic deadline - I just can't help you right now. The answers to your questions are complex -- can another Flashkit member help him out?
-
var x:Number = 1; x /= 0;
Okay...I know what you mean by intense projects with unrealistic deadlines...
well good luck!
and thanks again!
-
var x:Number = 1; x /= 0;
I'm going to guess that "sp" is the speed of the bullet...that's about as far as I can decode.
This is too advanced for me. Could someone else please help me figure it out?
oh, and is there a way to set the distance it travels?
-
var x:Number = 1; x /= 0;
-
Who needs pants?
Hey man, Haven't checked my pm's for a while. I'll try explain eileenb's code. Coments are in the code
PHP Code:
//Assign a function to the mouse down function, it will be called when ever the mouse is down
onMouseDown = function() {
//If the game is currently playing
if(game_playing == true){
//And if the player movieclip is currently on frame 1
if (player._currentframe == 1) {
//Increment b by one. b seems to be a variable that increments as the bullets are added to the screen
b++;
//create a variable called bullet, which is a reference to a movieclip that is retrieved from the library and attached to the bullet_holder movieclip
bullet = bullet_holder.attachMovie("bullet", "bullet_"+b, bullet_holder.getNextHighestDepth(1000, 2000));
//Assign a variable to the movieclip call dir and assign a direction
bullet.dir = dx*-1;
//Change the bullets _x position depending on what direction is set to
bullet._x = player._x+(20*bullet.dir)/10;
//change the bullets y position
bullet._y = player._y;
//Change the bullets _yscale (Increase/Decrease the size of the bullet)
bullet._yscale = 32+(((bullet._y-210)/300)*40);
//Change the bullets _xscale (Increase/Decrease the size of the bullet)
bullet._xscale = bullet._yscale;
//Create a variable for how fast the bullet moves along the y axis
bullet._yspeed = sp;
//Create a variable for how fast the bullet moves along the y axis
bullet._xspeed = xsp;
//Asign a value to sp
sp = 1;
//If the bullets direction is less then zero
if (bullet.dir<0) {
//Change the bullets x position
bullet._xscale = -Math.abs(bullet._xscale);
}
//Assign an onEnterFrame function to be called every frame, to update the bullets position
bullet.onEnterFrame = function() {
//Move the bullet along the x axis
this._x += (4*this.dir)/1;
//If the bullet x position is greater then 760 (probably stage width)
if (bullet._x>760) {
//Then remove the bullet
bullet_holder[name].removeMovieClip();
//Else if its less then 50
} else if (bullet._x<50) {
//Then remove the bullet
bullet_holder[name].removeMovieClip();
}
//if the bullet y is greater then 450
if (bullet._y>450) {
//Then increase the bullet yspeed by 1
sp++;
//Then move the bullet along the y axis at its current speed
this._y += this._yspeed;
}
};
}
}
}
How linkage names work is, first you need to create a movieclip in flash lets say a ball. You can then remove it from the stage. All we need is a reference of the ball in Flash's library. Now in the library select the new ball movie clip. And right click and select linkage. In the box that pops up put a tick in the box. Export for actionscript and give it a name in the top text box marked Identifier, lets say ball. Click ok and your done. Now you can reference this movieclip in your action script. Like the above example does with.
PHP Code:
bullet = bullet_holder.attachMovie("bullet", "bullet_"+b, bullet_holder.getNextHighestDepth(1000, 2000));
the bit in "bullet" is a link to the movieclip in the Library.
Hope this help's. If I have time I'll show you how I have done it in the past.
-
var x:Number = 1; x /= 0;
Wow, thanks for all the help...I couldn't get that to work correctly, so I tried to make something simpler.
Code:
onMouseDown = function(){
_root.bullet._x = _root.boat._x;
_root.bullet._y = _root.boat._y;
_root.bullet._rotation = _root.boat._rotation;
_root.bullet._visible = true;
}
in the boat movie clip
Code:
onClipEvent(enterFrame){
Angle = _rotation*(Math.PI/180);
_x += Math.sin(Angle)*10;
_y -= Math.cos(Angle)*10;
}
in the bullet.
I'll see what I can do with that.
Thanks for your help!
~Zippy Dee
Ted Newman
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|