Hello everyone once again! I’m having a problem trying to make a game, i have my concept and have gotten some help from my professor but im still coming up with errors.
The concept of the game is you control a bubble that you need to keep away from a pin floating around. There is more I want to add but for now, I would like help figuring out why my timer won’t work.
class timer {
// props
int startTime;
int interval;
//constructor
Timer(int timeInterval) {
interval = timeInterval;
}
//methods
void start() {
startTime = millis();
}
void complete(){
int elapsedTime = millis() - startTime;
if (elapsedTime > interval)
{
return true;
}
else {
return false;
}//end if
}
}//end class
I’ve also attached screenshots to everyone who helps can have a visual understanding of what’s going on
Wonderful that worked for that problem! my next issue comes with the if statements it’s saying these variables don’t exsits im confused if I need to replace the words with myTimer or something else
Timer myTimer;
int currentTime;
String s;
void setup() {
size(1200, 600);
myTimer = new Timer(1000);
s ="";
}
void draw() {
background(200);
//timer stuff
if (myTimer.complete()== true){
if (countdownTime > 0){
currentTime++;
countdownTIme--;
timer.start();
}
}
else {
fill (255, 0, 0);
rect(0,0, width, height);
}// end cdt
// text stuff
fill(255);
textSize(48);
textAlign(CENTER);
s= "Current time is" + currentTime;
s +="Countdown time is " + countdownTime;
text(s,width/2, height/2);
}Timer myTimer;
int currentTime;
String s;
void setup() {
size(1200, 600);
myTimer = new Timer(1000);
s ="";
}
void draw() {
background(200);
//timer stuff
if (myTimer.complete()== true){
if (countdownTime > 0){
currentTime++;
countdownTIme--;
timer.start();
}
}
else {
fill (255, 0, 0);
rect(0,0, width, height);
}// end cdt
// text stuff
fill(255);
textSize(48);
textAlign(CENTER);
s= "Current time is" + currentTime;
s +="Countdown time is " + countdownTime;
text(s,width/2, height/2);
i apologize for not responding for so long I was contemplating restarting from the ground up and decide to do that. I’m trying to figure out why “millis” won’t work
class myTimer {
// props
int startTime;
int interval;
//constructor
myTimer(int timeInterval) {
interval = timeInterval;
}
//methods
void start() {
startTime = millis();
}
boolean complete(){
int elapsedTime = millis() - startTime;
if (elapsedTime > interval)
{
return true;
}
else {
return false;
}//end if
}
}//end class
sorry was driving but here is the class code and the button code
class myTimer {
// props
int startTime;
int interval;
//constructor
myTimer(int timeInterval) {
interval = timeInterval;
}
//methods
void start() {
startTime = millis();
}
boolean complete(){
int elapsedTime = millis() - startTime;
if (elapsedTime > interval)
{
return true;
}
else {
return false;
}//end if
}
}//end class
class Button
{
PVector Pos= new PVector(0, 0);
float Width = 0;
float Height = 0;
color Color;
String Text;
Boolean Pressed = false;
Boolean Clicked = false;
// constructor to create a button
Button(int x, int y, int w, int h, String t, int r, int g, int b)
{
Pos.x = x;
Pos.y = y;
Width = w;
Height = h;
Color = color(r, g, b);
Text= t;
}
void update() //must be placed in void draw() to work
{
if (mousePressed==true &&mouseButton == LEFT && Pressed== false)
{
Pressed = true;
if (mouseX>=Pos.x && mouseX <= Pos.x+Width && mouseY >= Pos.y && mouseY <= Pos.y+Height)
{
Clicked = true;
} else
{
Clicked = false;
}
if (mousePressed !=true)
{
Pressed = false;
}
}
}
void render()// must be placed void draw to render the button to the screen
{
fill(Color);
rect(Pos.x,Pos.y,Width,Height);
fill(0);
textAlign(CENTER,CENTER);
text(Text,Pos.x+(Width/2),Pos.y+(Height/2));
}
//boolean isClicked()// Use this in a if statement to check if the button has clicked
//{
//return Clicked;