reset_programm_routine
in
Contributed Library Questions
•
8 months ago
hey guys,
i´ve a little problem with the processing code below. it´s a game where three balls flying in randomly and the user has to kick them by gestures. the balls are already flying like i want them to fly and also the gestures are working (realized with "kineticspace").
my problem is: if i´ve done the gesture and the ball is flying away it won´t come back. i need a routine structure which let´s reset the whole game. i tryed a for-construction, but i don´t really know how that workes and why it doesn´t work in my special case.
here is the code, thank for help:
PImage virtualMarathon;
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
import processing.video.*;
Movie enviroment;
Handicap handicapAbove;
Handicap handicapLeft;
Handicap handicapRight;
int gameSizeX = 600;
int gameSizeY = 600;
int detectedGestureID;
void oscEvent(OscMessage theOscMessage)
{
if (theOscMessage.checkAddrPattern("/kinect")==true)
{
if (theOscMessage.checkTypetag("is"))
{
int firstValue = theOscMessage.get(0).intValue();
detectedGestureID = firstValue;
String thirdValue = theOscMessage.get(1).stringValue();
print("### received an osc message /kinect with typetag is.");
println(" values: "+firstValue+", "+thirdValue);
return;
}
}
}
void setup()
{
size(gameSizeX, gameSizeY);
virtualMarathon = loadImage("VirtualMarathon.png");
frameRate(60);
oscP5 = new OscP5(this, 8000);
myRemoteLocation = new NetAddress("127.0.0.1", 8000);
enviroment = new Movie(this, "enviroment.mov");
enviroment.loop();
handicapAbove = new Handicap (0, 3, 0, 3, 230, -300, 230, -300, "ball_above.png");
handicapLeft = new Handicap (2, 2, -6, -6, -250, -50, -250, -50, "ball_left.png");
handicapRight = new Handicap (-2, 2, 6, -6, 600, 50, 600, 50, "ball_right.png");
}
void draw()
{
background(255);
if (detectedGestureID == 4)
{
image(enviroment, -600, -400);
handicapAbove.show();
handicapLeft.show();
handicapRight.show();
//for (int i = 0; i < 3; i++)
//{
if (detectedGestureID == 0)
{
handicapAbove.detectedGestureID();
}
if (detectedGestureID == 2)
{
handicapLeft.detectedGestureID();
}
if (detectedGestureID == 1)
{
handicapRight.detectedGestureID();
}
else
{
handicapAbove.move();
handicapLeft.move();
handicapRight.move();
}
//}
}
else
{
image(virtualMarathon, -600, -400);
}
}
void movieEvent(Movie enviroment)
{
enviroment.read();
}
class Handicap
{
PImage Image;
int xSpeed, ySpeed, xSpeedBack, ySpeedBack, xPos, yPos, xResetPos, yResetPos;
Handicap(int xV, int yV, int xVback, int yVback, int xPosition, int yPosition, int xResetPosition, int yResetPosition, String fileImage)
{
xSpeed = xV;
ySpeed = yV;
xSpeedBack = xVback;
ySpeedBack = yVback;
xPos = xPosition;
yPos = yPosition;
xResetPos = xResetPosition;
yResetPos = yResetPosition;
Image = loadImage(fileImage);
}
void show()
{
image(Image, xPos, yPos);
/*println("pos: " + xPos + "," + yPos);*/
}
void move()
{
xPos += xSpeed;
yPos += ySpeed;
if ((yPos > height) && (random(150) < 0.5))
{
xPos = xResetPos;
yPos = yResetPos;
}
}
void detectedGestureID()
{
xSpeed = xSpeedBack;
ySpeed = ySpeedBack;
}
}
greetings, vincent_imd
1