Mario-Code-Day7

//NAME

int imageIndex=10;
int xPosition, c=0, move=900;
boolean faceLeft=true;
int i=0, size=900;

//Declare two arrays of PImage respectively
PImage [] imageA = new PImage[imageIndex];
int [] Ax = new int[imageIndex];
int Ay = 200;

PImage [] imageB = new PImage[imageIndex];
int [] Bx = new int[imageIndex];
int [] By = new int[imageIndex];

 

//Face Right
//INSERT CODE

void setup()
{
size(1000,500);

//Use for loop to load/initialize array of Images
for(i=0; i<10; i++)
{
imageA[i]=loadImage(i+”.png”);
imageB[i]=loadImage(“f”+i+”.png”);
}
Ax[0]=900;
}

void draw()
{

//DRAWS RECTANGLE
background(255);
imageMode(CENTER);

//ADJUSTS SIZE OF IMAGE
//float size = map(0, 0, height, 0.5, 1.5);
//scale(size);
size=200;
//i=0;

println(move);

//if(c==0)
for(i=1; i<10; i++)
{
Ax[i]=Ax[i-1]-30;
Bx[i]=Bx[i-1]+30;
}

////Check running direction and load different array of images
if(faceLeft==true)
{
if(c<10 && c>0)
move=move-30;
else
{
c=0;
Ax[0]=move;
}

image(imageA[c],Ax[c],Ay,size,size+20);
c++;

if(move<0)
faceLeft=false;
}
else if(faceLeft==false)
{
if(c<10 && c>0)
move=move+30;
else
{
c=0;
Bx[0]=move+30;
}

image(imageB[c],Bx[c],Ay,size,size+20);
c++;

if(move>width)
faceLeft=true;
}

delay(100);

}

//Keyboard control
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
faceLeft=true;
xPosition = xPosition – 30;
}else if(keyCode == RIGHT){
faceLeft=false;
xPosition = xPosition + 30;
}
//println(faceLeft);
}
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *