John128
YaBB Newbies
Offline
Posts: 6
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(); } ---------------------------