• [2of2] continued Exploring 2.8" Color TFT Touch LCD by Pacman Game attempt

    Add this code to the initial one for having pacman continually walking around ins a square.

    // pacman walking around in a square (until w is set to false in cmd pane):
    var d, w;
    function r() {
      G.c();
      G.sClr(2);
      G.g.drawRect(
          x0 - (Math.round(P.w/2) + P.b) , y0 - (Math.round(P.w / 2) + P.b)
        , x0 + ((nmx + 1) * P.w   + 1  ) , y0 + ((nmx + 1) * P.w     + 1  )
        );
      G.g.drawRect(
          x0 + (Math.round(P.w/2) + P.b) , y0 + (Math.round(P.w / 2) + P.b)
        , x0 + ((nmx - 1) * P.w   - 1  ) , y0 + ((nmx - 1) * P.w     - 1  )
        );
      d = 0; // start direction (E) and ...
      P.s0(d,x0,y0); // start position
      n = 0;
      w = true;
      rx();
    }
    
    function rx() {
      if (n < nmx) { n++;
        P.n();
        setTimeout("rx();",tt);
      } else {
        P.f[P.s]();
        if (w) {
          d = (d < 12) ? d + 4 : 0;
          P.s0(d,P.x,P.y);
          n = 0;
          setTimeout("rx();",1);
        }
      }
     }
    

    In IDE's command / console window enter:

    • r(); // starts the walking in the NW corner
    • w = false; // stops the walking at the next corner



    PS: I used the 2.8" TFT LCD with Touchscreen Breakout Board w/MicroSD Socket from http://www.adafruit.com/products/1770 and wired according to http://www.espruino.com/ILI9341 Note that B2 goes to Lite on board (LED on module). See picture and watch (short, low-res pacmanvideo.mp4) movie...


    3 Attachments

About

Avatar for allObjects @allObjects started