Question: hello there is an issue with my processing code. mly can not be resolved as a variable it says. Here is the code. import processing.sound.

hello there is an issue with my processing code. mly can not be resolved as a variable it says. Here is the code.
import processing.sound.*;
ArrayList mountain1= new ArrayList();
ArrayList mountain2= new ArrayList();
ArrayList mountain3= new ArrayList();
PImage[] runFrames = new PImage[8];
int framelndex =0;
int frameDelay =8;
int frameCounter =0;
SoundFile runningSound;
float jumpForce =-10;
float gravity =0.6;
float yVelocity =0;
float characterY;
boolean isJumping = false;
PImage squirrelImg;
ArrayList squirrels = new ArrayList();
class Squirrel {
float x, y;
int size;
Squirrel(float x, float y, int size){
this.x = x;
this.y = y;
this.size = size;
}
void display(){
image(squirrelImg, x, y, size, size);
}
}
void setup(){
size(1080,720);
characterY = height /2;
m1y = height/2;
m2y = height/4;
m3y = height/6;
generate(mountain1, m1y, m1s);
generate(mountain2, m2y, m2s);
generate(mountain3, m3y, m3s);
noStroke();
for (int i =0; i < runFrames.length; i++){
runFrames[i]= loadImage("run-"+(i+1)+".png");
}
runningSound = new SoundFile(this, "running3.mp3");
squirrelImg = loadImage("squirrel.png");
}
void draw(){
background(100,200,255);
move(mountain1,4, m1y, m1s);
move(mountain2,2, m2y, m2s);
move(mountain3,1, m3y, m3s);
fill(169,36,178);
show(mountain3);
fill(174,89,180);
show(mountain2);
fill(255,200,200);
show(mountain1);
if (frameCounter++% frameDelay ==0){
framelndex =(framelndex +1)% runFrames.length;
}
image(runFrames[framelndex], width/2- runFrames[framelndex].width/2, characterY - runFrames[framelndex].height/2);
if (random(1)<0.01){// Adjust the probability of squirrel spawning
spawnSquirrel();
}
for (int i = squirrels.size()-1; i >=0; i--){
Squirrel squirrel = squirrels.get(i);
squirrel.display();
// Check for collision with sprite
if (dist(width/2, characterY, squirrel.x + squirrel.size/2, squirrel.y + squirrel.size/2)<50){
// Do something if there's a collision
}
}
if (isJumping){
yVelocity += gravity;
characterY += yVelocity;
if (characterY >= height /2){
characterY = height /2;
yVelocity =0;
isJumping = false;
}
}
}
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);
}
void spawnSquirrel(){
float x = random(width);
float y = random(height/2);
int size =50; // Adjust squirrel size as needed
Squirrel squirrel = new Squirrel(x, y, size);
squirrels.add(squirrel);
}
void keyPressed(){
if (key =='' && !isJumping){
yVelocity = jumpForce;
isJumping = true;
runningSound.play();
}
}

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!