Flash MX 2004 coding question.

Slayer5227Slayer5227 MemberElkridge Member
edited May 2012 in Internet & Media
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.

Comments

  • LincLinc Bard Detroit Icrontian
    edited May 2012
    1) Learning Actionscript in 2012 is an irresponsible waste of time. You shouldn't be in that class.
    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:
    
    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)) 
    )
    
    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?

  • Slayer5227Slayer5227 Member Elkridge Member
    Typo, wow, if that's the problem, I'm going to kick myself so badly. And I agree, completely useless, but I already am in it and might as well finish it out. The person who wrote the code is the "genius" coder of the class, and is a very condescending human being, maybe that will knock him down a few pegs haha. Thanks.
  • LincLinc Bard Detroit Icrontian
    edited May 2012
    A "genius" coder who writes illegible code is no genius at all. He has a hell of a lot to learn. :)
  • Slayer5227Slayer5227 Member Elkridge Member
    He is also 18, I doubt he is much of a "genius" anything at this point, so much to learn in life, and I doubt he has the entire coding language down.
  • shwaipshwaip Icrontian bluffin' with my muffin Icrontian
    edited May 2012
    _dem _underscores
  • Slayer5227Slayer5227 Member Elkridge Member
    That wasn't the problem (at least not the only one).
Sign In or Register to comment.