Commit e2d2df33 authored by Evan Hahn's avatar Evan Hahn

Powerup display

parent bd87da7e
......@@ -13,6 +13,11 @@
* r = scalar relative to screen size
* s = ∆t
* u = item constructor
* y = stats
* 0 => coins
* 1 => top speed
* 2 => boost
* 3 => turn
* z = stats display element
*/
......@@ -22,9 +27,16 @@
a.style.background = '#0f073b'
r = Math.min(a.width, a.height) / 30
b.style.font = c.font = '3vh sans-serif'
c.textAlign = 'center'
c.textBaseline = 'middle'
// Stats
y = [
['yellow', '$', 0],
['aqua', '⇒', r / 2],
['purple', '>', r / 2],
['green', '↺', 5],
['brown', '꛳', 100]
]
// The player
......@@ -35,11 +47,6 @@ p = (() => {
let playerAcceleration = 3
let playerDirection = 0
let playerTopSpeed = r / 2
let playerBoost = r / 2
let playerWeight = 100
let playerTurn = 5
f = g = h = 0
onkeydown = event => {
if (event.keyCode === 32) { h = 1 }
......@@ -49,7 +56,8 @@ p = (() => {
onkeyup = event => {
if (event.keyCode === 32) {
h = 0
playerSpeed += playerBoost
// y[2][2] === boost amount
playerSpeed += y[2][2]
}
if (event.keyCode === 65) { f = 0 }
if (event.keyCode === 68) { g = 0 }
......@@ -60,15 +68,18 @@ p = (() => {
z.style.position = 'absolute'
z.style.bottom = 0
z.style.paddingBottom = '1em'
z.style.fontSize = '3vh'
z.style.fontSize = '4vh'
return () => {
playerDirection += ((g * playerTurn) - (f * playerTurn)) * s
// y[3][2] === turn speed
playerDirection += ((g * y[3][2]) - (f * y[3][2])) * s
if (h) {
playerSpeed = Math.max(0, playerSpeed - playerWeight * s)
// y[4][2] === weight
playerSpeed = Math.max(0, playerSpeed - y[4][2] * s)
} else {
playerSpeed = Math.min(playerTopSpeed, playerSpeed + playerAcceleration * s)
// y[1][2] === top speed
playerSpeed = Math.min(y[1][2], playerSpeed + playerAcceleration * s)
}
playerX += Math.cos(playerDirection) * playerSpeed * r * s
......@@ -89,28 +100,28 @@ p = (() => {
c.fill()
c.setTransform(1, 0, 0, 1, 0, 0)
z.innerHTML = `<font color="aqua">⇒ ${playerTopSpeed}</font>`
z.innerHTML = y.map((stat) => (
`<font color="${stat[0]}">${stat[1]} ${stat[2]}</font>`
)).join('&nbsp;&nbsp;')
}
})()
// Item
u = (type) => {
let x = Math.random() * a.width
let y = Math.random() * a.height
let itemX = Math.random() * a.width
let itemY = Math.random() * a.height
return () => {
let icon
[c.fillStyle, icon] = [
['aqua', '⇒']
][type]
[c.fillStyle, icon] = y[type]
c.beginPath()
c.arc(x, y, r / 2, 0, 7)
c.arc(itemX, itemY, r, 0, 7)
c.fill()
c.fillStyle = 'black'
c.fillText(icon, x, y)
c.fillText(icon, itemX, itemY)
}
}
......@@ -127,6 +138,11 @@ requestAnimationFrame(q = (currentTime) => {
a.width = a.width // clears the screen
// canvas font stuff is reset when screen is cleared
c.textAlign = 'center'
c.textBaseline = 'middle'
b.style.font = c.font = 'bold 3vh sans-serif'
e.map(entity => entity())
requestAnimationFrame(q)
......
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