Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mud,tar,goal,zipper,spawn,init,collide,speed,gspeed;var startpos = [20,380,270];
- var car,gcar,canwin=true,frame,extra=[];
- ///////////////////////////////////////////////
- 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];
- var level = function(){
- 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);
- };
- ///////////////////////////////////////////////
- var version = "v0.6";
- var speedorig = 2;
- var driftorig = 2;
- var timer = 0;
- var frame = 0;
- if (ghost==="insert custom ghost here"){
- ghost=[[],""];
- }
- if (ghost.length===2){
- ghost.push("pre-0.5.1");
- }
- var recorder = [];
- var previoustime = "";
- var car = [];car[0]=startpos[0];car[1]=startpos[1];car[2]=startpos[2];
- var gcar = [];gcar[0]=startpos[0];gcar[1]=startpos[1];gcar[2]=startpos[2];
- var speed=speedorig;
- var drift=driftorig;
- var gspeed=speedorig;
- var gdrift=driftorig;
- var bugfix = true;
- var keys = [];
- var keyPressed = function(){keys[keyCode] = true;if (keyCode===71){println("[["+ghost[0]+"],"+ghost[1]+","+'"'+ghost[2]+'"]');}};
- var keyReleased = function(){keys[keyCode]=false;};
- var drawcar = function(x,y){
- fill(255);
- stroke(0);
- rect(x-10,y-5,20,10);
- };
- var drawghost = function(x,y){
- fill(0,0,255,50);
- noStroke();
- rect(x-10,y-5,20,10);
- };
- var gameend = function(){
- if (nf(timer,1,2)-0<=ghost[1]-0||ghost[1]===""){
- ghost[0]=[];
- for (var i=0;i<recorder.length;i++){
- ghost[0].push(recorder[i]);
- }
- ghost[1]=nf(timer,1,2);
- ghost[2]=version;
- }
- previoustime=nf(timer,1,2);
- timer=0;
- frame=0;
- car[0]=startpos[0];gcar[0]=startpos[0];
- car[1]=startpos[1];gcar[1]=startpos[1];
- car[2]=startpos[2];gcar[2]=startpos[2];
- recorder=[];
- };
- var restart = function(){
- timer=0;
- frame=0;
- canwin=true;
- car[0]=startpos[0];gcar[0]=startpos[0];
- car[1]=startpos[1];gcar[1]=startpos[1];
- car[2]=startpos[2];gcar[2]=startpos[2];
- recorder=[];
- if (init) {
- init();
- }
- };
- var spawn = function(x,y,a){
- startpos[0]=x;
- startpos[1]=y;
- startpos[2]=a;
- };
- var collide = function(x,y,l,w,ghost){
- if (!ghost&&car[0]+5>x&&car[0]-5<x+l&&car[1]+5>y&&car[1]-5<y+w){
- return true;
- }
- if (ghost&&gcar[0]+5>x&&gcar[0]-5<x+l&&gcar[1]+5>y&&gcar[1]-5<y+w){
- return true;
- }
- return false;
- };
- var tar = function(x,y,l,w){
- fill(0);
- noStroke();
- rect(x,y,l,w);
- if (collide(x,y,l,w,false)){
- speed=0;
- }
- if (collide(x,y,l,w,true)){
- gspeed=0;
- }
- };
- var mud = function(x,y,l,w){
- fill(100,50,0);
- noStroke();
- rect(x,y,l,w);
- if (collide(x,y,l,w,false)){
- speed=speedorig/2;
- }
- if (collide(x,y,l,w,true)){
- gspeed=speedorig/2;
- }
- };
- var zipper = function(x,y,l,w){
- fill(255,0,255);
- noStroke();
- rect(x,y,l,w);
- if (collide(x,y,l,w,false)){
- speed=speedorig*2;
- }
- if (collide(x,y,l,w,true)){
- gspeed=speedorig*2;
- }
- };
- var goal = function(x,y,l,w){
- if (canwin) {
- fill(255,0,0);
- noStroke();
- rect(x,y,l,w);
- if (collide(x,y,l,w,false)){
- gameend();
- bugfix=true;
- }
- }
- };
- draw = function() {
- speed=speedorig;gspeed=speedorig;
- timer+=(1/60);
- frame+=1;
- background(255);
- level();
- pushMatrix();
- translate(gcar[0],gcar[1]);
- rotate(gcar[2]);
- if (ghost[1]!==""){
- drawghost(0,0);
- }
- popMatrix();
- pushMatrix();
- translate(car[0],car[1]);
- rotate(car[2]);
- drawcar(0,0);
- popMatrix();
- fill(0);
- textAlign(LEFT,TOP);
- if (ghost[1]===""){
- text("Ghost Time: \n"+"Previous Time: "+previoustime+"\n"+nf(timer,1,2),0,0);
- } else {
- text("Ghost Time: "+nf(ghost[1],1,2)+"\n"+"Previous Time: "+previoustime+"\n"+nf(timer,1,2),0,0);
- }
- if (keys[82]){
- restart();
- }
- if (bugfix){
- restart();
- bugfix=false;
- }
- //MOVE
- car[0]+=speed*cos(car[2]);
- car[1]+=speed*sin(car[2]);
- gcar[0]+=gspeed*cos(gcar[2]);
- gcar[1]+=gspeed*sin(gcar[2]);
- //TURN
- recorder.push(0);
- if (keys[RIGHT]){
- car[2]+=drift;
- recorder[recorder.length-1]++;
- }
- if (keys[LEFT]){
- car[2]-=drift;
- recorder[recorder.length-1]+=2;
- }
- if (recorder.length<ghost[0].length){
- if (ghost[0][recorder.length-1]===1){
- gcar[2]+=gdrift;
- }
- if (ghost[0][recorder.length-1]===2){
- gcar[2]-=gdrift;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment