Loading...
Logo
Processing Forum
Forgive the 600+ lines of code, but this thing is working perfectly in Java mode but isn't doing anything in Javascript mode and I fail to understand why!

UPDATE: Thanks to antony74, I know the bug and have corrected the code.

Copy code
  1. int MODE;
  2. MenuText back;
  3. /* @pjs font="Arial.ttf"; */
  4. PFont titleF;
  5. PFont menuItemF;
  6. String[] menuItemsNames={"START","INSTRUCTIONS","CREDITS","EXIT"};  //Creates the array that will be passed to the Menu class for forming individual MenuText objects.
  7. Menu menu;
  8. Paddle paddleLeft;
  9. Paddle paddleRight;
  10. Ball pongBall;
  11. Ball pongScreenBall;
  12. Ball pongCreditsBall;
  13. Score tpScore;
  14. Field field;
  15. void setup(){
  16.   size(640,480);
  17.   background(255);
  18.   smooth();
  19.   noStroke();
  20.  
  21.   titleF=createFont("Arial");
  22.   menuItemF=createFont("Arial");
  23.   menu=new Menu("PONG",menuItemsNames,titleF,menuItemF,0,255,color(183,152,50),0,color(50,155,61));
  24.  
  25.   back=new MenuText("BACK",menuItemF,width/2,height/1.5+100,24,color(255),color(183,152,50),color(0),color(50,155,61));
  26.  
  27.   paddleLeft=new Paddle(width/48,height/5,color(183,152,50),0);
  28.   paddleRight=new Paddle(width/48,height/5,color(183,152,50),1);
  29.  
  30.   pongBall=new Ball(10,color(255),5);
  31.   pongScreenBall=new Ball(10,color(255),4);
  32.   pongCreditsBall=new Ball(10,color(255),10);
  33.  
  34.   tpScore=new Score(10,createFont("Arial"),32,0,255,0,40,height-40,width-40,height-40);
  35.  
  36.   field=new Field(color(255),color(50,155,61),color(255));
  37.  
  38.   MODE=0;
  39. }
  40. void draw(){
  41.   background(50,155,61);
  42.  
  43.  
  44.  
  45.   if(MODE==0){
  46.     pongScreenBall.update();
  47.     pongScreenBall.render();
  48.     pongScreenBall.wallCollision();
  49.    
  50.     menu.render();   
  51.    
  52.     switch(menu.whichItem()){
  53.       case 0:
  54.       MODE=1;
  55.       menu.passTo(menu.whichItem());
  56.       break;
  57.      
  58.       case 1:
  59.       MODE=2;
  60.       menu.passTo(menu.whichItem());
  61.       break;
  62.      
  63.       case 3:
  64.       exit();
  65.       break;
  66.      
  67.       case 2:
  68.       MODE=3;
  69.       menu.passTo(menu.whichItem());
  70.       break;
  71.      
  72.       default:
  73.       break;
  74.     }
  75.   }
  76.   else  if(MODE==1){
  77.     field.render();
  78.     tpScore.render();
  79.    
  80.     paddleLeft.render();
  81.     paddleRight.render();
  82.     paddleLeft.update();
  83.     paddleRight.update();
  84.    
  85.     pongBall.wallCollision(paddleLeft);
  86.     pongBall.paddleCollision(paddleLeft);
  87.     pongBall.paddleCollision(paddleRight);
  88.    
  89.     pongBall.update();
  90.     pongBall.render();
  91.    
  92.     if(pongBall.getSideHit()!=2){
  93.       tpScore.update(pongBall.getSideHit());
  94.       pongBall.setSideHit(2);
  95.       pongBall.reset();
  96.       pongBall.updateV(5);
  97.       if(tpScore.hasMaxed()!=0){
  98.         MODE=4;       
  99.       }
  100.     }
  101.    
  102.   }
  103.   else if(MODE==2){
  104.     background(50,155,61);
  105.    
  106.     textFont(createFont("Arial"));
  107.     textSize(75);
  108.     fill(255);
  109.     text("INSTRUCTIONS",width/2-textWidth("INSTRUCTIONS")/2,height/4);
  110.    
  111.     textFont(menuItemF);
  112.     textSize(20);
  113.     text("Welcome to Pong, a 2 Player, 2 Dimensional Tabble-Tennis Game",width/2-textWidth("Welcome to Pong, a 2 Player, 2 Dimensional Tabble-Tennis Game")/2,height/2-38);
  114.     text("Press W and S to control the Left Paddle",width/2-textWidth("Press W and S to control the Left Paddle")/2,height/2-10);
  115.     text("Press UP and DOWN to control the Right Paddle",width/2-textWidth("Press UP and DOWN to control the Right Paddle")/2,height/2+18);
  116.     text("Winner decided when one player amasses 10 points",width/2-textWidth("Winner decided when one player amasses 10 points")/2,height/2+46);
  117.    
  118.     back.update();
  119.     back.render();
  120.    
  121.     if(back.getClicked()){
  122.       MODE=0;
  123.       back.unClick();
  124.     }
  125.   }
  126.   else if(MODE==4){
  127.     pongScreenBall.update();
  128.     pongScreenBall.render();
  129.     pongScreenBall.wallCollision();
  130.    
  131.     background(50,155,61);
  132.    
  133.     textFont(titleF);
  134.     textSize(95);
  135.     fill(255);
  136.     text("GAME OVER",width/2-textWidth("GAME OVER")/2,height/2-(104/3));
  137.    
  138.     textFont(createFont("Arial"));
  139.     textSize(32);
  140.     text("Player "+str(tpScore.hasMaxed())+" WON!",width/2-textWidth("Player "+str(tpScore.hasMaxed())+" WON!")/2,height/2+25);   
  141.    
  142.     textFont(menuItemF);
  143.     textSize(48);
  144.     text("Thank You For Playing...",width/2-textWidth("Thank You For Playing...")/2,height/2+85);
  145.    
  146.     back.update();
  147.     back.render();
  148.    
  149.     if(back.getClicked()){
  150.       MODE=0;
  151.       back.unClick();
  152.       tpScore.reset();
  153.     }
  154.    
  155.   }
  156.   else if(MODE==3){
  157.     background(50,155,61);
  158.    
  159.     pongCreditsBall.update();
  160.     pongCreditsBall.render();
  161.     pongCreditsBall.wallCollision();
  162.    
  163.     fill(255);
  164.     textFont(createFont("Arial"));
  165.     textSize(32);
  166.     text("coded by",width/2-textWidth("coded by")/2,height/3);
  167.    
  168.     textFont(menuItemF);
  169.     textSize(45);
  170.     text("Le Shaun",width/2-textWidth("Le Shaun")/2,height/2);
  171.    
  172.     back.update();
  173.     back.render();
  174.    
  175.     if(back.getClicked()){
  176.       MODE=0;
  177.       back.unClick();
  178.     }
  179.   }
  180. }
  181. void mouseClicked(){
  182.   if(MODE==0){
  183.     menu.passTo(mouseX,mouseY);
  184.   }
  185.   else if(MODE==3 || MODE==2 || MODE==4){
  186.     back.mClicked(mouseX,mouseY);
  187.   }
  188. }
  189. void keyReleased(){
  190.   if(MODE==1){
  191.     if(key==CODED){
  192.       if(keyCode==UP){
  193.         paddleRight.updateMve(0);
  194.       }
  195.       else if(keyCode==DOWN){
  196.         paddleRight.updateMve(0);
  197.       }
  198.     }
  199.     else{
  200.       if(key=='W' || key=='w'){
  201.         paddleLeft.updateMve(0);
  202.       }
  203.       else if(key=='S' || key=='s'){
  204.         paddleLeft.updateMve(0);
  205.       }
  206.     }
  207.   }
  208. }
  209.    
  210. void keyPressed(){
  211.   if(MODE==1){
  212.     if(key==CODED){
  213.       if(keyCode==UP){
  214.         paddleRight.updateMve(-1);
  215.       }
  216.       else if(keyCode==DOWN){
  217.         paddleRight.updateMve(1);
  218.       }
  219.     }
  220.     else{
  221.       if(key=='W' || key=='w'){
  222.         paddleLeft.updateMve(-1);
  223.       }
  224.       else if(key=='S' || key=='s'){
  225.         paddleLeft.updateMve(1);
  226.       }
  227.     }
  228.     if(key=='p' || key=='P'){
  229.       noLoop();
  230.     }
  231.     if(key=='r' || key=='R'){
  232.       loop();
  233.     }
  234.   }
  235. }
  236. class Ball
  237. {
  238.   float radius;
  239.   float bX;
  240.   float bY;
  241.  
  242.   float vBase;
  243.   float vX;
  244.   float vY;
  245.   color bColor;
  246.   int sideHit;
  247.  
  248.   Ball(float radius,color bColor,float vBase){
  249.     this.radius=radius;
  250.     this.bColor=bColor;
  251.     this.vBase=vBase;
  252.    
  253.     bX=width/2;
  254.     bY=height/2;
  255.    
  256.     float rnd=random(0,3);
  257.     if(rnd<0){vX=-sqrt(sq(vBase)/2); vY=sqrt(sq(vBase)/2);}
  258.     else if(rnd>=0 && rnd<1){vX=-sqrt((vBase*vBase)/2); vY=-sqrt(sq(vBase)/2);}
  259.     else if(rnd>=1 && rnd<2){vX=sqrt(sq(vBase)/2); vY=sqrt(sq(vBase)/2);}
  260.     else{vX=sqrt(sq(vBase)/2); vY=-sqrt(sq(vBase)/2);}
  261.    
  262.     sideHit=2;
  263.   }
  264.  
  265.   void render(){
  266.     stroke(0);
  267.     fill(bColor);
  268.    
  269.     ellipse(bX,bY,radius*2,radius*2);
  270.   }
  271.  
  272.   void update(){
  273.     bX+=vX;
  274.     bY+=vY;
  275.   }
  276.  
  277.   void reset(){
  278.     bX=width/2;
  279.     bY=height/2;
  280.   }
  281.  
  282.   void updateV(float V){
  283.     vBase=V;
  284.   }
  285.  
  286.   void accelerate(float V){
  287.     vBase+=V;
  288.   }
  289.  
  290.   int getSideHit(){
  291.     return sideHit;
  292.   }
  293.  
  294.   void setSideHit(int hit){
  295.     sideHit=hit;
  296.   }
  297.  
  298.   void wallCollision(Paddle p){
  299.     if(bX>=(width-radius-p.getWidth()/2)){
  300.       sideHit=1;        
  301.     }
  302.     else if(bX<=radius+p.getWidth()/2){
  303.       sideHit=0;
  304.     }
  305.    
  306.     if(bY>=(height-radius) || bY<=radius){
  307.       vY*=-1;
  308.     }
  309.   }
  310.  
  311.   void wallCollision(){
  312.     if(bX>=(width-radius) || bX<=radius){
  313.       vX*=-1;
  314.     }
  315.     if(bY>=(height-radius) || bY<=radius){
  316.       vY*=-1;
  317.     }
  318.   }
  319.  
  320.   void paddleCollision(Paddle p){
  321.     if(p.getOrient()==0){
  322.       if(bY>=(p.getY()-p.getHeight()/2) && bY<=(p.getY()+p.getHeight()/2)){
  323.         if((bX-radius)<=p.getWidth()){
  324.           float varier=map(p.getY()-bY,0,p.getHeight()/2,0.1,1);
  325.          
  326.           vY=sqrt(sq(vBase)/2)*varier*-1;
  327.           vX=sqrt(sq(vBase)/2)*sqrt(2-sq(varier))*(-1*(vX/abs(vX)));
  328.          
  329.           accelerate(0.2);
  330.          
  331.           println(vX+" "+vY+" "+" "+sqrt(sq(vBase)/2)+" "+varier);
  332.         }
  333.       }
  334.     }
  335.     else if(p.getOrient()==1){
  336.       if(bY>=(p.getY()-p.getHeight()/2) && bY<=(p.getY()+p.getHeight()/2)){
  337.         if((bX+radius)>=width-p.getWidth()){
  338.           float varier=map(p.getY()-bY,0,p.getHeight()/2,0.1,1);
  339.          
  340.           vY=sqrt(sq(vBase)/2)*varier*-1;
  341.           vX=sqrt(sq(vBase)/2)*sqrt(2-sq(varier))*(-1*(vX/abs(vX)));
  342.          
  343.           accelerate(0.2);
  344.          
  345.           println(vX+" "+vY+" "+sqrt(sq(vBase)/2)+" "+varier);
  346.         }
  347.       }
  348.     }
  349.   }
  350. }
  351. class Field
  352. {
  353.   color fEdge;
  354.   color fFloor;
  355.   color fNet;
  356.  
  357.   Field(color fEdge,color fFloor,color fNet){
  358.     this.fEdge=fEdge;
  359.     this.fFloor=fFloor;
  360.     this.fNet=fNet;
  361.   }
  362.  
  363.   void render(){
  364.     rectMode(CENTER);
  365.    
  366.     fill(fFloor);
  367.     noStroke();
  368.     rect(width/2,height/2,width,height);
  369.    
  370.     noFill();
  371.     stroke(fEdge);
  372.     rect(width/2,height/2,width-10,height-10);
  373.    
  374.     stroke(fNet);
  375.     for(int i=9;i<=height-10;i+=(height-10)/100){
  376.       ellipse(width/2,i,1,1);
  377.     }
  378.   }
  379. }
  380. //Menu class uses the objects from the MenuText and forms a menu with a title and a list of MenuText objects.
  381. class Menu{
  382.   String titleT;
  383.  
  384.   PFont titleF;
  385.   PFont menuItem;
  386.  
  387.   color titleC;
  388.  
  389.   float spacer;    //This is used to define the space between successive MenuText objects.
  390.   float iniY=height/2.5;
  391.  
  392.   MenuText[] menuItems;
  393.  
  394.   Menu(String titleT,String[] menuItemsNames,PFont titleF,PFont menuItemF,color titleC,color menuItemC,color menuBackC,color itemHoverC,color backHoverC){
  395.     this.titleT=titleT;
  396.     this.titleF=titleF;
  397.     this.titleC=titleC;
  398.    
  399.     menuItems=new MenuText[menuItemsNames.length];  //Initializes the MenuText objects depending on the array passed to it. This makes the menu system very flexible.
  400.     spacer=48;
  401.     for(int i=0;i<menuItemsNames.length;i++){     
  402.       menuItems[i]=new MenuText(menuItemsNames[i],menuItemF,width/2,iniY+(spacer*i),24,menuItemC,menuBackC,itemHoverC,backHoverC);
  403.     }
  404.   }
  405.   void render(){
  406.     textFont(titleF);
  407.     textSize(92);
  408.     fill(titleC);
  409.     text(titleT,width/2-(textWidth(titleT)/2),height/3.8);
  410.    
  411.     for(int i=0;i<menuItems.length;i++){
  412.       menuItems[i].update();
  413.       menuItems[i].render();
  414.     }
  415.   }
  416.  
  417.   void passTo(float mX,float mY){    //This accepts the X,Y mouse coords when the mouse is clicked and passes it to the relevant MenuText object to check if the click occurs on that object.
  418.     for(int i=0;i<menuItems.length;i++){
  419.       menuItems[i].mClicked(mX,mY);
  420.     }
  421.   }
  422.  
  423.   void passTo(int item){
  424.     menuItems[item].unClick();
  425.   }
  426.  
  427.   int whichItem(){  //Checks each time if the clicked state of any MenuText object is true. If it is, returns the array position of the relevant object.
  428.     for(int i=0;i<menuItems.length;i++){
  429.       if(menuItems[i].getClicked()){
  430.         return i;
  431.       }
  432.     }
  433.     return menuItems.length;
  434.   }
  435. }
  436. //MenuText holds the attributes and methods relating to each single item on the menu. Thus each item is treated as a separate object.
  437. //Each MenuText object comprises mainly of a foreground text and a background object.
  438. class MenuText{
  439.  
  440.   String menuItem;
  441.   PFont menuFont;
  442.   float itemX;
  443.   float itemY;
  444.   float itemSize;
  445.   color itemColor;
  446.   color backColor;
  447.   color pressedColor;
  448.   color pressedBack;
  449.  
  450.   color presentItem;
  451.   color presentBack;
  452.  
  453.   float tWidth;
  454.  
  455.   boolean clicked=false;  //This vairable is used to check the clicked state of the menu item. If the mouse is clicked over the menu item, this variable becomes true.
  456.  
  457.   MenuText(String menuItem,PFont menuFont,float itemX,float itemY,float itemSize,color itemColor,color backColor,color pressedColor,color pressedBack){
  458.     this.menuItem=menuItem;
  459.     this.menuFont=menuFont;
  460.     this.itemX=itemX;
  461.     this.itemY=itemY;
  462.     this.itemSize=itemSize;
  463.     this.itemColor=itemColor;
  464.     this.backColor=backColor;
  465.     this.pressedColor=pressedColor;
  466.     this.pressedBack=pressedBack;
  467.   }
  468.  
  469.   void render(){
  470.     textFont(menuFont);
  471.     textSize(itemSize);
  472.     tWidth=textWidth(menuItem);
  473.    
  474.     stroke(0);
  475.     fill(presentBack);
  476.     rectMode(CENTER);
  477.     rect(itemX,itemY,tWidth*1.3,itemSize*1.4,50);
  478.    
  479.     fill(presentItem);
  480.     text(menuItem,itemX-tWidth/2,itemY+itemSize*.3);
  481.   }
  482.  
  483.   void update(){             //Constatnly checks for the state of the object. If the mouse is over it a certain style is show and otherwise another style is shown.
  484.     if(mouseX<(itemX+(tWidth*1.3)/2) && mouseX>(itemX-(tWidth*1.3)/2) && mouseY<(itemY+(itemSize*1.4)/2) && mouseY>(itemY-(itemSize*1.4)/2)){
  485.      presentItem=pressedColor;
  486.      presentBack=pressedBack;
  487.     }
  488.     else{
  489.      presentItem=itemColor;
  490.      presentBack=backColor;
  491.     }
  492.   }
  493.  
  494.   boolean getClicked(){    //Returns the clicked state of the object.
  495.     return clicked;
  496.   }
  497.  
  498.   void unClick(){
  499.     clicked=false;
  500.   }
  501.  
  502.   void mClicked(float mX,float mY){  //Changes the clicked state of the object depending on the position of the mouse as inputs.
  503.     if(mX<(itemX+(tWidth*1.3)/2) && mX>(itemX-(tWidth*1.3)/2) && mY<(itemY+(itemSize*1.4)/2) && mY>(itemY-(itemSize*1.4)/2)){
  504.       clicked=true;
  505.       println(menuItem);
  506.     }
  507.   }
  508. }
  509. class Paddle {
  510.   float pWidth;
  511.   float pHeight;
  512.   color pColor;
  513.   float pX;
  514.   float pY;
  515.   float pV;
  516.   int mve;
  517.  
  518.   int pOrient;
  519.   Paddle(float pWidth, float pHeight, color pColor, int pOrient){
  520.     this.pWidth=pWidth;
  521.     this.pHeight=pHeight;
  522.     this.pColor=pColor;
  523.     this.pOrient=pOrient;
  524.    
  525.     if (pOrient==0) {
  526.       this.pX=(pWidth/2);
  527.     }
  528.     else {
  529.       this.pX=width-(pWidth/2);
  530.     }
  531.    
  532.     this.pY=height/2;
  533.     this.pV=7;
  534.     this.mve=0;
  535.   }
  536.  
  537.   //Le Getters
  538.   int getOrient(){
  539.     return pOrient;
  540.   }
  541.  
  542.   float getX(){
  543.     return pX;
  544.   }
  545.  
  546.   float getY(){
  547.     return pY;
  548.   }
  549.  
  550.   float getDiag(){
  551.     return (float)(sqrt(pWidth*pWidth-pHeight*pHeight));
  552.   }
  553.  
  554.   float getWidth(){
  555.     return pWidth;
  556.   }
  557.  
  558.   float getHeight(){
  559.     return pHeight;
  560.   }
  561.  
  562.   //Le Rendered & Updater
  563.   void render() {
  564.     rectMode(CENTER);
  565.     fill(pColor);
  566.     stroke(0);
  567.     rect(pX, pY, pWidth, pHeight,pHeight/10);
  568.   }
  569.  
  570.   void updateMve(int mve){
  571.     this.mve=mve;
  572.   }
  573.  
  574.   void update(){
  575.     this.pY=constrain(this.pY+pV*mve, pHeight/2+10, height-(pHeight/2)-10);
  576.   }
  577.  
  578. }
  579. class Score{
  580.   int p1;
  581.   int p2;
  582.   int maxScore;
  583.  
  584.   PFont pFont;
  585.   int pSize;
  586.   color pText;
  587.   color pBack;
  588.   color pStroke;
  589.  
  590.   float p1X;
  591.   float p1Y;
  592.  
  593.   float p2X;
  594.   float p2Y;
  595.   
  596.   Score(int maxScore,PFont pFont,int pSize,color pText,color pBack,color pStroke,float p1X,float p1Y,float p2X,float p2Y){
  597.     p1=0;
  598.     p2=0;
  599.     this.maxScore=maxScore;
  600.     this.pSize=pSize;
  601.    
  602.     this.pFont=pFont;
  603.     this.pText=pText;
  604.     this.pBack=pBack;
  605.     this.pStroke=pStroke;
  606.    
  607.     this.p1X=p1X;
  608.     this.p2X=p2X;
  609.    
  610.     this.p1Y=p1Y;
  611.     this.p2Y=p2Y;
  612.   }
  613.  
  614.   void render(){
  615.     textFont(pFont);
  616.     textSize(pSize);
  617.    
  618.     fill(pBack);
  619.     stroke(pStroke);
  620.    
  621.     rectMode(CENTER);
  622.    
  623.     rect(p1X,p1Y,textWidth(str(p1))*1.3,pSize);
  624.     rect(p2X,p2Y,textWidth(str(p2))*1.3,pSize);
  625.    
  626.     fill(pText);
  627.     text(str(p1),p1X-(textWidth(str(p1))/2),p1Y+pSize*0.3);
  628.     text(str(p2),p2X-(textWidth(str(p2))/2),p2Y+pSize*0.3);
  629.   }
  630.  
  631.   void update(int p){
  632.     if(p==0){
  633.       p2+=1;
  634.     }
  635.     else if(p==1){
  636.       p1+=1;
  637.     }
  638.   }
  639.  
  640.   void reset(){
  641.     p1=0;
  642.     p2=0;
  643.   }
  644.  
  645.   int hasMaxed(){
  646.     if(p1>=maxScore){
  647.       return 1;
  648.     }
  649.     else if(p2>=maxScore){
  650.       return 2;
  651.     }
  652.     else{
  653.       return 0;
  654.     }
  655.   }
  656. }
