added topbar to timer and lots of comments
This commit is contained in:
parent
98034f48ef
commit
bd81a6b624
@ -10,13 +10,13 @@ function setup() {
|
|||||||
frameRate(60);
|
frameRate(60);
|
||||||
|
|
||||||
textbox = new Textbox(400, 200, 700);
|
textbox = new Textbox(400, 200, 700);
|
||||||
timer = new Timer(100,100,100,100,0,true,0,false,0,0,30,true);
|
timer = new Timer(0, 0, 100, 100, 0, true, '#000', true, '#000','#F3C969', 30, true);
|
||||||
timer.start();
|
timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function is called once per frame and draws all other elements
|
// this function is called once per frame and draws all other elements
|
||||||
function draw() {
|
function draw() {
|
||||||
background(255,100,100);
|
background(200);
|
||||||
textbox.draw();
|
textbox.draw();
|
||||||
timer.tick();
|
timer.tick();
|
||||||
timer.draw();
|
timer.draw();
|
||||||
|
@ -16,7 +16,7 @@ class Textbox {
|
|||||||
this.allowedLetters = [
|
this.allowedLetters = [
|
||||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
|
||||||
'l', 'm','n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
'l', 'm','n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
||||||
'x', 'y', 'z', 'enter', '\'', '"', ',', '.', ' '
|
'x', 'y', 'z', '\'', '"', ',', '.', ' '
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,16 +113,24 @@ class Timer {
|
|||||||
this.backgroundColor = pBackgroundColor;
|
this.backgroundColor = pBackgroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// time is the amount of seconds that the test should take
|
/**
|
||||||
|
* gets the amount of time the timer will run for
|
||||||
|
*/
|
||||||
getTime() {
|
getTime() {
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the amount of time the timer will run for
|
||||||
|
* @param {int} pTime
|
||||||
|
*/
|
||||||
setTime(pTime) {
|
setTime(pTime) {
|
||||||
this.time = pTime;
|
this.time = pTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// when the timer needs to be started this method is called
|
/**
|
||||||
|
* This method is called to start the timer
|
||||||
|
*/
|
||||||
start() {
|
start() {
|
||||||
this.startTime = frameCount;
|
this.startTime = frameCount;
|
||||||
// framecount is a special p5 value that counts the number of frames that have passed
|
// framecount is a special p5 value that counts the number of frames that have passed
|
||||||
@ -131,7 +139,10 @@ class Timer {
|
|||||||
this.timeElapsed = 0;
|
this.timeElapsed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function should be called once per frame
|
/**
|
||||||
|
* This method should be called once per frame
|
||||||
|
* it keeps track of the amount of time passed
|
||||||
|
*/
|
||||||
tick() {
|
tick() {
|
||||||
this.timeElapsed = frameCount - this.startTime;
|
this.timeElapsed = frameCount - this.startTime;
|
||||||
if (this.timeElapsed == this.time * 60) this.end();
|
if (this.timeElapsed == this.time * 60) this.end();
|
||||||
@ -139,7 +150,6 @@ class Timer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* this function is called at the end of the timer
|
* this function is called at the end of the timer
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
end() {
|
end() {
|
||||||
this.timeElapsed = 0;
|
this.timeElapsed = 0;
|
||||||
@ -149,22 +159,33 @@ class Timer {
|
|||||||
// this will likely including changing the screen and interacting with the api
|
// this will likely including changing the screen and interacting with the api
|
||||||
}
|
}
|
||||||
|
|
||||||
// currently just displays the amount of time left in seconds, also draws the bar if option
|
|
||||||
// been enabled
|
|
||||||
/**
|
/**
|
||||||
* Draws the timer, uses the attributes of the class as options
|
* Draws the timer, uses the attributes of the class as options
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
draw() {
|
draw() {
|
||||||
|
// if the time shouldn't be rendered it quickly exits out of this method
|
||||||
if (!this.visible) return;
|
if (!this.visible) return;
|
||||||
|
|
||||||
if (this.bar) {
|
// adds a border for the bar if one is needed
|
||||||
fill(100);
|
if (this.border && this.bar) {
|
||||||
rect(0, 0, windowWidth, this.height);
|
strokeWeight(1);
|
||||||
|
stroke(this.borderColor);
|
||||||
|
// this doesn't use the fill function like other drawings
|
||||||
|
// but this adds the necessary color to the border
|
||||||
|
} else {
|
||||||
|
noStroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
fill(0);
|
// draws a bar that move across the screen to show the time left
|
||||||
|
if (this.bar) {
|
||||||
|
fill(this.backgroundColor);
|
||||||
|
rect(this.y, this.x, windowWidth - windowWidth / (this.time * 60) * this.timeElapsed , this.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draws the text in the corner of the screen
|
||||||
|
noStroke();
|
||||||
|
fill(this.textColor);
|
||||||
let time = (this.time * 60 - this.timeElapsed) / 60
|
let time = (this.time * 60 - this.timeElapsed) / 60
|
||||||
text(Math.round(time), this.x, this.y)
|
text(Math.ceil(time), this.x + this.width / 6, this.y + this.height / 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user