mirror of
https://github.com/He4eT/DotDashPit.git
synced 2026-05-05 01:47:22 +00:00
game: morse code draft
This commit is contained in:
parent
4a96911d25
commit
420ecc2ff9
1 changed files with 100 additions and 12 deletions
108
game.js
108
game.js
|
|
@ -6,6 +6,41 @@
|
||||||
// version: 0.1
|
// version: 0.1
|
||||||
// script: js
|
// script: js
|
||||||
|
|
||||||
|
let morseTable = {
|
||||||
|
'.-': 'A',
|
||||||
|
'-...': 'B',
|
||||||
|
'-.-.': 'C',
|
||||||
|
'-..': 'D',
|
||||||
|
'.': 'E',
|
||||||
|
'..-.': 'F',
|
||||||
|
'--.': 'G',
|
||||||
|
'....': 'H',
|
||||||
|
'..': 'I',
|
||||||
|
'.---': 'J',
|
||||||
|
'-.-': 'K',
|
||||||
|
'.-..': 'L',
|
||||||
|
'--': 'M',
|
||||||
|
'-.': 'N',
|
||||||
|
'---': 'O',
|
||||||
|
'.--.': 'P',
|
||||||
|
'--.-': 'Q',
|
||||||
|
'.-.': 'R',
|
||||||
|
'...': 'S',
|
||||||
|
'-': 'T',
|
||||||
|
'..-': 'U',
|
||||||
|
'...-': 'V',
|
||||||
|
'.--': 'W',
|
||||||
|
'-..-': 'X',
|
||||||
|
'-.--': 'Y',
|
||||||
|
'--..': 'Z',
|
||||||
|
}
|
||||||
|
|
||||||
|
let keyDownAt = 0
|
||||||
|
let keyUpAt = 0
|
||||||
|
let isKeyDown = false
|
||||||
|
|
||||||
|
let morseBuffer = ''
|
||||||
|
|
||||||
function TIC() {
|
function TIC() {
|
||||||
gameStages[currentStage]()
|
gameStages[currentStage]()
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +100,7 @@ function startScreen() {
|
||||||
const instruction = 'Press any key to start'
|
const instruction = 'Press any key to start'
|
||||||
print(instruction, 12, 30, 4)
|
print(instruction, 12, 30, 4)
|
||||||
|
|
||||||
if ([BTN_A, BTN_B, BTN_X, BTN_Y].map((b) => btnp(b)).some(Boolean)) {
|
if (anyKeyPressed()) {
|
||||||
currentStage = 'gameScreen'
|
currentStage = 'gameScreen'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -81,17 +116,19 @@ function gameoverScreen() {
|
||||||
const title = 'Game Over'
|
const title = 'Game Over'
|
||||||
print(title, 12, SCREEN_H - 24, 10, false, 2)
|
print(title, 12, SCREEN_H - 24, 10, false, 2)
|
||||||
|
|
||||||
if ([BTN_A, BTN_B, BTN_X, BTN_Y].map((b) => btnp(b)).some(Boolean)) {
|
if (anyKeyPressed()) {
|
||||||
reset()
|
reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function gameover () {
|
function gameover() {
|
||||||
effects = [{
|
effects = [
|
||||||
|
{
|
||||||
type: 'flash',
|
type: 'flash',
|
||||||
frames: '7777777777654321000000000000000000'.split(''),
|
frames: '7777777777654321000000000000000000'.split(''),
|
||||||
}]
|
},
|
||||||
|
]
|
||||||
currentStage = 'gameoverScreen'
|
currentStage = 'gameoverScreen'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +138,7 @@ function gameScreen() {
|
||||||
checkColisions()
|
checkColisions()
|
||||||
|
|
||||||
handleMoves()
|
handleMoves()
|
||||||
handleMorse()
|
// handleMorse()
|
||||||
|
|
||||||
spawnEnemies()
|
spawnEnemies()
|
||||||
moveEnemies()
|
moveEnemies()
|
||||||
|
|
@ -112,6 +149,7 @@ function gameScreen() {
|
||||||
drawEnemies()
|
drawEnemies()
|
||||||
drawPlayer()
|
drawPlayer()
|
||||||
drawLetters()
|
drawLetters()
|
||||||
|
handleMorse()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Interface */
|
/* Interface */
|
||||||
|
|
@ -148,8 +186,6 @@ function arenaToScreen({ x, y }) {
|
||||||
/* Player */
|
/* Player */
|
||||||
|
|
||||||
function handleMoves() {
|
function handleMoves() {
|
||||||
player.speed = btn(BTN_A) ? 2 : 1
|
|
||||||
|
|
||||||
let dx = 0
|
let dx = 0
|
||||||
if (btn(BTN_L)) dx -= 1
|
if (btn(BTN_L)) dx -= 1
|
||||||
if (btn(BTN_R)) dx += 1
|
if (btn(BTN_R)) dx += 1
|
||||||
|
|
@ -172,12 +208,55 @@ function handleMoves() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMorse() {
|
function handleMorse() {
|
||||||
player.sprite = btn(BTN_B) ? 65 : 64
|
// Cheatcode
|
||||||
|
|
||||||
if (btnp(BTN_B, 100, 100)) {
|
if (btnp(BTN_B, 100, 100)) {
|
||||||
const letter = enemies[0].letter
|
const letter = enemies[0].letter
|
||||||
destroyEnemiesByLetter(letter)
|
destroyEnemiesByLetter(letter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Morse part
|
||||||
|
|
||||||
|
const buttonPressed = btn(4)
|
||||||
|
// const buttonPressed = [BTN_A, BTN_B, BTN_X, BTN_Y].map(btn).some(Boolean)
|
||||||
|
|
||||||
|
player.sprite = buttonPressed ? 65 : 64
|
||||||
|
player.speed = buttonPressed ? 2 : 1
|
||||||
|
|
||||||
|
const now = time()
|
||||||
|
const dotDashThreshold = 200
|
||||||
|
const idleTimeout = 500
|
||||||
|
|
||||||
|
// Start
|
||||||
|
if (buttonPressed && !isKeyDown) {
|
||||||
|
isKeyDown = true
|
||||||
|
keyDownAt = now
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release
|
||||||
|
if (!buttonPressed && isKeyDown) {
|
||||||
|
isKeyDown = false
|
||||||
|
keyUpAt = now
|
||||||
|
morseBuffer += keyUpAt - keyDownAt < dotDashThreshold ? '.' : '-'
|
||||||
|
|
||||||
|
effects.unshift({
|
||||||
|
type: 'detection',
|
||||||
|
frames: [8],
|
||||||
|
to: player.position,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flush by Timeout
|
||||||
|
if (!buttonPressed && morseBuffer.length > 0 && now - keyUpAt > idleTimeout) {
|
||||||
|
if (morseTable[morseBuffer]) {
|
||||||
|
destroyEnemiesByLetter(morseTable[morseBuffer])
|
||||||
|
}
|
||||||
|
morseBuffer = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug
|
||||||
|
print('Current Code: ' + morseBuffer, 10, 100)
|
||||||
|
print('Current Code Length: ' + morseBuffer.length, 10, 106)
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawPlayer() {
|
function drawPlayer() {
|
||||||
|
|
@ -491,6 +570,15 @@ function getDirection(from, to) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function anyKeyPressed() {
|
||||||
|
for (let i = 0; i < 8; i++) {
|
||||||
|
if (btnp(i)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
/* Constants */
|
/* Constants */
|
||||||
|
|
||||||
/* Screen */
|
/* Screen */
|
||||||
|
|
@ -560,6 +648,7 @@ const BTN_Y = 7
|
||||||
// 050:3210000022100000111000000000000000000000000000000000000000000000
|
// 050:3210000022100000111000000000000000000000000000000000000000000000
|
||||||
// 064:8800088080000080008880000088800000888000800000808800088000000000
|
// 064:8800088080000080008880000088800000888000800000808800088000000000
|
||||||
// 065:0000000008808800080008000008000008000800088088000000000000000000
|
// 065:0000000008808800080008000008000008000800088088000000000000000000
|
||||||
|
// 066:8800088080000080000000000008000000000000800000808800088000000000
|
||||||
// 080:aaaaaaa0aaaaaaa0aa000aa0aa000aa0aa000aa0aaaaaaa0aaaaaaa000000000
|
// 080:aaaaaaa0aaaaaaa0aa000aa0aa000aa0aa000aa0aaaaaaa0aaaaaaa000000000
|
||||||
// 081:aaaaaaa0a00a00a0a00a00a0aaaaaaa0a00a00a0a00a00a0aaaaaaa000000000
|
// 081:aaaaaaa0a00a00a0a00a00a0aaaaaaa0a00a00a0a00a00a0aaaaaaa000000000
|
||||||
// 082:00a0a00000000000a0aaa0a000aaa000a0aaa0a00000000000a0a00000000000
|
// 082:00a0a00000000000a0aaa0a000aaa000a0aaa0a00000000000a0a00000000000
|
||||||
|
|
@ -599,4 +688,3 @@ const BTN_Y = 7
|
||||||
// <PALETTE>
|
// <PALETTE>
|
||||||
// 000:000000002b36073642586e75657b8383949693a1a1ffffffb58900cb4b16dc322fd336826c71c4268bd22aa198859900
|
// 000:000000002b36073642586e75657b8383949693a1a1ffffffb58900cb4b16dc322fd336826c71c4268bd22aa198859900
|
||||||
// </PALETTE>
|
// </PALETTE>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue