<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #switch - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23switch</link>
      <pubDate>Sun, 08 Aug 2021 20:36:45 +0000</pubDate>
         <description>Tagged with #switch - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23switch/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Game menu with images</title>
      <link>https://forum.processing.org/two/discussion/18621/game-menu-with-images</link>
      <pubDate>Wed, 19 Oct 2016 15:29:55 +0000</pubDate>
      <dc:creator>vamo1986</dc:creator>
      <guid isPermaLink="false">18621@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone! i am really really reaaaaalllly new at processing.
I am trying to build a menu for my game in which the user clicks the mouse button and the game shows an image.
The problem is that when I run the program it show the first image and then when i clikc on an specific area it shows the las image, excluding states 1 and 2. Can anyone tell me whats wrong with my code? Thanks a lot!</p>

<pre><code>PImage img1;
PImage img2;
PImage img3;
PImage img4;
final int empezar = 0;
final int roles = 1;
final int instrucciones = 2;
final int asignar = 3;
int paginaActual = 0;
boolean botonPresionado = false;

void setup () {
  size (648, 480);
  img1 = loadImage ("Titulo2.jpg");
  img2 = loadImage ("Roles.jpg");
  img3 = loadImage ("Instrucciones.jpg");
  img4 = loadImage ("Asignar.jpg");
}

void draw () {

  switch (paginaActual) {

  case empezar:

    drawParaEmpezar ();
    break;

  case roles:

    drawParaRoles ();
    break;

  case instrucciones:
    drawParaInstrucciones ();
    break;

    //  case asignar:
    //   drawParaAsignar ();
    //  break;

  default: 
    println ("estado no identificado");
    break;
  }
}
void drawParaEmpezar () {
  image (img1, 0, 0);
  if (botonPresionado) 
  {
    drawParaRoles ();
  }
}

void drawParaRoles () {
  image (img2, 0, 0);
  if (botonPresionado) 
  {
    drawParaInstrucciones ();
  }
}

void drawParaInstrucciones () {
  image (img3, 0, 0);
  if (botonPresionado) 
  {
    image (img4, 0, 0);
  }
}

// void drawParaAsignar () {
//   image (img4, 0, 0);
// }

void mousePressed()
{ 
  switch (paginaActual) {

  case empezar:
    mousePressedParaEmpezar ();
    break;

  case roles:
    mousePressedParaRoles ();
    break;

  case instrucciones:
    mousePressedParaInstrucciones ();
    break;
  }
}

void mousePressedParaEmpezar () {
  if (  mouseX &gt; 250 &amp;&amp; mouseX &lt; 391 &amp;&amp; mouseY &gt; 277 &amp;&amp; mouseY &lt; 325 ) 
  {
    botonPresionado = !botonPresionado;
  } else {
  }
}

void mousePressedParaRoles () {
  if (  mouseX &gt; 473 &amp;&amp; mouseX &lt; 620 &amp;&amp; mouseY &gt; 408 &amp;&amp; mouseY &lt; 456 ) 
  {
    botonPresionado = !botonPresionado;
  } else {
  }
}

void mousePressedParaInstrucciones () {
  if (  mouseX &gt; 473 &amp;&amp; mouseX &lt; 620 &amp;&amp; mouseY &gt; 408 &amp;&amp; mouseY &lt; 456 ) 
  {
    botonPresionado = !botonPresionado;
  } else {
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Tetris: How to change boolean of Cell grid after each drop of shape?</title>
      <link>https://forum.processing.org/two/discussion/13842/tetris-how-to-change-boolean-of-cell-grid-after-each-drop-of-shape</link>
      <pubDate>Tue, 08 Dec 2015 20:33:21 +0000</pubDate>
      <dc:creator>cleanass</dc:creator>
      <guid isPermaLink="false">13842@/two/discussions</guid>
      <description><![CDATA[<p>Hello, this is my first post on openProcessing and I was wondering if I could get some help or advice on how to proceed with my Tetris game. I am making this game as a final project and I understand that it probably would have been wiser to start off with a boolean 2d array for the grid, but I found cells to be a lot easier to handle. I am still slightly a noob, so bear with me.</p>

<p>So I got the grid, I got the shapes, I got them to fall, the only issue now is whenever the shapes fall down, I need them to initiate the cell that they're in to true (grid[][].onOff = true) but switch the grid cell back to false after it has dropped more. This will allow for the stacking effect of blocks.
Thanks in advance!</p>

<p>I think the problem is in the brickfall() function. The if() statement that allows it to move is true from the start, but how to change it individually?</p>

<pre><code>//Creates the rows and columns of the grid
int cols;
int rows;
//Declaring a 2d array using the Cell class
Cell[][] grid;
Cell [] shape;
Cell [] shape2;

int turnTime;

int unit = 25;
int unitX, unitY;

void setup() {
  size(10*unit, 20*unit);

  //Rows and columns for the 2d array
  cols = 10;
  rows = 20;

  //array is utilizing the rows and cols with Grid object
  grid = new Cell[cols][rows];
  //instantiating the rows(i) and the cols(j) giving them values
  for (int i=0; i&lt;cols; i++) {
    for (int j=0; j&lt;rows; j++) {
      //array with i&amp;j is equal to the new Grid being declared
      grid[i][j] = new Cell(i, j, 25, false);
    }
  }
  shape = new Cell[2];
  for (int u=0; u&lt;shape.length; u++) {
    shape[0] = new Cell(2, 0, 25, true);
    shape[1] = new Cell(3, 0, 25, true);
  }
  shape2 = new Cell[2];
  for (int h=0; h&lt;shape2.length; h++) {
    shape2[0] = new Cell(2, 0, 25, true);
    shape2[1] = new Cell(3, 0, 25, true);
  }
}

void draw() {
  background(0);
  //for loops for the array to draw
  for (int i=0; i&lt;cols; i++) {
    for (int j=0; j&lt;rows; j++) {
      //Displays grid 2d array
      grid[i][j].display();
    }
  }
  for (int u=0; u&lt;shape.length; u++) {
    shape[u].display2();
    shape2[u].display2();
  }
  brickFall();
}

void keyPressed() {
  for (int i=9; i&lt;=9; i++) {
    for (int j=19; j&lt;=19; j++) {
      for (int u=0; u&lt;shape.length; u++) {
        if (key == CODED) {
          if (keyCode == LEFT &amp;&amp; shape[u].x &gt; 0 &amp;&amp; grid[i][j].onOff == false) {
            shape[u].x--;
          }
          if (keyCode == RIGHT &amp;&amp; shape[u].x &lt; 225 &amp;&amp; grid[i][j].onOff == false) {
            shape[u].x++;
          }
        }
      }
    }
  }
}

void brickFall() {
  if (millis() &gt; turnTime+200) {
    turnTime = millis();
    for (int i=9; i&lt;=9; i++) {
      for (int j=19; j&lt;=19; j++) {
        for (int u=0; u&lt;shape.length; u++) {
          //shape[u] = grid[i][j];
          if ( grid[i][j].onOff == false) {
            shape[u].y++;
            if (shape[u].y &gt;= 20) {
              shape[u].y--;
              grid[2][19].onOff=true;
              shape2[u].y++;
            }
          }
        }
      }
    }
  }
}

//Class that creates cells which will create the grid for tetris
class Cell {
  int x, y;
  int cellSize;//Size of cell
  int w, h;
  boolean onOff= false;
  color fillColor = color(0);//Variable to connect shape array to Cell and modify the color of each shape

  //Constructor currently in use
  Cell(int _x, int _y, int _cellSize, boolean _onOff) {
    x=_x;
    y=_y;
    cellSize=_cellSize;
    onOff=_onOff;
  }

  Cell(int _x, int _y, int _w, int _h, boolean _onOff) {
    x=_x;
    y=_y;
    w=_w;
    h=_h;
    onOff=_onOff;
  }

  //Method for the display of each cell
  void display() {
    //noFill();
    fill(fillColor);
    stroke(255);
    rect(x*25, y*25, cellSize, cellSize);//cell size = 30
  }

  void display2() {
    fill(255);
    stroke(0);
    rect(x*25, y*25, cellSize, cellSize);//cell size = 30
  }
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>