HOME | DD

worm-xp — Cube-ism 2.0

Published: 2005-12-24 04:55:08 +0000 UTC; Views: 2436; Favourites: 29; Downloads: 271
Redirect to original
Description CONTROLS:
left/right - rotate current cube
up/down - change elevation
deleting cubes - drag them outside the grid
copy cubes - hold ctrl and click an existing cube

defineable colour cubes - hold ctrl when you click them to set the current colour to that cube for later use
--

Here we go!

Basically, i made this before, but i wasnt really happy with it. My major gripe was that i basically said "screw it, it's done" when it clearly wasn't. So this is sort of that "done" stage. I didnt want to try to sift through my crappy code looking for stuff to clean up, so using the little techniques i picked up from making the first, i started again.

The interface has been cleaned up heaps. Now, instead of having loads of cubes all of the same shape just different angles, they're all grouped, and you simply rotate to the one you want. Spiffy or what?

One of my favourite things in here is the ability to define your own colours, and then save em in the defineable colour cubes. There's 7 of em, each able to hold a colour and shadow strength you define. Cooooool

Next, copying now works! This was the most annoying thing to work out. I think what was happening before was that when two cubes' depths swapped, it tried to keep them dragging, but couldn't, so it made a new one to drag, then THAT one got its depth swapped, etc etc, or something.

So i just added a boolean variable AllowedToDuplicate (imaginative, or what?) and set it to true on mouse up, and false after a cubes been duplicated, so you have to wait till you release the mouse to make a new one)

Woot, eh?





