private void action(int action) { mCubicStartAniSprite.setVisible(false); mCubicStartAniSprite.stopAnimation(0); switch (action) { case ACTION_TURN_LEVEL_1: case ACTION_TURN_LEVEL_2: case ACTION_TURN_LEVEL_3: ACTION = action; final Body body = (Body) this.getUserData(); final Vector2 vector2 = Vector2Pool.obtain(body.getPosition()); int frame[] = new int[] {0, 1}; body.setAngularDamping(1.2f); vector2.x = vector2.x / 3; vector2.y = vector2.y / 3; if (action == ACTION_TURN_LEVEL_2) { frame = new int[] {2, 3}; body.setAngularDamping(2.2f); vector2.x = vector2.x / 2; vector2.y = vector2.y / 2; } else if (action == ACTION_TURN_LEVEL_3) { frame = new int[] {4, 5}; body.setAngularDamping(3.2f); } Vol3Osyougatsu.OGG_A3_A_5_KOMATEI.play(); mCubicTurnAniSprite.animate(new long[] {250, 250}, frame, -1); mCubicTurnAniSprite.setVisible(true); body.setActive(true); Log.i(TAG, "body.getPosition " + vector2); vector2.x = random(vector2.x) + new Random().nextFloat(); vector2.y = random(vector2.y) + new Random().nextFloat(); body.setLinearVelocity(vector2); Log.i(TAG, "body.getPosition change " + vector2); this.unregisterUpdateHandler(timerHandler); this.registerUpdateHandler( timerHandler = new TimerHandler( 6f, new ITimerCallback() { @Override public void onTimePassed(TimerHandler timerHandler) { // Stop Turn stopTurn(); } })); break; } }
private void addObstacle(final Scene pScene, final float pX, final float pY) { final Sprite box = new Sprite(pX, pY, 32, 32, this.mBoxTextureRegion); final FixtureDef boxFixtureDef = PhysicsFactory.createFixtureDef(0.1f, 0.5f, 0.5f); final Body boxBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, box, BodyType.DynamicBody, boxFixtureDef); boxBody.setLinearDamping(10); boxBody.setAngularDamping(10); this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(box, boxBody, true, true)); pScene.getChild(LAYER_OBSTACLES).attachChild(box); }
public Puck( final float pX, final float pY, final TextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager, PhysicsWorld physicsWorld) { super(pX, pY, pTextureRegion, pVertexBufferObjectManager); fixtureDef.filter.categoryBits = NightHockeyActivity.CATEGORY_PUCK; fixtureDef.filter.maskBits = NightHockeyActivity.CATEGORY_WALL; body = PhysicsFactory.createCircleBody(physicsWorld, this, BodyType.DynamicBody, fixtureDef); body.setLinearDamping(0.3f); body.setAngularDamping(0.3f); body.setUserData(this); setAlpha(0.2f); physicsWorld.registerPhysicsConnector(new PhysicsConnector(this, body, true, true)); startPosition = new Vector2(body.getPosition()); }
@Override public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) { mPhysicsWorld = new FixedStepPhysicsWorld( 60, new Vector2(0f, -SensorManager.GRAVITY_EARTH * 2), false, 8, 3); mScene.registerUpdateHandler(mPhysicsWorld); final FixtureDef WALL_FIXTURE_DEF = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f); final Rectangle ground = new Rectangle( cameraWidth / 2f, 6f, cameraWidth - 4f, 8f, this.getVertexBufferObjectManager()); final Rectangle roof = new Rectangle( cameraWidth / 2f, cameraHeight - 6f, cameraWidth - 4f, 8f, this.getVertexBufferObjectManager()); final Rectangle left = new Rectangle( 6f, cameraHeight / 2f, 8f, cameraHeight - 4f, this.getVertexBufferObjectManager()); final Rectangle right = new Rectangle( cameraWidth - 6f, cameraHeight / 2f, 8f, cameraHeight - 4f, this.getVertexBufferObjectManager()); ground.setColor(0f, 0f, 0f); roof.setColor(0f, 0f, 0f); left.setColor(0f, 0f, 0f); right.setColor(0f, 0f, 0f); groundWallBody = PhysicsFactory.createBoxBody( this.mPhysicsWorld, ground, BodyType.StaticBody, WALL_FIXTURE_DEF); roofWallBody = PhysicsFactory.createBoxBody( this.mPhysicsWorld, roof, BodyType.StaticBody, WALL_FIXTURE_DEF); leftWallBody = PhysicsFactory.createBoxBody( this.mPhysicsWorld, left, BodyType.StaticBody, WALL_FIXTURE_DEF); rightWallBody = PhysicsFactory.createBoxBody( this.mPhysicsWorld, right, BodyType.StaticBody, WALL_FIXTURE_DEF); this.mScene.attachChild(ground); this.mScene.attachChild(roof); this.mScene.attachChild(left); this.mScene.attachChild(right); Rectangle GravityRect = new Rectangle(300f, 240f, 100f, 100f, this.getEngine().getVertexBufferObjectManager()); GravityRect.setColor(0f, 0.7f, 0f); mScene.attachChild(GravityRect); mScene.registerTouchArea(GravityRect); gravityBody = PhysicsFactory.createBoxBody( mPhysicsWorld, GravityRect, BodyType.DynamicBody, boxFixtureDef); gravityBody.setLinearDamping(0.4f); gravityBody.setAngularDamping(0.6f); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(GravityRect, gravityBody)); Rectangle AntiGravityRect = new Rectangle(500f, 240f, 100f, 100f, this.getEngine().getVertexBufferObjectManager()) { @Override protected void onManagedUpdate(final float pSecondsElapsed) { super.onManagedUpdate(pSecondsElapsed); antigravityBody.applyForce( -mPhysicsWorld.getGravity().x * antigravityBody.getMass(), -mPhysicsWorld.getGravity().y * antigravityBody.getMass(), antigravityBody.getWorldCenter().x, antigravityBody.getWorldCenter().y); } }; AntiGravityRect.setColor(0f, 0f, 0.7f); mScene.attachChild(AntiGravityRect); mScene.registerTouchArea(AntiGravityRect); antigravityBody = PhysicsFactory.createBoxBody( mPhysicsWorld, AntiGravityRect, BodyType.DynamicBody, boxFixtureDef); antigravityBody.setLinearDamping(0.4f); antigravityBody.setAngularDamping(0.6f); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(AntiGravityRect, antigravityBody)); mScene.setOnSceneTouchListener(this); pOnPopulateSceneCallback.onPopulateSceneFinished(); }
public Car( World world, int CarNum, int ColorNum, int playerNum, ScreenAssets assets, boolean testing) { this.playerNum = playerNum; this.carNum = CarNum; this.assets = assets; whichCar(CarNum, ColorNum); if (testing) { if (GameScreen.getMapNum() == 0) { lapCounter = 4; } else { lapCounter = 1; } } car_car = assets.manager.get(ScreenAssets.car_car_sound); car_wall1 = assets.manager.get(ScreenAssets.car_wall_sound1); car_wall2 = assets.manager.get(ScreenAssets.car_wall_sound2); car_wall3 = assets.manager.get(ScreenAssets.car_wall_sound3); car_Tire = assets.manager.get(ScreenAssets.car_tire_sound); car_lap_complete = assets.manager.get(ScreenAssets.lap_complete_sound); car_fueling = assets.manager.get(ScreenAssets.refueling_loop); car_going_on_fuel = assets.manager.get(ScreenAssets.getting_on_fuel_sound); fuelAreas = new Array<FuelAreaType>(); currentCheckpoints = new Array<Integer>(); tires = new Array<Tire>(); BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.DynamicBody; bodyDef.position.set(InitialPosition); body = world.createBody(bodyDef); body.setAngularDamping(3); Vector2[] vertices = new Vector2[8]; vertices[0] = new Vector2(0.75f, -2.5f); vertices[1] = new Vector2(1.5f, -2f); vertices[2] = new Vector2(1.5f, 2f); vertices[3] = new Vector2(0.75f, 2.5f); vertices[4] = new Vector2(-0.75f, 2.5f); vertices[5] = new Vector2(-1.5f, 2f); vertices[6] = new Vector2(-1.5f, -2f); vertices[7] = new Vector2(-0.75f, -2.5f); PolygonShape polygonShape = new PolygonShape(); polygonShape.set(vertices); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = polygonShape; fixtureDef.isSensor = false; fixtureDef.density = density; fixtureDef.filter.categoryBits = Constants.CAR; fixtureDef.filter.maskBits = Constants.GROUND | Constants.TIREOBS | Constants.CAR | Constants.WALL | Constants.FUEL | Constants.FINISH | Constants.BRIDGE | Constants.METAL | Constants.ICE; Fixture fixture = body.createFixture(fixtureDef); fixture.setUserData(new CarType(carSprite, this)); // body.applyTorque(1000, true); carSprite = new Sprite(new Texture(carLink)); carSprite.setSize(3, 6); carSprite.setOrigin(carSprite.getWidth() / 2, carSprite.getHeight() / 2); body.setUserData(new CarType(carSprite, this)); RevoluteJointDef jointDef = new RevoluteJointDef(); jointDef.bodyA = body; jointDef.enableLimit = true; jointDef.lowerAngle = 0; jointDef.upperAngle = 0; jointDef.localAnchorB.setZero(); float maxForwardSpeed = maxFSpeed; float maxBackwardSpeed = maxBSpeed; float backTireMaxDriveForce = backTireMDriveForce; float frontTireMaxDriveForce = frontTireMDriveForce; float backTireMaxLateralImpulse = backTireMLateralImpulse; float frontTireMaxLateralImpulse = frontTireMLateralImpulse; float breakingForcePourcentage = breakingFPourcentage; // Lower Left Tire tire = new Tire(world, playerNum); tire.setCharacteristics( maxForwardSpeed, maxBackwardSpeed, backTireMaxDriveForce, backTireMaxLateralImpulse, breakingForcePourcentage); jointDef.bodyB = tire.body; jointDef.localAnchorA.set(-1.125f, -1.5f); world.createJoint(jointDef); tires.add(tire); // Lower Right tire = new Tire(world, playerNum); tire.setCharacteristics( maxForwardSpeed, maxBackwardSpeed, backTireMaxDriveForce, backTireMaxLateralImpulse, breakingForcePourcentage); jointDef.bodyB = tire.body; jointDef.localAnchorA.set(1.125f, -1.5f); world.createJoint(jointDef); tires.add(tire); // Upper Left tire = new Tire(world, playerNum); tire.setCharacteristics( maxForwardSpeed, maxBackwardSpeed, frontTireMaxDriveForce, frontTireMaxLateralImpulse, breakingForcePourcentage); jointDef.bodyB = tire.body; jointDef.localAnchorA.set(-1.125f, 1.5f); leftJoint = (RevoluteJoint) world.createJoint(jointDef); tires.add(tire); // Upper Right tire = new Tire(world, playerNum); tire.setCharacteristics( maxForwardSpeed, maxBackwardSpeed, frontTireMaxDriveForce, frontTireMaxLateralImpulse, breakingForcePourcentage); jointDef.bodyB = tire.body; jointDef.localAnchorA.set(1.125f, 1.5f); rightJoint = (RevoluteJoint) world.createJoint(jointDef); tires.add(tire); } // end of car