smooth motion
in
Programming Questions
•
4 months ago
Hi,
I'm trying to make a movement system that causes an object such as a square to speed up from a stop while a key is being held down, and then coast to a stop when they key is released. I need help with the coding.
This is what I have so far:
- car[] cars;
- int x;
- void setup();
- size(600,600);
- car = new car[10];
- for(int i=0;i<cars.length;i++){
- cars[i] = new car(startX[i],startY[i]);
- }
- x=0;
- }
- void draw(){
- background(125);
- {
- cars[i].drawcar();
- }
- }
- void keyPressed(){
- if( key >= '0' && key <= '9'){
- x = key - '0';
- return;
- }
- if(key == CODED)
- {
- if (keyCode == UP)
- {
- cars[x].moveUP();
- }
- else if (keyCode == DOWN)
- {
- cars[x].moveDOWN();
- }
- else if (keyCode == LEFT)
- {
- cars[x].moveLEFT();
- }
- else if (keyCode == RIGHT)
- {
- cars[x].moveRIGHT();
- }
- }
1