generated from remarkablegames/kaboom-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
846f201
commit 80306f7
Showing
11 changed files
with
66 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import kaboom from 'kaboom' | ||
|
||
export function initKaboom() { | ||
import { initGameScene } from '../scenes' | ||
|
||
export function initGame() { | ||
kaboom({ | ||
width: 600, | ||
height: 600, | ||
canvas: document.querySelector('canvas')!, | ||
}) | ||
|
||
initGameScene() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './cursors' | ||
export * from './editor' | ||
export * from './kaboom' | ||
export * from './game' | ||
export * from './level' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import './style.css' | ||
import './scenes' | ||
|
||
import { Scene } from './types' | ||
|
||
const level = Number(new URLSearchParams(location.search).get('level')) || 0 | ||
|
||
go('game', level) | ||
go(Scene.game, level) | ||
|
||
// press F1 | ||
// debug.inspect = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
import { editorView, getLevel, initKaboom, renderLevel } from '../helpers' | ||
import { editorView, getLevel, initGame, renderLevel } from '../helpers' | ||
import { Scene } from '../types' | ||
|
||
const buttons = document.querySelectorAll('.run') | ||
export function initGameScene() { | ||
scene(Scene.game, async (currentLevel: number) => { | ||
const level = await getLevel(currentLevel) | ||
renderLevel(level) | ||
|
||
scene('game', async (currentLevel: number) => { | ||
const level = await getLevel(currentLevel) | ||
renderLevel(level) | ||
editorView.dispatch({ | ||
changes: { | ||
from: 0, | ||
to: editorView.state.doc.length, | ||
insert: level.script.trim(), | ||
}, | ||
}) | ||
|
||
editorView.dispatch({ | ||
changes: { | ||
from: 0, | ||
to: editorView.state.doc.length, | ||
insert: level.script.trim(), | ||
}, | ||
}) | ||
function run() { | ||
initGame() | ||
level.prescript() | ||
const script = editorView.state.doc.toString() | ||
eval(script) | ||
level.postscript() | ||
} | ||
|
||
function run() { | ||
initKaboom() | ||
level.prescript() | ||
const script = editorView.state.doc.toString() | ||
eval(script) | ||
level.postscript() | ||
} | ||
run() | ||
|
||
run() | ||
const buttons = document.querySelectorAll( | ||
'.run', | ||
) as NodeListOf<HTMLButtonElement> | ||
|
||
buttons.forEach((button) => button.addEventListener('click', run)) | ||
}) | ||
buttons.forEach((oldButton) => { | ||
const newButton = oldButton.cloneNode(true) as HTMLButtonElement | ||
newButton.addEventListener('click', run) | ||
oldButton.parentNode?.replaceChild(newButton, oldButton) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
import './game' | ||
export * from './game' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './level' | ||
export * from './scene' | ||
export * from './sprite' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export interface Level { | ||
level: number | ||
title: string | ||
prescript: () => void | ||
script: string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum Sprite { | ||
exit = 'exit', | ||
player = 'player', | ||
} |