Back to project page googol.
The source code is released under:
MIT License
If you think the Android project googol listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.martinb.googol.Control; /*from w w w . j ava 2s .co m*/ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.TimeUtils; /** * Path used by a character */ public class Path { public static final short MIRROR_LEFT_TO_RIGHT = 0; public static final short MIRROR_RIGHT_TO_LEFT = 1; public static final short MIRROR_UP_TO_DOWN = 2; public static final short MIRROR_DOWN_TO_UP = 3; float angleChangeCooldownDuration; // Cooldown time in millis long angleChangeCooldownStart; // Cooldown start time in millis float velocityChangeCooldownDuration; // Cooldown time in millis long velocityChangeCooldownStart; // Cooldown start time in millis float angleChange; float difficulty; Vector2 velocity; /** * Creates a path depending on difficulty chosen */ public Path(float difficulty) { this.difficulty = difficulty; this.velocity = new Vector2(); setAngleChange(difficulty); setVelocity(difficulty); } public void update(float delta) { if (TimeUtils.timeSinceMillis(angleChangeCooldownStart) > angleChangeCooldownDuration) { setAngleChange(difficulty); } if (TimeUtils.timeSinceMillis(velocityChangeCooldownStart) > velocityChangeCooldownDuration) { setVelocity(difficulty); } velocity = velocity.rotate(angleChange * delta); } public Vector2 getVelocity() { return velocity; } public void mirrorVelocity(short direction) { switch (direction) { case MIRROR_LEFT_TO_RIGHT: velocity.x = Math.abs(velocity.x); break; case MIRROR_RIGHT_TO_LEFT: velocity.x = -Math.abs(velocity.x); break; case MIRROR_DOWN_TO_UP: velocity.y = Math.abs(velocity.y); break; case MIRROR_UP_TO_DOWN: velocity.y = -Math.abs(velocity.y); break; } } void setAngleChange(float difficulty) { angleChange = (float) (Math.random() * 2 - 1) * difficulty * 100; angleChangeCooldownDuration = (float) (Math.random() * 8 + 2) * 1000; angleChangeCooldownStart = TimeUtils.millis(); } void setVelocity(float difficulty) { velocity.set(difficulty * 50, 0); velocity.setAngle((float) Math.random()*360); velocityChangeCooldownDuration = (float) (Math.random() * 16 + 2) * 1000; velocityChangeCooldownStart = TimeUtils.millis(); } }