Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class Car {
  2.  
  3. color c;
  4. float xPos;
  5. float yPos;
  6. float xSpeed;
  7.  
  8. Car() {
  9. c = color(155);
  10. xPos = width/2;
  11. yPos = height/2;
  12. xSpeed = 1;
  13. }
  14.  
  15. void display() {
  16. rectMode(CENTER);
  17. fill(c);
  18. rect(xPos, yPos, 20, 10);
  19. }
  20.  
  21. void drive() {
  22. xPos = xPos + xSpeed;
  23. if (xPos > width) {
  24. xPos = 0;
  25. }
  26. }
  27. }
  28.  
  29. Car myCar;
  30.  
  31. void setup() {
  32. myCar = new Car();
  33. }
  34.  
  35. void draw() {
  36. background(255);
  37. myCar.drive();
  38. myCar.display();
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement