////race car game void setup(){ size(600,900); } void draw(){ scene(); road(); traffic(); racecars(); instructions(); } void racecars(){ ////moves race car left and right if (keyPressed){ if (key=='a'){ racecarleft(); } if (key=='d'){ racecarright(); } }else{ racecarmiddle(); } } void scene(){ ////green grass background background(19,206,10); } void road(){ ////creates curbs and pavement for road stroke(198,197,196); strokeWeight(7); rectMode(CORNER); fill(86,98,85); rect(150,0,300,800); ////sets strokeWeight back to 0 strokeWeight(0); ////draws yellow dividing lines that move down screen fill(218,252,3); ////first two rect(245,(frameCount*5-20)%height-40,10,40); rect(345,(frameCount*5-20)%height-40,10,40); ////second two rect(245,(frameCount*5-150)%height-40,10,40); rect(345,(frameCount*5-150)%height-40,10,40); ////third two rect(245,(frameCount*5-280)%height-40,10,40); rect(345,(frameCount*5-280)%height-40,10,40); ////fourth two rect(245,(frameCount*5-410)%height-40,10,40); rect(345,(frameCount*5-410)%height-40,10,40); ////fifth two rect(245,(frameCount*5-540)%height-40,10,40); rect(345,(frameCount*5-540)%height-40,10,40); ////sixth two rect(245,(frameCount*5-670)%height-40,10,40); rect(345,(frameCount*5-670)%height-40,10,40); ////seventh two rect(245,(frameCount*5-800)%height-40,10,40); rect(345,(frameCount*5-800)%height-40,10,40); } void traffic(){ ////creates cars that move at different speeds down screen with road ////left lane car fill(227,23,23); rect(175,(frameCount*2.7-200)%height-100,50,100); ////creates windshield and back window for left lane car fill(110,237,252); rect(180,(frameCount*2.7-170)%height-100,40,15); rect(180,(frameCount*2.7-135)%height-100,40,10); ////middle lane car number 1 fill(235,43,250); rect(275,(frameCount*3.4-100)%height-100,50,100); ////creates windshield and back window for middle lane car fill(110,237,252); rect(280,(frameCount*3.4-70)%height-100,40,15); rect(280,(frameCount*3.4-35)%height-100,40,10); ////middle lane car number 2 fill(186,188,186); rect(275,(frameCount*3.4-500)%height-100,50,100); ////creates windshield and back window for middle lane car fill(110,237,252); rect(280,(frameCount*3.4-470)%height-100,40,15); rect(280,(frameCount*3.4-435)%height-100,40,10); ////right lane car fill(6,28,160); rect(375,(frameCount*2.7-500)%height-100,50,100); ////creates windshield and back window for right lane car fill(110,237,252); rect(380,(frameCount*2.7-470)%height-100,40,15); rect(380,(frameCount*2.7-435)%height-100,40,10); } void racecarmiddle(){ ////creates race car for middle lane ////front bumper fill(240,85,24); quad(295,600,275,610,325,610,305,600); ////long middle frame rect(295,600,10,100); ////cockpit ellipseMode(CENTER); ellipse(300,650,30,35); fill(188,185,184); ellipse(300,655,15,15); ////rear bumper fill(240,85,24); rect(275,690,50,10); ////tires fill(0); rect(278,612,15,20); rect(307,612,15,20); rect(278,668,15,20); rect(307,668,15,20); } void racecarleft(){ ////creates race car for left lane ////front bumper fill(240,85,24); quad(195,600,175,610,225,610,205,600); ////long middle frame rect(195,600,10,100); ////cockpit ellipseMode(CENTER); ellipse(200,650,30,35); fill(188,185,184); ellipse(200,655,15,15); ////rear bumper fill(240,85,24); rect(175,690,50,10); ////tires fill(0); rect(178,612,15,20); rect(207,612,15,20); rect(178,668,15,20); rect(207,668,15,20); } void racecarright(){ ////creates race car for right lane ////front bumper fill(240,85,24); quad(395,600,375,610,425,610,405,600); ////long middle frame rect(395,600,10,100); ////cockpit ellipseMode(CENTER); ellipse(400,650,30,35); fill(188,185,184); ellipse(400,655,15,15); ////rear bumper fill(240,85,24); rect(375,690,50,10); ////tires fill(0); rect(378,612,15,20); rect(407,612,15,20); rect(378,668,15,20); rect(407,668,15,20); } void instructions(){ ////shows controls fill(2,0,173); text("WELCOME TO:",23,50); text("MIKES SPEEDRACER 1.0",3,70); text("CONTROLS:",23,100); text("a = MOVE LEFT",25,120); text("s = MOVE RIGHT",25,140); if (keyPressed){ if (key=='q'){ exit(); } } text("q = QUIT",25,160); }