Tidy up code
parent
b673b26a0e
commit
ebf8e01dd5
|
|
@ -90,20 +90,13 @@ function incrementTimer() {
|
||||||
|
|
||||||
function drawBackground() {
|
function drawBackground() {
|
||||||
// Clear screen
|
// Clear screen
|
||||||
if (nightMode) {
|
const bgColor = (nightMode) ? NIGHT : LIGHTEST;
|
||||||
g.setColor(NIGHT);
|
g.setColor(bgColor);
|
||||||
} else {
|
|
||||||
g.setColor(LIGHTEST);
|
|
||||||
}
|
|
||||||
g.fillRect(0, 10, W, H);
|
g.fillRect(0, 10, W, H);
|
||||||
|
|
||||||
// set cloud colors
|
// set cloud colors and draw clouds
|
||||||
if (nightMode) {
|
const cloudColor = (nightMode) ? DARK : LIGHT;
|
||||||
g.setColor(DARKEST);
|
g.setColor(cloudColor);
|
||||||
} else {
|
|
||||||
g.setColor(LIGHT);
|
|
||||||
}
|
|
||||||
// draw clouds
|
|
||||||
g.fillRect(0, 10, g.getWidth(), 15);
|
g.fillRect(0, 10, g.getWidth(), 15);
|
||||||
g.fillRect(0, 17, g.getWidth(), 17);
|
g.fillRect(0, 17, g.getWidth(), 17);
|
||||||
g.fillRect(0, 19, g.getWidth(), 19);
|
g.fillRect(0, 19, g.getWidth(), 19);
|
||||||
|
|
@ -124,14 +117,15 @@ function drawFloor() {
|
||||||
function drawPyramid() {
|
function drawPyramid() {
|
||||||
const pPol = [pyramidSprite.x + 10, H - 6, pyramidSprite.x + 50, pyramidSprite.height, pyramidSprite.x + 90, H - 6]; // Pyramid poly
|
const pPol = [pyramidSprite.x + 10, H - 6, pyramidSprite.x + 50, pyramidSprite.height, pyramidSprite.x + 90, H - 6]; // Pyramid poly
|
||||||
|
|
||||||
g.setColor(LIGHT);
|
const color = (nightMode) ? DARK : LIGHT;
|
||||||
|
g.setColor(color);
|
||||||
g.fillPoly(pPol);
|
g.fillPoly(pPol);
|
||||||
|
|
||||||
pyramidSprite.x -= 1;
|
pyramidSprite.x -= 1;
|
||||||
// Reset and randomize pyramid if off-screen
|
// Reset and randomize pyramid if off-screen
|
||||||
if (pyramidSprite.x < - 100) {
|
if (pyramidSprite.x < - 100) {
|
||||||
pyramidSprite.x = 90;
|
pyramidSprite.x = 90;
|
||||||
pyramidSprite.height = Math.floor(Math.random() * (60 /* max */ - 25 /* min */ + 1) + 25 /* min */);
|
pyramidSprite.height = genRanNum(25, 60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,7 +140,7 @@ function drawTreesFrame(x, y) {
|
||||||
function generateTreeSprite() {
|
function generateTreeSprite() {
|
||||||
return {
|
return {
|
||||||
x: 90,
|
x: 90,
|
||||||
y: Math.floor(Math.random() * (60 /* max */ - 30 /* min */ + 1) + 30 /* min */)
|
y: genRanNum(30, 60)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -257,10 +251,10 @@ function drawCharacter(date, character) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(characterSprite.character) {
|
switch(characterSprite.character) {
|
||||||
case("toad"):
|
case(TOAD):
|
||||||
drawToadFrame(characterSprite.frameIdx, characterSprite.x, characterSprite.y);
|
drawToadFrame(characterSprite.frameIdx, characterSprite.x, characterSprite.y);
|
||||||
break;
|
break;
|
||||||
case("mario"):
|
case(MARIO):
|
||||||
default:
|
default:
|
||||||
drawMarioFrame(characterSprite.frameIdx, characterSprite.x, characterSprite.y);
|
drawMarioFrame(characterSprite.frameIdx, characterSprite.x, characterSprite.y);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue