# Midterm in progress: Don’t crash!

Description:

So my assignment is a video game where the player has to cross the road without hitting itself with any of the cars.

Process:

I got this idea while…well, crossing the road. This is just a rough sketch of what I actually wanted to do. The roads are made out of the rectangles. The cars are made using the rectangle with curved edges and ellipses for wheels. Along with a sun in the corner.

For now instead of a sprite sheet, I have used an ellipse for the players to detect the motion. Once the sprite sheet in used it, I expect the figure to have reactions for instances like getting hit by the car. I also plan in adding this image to make the game more realistic:

The speed of the car is randomly chosen between 1 and 5, every time the car leaves the screen so that the player does not get used to the speed. Every time the player is successful in crossing the road, the level increases, and the speed of the car also increases to make the game more difficult. As of now, I have only made the first level.

Also every time the player hits the car, the game restarts. I plan on adding upto 3 lives to this game to make it more intense and interesting. To give it a real life effect I will also add the following picture in the background later since at the moment it is creating an issue with the programme.

Here’s a demo of the game :

Code:

```int level = 1;
float car1x = 750;
float hood1x = 720;
float wheel1a = 825;
float wheel1b = 775;
float car2x = -150;
float hood2x = -50;
float wheel2a = -130;
float wheel2b = -75;
float speed1 = 50;
float speed2= 50;
float person = 300;

void setup() {
size(600,600);
frameRate(60);
}

void draw(){

if (level == 1){
//background
background(255);
stroke(255,69,0);
strokeWeight (3);

stroke (1);
strokeWeight (1);

fill(100);
rect(0,400,600,200);

fill(255,255,0);
rect(0,475,600,8);
rect(0,517,600,8);

//sun

//person
fill(0);
ellipse(300,person,50,50);
if (mousePressed){
person = person + 3;
}
if (person > 600){
level = level + 1;
}

//car1
fill(0,191,255);
rect(car1x,405,100,50,80,30,0,0);
rect(hood1x,430,30,25,40,0,0,0);
fill(1);
ellipse(wheel1a,450,25,25);
ellipse(wheel1b,450,25,25);

//move car1
car1x -=  speed1;
hood1x -=  speed1;
wheel1a -=  speed1;
wheel1b -=  speed1;

if (car1x < 0){
speed1 = random(1,5);
car1x = 750;
hood1x = 720;
wheel1a = 825;
wheel1b = 775;
}

//draw car2
fill(255,20,20);
rect(car2x,535,100,50,30,80,0,0);
rect(hood2x,560,30,25,0,40,0,0);
fill(1);
ellipse(wheel2a,580,25,25);
ellipse(wheel2b,580,25,25);

//move car 2
car2x += speed2;
hood2x += speed2;
wheel2a += speed2;
wheel2b += speed2;

if (car2x > 600){
speed2 = random(1,5);
car2x = -150;
hood2x = -50;
wheel2a = -130;
wheel2b = -75;
}

float distancehood1 = dist(hood1x,430,300,person);
float distancehood2 = dist(hood2x,560,300,person);
float distancecar1 = dist(car1x,405,300,person);
float distancecar2 = dist(car2x,535,300,person);
float distancebody1 = dist(car1x + 30,405,300,person);
float distancebody2 = dist(car2x + 30,405,300,person);
if (distancehood1 < 25 || distancecar1 < 25){
person = 150;
}
if (distancehood2 < 25 || distancecar2 < 40){
person = 150;
}
if (distancebody1 < 25){
person = 150;
}
if (distancebody2 < 25){
person = 150;
}
}
leveltext();
}

void leveltext(){
if (level == 1 || level == 2 || level == 3){
textSize(100);