all groups > flash actionscript > november 2006 >
You're in the

flash actionscript

group:

Please help beginner! Few pong questions.


Please help beginner! Few pong questions. tibor29
11/14/2006 8:32:02 PM
flash actionscript:
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. I actually managed
to get the computer to follow the ball but here comes the first problem. I
found a whole actionscript for the 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
[b]Text[/b]
Re: Please help beginner! Few pong questions. bob3546
3/21/2007 10:51:42 PM
hey, im not great at this easier, but i think the speed problem can be solved
by getting rid of the 2 lines

xspeed *= 1.08;
yspeed *= 1.08;

I think this increases the speed by 8% after every hit. You can also try
lowering the number, but if you go elow 1 it will slow down.


Re: Please help beginner! Few pong questions. bob3546
3/21/2007 10:58:13 PM
now i have a question for you can you tell em how you get the ball to bounce off the sides and paddles.
AddThis Social Bookmark Button