• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Physics类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.mostlyoriginal.api.component.physics.Physics的典型用法代码示例。如果您正苦于以下问题:Java Physics类的具体用法?Java Physics怎么用?Java Physics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Physics类属于net.mostlyoriginal.api.component.physics包,在下文中一共展示了Physics类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: process

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void process(E e) {
    final Physics physics = e.getPhysics();
    final Pos pos = e.getPos();
    final Bounds bounds = e.getBounds();

    //  no math required here.
    e.wallSensorOnPlatform(false);
    if (physics.vy < 0) {

        float px = pos.xy.x + physics.vx * world.delta;
        float py = pos.xy.y + physics.vy * world.delta;

        if (collides(px + bounds.minx + (bounds.maxx - bounds.minx) * 0.5f, py + bounds.miny)) {
            physics.vy = physics.bounce > 0 ? -physics.vy * physics.bounce : 0;
            e.wallSensorOnPlatform(true);
        }

    }

}
 
开发者ID:DaanVanYperen,项目名称:odb-artax,代码行数:22,代码来源:PlatformCollisionSystem.java


示例2: initialize

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void initialize() {
    super.initialize();

    dustParticle = new ArchetypeBuilder()
            .add(Pos.class)
            .add(Anim.class)
            .add(Renderable.class)
            .add(Schedule.class)
            .add(Scale.class)
            .add(Gravity.class)
            .add(Physics.class).build(world);
    smokeParticle = new ArchetypeBuilder()
            .add(Pos.class)
            .add(Anim.class)
            .add(Angle.class)
            .add(Renderable.class)
            .add(Schedule.class)
            .add(ZPos.class)
            .add(Scale.class)
            .add(Physics.class).build(world);
}
 
开发者ID:DaanVanYperen,项目名称:odb-dynasty,代码行数:23,代码来源:SmokeSystem.java


示例3: dust

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
public void dust(float y, float x1, float x2, int particles , int layer )
{
    for(int i = 0; i<particles; i++) {
        int e = world.create(dustParticle);
        mPos.get(e).set(MathUtils.random(x1,x2),y + MathUtils.random(-5f, 5f));
        mAnim.get(e).id="dust_particle";
        Physics physics = mPhysics.get(e);
        physics.vx=MathUtils.random(-5f,5f);
        physics.vy=5 + MathUtils.random(0,10f);
        physics.friction=0.01f;
        mScale.get(e).scale=MathUtils.random(0.5f,3f);
        mRenderable.get(e).layer = layer;

        mSchedule.get(e).operation.add(
                OperationFactory.sequence(
                        OperationFactory.tween(start, stop, 3f),
                        OperationFactory.deleteFromWorld()));

    }
}
 
开发者ID:DaanVanYperen,项目名称:odb-dynasty,代码行数:21,代码来源:SmokeSystem.java


示例4: cloud

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
public void cloud(int x, int y, int x2, int y2, int particles, int layer) {

        for(int i = 0; i<particles; i++) {
            int e = world.create(dustParticle);
            mPos.get(e).set(MathUtils.random(x,x2),MathUtils.random(y,y2));
            mAnim.get(e).id="dust_particle";
            Physics physics = mPhysics.get(e);
            physics.vx=MathUtils.random(-5f,5f);
            physics.vy=5 + MathUtils.random(5f,5f);
            physics.friction=0.01f;
            mScale.get(e).scale=MathUtils.random(0.5f,3f);
            mRenderable.get(e).layer = layer;

            mSchedule.get(e).operation.add(
                    OperationFactory.sequence(
                            OperationFactory.tween(start, stop, 3f),
                            OperationFactory.deleteFromWorld()));

        }
    }
 
开发者ID:DaanVanYperen,项目名称:odb-dynasty,代码行数:21,代码来源:SmokeSystem.java


示例5: spawn

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
public Entity spawn(String id, int productivity, String deathSfx) {
    System.out.println("Spawn " + id);
    Entity e = new DynastyEntityBuilder(world).with(
            new Bounds(0, 0, 0, 0),
            new Anim(id))
            .with(Pos.class, Scale.class,
                    Renderable.class, Physics.class, Gravity.class, Tint.class, ZPos.class)
            .schedule(tween(new Tint(TINT_INVISIBLE), new Tint("ffffffff"), 0.5f))
            .minion(productivity).build();
    randomizeLocation(e);
    Physics physics = mPhysics.get(e);
    physics.vy = 500;
    physics.friction = 20f;
    mColor.get(e).setHex(TINT_INVISIBLE);
    mScale.get(e).scale = G.ZOOM;
    mRenderable.get(e).layer = MINION_LAYER;
    mMinion.get(e).deathSfx = deathSfx;

    return e;
}
 
