Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var createTerrain = function(size,dist,store,scale){
- this.dist = dist;
- this.size = size;
- this.storage = store;
- this.scale = scale;
- };
- createTerrain.prototype.pushNoise=function(){
- for(var i = 0; i < this.size; i++){
- noiseDetail(7,0.69);
- this.storage.push([abs((noise(i*random(0,100)*0.06,i*random(0,100)*0.03)-1)+1)*233]);
- }
- };
- createTerrain.prototype.drawMap = function(){
- for(var i = 0; i < this.storage.length-3; i++){
- stroke(82, 35, 35);
- line(30*i+80,this.storage[i+1],30*i+140,this.storage[i+3]);
- }
- };
- /**
- @TODO:
- Work on collisions with curves and stuff
- Create the physics for driving/hills and stuff
- */
- var keys = [];
- var keyPressed = function() {
- keys[keyCode] = true;
- };
- var keyReleased = function() {
- keys[keyCode] = false;
- };
- var level = [
- []
- ];
- var createTerrain = function(size,dist,store,scale){
- this.dist = dist;
- this.size = size;
- this.storage = store;
- this.scale = scale;
- };
- createTerrain.prototype.pushNoise=function(){
- for(var i = 0; i < this.size; i++){
- noiseDetail(7,0.69);
- this.storage.push([abs((noise(i*random(0,100)*0.06,i*random(0,100)*0.03)-1)+1)*233]);
- }
- };
- createTerrain.prototype.drawMap = function(){
- for(var i = 0; i < this.storage.length-3; i++){
- stroke(82, 35, 35);
- //translate(10,10);
- // scale(this.scale);
- line(30*i+80,this.storage[i+1],30*i+140,this.storage[i+3]);
- }
- // println(this.storage[0]);
- };
- var b = new createTerrain(20,20,level,1.01);
- var car = function(locatio, accel, image, dragcoof) {
- this.loc = locatio;
- this.accel = accel;
- //this.power = power;
- this.image = image;
- this.volocity = new PVector(0, 0);
- this.acceleration = new PVector(0, 0);
- this.drag = new PVector(0, 0);
- this.dragcoof = new PVector(dragcoof.x, dragcoof.y);
- };
- car.prototype.draw = function() {
- if (this.image === null) {
- //println("please put a nice image but I will supply a simple box for testing");
- //pushMatrix();
- fill(255, 0, 0);
- rect(this.loc.x, this.loc.y, 50, 10);
- //popMatrix();
- } else {
- this.image(this.loc.x, this.loc.y);
- }
- };
- car.prototype.update = function() {
- //this.momentum = this.volocity.mult(this.mass);
- if (this.volocity.x >= 10) {
- this.volocity.x = 9.99;
- }
- if (this.volocity.x <= 0.1) {
- this.volocity.x = 0;
- }
- this.volocity.add(this.acceleration);
- //this.volocity.add(-this.drag);
- // this.acceleration.sub(this.drag);
- this.loc.add(this.volocity);
- // this.drag = this.volocity.mult(this.dragcoof);
- this.drag = PVector.mult(this.volocity, this.dragcoof);
- this.volocity.sub(this.drag);
- if (this.loc.x >= 0) {
- //this.loc.x = 0;
- translate(-this.loc.x,0);
- // println(this.volocity);
- }
- //this.
- };
- car.prototype.move = function(keycodeLeft, keycodeRight) {
- if (keys[RIGHT] && this.volocity.x < 10) {
- this.acceleration.add(this.accel.x,0);
- }
- if (!keys[RIGHT] && !keys[LEFT]) {
- this.acceleration.set(0, 0);
- }
- if (keys[LEFT] && this.volocity.x >= 0.5) {
- this.acceleration.set(-0.1, 0);
- }
- //if(this.acceleration.x<0){
- // this.acceleration.x = 0;
- //}
- };
- var a = new car(new PVector(10, 200), new PVector(0.01,0), null, new PVector(0.022, 0));
- b.pushNoise();
- var draw = function() {
- background(255, 255, 255);
- a.draw();
- a.update();
- a.move();
- text(a.acceleration + "n" + a.volocity+"n"+a.drag, 25, 25);
- b.drawMap();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement