Skip to content

Commit

Permalink
feat(levels): set background color
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed May 18, 2024
1 parent d81a8c8 commit ec09955
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
<noscript>You need to enable JavaScript to play this game.</noscript>
<script type="module">
import kaboom from 'kaboom'
kaboom()
kaboom({
background: [255, 255, 255],
})
</script>
<script type="module" src="src/index.ts"></script>

Expand Down
10 changes: 10 additions & 0 deletions src/levels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ export function getLevel(level: number) {
export function hasLevel(level: number): boolean {
return Boolean(levels[level])
}

/**
* Gets level background color.
*
* @param level - Level number.
* @returns - RGB color.
*/
export function getLevelBackground(level: number) {
return levels[level].background
}
20 changes: 14 additions & 6 deletions src/levels/levels.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// https://wikipedia.org/wiki/Box-drawing_characters
// ▲ ▼ ► ◄ ↑ ↓ → ← ⇦ ⇧ ⇨ ⇩
// △ ▷ ▽ ◁ ⬤ ◉ ◎
// ┓ ┗ ┏ ┛ ┣ ┫ ┳ ┻ ╋ ━ ┃
// ╔ ╗ ╚ ╝ ╠ ╣ ╦ ╩ ╬ ═ ║
// △ ▷ ▽ ◁
// ━ ┃ ┏ ┓ ┗ ┛ ┣ ┫ ┳ ┻ ╋
// ═ ║ ╔ ╗ ╚ ╝ ╠ ╣ ╦ ╩ ╬
// https://colorhunt.co/palettes/sea

export const levels = [
interface Level {
map: string[]
scale: number
background: [number, number, number]
}

export const levels: Level[] = [
// 0
{
// prettier-ignore
Expand All @@ -14,6 +19,7 @@ export const levels = [
' ╚═◁',
],
scale: 1,
background: [238, 247, 255],
},

// 1
Expand All @@ -25,6 +31,7 @@ export const levels = [
'▷═╩═╝',
],
scale: 1,
background: [205, 232, 229],
},

// 2
Expand All @@ -38,5 +45,6 @@ export const levels = [
' ╚══╩══╝ ',
],
scale: 0.8,
background: [224, 251, 226],
},
]
3 changes: 2 additions & 1 deletion src/scenes/game.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { EmptyToFilledPipe, Scene, Sound, Tag } from '../constants'
import { checkSolution, rotatePipe } from '../helpers'
import { getLevel, hasLevel } from '../levels'
import { getLevel, getLevelBackground, hasLevel } from '../levels'

scene(Scene.game, (levelNumber: number) => {
if (!hasLevel(levelNumber)) {
levelNumber = 0
}

setBackground(...getLevelBackground(levelNumber))
const level = addLevel(...getLevel(levelNumber))

level.get(Tag.pipe).forEach((pipe) => {
Expand Down

0 comments on commit ec09955

Please sign in to comment.