SPB Git

Repository Public License

DominoArt.swift 22.9 KB 473 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Arcade9// File             : Games/DominoCity/DominoArt.swift10// Description      : Domino City — all sprites drawn in code, per theme:11//                    building-slab dominoes (lit and dark), crates, explosives,12//                    rooftops, belts, platforms, seesaws, orbs, beacons,13//                    switches, hazards, the sky and the skyline.14// Module           : Games15// Repository       : https://git.spboucher.ai/orix-arcade16// Created          : 2026-11-2117// Last Modified    : 2026-11-2118//19// =============================================================================20// AUTHOR & PROFESSIONAL AFFILIATION21// =============================================================================22//23// Author           : Simon-Pierre Boucher24// Position         : Professor of Finance25// Institution      : Université du Québec en Outaouais (UQO)26// Department       : Département des sciences administratives27// Organization     : SP Boucher28//29// Website          : https://spboucher.ai30// Git              : https://git.spboucher.ai31//32// =============================================================================33// OFFICIAL CONTACT DIRECTORY34// =============================================================================35//36// General          : info@spboucher.ai37// Professional     : contact@spboucher.ai38// Direct           : simon@spboucher.ai39// Research         : research@spboucher.ai40// Development      : dev@spboucher.ai41// Support          : support@spboucher.ai42// Security/Admin   : admin@spboucher.ai43// Notifications    : notifications@spboucher.ai44//45// Preferred Contact: support@spboucher.ai46//47// =============================================================================48// COPYRIGHT & INTELLECTUAL PROPERTY49// =============================================================================50//51// Copyright (c) 202652// Simon-Pierre Boucher53//54// All rights reserved where applicable.55//56// This file is governed by the applicable project license,57// copyright notices, institutional agreements and relevant law.58//59// Unless expressly authorized by the applicable license or60// rights holder, copying, redistribution, sublicensing,61// publication and commercial exploitation are not permitted.62//63// Existing third-party rights and notices remain unaffected.64//65// =============================================================================66// CONFIDENTIALITY & SECURITY67// =============================================================================68//69// Classification   : Public70// Distribution     : Public repository; use is governed by the project license71// Security Contact : admin@spboucher.ai72//73// Access to this source does not independently grant permission74// to redistribute or disclose confidential materials.75//76// Do not embed credentials, private keys, access tokens,77// certificates or confidential personal information.78//79// =============================================================================80// LICENSE & MAINTENANCE81// =============================================================================82//83// License          : Proprietary, all rights reserved (see license file)84// License File     : LICENSE85// Maintainer       : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import SpriteKit93import UIKit9495enum DominoArt {96    /// Building colours of the default theme (also used by the lobby cover).97    static let palette: [UInt32] = DominoTheme.dusk.palette98    static let gold: UInt32 = 0xFFC94D99    static let danger: UInt32 = 0xFF4A4A100    static let night: UInt32 = DominoTheme.dusk.night101102    private static func gradient(_ ctx: CGContext, _ rect: CGRect, _ top: UIColor, _ bottom: UIColor) {103        let g = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: [top.cgColor, bottom.cgColor] as CFArray, locations: [0, 1])!104        ctx.drawLinearGradient(g, start: CGPoint(x: rect.midX, y: rect.minY), end: CGPoint(x: rect.midX, y: rect.maxY), options: [])105    }106107    private static func clipRounded(_ ctx: CGContext, _ rect: CGRect, _ radius: CGFloat) {108        ctx.addPath(UIBezierPath(roundedRect: rect, cornerRadius: radius).cgPath)109        ctx.clip()110    }111112    /// A slim tower slab: gradient body, darker side strip for depth, windows that are lit while it stands and dark once it has fallen.113    static func slab(width: CGFloat, height: CGFloat, colorHex: UInt32, gold isGold: Bool, lit: Bool = true) -> SKTexture {114        let key = "domino-slab-\(Int(width))x\(Int(height))-\(colorHex)-\(isGold)-\(lit)"115        return TextureFactory.texture(key, size: CGSize(width: width, height: height)) { ctx, size in116            let base = lit ? UIColor(hex: colorHex) : UIColor(hex: colorHex).darker(0.32)117            let rect = CGRect(origin: .zero, size: size)118            ctx.saveGState()119            clipRounded(ctx, rect, min(2.5, width * 0.25))120            gradient(ctx, rect, base.lighter(0.28), base.darker(0.22))121            // Side face.122            ctx.setFillColor(UIColor.black.withAlphaComponent(0.22).cgColor)123            ctx.fill(CGRect(x: size.width * 0.72, y: 0, width: size.width * 0.28, height: size.height))124            // Roof cap.125            ctx.setFillColor(UIColor.white.withAlphaComponent(lit ? 0.55 : 0.25).cgColor)126            ctx.fill(CGRect(x: 0, y: 0, width: size.width, height: 2))127            let glow = isGold ? UIColor(hex: 0xFFF6D0) : UIColor(hex: 0xFFF1B8)128            let cols = max(1, Int((size.width * 0.7) / 4.5))129            let cell = (size.width * 0.7) / CGFloat(cols)130            var row = 0131            var y: CGFloat = 5132            while y < size.height - 5 {133                for col in 0..<cols {134                    let on = lit && (row * 7 + col * 3 + Int(colorHex % 5)) % 3 != 0135                    ctx.setFillColor((on ? glow.withAlphaComponent(0.9) : UIColor.black.withAlphaComponent(0.28)).cgColor)136                    ctx.fill(CGRect(x: 1.2 + CGFloat(col) * cell, y: y, width: max(1.6, cell - 1.6), height: 2.6))137                }138                y += 6139                row += 1140            }141            ctx.restoreGState()142            if isGold {143                ctx.addPath(UIBezierPath(roundedRect: rect.insetBy(dx: 0.5, dy: 0.5), cornerRadius: 2.5).cgPath)144                ctx.setStrokeColor(UIColor(hex: 0xFFF3C4).cgColor)145                ctx.setLineWidth(1)146                ctx.strokePath()147            }148        }149    }150151    /// Explosive piece: red body, hazard chevrons, a pale cap. Recognisable without colour by its stripes.152    static func explosive(width: CGFloat, height: CGFloat) -> SKTexture {153        TextureFactory.texture("domino-tnt-\(Int(width))x\(Int(height))", size: CGSize(width: width, height: height)) { ctx, size in154            let rect = CGRect(origin: .zero, size: size)155            ctx.saveGState()156            clipRounded(ctx, rect, min(3, width * 0.25))157            gradient(ctx, rect, UIColor(hex: 0xFF6B5E), UIColor(hex: 0xB3202A))158            ctx.setFillColor(UIColor(hex: 0x2A0B10).withAlphaComponent(0.85).cgColor)159            var offset: CGFloat = -size.width160            while offset < size.height + size.width {161                ctx.move(to: CGPoint(x: 0, y: offset))162                ctx.addLine(to: CGPoint(x: size.width, y: offset + size.width * 0.8))163                ctx.addLine(to: CGPoint(x: size.width, y: offset + size.width * 0.8 + 4))164                ctx.addLine(to: CGPoint(x: 0, y: offset + 4))165                ctx.closePath()166                ctx.fillPath()167                offset += 10168            }169            ctx.setFillColor(UIColor(hex: 0xFFE9B0).cgColor)170            ctx.fill(CGRect(x: 0, y: 0, width: size.width, height: 2.5))171            ctx.restoreGState()172            ctx.addPath(UIBezierPath(roundedRect: rect.insetBy(dx: 0.5, dy: 0.5), cornerRadius: 3).cgPath)173            ctx.setStrokeColor(UIColor(hex: 0xFFD0C0).cgColor)174            ctx.setLineWidth(1)175            ctx.strokePath()176        }177    }178179    static func ledge(width: CGFloat, height: CGFloat, theme: DominoTheme) -> SKTexture {180        TextureFactory.texture("domino-ledge-\(theme.id)-\(Int(width))x\(Int(height))", size: CGSize(width: width, height: height)) { ctx, size in181            let rect = CGRect(origin: .zero, size: size)182            ctx.saveGState()183            clipRounded(ctx, rect, 3)184            gradient(ctx, rect, UIColor(hex: theme.ledgeTop), UIColor(hex: theme.ledgeBottom))185            ctx.setFillColor(UIColor(hex: theme.accent).withAlphaComponent(0.95).cgColor)186            ctx.fill(CGRect(x: 0, y: 0, width: size.width, height: 2))187            ctx.setFillColor(UIColor.white.withAlphaComponent(0.10).cgColor)188            var x: CGFloat = 6189            while x < size.width - 4 {190                ctx.fill(CGRect(x: x, y: 5, width: 5, height: max(1, size.height - 8)))191                x += 14192            }193            ctx.restoreGState()194        }195    }196197    static func plank(width: CGFloat, height: CGFloat, seesaw: Bool = false) -> SKTexture {198        TextureFactory.texture("domino-plank-\(Int(width))x\(Int(height))-\(seesaw)", size: CGSize(width: width, height: height)) { ctx, size in199            let rect = CGRect(origin: .zero, size: size)200            ctx.saveGState()201            clipRounded(ctx, rect, 2)202            if seesaw {203                gradient(ctx, rect, UIColor(hex: 0xFFC38A), UIColor(hex: 0xD9743A))204            } else {205                gradient(ctx, rect, UIColor(hex: 0xE2B07A), UIColor(hex: 0x9C6B3F))206            }207            ctx.setFillColor(UIColor.black.withAlphaComponent(0.2).cgColor)208            var x: CGFloat = 14209            while x < size.width - 4 {210                ctx.fill(CGRect(x: x, y: 0, width: 1, height: size.height))211                x += 18212            }213            if seesaw {214                // Bolt at the pivot.215                ctx.setFillColor(UIColor(hex: 0x3A2A20).cgColor)216                ctx.fillEllipse(in: CGRect(x: size.width / 2 - 3, y: size.height / 2 - 3, width: 6, height: 6))217            }218            ctx.restoreGState()219        }220    }221222    /// Triangular stand under a seesaw.223    static var pivot: SKTexture {224        TextureFactory.texture("domino-pivot", size: CGSize(width: 30, height: 26)) { ctx, size in225            ctx.move(to: CGPoint(x: size.width / 2, y: 0))226            ctx.addLine(to: CGPoint(x: size.width, y: size.height))227            ctx.addLine(to: CGPoint(x: 0, y: size.height))228            ctx.closePath()229            ctx.clip()230            gradient(ctx, CGRect(origin: .zero, size: size), UIColor(hex: 0xA9AED3), UIColor(hex: 0x4A4F78))231        }232    }233234    /// Belt body; the moving chevrons are separate sprites.235    static func belt(width: CGFloat, height: CGFloat) -> SKTexture {236        TextureFactory.texture("domino-belt-\(Int(width))x\(Int(height))", size: CGSize(width: width, height: height)) { ctx, size in237            let rect = CGRect(origin: .zero, size: size)238            ctx.saveGState()239            clipRounded(ctx, rect, min(6, size.height / 2))240            gradient(ctx, rect, UIColor(hex: 0x3C4466), UIColor(hex: 0x1C2038))241            ctx.setFillColor(UIColor(hex: 0x8CFFE2).withAlphaComponent(0.9).cgColor)242            ctx.fill(CGRect(x: 0, y: 0, width: size.width, height: 2))243            ctx.setFillColor(UIColor.black.withAlphaComponent(0.35).cgColor)244            ctx.fillEllipse(in: CGRect(x: 2, y: 3, width: size.height - 5, height: size.height - 5))245            ctx.fillEllipse(in: CGRect(x: size.width - size.height + 3, y: 3, width: size.height - 5, height: size.height - 5))246            ctx.restoreGState()247        }248    }249250    /// Chevron pointing right, tiled along a belt.251    static var chevron: SKTexture {252        TextureFactory.texture("domino-chevron", size: CGSize(width: 8, height: 7)) { ctx, size in253            ctx.setStrokeColor(UIColor(hex: 0x8CFFE2).cgColor)254            ctx.setLineWidth(1.6)255            ctx.setLineCap(.round)256            ctx.setLineJoin(.round)257            ctx.move(to: CGPoint(x: 1.5, y: 1))258            ctx.addLine(to: CGPoint(x: 6, y: size.height / 2))259            ctx.addLine(to: CGPoint(x: 1.5, y: size.height - 1))260            ctx.strokePath()261        }262    }263264    /// Moving platform: steel deck with hazard ends.265    static func platform(width: CGFloat, height: CGFloat) -> SKTexture {266        TextureFactory.texture("domino-platform-\(Int(width))x\(Int(height))", size: CGSize(width: width, height: height)) { ctx, size in267            let rect = CGRect(origin: .zero, size: size)268            ctx.saveGState()269            clipRounded(ctx, rect, 3)270            gradient(ctx, rect, UIColor(hex: 0xC9D2F0), UIColor(hex: 0x5B6490))271            ctx.setFillColor(UIColor(hex: 0xFFD23F).cgColor)272            ctx.fill(CGRect(x: 0, y: 0, width: 9, height: size.height))273            ctx.fill(CGRect(x: size.width - 9, y: 0, width: 9, height: size.height))274            ctx.setFillColor(UIColor(hex: 0x1A1030).cgColor)275            for x in [CGFloat(3), size.width - 6] { ctx.fill(CGRect(x: x, y: 0, width: 3, height: size.height)) }276            ctx.setFillColor(UIColor.white.withAlphaComponent(0.6).cgColor)277            ctx.fill(CGRect(x: 0, y: 0, width: size.width, height: 1.5))278            ctx.restoreGState()279        }280    }281282    static func orb(radius: CGFloat, colorHex: UInt32) -> SKTexture {283        TextureFactory.texture("domino-orb-\(Int(radius))-\(colorHex)", size: CGSize(width: radius * 2, height: radius * 2)) { ctx, size in284            let base = UIColor(hex: colorHex)285            let colors = [base.lighter(0.75).cgColor, base.cgColor, base.darker(0.45).cgColor] as CFArray286            let g = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: colors, locations: [0, 0.55, 1])!287            ctx.addEllipse(in: CGRect(origin: .zero, size: size).insetBy(dx: 0.5, dy: 0.5))288            ctx.clip()289            ctx.drawRadialGradient(g, startCenter: CGPoint(x: size.width * 0.36, y: size.height * 0.32), startRadius: 0,290                                   endCenter: CGPoint(x: size.width / 2, y: size.height / 2), endRadius: radius * 1.05, options: [.drawsAfterEndLocation])291            // A seam so rolling reads clearly.292            ctx.setStrokeColor(UIColor.black.withAlphaComponent(0.28).cgColor)293            ctx.setLineWidth(max(1, radius * 0.14))294            ctx.move(to: CGPoint(x: 1, y: size.height / 2))295            ctx.addLine(to: CGPoint(x: size.width - 1, y: size.height / 2))296            ctx.strokePath()297        }298    }299300    static func beacon(lit: Bool) -> SKTexture {301        TextureFactory.texture("domino-beacon-\(lit)", size: CGSize(width: 36, height: 36)) { ctx, size in302            let c = CGPoint(x: size.width / 2, y: size.height / 2)303            let color = lit ? UIColor(hex: 0x4DE3A1) : UIColor(hex: gold)304            ctx.setFillColor(UIColor(hex: night).withAlphaComponent(0.9).cgColor)305            ctx.fillEllipse(in: CGRect(x: 2, y: 2, width: 32, height: 32))306            ctx.setStrokeColor(color.cgColor)307            ctx.setLineWidth(2.5)308            ctx.strokeEllipse(in: CGRect(x: 3, y: 3, width: 30, height: 30))309            // Five-point star.310            let path = UIBezierPath()311            for i in 0..<10 {312                let a = CGFloat(i) * .pi / 5 - .pi / 2313                let r: CGFloat = i.isMultiple(of: 2) ? 10.5 : 4.6314                let p = CGPoint(x: c.x + cos(a) * r, y: c.y + sin(a) * r)315                if i == 0 { path.move(to: p) } else { path.addLine(to: p) }316            }317            path.close()318            ctx.addPath(path.cgPath)319            ctx.setFillColor(color.cgColor)320            ctx.fillPath()321        }322    }323324    static var gem: SKTexture {325        TextureFactory.texture("domino-gem", size: CGSize(width: 22, height: 22)) { ctx, size in326            let path = UIBezierPath()327            path.move(to: CGPoint(x: 11, y: 1))328            path.addLine(to: CGPoint(x: 21, y: 9))329            path.addLine(to: CGPoint(x: 11, y: 21))330            path.addLine(to: CGPoint(x: 1, y: 9))331            path.close()332            ctx.saveGState()333            ctx.addPath(path.cgPath)334            ctx.clip()335            gradient(ctx, CGRect(origin: .zero, size: size), UIColor(hex: 0xBFF4FF), UIColor(hex: 0x2FA8E8))336            ctx.setFillColor(UIColor.white.withAlphaComponent(0.55).cgColor)337            ctx.move(to: CGPoint(x: 11, y: 1))338            ctx.addLine(to: CGPoint(x: 6, y: 9))339            ctx.addLine(to: CGPoint(x: 11, y: 9))340            ctx.closePath()341            ctx.fillPath()342            ctx.restoreGState()343        }344    }345346    static func switchPad(fired: Bool) -> SKTexture {347        TextureFactory.texture("domino-switch-\(fired)", size: CGSize(width: 34, height: 34)) { ctx, _ in348            let rings: [(CGFloat, UIColor)] = fired349                ? [(16, UIColor(hex: 0x2A3350)), (11, UIColor(hex: 0x4DE3A1)), (5, UIColor(hex: 0x2A3350))]350                : [(16, UIColor.white), (12.5, UIColor(hex: 0xFF5470)), (8.5, UIColor.white), (4.5, UIColor(hex: 0xFF5470))]351            for (radius, color) in rings {352                ctx.setFillColor(color.cgColor)353                ctx.fillEllipse(in: CGRect(x: 17 - radius, y: 17 - radius, width: radius * 2, height: radius * 2))354            }355        }356    }357358    static func gate(width: CGFloat, height: CGFloat) -> SKTexture {359        TextureFactory.texture("domino-gate-\(Int(width))x\(Int(height))", size: CGSize(width: width, height: height)) { ctx, size in360            let rect = CGRect(origin: .zero, size: size)361            ctx.saveGState()362            clipRounded(ctx, rect, 2)363            ctx.setFillColor(UIColor(hex: 0x2A2440).cgColor)364            ctx.fill(rect)365            ctx.setFillColor(UIColor(hex: 0xFF5470).cgColor)366            var offset: CGFloat = -size.width367            while offset < size.height + size.width {368                ctx.move(to: CGPoint(x: 0, y: offset))369                ctx.addLine(to: CGPoint(x: size.width, y: offset + size.width))370                ctx.addLine(to: CGPoint(x: size.width, y: offset + size.width + 6))371                ctx.addLine(to: CGPoint(x: 0, y: offset + 6))372                ctx.closePath()373                ctx.fillPath()374                offset += 13375            }376            ctx.restoreGState()377        }378    }379380    static func tar(width: CGFloat, height: CGFloat) -> SKTexture {381        TextureFactory.texture("domino-tar-\(Int(width))x\(Int(height))", size: CGSize(width: width, height: height)) { ctx, size in382            let rect = CGRect(origin: .zero, size: size)383            ctx.saveGState()384            clipRounded(ctx, rect, min(5, size.height / 2))385            gradient(ctx, rect, UIColor(hex: 0xC86BFF), UIColor(hex: 0x4A1D7A))386            ctx.setFillColor(UIColor.white.withAlphaComponent(0.55).cgColor)387            var x: CGFloat = 8388            var index = 0389            while x < size.width - 6 {390                let r: CGFloat = index.isMultiple(of: 2) ? 2.2 : 1.4391                ctx.fillEllipse(in: CGRect(x: x, y: 2.5, width: r * 2, height: r * 2))392                x += index.isMultiple(of: 2) ? 17 : 11393                index += 1394            }395            ctx.restoreGState()396        }397    }398399    static func bouncer(width: CGFloat, height: CGFloat) -> SKTexture {400        TextureFactory.texture("domino-bouncer-\(Int(width))x\(Int(height))", size: CGSize(width: width, height: height)) { ctx, size in401            let rect = CGRect(origin: .zero, size: size)402            ctx.saveGState()403            clipRounded(ctx, rect, min(5, size.height / 2))404            gradient(ctx, rect, UIColor(hex: 0x8CFFE2), UIColor(hex: 0x16A085))405            ctx.setFillColor(UIColor(hex: night).withAlphaComponent(0.55).cgColor)406            var x: CGFloat = 6407            while x < size.width - 8 {408                // Up chevrons.409                ctx.move(to: CGPoint(x: x, y: size.height - 2.5))410                ctx.addLine(to: CGPoint(x: x + 4, y: 3))411                ctx.addLine(to: CGPoint(x: x + 8, y: size.height - 2.5))412                ctx.addLine(to: CGPoint(x: x + 4, y: size.height - 5))413                ctx.closePath()414                ctx.fillPath()415                x += 12416            }417            ctx.restoreGState()418        }419    }420421    /// Thin ring used for blast waves and target pings.422    static var ring: SKTexture {423        TextureFactory.texture("domino-ring", size: CGSize(width: 64, height: 64)) { ctx, size in424            ctx.setStrokeColor(UIColor.white.cgColor)425            ctx.setLineWidth(4)426            ctx.strokeEllipse(in: CGRect(origin: .zero, size: size).insetBy(dx: 3, dy: 3))427        }428    }429430    static func sky(theme: DominoTheme) -> SKTexture {431        TextureFactory.texture("domino-sky-\(theme.id)", size: CGSize(width: 8, height: 256)) { ctx, size in432            let colors = theme.sky.map { UIColor(hex: $0).cgColor } as CFArray433            let g = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: colors, locations: [0, 0.45, 0.8, 1])!434            ctx.drawLinearGradient(g, start: .zero, end: CGPoint(x: 0, y: size.height), options: [])435        }436    }437438    static func windowTile(theme: DominoTheme) -> SKTexture {439        TextureFactory.texture("domino-window-tile-\(theme.id)", size: CGSize(width: 48, height: 96)) { ctx, _ in440            for row in 0..<8 {441                for col in 0..<4 {442                    let on = (row * 5 + col * 7) % 4 == 0 || (row + col * 3) % 7 == 0443                    ctx.setFillColor((on ? UIColor(hex: theme.window).withAlphaComponent(0.55) : UIColor.white.withAlphaComponent(0.035)).cgColor)444                    ctx.fill(CGRect(x: 5 + col * 11, y: 6 + row * 11, width: 6, height: 6))445                }446            }447        }448    }449450    /// Decorative skyline behind the stage (no physics), two layers. Deterministic per level.451    static func skyline(levelID: Int, theme: DominoTheme, minX: Double, maxX: Double, layer: Int) -> SKNode {452        let node = SKNode()453        var rng = SeededRNG(seed: UInt64(1000 + levelID * 7 + layer))454        var x = minX - 320455        while x < maxX + 320 {456            let width = rng.double(in: 34...74)457            let height = rng.double(in: layer == 0 ? 150...420 : 70...240)458            let building = SKSpriteNode(color: UIColor(hex: layer == 0 ? theme.skylineFar : theme.skylineNear), size: CGSize(width: width, height: height))459            building.anchorPoint = CGPoint(x: 0, y: 0)460            building.position = CGPoint(x: x, y: DominoTuning.groundTop)461            node.addChild(building)462            let tile = SKSpriteNode(texture: windowTile(theme: theme), size: CGSize(width: 48, height: 96))463            tile.anchorPoint = CGPoint(x: 0, y: 1)464            tile.position = CGPoint(x: (width - 48) / 2, y: height - 4)465            tile.alpha = layer == 0 ? 0.55 : 0.8466            tile.zPosition = 1467            if width >= 50, height > 100 { building.addChild(tile) }468            x += width + rng.double(in: 2...22)469        }470        return node471    }472}473
Files main
Menu

Theme