Android Open Source - CircleWorldGDX Avatar From Project Back to project page CircleWorldGDX .
License The source code is released under:
MIT License
If you think the Android project CircleWorldGDX listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.fdangelo.circleworld.universeengine.objects;
/ * w w w . j a v a 2 s . c o m * /
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.fdangelo.circleworld.universeengine.tilemap.Planet;
import com.fdangelo.circleworld.universeengine.tilemap.TileHitFlags;
import com.fdangelo.circleworld.utils.Mathf;
import com.fdangelo.circleworld.utils.Vector2I;
public class Avatar extends UniverseObject {
public AvatarInput input = new AvatarInput();
private final float jumpSpeed = 7.0f;
private final float walkSpeedMax = 3.0f;
private final float walkAcceleration = 10.0f;
private final float walkFriction = 10.0f;
private Ship onShip;
@Override
protected void onUpdate(final float deltaTime) {
if (onShip == null) {
if (canWalk()) {
if (input.walkDirection != 0) {
velocityX += input.walkDirection * walkAcceleration * deltaTime;
} else {
velocityX -= Mathf.Sign(velocityX) * MathUtils.clamp(walkFriction * deltaTime, 0, Math.abs(velocityX));
}
velocityX = MathUtils.clamp(velocityX, -walkSpeedMax, walkSpeedMax);
}
if (input.jump && canJump()) {
velocityY = jumpSpeed;
}
} else {
velocityX = 0;
velocityY = 0;
positionX = onShip.getPositionX();
positionY = onShip.getPositionY();
}
input.reset();
}
public final boolean canWalk() {
return true;
}
public final boolean canJump() {
return (hitFlags & TileHitFlags.Down) != 0;
}
public final void boardShip(final Ship ship) {
onShip = ship;
scale = 1.0f;
setParent(null, FollowParentParameters.None, ship.getPositionX(), ship.getPositionY(), rotation);
setVisible(false);
}
static private Vector2I tmpvi = new Vector2I();
public final void travelToPlanet(final Planet planet) {
if (onShip != null) {
Vector2I landTile = tmpvi;
// Set position closest to the ship
planet.getTileCoordinatesFromPosition(onShip.getPositionX(), onShip.getPositionY(), landTile);
final int landTileX = landTile.x;
int landTileY = landTile.y;
landTile = null;
landTileY = planet.getHeight();
final Vector2 tilePositionOnPlanet = planet.getPositionFromTileCoordinate(landTileX, landTileY);
setParent(planet, FollowParentParameters.Default, tilePositionOnPlanet.x, tilePositionOnPlanet.y, 0.0f);
// Leave ship
onShip = null;
} else {
final Vector2 tilePositionOnPlanet = planet.getPositionFromTileCoordinate(0, planet.getHeight());
setParent(planet, FollowParentParameters.Default, tilePositionOnPlanet.x, tilePositionOnPlanet.y, 0.0f);
}
setVisible(true);
}
}
Java Source Code List .AssetsUpdater.java com.fdangelo.circleworld.GameLogicState.java com.fdangelo.circleworld.GameLogic.java com.fdangelo.circleworld.MainActivity.java com.fdangelo.circleworld.Main.java com.fdangelo.circleworld.MyGdxGame.java com.fdangelo.circleworld.RobovmLauncher.java com.fdangelo.circleworld.client.GwtLauncher.java com.fdangelo.circleworld.gui.AvatarEditControlScreen.java com.fdangelo.circleworld.gui.AvatarMoveControlScreen.java com.fdangelo.circleworld.gui.HudScreen.java com.fdangelo.circleworld.gui.core.Gui.java com.fdangelo.circleworld.gui.core.ScreenTable.java com.fdangelo.circleworld.gui.core.Screen.java com.fdangelo.circleworld.universeengine.IUniverseListener.java com.fdangelo.circleworld.universeengine.ThingPosition.java com.fdangelo.circleworld.universeengine.ThingType.java com.fdangelo.circleworld.universeengine.Thing.java com.fdangelo.circleworld.universeengine.UniverseFactory.java com.fdangelo.circleworld.universeengine.UniverseGeneratorDefault.java com.fdangelo.circleworld.universeengine.UniverseGenerator.java com.fdangelo.circleworld.universeengine.Universe.java com.fdangelo.circleworld.universeengine.objects.AvatarInput.java com.fdangelo.circleworld.universeengine.objects.Avatar.java com.fdangelo.circleworld.universeengine.objects.FollowParentParameters.java com.fdangelo.circleworld.universeengine.objects.IUniverseObjectListener.java com.fdangelo.circleworld.universeengine.objects.ShipInput.java com.fdangelo.circleworld.universeengine.objects.Ship.java com.fdangelo.circleworld.universeengine.objects.UniverseObject.java com.fdangelo.circleworld.universeengine.tilemap.ITilemapCircleListener.java com.fdangelo.circleworld.universeengine.tilemap.PlanetType.java com.fdangelo.circleworld.universeengine.tilemap.PlanetTypes.java com.fdangelo.circleworld.universeengine.tilemap.Planet.java com.fdangelo.circleworld.universeengine.tilemap.TileDirection.java com.fdangelo.circleworld.universeengine.tilemap.TileHitFlags.java com.fdangelo.circleworld.universeengine.tilemap.TileHitInfo.java com.fdangelo.circleworld.universeengine.tilemap.TileSubtype.java com.fdangelo.circleworld.universeengine.tilemap.TileType.java com.fdangelo.circleworld.universeengine.tilemap.TileTypes.java com.fdangelo.circleworld.universeengine.tilemap.TilemapCircle.java com.fdangelo.circleworld.universeengine.utils.DataPools.java com.fdangelo.circleworld.universeengine.utils.PoolByte.java com.fdangelo.circleworld.universeengine.utils.PoolColor.java com.fdangelo.circleworld.universeengine.utils.PoolFloat.java com.fdangelo.circleworld.universeengine.utils.PoolInt.java com.fdangelo.circleworld.universeengine.utils.PoolVector2.java com.fdangelo.circleworld.universeengine.utils.PoolVector3.java com.fdangelo.circleworld.universeengine.utils.UEProfilerSample.java com.fdangelo.circleworld.universeengine.utils.UEProfiler.java com.fdangelo.circleworld.universeview.FollowCameraParameters.java com.fdangelo.circleworld.universeview.UniverseViewCamera.java com.fdangelo.circleworld.universeview.UniverseViewFactory.java com.fdangelo.circleworld.universeview.UniverseView.java com.fdangelo.circleworld.universeview.objects.AvatarInputEditTool.java com.fdangelo.circleworld.universeview.objects.AvatarInputMode.java com.fdangelo.circleworld.universeview.objects.AvatarViewInput.java com.fdangelo.circleworld.universeview.objects.AvatarView.java com.fdangelo.circleworld.universeview.objects.InputAreas.java com.fdangelo.circleworld.universeview.objects.ShipInputMode.java com.fdangelo.circleworld.universeview.objects.ShipViewInput.java com.fdangelo.circleworld.universeview.objects.ShipView.java com.fdangelo.circleworld.universeview.objects.UniverseObjectView.java com.fdangelo.circleworld.universeview.tilemap.PlanetView.java com.fdangelo.circleworld.universeview.tilemap.TilemapCircleViewBackgroundRenderer.java com.fdangelo.circleworld.universeview.tilemap.TilemapCircleViewRenderer.java com.fdangelo.circleworld.universeview.tilemap.TilemapCircleView.java com.fdangelo.circleworld.utils.Mathf.java com.fdangelo.circleworld.utils.Vector2I.java