summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2021-02-15 11:30:32 -0600
committerColin Okay <okay@toyful.space>2021-02-15 11:30:32 -0600
commitaecd54d7c5717ae8dd85fe21cff669a616c79e9c (patch)
treebb8a3de9d8a58e7f28b6d756bf32d7376a32f502
parent9bb52e1b393cd7b09f1c140ce5873391987ebaab (diff)
wigglers scooting
-rw-r--r--Source/Main.hx24
1 files changed, 20 insertions, 4 deletions
diff --git a/Source/Main.hx b/Source/Main.hx
index 9ea697d..8103d6a 100644
--- a/Source/Main.hx
+++ b/Source/Main.hx
@@ -115,14 +115,14 @@ class Wiggler extends Sprite
static inline var radiusGradient:Float = 5.0;
static inline var radiiSizes:Int = 15;
-
var path:Array<Point> = [];
-
var circles:Array<ColoredCircle> = [];
var bones:Map<Pt, Array<SkeletonNode>>;
+ var drift : Pt;
+
public function new (path:Array<Point>)
{
super();
@@ -130,6 +130,8 @@ class Wiggler extends Sprite
addCircles();
addBones();
+ drift = {x: Math.random() * Util.randomSign(), y: Math.random() * Util.randomSign()};
+
addEventListener(Event.ENTER_FRAME, perFrame);
//render();
}
@@ -403,6 +405,13 @@ function perFrame (e)
Util.rotatePtAboutPivot( hinge, follower, node.spin);
}
render();
+
+ this.x += drift.x;
+ this.y += drift.y;
+ if (this.x <= 0 || this.x + this.width >= stage.stageWidth)
+ drift.x *= -1;
+ if (this.y <= 0 || this.y + this.height >= stage.stageHeight)
+ drift.y *= -1;
}
static inline var ONE_DEGREE: Float = 0.01745329;
@@ -425,7 +434,8 @@ class DrawingScreen extends Sprite
suitable for passing in as the "skin" of a wiggler. */
var path: Array<Point> = [];
-
+ var wigglers:Array<Wiggler> = [];
+
var candidateWiggler:Wiggler;
var holdPath:Bool = false;
@@ -474,7 +484,8 @@ class DrawingScreen extends Sprite
Actuate.stop(this);
if (candidateWiggler != null)
{
- removeChild( candidateWiggler );
+ //removeChild( candidateWiggler );
+ wigglers.push(candidateWiggler);
candidateWiggler = null;
}
graphics.clear();
@@ -574,6 +585,11 @@ enum Line {
class Util
{
+ public static function randomSign():Int
+ {
+ return if ( cointoss() ) -1 else 1;
+ }
+
public static function cointoss():Bool
{
return Math.random() >= 0.5;