We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Processing/Procontroll Simon Memory Game Help
Page Index Toggle Pages: 1
Processing/Procontroll Simon Memory Game Help (Read 1472 times)
Processing/Procontroll Simon Memory Game Help
Apr 30th, 2010, 2:27pm
 
Ok so I am relatively new to Processing. I've been taking a class that focuses on it all semester and right now I'm working on the final project. In my sketch I use the Procontroll library with Processing to use an xbox 360 controller as the input device.

The controller works fine and I have all the buttons set up but I'm having a problem with the functionality of my other code, governing how the game itself should run.

At this point, my addNewButton function works, because on start up it does highlight a button that it wants me to copy. However, it doesn't seem to be turning it over to me to copy it after that, and when I copy it, nothing happens. If anyone could take a look at my code and help me out with what I need to change/what I am missing, that would be much appreciated.

Thanks.
Code:
import processing.opengl.*;
import procontroll.*;
import net.java.games.input.*;
Simon simon;

ControllIO controllIO;
ControllDevice joypad;
ControllStick stick1;
ControllStick stick2;
ControllButton button11;
ControllButton button12;
ControllButton button13;
ControllButton button14;
ControllButton button8;
ControllButton button9;
ControllButton button6;
ControllButton button7;
ControllButton button4;

PImage controller;
PImage controllera;
PImage controllerb;
PImage controllerx;
PImage controllery;
PImage controllerleftbumper;
PImage controllerrightbumper;
PImage controllerleftthumb;
PImage controllerrightthumb;
PImage title;
PImage titlescreen;
PImage gameover;
boolean screen = false;
boolean button11state = false;
boolean button12state = false;
boolean button13state = false;
boolean button14state = false;
boolean button6state = false;
boolean button7state = false;
boolean button8state = false;
boolean button9state = false;
boolean playerMode = false;

void setup(){
 size(900,684,OPENGL);
 frameRate(6);
 
 simon = new Simon();
 controllIO = ControllIO.getInstance(this);
 
 joypad = controllIO.getDevice("Wireless 360 Controller");
 joypad.plug(this, "handleButton1Press", ControllIO.ON_PRESS, 1);
 joypad.plug(this, "handleButton1Release", ControllIO.ON_RELEASE, 1);
 
 controller = loadImage("controller.png");
 controllera = loadImage("controllera.png");
 controllerb = loadImage("controllerb.png");
 controllerx = loadImage("controllerx.png");
 controllery = loadImage("controllery.png");
 controllerleftbumper = loadImage("controllerleftbumper.png");
 controllerrightbumper = loadImage("controllerrightbumper.png");
 controllerleftthumb = loadImage("controllerleftthumb.png");
 controllerrightthumb = loadImage("controllerrightthumb.png");
 titlescreen = loadImage("titlescreen.png");
 gameover = loadImage("gameover.png");
 
 title = loadImage("title.png");
 
 stick1 = joypad.getStick(0);
 stick1.setMultiplier(PI);

 stick2 = joypad.getStick(1);
 stick2.setTolerance(0.06f);
 stick2.setMultiplier(0.05f);
 
 button11 = joypad.getButton(11);
//  button11.pressed();
 
 button12 = joypad.getButton(12);
//  button12.pressed();
 
 button13 = joypad.getButton(13);
//  button13.pressed();
 
 button14 = joypad.getButton(14);
//  button14.pressed();
 
 button8 = joypad.getButton(8);
//  button8.pressed();
 
 button9 = joypad.getButton(9);
//  button9.pressed();
 
 button6 = joypad.getButton(6);
//  button6.pressed();
 
 button7 = joypad.getButton(7);
//  button7.pressed();
 
 button4 = joypad.getButton(4);
//  button4.pressed();
 
}

void handleButton1Press(){
 fill(255,0,0);
 joypad.rumble(1);
}

void handleButton1Release(){
 fill(255);
}