开发者ID:DaanVanYperen,项目名称:odb-dynasty,代码行数:21,代码来源:MinionSystem.java


示例6: gravitateItemsAwayFromEdge

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
private void gravitateItemsAwayFromEdge(Entity item, Entity belt) {
	float beltAngle = getAngle(belt);
	Physics physics = mPhysics.get(item);
	final Pos pos = mPos.get(item);

	final TextureRegion frame = assetSystem.get(mAnim.get(item).id).getKeyFrame(0);

	final int x = (int) (pos.x + frame.getRegionWidth() / 2);
	final int y = (int) (pos.y + frame.getRegionHeight() / 2 - G.FOOTER_H);

	beltAngle = Math.abs(beltAngle);
	if (beltAngle == 0 || beltAngle == 180) {
		if (y % G.TILE_SIZE <= SAFETY_BORDER_PIXELS) physics.vy = SAFETY_BORDER_VELOCITY;
		if (y % G.TILE_SIZE >= G.TILE_SIZE - SAFETY_BORDER_PIXELS) physics.vy = -SAFETY_BORDER_VELOCITY;
	}

	if (beltAngle == 90 || beltAngle == 270) {
		if (x % G.TILE_SIZE <= SAFETY_BORDER_PIXELS) physics.vx = SAFETY_BORDER_VELOCITY;
		if (x % G.TILE_SIZE >= G.TILE_SIZE - SAFETY_BORDER_PIXELS) physics.vx = -SAFETY_BORDER_VELOCITY;
	}
}
 
开发者ID:DaanVanYperen,项目名称:odb-minion-factorium,代码行数:22,代码来源:ConveyerSystem.java


示例7: initialize

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void initialize() {
	super.initialize();

	aActor   = newType(Pos.class, Bounds.class, Anim.class, Renderable.class);
	aHamster = newSubType(aActor, PlayerControlled.class, Physics.class, Clamped.class, Ripple.class);
	aBubble  = newSubType(aActor, Attached.class, Color.class);
	aOcean   = newSubType(aActor, LiquidVolume.class);
	aSky     = newSubType(aActor, LiquidVolume.class);
	aBuoy = newSubType(aActor, Physics.class);

	Entity hamster = createEntity("hamster", 10, 10, null);
	Entity ocean = createEntity("ocean");
	Entity sky = createEntity("sky");

	// hook up entities.

	mClamped.get(hamster).maxx = G.SCREEN_WIDTH;
	mClamped.get(hamster).maxy = G.SCREEN_HEIGHT * 0.6f;

}
 
开发者ID:DaanVanYperen,项目名称:splash-racer,代码行数:22,代码来源:EntityFactorySystem.java


示例8: process

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void process(Entity e) {

	Physics physics = mPhysics.get(e);

	int y=0;
	int x=0;

	if (Gdx.input.isKeyPressed(Input.Keys.UP) || Gdx.input.isKeyPressed(Input.Keys.W)) y=1;
	if (Gdx.input.isKeyPressed(Input.Keys.DOWN) || Gdx.input.isKeyPressed(Input.Keys.S)) y=-1;
	if (Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.isKeyPressed(Input.Keys.A)) x=-1;
	if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) || Gdx.input.isKeyPressed(Input.Keys.D)) x=+1;

	physics.vx = x * 120;
	physics.vy = y * 100;

	Anim anim = mAnim.get(e);
	if ( x < 0 ) {
		anim.id = "boat-left";
	} else if ( x > 0 ) {
		anim.id = "boat-right";
	} else {
		anim.id = "boat";
	}
}
 
开发者ID:DaanVanYperen,项目名称:splash-racer,代码行数:26,代码来源:PlayerControlSystem.java


