public b2World GetWorld() { global::System.IntPtr cPtr = Box2DPINVOKE.b2Body_GetWorld__SWIG_0(swigCPtr); b2World ret = (cPtr == global::System.IntPtr.Zero) ? null : new b2World(cPtr, false); return(ret); }
} //defined in Constants.cs public StackObject(b2World world, CCPoint location, string spriteFileName, bool breaksOnGround, bool breaksFromNinja, bool hasAnimatedBreakFrames, bool damagesEnemy, float density, CreationMethod createHow, int angleChange, bool makeImmovable, int points, BreakEffect simpleScoreVisualFXType) { InitWithWorld(world, location, spriteFileName, breaksOnGround, breaksFromNinja, hasAnimatedBreakFrames, damagesEnemy, density, createHow, angleChange, makeImmovable, points, simpleScoreVisualFXType); }
protected LunarLanderEnv(bool continuous = false) : base(null, null) { this.continuous = continuous; world = new b2World(new b2Vec2(0, -10)); // useful range is -1 .. +1, but spikes can be higher ObservationSpace = new Box(float.NegativeInfinity, float.PositiveInfinity, new Shape(8)); if (continuous) { // Action is two floats [main engine, left-right engines]. // Main engine: -1..0 off, 0..+1 throttle from 50% to 100% power. Engine can't work with less than 50% power. // Left-right: -1.0..-0.5 fire left engine, +0.5..+1.0 fire right engine, -0.5..0.5 off ActionSpace = new Box(-1, 1, new Shape(2)); } else { // Nop, fire left engine, main engine, right engine ActionSpace = new Discrete(4); } Reset(); }
private void InitWithWorld(b2World world, CCPoint location, string spriteFileName) { this.theWorld = world; this.initialLocation = location; this.spriteImageName = spriteFileName; CreateGround(); }
bool enemyCantBeDamagedForShortInterval; // after damage occurs the enemy gets a moment of un-damage-abilty, which should play better ( I think) public Enemy(b2World world, CCPoint location, string spriteFileName, bool isTheRotationFixed, bool getsDamageFromGround, bool doesGetDamageFromDamageEnabledStackObjects, int breaksFromHowMuchContact, bool hasDifferentSpritesForDamage, int numberOfFramesToAnimateOnBreak, float density, CreationMethod createHow, int points, BreakEffect simpleScoreVisualFXType) { InitWithWorld(world, location, spriteFileName, isTheRotationFixed, getsDamageFromGround, doesGetDamageFromDamageEnabledStackObjects, breaksFromHowMuchContact, hasDifferentSpritesForDamage, numberOfFramesToAnimateOnBreak, density, createHow, points, simpleScoreVisualFXType); }
void InitPhysics() { var gravity = new b2Vec2(0.0f, -10.0f); world = new b2World(gravity); world.SetAllowSleeping(true); world.SetContinuousPhysics(true); var def = new b2BodyDef(); def.allowSleep = true; def.position = b2Vec2.Zero; def.type = b2BodyType.b2_staticBody; b2Body groundBody = world.CreateBody(def); groundBody.SetActive(true); b2EdgeShape groundBox = new b2EdgeShape(); groundBox.Set(b2Vec2.Zero, new b2Vec2(900, 100)); b2FixtureDef fd = new b2FixtureDef(); fd.friction = 0.3f; fd.restitution = 0.1f; fd.shape = groundBox; groundBody.CreateFixture(fd); }
public Test() { m_destructionListener = new DestructionListener(); m_debugDraw = new CCBox2dDraw("fonts/arial-12"); b2Vec2 gravity = new b2Vec2(); gravity.Set(0.0f, -10.0f); m_world = new b2World(gravity); m_bomb = null; m_textLine = 30; m_mouseJoint = null; m_pointCount = 0; m_destructionListener.test = this; m_world.SetDestructionListener(m_destructionListener); m_world.SetContactListener(this); m_world.SetDebugDraw(m_debugDraw); m_world.SetContinuousPhysics(true); m_world.SetWarmStarting(true); m_bombSpawning = false; m_stepCount = 0; b2BodyDef bodyDef = new b2BodyDef(); m_groundBody = m_world.CreateBody(bodyDef); }
void InitPhysics() { CCSize size = Layer.VisibleBoundsWorldspace.Size; var gravity = new b2Vec2(0.0f, -10.0f); world = new b2World(gravity); world.SetAllowSleeping(true); world.SetContinuousPhysics(true); var def = new b2BodyDef(); def.allowSleep = true; def.position = b2Vec2.Zero; def.type = b2BodyType.b2_staticBody; b2Body groundBody = world.CreateBody(def); groundBody.SetActive(true); b2EdgeShape groundBox = new b2EdgeShape(); groundBox.Set(b2Vec2.Zero, new b2Vec2(size.Width / PTM_RATIO, 0)); b2FixtureDef fd = new b2FixtureDef(); fd.shape = groundBox; groundBody.CreateFixture(fd); }
/// <summary> /// /// </summary> /// <param name="world"></param> public virtual void CreatePhysicsBody(b2World world, int ptm) { PtmRatio = ptm; PhysicsBodyDef = new b2BodyDef(); PhysicsBodyDef.position = InitialPosition; PhysicsBodyDef.type = BodyType; PhysicsBodyDef.fixedRotation = FixedRotation; PhysicsBodyDef.gravityScale = GravityScale; PhysicsBodyDef.linearDamping = LinearDamping; PhysicsBodyDef.bullet = Bullet; PhysicsBody = world.CreateBody(PhysicsBodyDef); PhysicsBody.Mass = Mass; PhysicsBody.ResetMassData(); var fixtureDef = new b2FixtureDef(); fixtureDef.shape = CreatePhysicsShape(); fixtureDef.density = Density; fixtureDef.friction = Friction; PhysicsBodyFixture = PhysicsBody.CreateFixture(fixtureDef); PositionX = GetMeterToPoint(InitialPosition.x); PositionY = GetMeterToPoint(InitialPosition.y); }
void InitStackWithWorld(b2World theWorld) { this.world = theWorld; if (TheLevel.SharedLevel.IS_IPAD) { stackLocationX = 1400; //base X starting point for the entire stack on the iPad (make further tweaks using the stackAdjustmentX var in the buildLevel function per level stackLocationY = 100; //base Y starting point for the entire stack on the iPad (make further tweaks using the stackAdjustmentY var in the buildLevel function per level } else { stackLocationX = 900; //base X starting point for the entire stack on the iPhone (make further tweaks using the stackAdjustmentX var in the buildLevel function per level stackLocationY = 35; //base Y starting point for the entire stack on the iPhone (make further tweaks using the stackAdjustmentY var in the buildLevel function per level } currentLevel = GameData.SharedData.Level; if (currentLevel % 2 == 0) { BuildLevel2(); } else { BuildLevel1(); } }
public static b2Body CreateDynamicBody(this b2World world, IEntityIdentifier identifier, MetreVector position) { return(world.CreateBody(new b2BodyDef { type = b2BodyType.b2_dynamicBody, position = position, userData = identifier })); }
void Awake() { _world = new b2World(new b2Vec2(gravity.x, gravity.y), allowSleep); #if UNITY_EDITOR _debugDraw = new b2DebugDraw(); _debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit); _world.SetDebugDraw(_debugDraw); #endif gameObject.BroadcastMessage("onWorldInitialized", this); }
/// <summary> /// /// </summary> /// <param name="world"></param> /// <param name="ptm"></param> public override void CreatePhysicsBody(b2World world, int ptm) { base.CreatePhysicsBody(world, ptm); SetVelocity(InitialVelocityX, InitialVelocityY); Ghost.Cleanup(); Ghost.PositionX = PositionX; Ghost.PositionY = PositionY; Ghost.DrawRect(new CCRect(0, 0, Width, Height), new CCColor4B(0, 0, 0, 50)); }
private void InitWithWorld(b2World world, CCPoint location, string baseFileName) { theWorld = world; initialLocation = location; baseImageName = baseFileName; //later we use initialLocation.x CreateNinja(); }
void InitWithWorld(b2World world, CCPoint location, string spriteFileName, bool isTheRotationFixed, bool getsDamageFromGround, bool doesGetDamageFromDamageEnabledStackObjects, int breaksFromHowMuchContact, bool hasDifferentSpritesForDamage, int numberOfFramesToAnimateOnBreak, float density, CreationMethod createHow, int points, BreakEffect simpleScoreVisualFXType) { this.theWorld = world; this.initialLocation = location; this.baseImageName = spriteFileName; this.spriteImageName = String.Format("{0}.png", baseImageName); this.DamagesFromGroundContact = getsDamageFromGround; // does the ground break / damage the enemy this.damageLevel = 0; //starts at 0, if breaksAfterHowMuchContact also equals 0 then the enemy will break on first/next contact this.breaksAfterHowMuchContact = breaksFromHowMuchContact; //contact must be made this many times before breaking, or if set to 0, the enemy will break on first/next contact this.differentSpritesForDamage = hasDifferentSpritesForDamage; //will progress through damage frames if this is YES, for example, enemy_damage1.png, enemy_damage2.png this.currentFrame = 0; this.framesToAnimateOnBreak = numberOfFramesToAnimateOnBreak; //will animate through breaks frames if this is more than 0, for example, enemy_break0001.png, enemy_break0002.png this.theDensity = density; this.shapeCreationMethod = createHow; this.isRotationFixed = isTheRotationFixed; this.PointValue = points; this.SimpleScoreVisualFX = simpleScoreVisualFXType; this.DamagesFromDamageEnabledStackObjects = doesGetDamageFromDamageEnabledStackObjects; if (damageLevel == breaksAfterHowMuchContact) { BreaksOnNextDamage = true; } else { BreaksOnNextDamage = false; //duh } CreateEnemy(); }
//Start()函数调用 protected void initBase(float gravityX = 0, float gravityY = -10) { _gravity.x = gravityX; _gravity.y = gravityY; _world = new b2World(_gravity, true); createDebugDraw(); Rect r = Camera.main.pixelRect; Vector3 lowerPoint = Camera.main.ScreenToWorldPoint(new Vector3(r.xMin, r.yMin)); Vector3 upperPoint = Camera.main.ScreenToWorldPoint(new Vector3(r.xMax, r.yMax)); createWrapWallBodies(lowerPoint.x * ptm_ratio, lowerPoint.y * ptm_ratio, upperPoint.x * 2 * ptm_ratio, upperPoint.y * 2 * ptm_ratio); }
private void onWorldInitialized(b2WorldObject worldObj) { _fixtureDict = new Dictionary <Collider2D, b2Fixture[]>(); _worldObj = worldObj; _world = _worldObj.world; b2BodyDef bodyDef = new b2BodyDef(); _body = _world.CreateBody(bodyDef); _body.SetAngle(transform.eulerAngles.z * Mathf.Deg2Rad); createWithCollider2Ds(); setPropertyToBody(); }
protected BipedalWalkerEnv(bool hardcore) : base(new Box(new[] { -1.0f, -1.0f, -1.0f, -1.0f }, new[] { 1.0f, 1.0f, 1.0f, 1.0f }, new Shape(4)), new Box(float.NegativeInfinity, float.PositiveInfinity, new Shape(24))) { this.hardcore = hardcore; contactDetector = new ContactDetector(this); var worldAabb = new b2AABB() { lowerBound = new b2Vec2(-100, -100), upperBound = new b2Vec2(1000, 1000) }; World = new b2World(new b2Vec2(0, -9.807f)); HULL_FD.shape = new b2PolygonShape(); (HULL_FD.shape as b2PolygonShape).Set(HULL_POLY.Select(v => new b2Vec2(v[0] / SCALE, v[1] / SCALE)).ToArray()); HULL_FD.density = 5.0f; HULL_FD.friction = 0.1f; HULL_FD.filter.categoryBits = 0x0020; HULL_FD.filter.maskBits = 0x0001; // collide only with ground HULL_FD.restitution = 0; // 0.99 bouncy LEG_FD.shape = new b2PolygonShape(); (LEG_FD.shape as b2PolygonShape).SetAsBox(LEG_W / 2, LEG_H / 2); LEG_FD.density = 1.0f; LEG_FD.filter.categoryBits = 0x0020; LEG_FD.filter.maskBits = 0x0001; LEG_FD.restitution = 0; LOWER_FD.shape = new b2PolygonShape(); (LOWER_FD.shape as b2PolygonShape).SetAsBox(0.8f * LEG_W / 2, LEG_H / 2); LOWER_FD.density = 1.0f; LOWER_FD.filter.categoryBits = 0x0020; LOWER_FD.filter.maskBits = 0x0001; LOWER_FD.restitution = 0; fd_polygon.shape = new b2PolygonShape(); (fd_polygon.shape as b2PolygonShape).Set(new[] { new b2Vec2(0, 0), new b2Vec2(1, 0), new b2Vec2(1, -1), new b2Vec2(0, -1) }); fd_polygon.friction = FRICTION; fd_edge.shape = new b2EdgeShape(); (fd_edge.shape as b2EdgeShape).Set(new b2Vec2(0, 0), new b2Vec2(1, 1)); fd_edge.friction = FRICTION; fd_edge.filter.categoryBits = 0x0001; Reset(); }
// This method should undo anything that was done by the loadWorld and afterLoadProcessing // methods, and return to a state where loadWorld can safely be called again. public void clear() { if (m_world != null) { Console.WriteLine("Deleting Box2D world"); m_world = null; } if (m_debugDraw != null) { m_debugDraw = null; } //m_world = NULL; //m_mouseJoint = NULL; // m_mouseJointGroundBody = null; }
protected void CreateBodyWithSpriteAndFixture(b2World world, b2BodyDef bodyDef, b2FixtureDef fixtureDef, string spriteName) { // this is the meat of our class, it creates (OR recreates) the body in the world with the body definition, fixture definition and sprite name RemoveBody(); //if remove the body if it already exists RemoveSprite(); //if remove the sprite if it already exists sprite = new CCSprite(spriteName); AddChild(sprite); body = world.CreateBody(bodyDef); body.UserData = this; if (fixtureDef != null) { body.CreateFixture(fixtureDef); } }
public BoxProp( b2World b2world, double[] size, double[] position ) { /* * static rectangle shaped prop * * pars: * size - array [width, height] * position - array [x, y], in world meters, of center */ this.size = size; //initialize body var bdef = new b2BodyDef(); bdef.position = new b2Vec2(position[0], position[1]); bdef.angle = 0; bdef.fixedRotation = true; this.body = b2world.CreateBody(bdef); //initialize shape var fixdef = new b2FixtureDef(); var shape = new b2PolygonShape(); fixdef.shape = shape; shape.SetAsBox(this.size[0] / 2, this.size[1] / 2); fixdef.restitution = 0.4; //positively bouncy! this.body.CreateFixture(fixdef); }
public b2World box2dWorld() { if (null == _world) { var gravity = new b2Vec2(0.0f, -10.0f); _world = new b2World(gravity); _world.SetAllowSleeping(true); _world.SetContinuousPhysics(true); _debugDraw = new LHBox2dDraw("fonts/MarkerFelt-16"); _world.SetDebugDraw(_debugDraw); _debugDraw.AppendFlags(b2DrawFlags.e_shapeBit); Schedule(t => { _world.Step(t, 8, 1); }); } return(_world); }
public Mouse() { //m_destructionListener = new DestructionListener(); m_debugDraw = new CCBox2dDraw("fonts/arial-16"); b2Vec2 gravity = new b2Vec2(); gravity.Set(500, 500); m_world = new b2World(gravity); m_world.SetAllowSleeping(false); m_world.SetContinuousPhysics(true); m_world.SetDebugDraw(m_debugDraw); m_debugDraw.AppendFlags(b2DrawFlags.e_shapeBit | b2DrawFlags.e_aabbBit | b2DrawFlags.e_centerOfMassBit | b2DrawFlags.e_jointBit | b2DrawFlags.e_pairBit); m_world.SetContinuousPhysics(true); m_world.SetWarmStarting(true); }
public void SetJson(string fullpath) { Console.WriteLine("Full path is: %s", fullpath); Nb2dJson json = new Nb2dJson(); StringBuilder tmp = new StringBuilder(); m_world = json.ReadFromFile(fullpath, tmp); if (m_world != null) { Console.WriteLine("Loaded JSON ok"); m_world.SetDebugDraw(m_debugDraw); b2BodyDef bodyDef = new b2BodyDef(); m_groundBody = m_world.CreateBody(bodyDef); } else { Console.WriteLine(tmp); //if this warning bothers you, turn off "Typecheck calls to printf/scanf" in the project build settings } }
/// Call this if you want to establish collision that was previously disabled by b2ContactFilter::ShouldCollide. public void Refilter() { if (m_body == null) { return; } // Flag associated contacts for filtering. b2ContactEdge edge = m_body.GetContactList(); while (edge != null) { b2Contact contact = edge.contact; b2Fixture fixtureA = contact.GetFixtureA(); b2Fixture fixtureB = contact.GetFixtureB(); if (fixtureA == this || fixtureB == this) { contact.FlagForFiltering(); } edge = edge.next; } b2World world = m_body.GetWorld(); if (world == null) { return; } // Touch each proxy so that new pairs may be created b2BroadPhase broadPhase = world.m_contactManager.m_broadPhase; for (int i = 0; i < m_proxyCount; ++i) { broadPhase.TouchProxy(m_proxies[i].proxyId); } }
private void AddShape(b2World world, CCPoint position) { b2Vec2 positionVec = new b2Vec2(position.X, position.Y); var box = new CCPhysicsSprite("hd/images/cloud", IntroLayer.PTM_RATIO); box.Position = position; var def = new b2BodyDef(); def.position = new b2Vec2(positionVec.x / IntroLayer.PTM_RATIO, positionVec.y / IntroLayer.PTM_RATIO); def.linearVelocity = new b2Vec2(0.0f, -1.0f); def.type = b2BodyType.b2_dynamicBody; b2Body body = world.CreateBody(def); // Polygon Shape //var shape = new b2PolygonShape(); //shape.SetAsBox(50f / IntroLayer.PTM_RATIO, 50f / IntroLayer.PTM_RATIO); // Circle Shape var shape = new b2CircleShape(); shape.Radius = 50f / IntroLayer.PTM_RATIO; var fd = new b2FixtureDef(); fd.shape = shape; fd.density = 1f; fd.restitution = 0f; fd.friction = 0.2f; body.CreateFixture(fd); box.PhysicsBody = body; sprites.Add(box); AddChild(box); }
void InitWithWorld(b2World world, CCPoint location, string spriteFileName, bool breaksOnGround, bool breaksFromNinja, bool hasAnimatedBreakFrames, bool damagesEnemy, float density, CreationMethod createHow, int angleChange, bool makeImmovable, int points, BreakEffect simpleScoreVisualFXType) { this.theWorld = world; this.initialLocation = location; this.baseImageName = spriteFileName; this.spriteImageName = String.Format("{0}.png", baseImageName); this.IsBreaksOnGroundContact = breaksOnGround; this.IsBreaksOnNinjaContact = breaksFromNinja; this.addedAnimatedBreakFrames = hasAnimatedBreakFrames; this.IsCanDamageEnemy = damagesEnemy; this.theDensity = density; this.shapeCreationMethod = createHow; this.angle = angleChange; this.IsStatic = makeImmovable; this.currentFrame = 0; this.framesToAnimate = 10; this.PointValue = points; this.SimpleScoreVisualFX = simpleScoreVisualFXType; CreateObject(); }
public GroundPlane (b2World world, CCPoint location, string spriteFileName ) { InitWithWorld(world, location, spriteFileName); }
private void Form1_Load(object sender, EventArgs e) { sogc = new SimpleOpenGlControl(); sogc.Dock = DockStyle.Fill; sogc.Paint += new PaintEventHandler(sogc_Paint); sogc.Resize += new EventHandler(sogc_Resize); Controls.Add(sogc); sogc.InitializeContexts(); InitOpenGL(sogc.Size, 1, PointF.Empty); // Define the gravity vector. b2Vec2 gravity = new b2Vec2(0.0f, -10.0f); // Do we want to let bodies sleep? bool doSleep = true; // Construct a world object, which will hold and simulate the rigid bodies. world = new b2World(gravity, doSleep); // world.SetWarmStarting(true); { b2BodyDef bd = new b2BodyDef(); b2Body ground = world.CreateBody(bd); b2PolygonShape shape = new b2PolygonShape(); shape.SetAsEdge(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f)); ground.CreateFixture(shape, 0.0f); } { float a = 0.5f; b2CircleShape shape = new b2CircleShape(); shape.m_radius = a; b2Vec2 x = new b2Vec2(-7.0f, 0.95f); b2Vec2 y; b2Vec2 deltaX = new b2Vec2(0, 1.25f); b2Vec2 deltaY = new b2Vec2(0, 1.25f); y= deltaY; for (int j = 0; j < 8; ++j) { b2BodyDef bd = new b2BodyDef(); bd.type = b2BodyType.b2_dynamicBody; bd.position = y; b2Body body = world.CreateBody(bd); body.CreateFixture(shape, 5.0f); y += deltaY; } } GDIDebugThing.instance.SetFlags(EDebugFlags.e_shapeBit); world.SetDebugDraw(GDIDebugThing.instance); System.Timers.Timer timer = new System.Timers.Timer(); timer.Interval = 85; timer.SynchronizingObject = this; timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.Start(); }
/// <summary> /// /// </summary> public MapInstance() { m_updateWatch = Stopwatch.StartNew(); m_gameObjects = new Dictionary <int, GameObject>(); World = new b2World(new b2Vec2(0, 0)); }
public Ninja(b2World world, CCPoint location, string baseFileName) { InitWithWorld(world, location, baseFileName); }