Copy code

    Replies(11)

    I don't think that loadFont() with vlw fonts works with PJS.
    I tried replacing those with createFont(), but to no effect. PFont objects are still supported, right?
    An why isn't the ball bouncing? The ball on the menu screen should be bouncing and at least the menu-boxes should showing. But nothing seems to be working.
    It's a very nice Pong sketch, I like that :-)

    I changed to createFont because I was too lazy to generate .vlw files ;-)

    Didn't run in Javascript-mode like you said.  So I opened FireBug and the error on the console was:

    TypeError: $this_1.textWidth is not a function

    Variables and functions share the same namespace in JavaScript so a variable textWidth seems to be the cause of the problem.  So I renamed it on line 152, flipped back to Java-mode and used the compile errors to show me where else it needed renaming, now it's running fine for me in JavaScript mode too :-)

    This language is really in need of a decent lint tool!

         Best wishes,

            Antony

    THANK YOU!  It works perfect now! I can't believe one little thing was messing up my whole sketch. But such is the way...during the first few classes I made a typo that drove me crazy trying to debug >.> Three days...logical error...-sigh-

    Firebug, huh? I'm definitely gonna look that up.

    Anyway, thanks for helping with this and teaching me something new. I'm a total newbie at programming in general so need all the help I can get.

    Do you think I need to improve  the algorithm anywhere? Something I could done better? Some tricks I could have used?
    Yes, compared to how nice and friendly the rest of Processing is, this whole JavaScript thing is like a road accident happening in slow motion.  I mean it's genius what it can do, but it's too easy to get tripped up and too hard to pick yourself up again afterwards.
    Hi Kaylors,

    Glad I could be of assistance.  Your code is very good - it's hard to believe that you're "a total newbie at programming in general".  You might want to work on those magic numbers (it would be especially nice if your modes were named).  But as far as I'm concerned everything is fine as long at it works (it does), and another person can read it (I can).

         Best wishes,

            Antony

    One should compile these pitfalls... From memory:

    - Integer division doesn't work:
    int a = 5;
    int b = 2;
    a / b gives 2 in Java and 2.5 in JavaScript...

    - Beware, some variable names can collide with JavaScript reserved words...

    - In Java, you can have a variable of same name than a function. In JavaScript, they conflict. Not sure how mousePressed vs. mousePressed() is handled, though. Perhaps they are changed at "compilation" (transformation to JS) time, because they are official names.

    What I am forgetting?
    I think they're the main ones.  This " hoisting" bug (assuming that's what it was) was particularly interesting.

    https://forum.processing.org/topic/playing-pde-files-online

        Best wishes,

            Antony

    And don't forget your original comment about loadFont() not working with vlw fonts.
    Hi Kaylor,
    this is not answer to your initial question, but an answer to the question, what you could have done better, more efficient etc.
    I downloaded your code and I think your pong game is great. I tried to play it in processings present mode on a 24 inch iMac by changing size to size(displayWidth,displayHeight); It works, but the Ball is too slow with this screensize.
    So I declared a variable speedfactor = 1.0/640.0*width; and multiplied the ballspeed with it in the classes Ball and Paddle. It then is playable independant of screensize.
    Since in PApplet all classes are inner classes I think it is sufficient to create the font in setup only. This gives less code and less parameters for the inner classes.

    Great Game Peter