forked from iamkun/tower_game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline.js
40 lines (37 loc) · 1.01 KB
/
line.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { getMoveDownValue, getLandBlockVelocity } from './utils'
import * as constant from './constant'
export const lineAction = (instance, engine, time) => {
const i = instance
if (!i.ready) {
i.y = engine.getVariable(constant.lineInitialOffset)
i.ready = true
i.collisionX = engine.width - engine.getVariable(constant.blockWidth)
}
engine.getTimeMovement(
constant.moveDownMovement,
[[instance.y, instance.y + (getMoveDownValue(engine, { pixelsPerFrame: s => s / 2 }))]],
(value) => {
instance.y = value
},
{
name: 'line'
}
)
const landBlockVelocity = getLandBlockVelocity(engine, time)
instance.x += landBlockVelocity
instance.collisionX += landBlockVelocity
}
export const linePainter = (instance, engine) => {
const { ctx, debug } = engine
if (!debug) {
return
}
ctx.save()
ctx.beginPath()
ctx.strokeStyle = 'red'
ctx.moveTo(instance.x, instance.y)
ctx.lineTo(instance.collisionX, instance.y)
ctx.lineWidth = 1
ctx.stroke()
ctx.restore()
}