SPB Git

Repository Public License

PulseBeatGame.swift 16.5 KB 291 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Arcade9// File             : Games/PulseBeat/PulseBeatGame.swift10// Description      : Pulse Beat — arcade descriptor, trophies, statistics,11//                    challenge templates and the animated cover.12// Module           : Games13// Repository       : https://git.spboucher.ai/orix-arcade14// Created          : 2026-11-2115// Last Modified    : 2026-11-2216//17// =============================================================================18// AUTHOR & PROFESSIONAL AFFILIATION19// =============================================================================20//21// Author           : Simon-Pierre Boucher22// Position         : Professor of Finance23// Institution      : Université du Québec en Outaouais (UQO)24// Department       : Département des sciences administratives25// Organization     : SP Boucher26//27// Website          : https://spboucher.ai28// Git              : https://git.spboucher.ai29//30// =============================================================================31// OFFICIAL CONTACT DIRECTORY32// =============================================================================33//34// General          : info@spboucher.ai35// Professional     : contact@spboucher.ai36// Direct           : simon@spboucher.ai37// Research         : research@spboucher.ai38// Development      : dev@spboucher.ai39// Support          : support@spboucher.ai40// Security/Admin   : admin@spboucher.ai41// Notifications    : notifications@spboucher.ai42//43// Preferred Contact: support@spboucher.ai44//45// =============================================================================46// COPYRIGHT & INTELLECTUAL PROPERTY47// =============================================================================48//49// Copyright (c) 202650// Simon-Pierre Boucher51//52// All rights reserved where applicable.53//54// This file is governed by the applicable project license,55// copyright notices, institutional agreements and relevant law.56//57// Unless expressly authorized by the applicable license or58// rights holder, copying, redistribution, sublicensing,59// publication and commercial exploitation are not permitted.60//61// Existing third-party rights and notices remain unaffected.62//63// =============================================================================64// CONFIDENTIALITY & SECURITY65// =============================================================================66//67// Classification   : Public68// Distribution     : Public repository; use is governed by the project license69// Security Contact : admin@spboucher.ai70//71// Access to this source does not independently grant permission72// to redistribute or disclose confidential materials.73//74// Do not embed credentials, private keys, access tokens,75// certificates or confidential personal information.76//77// =============================================================================78// LICENSE & MAINTENANCE79// =============================================================================80//81// License          : Proprietary, all rights reserved (see license file)82// License File     : LICENSE83// Maintainer       : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import SwiftUI9192enum PulseBeatGame {93    static let achievements: [AchievementDef] = [94        .init(id: "pulse.first", game: .pulseBeat, title: "Sound Check", detail: "Clear your first chart.", symbol: "music.note",95              goal: .total("pulse.cleared", 1)),96        .init(id: "pulse.notes500", game: .pulseBeat, title: "Warm Hands", detail: "Hit 500 notes.", symbol: "hand.tap.fill",97              goal: .total("pulse.notes", 500)),98        .init(id: "pulse.notes5000", game: .pulseBeat, title: "Metronome", detail: "Hit 5,000 notes.", symbol: "metronome.fill",99              rarity: .rare, goal: .total("pulse.notes", 5000)),100        .init(id: "pulse.notes25000", game: .pulseBeat, title: "Human Sequencer", detail: "Hit 25,000 notes.", symbol: "pianokeys",101              rarity: .epic, goal: .total("pulse.notes", 25000)),102        .init(id: "pulse.perfects1000", game: .pulseBeat, title: "Sharp Ears", detail: "Land 1,000 Perfects.", symbol: "ear.fill",103              rarity: .rare, goal: .total("pulse.perfects", 1000)),104        .init(id: "pulse.combo50", game: .pulseBeat, title: "In the Pocket", detail: "Reach a 50 combo.", symbol: "bolt.fill",105              goal: .best("pulse.bestCombo", 50)),106        .init(id: "pulse.combo150", game: .pulseBeat, title: "Locked In", detail: "Reach a 150 combo.", symbol: "bolt.circle.fill",107              rarity: .rare, goal: .best("pulse.bestCombo", 150)),108        .init(id: "pulse.combo300", game: .pulseBeat, title: "Unbroken", detail: "Reach a 300 combo.", symbol: "bolt.shield.fill",109              rarity: .epic, goal: .best("pulse.bestCombo", 300)),110        .init(id: "pulse.score150k", game: .pulseBeat, title: "Six Figures", detail: "Score 150,000 on one chart.", symbol: "star.circle.fill",111              rarity: .rare, goal: .best("pulse.bestScore", 150_000)),112        .init(id: "pulse.cleared25", game: .pulseBeat, title: "Heavy Rotation", detail: "Clear 25 charts in total.", symbol: "repeat",113              rarity: .rare, goal: .total("pulse.cleared", 25)),114        .init(id: "pulse.fullCombo", game: .pulseBeat, title: "No Dropped Beats", detail: "Finish a chart without a single Miss.", symbol: "link",115              rarity: .rare, goal: .total("pulse.fullCombos", 1)),116        .init(id: "pulse.fullCombo10", game: .pulseBeat, title: "Clean Sets", detail: "Earn 10 full combos.", symbol: "link.circle.fill",117              rarity: .epic, goal: .total("pulse.fullCombos", 10)),118        .init(id: "pulse.sRank", game: .pulseBeat, title: "Headliner", detail: "Earn an S grade on any chart.", symbol: "s.circle.fill", rarity: .rare),119        .init(id: "pulse.hardClear", game: .pulseBeat, title: "Turn It Up", detail: "Clear a chart on Hard.", symbol: "flame.fill", rarity: .rare),120        .init(id: "pulse.expertClear", game: .pulseBeat, title: "Main Stage", detail: "Clear a chart on Expert.", symbol: "flame.circle.fill", rarity: .epic),121        .init(id: "pulse.allTracks", game: .pulseBeat, title: "Full Setlist", detail: "Clear all five tracks.", symbol: "music.note.list", rarity: .epic),122        .init(id: "pulse.calibrated", game: .pulseBeat, title: "Tuned Up", detail: "Calibrate your timing by tapping along.", symbol: "tuningfork"),123        .init(id: "pulse.expertS", game: .pulseBeat, title: "Virtuoso", detail: "Earn an S grade on Expert.", symbol: "crown.fill", rarity: .legendary),124        .init(id: "pulse.allPerfect", game: .pulseBeat, title: "Flawless Signal", detail: "Finish a chart with nothing but Perfects.", symbol: "sparkles",125              rarity: .legendary),126    ]127128    static let stats: [StatDef] = [129        .init(key: "pulse.notes", title: "Notes hit", symbol: "hand.tap.fill"),130        .init(key: "pulse.perfects", title: "Perfects", symbol: "sparkles"),131        .init(key: "pulse.bestCombo", title: "Best combo", symbol: "bolt.fill", kind: .best),132        .init(key: "pulse.bestAccuracy", title: "Best accuracy", symbol: "scope", kind: .best, unit: .percent),133        .init(key: "pulse.bestScore", title: "Best score", symbol: "star.fill", kind: .best, unit: .points),134        .init(key: "pulse.cleared", title: "Charts cleared", symbol: "checkmark.seal.fill"),135        .init(key: "pulse.fullCombos", title: "Full combos", symbol: "link"),136        .init(key: "pulse.plays", title: "Charts played", symbol: "play.fill"),137    ]138139    static let challenges: [ChallengeTemplate] = [140        .init(id: "pulse.c.notes", game: .pulseBeat, kind: .total, stat: "pulse.notes", title: "Hit %@ notes in Pulse Beat",141              symbol: "hand.tap.fill", daily: [150, 400, 800], weekly: 4000),142        .init(id: "pulse.c.perfects", game: .pulseBeat, kind: .total, stat: "pulse.perfects", title: "Land %@ Perfects in Pulse Beat",143              symbol: "sparkles", daily: [80, 220, 450], weekly: 2500),144        .init(id: "pulse.c.combo", game: .pulseBeat, kind: .best, stat: "pulse.bestCombo", title: "Reach a %@ combo in Pulse Beat",145              symbol: "bolt.fill", daily: [40, 80, 140], weekly: 220),146        .init(id: "pulse.c.cleared", game: .pulseBeat, kind: .total, stat: "pulse.cleared", title: "Clear %@ charts in Pulse Beat",147              symbol: "checkmark.seal.fill", daily: [1, 2, 4], weekly: 15),148    ]149150    static let descriptor = GameDescriptor(151        id: .pulseBeat,152        title: "Pulse Beat",153        tagline: "Hit every note of an original soundtrack.",154        theme: .pulseBeat,155        music: .pulseBeat,156        preview: { AnyView(PulseCoverView()) },157        bestLabel: { save in158            let best = save.pulse.overallBestScore159            return best > 0 ? "BEST \(best.formatted())" : nil160        },161        progress: { save in162            let cleared = save.pulse.chartsCleared163            return ("\(cleared) / \(PulseLibrary.chartCount) charts", Double(cleared) / Double(PulseLibrary.chartCount))164        },165        root: { onExit in AnyView(PulseRootView(onExit: onExit)) },166        category: .rhythm,167        isNew: true,168        achievements: achievements,169        stats: stats,170        challenges: challenges,171        mastery: { $0.pulse.mastery },172        continueLabel: { save in173            guard save.pulse.plays > 0, let track = PulseLibrary.track(save.pulse.lastTrack) else { return nil }174            return "\(track.title) · \(save.pulse.difficulty.title)"175        })176}177178/// Lobby cover: notes streaming down a neon highway towards the hit line, under a striped sun and a spectrum that moves on the beat.179struct PulseCoverView: View {180    var body: some View {181        AnimatedCover(stillTime: 2.3) { context, size, time in182            PulseCoverArt.draw(&context, size: size, time: time)183        }184    }185}186187enum PulseCoverArt {188    private static let laneColors: [Color] = PulseArt.laneHex.map { Color(hex: $0) }189    /// (lane, beat) pairs of a two-bar pattern that loops.190    private static let pattern: [(lane: Int, beat: Double)] = [191        (0, 0), (2, 0.5), (1, 1), (3, 1.5), (2, 2), (0, 2.5), (1, 3), (3, 3), (2, 4), (1, 4.5), (0, 5), (3, 5.5), (1, 6), (2, 6.5), (0, 7), (3, 7),192    ]193194    static func draw(_ context: inout GraphicsContext, size: CGSize, time: Double) {195        let w = size.width, h = size.height196        let theme = GameTheme.pulseBeat197        let beat = 0.5198        let phase = time / beat199        let pulse = exp(-4 * (phase - phase.rounded(.down)))200        context.fill(Path(CGRect(origin: .zero, size: size)),201                     with: .linearGradient(Gradient(colors: [Color(hex: 0x070312), theme.deep, Color(hex: 0x241046), Color(hex: 0x070312)]),202                                           startPoint: .zero, endPoint: CGPoint(x: 0, y: h)))203        let horizon = h * 0.36204        let center = w * 0.5205        // Sun.206        let radius = min(w, h) * 0.24207        let sunCenter = CGPoint(x: center, y: horizon - radius * 0.25)208        context.fill(Path(ellipseIn: CGRect(x: sunCenter.x - radius * 2.2, y: sunCenter.y - radius * 2.2, width: radius * 4.4, height: radius * 4.4)),209                     with: .radialGradient(Gradient(colors: [theme.primary.opacity(0.32 + 0.16 * pulse), .clear]), center: sunCenter, startRadius: 0, endRadius: radius * 2.2))210        var sun = context211        sun.clip(to: Path(CGRect(x: 0, y: 0, width: w, height: horizon)))212        sun.fill(Path(ellipseIn: CGRect(x: sunCenter.x - radius, y: sunCenter.y - radius, width: radius * 2, height: radius * 2)),213                 with: .linearGradient(Gradient(colors: [Color(hex: 0xFFD166), theme.primary]), startPoint: CGPoint(x: 0, y: sunCenter.y - radius),214                                       endPoint: CGPoint(x: 0, y: sunCenter.y + radius)))215        var stripeY = sunCenter.y + radius * 0.05216        var thickness: CGFloat = 1.5217        while stripeY < horizon {218            sun.fill(Path(CGRect(x: sunCenter.x - radius, y: stripeY, width: radius * 2, height: thickness)), with: .color(Color(hex: 0x160733)))219            stripeY += thickness + 6220            thickness += 1221        }222        // Spectrum along the horizon.223        let barCount = 18224        for index in 0..<barCount {225            let x = (CGFloat(index) + 0.5) * w / CGFloat(barCount)226            let wobble = 0.5 + 0.5 * sin(time * (2.1 + Double(index % 5) * 0.7) + Double(index) * 1.3)227            let height = (6 + 30 * wobble * (0.45 + 0.55 * pulse)) * h / 300228            context.fill(Path(roundedRect: CGRect(x: x - w / CGFloat(barCount) * 0.3, y: horizon - height, width: w / CGFloat(barCount) * 0.6, height: height), cornerRadius: 1.5),229                         with: .color(index.isMultiple(of: 2) ? theme.secondary.opacity(0.75) : theme.primary.opacity(0.75)))230        }231        // Ground and road.232        context.fill(Path(CGRect(x: 0, y: horizon, width: w, height: h - horizon)), with: .color(Color(hex: 0x06040F)))233        let halfTop = w * 0.09, halfBottom = w * 0.46234        let hitY = h * 0.84235        func point(_ lane: CGFloat, _ f: CGFloat) -> CGPoint {236            let half = halfBottom + (halfTop - halfBottom) * f237            return CGPoint(x: center + (lane - 2) / 2 * half, y: hitY + (horizon - hitY) * f)238        }239        let bottomF = -(h - hitY) / (hitY - horizon)240        var road = Path()241        road.move(to: point(0, bottomF)); road.addLine(to: point(4, bottomF)); road.addLine(to: point(4, 1)); road.addLine(to: point(0, 1)); road.closeSubpath()242        context.fill(road, with: .color(Color(hex: 0x0B0720)))243        for divider in 0...4 {244            var line = Path()245            line.move(to: point(CGFloat(divider), bottomF)); line.addLine(to: point(CGFloat(divider), 1))246            let edge = divider == 0 || divider == 4247            context.stroke(line, with: .color(edge ? theme.primary.opacity(0.9) : Color.white.opacity(0.14)), lineWidth: edge ? 2.2 : 1)248        }249        func fraction(_ p: Double) -> CGFloat { CGFloat(p * 2.5 / (1 + 1.5 * p)) }250        // Beat lines.251        let lookahead = 4.0252        for k in 0..<5 {253            let p = (Double(k) + 1 - (phase - phase.rounded(.down))) / lookahead254            guard p <= 1 else { continue }255            let f = fraction(p)256            var line = Path()257            line.move(to: point(0, f)); line.addLine(to: point(4, f))258            context.stroke(line, with: .color(.white.opacity(0.12 * (1 - p))), lineWidth: 1)259        }260        // Notes.261        let loop = phase.truncatingRemainder(dividingBy: 8)262        for note in pattern {263            var ahead = note.beat - loop264            if ahead < -0.5 { ahead += 8 }265            let p = ahead / lookahead266            guard p <= 1, p > -0.12 else { continue }267            let f = p >= 0 ? fraction(p) : CGFloat(p * 2.5)268            let left = point(CGFloat(note.lane) + 0.1, f), right = point(CGFloat(note.lane) + 0.9, f)269            let height = max(3, 13 * (1 - 0.72 * f))270            let rect = CGRect(x: left.x, y: left.y - height / 2, width: right.x - left.x, height: height)271            let color = laneColors[note.lane]272            let alpha = min(1, (1 - p) / 0.15)273            context.fill(Path(roundedRect: rect.insetBy(dx: -3, dy: -3), cornerRadius: height), with: .color(color.opacity(0.28 * alpha)))274            context.fill(Path(roundedRect: rect, cornerRadius: height / 2), with: .color(color.opacity(alpha)))275            context.fill(Path(roundedRect: rect.insetBy(dx: rect.width * 0.2, dy: height * 0.32), cornerRadius: height / 4), with: .color(.white.opacity(0.75 * alpha)))276            // The lane lights up as its note lands.277            if abs(ahead) < 0.22 {278                var lane = Path()279                lane.move(to: point(CGFloat(note.lane), bottomF)); lane.addLine(to: point(CGFloat(note.lane) + 1, bottomF))280                lane.addLine(to: point(CGFloat(note.lane) + 1, 1)); lane.addLine(to: point(CGFloat(note.lane), 1)); lane.closeSubpath()281                context.fill(lane, with: .color(color.opacity(0.3 * (1 - abs(ahead) / 0.22))))282            }283        }284        // Hit line.285        var hit = Path()286        hit.move(to: point(0, 0)); hit.addLine(to: point(4, 0))287        context.stroke(hit, with: .color(.white.opacity(0.75 + 0.25 * pulse)), lineWidth: 2.5)288        context.stroke(hit, with: .color(theme.secondary.opacity(0.35 + 0.3 * pulse)), lineWidth: 8)289    }290}291
Files main
Menu

Theme