Trying to make a User made object move across the screen, Running into issues
in
Programming Questions
•
5 months ago
I'm working on maaking a guitar hero clone for my final project in my Computer Science class, and I've run into an issue. I've created a class called note, with a display method and a move method.
- class Note {
int y;
int x;
boolean touching;
int w;
int h;
Note(int xVal, int yVal) {
x = xVal;
y = yVal;
touching = false;
w = 20;
h = 20;
}
boolean isTouching(int yVal) {
return y>yVal-10 || y<yVal+10;
}
void display() {
noStroke();
fill(#21E817);
rect(x,y,w,h);
}
void move() {
y+=20;
}
}
Then my other class looks like this
- import ddf.minim.*;
- Note n;
- AudioPlayer player;
Minim minim; - boolean going = false;
- int yPos = 0;
- int alphq = 100;
int alphw = 100;
int alphe = 100;
int alphr = 100;
int alpht = 100;
int barY = 500;- double timer = 0.0;
- PImage img;
- int score = 0;
- void setup() {
img = loadImage("guitarHeroBackground.jpg");
size(img.width, img.height);
smooth();
minim = new Minim(this);
player = minim.loadFile("intoodeep.mp3",2048);
player.play();
}
void stop(){
player.close();
minim.stop();
super.stop();
} - void draw() {
timer += 1;
background(img);
smooth();
//Scoreboard
textSize(32);
fill(0,102,153);
text("Score: " + score, 50, 50);
n = new Note(20,20);
n.display();
n.move();
fill(255);
rect(100,yPos,20,20);
//fret
fill(#18D626,alphq);
rect(100,barY,30,30); //q
fill(206,29,29,alphw);
rect(200,barY,30,30); //w
fill(#F4F525,alphe);
rect(300,barY,30,30); //e
fill(#194AF5,alphr);
rect(400,barY,30,30); //e
fill(#F5A119,alpht);
rect(500,barY,30,30); //r
if(going) {
yPos += 2;
n.move();
}
}
void keyPressed(){
if(key == ENTER)
going = true;
if(key == 'q')
alphq = 1000;
if(key == 'w')
alphw = 1000000000;
if(key == 'e')
alphe = 1000;
if(key == 'r')
alphr = 1000;
if(key == 't')
alpht = 1000;
} - void keyReleased(){
if(key == 'q')
alphq = 100;
if(key == 'w')
alphw = 100;
if(key == 'e')
alphe = 100;
if(key == 'r')
alphr = 100;
if(key == 't')
alpht = 100;
}
When I press enter, the rectangle I created moves down the screen, but the Note object, n, does not. Can someone help me see what I'm missing? I'd really appreciate it.
1