Score/timer
in
Programming Questions
•
7 months ago
Hi. I’m pretty new to Processing and I want to add a score keeper to my game. The object of the game is to hit the ball back and forth with different levels: easy, normal, hard, and extreme. I want to add make the score go up each second. I’m not familiar with the millis function, and I need help. I want the level easy to only get half as many points per second while keeping the ball on the screen as normal, and stuff like that. Here is my code if you need it(don’t worry about the IMG):
boolean go;
float x, overX1, overX2, size1, size2, speed;
PImage img;
void setup() {
size (1100, 700);
img = loadImage ("space.jpg");
x = width/2;
go = false;
}
void draw() {
background(img);
text ("To play hit the ball with the right and left arrow keys!", 156, 100);
text ("To make the ball start moving, hit a, s, d, or f. To reset the ball hit r!", 80, 135);
textSize (30);
text ("A = Easy", 80, 165);
text ("S = Normal", 80, 195);
text ("D = Hard", 80, 225);
text ("F = EXTREME", 80, 255);
ellipse(x, 350, size1, size2);
fill(200, 15, 35);
if (keyPressed) {
if (key == CODED){
if (keyCode == LEFT){
rect(0, 250, 15, 200);
}
}
if (keyPressed) {
if (key == CODED){
if (keyCode == RIGHT){
rect(1085, 250, 15, 200);
}
}
}
if (keyPressed) {
if (key == CODED){
if (keyCode == LEFT && x <= overX1 && x > 0){
speed *= -1;
}
}
}
}
if (keyPressed) {
if (key == CODED){
if (keyCode == RIGHT && x >= overX2 && x < 1100){
speed *= -1;
}
}
}
if (go) x = x+speed*2.2;
}
void keyPressed() {
if (key == 'a' || key == 'A') {
go = true;
speed = 16;
overX1 = 25;
overX2 = 1075;
size1 = 21;
size2 = 21;
}
if (key == 's' || key == 'S') {
go = true;
speed = 20;
overX1 = 25;
overX2 = 1075;
size1 = 18;
size2 = 20;
}
if (key == 'd' || key == 'D') {
go = true;
speed = 24;
overX1 = 27;
overX2 = 1073;
size1 = 11;
size2 = 11;
}
if (key == 'f' || key == 'F') {
go = true;
speed = 27.7;
overX1 = 25;
overX2 = 1075;
size1 = 7;
size2 = 7;
}
if (key == 'r' || key == 'R') {
go = false;
x = width/2;
}
}
1