05. Note Lifetime
In this chapter, we will implement lifetime logic of Note.
Note Archetype
Let's first set up Note:
export class Note extends Archetype {}
export class Note extends Archetype {}
export const archetypes = defineArchetypes({
// ...
Note,
})
export const archetypes = defineArchetypes({
// ...
Note,
})
While we are at it, let's also add life:
export class Note extends Archetype {
globalPreprocess() {
this.life.set({
perfect: 10,
great: 0,
good: 0,
miss: -100,
})
}
}
export class Note extends Archetype {
globalPreprocess() {
this.life.set({
perfect: 10,
great: 0,
good: 0,
miss: -100,
})
}
}
Target and Visual Times
Similar to play mode, we can use note's beat to calculate target and visual times:
export class Note extends Archetype {
import = this.defineImport({
beat: { name: EngineArchetypeDataName.Beat, type: Number },
})
targetTime = this.entityMemory(Number)
visualTime = this.entityMemory({
min: Number,
max: Number,
})
// ...
preprocess() {
this.targetTime = bpmChanges.at(this.import.beat).time
this.visualTime.max = timeScaleChanges.at(this.targetTime).scaledTime
this.visualTime.min = this.visualTime.max - 120 / bpmChanges.at(this.import.beat).bpm
}
}
export class Note extends Archetype {
import = this.defineImport({
beat: { name: EngineArchetypeDataName.Beat, type: Number },
})
targetTime = this.entityMemory(Number)
visualTime = this.entityMemory({
min: Number,
max: Number,
})
// ...
preprocess() {
this.targetTime = bpmChanges.at(this.import.beat).time
this.visualTime.max = timeScaleChanges.at(this.targetTime).scaledTime
this.visualTime.min = this.visualTime.max - 120 / bpmChanges.at(this.import.beat).bpm
}
}
Lifetime
Note's lifetime is simply its visual time:
export class Note extends Archetype {
// ...
spawnTime() {
return this.visualTime.min
}
despawnTime() {
return this.visualTime.max
}
}
export class Note extends Archetype {
// ...
spawnTime() {
return this.visualTime.min
}
despawnTime() {
return this.visualTime.max
}
}