A Tipsy Adventure – vtavarez

For this piece, I wanted to use the walking animation that we used in a previous assignment to take our walker on an adventure. I decided to make the figures of this adventure and was happy to figure out a way to make it seem like it is going really slow. There are times where he randomly disappears as everything else in this piece seemingly fades away. It was difficult to figure out the mechanics to making the looping work, but once I did I was able to apply it to the two main objects that I created. I was hoping to get the character to move around like a game but didn’t get that far. Maybe next time I will get it.

landscape-sketch

sketch-31.js

//Victor Tavarez
//Secion D
//vtavarez@andrew.cmu.edu
//Project-10-Landscape


var frames = []; // An array to store the images
var lamps = [];
var lights = []

//=====Code directly from HomeWork 9 for walking man
//---------------------------------------
function preload(){
    // These URLs are for the individual walk cycle images,
    // stored in the imgur album http://imgur.com/a/85DTu
    var filenames = [];
    filenames[0] = "http://i.imgur.com/svA3cqA.png";
    filenames[1] = "http://i.imgur.com/jV3FsVQ.png";
    filenames[2] = "http://i.imgur.com/IgQDmRK.png";
    filenames[3] = "http://i.imgur.com/kmVGuo9.png";
    filenames[4] = "http://i.imgur.com/jcMNeGq.png";
    filenames[5] = "http://i.imgur.com/ttJGwkt.png";
    filenames[6] = "http://i.imgur.com/9tL5TRr.png";
    filenames[7] = "http://i.imgur.com/IYn7mIB.png";
    // PUT CODE HERE TO LOAD THE IMAGES INTO THE frames ARRAY,
    // USING THE FILENAMES STORED IN THE filenames ARRAY.
    for (var i=0; i < filenames.length; i++){
        frames.push(loadImage(filenames[i]));
    }  
}
function setup(){
    createCanvas(600,400);
    imageMode(CENTER);
    //create lamps
    for(var i=0; i<6; i++){
        var rx=random(width);
        var rx2=random(width);
        lamps.push(makeLamps(rx));
        lights.push(makeLights(rx2));
    }
    frameRate(10);    
}
//---------------------------------------
function draw() {
    background(0,30,30,30);
    updateAndDisplayLights();
    removeLights();
    addNewLights();   
      
    updateAndDisplayLamps();
    removeLamps();
    addNewLamps();
    //walker from HW 9
}
function drawWalker(y){
    noStroke();  
    var currentFrame = frameCount % 8;
    push();     
    image(frames[currentFrame], width/2, height-50);
    pop()
}
function removeLamps(){
    var lampsToKeep = [];
    for (var i=0; i<lamps.length; i++){
        if (lamps[i].x + lamps[i].lampWidth >0){
            lampsToKeep.push(lamps[i])
        }
    }
    lamps=lampsToKeep
}
function removeLights(){
    var lightsToKeep = [];
    for (var i=0; i<lights.length; i++){
        if (lights[i].x + lights[i].size >0){
            lightsToKeep.push(lights[i])
        }
    }    
    lights=lightsToKeep

}
function addNewLamps(){
    var newLampsProbability = 0.06;
    if (random(0,1) < newLampsProbability){
        lamps.push(makeLamps(width));
    }
}
function addNewLights(){
    var newLightsProbability = 0.9;
    if (random(0,1) < newLightsProbability){
        lights.push(makeLights(width));
    }
}
function updateAndDisplayLamps(){
    for (var i=0; i<lamps.length; i++){
        lamps[i].move();
        lamps[i].display();
    }
}
function updateAndDisplayLights(){
    for (var i=0; i<lights.length; i++){
        lights[i].move();
        lights[i].display();
    }
}
function lampMove(){
    this.x+=this.speed;
}
function lightsMove(){
    this.x+=this.speed;
}
function lampDisplay(){
    fill(255,random(200,255),random(130,255));
    stroke(0);
    push();
    rect(this.x,0,this.lampWidth,this.lampHeight);

    rect(this.x,this.lampHeight+150,this.lampWidth,height)
    pop();

    drawWalker(this.lampHeight+75);
}
function lightsDisplay(){
    fill(random(200,255),random(230,255),random(200,255),40);
    noStroke()
    push();
    ellipse(this.x,this.y,this.size,this.size)
    pop();
}
function makeLamps(birthLocationX){
    var lamp = {x: birthLocationX,
                lampWidth: random(5,10),
                speed: -10.0,
                lampHeight: random(50,250),
                move: lampMove,
                display: lampDisplay}
    return lamp;
}
function makeLights(birthLocationX){
    var lamp = {x: birthLocationX,
                y: random(0,height),
                size: random(5,30),
                speed: -1*random(1,10),
                move: lightsMove,
                display: lightsDisplay}
    return lamp;
}

Leave a Reply