From c57aeacc986bd1c6c8a10fd8c98fc988cce0dc97 Mon Sep 17 00:00:00 2001 From: Zutatensuppe Date: Sun, 18 Jul 2021 18:10:09 +0200 Subject: [PATCH] magnet time --- src/main.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.js b/src/main.js index e447b59..621fd6d 100644 --- a/src/main.js +++ b/src/main.js @@ -503,6 +503,8 @@ function attack(name, ...args) { } else { obj.vy = player.y > obj.y ? -1 : 1 } + obj.vx *=2 + obj.vy *=2 } } const anim = createAttackAnim(player, (50 + extraRadius + extraRadius) * 1.25 ) @@ -620,6 +622,26 @@ function play(delta) { } } + if (chargeLen > 0) { + const extraRadius = 50 + const playerRect = { + x: player.x - extraRadius, + y: player.y - extraRadius, + width: player.width + extraRadius + extraRadius, + height: player.height + extraRadius + extraRadius, + } + for (const obj of objects) { + if (hitTestRectangle(playerRect, obj)) { + const dir = player.x > obj.x ? 1 : -1 + obj.vrot = .1 * dir + obj.ticks += 1 + + obj.vx = player.x > obj.x ? 1 : -1 + obj.vy = player.y > obj.y ? 1 : -1 + } + } + } + for (const c of objects) { if (c.type === 'cow') { if (c.vrot > 0 && c.ticks > 0) {