-
Notifications
You must be signed in to change notification settings - Fork 7
/
note.ts
140 lines (124 loc) · 3.44 KB
/
note.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { EffectClip, ParticleEffect, SkinSprite } from 'sonolus-core'
import {
Add,
And,
createEntityData,
Divide,
Draw,
EntityMemory,
Greater,
GreaterOr,
If,
InputAccuracy,
InputBucket,
InputBucketValue,
InputJudgment,
InputOffset,
Judge,
Multiply,
Not,
Or,
Play,
Pointer,
Random,
Remap,
Script,
SpawnParticleEffect,
Subtract,
Time,
TouchST,
TouchStarted,
} from 'sonolus.js'
import { options } from '../../configuration/options'
import { buckets } from '../buckets'
import { isTouchOccupied } from './level-memory'
class EntityDataPointer extends Pointer {
public get time() {
return this.to<number>(0)
}
}
const EntityData = createEntityData(EntityDataPointer)
export function note(): Script {
const spawnTime = EntityMemory.to<number>(0)
const z = EntityMemory.to<number>(1)
const minInputTime = EntityMemory.to<number>(2)
const maxInputTime = EntityMemory.to<number>(3)
const yCurrent = EntityMemory.to<number>(32)
const inputState = EntityMemory.to<boolean>(33)
const preprocess = [
EntityData.time.set(Divide(EntityData.time, options.speed)),
spawnTime.set(
Subtract(EntityData.time, If(options.random, Random(0.5, 1.5), 1))
),
z.set(Subtract(1000, EntityData.time)),
minInputTime.set(Add(EntityData.time, -0.2, InputOffset)),
maxInputTime.set(Add(EntityData.time, 0.2, InputOffset)),
]
const spawnOrder = Add(spawnTime, 1000)
const shouldSpawn = GreaterOr(Time, spawnTime)
const touch = And(
TouchStarted,
GreaterOr(TouchST, minInputTime),
Not(isTouchOccupied),
[
inputState.set(true),
isTouchOccupied.set(true),
InputJudgment.set(
Judge(
Subtract(TouchST, InputOffset),
EntityData.time,
0.05,
0.1,
0.2
)
),
InputAccuracy.set(Subtract(TouchST, InputOffset, EntityData.time)),
InputBucket.set(buckets.noteIndex),
InputBucketValue.set(Multiply(1000, InputAccuracy)),
Play(Add(EffectClip.Miss, InputJudgment), 0.02),
SpawnParticleEffect(
ParticleEffect.NoteCircularTapCyan,
-0.4,
-1,
-0.4,
-0.2,
0.4,
-0.2,
0.4,
-1,
0.3,
false
),
]
)
const radius = 0.2
const yFrom = 1 + radius
const yTo = -0.6
const left = -radius
const right = radius
const top = Add(yCurrent, radius)
const bottom = Subtract(yCurrent, radius)
const updateParallel = Or(inputState, Greater(Time, maxInputTime), [
yCurrent.set(Remap(spawnTime, EntityData.time, yFrom, yTo, Time)),
Draw(
SkinSprite.NoteHeadCyan,
left,
bottom,
left,
top,
right,
top,
right,
bottom,
z,
1
),
])
return {
preprocess,
spawnOrder,
shouldSpawn,
touch,
updateParallel,
}
}