示例9: process

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void process(int e) {
    final Physics physics = ym.get(e);
    final Pos pos = pm.get(e);
    final Bounds bounds = bm.get(e);

    //  no math required here.
    if (physics.vx != 0 || physics.vy != 0) {

        float px = pos.xy.x + physics.vx * world.delta;
        float py = pos.xy.y + physics.vy * world.delta;

        if ((physics.vx > 0 && collides(px + bounds.maxx, py + bounds.miny + (bounds.maxy - bounds.miny) * 0.5f)) ||
                (physics.vx < 0 && collides(px + bounds.minx, py + bounds.miny + (bounds.maxy - bounds.miny) * 0.5f))) {
            physics.vx = physics.bounce > 0 ? -physics.vx * physics.bounce : 0;
            px = pos.xy.x;
        }

        if ((physics.vy > 0 && collides(px + bounds.minx + (bounds.maxx - bounds.minx) * 0.5f, py + bounds.maxy)) ||
                (physics.vy < 0 && collides(px + bounds.minx + (bounds.maxx - bounds.minx) * 0.5f, py + bounds.miny))) {
            physics.vy = physics.bounce > 0 ? -physics.vy * physics.bounce : 0;
        }

    }

}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:27,代码来源:MapCollisionSystem.java


示例10: process

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void process(int e) {
    final Physics physics = ym.get(e);
    final Pos pos = pm.get(e);

    // don't process frozen entities.
    if ( frozenm.has(e)) return;

    if ( physics.maxVelocity < Float.MAX_VALUE)
        clampVelocity(e, 0, physics.maxVelocity);

    pos.xy.x += physics.vx * world.getDelta();
    pos.xy.y += physics.vy * world.getDelta();

    if ( physics.vr != 0 && am.has(e))
    {
        am.get(e).rotation += physics.vr * world.delta;
    }
    
    if (physics.friction != 0) {
        updateFudgeFriction(physics);
    }

}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:25,代码来源:PhysicsSystem.java


示例11: updateFudgeFriction

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
/**
 * Not really friction, not really fudge!
 */
