Jump to content

Pong help


Dragyn3652
 Share

Recommended Posts

After you apply speed to the Y, you need to check to see if it's in bounds, if not move it to the edge.  I have the variables screenTop and screenHeight which you'll need to replace with your own. Probably 0 (zero) for screenTop and window.innerHeight for screenHeight.

this.update = function() {      if(this.side == "left") {        if(keys.p1.down) {          this.y += this.speed;          if ((this.y + this.sizeLength) > screenHeight) {              this.y = screenHeight - this.sizeLength          }        }        if(keys.p1.up) {          this.y -= this.speed;          if (this.y < screenTop) {            this.y = screenTop;          }        }      }else{        if(keys.p2.down) {          this.y += this.speed;          if ((this.y + this.sizeLength) > screenHeight) {              this.y = screenHeight - this.sizeLength          }        }        if(keys.p2.up) {          this.y -= this.speed;          if (this.y < screenTop) {            this.y = screenTop;          }        }      }    }      }
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...