added some basic screen functionality
This commit is contained in:
parent
bc25578c01
commit
c2cd889fdd
@ -12,12 +12,16 @@
|
|||||||
|
|
||||||
<!-- Element Script Files -->
|
<!-- Element Script Files -->
|
||||||
<script src="./ui_elements/canvas.js"></script>
|
<script src="./ui_elements/canvas.js"></script>
|
||||||
<script src="./screens/screenmanager.js"></script>
|
|
||||||
|
|
||||||
<script src="./ui_elements/textbox.js"></script>
|
<script src="./ui_elements/textbox.js"></script>
|
||||||
<script src="./ui_elements/timer.js"></script>
|
<script src="./ui_elements/timer.js"></script>
|
||||||
<script src="./ui_elements/button.js"></script>
|
<script src="./ui_elements/button.js"></script>
|
||||||
|
|
||||||
|
<!-- Screen Files-->
|
||||||
|
<script src="./screens/screenmanager.js"></script>
|
||||||
|
<script src="./screens/startscreen.js"></script>
|
||||||
|
<script src="./screens/testscreen.js"></script>
|
||||||
|
<script src="./screens/endscreen.js"></script>
|
||||||
|
|
||||||
<!-- API Script Files -->
|
<!-- API Script Files -->
|
||||||
<script src="./api/api.js"></script>
|
<script src="./api/api.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
@ -10,11 +10,11 @@ function setup() {
|
|||||||
|
|
||||||
api = new API();
|
api = new API();
|
||||||
screenManager = new ScreenManager();
|
screenManager = new ScreenManager();
|
||||||
|
screenManager.setScreen(new StartScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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(200);
|
|
||||||
screenManager.draw();
|
screenManager.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
0
website/screens/endscreen.js
Normal file
0
website/screens/endscreen.js
Normal file
@ -1,13 +1,19 @@
|
|||||||
class ScreenManager {
|
class ScreenManager {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.textbox = new Textbox(400, 200, 700);
|
this.textbox;
|
||||||
this.timer = new Timer(0, 0, 100, 100, 0, true, '#000', true, '#000','#F3C969', 10, true);
|
this.timer;
|
||||||
this.button = new Button(300, 300, 100, 50, 0, true, '#fff', false, '#000', '#666', 'button');
|
this.screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
this.textbox.draw();
|
this.screen.draw();
|
||||||
this.timer.draw();
|
}
|
||||||
this.button.draw();
|
|
||||||
|
setScreen(pScreen) {
|
||||||
|
this.screen = pScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
getScreen() {
|
||||||
|
return this.screen;
|
||||||
}
|
}
|
||||||
}
|
}
|
12
website/screens/startscreen.js
Normal file
12
website/screens/startscreen.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
class StartScreen {
|
||||||
|
constructor() {
|
||||||
|
screenManager.textbox = new Textbox(0,0,0,0,0,false,"#000", false, "#000", "#000");
|
||||||
|
}
|
||||||
|
|
||||||
|
draw() {
|
||||||
|
background("#eeeee4");
|
||||||
|
textSize(100);
|
||||||
|
textAlign(CENTER, CENTER);
|
||||||
|
text("Press enter to start test", 0, 0, windowWidth - 100, windowHeight - 100);
|
||||||
|
}
|
||||||
|
}
|
14
website/screens/testscreen.js
Normal file
14
website/screens/testscreen.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
class TestScreen {
|
||||||
|
constructor() {
|
||||||
|
screenManager.textbox = new Textbox(100,100,windowWidth - 100,windowHeight,0,true,"#000", false, "#000", "#000");
|
||||||
|
screenManager.timer = new Timer(0,0,windowWidth,50,0,true,"#fff", true, "#000", "#666", 15, true);
|
||||||
|
screenManager.timer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
draw() {
|
||||||
|
background("#eeeee4");
|
||||||
|
screenManager.textbox.draw();
|
||||||
|
screenManager.timer.draw();
|
||||||
|
screenManager.timer.tick();
|
||||||
|
}
|
||||||
|
}
|
@ -110,6 +110,11 @@ class Textbox {
|
|||||||
|
|
||||||
letterTyped(pKey) {
|
letterTyped(pKey) {
|
||||||
console.log(pKey);
|
console.log(pKey);
|
||||||
|
if (pKey === "Enter" && screenManager.screen.constructor.name === "StartScreen") {
|
||||||
|
screenManager.setScreen(new TestScreen());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (pKey === "Backspace" && this.letters.length > 1) {
|
if (pKey === "Backspace" && this.letters.length > 1) {
|
||||||
this.letters.pop();
|
this.letters.pop();
|
||||||
return;
|
return;
|
||||||
@ -140,9 +145,16 @@ class Textbox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
// sets the default characteristics these should be replaced with attributes
|
// doesn't render the textbox if it should not be visible to the user.
|
||||||
color(0);
|
if (this.visible === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets the parameters of what the text should look like;
|
||||||
|
color(this.textColor);
|
||||||
textSize(23);
|
textSize(23);
|
||||||
|
textAlign(LEFT);
|
||||||
|
// font needs to be monospaced for outputting text to the screen like I do
|
||||||
textFont('monospace');
|
textFont('monospace');
|
||||||
|
|
||||||
// these variables allow me to use the values of x and y while updating them
|
// these variables allow me to use the values of x and y while updating them
|
||||||
|
@ -166,6 +166,7 @@ class Timer {
|
|||||||
draw() {
|
draw() {
|
||||||
// if the time shouldn't be rendered it quickly exits out of this method
|
// if the time shouldn't be rendered it quickly exits out of this method
|
||||||
if (!this.visible) return;
|
if (!this.visible) return;
|
||||||
|
textAlign(LEFT);
|
||||||
|
|
||||||
// adds a border for the bar if one is needed
|
// adds a border for the bar if one is needed
|
||||||
if (this.border && this.bar) {
|
if (this.border && this.bar) {
|
||||||
|
Loading…
Reference in New Issue
Block a user