Nik333

Robert Racing 0.6

Oct 8th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1. var mud,tar,goal,zipper,spawn,init,collide,speed,gspeed;var startpos = [20,380,270];
  2. var car,gcar,canwin=true,frame,extra=[];
  3.  
  4. ///////////////////////////////////////////////
  5.  
  6. var ghost = [[2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2],11.27];
  7.  
  8. var level = function(){
  9. mud(45,45,45,30);mud(0,150,45,40);mud(75,260,225,60);mud(117,100,5,100);mud(250,60,50,100);mud(335,60,30,50);mud(350,160,50,50);mud(300,260,50,50);mud(75,365,225,60);goal(75,365,50,40);tar(350,365,50,50);tar(45,75,45,500);tar(150,0,50,220);tar(250,60,50,70);tar(250,160,50,160);tar(45,300,255,40);tar(-5,-5,500,5);tar(400,-5,5,500);
  10. };
  11.  
  12. ///////////////////////////////////////////////
  13.  
  14. var version = "v0.6";
  15.  
  16. var speedorig = 2;
  17. var driftorig = 2;
  18. var timer = 0;
  19. var frame = 0;
  20. if (ghost==="insert custom ghost here"){
  21. ghost=[[],""];
  22. }
  23. if (ghost.length===2){
  24. ghost.push("pre-0.5.1");
  25. }
  26. var recorder = [];
  27. var previoustime = "";
  28.  
  29. var car = [];car[0]=startpos[0];car[1]=startpos[1];car[2]=startpos[2];
  30. var gcar = [];gcar[0]=startpos[0];gcar[1]=startpos[1];gcar[2]=startpos[2];
  31. var speed=speedorig;
  32. var drift=driftorig;
  33. var gspeed=speedorig;
  34. var gdrift=driftorig;
  35. var bugfix = true;
  36.  
  37. var keys = [];
  38. var keyPressed = function(){keys[keyCode] = true;if (keyCode===71){println("[["+ghost[0]+"],"+ghost[1]+","+'"'+ghost[2]+'"]');}};
  39. var keyReleased = function(){keys[keyCode]=false;};
  40.  
  41. var drawcar = function(x,y){
  42. fill(255);
  43. stroke(0);
  44. rect(x-10,y-5,20,10);
  45. };
  46. var drawghost = function(x,y){
  47. fill(0,0,255,50);
  48. noStroke();
  49. rect(x-10,y-5,20,10);
  50. };
  51. var gameend = function(){
  52. if (nf(timer,1,2)-0<=ghost[1]-0||ghost[1]===""){
  53. ghost[0]=[];
  54. for (var i=0;i<recorder.length;i++){
  55. ghost[0].push(recorder[i]);
  56. }
  57. ghost[1]=nf(timer,1,2);
  58. ghost[2]=version;
  59. }
  60. previoustime=nf(timer,1,2);
  61. timer=0;
  62. frame=0;
  63. car[0]=startpos[0];gcar[0]=startpos[0];
  64. car[1]=startpos[1];gcar[1]=startpos[1];
  65. car[2]=startpos[2];gcar[2]=startpos[2];
  66. recorder=[];
  67. };
  68. var restart = function(){
  69. timer=0;
  70. frame=0;
  71. canwin=true;
  72. car[0]=startpos[0];gcar[0]=startpos[0];
  73. car[1]=startpos[1];gcar[1]=startpos[1];
  74. car[2]=startpos[2];gcar[2]=startpos[2];
  75. recorder=[];
  76. if (init) {
  77. init();
  78. }
  79. };
  80.  
  81. var spawn = function(x,y,a){
  82. startpos[0]=x;
  83. startpos[1]=y;
  84. startpos[2]=a;
  85. };
  86. var collide = function(x,y,l,w,ghost){
  87. if (!ghost&&car[0]+5>x&&car[0]-5<x+l&&car[1]+5>y&&car[1]-5<y+w){
  88. return true;
  89. }
  90. if (ghost&&gcar[0]+5>x&&gcar[0]-5<x+l&&gcar[1]+5>y&&gcar[1]-5<y+w){
  91. return true;
  92. }
  93. return false;
  94. };
  95. var tar = function(x,y,l,w){
  96. fill(0);
  97. noStroke();
  98. rect(x,y,l,w);
  99. if (collide(x,y,l,w,false)){
  100. speed=0;
  101. }
  102. if (collide(x,y,l,w,true)){
  103. gspeed=0;
  104. }
  105. };
  106. var mud = function(x,y,l,w){
  107. fill(100,50,0);
  108. noStroke();
  109. rect(x,y,l,w);
  110. if (collide(x,y,l,w,false)){
  111. speed=speedorig/2;
  112. }
  113. if (collide(x,y,l,w,true)){
  114. gspeed=speedorig/2;
  115. }
  116. };
  117. var zipper = function(x,y,l,w){
  118. fill(255,0,255);
  119. noStroke();
  120. rect(x,y,l,w);
  121. if (collide(x,y,l,w,false)){
  122. speed=speedorig*2;
  123. }
  124. if (collide(x,y,l,w,true)){
  125. gspeed=speedorig*2;
  126. }
  127. };
  128. var goal = function(x,y,l,w){
  129. if (canwin) {
  130. fill(255,0,0);
  131. noStroke();
  132. rect(x,y,l,w);
  133. if (collide(x,y,l,w,false)){
  134. gameend();
  135. bugfix=true;
  136. }
  137. }
  138. };
  139.  
  140. draw = function() {
  141. speed=speedorig;gspeed=speedorig;
  142. timer+=(1/60);
  143. frame+=1;
  144. background(255);
  145. level();
  146. pushMatrix();
  147. translate(gcar[0],gcar[1]);
  148. rotate(gcar[2]);
  149. if (ghost[1]!==""){
  150. drawghost(0,0);
  151. }
  152. popMatrix();
  153. pushMatrix();
  154. translate(car[0],car[1]);
  155. rotate(car[2]);
  156. drawcar(0,0);
  157. popMatrix();
  158. fill(0);
  159. textAlign(LEFT,TOP);
  160. if (ghost[1]===""){
  161. text("Ghost Time: \n"+"Previous Time: "+previoustime+"\n"+nf(timer,1,2),0,0);
  162. } else {
  163. text("Ghost Time: "+nf(ghost[1],1,2)+"\n"+"Previous Time: "+previoustime+"\n"+nf(timer,1,2),0,0);
  164. }
  165. if (keys[82]){
  166. restart();
  167. }
  168. if (bugfix){
  169. restart();
  170. bugfix=false;
  171. }
  172. //MOVE
  173. car[0]+=speed*cos(car[2]);
  174. car[1]+=speed*sin(car[2]);
  175. gcar[0]+=gspeed*cos(gcar[2]);
  176. gcar[1]+=gspeed*sin(gcar[2]);
  177. //TURN
  178. recorder.push(0);
  179. if (keys[RIGHT]){
  180. car[2]+=drift;
  181. recorder[recorder.length-1]++;
  182. }
  183. if (keys[LEFT]){
  184. car[2]-=drift;
  185. recorder[recorder.length-1]+=2;
  186. }
  187. if (recorder.length<ghost[0].length){
  188. if (ghost[0][recorder.length-1]===1){
  189. gcar[2]+=gdrift;
  190. }
  191. if (ghost[0][recorder.length-1]===2){
  192. gcar[2]-=gdrift;
  193. }
  194. }
  195. };
Advertisement
Add Comment
Please, Sign In to add comment