2 Replies Latest reply on Mar 21, 2007 3:58 PM by bob3546

    Please help beginner! Few pong questions.

    tibor29 Level 1
      So, I have just started creating my own pong game after learning the basics of Flash 8. Everything went perfectly until now, I got a bit stuck.
      I got to point where I have fully working menu, multiplayer and singleplayer, you can play against another person using mouse and arrows. The scoring system works too and I actually managed to get the computer to follow the ball but here comes the first problem. I found a whole actionscript for the ball on the internet here it is:

      onClipEvent(load){
      s = {l:10,r:490,t:20,b:405,w:10,h:10};

      function setSpeed(){
      xspeed = Math.round(Math.random()*5)+1;
      yspeed = Math.round(Math.random()*5)+1;

      xspeed *= Math.round(Math.random()*2)==1 ? -1 : 1;
      yspeed *= Math.round(Math.random()*2)==1 ? -1 : 1;
      }

      setSpeed();
      _root.cscore = _root.pscore = 0;
      }

      onClipEvent(enterFrame){
      _x += xspeed;
      _y += yspeed;

      if(_x+(s.w/2)+xspeed>s.r){
      _x = s.r/2;
      _y = s.b/2;

      setSpeed();
      _root.cscore += 1;
      }
      if(_x-(s.w/2)+xspeed<s.l){
      _x = s.r/2;
      _y = s.b/2;

      setSpeed();
      _root.pscore += 1;
      }
      if(_y+(s.h/2)+yspeed>s.b){
      _y = s.b-(s.h/2);
      yspeed *= -1;
      }
      if(_y-(s.h/2)+yspeed<s.t){
      _y = s.t+(s.h/2);
      yspeed *= -1;
      }
      if(this.hitTest(_root.player)){
      _x = _root.player._x - _root.player._width/2;
      xspeed *= -1;
      xspeed *= 1.08;
      yspeed *= 1.08;
      }
      if(this.hitTest(_root.computer)){
      _x = _root.computer._x + _root.computer._width/2;
      xspeed *= -1;
      xspeed *= 1.08;
      yspeed *= 1.08;
      }
      }


      As I said I am a beginner and I dont really understand the code. The problem is that after every hit the ball gets faster and faster and faster until it is impossible to see it.
      Here comes another problem: I have got the enemy just following the ball so it is impossible to score the script for enemy is:

      onClipEvent(enterFrame){
      ydist = _root.ball._y - _y;
      _y = _root.ball._y;
      }

      Now my question is can someone plese tell me what do I have to change in the ball code so it stays at the constant speed or it just increases a little bit. The second qustion is how can I make the enemy computer not perfect? So you can actually win the game? Something like hit it randomly.

      My last question is: The game should be quiz pong. So if you score a point a qustion will pop up and you will have to answer it. What is the best way to do that? I think it should mean somethin like this: If score=+1 gotoandplay(lets say the question will be at frame 20) I dont know if that is the way it should be formed in the action script it is just my guess.
      Please if someone can help me at least with one of those questions I would be incredibly oblidged. thanks