For those of you who're interested, i'm gonna attach the code from the main stage. Note - it wasn't written with the intention that anyone but me would ever see it, so don't expect it to be all that well commented (read: it's not commented at all) or that logical. Read at your own risk!


Each cube type is a movieClip on its own, and inside is three things - the outline, the shadows, and the colour. Each of these has 4 frames, 1 for each angle that cube can be viewed at. That's about it, really!

cubeTypes = 11;
init();
function init() {
cubez = [];
n = 0;
//
Key.addListener(_root);
//
t = 0;
framesPerPush = 10;
canPush = true;
//
snapDist = 40;
//
allowedToDuplicate = true;
//
cubeDepthStart = 1000;
defineColourCubes();
createPoints();
defineDepths();
defineCreation();
}
function createPoints() {
numPoints = 100;
pointz = [];
//
xSize = 11;
ySize = 16;
xMin = placer_mc._x;
yMin = placer_mc._y;
xInt = 40;
yInt = 10;
xMax = xMin+xSize*xInt;
yMax = yMin+ySize*yInt*2+10;
xMod = 20;
x = xMin;
y = yMin;
//
for (i=0; y point = attachMovie("point", "point"+i, i+1);
pointz[i] = point;
point._x = x;
point._y = y;
point.depth = i;
x += xInt;
if (x>xMax) {
xMin += xMod;
x = xMin;
y += yInt;
if (xMod == 20) {
xMod = -20;
} else {
xMod = 20;
}
}
}
}
function defineDepths() {
currentDepth = 10;
levelsPerDepth = 10000;
depthz = [];
for (i=1; i<=20; i++) {
depthz[i] = new Object();
depthz[i].startValue = i*levelsPerDepth;
}
}
function defineColourCubes() {
//
defineableColours = 7;
colours = [30, 30, 30, 50, 50, 50, 70, 70, 70, 100, 100, 100, 84, 69, 51, 100, 84, 62, 70, 21, 14, 73, 67, 1, 8, 70, 0, 8, 70, 70, 6, 12, 70, 51, 1, 70, 100, 41, 34, 100, 100, 31, 38, 100, 21, 24, 100, 100, 16, 42, 100, 81, 31, 100];
colourCubes = colours.length/3+defineableColours;
for (i=1; i<=colourCubes; i++) {
_root["col"+i] = new Object();
_root["col"+i].red = colours[(i-1)*3];
_root["col"+i].green = colours[(i-1)*3+1];
_root["col"+i].blue = colours[(i-1)*3+2];
if (i>colourCubes-defineableColours) {
_root["col"+i].red = _root["col"+i].green=_root["col"+i].blue=100;
}
}
//
perRow = 6;
xMin = 210;
yMin = 400;
xJump = 30;
yMod1 = 30;
yMod = 15;
xInt = xMod=xJump/2;
xMax = perRow*(xJump-1)+xMin;
yInt = yMod;
x = xMin;
y = yMin;
colourCubez = [];
defineableXstart = 440;
defineableYstart = 410;
for (i=0; i colourCube = attachMovie("cube0", "colourCube"+i, i+10000);
colourCube._xscale = colourCube._yscale=75;
colourCube._x = x;
colourCube._y = y;
x += xJump;
if (x>xMax) {
xMin += xInt;
if (xInt == xMod) {
xInt = -xMod;
} else {
xInt = xMod;
}
x = xMin;
y += yMod1;
yMod1 = yMod;
}
colourCube.red = _root["col"+(i+1)].red;
colourCube.green = _root["col"+(i+1)].green;
colourCube.blue = _root["col"+(i+1)].blue;
colourCube.colourSetting = colourCube.red*2.55 << 16 | colourCube.green*2.55 << 8 | colourCube.blue*2.55;
colourCube.col = new Color(colourCube.colour);
colourCube.col.setRGB(colourCube.colourSetting);
colourCube.shadows._alpha = 50;
colourCubez[i] = colourCube;
if (i colourCube.onRelease = function() {
colourChooser.redBar.sliderBar._x = this.red;
colourChooser.greenBar.sliderBar._x = this.green;
colourChooser.blueBar.sliderBar._x = this.blue;
colourChooser.update();
updateColours();
};
}
}
for (i=0; i<2; i++) {
colourCubez[colourCubez.length-defineableColours+i]._x = defineableXstart+30*i;
colourCubez[colourCubez.length-defineableColours+i]._y = defineableYstart;
}
for (i=0; i<3; i++) {
colourCubez[colourCubez.length-defineableColours+2+i]._x = defineableXstart-xMod+30*i;
colourCubez[colourCubez.length-defineableColours+2+i]._y = defineableYstart+yMod;
}
for (i=0; i<2; i++) {
colourCubez[colourCubez.length-defineableColours+5+i]._x = defineableXstart+30*i;
colourCubez[colourCubez.length-defineableColours+5+i]._y = defineableYstart+2*yMod;
}
defineable = [];
for (i=0; i defineable[i] = colourCubez[colourCubez.length-defineableColours+i];
defineable[i].onRelease = function() {
if (Key.isDown(Key.CONTROL)) {
this.red = colourChooser.red/2.55;
this.green = colourChooser.green/2.55;
this.blue = colourChooser.blue/2.55;
this.colourSetting = this.red*2.55 << 16 | this.green*2.55 << 8 | this.blue*2.55;
this.col.setRGB(this.colourSetting);
this.shadows._alpha = colourChooser.alpha;
} else {
colourChooser.redBar.sliderBar._x = this.red;
colourChooser.greenBar.sliderBar._x = this.green;
colourChooser.blueBar.sliderBar._x = this.blue;
colourChooser.alphaBar.sliderBar._x = this.shadows._alpha;
}
};
}
}
function defineCreation() {
cubeType = [];
for (i=0; i cubeType[i] = _root["cube"+i];
cubeType[i].f = 1;
cubeType[i].cubeType = i;
//
cubeType[i].cubeColour = new Color(cubeType[i].colour);
cubeType[i].onPress = function() {
create(this);
};
}
}
function updateColours() {
for (i=0; i cubeType[i].cubeColour.setRGB(colourChooser.colour);
cubeType[i].shadows._alpha = colourChooser.alpha;
cubeType[i].outline._alpha = colourChooser.outline;
}
}
function create(cube) {
n++;
cubeDepth = n+cubeDepthStart;
newCube = attachMovie("cube"+cube.cubeType, "newCube"+n, cubeDepth);
newCube.cubeType = cube.cubeType;
cubez[n] = newCube;
newCube._x = cube._x;
newCube._y = cube._y;
newCube.f = cube.f;
newCube.cubeColour = new Color(newCube.colour);
newCube.cubeColour.setRGB(cube.cubeColour.getRGB());
newCube.shadows._alpha = cube.shadows._alpha;
newCube.outline._alpha = cube.outline._alpha;
newCube.shadows.gotoAndStop(newCube.f);
newCube.colour.gotoAndStop(newCube.f);
newCube.outline.gotoAndStop(newCube.f);
}
function duplicate(cube) {
create(cube);
}
onMouseUp = function () {
if (_xmouse>510 or _ymouse>390) {
removeMovieClip(newCube);
}
newCube = null;
allowedToDuplicate = true;
};
onKeyDown = function () {
if (Key.isDown(Key.BACKSPACE)) {
removeMovieClip(newCube);
}
if (Key.isDown(Key.UP)) {
if (currentDepth currentDepth++;
placer_mc.swapDepths(depthz[currentDepth].startValue-1);
}
} else if (Key.isDown(Key.DOWN)) {
if (currentDepth>1) {
currentDepth--;
placer_mc.swapDepths(depthz[currentDepth].startValue-1);
}
}
if (Key.isDown(Key.LEFT)) {
if (newCube.f newCube.f++;
} else {
newCube.f = 1;
}
newCube.shadows.gotoAndStop(newCube.f);
newCube.colour.gotoAndStop(newCube.f);
newCube.outline.gotoAndStop(newCube.f);
} else if (Key.isDown(Key.RIGHT)) {
if (newCube.f>1) {
newCube.f--;
} else {
newCube.f = newCube.shadows._totalframes;
}
newCube.shadows.gotoAndStop(newCube.f);
newCube.colour.gotoAndStop(newCube.f);
newCube.outline.gotoAndStop(newCube.f);
}
};
function sortDepths() {
for (i=0; i cubez[i].swapDepths(cubez[i].point.depth+cubez[i].depth);
}
}
onMouseMove = function () {
if (_xmouse>xMin-snapDist and _xmouseyMin-snapDist and _ymouse snap(newCube);
} else {
newCube._x = _xmouse;
newCube._y = _ymouse;
}
};
function snap(what) {
minDist = 1000;
for (j=0; j < pointz.length; j++) {
current = pointz[j];
dx = pointz[j]._x-_xmouse;
dy = pointz[j]._y-_ymouse;
dist = Math.sqrt(dx*dx+dy*dy);
if (dist minDist = dist;
closestPoint = j;
}
}
what.depth = depthz[currentDepth].startValue;
what.point = pointz[closestPoint];
what._x = pointz[closestPoint]._x;
what._y = pointz[closestPoint]._y;
what.onPress = function() {
if (Key.isDown(Key.CONTROL)) {
if (allowedToDuplicate) {
duplicate(what);
allowedToDuplicate = false;
}
} else {
newCube = what;
}
};
sortDepths();
}
Related content
Comments: 7

Sup-Gurl [2013-07-14 00:59:40 +0000 UTC]

soo cool .-.

👍: 0 ⏩: 0

NightSkiesRavens [2011-12-18 02:34:06 +0000 UTC]

THIS IS AN AWESOME GAME!

👍: 0 ⏩: 0

imAmazing [2007-12-28 09:05:51 +0000 UTC]

nice.

👍: 0 ⏩: 0

sven-is-kool [2007-09-15 05:05:27 +0000 UTC]

this is amazing!! it must have taken ages to make!!!
I've always wanted to make something like this but its to hard for me

👍: 0 ⏩: 0

0uk4m1 [2005-12-24 23:04:35 +0000 UTC]

oO''
ooooohh!
that's so complicated!
fav!

👍: 0 ⏩: 0

SenatorKang [2005-12-24 14:43:24 +0000 UTC]

Cooooool.... I especially like the bit where you have to flick the scroll wheel seventy billion times to get down to the comments bit

Also, joy for round things, like that funkeh thingo shape... coney funnely thing. i probably would know the name of the shape if i paid attention in calc.

Beach!

👍: 0 ⏩: 0

Ugghhzilla [2005-12-24 13:15:33 +0000 UTC]

Really nice app. Not something I've seen done before in Flash. I checked out the original version after trying this version and it really is a major improvement.

👍: 0 ⏩: 0