Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Car {
- color c;
- float xPos;
- float yPos;
- float xSpeed;
- Car() {
- c = color(155);
- xPos = width/2;
- yPos = height/2;
- xSpeed = 1;
- }
- void display() {
- rectMode(CENTER);
- fill(c);
- rect(xPos, yPos, 20, 10);
- }
- void drive() {
- xPos = xPos + xSpeed;
- if (xPos > width) {
- xPos = 0;
- }
- }
- }
- Car myCar;
- void setup() {
- myCar = new Car();
- }
- void draw() {
- background(255);
- myCar.drive();
- myCar.display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement