Question: Hello, I have a code using processing IDE that shows a woman running with a scrolling background of mountains. I want to change this code

Hello, I have a code using processing IDE that shows a woman running with a scrolling background of mountains. I want to change this code so that it is able to be a game. I would like you to keep most of the code the same as much as you can because it works perfectly. I just want the running sprite woman to be able to jump and I want you to implement a soundfile called running3.mp3. Remainder that this is processing code:
ArrayList mountain1= new ArrayList();
ArrayList mountain2= new ArrayList();
ArrayList mountain3= new ArrayList();
float m1y, m2y, m3y;
float m1s =100, m2s =50, m3s =25;
PImage[] runFrames = new PImage[8];
int frameIndex =0;
int frameDelay =8; // Controls the speed of the frame update
int frameCounter =0; // Frame counter to manage animation timing
void setup(){
size(1080,720);
m1y = height /2;
m2y = height /4;
m3y = height /6;
generate(mountain1, m1y, m1s);
generate(mountain2, m2y, m2s);
generate(mountain3, m3y, m3s);
noStroke();
// Load sprite images
for (int i =0; i < runFrames.length; i++){
runFrames[i]= loadImage("run-"+(i +1)+".png");
}
}
void draw(){
background(100,200,255);
// Move mountains
move(mountain1,4, m1y, m1s);
move(mountain2,2, m2y, m2s);
move(mountain3,1, m3y, m3s);
// Show mountains
fill(0,100,50);
show(mountain3);
fill(0,125,25);
show(mountain2);
fill(0,155,0);
show(mountain1);
// Animate sprite
if (frameCounter++% frameDelay ==0){
frameIndex =(frameIndex +1)% runFrames.length;
}
// Display sprite centered
image(runFrames[frameIndex], width/2- runFrames[frameIndex].width/2, height/2- runFrames[frameIndex].height/2);
}
void move(ArrayList mountain, float speed, float y, float size){
for (int i =0; i < mountain.size(); i++){
mountain.get(i).x -= speed;
}
if (mountain.get(0).x <0){
mountain.remove(0);
}
while (mountain.get(mountain.size()-1).x < width +2* size){
mountain.add(new PVector(mountain.get(mountain.size()-1).x + size + random(-size /2, size /2), y + random(-size, size)));
}
}
void generate(ArrayList mountain, float y, float size){
mountain.add(new PVector(0, y + random(-size, size)));
while (mountain.get(mountain.size()-1).x < width){
mountain.add(new PVector(mountain.get(mountain.size()-1).x + size + random(-size /2, size /2), y + random(-size, size)));
}
}
void show(ArrayList mountain){
beginShape();
vertex(width, height);
vertex(0, height);
for (int i =0; i < mountain.size(); i++){
vertex(mountain.get(i).x, mountain.get(i).y);
}
endShape(CLOSE);}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!