How to use array and for loop in my case?? please help

edited February 2015 in Questions about Code

Hello guys, i am bad at english, hope you guys understand what i'm talking about. I am working on my assignment of processing, i would like to create a mini game like NS SHAFT. I want 3 object move from the bottom to the top,

in my code , obsX is the x position, obsY is y position:

obsX=int(random(-50, width-200));

obsY=height-100;

obsX2=int(random(-50, width-200));

obsY2=height+200;

obsX3=int(random(-50, width-200));

obsY3=height+400;

obsWidth=200;

obsHeight=100;

obsSpeed=5;

and i write a function call wood to make it move those objects upward:

void wood() {

image(cloud,obsX, obsY, obsWidth, obsHeight); obsY=obsY-obsSpeed;

image(cloud,obsX2, obsY2, obsWidth, obsHeight); obsY2=obsY2-obsSpeed;

image(cloud,obsX3, obsY3, obsWidth, obsHeight); obsY3=obsY3-obsSpeed;

}

How could i use array and for loop to simplify the code??

Comments

Sign In or Register to comment.