Jump to content

Anyone want to take try to revive a very old Philippe Rosedale's Magic Blocks game?


Deep Semaphore
 Share

You are about to reply to a thread that has been inactive for 4250 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello,

I tried but could not get it to work. Anyone wants to try?

The code is available here:

http://www.foxsan.com/scripts/tag/lego/

above site says:

A fun toy and made by Philip Linden!  Hours of very fun, and pleasure.
Click and drag the block to position.  Block will snap into position when near other blocks.
Click and quickly release to make a new block above the old.

vector pos;
vector found_pos;
vector start_touch_pos;
vector diff;
vector scale;
string name_detected;
 
vector PULSE_COLOR = <1,1,1>;
 
float GRAB_ALPHA = 0.5;
float INC = 2.0;                    // Grid spacing for snap, scale
float MAX_INC = 2.5;                // Biggest dimension
 
list colors = [<1,0,0>, <0,1,0>, <0,0,1>,
                <0,1,1>, <1,0,1>, <1,1,0>];
 
//list tones = ["piano_1", "piano_3", "piano_5"];
 
vector color;
integer color_index = 0; 
 
integer CHANNEL = 3442;
integer pulse = FALSE;
integer inhibit = FALSE;
float INHIBIT_DELAY = 2.0;
float DECAY_FACTOR = 0.5;
 
send_pulse()
{
    // Change color briefly and transmit a neural 'pulse'
    inhibit = TRUE;
    llSetTimerEvent(INHIBIT_DELAY);
    //integer tone = llRound(llFrand((float)(llGetListLength(tones) - 1)));
    //llTriggerSound(llList2String(tones, tone), 1.0);
    llSetColor(PULSE_COLOR, ALL_SIDES);
    llSetObjectName("Magic Block P");
    llWhisper(CHANNEL, "pulse");
}
 
vector vec_round(vector vec, float inc)
{
    //  Rounds vector components to the nearest units of inc
    vec *= 1.0/inc;
    vec.x = ((float)llRound(vec.x));
    vec.y = ((float)llRound(vec.y));
    vec.z = ((float)llRound(vec.z));
    vec *= inc;
    return vec;
}
 
set_pos()
{
   //
   //  On finding a neighbor, snap relative to neighbor
   //
   pos = llGetPos();
    llSetColor(color*0.5, ALL_SIDES);
    diff = pos - found_pos;
    diff = vec_round(diff, INC/2.0);
    diff += found_pos;
    llSetPos(diff);
    llTriggerSound("on", 1.0);
    llSetColor(color, ALL_SIDES);
}
 
vector new_color()
{
    integer num_colors = llGetListLength(colors);
    color_index++;
    if (color_index >= num_colors) color_index = 0;
    return llList2Vector(colors, color_index);
}
 
snap()
{
    //  Issues the sensor to look for nearby blocks to snap to
    float range = 3.0;
    llSensor("Magic Block", "", PASSIVE | SCRIPTED, range, 2.0*PI);
}
 
default
{
    state_entry()
    {
        scale = llGetScale();
        color = new_color();
        llSetColor(color, ALL_SIDES);
        llSetStatus(STATUS_BLOCK_GRAB, FALSE);
        llSetBuoyancy(1.0);
        llListen(CHANNEL, "", "", "pulse");
    }
 
    on_rez(integer param)
    {
        found_pos = llGetPos();
        set_pos();
        snap();
    }
 
    timer()
    {
        llSetObjectName("Magic Block");
        llSetTimerEvent(0.0);
        inhibit = FALSE;
        llSetColor(color, ALL_SIDES);
    }
 
    changed(integer change)
    {
        if (change == CHANGED_SCALE)
        {
            scale = llGetScale();
            scale = vec_round(scale, INC);
            if (scale.x == 0.0) scale.x = INC;
            if (scale.y == 0.0) scale.y = INC;
            if (scale.z == 0.0) scale.z = INC;
            if (scale.x > MAX_INC) scale.x = MAX_INC;
            if (scale.y > MAX_INC) scale.y = MAX_INC;
            if (scale.z > MAX_INC) scale.z = MAX_INC;
            llSay(0, "new scale = " + (string)scale);
            llSetScale(scale);
            // Choose a new color for the block
            snap();
        }
    }
 
    touch_start(integer total_number)
    {
        start_touch_pos = llGetPos();
        llSetAlpha(GRAB_ALPHA, ALL_SIDES);
        llTriggerSound("on", 1.0);
        llResetTime();
        llSetStatus(STATUS_PHYSICS, FALSE);
    }
    touch_end(integer total_number)
    {
        llSetStatus(STATUS_PHYSICS, FALSE);
        llSetAlpha(1.0, ALL_SIDES);
        vector moved = llGetPos() - start_touch_pos;
 
        if (llGetTime() < 0.3)
        {
            //  Cycle colors on short click
            llSetPos(start_touch_pos);
            llTriggerSound("color", 1.0);
            color = new_color();
            llSetColor(color, ALL_SIDES);
        }
        else if (llVecMag(moved) < (INC/10.0))
        {
            llSetPos(start_touch_pos);
            send_pulse();
        }
        else
        {
            // Try to find a block to stick to!
            llSetColor(color, ALL_SIDES);
            snap();
        }
        llSetRot(<0,0,0,1>);
    }
 
    listen(integer channel, string name, key id, string message)
    {
        // Received neural pulse, so sense sender's distance
        if (!inhibit)
        {
            pulse = TRUE;
            llSensor("Magic Block P", id, PASSIVE | SCRIPTED, 10.0, 2.0*PI);
        }
    }
 
    no_sensor()
    {
        pulse = FALSE;
    }
    sensor(integer num_detected)
    {
        if (!pulse)
        {
            //
            //  Rotate/snap to nearest box
            //
            //  Issue scale request to this box
            //
            found_pos = llDetectedPos(0);
            set_pos();
        }
        else
        {
            //
            //  Gauge distance to nearest box, decide whether to 'fire'
            //
            pulse = FALSE;
            pos = llGetPos();
            found_pos = llDetectedPos(0);
            diff = pos - found_pos;
            // probability of neural firing is related to distance
            float distance = llVecMag(diff);
            if (distance > 0.0)
            {
                if (distance < INC)
                //if (llFrand(1.0) < ((INC/(distance*distance))*DECAY_FACTOR))
                {
                    send_pulse();
                }
            }
        }
    }
}
**Only uploaded images may be used in postings**://www.foxsan.com/scripts/wp-content/plugins/addmarx/sharebookmarx.png" border="0" />

 

Link to comment
Share on other sites

I can't get in world to test this script, but it compiles OK. If the directions are to be believed, there's something missing here, though. There's no way that clicking and quickly releasing is going to create a new block.  There's no llRezAtRoot statement in the script.  The script obviously assumes that the block is initially physical too, since it makes the block non-physical when you touch it. 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4250 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...