当前位置: 首页>>代码示例>>Java>>正文


Java MathUtils.isZero方法代码示例

本文整理汇总了Java中com.badlogic.gdx.math.MathUtils.isZero方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.isZero方法的具体用法?Java MathUtils.isZero怎么用?Java MathUtils.isZero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.math.MathUtils的用法示例。


在下文中一共展示了MathUtils.isZero方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setHealth

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/**
 * Setzt die Anzahl der Lebenspunkte direkt.
 * Sollte so ehr selten benutzt werden.
 *
 * @see Player#applyDamage(int)
 * @see Player#heal(int)
 *
 * @param health die neue Anzahl Lebenspunkte
 */
public void setHealth(int health) {
    if (health > 100)
        health = 100;

    if (health < 0 || MathUtils.isZero(health))
    {
        if (cheatManager.isImmortal())
        {
            this.health = 100;
            return;
        }

        health = 0;
        if (deadCallback != null)
            deadCallback.run();
    }

    this.health = health;
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:29,代码来源:Player.java

示例2: onUpdate

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
public void onUpdate(float deltaTime)
{
    if (!MathUtils.isZero(hitTimer))
    {
        hitTimer -= deltaTime;

        if (hitTimer <= 0f)
            hitTimer = 0f;
    }

    body.setLinearVelocity(Vector2.Zero);
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:14,代码来源:TutorialDummy.java

示例3: render

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
public void render(Batch batch, float deltaTime)
{
    if (body == null) return;

    Color oldColor = batch.getColor();

    batch.setColor(1f, (health + 5)/10f, (health + 5)/10f, 1f);

    Vector2 pos = body.getPosition();
    pos.scl(Physics.PPM);

    TextureRegion region = MathUtils.isZero(hitTimer) ? dummy : dummy_hit;

    batch.draw(region,                                    // TextureRegion (front, back, side)
            pos.x - dummy.getRegionWidth() / 2,           // Offset to the X position (character center)
            pos.y,                                        // Y position is at the foots
            dummy.getRegionWidth() / 2,                   // Origin X (important for flipping)
            dummy.getRegionHeight(),                      // Origin Y
            dummy.getRegionWidth(),                       // Width
            dummy.getRegionHeight(),                      // Height
            1f,                                           // Scale X (-1 to flip)
            1f,                                           // Scale Y
            0f);                                          // Rotation

    batch.setColor(oldColor);
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:28,代码来源:TutorialDummy.java

示例4: onUpdate

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
public void onUpdate(float deltaTime)
{
    if (!MathUtils.isZero(hitTimer))
    {
        hitTimer -= deltaTime;

        if (hitTimer <= 0f)
            hitTimer = 0f;
    }

    if (attackTimer > 0f)
        attackTimer -= deltaTime;

    if (handler.canAttack())
    {
        if (attackTimer <= 0f)
        {
            attackTimer = 1.6f;

            handler.attack(3);
        }
    }

    bodyPosition = body.getPosition();

    if (body.getLinearVelocity().sub(direction).len2() > 1 || (MathUtils.isEqual(oldPosition.x, bodyPosition.x) && MathUtils.isEqual(oldPosition.y, bodyPosition.y)))
    {
        direction.set(MathUtils.random(-1f, 1f), MathUtils.random(-1f, 1f));
        direction.scl(4f);
    }

    oldPosition = bodyPosition;

    body.applyForceToCenter(direction, true);
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:37,代码来源:Crab.java

示例5: render

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/**
 * Rendert das Objekt in die Map.
 *
 * @param batch der Batch der Map
 * @param deltaTime die Zeit, die seit dem letzten Frame vergangen ist
 */
@Override
public void render(Batch batch, float deltaTime)
{
    if (body == null) return;

    Vector2 pos = body.getPosition();
    pos.scl(Physics.PPM);

    TextureRegion region = null;
    float scaleX = 1f;

    boolean notMoving = MathUtils.isZero(body.getLinearVelocity().x, 0.5f) && MathUtils.isZero(body.getLinearVelocity().y, 0.5f);

    if (notMoving)
    {
        animationTime = 0f;
    } else {
        animationTime += deltaTime;
    }

    switch (orientation)
    {
        case LOOK_FORWARD:
            region = notMoving ? npcFront : npcFrontWalk.getKeyFrame(animationTime);
            break;
        case LOOK_LEFT:
            region = notMoving ? npcSide : npcSideWalk.getKeyFrame(animationTime);
            scaleX = -1f;
            break;
        case LOOK_BACKWARD:
            region = notMoving ? npcBack : npcBackWalk.getKeyFrame(animationTime);
            scaleX = -1f;
            break;
        case LOOK_RIGHT:
            region = notMoving ? npcSide : npcSideWalk.getKeyFrame(animationTime);
            break;
    }

    batch.draw(region,                                      // TextureRegion (front, back, side)
            pos.x - npcSide.getRegionWidth() / 2,           // Offset to the X position (character center)
            pos.y,                                          // Y position is at the foots
            npcSide.getRegionWidth() / 2,                   // Origin X (important for flipping)
            npcSide.getRegionHeight(),                      // Origin Y
            npcSide.getRegionWidth(),                       // Width
            npcSide.getRegionHeight(),                      // Height
            scaleX,                                         // Scale X (-1 to flip)
            1f,                                             // Scale Y
            0f);                                            // Rotation
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:56,代码来源:BaseNPC.java

示例6: applyDamage

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/**
 * Fügt dem Spieler schaden zu.
 *
 * @param damage wie viele Lebenspunkte soll der Spieler verlieren?
 */
public void applyDamage(int damage) {

    if (!MathUtils.isZero(damageTime)) return;

    if (!cheatManager.isImmortal())
        this.setHealth(health - damage);

    damageTime = 0.1f * (float) damage;
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:15,代码来源:Player.java


注:本文中的com.badlogic.gdx.math.MathUtils.isZero方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。