dim3 Forum

Full Version: Scruffy Scripts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm posting a couple in-dev Scruffy scripts to help out some people doing 2D like games (as everybody has my 3D scripts.)

This is the balloon snake, he's a snake built up of a bunch of balloons. Every hit pops up a balloon and speeds up the snake a bit. All the snake does is get spawned and then go until it hits something and then turns around (very much like a green mario turtle.)

Code:
var balloonPop=0;
var balloonDamageTick=0;

function snakeConstruct(obj)
{
    obj.model.on=true;
    obj.model.name="Balloon Snake";
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;
    obj.model.shadow.on=true;

    obj.setting.suspend=false;
    obj.setting.damage=true;
    obj.setting.invincible=true;
    obj.setting.ignorePickUpItems=true;
    obj.setting.singleSpeed=true;

    obj.forwardSpeed.acceleration=100;
    obj.forwardSpeed.deceleration=100;
    obj.turnSpeed.facingWalk=360;
    obj.turnSpeed.motionWalk=360;

    obj.lock.z=true;
    
    obj.size.x=1400;
    obj.size.z=1400;
    obj.size.y=5500;
    
    obj.size.weight=10000;        // don't be pushed around by explosions

    obj.melee.strikeBoneTag='base';
    obj.melee.strikePoseName='Idle';
    obj.melee.radius=2500;
    obj.melee.distance=0;
    obj.melee.damage=5;
    obj.melee.force=10;
}

function snakeSpawn(obj)
{
    var            i;
    
    obj.model.animation.showOnlyMesh('Seg0');
    
    balloonPop=0;
    obj.model.offset.y=0;
    obj.size.y=5500;

    obj.forwardSpeed.walk=30;

    obj.angle.rotateTo(270);
    obj.model.rotate.y=280;

    obj.motionVector.go();
    
    obj.model.animation.start('Walk');
}

function snakeCollide(obj)
{
    if (obj.angle.y==90) {
        obj.angle.rotateTo(270);
        obj.model.rotate.y=280;
    }
    else {
        obj.angle.rotateTo(90);
        obj.model.rotate.y=80;
    }
}

function snakeTouch(obj)
{
        // reverse snake

    snakeCollide(obj);

        // hurt player if touching

    if (obj.touch.objectId==map.object.findPlayer()) obj.melee.spawnFromObjectBone();        
}


function snakeDamage(obj,tick)
{
        // can only damage once per 1/2 a second
        
    if (balloonDamageTick>tick) return;
    
    balloonDamageTick=tick+500;
    
        // pop balloon
        
    balloonPop++;
    
    sound.play("Cloud Pop",obj.position.x,obj.position.z,obj.position.y,(0.5-((4-balloonPop)*0.15)));
    
        // snake all gone?
        
    if (balloonPop==4) {
        obj.motionVector.stop();
        obj.setting.hidden=true;
        obj.setting.contact=false;
        return;
    }
    
        // remove a balloon
        
    obj.model.animation.showOnlyMesh('Seg'+balloonPop);

    obj.size.y-=1400;

        // speed up snake

    obj.forwardSpeed.walk+=20;

        // turn snake around

    snakeCollide(obj,tick);
}

//
// events
//

function event(obj,mainEvent,subEvent,id,tick)
{
    switch (mainEvent) {
    
        case DIM3_EVENT_CONSTRUCT:
            snakeConstruct(obj);
            return;
    
        case DIM3_EVENT_SPAWN:
            snakeSpawn(obj);
            return;

        case DIM3_EVENT_COLLIDE:
            snakeCollide(obj);
            return;

        case DIM3_EVENT_TOUCH:
            snakeTouch(obj);
            return;
            
        case DIM3_EVENT_DAMAGE:
            snakeDamage(obj,tick);
            return;
            
    }
}

[>] Brian
Reference URL's