private void updateFudgeFriction(Physics physics) {
    float adjustedFriction = physics.friction;

    if (Math.abs(physics.vx) > 0.005f) {
        physics.vx = physics.vx - (physics.vx * world.delta * adjustedFriction);
    } else {
        physics.vx = 0;
    }

    if (Math.abs(physics.vr) > 0.005f) {
        physics.vr = physics.vr - (physics.vr * world.delta * adjustedFriction);
    } else {
        physics.vr = 0;
    }

    if (Math.abs(physics.vy) > 0.005f) {
        physics.vy = physics.vy - (physics.vy * world.delta * adjustedFriction * 0.1f);
    } else {
        physics.vy = 0;
    }
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:25,代码来源:PhysicsSystem.java


示例12: process

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void process(int e) {
    final Pos pos = pm.get(e);
    final Bounds bounds = bm.has(e) ? bm.get(e) : Bounds.NONE;
    final Clamped clamped = cm.get(e);

    // determine valid viewport.
    final float wx1 = clamped.minx - bounds.minx;
    final float wx2 = clamped.maxx - bounds.maxx;
    final float wy1 = clamped.miny - bounds.miny;
    final float wy2 = clamped.maxy - bounds.maxy;

    // halt momentum if required.
    if ( ym.has(e))
    {
        Physics physics = ym.get(e);
        if ( physics.vx < 0 && pos.xy.x + physics.vx* world.delta <= wx1 ) physics.vx =0;
        if ( physics.vx > 0 && pos.xy.x + physics.vx* world.delta >= wx2 ) physics.vx =0;
        if ( physics.vy < 0 && pos.xy.y + physics.vy* world.delta <= wy1 ) physics.vy =0;
        if ( physics.vy > 0 && pos.xy.y + physics.vy* world.delta >= wy2 ) physics.vy =0;
    }

    // clamp coords
    pos.xy.x = MathUtils.clamp( pos.xy.x, wx1, wx2);
    pos.xy.y = MathUtils.clamp( pos.xy.y, wy1, wy2);
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:27,代码来源:ClampedSystem.java


示例13: createJumpingImp

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
private Entity createJumpingImp(int cx, int cy) {

        Physics phys = new Physics();
        phys.vx = MathUtils.random(25f,80f) * 3f;
        if ( MathUtils.randomBoolean() ) phys.vx = -phys.vx;
        phys.vy = MathUtils.random(100f,120f) * 3f;
        phys.vr = MathUtils.random(-90,90);
        phys.friction = 1f;

        return world.createEntity()
		        .edit()
                        .add(new Pos(cx, cy))
                        .add(new Bounds(10, 10))
                        .add(new Angle())
                        .add(new Gravity())
                        .add(new ColorAnimation(new Color(1, 1, 1, 1), new Color(1, 1, 1, 0), Interpolation.linear, 1f, 1f))
                        .add(new Schedule().wait(1f).deleteFromWorld())
                        .add(phys)
                        .add(new Anim("marker-monster", 9)).getEntity();
    }
 
开发者ID:DaanVanYperen,项目名称:underkeep,代码行数:21,代码来源:EntityFactorySystem.java


示例14: createParticleDebris

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
private Entity createParticleDebris(int cx, int cy) {

        Physics phys = new Physics();
        phys.vx = MathUtils.random(25f,80f) * 3f;
        if ( MathUtils.randomBoolean() ) phys.vx = -phys.vx;
        phys.vy = MathUtils.random(100f,120f) * 2f;
        phys.vr = MathUtils.random(-90,90);
        phys.friction = 3f;

        Anim anim = staticRandomizedAnim("particle-debris");
        anim.layer=9;
        return world.createEntity()
		        .edit()
                        .add(new Pos(cx, cy))
                        .add(new Bounds(6, 5))
                        .add(new Angle())
                        .add(new Gravity())
                        .add(new Schedule()
		                        .wait(MathUtils.random(0.1f, 0.25f))
		                        .add(new ColorAnimation(new Color(1, 1, 1, 1), new Color(1, 1, 1, 0), Interpolation.linear, 0.5f, 0.5f))
		                        .wait(1f)
		                        .deleteFromWorld())
                        .add(phys)
                        .add(anim).getEntity();
    }
 
开发者ID:DaanVanYperen,项目名称:underkeep,代码行数:26,代码来源:EntityFactorySystem.java


示例15: createParticleCoin

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
private Entity createParticleCoin(int cx, int cy) {

        Physics phys = new Physics();
        phys.vx = MathUtils.random(25f,80f) * 3f;
        if ( MathUtils.randomBoolean() ) phys.vx = -phys.vx;
        phys.vy = MathUtils.random(100f,120f) * 2f;
        phys.vr = MathUtils.random(-90,90);
        phys.friction = 3f;

        Anim anim = staticRandomizedAnim("particle-coin");
        anim.layer=200;
        return world.createEntity().edit()
                        .add(new Pos(cx, cy))
                        .add(new Bounds(6,5))
                        .add(new Angle())
                        .add(new Gravity())
                        .add(new Schedule()
                                .wait(MathUtils.random(0.1f, 0.25f))
                                .add(new ColorAnimation(new Color(1, 1, 1, 1), new Color(1, 1, 1, 0), Interpolation.linear, 0.5f, 0.5f))
                                .wait(1f)
                                .deleteFromWorld())
                        .add(phys)
                        .add(anim).getEntity();
    }
 
开发者ID:DaanVanYperen,项目名称:underkeep,代码行数:25,代码来源:EntityFactorySystem.java


示例16: createCloud

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
private Entity createCloud(int cx, int cy) {
    Physics physics = new Physics();
    physics.friction=0;
    physics.vx=MathUtils.random(0.2f,2f);

    // clamp with wrap so clouds can swoop around
    Clamped clamped = new Clamped(-40, 0, Gdx.graphics.getWidth() / G.CAMERA_ZOOM_FACTOR +10, Gdx.graphics.getHeight() / G.CAMERA_ZOOM_FACTOR);
    clamped.wrap = true;
    Anim anim = staticRandomizedAnim("cloud");
    anim.scale=MathUtils.random(1f,1.2f);
    anim.color.a= 0.1f + (MathUtils.random(0.1f, 0.2f) * (1f/anim.scale));
    anim.layer = -98;
    return world.createEntity()
      .edit().add(new Pos(cx, cy))
            .add(anim)
            .add(physics)
            .add(clamped).getEntity();
}
 
开发者ID:DaanVanYperen,项目名称:underkeep,代码行数:19,代码来源:EntityFactorySystem.java


示例17: process

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void process(Entity e) {
    final Physics physics = ym.get(e);
    final Pos pos = pm.get(e);
    final Bounds bounds = bm.get(e);

    //  no math required here.
    if (physics.vx != 0 || physics.vy != 0) {

        float px = pos.x + physics.vx * world.delta;
        float py = pos.y + physics.vy * world.delta;

        if ((physics.vx > 0 && collides(px + bounds.maxx, py + bounds.miny + (bounds.maxy - bounds.miny) * 0.5f)) ||
                (physics.vx < 0 && collides(px + bounds.minx, py + bounds.miny + (bounds.maxy - bounds.miny) * 0.5f))) {
            physics.vx = physics.bounce > 0 ? -physics.vx * physics.bounce : 0;
            px = pos.x;
        }

        if ((physics.vy > 0 && collides(px + bounds.minx + (bounds.maxx - bounds.minx) * 0.5f, py + bounds.maxy)) ||
                (physics.vy < 0 && collides(px + bounds.minx + (bounds.maxx - bounds.minx) * 0.5f, py + bounds.miny))) {
            physics.vy = physics.bounce > 0 ? -physics.vy * physics.bounce : 0;
        }

    }

}
 
开发者ID:DaanVanYperen,项目名称:underkeep,代码行数:27,代码来源:MapCollisionSystem.java


示例18: process

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void process(Entity e) {
    final Physics physics = ym.get(e);
    final Pos pos = pm.get(e);

    // don't process frozen entities.
    if ( frozenm.has(e)) return;

    if ( physics.maxVelocity < Float.MAX_VALUE)
        clampVelocity(e, physics.minVelocity, physics.maxVelocity);

    pos.x += physics.vx * world.getDelta();
    pos.y += physics.vy * world.getDelta();

    if ( physics.vr != 0 && am.has(e))
    {
        am.get(e).rotation += physics.vr * world.delta;
    }
    
    if (physics.friction != 0) {
        updateFudgeFriction(physics);
    }

}
 
开发者ID:DaanVanYperen,项目名称:underkeep,代码行数:25,代码来源:PhysicsSystem.java


示例19: process

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void process(E e) {
    Vector2 gravityVector = v.set(e.planetboundGravity());

    if (e.massInverse()) {
        gravityVector.rotate(180);
    }

    // apply gravity.
    Physics physics = e.getPhysics();

    // don't move through solid matter.
    PlanetCell cell = e.planetboundCell();
    if (cell != null && cell.type != null && (cell.type.density == null || cell.type.density >= e.massDensity())) {
        if (cell.type.flows() && !e.hasDolphinized()) {
            gravityVector.rotate(180);
            physics.vx = 0;
            physics.vy = 0;
        } else {
            gravityVector.set(0, 0);
            physics.vx = 0;
            physics.vy = 0;
        }
    }

    boolean inSpace = cell == null || cell.depth() <= 0;

    physics.vx += gravityVector.x * (inSpace ? 0.5f : 4f);
    physics.vy += gravityVector.y * (inSpace ? 0.5f : 4f);


    if (inSpace) {
        e.angleRotation(gravityVector.angle()-90);
    }

    physics.friction = 0.05f;

}
 
开发者ID:DaanVanYperen,项目名称:odb-little-fortune-planet,代码行数:39,代码来源:GravitySystem.java


示例20: process

import net.mostlyoriginal.api.component.physics.Physics; //导入依赖的package包/类
@Override
protected void process(E e) {
    if (e.explosivePrimed()) {
        int cx = (int) (e.posX() + e.boundsCx());
        int cy = (int) (e.posY() + e.boundsCy());
        drawingSystem.draw(planetCreationSystem.planetEntity,
                cx, cy,
                e.explosiveYield(),
                PlanetCell.CellType.FIRE);
        e.deleteFromWorld();

        for (E wanderer : allEntitiesMatching(Aspect.all(Wander.class, Pos.class, Physics.class))) {

            v2.set(wanderer.posX(), wanderer.posY()).sub(cx, cy);

            float len = Math.abs(v2.len());
            if (len < 100) {
                float strength = MathUtils.clamp(0, 220 - len, 100);
                v2.nor().scl(strength);

                v3.set(wanderer.posX(), wanderer.posY()).sub(G.PLANET_CENTER_X, G.PLANET_CENTER_Y).nor().scl(strength / 2);

                v2.add(v3);

                wanderer.physicsVx(v2.x);
                wanderer.physicsVy(v2.y);
            }
        }
    }
}
 
开发者ID:DaanVanYperen,项目名称:odb-little-fortune-planet,代码行数:31,代码来源:ExplosiveSystem.java



注:本文中的net.mostlyoriginal.api.component.physics.Physics类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BugPattern类代码示例发布时间:2022-05-23
下一篇:
Java GenerationConfig类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap