Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. var createTerrain = function(size,dist,store,scale){
  2. this.dist = dist;
  3. this.size = size;
  4. this.storage = store;
  5. this.scale = scale;
  6.  
  7. };
  8.  
  9. createTerrain.prototype.pushNoise=function(){
  10. for(var i = 0; i < this.size; i++){
  11.  
  12. noiseDetail(7,0.69);
  13. this.storage.push([abs((noise(i*random(0,100)*0.06,i*random(0,100)*0.03)-1)+1)*233]);
  14.  
  15. }
  16. };
  17. createTerrain.prototype.drawMap = function(){
  18.  
  19. for(var i = 0; i < this.storage.length-3; i++){
  20. stroke(82, 35, 35);
  21.  
  22. line(30*i+80,this.storage[i+1],30*i+140,this.storage[i+3]);
  23.  
  24. }
  25.  
  26. };
  27.  
  28. /**
  29. @TODO:
  30. Work on collisions with curves and stuff
  31. Create the physics for driving/hills and stuff
  32.  
  33. */
  34.  
  35.  
  36.  
  37. var keys = [];
  38. var keyPressed = function() {
  39. keys[keyCode] = true;
  40. };
  41. var keyReleased = function() {
  42. keys[keyCode] = false;
  43. };
  44. var level = [
  45. []
  46.  
  47. ];
  48. var createTerrain = function(size,dist,store,scale){
  49. this.dist = dist;
  50. this.size = size;
  51. this.storage = store;
  52. this.scale = scale;
  53.  
  54. };
  55.  
  56. createTerrain.prototype.pushNoise=function(){
  57. for(var i = 0; i < this.size; i++){
  58.  
  59. noiseDetail(7,0.69);
  60. this.storage.push([abs((noise(i*random(0,100)*0.06,i*random(0,100)*0.03)-1)+1)*233]);
  61.  
  62. }
  63. };
  64. createTerrain.prototype.drawMap = function(){
  65.  
  66. for(var i = 0; i < this.storage.length-3; i++){
  67. stroke(82, 35, 35);
  68. //translate(10,10);
  69. // scale(this.scale);
  70. line(30*i+80,this.storage[i+1],30*i+140,this.storage[i+3]);
  71.  
  72. }
  73. // println(this.storage[0]);
  74. };
  75. var b = new createTerrain(20,20,level,1.01);
  76.  
  77. var car = function(locatio, accel, image, dragcoof) {
  78. this.loc = locatio;
  79. this.accel = accel;
  80. //this.power = power;
  81. this.image = image;
  82. this.volocity = new PVector(0, 0);
  83. this.acceleration = new PVector(0, 0);
  84. this.drag = new PVector(0, 0);
  85. this.dragcoof = new PVector(dragcoof.x, dragcoof.y);
  86. };
  87. car.prototype.draw = function() {
  88. if (this.image === null) {
  89. //println("please put a nice image but I will supply a simple box for testing");
  90. //pushMatrix();
  91. fill(255, 0, 0);
  92. rect(this.loc.x, this.loc.y, 50, 10);
  93. //popMatrix();
  94. } else {
  95. this.image(this.loc.x, this.loc.y);
  96. }
  97. };
  98. car.prototype.update = function() {
  99. //this.momentum = this.volocity.mult(this.mass);
  100. if (this.volocity.x >= 10) {
  101. this.volocity.x = 9.99;
  102. }
  103. if (this.volocity.x <= 0.1) {
  104. this.volocity.x = 0;
  105. }
  106. this.volocity.add(this.acceleration);
  107. //this.volocity.add(-this.drag);
  108. // this.acceleration.sub(this.drag);
  109. this.loc.add(this.volocity);
  110. // this.drag = this.volocity.mult(this.dragcoof);
  111. this.drag = PVector.mult(this.volocity, this.dragcoof);
  112. this.volocity.sub(this.drag);
  113. if (this.loc.x >= 0) {
  114. //this.loc.x = 0;
  115. translate(-this.loc.x,0);
  116. // println(this.volocity);
  117.  
  118. }
  119. //this.
  120. };
  121. car.prototype.move = function(keycodeLeft, keycodeRight) {
  122. if (keys[RIGHT] && this.volocity.x < 10) {
  123. this.acceleration.add(this.accel.x,0);
  124. }
  125. if (!keys[RIGHT] && !keys[LEFT]) {
  126.  
  127. this.acceleration.set(0, 0);
  128. }
  129. if (keys[LEFT] && this.volocity.x >= 0.5) {
  130. this.acceleration.set(-0.1, 0);
  131. }
  132.  
  133. //if(this.acceleration.x<0){
  134. // this.acceleration.x = 0;
  135.  
  136. //}
  137. };
  138. var a = new car(new PVector(10, 200), new PVector(0.01,0), null, new PVector(0.022, 0));
  139. b.pushNoise();
  140. var draw = function() {
  141. background(255, 255, 255);
  142. a.draw();
  143. a.update();
  144. a.move();
  145. text(a.acceleration + "n" + a.volocity+"n"+a.drag, 25, 25);
  146.  
  147. b.drawMap();
  148.  
  149.  
  150. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement