new starter in programming, trying to get the score to update in my simple game?
in
Programming Questions
•
2 years ago
Hello,
I've created a simple game for an assignment, i'm new to programming so its not the best coded for efficiency etc and i can't figure out why the score won't update? The code is below, I would appreciate it a lot if someone could point me in the right direction.
Thanks
Block standardBlock; // Declare block object as a global variable
Block standardBlock2;
Block standardBlock3;
float count = 0;
float count2 = 1;
int scorestandard;
int scorequick;
int scoretotal = (scorestandard + (scorequick*10));
float yposBlock1;
float xposBlock1;
float yposBlock2;
float xposBlock2;
float xuplimit = (mouseX + 20);
float xlowlimit = (mouseX - 20);
Block standardBlock2;
Block standardBlock3;
float count = 0;
float count2 = 1;
int scorestandard;
int scorequick;
int scoretotal = (scorestandard + (scorequick*10));
float yposBlock1;
float xposBlock1;
float yposBlock2;
float xposBlock2;
float xuplimit = (mouseX + 20);
float xlowlimit = (mouseX - 20);
void setup() {
size(900,500);
standardBlock = new Block(color (0), random (10,890), 0, 5); //Initialises blocks object by calling constructor
standardBlock2 = new Block(color (150), random (10, 890), -20, 7.5);
standardBlock3 = new Block (color (0), mouseX, 500, 0);
}
size(900,500);
standardBlock = new Block(color (0), random (10,890), 0, 5); //Initialises blocks object by calling constructor
standardBlock2 = new Block(color (150), random (10, 890), -20, 7.5);
standardBlock3 = new Block (color (0), mouseX, 500, 0);
}
void draw() {
background(255);
if ((yposBlock1 == 500) && (xposBlock1 < xuplimit) && (xposBlock1 > xlowlimit)) {
scorestandard ++; }
if ((yposBlock2 == 500) && (xposBlock2 < xuplimit) && (xposBlock2 > xlowlimit)) {
scorequick ++; }
if (count <= 20) {
standardBlock.move(); //Operate the blocks object by calling object
standardBlock.display();
standardBlock2.move2();
standardBlock2.display();
standardBlock3.move3();
standardBlock3.display2(); }
else {
println ("You scored " + scoretotal); }
background(255);
if ((yposBlock1 == 500) && (xposBlock1 < xuplimit) && (xposBlock1 > xlowlimit)) {
scorestandard ++; }
if ((yposBlock2 == 500) && (xposBlock2 < xuplimit) && (xposBlock2 > xlowlimit)) {
scorequick ++; }
if (count <= 20) {
standardBlock.move(); //Operate the blocks object by calling object
standardBlock.display();
standardBlock2.move2();
standardBlock2.display();
standardBlock3.move3();
standardBlock3.display2(); }
else {
println ("You scored " + scoretotal); }
}
class Block { //Defined a class called Block
color c;
float xpos;
float ypos;
float yspeed;
Block(color tempC, float tempXpos, float tempYpos, float tempYspeed) { // constructor
c = tempC;
xpos= tempXpos; // initialises the variables
ypos= tempYpos;
yspeed=tempYspeed;
}
void display() { // Method to display the block
rectMode(CENTER);
fill(c);
rect(xpos,ypos,20,10);
}
void move() { //Method to move the block
ypos=ypos+yspeed;
yposBlock1 = ypos;
if (ypos>height) {
ypos = 0;
xpos = random(10,890);
count ++;
xposBlock1 = xpos;
}
}
void move2() {
if (count / count2 == 10) {
ypos = ypos+yspeed;
yposBlock2 = ypos; {
if (ypos>height) {
ypos = -20;
xpos = random(10,890);
count2 ++;
xposBlock2 = xpos;
}
}
}
}
void display2 () {
rectMode(CENTER);
fill(c);
rect(xpos,ypos,40,10);
}
void move3 () {
ypos = 500;
xpos = mouseX;
}
}
1