simple animation work
in
Programming Questions
•
2 years ago
I want to >>>
Draw a bus that moves horizontally from left to right. When the vehicle hits the right boundary, it "wraps around" to the left and moves down 50 pixels. Draw a road for the bus to travel on. When you press and release the b key, this will toggle bus motion. Press the key repeatedly to stop and continue the vehicle animation.
the problem is that I am just getting familiar with this program... so lots of problems!
so far I tried to create an object and make it move, but it gives errors...
Bus myBus;
void setup() {
size(500,500);
background(255);
myBus = new Bus;
smooth();
}
void draw() {
background(255);
myBus.display();
myBus.drive();
}
class Bus {
int xPos;
int yPos;
bus(xPos, yPos) {
xPos=0;
yPos=height/2;
}
void display() {
fill(255,0,0); //drawing the bus
stroke(0);
rect(xPos,yPos,100,40);
fill(0);
ellipse(xPos+25,yPos+40,20,20);
ellipse(xPos+75,yPos+40,20,20);
}
void drive() {
xPos++; //moving the bus to the right
if(xPos>width) {
xPos= width;
}
}
I am really confused now, and about the errors!!!!! also have no idea how to continue!
I appreciate some guideline !
thanks
1