how do i make the “trash” image move in a random direction with 10 pixels per frame. (so randomly have trashX move either -10 or +10 pixels)
float trashX;
float trashY;
float boatX;
float boatY;
float movingspeed = 10;
PImage[] trash = new PImage[18];
PImage[] boat = new PImage[3];
int right = 1;
int left = 2;
int bag = 1;
int beer = 2;
int box = 3;
int coffee = 4;
int deodorant = 5;
int energy = 6;
int jar = 7;
int laundrydetergent = 8;
int milk = 9;
int milkshake = 10;
int paper = 11;
int pizza = 12;
int soda = 14;
int tin = 15;
int tuna = 16;
int waterbottle = 17;
int boati = 1;
int trashi = int(random(0, 18));
boolean side;
void setup() {
fullScreen();
trashX = width / 2;
trashY = ((height / 2) / 2) * 3;
boatX = width / 2;
boatY = (height / 2) / 2;
trash[bag] = loadImage("bag.png");
trash[beer] = loadImage("beer.png");
trash[box] = loadImage("box.png");
trash[coffee] = loadImage("coffee.png");
trash[deodorant] = loadImage("deodorant.png");
trash[energy] = loadImage("energy.png");
trash[jar] = loadImage("jar.png");
trash[laundrydetergent] = loadImage("laundry detergent.png");
trash[milk] = loadImage("milk.png");
trash[milkshake] = loadImage("milkshake.png");
trash[paper] = loadImage("paper.png");
trash[pizza] = loadImage("pizza.png");
trash[soda] = loadImage("soda.png");
trash[tin] = loadImage("tin.png");
trash[tuna] = loadImage("tuna.png");
trash[waterbottle] = loadImage("water bottle.png");
boat[right] = loadImage("boatright.png");
boat[left] = loadImage("boatleft.png");
}
void draw() {
background(#006994);
trashY= trashY - 1;
image(trash[trashi], trashX, trashY, 20, 20);
image(boat[boati], boatX, boatY, 50, 20);
if (keyPressed) {
if (key == 'a') {
boati = left;
}
if (key == 'd') {
boati = right;
}
}
}