megeness
YaBB Newbies
Offline
Posts: 2
Guys I need ur help urgently
Feb 2nd , 2010, 4:20pm
Guy, I am working on a final semester project and I have few problems with my application, I was asked to design a game that teaches Kids shapes and colours, I have written codes to identify these shapes and some colors but I cant get around the next stage where I am supposed to place an image and have it stick on the interface, those coordinates are driving me nuts, e.g Place "triangle red" where there you see triangle red this is my code below: import ddf.minim.*; import TUIO.*; TuioProcessing tuioClient; float obj_size = 100; int txtSize=12; PFont font; PImage bkgrnd,bkgrndbottom; public int choice=0; int id; HashMap symbols=new HashMap(); Minim minim,playletter; AudioPlayer ap,groove; String objects[]={"triangle","rectangle","circle","ecclipse","star"}; String colors[]= {"red","blue","green","yellow"}; boolean played[]=new boolean[20]; void setup() { bkgrnd=loadImage("bkgrnd.jpg"); bkgrndbottom=loadImage("bkgrndbottom.gif"); for (int i=0;i <20; i++) played[i]=false; minim = new Minim(this); /* bd = minim.loadFile("tr.mp3", 12000); snare = minim.loadFile("tb.mp3", 12000); bass = minim.loadFile("tg.mp3", 11000); cym = minim.loadFile("ty.mp3", 12000); intro = minim.loadFile("inero.mp3", 12000); cha = minim.loadFile("sr.mp3", 12000); ma = minim.loadFile("sb.mp3", 12000); re = minim.loadFile("sg.mp3", 12000); ge = minim.loadFile("sy.mp3", 12000); gh = minim.loadFile("cr.mp3", 12000); ju = minim.loadFile("cb.mp3", 12000); inm = minim.loadFile("cg.mp3", 12000); ur = minim.loadFile("cy.mp3", 12000); mss = minim.loadFile("errmsg.mp3", 12000);*/ //intro.play(); groove = minim.loadFile("backmusic.mp3" , 10000); groove.play(); groove.loop(); size(1000,700); noStroke(); font = createFont("Arial", txtSize); textFont(font,txtSize); tuioClient = new TuioProcessing(this); } void drawshape(int i) { if (i==0) triangle(30, 75, 58, 20, 86, 75); else if (i==1) rect(30, 20, 100, 100); } void fillcolor(int i) { if (i==0) fill(237, 28, 36); else if (i==1) fill(46, 49, 146); else if (i==2) fill(0, 166, 81); else if (i==3) fill(255, 242, 0); } void draw() { TuioObject[] tuioObjectList = sortObjs(tuioClient.getTuioObjects()); background(1); image(bkgrndbottom,0,630); image(bkgrnd,0,0); for (int i=0;i<tuioObjectList.length;i++) { TuioObject tobj = tuioObjectList[i]; id = tobj.getSymbolID(); fill(255); stroke(0); fill(192,168,225); String currentcolor=colors[id%4]; String currentObject=objects[id/4]; pushMatrix(); translate(tobj.getScreenX(width),tobj.getScreenY(height)); textSize(25); fillcolor(id%4); drawshape(id/4); //text (currentObject.charAt(0)+""+currentcolor.charAt(0)+ ".mp3",400,400); if (played[id]==false) { playletter = new Minim (this); ap = playletter.loadFile(currentObject.charAt(0)+""+currentcolor.charAt(0) + ".mp3", 12000); ap.play(); playletter.stop(); played[id]=true; } text ("shape" + currentObject + "Colour" + currentcolor ,-100,100); popMatrix(); } } TuioObject [] sortObjs(Vector objs){ /* Sort the objects in order of their X position - left-most first */ TuioObject [] newObjs = new TuioObject [objs.size()]; int numObjs =objs.size(); float prevX=-1; TuioObject o; for (int i =0; i<numObjs; i++){ float minX = width; for (int j =0; j<numObjs; j++){ TuioObject x=(TuioObject)objs.elementAt(j); if (x.getX()<minX && x.getX()>prevX){ minX=x.getX(); newObjs[i]=x; } } prevX=minX; } return newObjs; } // these callback methods are called whenever a TUIO event occurs // called when an object is added to the scene void addTuioObject(TuioObject tobj) { } // called when an object is removed from the scene void removeTuioObject(TuioObject tobj) { } // called when an object is moved void updateTuioObject (TuioObject tobj) { } // called when a cursor is added to the scene void addTuioCursor(TuioCursor tcur) { } // called when a cursor is moved void updateTuioCursor (TuioCursor tcur) { } // called when a cursor is removed from the scene void removeTuioCursor(TuioCursor tcur) { } // called after each message bundle // representing the end of an image frame void refresh(TuioTime bundleTime) { //redraw(); }