PDA

View Full Version : MX- i have no idea what im doing



fez
December 2nd, 2002, 09:38 PM
just so you all know, i didnt actually write this code. so im not really as smart as i may seem...getting back to the point, what im looking for is a semi thorough explanation for the following lines. excluding this
and this
and this



init();
function init() {
right = 500;
left = 50;
top = 50;
bottom = 350;
ball.vx = Math.random()*20-10;
ball.vy = Math.random()*20-10;
ball.onEnterFrame = move;
pc.onEnterFrame = function() {
this._y = ball._y;
};
player.onEnterFrame = function() {
this._y = _root._ymouse;
};
Mouse.hide();
}
function move() {
this._x += this.vx;
this._y += this.vy;
playerBounds = player.getBounds(_root);
if (this._x>right-this._width/2) {
if (this._y>playerBounds.yMin && this._y<playerBounds.yMax) {
this.vx *= -1;
this._x = right-this._width/2;
} else {
this._x = 275;
this._y = 200;
this.vx = Math.random()*20-10;
this.vy = Math.random()*20-10;
pcScore++;
}
}
pcBounds = pc.getBounds(_root);
if (this._x<left+this._width/2) {
if (this._y>pcBounds.yMin && this._y<pcBounds.yMax) {
this.vx *= -1;
this._x = left+this._width/2;
} else {
this._x = 275;
this._y = 200;
this.vx = Math.random()*20-10;
this.vy = Math.random()*20-10;
playerScore++;
}
}
if (this._y>bottom-this._height/2) {
this.vy *= -1;
this._y = bottom-this._height/2;
}
if (this._y<top+this._height/2) {
this.vy *= -1;
this._y = top+this._height/2;
}
}


cheers
fez

ps. its a pong sort of game btw

pom
December 2nd, 2002, 10:19 PM
Repost the code using the php tag. There are problems when you use < and > .

Nice code, by the way. Which part did you not understand?

pom :asian:

Ryall
December 3rd, 2002, 12:38 PM
Yeah, nice code. I definitly agree, who wrote it?

Peace

fez
December 3rd, 2002, 02:41 PM
im not sure exactly who wrote it, i got it from h88 in a reply to one of my other posts.
credit goes to anonymouse fro writing it



init();
function init() {
right = 500;
left = 50;
top = 50;
bottom = 350;
ball.vx = Math.random()*20-10;
ball.vy = Math.random()*20-10;
ball.onEnterFrame = move;
pc.onEnterFrame = function() {
this._y = ball._y;
};
player.onEnterFrame = function() {
this._y = _root._ymouse;
};
Mouse.hide();
}
function move() {
this._x += this.vx;
this._y += this.vy;
playerBounds = player.getBounds(_root);
if (this._x>right-this._width/2) {
if (this._y>playerBounds.yMin && this._y this.vx *= -1;
this._x = right-this._width/2;
} else {
this._x = 275;
this._y = 200;
this.vx = Math.random()*20-10;
this.vy = Math.random()*20-10;
pcScore++;
}
}
pcBounds = pc.getBounds(_root);
if (this._x if (this._y>pcBounds.yMin && this._y this.vx *= -1;
this._x = left+this._width/2;
} else {
this._x = 275;
this._y = 200;
this.vx = Math.random()*20-10;
this.vy = Math.random()*20-10;
playerScore++;
}
}
if (this._y>bottom-this._height/2) {
this.vy *= -1;
this._y = bottom-this._height/2;
}
if (this._y this.vy *= -1;
this._y = top+this._height/2;
}
}

fez
December 3rd, 2002, 02:44 PM
lol...parts i didnt understand...lets see..
basically all of it, although there are little snippets which i can figure out. if a detailed explanation is too muhc, could anyone repost the code to make it move in the other direction, ie i want the paddle to be at the bottom, moving left and right, not up and down. the ball i guess should do the same. i can get the boundaries myself, just cant seem to tweak the rest of the code right

cheers