void draw(){
 if (screen){
 
 background(255);
 image(controller,60,130);
 image(title,45,-140);
 
 simon.addNewButton();
 simon.showNextButton();
 
 
 if(button11.pressed() && button11state==false){
   button11state = true;
   simon.checkButtonPress(11);
 }
 if(!button11.pressed() && button11state==true){
   //simon.checkButtonPress(11);
   button11state = false;
 }
 
 if(button12.pressed() && button12state==false){
   button12state = true;
   simon.checkButtonPress(12);
 }
 if(!button12.pressed() && button12state==true){
   //simon.checkButtonPress(12);
   button12state = false;
 }
 
 if(button13.pressed() && button13state==false){
   button13state = true;
   simon.checkButtonPress(13);
 }
 if(!button13.pressed() && button13state==true){
   //simon.checkButtonPress(13);
   button13state = false;
 }
 
 if(button14.pressed() && button14state==false){
   button14state = true;
   simon.checkButtonPress(14);
 }
 if(!button14.pressed() && button14state==true){
   //simon.checkButtonPress(14);
   button14state = false;
 }
 
 if(button8.pressed() && button8state==false){
   button8state = true;
   simon.checkButtonPress(8);
 }
 if(!button8.pressed() && button8state==true){
   //simon.checkButtonPress(8);
   button8state = false;
 }
 
 if(button9.pressed() && button9state==false){
   button9state = true;
   simon.checkButtonPress(9);
 }
 if(!button9.pressed() && button9state==true){
   //simon.checkButtonPress(9);
   button9state = false;
 }
 
 if(button6.pressed() && button6state==false){
   button6state = true;
   simon.checkButtonPress(6);
 }
 if(!button6.pressed() && button6state==true){
   //simon.checkButtonPress(6);
   button6state = false;
 }
 
 if(button7.pressed() && button7state==false){
   button7state = true;
   simon.checkButtonPress(7);
 }
 if(!button7.pressed() && button7state==true){
   //simon.checkButtonPress(7);
   button7state = false;
 }
} else {
 image(titlescreen,0,0);
}
if(button4.pressed()){
  screen = true;
}

}


Here is the initial Sketch code.
Re: Process/Procontroll Simon Memory Game Help
Reply #1 - Apr 30th, 2010, 2:27pm
 
And here's the Simon Class tab to it.




Code:
class Simon{
ArrayList order;
int newButton = 10;
int orderIndex = 0;
int playerIndex = 0;
boolean playerMode = false;

Simon(){
order = new ArrayList();
addNewButton();

}

void addNewButton(){
while (newButton == 10) newButton = int( random(7,15));
// while (newButton == 10) newButton = (int) random(7,15);
order.add(newButton);
}

void showNextButton(){
if(orderIndex >= order.size()){
playerMode = true;
orderIndex = 0;
return;
}
int theButton = (Integer) order.get(orderIndex);
switch(theButton){
case 6:
image(controllerleftthumb,60,130);
break;
case 7:
image(controllerrightthumb,60,130);
break;
case 8:
image(controllerleftbumper,60,130);
break;
case 9:
image(controllerrightbumper,60,130);
break;
case 11:
image(controllera,60,130);
break;
case 12:
image(controllerb,60,130);
break;
case 13:
image(controllerx,60,130);
break;
case 14:
image(controllery,60,130);
break;
}
addNewButton();
orderIndex++;
}

void checkButtonPress(int buttonID){
int correctButton = (Integer) order.get(playerIndex);
if(buttonID == correctButton){
switch(correctButton){
case 6:
image(controllerleftthumb,60,130);
break;
case 7:
image(controllerrightthumb,60,130);
break;
case 8:
image(controllerleftbumper,60,130);
break;
case 9:
image(controllerrightbumper,60,130);
break;
case 11:
image(controllera,60,130);
break;
case 12:
image(controllerb,60,130);
break;
case 13:
image(controllerx,60,130);
break;
case 14:
image(controllery,60,130);
break;
}
playerIndex++;

if(playerIndex >= order.size()){
playerIndex=0;
playerMode = false;
addNewButton();
}

} else {
//image(gameover,0,0);
}

}
}

Page Index Toggle Pages: 1