Commit b2958b35 authored by Evan Hahn's avatar Evan Hahn

Further crushing, new powerup to make you bigger

parent a527c509
......@@ -30,77 +30,75 @@ r = Math.min(a.width, a.height) / 30
// Stats
y = [
['gold', '¢', 0, 1],
['aqua', '⇒', r / 2, r / 5],
['purple', '>', r / 2, r / 5],
['chartreuse', '↺', 5, 0.1],
['white', '⧖', 10, 3]
['gold', '¢', 0, 1, 0],
['aqua', '⇒', r / 2, r / 5, 0],
['tomato', '+', 1, r / 100, 0],
['chartreuse', '↺', 5, 0.1, 0],
['white', '⧖', 60, 5, 60]
]
// The stats element
b.appendChild(z = document.createElement('center'))
z.style.width = '100%'
b.appendChild(z = document.createElement('b'))
z.style.margin = z.style.padding = '1vh'
z.style.position = 'absolute'
z.style.paddingBottom = '1em'
z.style.fontSize = '4vh'
// z.style.bottom = 0 is done later to save bytes
z.style.background = 'rgba(0,0,0,.8)'
// `z.style.bottom = 0` is done later to save bytes
// The player
p = (() => {
m = a.width / 2
n = a.height / 2
j = k = f = g = h = z.style.bottom = 0
onkeydown = event => {
if (event.keyCode === 32) { h = 1 }
if (event.keyCode === 65) { f = 1 }
if (event.keyCode === 68) { g = 1 }
}
onkeyup = event => {
if (event.keyCode === 32) {
h = 0
// y[2][2] === boost amount
j += y[2][2]
}
if (event.keyCode === 65) { f = 0 }
if (event.keyCode === 68) { g = 0 }
m = a.width / 2
n = a.height / 2
j = k = f = g = h = z.style.bottom = 0
onkeydown = event => {
if (event.keyCode === 32) { h = 1 }
if (event.keyCode === 65) { f = 1 }
if (event.keyCode === 68) { g = 1 }
}
onkeyup = event => {
if (event.keyCode === 32) {
h = 0
j += r / 2
}
if (event.keyCode === 65) { f = 0 }
if (event.keyCode === 68) { g = 0 }
}
return () => {
// y[3][2] === turn speed
k += ((g * y[3][2]) - (f * y[3][2])) * s
if (h) {
j = Math.max(0, j - 100 * s)
} else {
// y[1][2] === top speed
j = Math.min(y[1][2], j + 3 * s)
}
p = () => {
// y[3][2] === turn speed
k += ((g * y[3][2]) - (f * y[3][2])) * 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
n = n % a.height
// this could probably be smaller ^
c.fillStyle = 'deeppink'
c.translate(m, n)
c.rotate(k)
c.beginPath()
c.moveTo(-r, -r)
c.lineTo(r, 0)
c.lineTo(-r, r)
c.fill()
c.setTransform(1, 0, 0, 1, 0, 0)
z.innerHTML = y.map(stat => (
`<font color="${stat[0]}">${stat[1]} ${stat[2] | 0}</font>`
)).join('&nbsp;&nbsp;')
if (h) {
j = Math.max(0, j - 100 * s)
} else {
// y[1][2] === top speed
j = Math.min(y[1][2], j + 3 * 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
n = n % a.height
// this could probably be smaller ^
c.fillStyle = 'deeppink'
c.translate(m, n)
c.rotate(k)
c.beginPath()
// y[2][2] === size
c.moveTo(-r * y[2][2], -r * y[2][2])
c.lineTo(r * y[2][2], 0)
c.lineTo(-r * y[2][2], r * y[2][2])
c.fill()
c.setTransform(1, 0, 0, 1, 0, 0)
z.innerHTML = y.map(stat => (
`<font color="${stat[0]}">${stat[1]} ${stat[4]}</font>`
)).join(' ')
}
// Item
......@@ -119,8 +117,9 @@ u = (type) => {
c.fillStyle = 'black'
c.fillText(icon, itemX, itemY)
if (((itemX - m) ** 2 + (itemY - n) ** 2) < (r * r)) {
if (((itemX - m) ** 2 + (itemY - n) ** 2) < ((r * y[2][2]) ** 2)) {
y[type][2] += y[type][3]
y[type][4] += type === 4 ? y[type][3] : 1
e.splice(e.indexOf(me), 1)
}
}
......@@ -130,15 +129,14 @@ u = (type) => {
// Define the list of entities
e = [p, u(0)]
e = [p]
// Add a new item
v = () => {
;(v = () => {
e.push(u((Math.random() * y.length) | 0))
setTimeout(v, Math.random() * 5000)
}
v()
setTimeout(v, Math.random() * 4000)
})()
// Tick function
......@@ -165,4 +163,4 @@ requestAnimationFrame(q = (currentTime) => {
// Less and less time
setInterval('y[4][2]--', 1000)
setInterval('y[4][2]--;y[4][4]--', 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