hardest part of integrating with jigsawX

This commit is contained in:
2022-07-08 22:54:53 +00:00
parent 9b50f893f0
commit 5fa18b4ba0
6 changed files with 116 additions and 63 deletions

View File

@@ -1,4 +1,5 @@
package jigsawx;
import flixel.math.FlxRandom;
typedef JigsawPieceData = {
var north: JigsawSideData;
var east: JigsawSideData;
@@ -24,14 +25,14 @@ class JigsawSideData{
public var rightWide: Float;
public var rightHi: Float;
// returns half a jigsawPieceData, the other side is populated from piece above and from left
public static function halfPieceData(): JigsawPieceData{
#if !noRandom return { north: null, east: create(), south: create(), west: null };
public static function halfPieceData(r:FlxRandom): JigsawPieceData{
#if !noRandom return { north: null, east: create(r), south: create(r), west: null };
// Test use -D noRandom
#else return { north: null, east: createSimple(), south: createSimple(), west: null };
#else return { north: null, east: createSimple(r), south: createSimple(r), west: null };
#end
}
private static function createBubble(): Bubble {
return ( Math.round( Math.random() ) == 1 )? IN: OUT;
private static function createBubble(r:FlxRandom): Bubble {
return r.bool() ? IN: OUT;
}
private static function swapBubble( bubble: Bubble ): Bubble {
if( bubble == OUT ) return IN;
@@ -56,9 +57,9 @@ class JigsawSideData{
return side;
}
// when you want to test no random.
public static function createSimple(): JigsawSideData {
public static function createSimple(r:FlxRandom): JigsawSideData {
var side = new JigsawSideData();
side.bubble = createBubble();
side.bubble = createBubble(r);
//left right or up dawn offset.
side.squew = 0.5;
// in out
@@ -72,20 +73,20 @@ class JigsawSideData{
side.rightHi = 0.5;
return side;
}
public static function create(): JigsawSideData {
public static function create(r:FlxRandom): JigsawSideData {
var side = new JigsawSideData();
side.bubble = createBubble();
side.bubble = createBubble(r);
//left right or up dawn offset.
side.squew = Math.random();
side.squew = r.float();
// in out
side.inout = Math.random();
side.inout = r.float();
// radii of ellipses
side.leftWide = Math.random();
side.leftHi = Math.random();
side.centreWide = Math.random();
side.centreHi = Math.random();
side.rightWide = Math.random();
side.rightHi = Math.random();
side.leftWide = r.float();
side.leftHi = r.float();
side.centreWide = r.float();
side.centreHi = r.float();
side.rightWide = r.float();
side.rightHi = r.float();
return side;
}
// use create instead

View File

@@ -3,6 +3,7 @@ import jigsawx.OpenEllipse ;
import jigsawx.JigsawPiece ;
import jigsawx.math.Vec2;
import jigsawx.JigsawSideData;
import flixel.math.FlxRandom;
class Jigsawx {
private var rows: Int;
private var cols: Int;
@@ -16,31 +17,32 @@ class Jigsawx {
private var dx: Float;
private var dy: Float;
private var length: Int;
public function new( dx_: Float
, dy_: Float
public function new( pieceWidth: Float
, pieceHeight: Float
, edgeLeeway: Float
, rows_: Int
, cols_: Int
) {
, r: FlxRandom) {
pieces = [];
jigs = [];
sides = [];
dx = dx_;
dy = dy_;
dx = pieceWidth - edgeLeeway * 2;
dy = pieceHeight - edgeLeeway * 2;
rows = rows_;
cols = cols_;
//corners, theoretically JigsawSideData could be modified to allow these to have a random element.
var xy = new Vec2( 20, 20 );
var lt = new Vec2( 20, 20 );
var rt = new Vec2( 20 + dx, 20 );
var rb = new Vec2( 20 + dx, dy + 20 );
var lb = new Vec2( 20, dy + 20 );
var xy = new Vec2( edgeLeeway, edgeLeeway );
var lt = new Vec2( edgeLeeway, edgeLeeway );
var rt = new Vec2( edgeLeeway + dx, edgeLeeway );
var rb = new Vec2( edgeLeeway + dx, dy + edgeLeeway );
var lb = new Vec2( edgeLeeway, dy + edgeLeeway );
length = 0;
var last: JigsawPieceData;
for( row in 0...rows ){
last = { north: null, east: null, south: null, west: null };
sides.push( new Array() );
for( col in 0...cols ){
var jigsawPiece = JigsawSideData.halfPieceData();
var jigsawPiece = JigsawSideData.halfPieceData(r);
if( last.east != null ) jigsawPiece.west = JigsawSideData.reflect( last.east );
if( col == cols - 1 ) jigsawPiece.east = null;
sides[ row ][ col ] = jigsawPiece;
@@ -66,7 +68,7 @@ class Jigsawx {
jigs.push( jig );
xy.x += dx;
}
xy.x = 20;
xy.x = edgeLeeway;
xy.y += dy;
}
}

View File

@@ -31,7 +31,7 @@
*/
package jigsawx.hxopenfl;
package jigsawx;