private void checkHit() { AllMinionState m = (AllMinionState) getOneIntersectingObject(AllMinionState.class); SWorld sWorld = (SWorld) getWorld(); if (m != null) { oneUpSound.play(); CollectPoints cp = new CollectPoints(); cp.collectLives(1); if (getWorld() instanceof MyWorld) { MyWorld myWorld = (MyWorld) sWorld; myWorld.updatePointScoreboard(); } getWorld().removeObject(this); } }
/** Check whether a hand (of any user) touches the radio. Play radio if it does. */ public void checkHands() { MyWorld world = (MyWorld) getWorld(); UserData[] users = world.getTrackedUsers(); for (UserData user : users) { Joint rightHand = user.getJoint(Joint.RIGHT_HAND); Radio radio = getRadio(rightHand.getX(), rightHand.getY()); if (radio != null) { // yes, there was a radio radio.play(1); } else { Joint leftHand = user.getJoint(Joint.LEFT_HAND); radio = getRadio(leftHand.getX(), leftHand.getY()); if (radio != null) { radio.play(2); } } } }
public static void main(String[] args) { if (args.length != 3) { System.out.println("usage: java PhysicsLab <delta_time[s]> <end_time[s]> <sampling_time[s]>"); System.exit(-1); } double deltaTime = Double.parseDouble(args[0]); // [s] double endTime = Double.parseDouble(args[1]); // [s] double samplingTime = Double.parseDouble(args[2]); // [s] MyWorld world = new MyWorld(System.out); double mass = 1.0; // 1 [kg] double radius = 0.1; // 10 [cm] double position = 1.0; // 1 [m] double speed = 0.5; // 0.5 [m/s] Ball b0 = new Ball(mass, radius, position, speed); Ball b1 = new Ball(2.0, radius, 2.56, 0); Ball b2 = new Ball(mass, radius, 4.56, 0); world.addElement(b0); // SE AGREGA A ARRAYLIST, ES UN PHYSICSELEMENT world.addElement(b1); // SE AGREGA A ARRAYLIST, ES UN PHYSICSELEMENT world.addElement(b2); // SE AGREGA A ARRAYLIST, ES UN PHYSICSELEMENT world.simulate(deltaTime, endTime, samplingTime); // delta time[s], total simulation time [s]. }