Commit ab4e8b39 authored by Evan Hahn's avatar Evan Hahn

Collecting powerups

parent e2d2df33
......@@ -8,16 +8,15 @@
* g = pressing Right?
* h = pressing Stop?
* l = last tick time
* m = player X
* n = player Y
* p = player
* q = tick function
* r = scalar relative to screen size
* s = ∆t
* u = item constructor
* v = function to push new item
* y = stats
* 0 => coins
* 1 => top speed
* 2 => boost
* 3 => turn
* z = stats display element
*/
......@@ -31,18 +30,18 @@ r = Math.min(a.width, a.height) / 30
// Stats
y = [
['yellow', '$', 0],
['aqua', '⇒', r / 2],
['purple', '>', r / 2],
['green', '↺', 5],
['brown', '꛳', 100]
['yellow', '¢', 0, 1],
['aqua', '⇒', r / 2, r / 2],
['purple', '>', r / 2, r / 5],
['green', '↺', 5, 0.1],
['white', '⧖', 60, 3]
]
// The player
p = (() => {
let playerX = a.width / 2
let playerY = a.height / 2
m = a.width / 2
n = a.height / 2
let playerSpeed = 0
let playerAcceleration = 3
let playerDirection = 0
......@@ -75,23 +74,22 @@ p = (() => {
playerDirection += ((g * y[3][2]) - (f * y[3][2])) * s
if (h) {
// y[4][2] === weight
playerSpeed = Math.max(0, playerSpeed - y[4][2] * s)
playerSpeed = Math.max(0, playerSpeed - 100 * s)
} else {
// y[1][2] === top speed
playerSpeed = Math.min(y[1][2], playerSpeed + playerAcceleration * s)
}
playerX += Math.cos(playerDirection) * playerSpeed * r * s
playerY += Math.sin(playerDirection) * playerSpeed * r * s
if (playerX < 0) { playerX += a.width }
if (playerY < 0) { playerY += a.height }
playerX = playerX % a.width
playerY = playerY % a.height
m += Math.cos(playerDirection) * playerSpeed * r * s
n += Math.sin(playerDirection) * playerSpeed * 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 = '#ffff00'
c.translate(playerX, playerY)
c.fillStyle = 'pink'
c.translate(m, n)
c.rotate(playerDirection)
c.beginPath()
c.moveTo(-r, -r)
......@@ -101,7 +99,7 @@ p = (() => {
c.setTransform(1, 0, 0, 1, 0, 0)
z.innerHTML = y.map((stat) => (
`<font color="${stat[0]}">${stat[1]} ${stat[2]}</font>`
`<font color="${stat[0]}">${stat[1]} ${stat[2] | 0}</font>`
)).join('&nbsp;&nbsp;')
}
})()
......@@ -112,7 +110,7 @@ u = (type) => {
let itemX = Math.random() * a.width
let itemY = Math.random() * a.height
return () => {
let me = () => {
let icon
[c.fillStyle, icon] = y[type]
......@@ -122,13 +120,28 @@ u = (type) => {
c.fillStyle = 'black'
c.fillText(icon, itemX, itemY)
if (((itemX - m) ** 2 + (itemY - n) ** 2) < (r * r)) {
y[type][2] += y[type][3]
e.splice(e.indexOf(me), 1)
}
}
return me
}
// Define the list of entities
e = [p, u(0)]
// Add a new item
v = () => {
e.push(u((Math.random() * y.length) | 0))
setTimeout(v, Math.random() * 5000)
}
v()
// Tick function
l = 0
......@@ -147,3 +160,7 @@ requestAnimationFrame(q = (currentTime) => {
requestAnimationFrame(q)
})
// Less and less time
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