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.
Page Index Toggle Pages: 1
Memory Game (Read 679 times)
Memory Game
Apr 16th, 2010, 3:09am
 
Hi,

I'm trying to build a memory game with Processing. Now I'm having the problem I don't know how to get an audio file behind a card. (so when you click a card an audio file will start playing.

I'm a beginner with Processing.

The code:
------------------------

boolean playing=false;

int leftMouse = 0;
//////////////////////////////////////////////////CLASS CARD/////////////////////////////////
class Card
{
 private int x,y,w=100,h=70;
 private int soundfragment;
 private boolean exposed=false;
   
 Card(int x,int y)
 {
   this.x=x;
   this.y=y;
   soundfragment=0;
 }
 
 void paint()
 {
   if(exposed)
   {
   fill (255);
   }
   else {
    fill (0);
   }
    rect(x,y,w,h);
 }
 
 boolean inside(int x,int y)
 {
   if(x>=this.x && x<=this.x+w && y>=this.y && y<=this.y+h) return true;
   else return false;
 }
 
 void setExposed(boolean e)
 {
   exposed=e;
 }
} // Card{}


Card [] card = new Card[12];

//////////////////////////////////////////////////VOID SETUP/////////////////////////////////
void setup() {
size(700, 700);
background(255, 204, 0);
frameRate(30);


for(int i=0; i<12; i++) card[i] = new Card(20+(i%3)*150,20+(i/3)*100);
}

//////////////////////////////////////////////////MOUSE CLICK/////////////////////////////////
void mouseClicked()
{
  for(int i=0; i<12; i++)
  {
    if(card[i].inside(mouseX,mouseY))
    {
      card[i].setExposed(true);
    }
    else  card[i].setExposed(false);
  }

}
 
//////////////////////////////////////////////////DRAW//////////////////////////
///////
void draw() {
 for(int i=0; i< 12; i++) card[i].paint();  
 
}


---------------------------
Re: Memory Game
Reply #1 - Apr 17th, 2010, 3:54am
 
If your issue is to play sounds, I think you have to look into the Minim sound library.
Page Index Toggle Pages: 1