A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: paddle game and moving buttons

  1. #1

    Question paddle game and moving buttons

    I have a paddle game where the ball bounces of the paddle and hits blocks. (nothing special) It works but i was wondering is there a way to make it so that the ball bounces at a different angle if it hits the very edge of the paddle.

    Heres the code for the paddle:

    onClipEvent (enterFrame) {
    if (Key.isDown(Key.RIGHT)) {
    if (this._x<=485) {
    this._x += 13;
    }
    }
    if (Key.isDown(Key.LEFT)) {
    if (this._x>=25) {
    this._x -= 13;
    }
    }
    }


    and heres the code for the ball :

    onClipEvent (load) {
    dir = Math.round(Math.random()*1);
    speed = 15;
    if (dir == 1) {
    var Ang = 45;
    } else {
    var Ang = 135;
    }
    xspeed = speed*Math.cos((Ang)*Math.PI/180);
    yspeed = speed*Math.sin((Ang)*Math.PI/180);
    }
    onClipEvent (enterFrame) {
    this._x += xspeed;
    this._y += yspeed;
    if ((this._x<=5) || (this._x>=495)) {
    xspeed = -xspeed;
    }
    if ((this._y<=5) || (_root.pad.hitTest(this))) {
    yspeed = -yspeed;
    }
    if (this._y>420) {
    _root.lives -= 1;
    _root.score -= 10;
    if (_root.lives == 0) {
    _root.gotoAndPlay(5);
    }
    _x = 150;
    _y = 100;
    dir = Math.round(Math.random()*1);
    speed = 15;
    if (dir == 1) {
    var Ang = 45;
    } else {
    var Ang = 135;
    }
    xspeed = speed*Math.cos((Ang)*Math.PI/180);
    yspeed = speed*Math.sin((Ang)*Math.PI/180);
    }
    }

    If anyone knows how to help please post
    by the wat does anyone know how to make a moving button
    oh yah, and i am using MX
    Last edited by bob58; 08-20-2008 at 02:52 PM.

  2. #2
    Bald By Choice jasondefra's Avatar
    Join Date
    Mar 2008
    Location
    Wisconsin, USA
    Posts
    205
    1)Make sure the slider is at center registration.

    2)When the ball hits the slider, it needs to know where on sliders x-axis it is hitting and at what angle it is approaching from (make sure to convert angles to radians).

    3)When ball gets the info for where it is hitting on slider and the angle it is coming from, simple apply a directional change via adjusting xspeed and yspeed.

    And there you have the theory behind it, now it's up to you (or someone else on these boards who is nicer than I am) to figure out what syntax and formulas to use.

    And as for the buttons: use movieclips instead and script them into pseudo-buttons... that way you have full manipulative control without sacrificing functionality.

  3. #3
    o.k. thanks but how do you tell where the ball is on the sliders x-axis. i think i can do the rest

  4. #4
    is anyone going to help because i need to get this done

  5. #5
    Bald By Choice jasondefra's Avatar
    Join Date
    Mar 2008
    Location
    Wisconsin, USA
    Posts
    205
    This should guide you in the right direction: http://www.flashwiki.net/index.php?title=HitTest

  6. #6

    Exclamation

    o.k. i went there but i'm still confused. if anyone can tell me whats wrong please do. here is the part of the code that controls the balls movement:

    if ((this._x<=5) || (this._x>=495)) {
    xspeed = -xspeed;
    }
    if ((this._y<=5) || (_root.pad.hitTest(this))) {
    yspeed = -yspeed;
    }
    while (_root.ball.hitTest(_root.pad._x+0, _root.pad._y+0, true) || _root.ball.hitTest(_root.pad._x + 10, _root.pad._y + 0, true)) {
    xspeed = xspeed;
    yspeed = -yspeed;
    }

    this is just for the left side of the pad and the ball is suppose to move back in the direction it came from
    Last edited by bob58; 08-21-2008 at 04:21 PM.

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