2

こんにちは、私は処理が初めてで、マウスの代わりにマーカーを使用して球を左から右に移動させる方法を見つけようとしています。私を助けてくれませんか?マーカーを使って撃つことはできますが、撃って球体を動かすことはできません

import TUIO.*;
TuioProcessing tuioClient;
HashMap symbols=new HashMap();

PFont fontA;
int sphereDiameter = 50;
boolean shoot = false;

 float obj_size = 60;


 int randx()
 {
return int(random(600));
 }

 int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
 int[] sphereYCoords = { 0, 0, 0, 0, 0 };

 void setup()
{
size(1000,700);

tuioClient  = new TuioProcessing(this);
}

void draw()
{ 
Vector<TuioObject> tuioObjectList =tuioClient.getTuioObjects();
 Collections.sort(tuioObjectList, comp);

  for (TuioObject tobj:tuioObjectList) {
  fill(50, 50, 100);

  int id = tobj.getSymbolID();
  int x = tobj.getScreenX(width);
  int y = tobj.getScreenY(height);
  rect(x, y, obj_size, obj_size);

  String txt="?";
  if (symbols.containsKey(id)) {// if it's one in symbols, then look it up
  txt = (String)symbols.get(id);
  } 
  fill(255);
  text(txt, x, y);
  }   

 int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
      fill(100, 0, 0);
      // draw the answer box
    //  ellipse(answerX, answerY, obj_size, obj_size);
      fill(255);
      // write the answer text
    // text(""+answer, answerX, answerY);



  background(1);
  fill(color(255,255,0));
  stroke(color(0,255,0));
  triangle(mouseX-8, 580, mouseX+8, 580, mouseX, 565);
  fill(color(255,0,0));
  stroke(color(255,0,0));

if(shoot==true)
{
  sphereKiller( mouseX);
  shoot = false;
  }

  sphereDropper();
  //gameEnder();  
 }

   Comparator<TuioObject> comp = new Comparator<TuioObject>() {
   // Comparator object to compare two TuioObjects on the basis of their x position
 // Returns -1 if o1 left of o2; 0 if they have same x pos; 1 if o1 right of o2
 public int compare(TuioObject o1, TuioObject o2) {
  if (o1.getX()<o2.getX()) { 
    return -1;
    }  
  else if (o1.getX()>o2.getX()) { 
  return 1;
  }  
    else { 
  return 0;
  }
  }
  };

    void mousePressed()
   {
  shoot = true;
  }




  void sphereDropper()
  {  
  stroke(255);
  fill(255);

   for (int i=0; i<5; i++)
  {
  ellipse(sphereXCoords[i], sphereYCoords[i]++,
          sphereDiameter, sphereDiameter);

   }
  }

  void sphereKiller(int shotX)
  {
   boolean hit = false;
   for (int i = 0; i < 5; i++)
    {
     if((shotX >= (sphereXCoords[i]-sphereDiameter/2)) && 
        (shotX <= (sphereXCoords[i]+sphereDiameter/2)))
     {
      hit = true;
    line(mouseX, 565, mouseX, sphereYCoords[i]);
    ellipse(sphereXCoords[i], sphereYCoords[i],
            sphereDiameter+25, sphereDiameter+25);
    sphereXCoords[i] = randx();
    sphereYCoords[i] = 0;
  }    
  }

  if(hit == false)
  {
    line(mouseX, 565, mouseX, 0);
   }  

   }

     /* void gameEnder()
  {
   for (int i=0; i< 5; i++)
    {
    if(sphereYCoords[i]==600)
  {
    fill(color(255,0,0));
    noLoop();
    }
   }
     }*/

  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) {

  if(tobj.getSymbolID() == 32)
   {
    shoot = true;
   }
   }

   // 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();
   }
4

1 に答える 1