class Terrain implements Drawable { int[][] points; Terrain() { reset(); } void addPoint(int x, int y) { if (points.length > 0) { x = constrain(x, points[points.length - 1][0]+1, scene.WIDTH); } int[] point = {x, constrain(y, (scene.HEIGHT / 4), scene.HEIGHT-1) }; points = (int[][]) append(points, point); } int heightAt(int x) { float d = 0; if(points.length == 4) return scene.HEIGHT / 4; for(int i = 2; i < points.length-1; i++) { if(points[i][0] <= x && points[i+1][0] > x) { if(points[i][0] == x || points[i][1] == points[i+1][1]) return scene.HEIGHT - points[i][1]; d = int( (plane.posX - points[i][0]) / (points[i+1][0] - points[i][0]) * (points[i][1] - points[i+1][1]) ); return int(scene.HEIGHT - points[i][1] + d); } } return 0; } void reset() { points = new int[0][2]; int[] point0 = { scene.WIDTH, scene.HEIGHT - scene.HEIGHT / 4 }; points = (int[][]) append(points, point0); int[] point1 = { scene.WIDTH, scene.HEIGHT }; points = (int[][]) append(points, point1); int[] point2 = { 0, scene.HEIGHT }; points = (int[][]) append(points, point2); int[] point3 = { 0, scene.HEIGHT - scene.HEIGHT / 4 }; points = (int[][]) append(points, point3); } void draw() { fill(74, 152, 45); beginShape(); for(int i = 0; i < points.length; i++) { vertex(points[i][0], points[i][1]); } endShape(CLOSE); } }