xxxxxxxxxx
154
let myCar;
let myNumber=[]
function setup() {
createCanvas(800, 600);
//setup the car
rectMode(CENTER);
// posX = width/2;
// posY = height/2;
// carWidth = 100;
// carHeight = carWidth/2.5;
// carColor = color(255,0,0);
// wheelWidth = carWidth * .2;
// wheelHeight = wheelWidth/2.5;
// myNum=0;
myCar=new.Car();
}
function timesTwo(num) {
return num2;
}
function draw() {
background(255);
drawCarBody();
updateCar();
myCar.run();
//////////////////////
//car body
// function drawCarBody() {
// fill(carColor);
// noStroke();
// rect(posX, posY, carWidth, carHeight);
// fill(0);
// // //drive the car
// // posX += 10;
// // if (posX > width+carWidth/2) {
// // posX = -carWidth/2;
// }
// fill(0);
// //left top wheel
// rect(
// posX - carWidth / 2 + wheelWidth / 2,
// posY - carHeight / 2 - wheelHeight / 2,
// wheelWidth,
// wheelHeight
// );
// //right top wheel
// rect(
// posX + carWidth / 2 - wheelWidth / 2,
// posY - carHeight / 2 - wheelHeight / 2,
// wheelWidth,
// wheelHeight
// );
// //left bottom wheel
// rect(
// posX - carWidth / 2 + wheelWidth / 2,
// posY + carHeight / 2 + wheelHeight / 2,
// wheelWidth,
// wheelHeight
// );
// //right bottom wheel
// rect(
// posX + carWidth / 2 - wheelWidth / 2,
// posY + carHeight / 2 + wheelHeight / 2,
// wheelWidth,
// wheelHeight
// );
// }
// function updateCar() {
// //drive the car
// posX += 10;
// if (posX > width + carWidth / 2) {
// posX = -carWidth / 2;
// }
// }
/////////////
class Car {
constructor() {
this.posX = random(width);
this.posY = random(height);
this.carWidth = 100;
this.carHeight = carWidth / 2.5;
this.carColor = color(255, 0, 0);
this.wheelWidth = carWidth * 0.2;
this.wheelHeight = wheelWidth / 2.5;
this.myNum = 0;
}
function drawCarBody() {
this.fill(carColor);
this.noStroke();
this.rect(posX, posY, carWidth, carHeight);
fill(0);
//left top wheel
rect(
this.posX - carWidth / 2 + wheelWidth / 2,
this.posY - carHeight / 2 - wheelHeight / 2,
this.wheelWidth,
this.wheelHeight
);
//right top wheel
rect(
this.posX + carWidth / 2 - wheelWidth / 2,
this.posY - carHeight / 2 - wheelHeight / 2,
this. wheelWidth,
this. wheelHeight
);
//left bottom wheel
rect(
this.posX - carWidth / 2 + wheelWidth / 2,
this.posY + carHeight / 2 + wheelHeight / 2,
this.wheelWidth,
this.wheelHeight
);
//right bottom wheel
rect(
this.posX + carWidth / 2 - wheelWidth / 2,
this.posY + carHeight / 2 + wheelHeight / 2,
this.wheelWidth,
this.wheelHeight
);
}
// //drive the car
// posX += 10;
// if (posX > width+carWidth/2) {
// posX = -carWidth/2;
}
function updateCar() {
//drive the car
posX += 10;
if (posX > width + carWidth / 2) {
posX = -carWidth / 2;
}
}
}