/* global variables */ // the terrain contains the bitmap for all the static pixels Terrain terrain; // the background image is drawn behind the terrain PImage bg; // physics and rendering engines Physics physics; // has a list of all physics objects, and uses their velocity to move them Renderer renderer; // has a list of all renderable objects, and calls their draw() method Player player; // translation, used to keep track of where the camera is int translateX; int translateY; // setup(), called before any looping is done void setup() { size(600,450, JAVA2D); // load our images for terrain and background bg = loadImage("bg/sky-blurry.png"); terrain = new Terrain(loadImage("maps/more-trees.png"), 2); // new Terrain(image, destructionRes) // initialize the physics and rendering engines physics = new Physics(); renderer = new Renderer(); // create the player player = new Player(100,100); physics.add(player); renderer.add(player); } // Draw loop void draw() { // update physics physics.update(); // load changes into the terrain terrain.update(); /* Rendering */ // first move our perspective to where the player is translateX = (int)constrain(width/2 - player.x, width - terrain.width(), 0); translateY = (int)constrain(height/2 - player.y, height - terrain.height(), 0); translate(translateX, translateY); // render the background background(255); image(bg,translateX * -0.8, translateY * -0.8); // draw the terrain terrain.draw(0,0); // show terrain normals //showNormals(); // draw everything else renderer.draw(); }