Commit d11c4114 authored by Evan Hahn's avatar Evan Hahn

Byte reduction; remove some `let`s

parent 4546e1a2
/*
* variable list
* a = canvas
* b = body
* c = context
......@@ -10,6 +9,8 @@
* l = last tick time
* m = player X
* n = player Y
* j = player speed
* k = player direction
* p = player
* q = tick function
* r = scalar relative to screen size
......@@ -20,11 +21,10 @@
* z = stats display element
*/
/* eslint-disable no-undef, no-return-assign */
/* eslint-disable no-undef, no-return-assign, no-implied-eval */
// Initial setup
a.style.background = '#0f073b'
r = Math.min(a.width, a.height) / 30
// Stats
......@@ -37,16 +37,21 @@ y = [
['white', '⧖', 10, 3]
]
// The stats element
b.appendChild(z = document.createElement('center'))
z.style.width = '100%'
z.style.position = 'absolute'
z.style.paddingBottom = '1em'
z.style.fontSize = '4vh'
// z.style.bottom = 0 is done later to save bytes
// The player
p = (() => {
m = a.width / 2
n = a.height / 2
let playerSpeed = 0
let playerAcceleration = 3
let playerDirection = 0
f = g = h = 0
j = k = f = g = h = z.style.bottom = 0
onkeydown = event => {
if (event.keyCode === 32) { h = 1 }
if (event.keyCode === 65) { f = 1 }
......@@ -56,32 +61,25 @@ p = (() => {
if (event.keyCode === 32) {
h = 0
// y[2][2] === boost amount
playerSpeed += y[2][2]
j += y[2][2]
}
if (event.keyCode === 65) { f = 0 }
if (event.keyCode === 68) { g = 0 }
}
b.appendChild(z = document.createElement('center'))
z.style.width = '100%'
z.style.position = 'absolute'
z.style.bottom = 0
z.style.paddingBottom = '1em'
z.style.fontSize = '4vh'
return () => {
// y[3][2] === turn speed
playerDirection += ((g * y[3][2]) - (f * y[3][2])) * s
k += ((g * y[3][2]) - (f * y[3][2])) * s
if (h) {
playerSpeed = Math.max(0, playerSpeed - 100 * s)
j = Math.max(0, j - 100 * s)
} else {
// y[1][2] === top speed
playerSpeed = Math.min(y[1][2], playerSpeed + playerAcceleration * s)
j = Math.min(y[1][2], j + 3 * s)
}
m += Math.cos(playerDirection) * playerSpeed * r * s
n += Math.sin(playerDirection) * playerSpeed * r * s
m += Math.cos(k) * j * r * s
n += Math.sin(k) * j * r * s
if (m < 0) { m += a.width }
if (n < 0) { n += a.height }
m = m % a.width
......@@ -90,7 +88,7 @@ p = (() => {
c.fillStyle = 'deeppink'
c.translate(m, n)
c.rotate(playerDirection)
c.rotate(k)
c.beginPath()
c.moveTo(-r, -r)
c.lineTo(r, 0)
......@@ -98,7 +96,7 @@ p = (() => {
c.fill()
c.setTransform(1, 0, 0, 1, 0, 0)
z.innerHTML = y.map((stat) => (
z.innerHTML = y.map(stat => (
`<font color="${stat[0]}">${stat[1]} ${stat[2] | 0}</font>`
)).join('&nbsp;&nbsp;')
}
......@@ -159,7 +157,7 @@ requestAnimationFrame(q = (currentTime) => {
e.map(entity => entity())
if (y[4][2] <= 0) {
z.innerHTML = `<font color="gold">Game over! Score: ¢${y[0][2]}</font>`
z.innerHTML = `<font color="gold">Game over! Score: ${y[0][2]}¢</font>`
} else {
requestAnimationFrame(q)
}
......@@ -167,4 +165,4 @@ requestAnimationFrame(q = (currentTime) => {
// Less and less time
setInterval(() => { y[4][2]-- }, 1000)
setInterval('y[4][2]--', 1000)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment