Jump to content
  • Advertisement

DevonDoerfer

Member
  • Content Count

    20
  • Joined

  • Last visited

Community Reputation

100 Neutral

About DevonDoerfer

  • Rank
    Member
  1. DevonDoerfer

    help with Flash code

    Strange. so you could set the ball speed and it worked (or leave it blank and it defaulted to 10) and the score worked correctly. I think I may do as you said and completely start over from scratch. Anyway thanks for all the help and advice.
  2. DevonDoerfer

    help with Flash code

    defiantly better. Thanks.
  3. DevonDoerfer

    help with Flash code

    Here is the current code: [source lang="as3"] onLoad = function(){ init(); ball.checkOptions(); } // end onLoad event handler function init(){ Mouse.hide(); // init ball position ball._x = paddle1._x + 20; ball._y = paddle1._y; ball.dy = 0; ball.dy = 10; trace (ball.dy); // paddle2.speed is opponent speed // determines max dy for opponent // 15 is nearly flawless // 0 is dead paddle2.speed = 10 playerScore = 0 oppScore = 0 } // end init // paddle1 control code paddle1.onEnterFrame = function(){ paddle.checkBoundaries(); paddle1._y = _root._ymouse; } // end paddle1 control // paddle 2 control code paddle2.onEnterFrame = function(){ // check to see if ball is above or below opponent if (ball._y < paddle2._y){ // move opponent up paddle2.dy = -paddle2.speed; } else { // move opp down paddle2.dy = paddle2.speed; } // end if paddle2._y += paddle2.dy; } // end paddle2 control paddle.CheckBoundaries = function(){ if (paddle1._y > Stage.height){ paddle1._y = 0 } // end if } // end paddleCheckBoundaries // ball bounce control code ball.onEnterFrame = function(){ ball.move(); ball.checkBoundaries(); ball.checkPaddles(); } // end enterFrame ball.move = function(){ ball._x += ball.dx; ball._y += ball.dy; } // end move ball.checkBoundaries = function(){ // code for making ball stop at the edge of the screen // ball bounces off the top and bottom walls if (ball._y > Stage.height -20){ ball.dy = -ball.dy } // end if if (ball._y < 0){ ball.dy = -ball.dy } // end if // if ball pass left of screen opponent scores if (ball._x < 0){ oppScore++; // checks if opponent wins if (oppScore == 3 ){ gotoAndStop("lose"); } // end opponent check ball._x = paddle2._x - 50; ball._y = paddle2._y; ball.dy = 0 } // end if // if past the right of the stage. player scores if (ball._x > Stage.width){ playerScore++; // checks if player wins if (playerScore == 3){ gotoAndStop("win"); } // end player win check ball._x = paddle1._x + 30; ball._y = paddle1._y; ball.dy = 0; } // end if } // end check boundaries // code to check for paddle collision ball.checkPaddles = function(){ if (ball.hitTest(paddle1)){ ball.dx = -ball.dx; ball.dy = getDy(paddle); } // end if if (ball.hitTest(paddle2)){ ball.dx = -ball.dx; ball.dy = getDy(paddle); } // end if } // end checkpaddles // determine ball dy based on where ball hits paddle function getDy(paddle){ // relY is relative y of ball to paddle relY = ball._y - paddle1._y; trace (relY); // relPerc is relY / height of paddle // will range from -.5 to .5 relPerc = relY / ball._height; // trace (relPerc); // new DY ranges from -15 to +15 newDY = relPerc * 20; // trace (newDY); return newDY; } // end getDY // set ball speed and opponent options ball.checkOptions = function(){ if (_root._balldx == undefined||_root._balldx == 0){ ball.dx = 10; trace (ball.dx); } else { ball.dx = parseInt(_root._balldx); trace (ball.dx); if (isNaN(_root.balldx)) ball.dx = 10; } // end ball.dx speed option } // end ball.checkOptions[/source] the timeline is structured like this: startScreen mainGame win lose option all the screens except main game only have btn.onRelease code. Start screen has 2 buttons, one to go to straight to the mainGame frame, the other to go to the options frame. mainGame has the above code. win has a button to return to the startScreen frame lose has a button to return to the startScreen frame option has 2 input fields. One is the variable _root._balldx, the other is called paddle2.speed (This is supposed to control opponent speed but no code written for it. I assume it will be the same as the ball speed code). It also has one button the goes to the mainGame frame (my thinking was once they set the ball and opponent speed the go right to the game) I will try to write code with your suggestions, I am having trouble visualizing the single frame, create a movie clip inside of a movie clip but I will play around with and see if I can get it. EDIT: I forgot there is code on the startScreen but it it just for some movement on the screen: [source lang="as3"]init(); function init(){ // inital ball speed ball.dx = 8; ball.dy = 8; // intial ball position ball._x = 570.95 ball._y = 365.00 // paddle2.speed is opponent speed // determines max dy for opponent // 15 is nearly flawless // 0 is dead paddle1.speed = 10 paddle2.speed = 10 } // end init // paddle1 control code paddle1.onEnterFrame = function(){ paddle1._y = ball._y } // end paddle1 control // paddle 2 control code paddle2.onEnterFrame = function(){ paddle2._y = ball._y } // end paddle2 control paddle.CheckBoundaries = function(){ if (paddle > Stage.height){ paddle_y = 0 } // end if } // end paddleCheckBoundaries // ball bounce control code ball.onEnterFrame = function(){ ball.move(); ball.checkBoundaries(); ball.checkPaddles(); } // end enterFrame ball.move = function(){ ball._x += ball.dx; ball._y += ball.dy; } // end move ball.checkBoundaries = function(){ // code for making ball stop at the edge of the screen if (ball._x > Stage.width){ ball.dx = 0 } // end if if (ball._x < 0){ ball.dx = Stage.width; } // end if if (ball._y > Stage.height - (ball._height)){ ball.dy = -ball.dy } // end if if (ball._y < ball._height/7){ ball.dy = -ball.dy } // end if } // end check boundaries // code to check for paddle collision ball.checkPaddles = function(){ if (ball.hitTest(paddle1)){ ball.dx = -ball.dx; ball.dy = getDy(paddle); } // end if if (ball.hitTest(paddle2)){ ball.dx = -ball.dx; ball.dy = getDy(paddle); } // end if } // end checkpaddles // determine ball dy based on where ball hits paddle function getDy(paddle){ // relY is relative y of ball to paddle relY = ball._y - paddle1._y; // trace (relY); // relPerc is relY / height of paddle // will range from -.5 to .5 relPerc = relY / ball._height; // trace (relPerc); // new DY ranges from -15 to +15 newDY = relPerc * 20; // trace (newDY); return newDY; } // end getDT[/source]
  4. DevonDoerfer

    help with Flash code

    IT will only let me save it as CS5 or CS4. I attached the CS4 version. I really appreciate the all the help. Edit: for some reason it will not let me attach the file.
  5. DevonDoerfer

    help with Flash code

    Ok, so that didn't work. When I try to put something in the _root._balldx the ball does nothing. also now the score does not work. It starts blank (started as 0 - 0) when one wither I or the opponent score it goes to N ( I assume NaN) and that is it. If I leave _root._balldx blank. the ball works fine but the score still does not work.
  6. DevonDoerfer

    help with Flash code

    So, just so I'm understanding what is going on, The checkOption function is not working because the ball movie clip is not loaded yet? Also is this how the new init() code should look? onLoad = function(){ init(); ball.checkOptions(); } // end onLoad event handler function init(){ Mouse.hide(); // init ball position ball._x = paddle1._x + 20; ball._y = paddle1._y; ball.dy = 0; ball.dy = 10; trace (ball.dy); // paddle2.speed is opponent speed // determines max dy for opponent // 15 is nearly flawless // 0 is dead paddle2.speed = 10 playerScore = 0 oppScore = 0 } // end init
  7. DevonDoerfer

    help with Flash code

    I wanted to make it so if the player wants to just jump right into the game they wouldn't have to set the ball speed themselves. So I thought the checkOption was the best way to do that. Bear in mind the book that I'm following so up to this point in the book the encapsulation feature seemed the way to go. I tried putting ball,dx = _root._balldx in the init() function and in the ball.OnEnterFrame function and for some reason it goes straight to the next frame (which happens to be the winner frame). I even set _root._balldx to 1 and still the same thing. When it is set to 1 you can see the score count to 3 quickly and then go to the winner frame.
  8. DevonDoerfer

    help with Flash code

    I thought that was where it was supposed to go but whenever I put it in there, it doesn't react to the checkPaddles() function correctly. For example, if I if I put a number in _root._balldx (or even if I fon't I just checked) the ball comes off the player paddle hits the computer paddle and deflects 90 degrees.
  9. DevonDoerfer

    help with Flash code

    Yeah, it's being called in the init() function: init(); function init(){ Mouse.hide(); // init ball position ball._x = paddle1._x + 20; ball._y = paddle1._y; ball.dy = 0; [color="#ff0000"]ball.checkOptions(); trace (ball.dy); // paddle2.speed is opponent speed // determines max dy for opponent // 15 is nearly flawless // 0 is dead paddle2.speed = 10 playerScore = 0 oppScore = 0 } // end init The only change in this from the original post is I changed the initial ball position to start on the players paddle instead of the middle.
  10. DevonDoerfer

    help with Flash code

    Ok, this is what I have now: ball.checkOptions = function(){ if (_root._balldx == undefined||_root._balldx == 0){ ball.dx = 10; [color="#ff0000"]trace (ball.dx); } else { ball.dx = parseInt(_root._balldx); [color="#ff0000"]trace (ball.dx); if (isNaN(_root.balldx)) ball.dx = 10; } // end ball.dx speed option } // end ball.checkOptions I highlighted the 2 trace statements. ball.dx doesn't show up whether I put a number in the _root._balldx or not. Is there something in the rest of the code interfering with the variable changing ball,dx?
  11. DevonDoerfer

    help with Flash code

    If I put a number in the _root._balldx field it shows up in the trace statement. So the code is recognizing the input but it is not assigning it to ball.dx for some reason. If I don't put anything in the field it seems like it basically ignores the whole if/else statement because it doesn't even set ball.dx to 10.
  12. DevonDoerfer

    help with Flash code

    This is what I have for the check.Options encapsulation. ball.checkOptions = function(){ if (_root._balldx == undefined||_root._balldx == 0){ ball.dx = 10; } else { ball.dx = parseInt(_root._balldx); } // end ball.dx speed option } // end ball.checkOptions if I put this in the ball.onEnterFrame function it recognizes the _root._balldx variable but it ignores the checkPaddles() instruction. if I put the checkOptions() anywhere else in the code, ive tried above the ball.onEnterFrame. below it, in the init()... It doesn't recognize the variable. By the way, thank you for taking the time to work through this with me.
  13. DevonDoerfer

    help with Flash code

    Ok. I put trace statements in for ball.dx, ball.dy and _root._balldx. If I leave _root._balldx empty ball.dx defaults to 8 and _root._balldx is undefined. If I enter a value into _root._balldx the value shows up in the trace statement but ball.dx becomes undefined. Hope that makes sense.
  14. DevonDoerfer

    help with Flash code

    May have spoken too soon. If I leave _root._balldx empty it looks like it defaults to 10. If I put any value in that field the ball does not move.
  15. DevonDoerfer

    help with Flash code

    That seemed to do the trick. what does the || mean?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!