Flash MX 2004 coding question.
Slayer5227
Elkridge Member
We have been making a pong game in class for the past 2 weeks. It is almost done but we are stuck on a line of code a fellow classmate gave us and said that we only have to make an adjustment to, what that adjustment is, is beyond me. The code is as follows:
onClipEvent (enterFrame){
if (Key.isDown(87))this._y-=20;
if (Key.isDown(83))this._y+=20;
}
onClipEvent(enterFrame)
{
var Ballx = _root.ball._x-_root.ball._width/2;
var xspeed = _root.ball.xspeed;
var yspeed = _root.ball.yspeed;
var endx = Ballx-xspeed;
var endy = Bally-yspeed;
var endz = Bally-yspeed;
if((endx) < (this._x+this._width/2) && (endy) > (this._y+this._height/2+_root.ball.width/2) && (endz) < (this._y-this.height/2+_root.ball.width/2))
{
_root.ball._x = (this._x)+this._width/2+_root.ball._width/2;
_root.ball.xspeed*=-1;
if(_root.ball.xspeed<30 && _root.ball.xspeed>-30)
{
_root.ball.xspeed*=1.1;
}
}
}
This is the code for the paddle, the error is in this line:
if((endx) < (this._x+this._width/2) && (endy) > (this._y+this._height/2+_root.ball.width/2) && (endz) < (this._y-this.height/2+_root.ball.width/2))
Any help would be appreciated, thanks.
onClipEvent (enterFrame){
if (Key.isDown(87))this._y-=20;
if (Key.isDown(83))this._y+=20;
}
onClipEvent(enterFrame)
{
var Ballx = _root.ball._x-_root.ball._width/2;
var xspeed = _root.ball.xspeed;
var yspeed = _root.ball.yspeed;
var endx = Ballx-xspeed;
var endy = Bally-yspeed;
var endz = Bally-yspeed;
if((endx) < (this._x+this._width/2) && (endy) > (this._y+this._height/2+_root.ball.width/2) && (endz) < (this._y-this.height/2+_root.ball.width/2))
{
_root.ball._x = (this._x)+this._width/2+_root.ball._width/2;
_root.ball.xspeed*=-1;
if(_root.ball.xspeed<30 && _root.ball.xspeed>-30)
{
_root.ball.xspeed*=1.1;
}
}
}
This is the code for the paddle, the error is in this line:
if((endx) < (this._x+this._width/2) && (endy) > (this._y+this._height/2+_root.ball.width/2) && (endz) < (this._y-this.height/2+_root.ball.width/2))
Any help would be appreciated, thanks.
0
Comments
2) Whoever wrote that code should be punched. It's an illegible mess, and the variable names are stupendously bad.
3) You can't ask the classmate wtf they were talking about?
4) You didn't provide what the error was.
Remembering precisely nothing about Actionscript, I reformatted your noted line above to be legible: Looking at that code, the only thing that jumps out at me is that you use this._height in the second condition and then this.height (no underscore) in the third condition. Typo or intended?