A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [F8] How do I set this up?

  1. #1
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549

    [F8] How do I set this up?

    Quote 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.
    Z¡µµ¥ D££

    Soup In A Box

  2. #2
    Senior Member
    Join Date
    Apr 2005
    Posts
    118

    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;
    			}
    		};
    	}
     }
    }

  3. #3
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    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
    Z¡µµ¥ D££

    Soup In A Box

  4. #4
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    also, how do you use linkage names? I still don't entirely understand...
    Z¡µµ¥ D££

    Soup In A Box

  5. #5
    Senior Member
    Join Date
    Apr 2005
    Posts
    118
    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?

  6. #6
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    Okay...I know what you mean by intense projects with unrealistic deadlines...

    well good luck!

    and thanks again!
    Z¡µµ¥ D££

    Soup In A Box

  7. #7
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    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?
    Z¡µµ¥ D££

    Soup In A Box

  8. #8
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    bump!?
    Z¡µµ¥ D££

    Soup In A Box

  9. #9
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    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_"+bbullet_holder.getNextHighestDepth(10002000));
    //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_"+bbullet_holder.getNextHighestDepth(10002000)); 
    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.

  10. #10
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    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
    Z¡µµ¥ D££

    Soup In A Box

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center