public void setUp() { BodyDef bodyDef = new BodyDef(); bodyDef.position.set(x + width / 2, y + height / 2); bodyDef.type = BodyDef.BodyType.KinematicBody; PolygonShape shape = new PolygonShape(); shape.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; body = world.createBody(bodyDef); body.createFixture(fixtureDef); body.setUserData(Constants.robotNinjaID); body.setLinearVelocity(Constants.standardVelocity); sprite = new Sprite(texture); sprite.setSize(width, height); sprite.setOrigin(width / 2, height / 2); sprite.flip(false, flipy); sprite.setPosition(x, y); dead = false; }
private void createCoins() { coins = new Array<Coin>(); MapLayer layer = tileMap.getLayers().get("Coins"); BodyDef bdef = new BodyDef(); FixtureDef fdef = new FixtureDef(); for (MapObject mo : layer.getObjects()) { bdef.type = BodyType.StaticBody; float x = mo.getProperties().get("x", Float.class) / PPM; float y = mo.getProperties().get("y", Float.class) / PPM; bdef.position.set(x, y); CircleShape cShape = new CircleShape(); cShape.setRadius(8 / PPM); fdef.shape = cShape; fdef.isSensor = true; fdef.filter.categoryBits = B2DVars.BIT_COINS; fdef.filter.maskBits = B2DVars.BIT_PLAYER; Body body = world.createBody(bdef); body.createFixture(fdef).setUserData("coin"); Coin c = new Coin(body); coins.add(c); body.setUserData(c); } }
// Create everything from a SceneModel. (SceneModels are easily serialized) private void buildFromModel(PhysicsSceneModel physicsModel) { logger.debug("Build from physics scene model"); scene.createFromModel(physicsModel); for (Body b : scene.getBodies()) { b.setUserData(this); } }
private void createPhysics(final Camera camera, PhysicsWorld physicsWorld) { body = PhysicsFactory.createBoxBody( physicsWorld, this, BodyType.DynamicBody, PhysicsFactory.createFixtureDef(0, 0, 0)); body.setUserData("player"); body.setFixedRotation(true); physicsWorld.registerPhysicsConnector( new PhysicsConnector(this, body, true, false) { @Override public void onUpdate(float pSecondsElapsed) { super.onUpdate(pSecondsElapsed); camera.onUpdate(0.1f); if (getY() <= 0) { onDie(); } if (canRun) { body.setLinearVelocity(new Vector2(5, body.getLinearVelocity().y)); } } }); }
@Override public void start() { createBodyDef() .ifPresent( bodyDef -> { physicalBody = world.createBody(bodyDef); physicalBody.setUserData(getGameObject()); collisionShape.affixTo(physicalBody, isSensor).setUserData(gameObject); }); }
public Portal(float x, float y, World world, OrthographicCamera camera) { super(world, camera); this.x = x; this.y = y; this.prepareTextures(); portalBody = BodyFactory.createBody(new Vector2(x, y), BodyType.StaticBody); CircleShape shape = BodyFactory.createCircleShape(frames[0].getRegionWidth() / 4); BodyFactory.createFixture( portalBody, shape, new float[] {1, 1, 1}, true, Constants.ENVIRONMENT_GROUP); portalBody.setUserData(this); portalBody.setFixedRotation(true); }
private void createPlayer() { this.player = new Player( PLAYER_X, GROUND_LEVEL + GROUND_THICKNESS / 2 + 32, this.resourcesManager.player, this.vbom, this.physicWorld) { @Override protected void onUpdateColor() { super.onUpdateColor(); if (BaseGameScene.this.playerTrail != null) { BaseGameScene.this.playerTrail.setColor(this.getColor()); } } }; this.player.getBody().setUserData("player"); this.player.registerPlayerListener(new BaseGamePlayerListener()); this.attachChild(this.player); this.playerTrail = new Trail( 36, 0, 0, 64, -340, -300, -2, 2, 25, 30, 50, Trail.ColorMode.NORMAL, this.resourcesManager.trail, this.vbom); this.playerTrail.bind(this.player); this.attachChild(this.playerTrail); this.playerTrail.hide(); this.playerTrail.setZIndex(this.player.getZIndex() - 1); this.sortChildren(); Body retention = PhysicsFactory.createBoxBody( this.physicWorld, PLAYER_X - this.player.getWidth() / 2, 250, 1, 400, BodyDef.BodyType.StaticBody, PhysicsFactory.createFixtureDef(0, 0, 0)); retention.setUserData("retention"); }
public static Body createWall(World world, float x, float y, float width, float height) { BodyDef bodyDef = new BodyDef(); bodyDef.position.set(new Vector2(x, y)); Body body = world.createBody(bodyDef); PolygonShape shape = new PolygonShape(); shape.setAsBox(width / 2, height / 2); Fixture fixture = body.createFixture(shape, Constants.WALL_DENSITY); body.setUserData(new WallUserData()); shape.dispose(); return body; }
public void createObject(World world) { // position = (direction)?position.add(1, 0):position.add(-1, 0); body = Box2DUtils.createPolygonBody( world, null, new Vector2(-100f, -100f), 0.3f, 0.1f, 0f, 0f, 0f, true, true, true); body.setUserData(this); // Image // Sprite sprite = new Sprite(new Texture(this.spritePath)); // sprite.setSize(15f, 15f); // sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2); // body.setUserData(sprite); }
public static void addDynamicBody(Game game, DynamicGameObject gameObject, World box2dWorld) { gameObject.setBox2DWorld(box2dWorld); BodyDef characterBodyDef = new BodyDef(); characterBodyDef.type = BodyDef.BodyType.DynamicBody; Body body = box2dWorld.createBody(characterBodyDef); body.setUserData(gameObject); body.setTransform(gameObject.pos, 0f); gameObject.body = body; }
public void render(OrthographicCamera camera) { // update the world with a fixed time step world.step(Gdx.app.getGraphics().getDeltaTime() * 10, 8, 3); if (mouseJoint != null) mouseJoint.setTarget(bob.getBody().getWorldCenter()); // Destroy mouseJoint? (drop item) if (destroyMousejoint == true) { if (!world.isLocked()) { world.destroyJoint(mouseJoint); mouseJoint = null; destroyMousejoint = false; } } // Delete any bodies up for deletion if (!bodiesToDelete.isEmpty()) { // Make sure it is safe to delete!! if (!world.isLocked()) { for (Body body : bodiesToDelete) { world.destroyBody(body); body.setUserData(null); body = null; } bodiesToDelete.clear(); // Don't forget to clear the null bodies! } } // Create any bodies up for creation if (!bodiesToCreate.isEmpty()) { // Make sure it is safe to create!! if (!world.isLocked()) { for (BodyDef body : bodiesToCreate) { world.createBody(body); } bodiesToCreate.clear(); // Don't forget to clear! } } // Create any joints up for creation if (!jointsToCreate.isEmpty()) { // Make sure it is safe to create!! if (!world.isLocked()) { for (JointDef body : jointsToCreate) { mouseJoint = (MouseJoint) world.createJoint(body); } jointsToCreate.clear(); // Don't forget to clear! } } // render the world using the debug renderer renderer.render(world, camera.combined); }
public void createIceBall() { // gear base BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.StaticBody; bodyDef.position.x = x; bodyDef.position.y = y; CircleShape circleShape = new CircleShape(); circleShape.setRadius(1); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.isSensor = true; fixtureDef.shape = circleShape; gearBody = world.createBody(bodyDef); gearBody.createFixture(fixtureDef); circleShape = new CircleShape(); circleShape.setRadius(size); BodyDef boxBodyDef = new BodyDef(); boxBodyDef.type = BodyType.DynamicBody; boxBodyDef.position.x = x; boxBodyDef.position.y = y; fixtureDef = new FixtureDef(); fixtureDef.shape = circleShape; fixtureDef.friction = 0f; fixtureDef.density = 4.10f; fixtureDef.restitution = 1.5f; fixtureDef.isSensor = true; fixtureDef.filter.groupIndex = -1; gearBase = world.createBody(boxBodyDef); SpriteInfo spriteTemp = new SpriteInfo(assets.getSprite("star")); spriteTemp.setName("star"); gearBase.setUserData(spriteTemp); gearBase.createFixture(fixtureDef); // iceBody.createFixture(circleShape, .1f); RevoluteJointDef wheeljointDef = new RevoluteJointDef(); wheeljointDef.bodyA = gearBase; wheeljointDef.bodyB = gearBody; wheeljointDef.localAnchorA.y = 0; wheeljointDef.localAnchorB.y = 0; wheeljointDef.motorSpeed = .5f; wheeljointDef.enableMotor = true; wheeljointDef.maxMotorTorque = 100000f; // Joint joint = // wheeljointDef.bodyA.getWorld().createJoint(wheeljointDef); world.createJoint(wheeljointDef); circleShape.dispose(); }
/* * (non-Javadoc) * * @see * com.rougeprogrammers.shootthecat.objects.models.Model#createBody(float, * float) */ @Override protected Body createBody(float x, float y) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.KinematicBody; bodyDef.position.set(x * Constants.WORLD_TO_BOX, y * Constants.WORLD_TO_BOX); Body body = gameStage.getWorld().createBody(bodyDef); PolygonShape shape = new PolygonShape(); shape.setAsBox( getWidth() / 2 * Constants.WORLD_TO_BOX, getHeight() / 2 * Constants.WORLD_TO_BOX); body.createFixture(shape, Obstacle.DENSITY); shape.dispose(); body.setUserData(new ObjectType(Type.THORN, index)); return body; }
public static Body createMovingPlatform( World world, float x, float y, float width, float height, float restituition) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.KinematicBody; bodyDef.position.set(new Vector2(x, y)); Body body = world.createBody(bodyDef); PolygonShape shape = new PolygonShape(); shape.setAsBox(width / 2, height / 2); Fixture fixture = body.createFixture(shape, Constants.GROUND_DENSITY); fixture.setRestitution(restituition); body.setUserData(new GroundUserData()); shape.dispose(); return body; }
private Body addPortalBody(World world, String portalName, Vector2 portalPosition) { final BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; final Body body = world.createBody(bodyDef); body.setTransform(portalPosition.x + offset.x, portalPosition.y + offset.y, 0); final PolygonShape shape = new PolygonShape(); shape.setAsBox(0.1f, 0.1f); final FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; fixtureDef.isSensor = true; final Fixture fixture = body.createFixture(fixtureDef); body.setUserData(portalName); fixture.setUserData("portal"); shape.dispose(); return body; }
/** * attaches this object to a real world * * @param world */ public void attachTo(World world) { // Create a body from the defintion and add it to the world body = world.createBody(def); if (userData != null) { userData.attachPhysicalObject(this); } fixture = body.createFixture(fixtureDef); // fixtureDef.shape.dispose(); body.setUserData(userData); if (attrs.containsKey("mass")) { changeMass(Float.parseFloat(attrs.get("mass"))); } body.setAwake(true); }
private void createGoal(float x, float y) { BodyDef bdef = new BodyDef(); FixtureDef fdef = new FixtureDef(); PolygonShape shape = new PolygonShape(); // create gravBot bdef.position.set(x / PPM, y / PPM); bdef.type = BodyType.StaticBody; Body body = gameWorldPhysics.createBody(bdef); shape.setAsBox(16 / PPM, 16 / PPM); fdef.shape = shape; body.createFixture(fdef); body.setUserData("Goal"); goal = new Goal(body); }
public void remove(Array<RobotNinjas> robotNinjases) { if (body.getUserData() == Constants.deadID) { robotNinjases.removeValue(this, true); robotNinjasPool.free(this); } if (body.getPosition().x < 0 - width) { body.setUserData(Constants.deadID); if (!dead) { Constants.currentScoreValue++; Constants.standardVelocity.x += Constants.globalAcceleration; Constants.ninjaVelocity.x += Constants.globalAcceleration; Constants.globalAcceleration -= Constants.globalAccelerationDecline; } dead = true; } }
private void createGravBot() { BodyDef bdef = new BodyDef(); FixtureDef fdef = new FixtureDef(); PolygonShape shape = new PolygonShape(); // create gravBot bdef.position.set(0 / PPM, 0 / PPM); bdef.type = BodyType.DynamicBody; Body body = gameWorldPhysics.createBody(bdef); shape.setAsBox(16 / PPM, 16 / PPM); fdef.shape = shape; body.createFixture(fdef); body.setUserData("Gravbot"); // create GravBot gravBot = new GravBot(body); }
private void createPlayer() { BodyDef bdef = new BodyDef(); PolygonShape shape = new PolygonShape(); FixtureDef fdef = new FixtureDef(); fdef.shape = shape; bdef.position.set(160 / PPM, 200 / PPM); bdef.type = BodyType.DynamicBody; Body body = world.createBody(bdef); shape.setAsBox(13 / PPM, 13 / PPM); fdef.filter.categoryBits = (B2DVars.BIT_PLAYER); fdef.filter.maskBits = B2DVars.BIT_BLOCKS; body.createFixture(fdef).setUserData("player"); shape.setAsBox(13 / PPM, 13 / PPM, new Vector2(0, -13 / PPM), 0); fdef.shape = shape; fdef.filter.categoryBits = (B2DVars.BIT_PLAYER); fdef.filter.maskBits = B2DVars.BIT_BLOCKS | B2DVars.BIT_COINS; fdef.isSensor = true; body.createFixture(fdef).setUserData("foot"); player = new Player(body); body.setUserData(player); }
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()); }
public static Body createBullet(World world, GunShot gunshot, Vector2 origin) { Vector2 position = origin.cpy().add(gunshot.getDir().cpy().scl(.4f)), velocity = gunshot.getDir().cpy().scl(gunshot.getGun().getMuzzleVelocity()); float angle = (float) Math.atan2(gunshot.getDir().y, gunshot.getDir().x); Body body = com.blastedstudios.gdxworld.physics.PhysicsHelper.createCircle( world, BULLET_RADIUS, position, angle, BodyType.DynamicBody, .2f, .5f, BULLET_DENSITY, gunshot.getBeing().getMask(), gunshot.getBeing().getCat(), (short) 0); body.setLinearVelocity(velocity); body.setBullet(true); body.setUserData(gunshot); return body; }
public static Body createRunner(World world, float x, float y, float width, float height) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; bodyDef.position.set(new Vector2(x, y)); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.5f, new Vector2(2, 2), 45); Body body = world.createBody(bodyDef); body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE); Fixture fixture = body.createFixture(shape, Constants.RUNNER_DENSITY); body.setFixedRotation(true); fixture.setFriction(2f); body.resetMassData(); body.setUserData(new RunnerUserData()); shape.dispose(); body.setBullet(true); return body; }
private Body createBody(float x, float y, float width, float height, boolean sensor) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.KinematicBody; bodyDef.position.set(new Vector2(x, y)); bodyDef.allowSleep = true; PolygonShape shape = new PolygonShape(); shape.setAsBox(width / 2, height / 2, new Vector2(0, 0), 0); Body _body = WorldUtils.world.createBody(bodyDef); Fixture fixture = _body.createFixture(shape, 1.0f); fixture.setFriction(0); fixture.setSensor(sensor); if (!sensor) { fixture.setUserData(Constants.POTION_FIXTURE); } else { fixture.setUserData(Constants.NOT_COLLIDER_FIXTURE); } Filter filter = new Filter(); filter.categoryBits = Constants.COLLISION_CREATURE; filter.maskBits = Constants.COLLISION_GROUND + Constants.COLLISION_CREATURE + Constants.COLLISION_FIELD; fixture.setFilterData(filter); _body.setUserData(this); return _body; }
public Entity(Engine engine, PhysicsWorld physicsWorld, Sprite sprite, Body body) { this.engine = engine; this.physicsWorld = physicsWorld; body.setUserData(this); bodySpriteConnector = new PhysicsConnector(sprite, body); }
@Override public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) { final VertexBufferObjectManager vertexBufferObjectManager = activity.getVertexBufferObjectManager(); // FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(0.0f, // 0.0f, 0.0f); // centerText.detachSelf(); if (linesDrawn <= 150) { if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) { isDrawing = true; i = 0; } if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) { isDrawing = false; } if (isDrawing = true) { rec[i] = new Rectangle( pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), 1, 1, vertexBufferObjectManager); if (i != 0) { Line l = new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null); Line bodyLine = new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null); Body lb; Line line = new Line(rec[i - 1].getX(), rec[i - 1].getY(), rec[i].getX(), rec[i].getY(), null); lb = PhysicsFactory.createLineBody(mPhysicsWorld, bodyLine, wallFixtureDef); lb.setUserData("line"); line.setLineWidth(5); bodyLine.setVisible(false); line.setColor(Color.WHITE); bodyLine.setColor(Color.WHITE); attachChild(bodyLine); attachChild(line); linesDrawn++; rectangle(linesDrawn); } linesDrawn++; i++; // final Text elapsedText = new Text(500, 360, activity.mFont, "Seconds elapsed:", "Seconds // elapsed: XXXXX".length(), activity.getVertexBufferObjectManager()); // final Text fpsText = new Text(500, 400, activity.mFont, "FPS:", "FPS: XXXXX".length(), // activity.getVertexBufferObjectManager()); // attachChild(elapsedText); // attachChild(fpsText); // final FPSCounter fpsCounter = new FPSCounter(); // registerUpdateHandler(new TimerHandler(1 / 20.0f, true, new ITimerCallback() { // @Override // public void onTimePassed(final TimerHandler pTimerHandler) { // elapsedText.setText("Globs Used: " + linesDrawn); // fpsText.setText("Globs Left: " + ( 150 - linesDrawn)); // } // })); // } } } return true; }
public BLevel4() { setBackground(new Background(0, 0, 0)); setOnSceneTouchListener(this); activity = World2Activity.getSharedInstance(); Camera mCamera = activity.mCamera; W1LSMenu.bPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_THE_ISLAND), false); mPhysicsWorld = W1LSMenu.bPhysicsWorld; menu = (activity.createMenuScene()); Sprite bg = new Sprite(0, 0, activity.menuBgTexture, activity.getVertexBufferObjectManager()); setBackground(new SpriteBackground(bg)); // PhysicsWorld bPhysicsWorld = new PhysicsWorld(new Vector2(0, // SensorManager.GRAVITY_THE_ISLAND), false); final VertexBufferObjectManager vertexBufferObjectManager = activity.getVertexBufferObjectManager(); final Rectangle ground = new Rectangle(0, mCamera.getHeight() - 2, mCamera.getWidth(), 2, vertexBufferObjectManager); final Rectangle roof = new Rectangle(0, 0, mCamera.getWidth(), 2, vertexBufferObjectManager); final Rectangle left = new Rectangle(0, 0, 2, mCamera.getHeight(), vertexBufferObjectManager); final Rectangle right = new Rectangle(mCamera.getWidth() - 2, 0, 2, mCamera.getHeight(), vertexBufferObjectManager); final Rectangle reset = new Rectangle(0, 0, 200, 20, vertexBufferObjectManager); ground.setColor(Color.RED); roof.setColor(Color.RED); right.setColor(Color.RED); // final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f); Body Ground = PhysicsFactory.createBoxBody(mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef); Body Roof = PhysicsFactory.createBoxBody(mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef); Body Left = PhysicsFactory.createBoxBody(mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef); Body Right = PhysicsFactory.createBoxBody(mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef); Body Reset = PhysicsFactory.createBoxBody(mPhysicsWorld, reset, BodyType.StaticBody, wallFixtureDef); Ground.setUserData("ground"); Roof.setUserData("ground"); Left.setUserData("wall"); Right.setUserData("ground"); Reset.setUserData("tw"); attachChild(ground); attachChild(roof); attachChild(left); attachChild(right); activity.menu = 3; x = 3; final DelayModifier dMod = new DelayModifier( 2, new IEntityModifierListener() { @Override public void onModifierStarted(IModifier arg0, IEntity arg1) {} public void onModifierFinished(IModifier arg0, IEntity arg1) { destroy(0); } }); final Text elapsedText = new Text( 600, 10, activity.mFont, "Score:0123456789", activity.getVertexBufferObjectManager()); registerUpdateHandler( new TimerHandler( 1 / 10.0f, true, new ITimerCallback() { @Override public void onTimePassed(final TimerHandler pTimerHandler) { score = (score - Math.round(activity.mCurrentScene.getSecondsElapsedTotal())); elapsedText.setText("Time :" + score); } })); attachChild(elapsedText); final Rectangle bL = new Rectangle(350, 365, 50, 20, vertexBufferObjectManager); final Rectangle bB = new Rectangle(325, 355, 50, 10, vertexBufferObjectManager); final Rectangle bR = new Rectangle(375, 355, 50, 10, vertexBufferObjectManager); final Rectangle finish = new Rectangle(350, 360, 50, 20, vertexBufferObjectManager); bR.setRotation(90); bB.setRotation(90); final Rectangle gate = new Rectangle(325, 330, 100, 10, vertexBufferObjectManager); // gate.setRotation(90); final Body Gate = PhysicsFactory.createBoxBody(mPhysicsWorld, gate, BodyType.StaticBody, wallFixtureDef); Gate.setUserData("gate"); gate.setColor(Color.GREEN); attachChild(gate); final Rectangle power = new Rectangle(650, 250, 15, 15, vertexBufferObjectManager); final Body Power = PhysicsFactory.createBoxBody(mPhysicsWorld, power, BodyType.StaticBody, wallFixtureDef); power.setColor(Color.BLUE); Power.setUserData("power"); attachChild(power); one = new Rectangle(765, 290, 25, 38, vertexBufferObjectManager); two = new Rectangle(765, 330, 25, 38, vertexBufferObjectManager); three = new Rectangle(765, 370, 25, 38, vertexBufferObjectManager); four = new Rectangle(765, 410, 25, 38, vertexBufferObjectManager); five = new Rectangle(765, 445, 25, 38, vertexBufferObjectManager); one.setColor(Color.GREEN); two.setColor(Color.GREEN); three.setColor(Color.YELLOW); four.setColor(Color.YELLOW); five.setColor(Color.RED); attachChild(one); attachChild(two); attachChild(three); attachChild(four); attachChild(five); Body bod = PhysicsFactory.createBoxBody(mPhysicsWorld, bL, BodyType.StaticBody, wallFixtureDef); Body lbod = PhysicsFactory.createBoxBody(mPhysicsWorld, bR, BodyType.StaticBody, wallFixtureDef); Body rbod = PhysicsFactory.createBoxBody(mPhysicsWorld, bB, BodyType.StaticBody, wallFixtureDef); Body Finish = PhysicsFactory.createBoxBody(mPhysicsWorld, finish, BodyType.StaticBody, wallFixtureDef); Rectangle help = new Rectangle(0, 150, 300, 10, vertexBufferObjectManager); Body Help = PhysicsFactory.createBoxBody(mPhysicsWorld, help, BodyType.StaticBody, wallFixtureDef); Rectangle block = new Rectangle(290, 100, 250, 10, vertexBufferObjectManager); block.setRotation(-25); Body Block = PhysicsFactory.createBoxBody(mPhysicsWorld, block, BodyType.StaticBody, wallFixtureDef); Block.setUserData("block"); bod.setUserData("body"); rbod.setUserData("body"); lbod.setUserData("body"); Finish.setUserData("finish"); Help.setUserData("Help"); bL.setColor(Color.WHITE); block.setColor(Color.WHITE); bR.setColor(Color.WHITE); bB.setColor(Color.WHITE); help.setColor(Color.WHITE); finish.setColor(0, 0, 1); finish.setVisible(false); attachChild(block); attachChild(bL); attachChild(bR); attachChild(bB); attachChild(help); attachChild(finish); // final ButtonSprite button = new ButtonSprite(5, 5, activity.mMenuResetTextureRegion, // vertexBufferObjectManager); // attachChild(button); // FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(0.0f, // 0.0f, 0.0f); FixtureDef FIXTURE_DEF2 = PhysicsFactory.createFixtureDef(1, .9f, 0.5f); final int blue = activity.faceSelected(1); if (blue == 1) face = new AnimatedSprite(05, 50, activity.redFace, activity.getVertexBufferObjectManager()); else if (blue == 2) face = new AnimatedSprite(05, 50, activity.blueFace, activity.getVertexBufferObjectManager()); else if (blue == 3) face = new AnimatedSprite(05, 50, activity.yellowFace, activity.getVertexBufferObjectManager()); else if (blue == 4) { activity.grav = 5; face = new AnimatedSprite(05, 50, activity.hairFace, activity.getVertexBufferObjectManager()); } else if (blue == 5) face = new AnimatedSprite(05, 50, activity.djFace, activity.getVertexBufferObjectManager()); else if (blue == 6) { activity.grav = 2; face = new AnimatedSprite(05, 50, activity.jetFace, activity.getVertexBufferObjectManager()); } else if (blue == 7) face = new AnimatedSprite(05, 50, activity.slowFace, activity.getVertexBufferObjectManager()); else if (blue == 8) face = new AnimatedSprite(05, 50, activity.fastFace, activity.getVertexBufferObjectManager()); else face = new AnimatedSprite(05, 50, activity.redFace, activity.getVertexBufferObjectManager()); if (blue == 5) body = PhysicsFactory.createCircleBody(mPhysicsWorld, face, BodyType.DynamicBody, FIXTURE_DEF2); else if (blue == 6) body = PhysicsFactory.createBoxBody(mPhysicsWorld, face, BodyType.DynamicBody, FIXTURE_DEF); else body = PhysicsFactory.createCircleBody(mPhysicsWorld, face, BodyType.DynamicBody, FIXTURE_DEF); body.setUserData("face"); face.animate(200); attachChild(face); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face, body, true, true)); registerUpdateHandler(mPhysicsWorld); Rectangle pauseBtn = new Rectangle(0, 0, 130, 130, activity.getVertexBufferObjectManager()) { @Override public boolean onAreaTouched( TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) { if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_UP) { activity.menu = 4; setChildScene(menu, false, true, true); } return true; } }; pauseBtn.setVisible(false); // pauseBtn.setColor(0,0,1); attachChild(pauseBtn); registerTouchArea(pauseBtn); final Text resetText = new Text( 10, 10, activity.mFont, "Pause", new TextOptions(HorizontalAlign.CENTER), vertexBufferObjectManager); attachChild(resetText); mPhysicsWorld.setContactListener( new ContactListener() { @Override public void beginContact(final Contact contact) { final Fixture A = contact.getFixtureA(); final Fixture B = contact.getFixtureB(); final Body bodyA = A.getBody(); final Body bodyB = B.getBody(); String abe = bodyA.getUserData().toString(); String be = bodyB.getUserData().toString(); if (abe == "power" || be == "power") { power.setVisible(false); Power.setActive(false); Gate.setActive(false); gate.setColor(Color.TRANSPARENT); } else if (abe == "ground" || be == "ground") { activity.gameToast("You ran into a fire wall"); destroy(1); } else if (abe == "finish" || be == "finish") { bB.setColor(0, 0, 1); bL.setColor(0, 0, 1); bR.setColor(0, 0, 1); registerEntityModifier(dMod); } else if (abe == "ground" || be == "ground") { activity.gameToast("You fell into a pit try again"); destroy(1); } } @Override public void endContact(final Contact pContact) { /* Do something... */ } @Override public void preSolve(Contact contact, Manifold oldManifold) {} @Override public void postSolve(Contact contact, ContactImpulse impulse) { // TODO Auto-generated method stub } }); }
public Level21() { setBackground(new Background(0, 0, 0)); setOnSceneTouchListener(this); activity = World1Activity.getSharedInstance(); Camera mCamera = activity.mCamera; Level1.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false); mPhysicsWorld = Level1.mPhysicsWorld; Sprite bg = new Sprite(0, 0, activity.menuBgTexture6, activity.getVertexBufferObjectManager()); setBackground(new SpriteBackground(bg)); // activity.gameToast("The bugs have morphed and can travel through lines"); // PhysicsWorld bPhysicsWorld = new PhysicsWorld(new Vector2(0, // SensorManager.GRAVITY_THE_ISLAND), false); final VertexBufferObjectManager vertexBufferObjectManager = activity.getVertexBufferObjectManager(); final Rectangle ground = new Rectangle(0, mCamera.getHeight() - 2, mCamera.getWidth(), 2, vertexBufferObjectManager); final Rectangle roof = new Rectangle(0, 0, mCamera.getWidth(), 2, vertexBufferObjectManager); final Rectangle left = new Rectangle(0, 0, 2, mCamera.getHeight(), vertexBufferObjectManager); final Rectangle right = new Rectangle(mCamera.getWidth() - 2, 0, 2, mCamera.getHeight(), vertexBufferObjectManager); final Rectangle reset = new Rectangle(0, 0, 200, 20, vertexBufferObjectManager); ground.setColor(0, 255, 255); // right.setColor(Color.RED); // final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f, false, // CATEGORYBIT_WALL, MASKBITS_WALL, (short)0); Body Ground = PhysicsFactory.createBoxBody(mPhysicsWorld, ground, BodyType.StaticBody, WALL_FIXTURE_DEF); Body Roof = PhysicsFactory.createBoxBody(mPhysicsWorld, roof, BodyType.StaticBody, WALL_FIXTURE_DEF); Body Left = PhysicsFactory.createBoxBody(mPhysicsWorld, left, BodyType.StaticBody, WALL_FIXTURE_DEF); Body Right = PhysicsFactory.createBoxBody(mPhysicsWorld, right, BodyType.StaticBody, WALL_FIXTURE_DEF); Body Reset = PhysicsFactory.createBoxBody(mPhysicsWorld, reset, BodyType.StaticBody, WALL_FIXTURE_DEF); Ground.setUserData("ground"); Roof.setUserData("roof"); Left.setUserData("left"); Right.setUserData("right"); Reset.setUserData("tw"); attachChild(ground); attachChild(roof); attachChild(left); attachChild(right); Rectangle help = new Rectangle(50, 220, 250, 10, vertexBufferObjectManager); Body Help = PhysicsFactory.createBoxBody(mPhysicsWorld, help, BodyType.StaticBody, WALL_FIXTURE_DEF); final Rectangle help2 = new Rectangle(0, 220, 50, 10, vertexBufferObjectManager); final Body Help2 = PhysicsFactory.createBoxBody(mPhysicsWorld, help2, BodyType.StaticBody, WALL_FIXTURE_DEF); Help2.setUserData("help"); help2.setColor(Color.WHITE); attachChild(help2); Rectangle block = new Rectangle(180, 220, 250, 10, vertexBufferObjectManager); block.setRotation(90); Body Block = PhysicsFactory.createBoxBody(mPhysicsWorld, block, BodyType.StaticBody, WALL_FIXTURE_DEF); Block.setUserData("block"); Help.setUserData("help"); block.setColor(Color.WHITE); help.setColor(Color.WHITE); attachChild(help); attachChild(block); // final FixtureDef objectFixtureDef2 = PhysicsFactory.createFixtureDef(10, 0.2f, 0.5f,false, // CATEGORYBIT_WALL, MASKBITS_WALL, (short)0); final Text elapsedText = new Text( 600, 10, activity.mFont3, "Score:0123456789", activity.getVertexBufferObjectManager()); registerUpdateHandler( new TimerHandler( 1 / 10f, true, new ITimerCallback() { @Override public void onTimePassed(final TimerHandler pTimerHandler) { if (score > 2501) { score = (score - Math.round(activity.mCurrentScene.getSecondsElapsedTotal())); elapsedText.setText("Score:" + score); } else { score = 2500; elapsedText.setText("Score:" + score); } } })); attachChild(elapsedText); final DelayModifier dMod = new DelayModifier( 2, new IEntityModifierListener() { @Override public void onModifierStarted(IModifier arg0, IEntity arg1) {} public void onModifierFinished(IModifier arg0, IEntity arg1) { destroy(0); } }); final Rectangle bL = new Rectangle(150, 365, 50, 20, vertexBufferObjectManager); final Rectangle bB = new Rectangle(125, 355, 50, 10, vertexBufferObjectManager); final Rectangle bR = new Rectangle(175, 355, 50, 10, vertexBufferObjectManager); final Rectangle finish = new Rectangle(150, 360, 50, 20, vertexBufferObjectManager); bR.setRotation(90); bB.setRotation(90); one = new Rectangle(765, 290, 25, 35, vertexBufferObjectManager); two = new Rectangle(765, 330, 25, 35, vertexBufferObjectManager); three = new Rectangle(765, 370, 25, 35, vertexBufferObjectManager); four = new Rectangle(765, 410, 25, 35, vertexBufferObjectManager); five = new Rectangle(765, 450, 25, 35, vertexBufferObjectManager); one.setColor(Color.GREEN); two.setColor(Color.GREEN); three.setColor(Color.YELLOW); four.setColor(Color.YELLOW); five.setColor(Color.RED); attachChild(one); attachChild(two); attachChild(three); attachChild(four); attachChild(five); Rectangle laser = new Rectangle(350, 200, 20, 20, vertexBufferObjectManager); laser.setColor(Color.RED); attachChild(laser); final Line lase = new Line(350, 205, 805, 200, 5, vertexBufferObjectManager); final Body Lase = PhysicsFactory.createLineBody(mPhysicsWorld, lase, WALL_FIXTURE_DEF); Lase.setUserData("laser"); lase.setColor(Color.RED); lase.setVisible(false); Lase.setActive(false); attachChild(lase); registerUpdateHandler( new IUpdateHandler() { @Override public void onUpdate(float pSecondsElapsed) { x = x + 1; if (x == 50) { lase.setVisible(true); Lase.setActive(true); } else if (x == 100) { lase.setVisible(false); Lase.setActive(false); x = 0; } } @Override public void reset() { // TODO Auto-generated method stub } }); final Rectangle powerup = new Rectangle(665, 050, 15, 15, vertexBufferObjectManager); powerup.setColor(Color.RED); final Body power = PhysicsFactory.createBoxBody(mPhysicsWorld, powerup, BodyType.StaticBody, WALL_FIXTURE_DEF); powerup.setVisible(true); power.setActive(true); Body bod = PhysicsFactory.createBoxBody(mPhysicsWorld, bL, BodyType.StaticBody, WALL_FIXTURE_DEF); Body lbod = PhysicsFactory.createBoxBody(mPhysicsWorld, bR, BodyType.StaticBody, WALL_FIXTURE_DEF); Body rbod = PhysicsFactory.createBoxBody(mPhysicsWorld, bB, BodyType.StaticBody, WALL_FIXTURE_DEF); Body Finish = PhysicsFactory.createBoxBody( mPhysicsWorld, finish, BodyType.StaticBody, CIRCLE_FIXTURE_DEF); // Rectangle help = new Rectangle(0, 220, 300, 10, vertexBufferObjectManager); // Body Help = PhysicsFactory.createBoxBody(mPhysicsWorld, help, BodyType.StaticBody, // wallFixtureDef); // Rectangle block = new Rectangle(180, 220, 250, 10, vertexBufferObjectManager); // block.setRotation(90); // Body Block = PhysicsFactory.createBoxBody(mPhysicsWorld, block, BodyType.StaticBody, // wallFixtureDef); // Block.setUserData("block"); bod.setUserData("body"); rbod.setUserData("body"); lbod.setUserData("body"); Finish.setUserData("finish"); power.setUserData("power"); // Help.setUserData("Help"); bL.setColor(Color.WHITE); // block.setColor(255, 0, 0); bR.setColor(Color.WHITE); bB.setColor(Color.WHITE); // help.setColor(255, 0, 0); finish.setColor(0, 0, 1); finish.setVisible(false); // attachChild(block); attachChild(bL); attachChild(bR); attachChild(bB); // attachChild(help); attachChild(finish); attachChild(powerup); // centerText = new Text(320, 40, activity.mFont, "IMPORTANT!!! Keep an eye \n out for powerups // \n to help you through \n the level \n (touch anywhere to make \n this message dissapear)", // new TextOptions(HorizontalAlign.CENTER), vertexBufferObjectManager); // attachChild(centerText); // final ButtonSprite button = new ButtonSprite(5, 5, activity.mMenuResetTextureRegion, // vertexBufferObjectManager); // attachChild(button); final int blue = activity.faceSelected(1); if (blue == 1) face = new AnimatedSprite(05, 150, activity.redFace, activity.getVertexBufferObjectManager()); else if (blue == 2) face = new AnimatedSprite(05, 150, activity.blueFace, activity.getVertexBufferObjectManager()); else if (blue == 3) face = new AnimatedSprite(05, 150, activity.yellowFace, activity.getVertexBufferObjectManager()); else if (blue == 4) face = new AnimatedSprite(05, 150, activity.hairFace, activity.getVertexBufferObjectManager()); else if (blue == 5) face = new AnimatedSprite(05, 150, activity.djFace, activity.getVertexBufferObjectManager()); else if (blue == 6) face = new AnimatedSprite(05, 150, activity.jetFace, activity.getVertexBufferObjectManager()); else if (blue == 7) face = new AnimatedSprite(05, 150, activity.slowFace, activity.getVertexBufferObjectManager()); else if (blue == 8) face = new AnimatedSprite(05, 150, activity.fastFace, activity.getVertexBufferObjectManager()); else face = new AnimatedSprite(05, 150, activity.redFace, activity.getVertexBufferObjectManager()); body = PhysicsFactory.createCircleBody( mPhysicsWorld, face, BodyType.DynamicBody, FACE_FIXTURE_DEF); body.setUserData("face"); face.animate(200); attachChild(face); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face, body, true, true)); registerUpdateHandler(mPhysicsWorld); Random r = new Random(); int i = r.nextInt(4 - 1) + 1; if (i == 1) { enemy = new Sprite(400, 200, activity.bug2, activity.getVertexBufferObjectManager()); enemy2 = new Sprite(400, 200, activity.bug3, activity.getVertexBufferObjectManager()); enemy3 = new Sprite(400, 200, activity.bug1, activity.getVertexBufferObjectManager()); } else if (i == 2) { enemy = new Sprite(400, 200, activity.bug2, activity.getVertexBufferObjectManager()); enemy2 = new Sprite(400, 200, activity.bug1, activity.getVertexBufferObjectManager()); enemy3 = new Sprite(400, 200, activity.bug2, activity.getVertexBufferObjectManager()); } else if (i == 3) { enemy = new Sprite(400, 200, activity.bug3, activity.getVertexBufferObjectManager()); enemy2 = new Sprite(400, 200, activity.bug2, activity.getVertexBufferObjectManager()); enemy3 = new Sprite(400, 200, activity.bug3, activity.getVertexBufferObjectManager()); } else enemy = new Sprite(400, 200, activity.bug1, activity.getVertexBufferObjectManager()); enemy2 = new Sprite(400, 200, activity.bug2, activity.getVertexBufferObjectManager()); enemy3 = new Sprite(400, 200, activity.bug3, activity.getVertexBufferObjectManager()); // final Rectangle enemy = new Rectangle(600,400, 15, 15, // activity.getVertexBufferObjectManager()); Enemy = PhysicsFactory.createBoxBody( mPhysicsWorld, enemy, BodyType.DynamicBody, CIRCLE_FIXTURE_DEF); Enemy.setUserData("enemy"); attachChild(enemy); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(enemy, Enemy, true, true)); // final Rectangle enemy2 = new Rectangle(500,400, 15, 15, // activity.getVertexBufferObjectManager()); Enemy2 = PhysicsFactory.createBoxBody( mPhysicsWorld, enemy2, BodyType.DynamicBody, CIRCLE_FIXTURE_DEF); Enemy2.setUserData("enemy"); attachChild(enemy2); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(enemy2, Enemy2, true, true)); // final Rectangle enemy3 = new Rectangle(400,400, 15, 15, // activity.getVertexBufferObjectManager()); Enemy3 = PhysicsFactory.createBoxBody( mPhysicsWorld, enemy3, BodyType.DynamicBody, CIRCLE_FIXTURE_DEF); Enemy3.setUserData("enemy"); attachChild(enemy3); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(enemy3, Enemy3, true, true)); // Enemy.setLinearVelocity(10, -10); /*final AnimatedSprite windArea = new AnimatedSprite(200, 0, 50, 500, activity.mBoxFaceTextureRegion, activity.getVertexBufferObjectManager()) { @Override protected void onManagedUpdate(float pSecondsElapsed) { if (face.collidesWith(this)) { body.applyLinearImpulse(new Vector2(0, -10f), body.getWorldCenter()); } }; }; // windArea.setVisible(false); attachChild(windArea); */ Rectangle pauseBtn = new Rectangle(10, 10, 100, 100, activity.getVertexBufferObjectManager()) { @Override public boolean onAreaTouched( TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) { if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_UP) { Scene menu = (activity.createMenuScene()); activity.menu = 21; setChildScene(menu, false, true, true); } return true; } }; pauseBtn.setVisible(false); // pauseBtn.setColor(0,0,1); attachChild(pauseBtn); registerTouchArea(pauseBtn); final Text resetText = new Text( 10, 10, activity.mFont3, "Pause", new TextOptions(HorizontalAlign.CENTER), vertexBufferObjectManager); attachChild(resetText); mPhysicsWorld.setContactListener( new ContactListener() { @Override public void beginContact(final Contact contact) { final Fixture A = contact.getFixtureA(); final Fixture B = contact.getFixtureB(); final Body bodyA = A.getBody(); final Body bodyB = B.getBody(); String abe = bodyA.getUserData().toString(); String be = bodyB.getUserData().toString(); if (abe == "left" || be == "left") { Enemy.applyLinearImpulse(new Vector2(1, 0.5f), body.getWorldCenter()); Enemy2.applyLinearImpulse(new Vector2(1, 0.5f), body.getWorldCenter()); Enemy3.applyLinearImpulse(new Vector2(1, 0.5f), body.getWorldCenter()); } else if (abe == "power" && be != "enemy") { l = -5; activity.gameToast("Nice super shield active. Resetting line...."); linesDrawn = 0; rectangle(linesDrawn); powerup.setVisible(false); power.setActive(false); help2.setVisible(false); Help2.setActive(false); } if (abe == "finish" && be == "face") { bB.setColor(0, 0, 1); bL.setColor(0, 0, 1); bR.setColor(0, 0, 1); // lase.setVisible(false); // Lase.setActive(false); // x = 500; registerEntityModifier(dMod); } if (abe == "laser" && be == "face") { if (l >= 0) { l = l + 1; activity.gameToast("Shield only blocks one laser hit-Hit #" + l); if (l == 2) destroy(1); } else if (l < 0) { activity.gameToast("Super Shield active"); l = l + 1; } } else if (abe == "roof" || be == "roof") { Enemy.applyLinearImpulse(new Vector2(0.5f, 1f), body.getWorldCenter()); Enemy2.applyLinearImpulse(new Vector2(0.5f, 1f), body.getWorldCenter()); Enemy3.applyLinearImpulse(new Vector2(0.5f, 1f), body.getWorldCenter()); } else if (abe == "right" || be == "right") { Enemy.applyLinearImpulse(new Vector2(-1, 0.5f), body.getWorldCenter()); Enemy2.applyLinearImpulse(new Vector2(-1, 0.5f), body.getWorldCenter()); Enemy3.applyLinearImpulse(new Vector2(-1, 0.5f), body.getWorldCenter()); } else if (abe == "ground" || be == "ground") { Enemy.applyLinearImpulse(new Vector2(0.5f, -2f), body.getWorldCenter()); Enemy2.applyLinearImpulse(new Vector2(0.5f, -2f), body.getWorldCenter()); Enemy3.applyLinearImpulse(new Vector2(0.5f, -2f), body.getWorldCenter()); } else if (abe == "enemy" && be == "face") { if (l >= 0) { l = l + 1; activity.gameToast("Hit #" + l); if (l == 3) destroy(1); } else if (l < 0) { if (dead == 0) { enemy.setVisible(false); Enemy.setActive(false); dead = dead + 1; l = l + 1; activity.gameToast("Enemy eleminated"); } else if (dead == 1) { enemy2.setVisible(false); Enemy2.setActive(false); l = l + 1; dead = dead + 1; activity.gameToast("Enemy 2 eleminated"); } else if (l == -3) { enemy3.setVisible(false); Enemy3.setActive(false); l = l + 1; dead = dead + 1; activity.gameToast("Enemy 3 eleminated"); } else { l = l + 1; } } } } @Override public void endContact(final Contact pContact) {} @Override public void preSolve(Contact contact, Manifold oldManifold) {} @Override public void postSolve(Contact contact, ContactImpulse impulse) {} }); }
private void createElevetors() { // TODO Auto-generated method stub BodyDef bodyDef = new BodyDef(); for (int i = 0; i < XMLReader.ropes.size; i++) { // if(XMLReader.ropes.get(i).pathType == "path") Helper.println("pathtype" + XMLReader.ropes.get(i).pathType); XMLReader.ropes.get(i).pathType = XMLReader.ropes.get(i).pathType.toLowerCase(); // if(true) if (!XMLReader.ropes.get(i).pathType.contains("lift")) { Vector2 vs[] = new Vector2[XMLReader.ropes.get(i).getNodes().size()]; // for (int vertexCount // =0;vertexCount<XMLReader.ropes.get(i).getNodes().size();vertexCount++) // { // vs[vertexCount] = new Vector2(); // } for (int vertexCount = 0; vertexCount < XMLReader.ropes.get(i).getNodes().size(); vertexCount++) { if (XMLReader.ropes.get(i).getNodes().get(vertexCount).getY() < fallY) fallY = XMLReader.ropes.get(i).getNodes().get(vertexCount).getY(); Helper.println("fallY::" + fallY); // Helper.println("vertex count::"+ vertexCount); // vs[vertexCount] = new Vector2(vs[vertexCount-1].x + // elevetorWidth, vs[vertexCount-1].y * 1.10f); // Helper.println("vertex position in // pixel:::"+PhysicsHelper.ConvertToWorld((vs[vertexCount-1].x) // )); // Helper.println("value of i:::"+i+"value of certexCpunt::"+vertexCount); try { // Helper.println("xml reader given rope no::::;"+XMLReader.ropes.get(i)+"xml reader // given rope nodes // ate::::;"+XMLReader.ropes.get(i).getNodes().get(vertexCount).getX()); vs[vertexCount] = new Vector2( PhysicsHelper.ConvertToBox( XMLReader.ropes.get(i).getNodes().get(vertexCount).getX()), PhysicsHelper.ConvertToBox( XMLReader.ropes.get(i).getNodes().get(vertexCount).getY())); // Helper.println("rope no:"+i+"rope node no:"+vertexCount+"rope node // position"+PhysicsHelper.ConvertToWorld(vs[vertexCount].x)+"rope node // position"+PhysicsHelper.ConvertToWorld(vs[vertexCount].y)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } ChainShape chain = new ChainShape(); // chain.setPrevVertex(new Vector2(vs[0].x - elevetorWidth, // vs[0].y)); // // chain.setNextVertex(new Vector2(vs[vs.length-1].x + // elevetorWidth, vs[vs.length-1].y * 1.05f)); chain.createChain(vs); // chain.setRadius(.625f); FixtureDef chainShepDef = new FixtureDef(); chainShepDef.friction = friction; chainShepDef.shape = chain; chainShepDef.density = 0f; chainShepDef.restitution = 0f; // chainShepDef.filter.groupIndex = 1; chainShepDef.filter.categoryBits = 11; chainShepDef.filter.maskBits = 14 | 13 | 4 | 5 | 6 | 7 | 1; chains.add(chain); // bodyDef.position = anchor.add(new Vector2(0, i * 0.25f)); // anchor.add(new Vector2(i*.25f, 0)); // anchor.set(new Vector2(i*0f, i*0.55f)); // anchor.add(PhysicsHelper.ConvertToBox(startPoint.x), // PhysicsHelper.ConvertToBox(startPoint.y)); // anchor.add(startPoint); // calculatedAngle = Helper.getAngle(p, q); // bodyDef.angle = MathUtils.degreesToRadians*calculatedAngle; elevetor = world.createBody(bodyDef); elevetor.setUserData("elevator"); elevetor.createFixture(chainShepDef); elevetor.setType(BodyType.StaticBody); elevators.add(elevetor); Helper.println("body angle is :::" + elevetor.getAngle()); } else if (XMLReader.ropes.get(i).pathType.contains("lift")) { Vector2 vs1[] = new Vector2[XMLReader.ropes.get(i).getNodes().size()]; // for (int vertexCount // =0;vertexCount<XMLReader.ropes.get(i).getNodes().size();vertexCount++) // { // vs1[vertexCount] = new Vector2(); // } for (int vertexCount = 0; vertexCount < XMLReader.ropes.get(i).getNodes().size(); vertexCount++) { // if (XMLReader.ropes.get(i).getNodes().get(vertexCount) // .getY() < fallY) // fallY = XMLReader.ropes.get(i).getNodes() // .get(vertexCount).getY(); // Helper.println("value of i:::"+i+"value of certexCpunt::"+vertexCount); vs1[vertexCount] = new Vector2( PhysicsHelper.ConvertToBox( XMLReader.ropes.get(i).getNodes().get(vertexCount).getX()), PhysicsHelper.ConvertToBox( XMLReader.ropes.get(i).getNodes().get(vertexCount).getY())); if (vertexCount == XMLReader.ropes.get(i).getNodes().size() - 1) liftWidth = PhysicsHelper.ConvertToWorld( (float) Helper.pointToPointDistance(vs1[vertexCount], vs1[0])); Helper.println("lift width ::" + liftWidth); } boolean b = XMLReader.ropes.get(i).pathType.contains("up"); Helper.println("\n\n\n\n\n*****************************\nLift rope number :::" + i); Lift lift = new Lift( new Vector2( PhysicsHelper.ConvertToWorld(vs1[0].x), PhysicsHelper.ConvertToWorld(vs1[0].y)), null, null, null, 1, world, true, liftWidth, 7 * LevelInfo.ratioY, b); // lift.getBody().setTransform(lift.getBody().getPosition(), // (float) (lift.getBody().getAngle()+ Math.PI/2)); GlobalVars.ge.getCurrentStage().addElement(lift); // elevators.add(lift.getBody()); // elevators.add(elevetor); } // elevators.add(i, elevetor); } ((BikeLevel) GlobalVars.ge.getCurrentStage()) .setElevatorInfo(XMLReader.ropes.get(XMLReader.ropes.size - 1).getNodes().getLast(), fallY); }
@Override public void resize(int width, int height) { PPuX = width / 10; System.out.println("width = " + width); System.out.println("height = " + height); PPuY = height / 10; world = new World(new Vector2(0, -9.8f), false); renderer = new Box2DDebugRenderer(); camera = new OrthographicCamera(width, height); debugMatrix = new Matrix4(camera.combined); Circle.setBounds( Circle.getX() * PPuX, Circle.getY() * PPuY, Circle.getWidth() * PPuX, Circle.getHeight() * PPuY); Circle.setOrigin(Circle.getWidth() / 2, Circle.getHeight() / 2); BodyDef circleDef = new BodyDef(); circleDef.type = BodyType.DynamicBody; // To allign the Circle sprite with box 2d circleDef.position.set( convertToBox(Circle.getX() + Circle.getWidth() / 2), convertToBox(Circle.getY() + Circle.getHeight() / 2)); circleBody = world.createBody(circleDef); // box2d builds around 0,0 you can see -X and -Y, this makes sure that you only see X,Y debugMatrix.translate(-camera.viewportWidth / 2, -camera.viewportHeight / 2, 0); // scale the debug matrix by the scaling so everything looks normal debugMatrix.scale(BOX_TO_WORLD, BOX_TO_WORLD, 0); circleShape = new CircleShape(); circleShape.setRadius(convertToBox(Circle.getWidth() / 2)); FixtureDef circleFixture = new FixtureDef(); circleFixture.shape = circleShape; circleFixture.density = 0.4f; circleFixture.friction = 0.2f; circleFixture.restitution = 1f; circleBody.createFixture(circleFixture); circleBody.setUserData(Circle); // create ground BodyDef groundDef = new BodyDef(); groundDef.position.set(convertToBox(camera.viewportWidth / 2), 0); Body groundBody = world.createBody(groundDef); PolygonShape groundBox = new PolygonShape(); groundBox.setAsBox(convertToBox(camera.viewportWidth / 2), 0); groundBody.createFixture(groundBox, 0); BodyDef def = new BodyDef(); def.type = BodyType.DynamicBody; def.position.set(0, 0); Body box = world.createBody(def); PolygonShape poly = new PolygonShape(); poly.setAsBox(0.1f, 0.2f); playerPhysicsFixture = box.createFixture(poly, 1); poly.dispose(); CircleShape circle = new CircleShape(); circle.setRadius(0.1f); circle.setPosition(new Vector2(0, -0.2f)); playerSensorFixture = box.createFixture(circle, 0); circle.dispose(); box.setBullet(true); player = box; player.setTransform(1.0f, 2.0f, 0); player.setFixedRotation(true); }