/* Parallax Clouds * inspired by Odin Sphere */ //import processing.opengl.*; import ddf.minim.*; // import fullscreen.*; ParallaxSystem parallaxSystem; //ParallaxSystem ps2; PFont font; PImage[] bird; int birdFrame; int birdFrameSpeed; // sound Minim minim; AudioPlayer groove; // timer int now; int then; PImage blueSky; PImage scanLines; // player float x; float y; float targetX, targetY; float easing = 0.05; // candy // FullScreen fs; void setup() { size(640,480); int[] systemTint = {240, 215, 200}; frameRate(60); noCursor(); //font = loadFont("ProggyClean-11.vlw"); //textFont(font, 11); // load our sprite sheet into frames PImage birdSheet = loadImage("textures/kloanasheet3.gif"); bird = new PImage[4]; bird[0] = birdSheet.get(354, 91, 27, 26 ); // 354x92 to 381x107 bird[1] = birdSheet.get(382, 91, 24, 26 ); // 382x92 to 406x107 bird[2] = birdSheet.get(406, 91, 24, 26 ); // 406x92 to ???x107 bird[3] = birdSheet.get(432, 91, 24, 26 ); // 432x92 to 406x107 birdFrame = 0; birdFrameSpeed = 0; minim = new Minim(this); groove = minim.loadFile("riagt.wav", 2048); // groove.play(); blueSky = loadImage("textures/cotopaxi_sized.png"); parallaxSystem = new ParallaxSystem(3, new Vector3d(-2.0, 0.0, 0.0), systemTint); scanLines = genScanLines(); groove.loop(); // fs = new FullScreen(this); //fs.enter(); } void draw() { then = now; float elapsed = 0; // wait for at least 1/100th of a second to pass while( elapsed < 1.0/100.0 ) { now = millis(); // compute elapsed time in seconds elapsed = (now - then) / 1000.0f; } background(0); tint(255,255,255,255); image(blueSky, 0, 0, blueSky.width, blueSky.height); parallaxSystem.draw(); parallaxSystem.run(elapsed); targetX = mouseX; float dx = targetX - x; if(abs(dx) > 1) { x += dx * easing; } targetY = mouseY; float dy = targetY - y; if(abs(dy) > 1) { y += dy * easing; } pushMatrix(); translate(x, y); image(bird[birdFrame], 0, 0); popMatrix(); tint(255,255,255,80); image(scanLines, 0, 0, scanLines.width, scanLines.height); if (birdFrameSpeed == 4) { birdFrame++; birdFrameSpeed = 0; } else { birdFrameSpeed++; } if (birdFrame == 4) { birdFrame = 0; } } public void stop() { groove.close(); minim.stop(); super.stop(); } PImage genScanLines() { PGraphics sl = createGraphics(width, height, P2D); int lineSize = 1; sl.beginDraw(); //sl.background(0); sl.stroke(0,0,0,20); //sl.tint(255,255,255,25); for (int i=0; i < height; i+=lineSize * 2) { sl.line(0,i,width,i); } sl.endDraw(); return sl; } class ParallaxSystem { ArrayList layers = new ArrayList(); ParallaxLayer [] paraLayers; float speedDiff = 0.95; float baseSpeed = -1.0; Vector3d systemLocation = new Vector3d(0, height * .40, 0); int[] systemTint; int numLayers; /* constructor arranges a list of layers * each tinted off base color, each moving * off base vector. */ public ParallaxSystem(int numLayers, Vector3d systemVelocity, int[] systemTint) { Vector3d layerVelocity = new Vector3d(); Vector3d layerPosition = new Vector3d(); Vector3d altLayerPosition = new Vector3d(); int scaleI = 25; // percent size increment int tintI = 15; // percent tint increment //this.systemTint = systemTint; this.numLayers = numLayers; paraLayers = new ParallaxLayer[numLayers]; String layerTexture = new String("textures/clouds.gif"); int layerScale; // this sets up layers from top to bottom for (int i=0; i < numLayers; i++) { // each layer gets progressively slower layerVelocity = systemVelocity.add(systemVelocity, new Vector3d(baseSpeed + (speedDiff * i), 0, 0)); //println(layerVelocity.x); //debug // each layer gets larget up to 100% off base size, this has to be tweaked manually // 100 - (numLayers * scaleI) layerScale = 100 - (i * scaleI); //println("LAYERSCALE " + layerScale); // each layer gets progressively lower on the screen layerPosition = systemLocation.add(systemLocation, new Vector3d(0, (float)-layerScale * i, -i)); //altLayerPosition = systemLocation.sub(systemLocation, new Vector3d(-1200, layerScale * -i, i)); // texture files need to follow convention //String layerTexture = new String("textures/clouds_" + i + ".png"); int[] layerTint = new int[2]; layerTint = systemTint; //layerTint[1] = systemTint[1]; // layer needs to fade tint layerTint[0] = systemTint[0] - (i * tintI); layerTint[1] = systemTint[1] - (i * tintI); layerTint[2] = systemTint[2] - (i * tintI); //print(" 0: " + layerTint[0]); //print(" 1: " + layerTint[1]); //print(" 2: " + layerTint[2] + "\n"); paraLayers[i] = new ParallaxLayer(layerTexture, layerVelocity, layerPosition, layerScale, layerTint); //layers.add(new ParallaxLayer(layerTexture, layerVelocity, layerPosition, layerScale, layerTint)); } } void draw() { /* for (int j = layers.size()-1; j >= 0; j--) { ParallaxLayer parallaxLayer = (ParallaxLayer) layers.get(j); parallaxLayer.render(); } */ for (int i = numLayers - 1; i >= 0; i--) { paraLayers[i].render(); } } // run our layers void run(float elapsed) { /* for (int j = layers.size()-1; j >= 0; j--) { ParallaxLayer parallaxLayer = (ParallaxLayer) layers.get(j); parallaxLayer.run(elapsed); if (parallaxLayer.dead()){ parallaxLayer.setLocationX(0); } } */ for (int i = numLayers - 1; i >= 0; i--) { paraLayers[i].run(elapsed); if (paraLayers[i].dead()) { paraLayers[i].setLocationX(0); } } } } class ParallaxLayer { Vector3d location; Vector3d velocity; Vector3d acceleration; PImage layerTexture; float speed; //Vector3d layerDirection; int tintR; int tintG; int tintB; //int[] layerTint = new int[2]; float layerScale; float w; float h; ParallaxLayer(String imageFile, Vector3d velocity, Vector3d location, int layerScale, int[] passedTint) { this.velocity = velocity; this.acceleration = new Vector3d(0,0,0); this.layerTexture = new PImage(); this.layerTexture = loadImage(imageFile); this.location = location; this.layerScale = (float)((float)layerScale/100); /* int dimension = (layerTexture.width * layerTexture.height); loadPixels(); float[] c = new float[3]; for (int i=0; i