Hello! I’m fairly new to this so please bear with me. I’ve been looking all over the place but I couldn’t find anything on this in particular.
So I made a little game where you have different types of food moving from the top left and right areas of the screen towards the middle and pressing A W and D would make the food from the corresponding sides dissapear. Pressing S is supposed to reset the screen and put the food back on the screen in their starting position, except a randomly different type of food on each side this time.
**So herein lies the problem… I dumped all the different food images into an array, then I set the draw to show a random food from the array… except it constantly rapidfire cycles through all the images. Now I have 3 constant cycling objects moving to the center of the screen. I want the food to be set randomly ONCE on each side and then when I press S, it resets and changes to a different food. What am I doing wrong here? Thanks!
//array1
PImage[] myImageArray = new PImage[10];
PImage potato, grape, wood, title, slice, grapecut;
///Place food here
int foodleft=0;
int foodtop=0;
int foodright=800;
//booleans here//
boolean attack=true;
boolean fromtop=true;
boolean fromleft=true;
boolean fromright=true;
boolean life=true;
//setup start
void setup() {
//array2
myImageArray [0] = loadImage( "potato.png");
myImageArray [1] = loadImage( "grape.png");
myImageArray [2] = loadImage( "banana.png");
myImageArray [3] = loadImage( "carrot.png");
myImageArray [4] = loadImage( "cucumber.png");
myImageArray [5] = loadImage( "eggplant.png");
myImageArray [6] = loadImage( "onion.png");
myImageArray [7] = loadImage( "pear.png");
myImageArray [8] = loadImage( "radish.png");
myImageArray [9] = loadImage( "strawberry.png");
//loadimage
potato=loadImage("potato.png");
grape=loadImage("grape.png");
wood=loadImage("wood.png");
title=loadImage("title.png");
slice=loadImage("slice.gif");
grapecut=loadImage("grapecut.png");
//screen settings//
size(800,800);
}
//setup end
//draw start
void draw() {
background(0);
if (key=='w') {
foodtop=0;
fromtop=false;
}
if (key=='a') {
foodleft=0;
fromleft=false;
}
if (key=='d') {
foodright=800;
fromright=false;
}
if (key=='s'){
attack=true;
fromleft=true;
fromright=true;
fromtop=true;
}
if (fromleft==true){
image(myImageArray[(int)random(9)],foodleft, 400, 90, 120);
foodleft += 2;
}
if (foodleft>400){
life=false;
}
/////////////////////////////////////////////////
if (fromtop==true){
image(myImageArray[(int)random(9)],400, foodtop, 90, 120);
foodtop += 2;
}
if (foodtop>400){
life=false;
}
/////////////////////////////////////////////////
if (fromright==true){
image(myImageArray[(int)random(9)],foodright, 400, 90, 120);
foodright -= 2;
}
if (foodright<400){
life=false;
}
/////////////////////////////////////////////////
}//draw end