/** * Called to deserialize entity's state. * * @param loader */ public final void load(DataLoader loader) { if (loader == null) { return; } // load common entity parameters boolean topLeftCoordinatesMode = loader.getStringValue("coordinatesMode").equalsIgnoreCase("TopLeft"); m_bb.load("localBounds", loader); m_pos.load("position", loader); if (topLeftCoordinatesMode) { m_pos.m_x += m_bb.getWidth() * 0.5f; m_pos.m_y -= m_bb.getHeight() * 0.5f; } m_facing = loader.getFloatValue("facing"); updateWorldBounds(); // load the aspects int aspectsCount = m_aspects.size(); for (int i = 0; i < aspectsCount; ++i) { m_aspects.get(i).load(loader); } // load implementation specific stuff onLoad(loader); }
/** * Sets the bounding box of the entity. * * @param width * @param height */ public final void setBoundingBox(float width, float height) { float halfWidth = width * 0.5f; float halfHeight = height * 0.5f; m_bb.m_minX = -halfWidth; m_bb.m_maxX = halfWidth; m_bb.m_minY = -halfHeight; m_bb.m_maxY = halfHeight; updateWorldBounds(); }
@Override public void draw(SpriteBatcher batcher, Camera2D camera, float deltaTime) { Vector3 pos = m_hunter.getPosition(); BoundingBox bs = m_hunter.getBoundingShape(); // select an animation appropriate to the state the pedestrian's in switch (m_hunter.m_state) { case Aiming: { m_animationPlayer.select(ANIM_AIM); break; } case AimingZombie: { m_animationPlayer.select(ANIM_AIM); break; } case Shooting: { m_animationPlayer.select(ANIM_SHOOT); break; } case ShootingZombie: { m_animationPlayer.select(ANIM_SHOOT); break; } case S*****d: { m_animationPlayer.select(ANIM_SHITTED); break; } case Eaten: { m_animationPlayer.select(ANIM_AIM); break; } } // draw the hunter batcher.drawSprite( pos.m_x, pos.m_y, bs.getWidth(), bs.getHeight(), m_hunter.getFacing(), m_animationPlayer.getTextureRegion(m_hunter, deltaTime)); }
/** Updates the world bounds of the entity. */ private final void updateWorldBounds() { // update the world bounding box m_worldBB.set( m_bb.m_minX + m_pos.m_x, m_bb.m_minY + m_pos.m_y, m_bb.m_maxX + m_pos.m_x, m_bb.m_maxY + m_pos.m_y); }
/** * Called to serialize entity's state. * * @param saver */ public void save(DataSaver saver) { if (saver == null) { return; } // load common entity parameters m_bb.save("localBounds", saver); m_pos.save("position", saver); saver.setFloatValue("facing", m_facing); // load the aspects int aspectsCount = m_aspects.size(); for (int i = 0; i < aspectsCount; ++i) { m_aspects.get(i).save(saver); } // save implementation specific stuff onSave(saver); }