fork download
  1. import SwiftUI
  2.  
  3. struct ContentView: View {
  4. var body: some View {
  5. TabView {
  6. HomeView()
  7. .tabItem {
  8. Image(systemName: "house.fill")
  9. Text("Home")
  10. }
  11.  
  12. GachaView()
  13. .tabItem {
  14. Image(systemName: "gift.fill")
  15. Text("Gacha")
  16. }
  17.  
  18. TeamView()
  19. .tabItem {
  20. Image(systemName: "person.3.fill")
  21. Text("Team")
  22. }
  23.  
  24. SettingsView()
  25. .tabItem {
  26. Image(systemName: "gearshape.fill")
  27. Text("Settings")
  28. }
  29. }
  30. .accentColor(.blue) // เปลี่ยนสีของ Tab Bar
  31. }
  32. }
  33.  
  34. struct HomeView: View {
  35. var body: some View {
  36. ZStack {
  37. Image("background_home") // ใช้ภาพพื้นหลัง
  38. .resizable()
  39. .scaledToFill()
  40. .edgesIgnoringSafeArea(.all)
  41.  
  42. VStack {
  43. Text("Welcome to Blue Archive Clone")
  44. .font(.title)
  45. .fontWeight(.bold)
  46. .foregroundColor(.white)
  47. .padding()
  48.  
  49. Spacer()
  50.  
  51. Button(action: {
  52. print("Go to Battle!")
  53. }) {
  54. Text("Battle")
  55. .font(.title2)
  56. .padding()
  57. .frame(maxWidth: .infinity)
  58. .background(Color.blue)
  59. .foregroundColor(.white)
  60. .cornerRadius(10)
  61. .padding(.horizontal, 20)
  62. }
  63.  
  64. Spacer()
  65. }
  66. }
  67. }
  68. }
  69.  
  70. // สร้างโครงหน้ากาชา
  71. struct GachaView: View {
  72. var body: some View {
  73. Text("Gacha System")
  74. .font(.title)
  75. }
  76. }
  77.  
  78. // สร้างโครงหน้าทีม
  79. struct TeamView: View {
  80. var body: some View {
  81. Text("Team Management")
  82. .font(.title)
  83. }
  84. }
  85.  
  86. // สร้างโครงหน้าตั้งค่า
  87. struct SettingsView: View {
  88. var body: some View {
  89. Text("Settings")
  90. .font(.title)
  91. }
  92. }
  93.  
  94. struct ContentView_Previews: PreviewProvider {
  95. static var previews: some View {
  96. ContentView()
  97. }
  98. }
  99. import SwiftUI
  100. import SceneKit
  101.  
  102. struct BattleView: View {
  103. var scene = SCNScene(named: "BattleScene.scn")!
  104.  
  105. var body: some View {
  106. SceneView(
  107. scene: scene,
  108. options: [.allowsCameraControl, .autoenablesDefaultLighting]
  109. )
  110. .edgesIgnoringSafeArea(.all)
  111. }
  112. }
  113. let player = SCNNode()
  114. player.geometry = SCNSphere(radius: 0.5) // ใช้ Sphere แทนตัวละครชั่วคราว
  115. player.position = SCNVector3(x: -2, y: 0, z: 0)
  116.  
  117. let enemy = SCNNode()
  118. enemy.geometry = SCNSphere(radius: 0.5)
  119. enemy.position = SCNVector3(x: 2, y: 0, z: 0)
  120.  
  121. scene.rootNode.addChildNode(player)
  122. scene.rootNode.addChildNode(enemy)
  123. func attackAction() {
  124. let attackMove = SCNAction.move(to: SCNVector3(1, 0, 0), duration: 0.5)
  125. let returnMove = SCNAction.move(to: SCNVector3(-2, 0, 0), duration: 0.5)
  126. let attackSequence = SCNAction.sequence([attackMove, returnMove])
  127.  
  128. player.runAction(attackSequence)
  129. }
  130. struct BattleView: View {
  131. var scene = SCNScene(named: "BattleScene.scn")!
  132.  
  133. var body: some View {
  134. ZStack {
  135. SceneView(
  136. scene: scene,
  137. options: [.allowsCameraControl, .autoenablesDefaultLighting]
  138. )
  139. .edgesIgnoringSafeArea(.all)
  140.  
  141. VStack {
  142. Spacer()
  143. Button("Attack") {
  144. attackAction()
  145. }
  146. .padding()
  147. .background(Color.red)
  148. .foregroundColor(.white)
  149. .cornerRadius(10)
  150. }
  151. }
  152. }
  153. }
  154.  
Success #stdin #stdout 0.02s 25904KB
stdin
Standard input is empty
stdout
import SwiftUI

struct ContentView: View {
    var body: some View {
        TabView {
            HomeView()
                .tabItem {
                    Image(systemName: "house.fill")
                    Text("Home")
                }
            
            GachaView()
                .tabItem {
                    Image(systemName: "gift.fill")
                    Text("Gacha")
                }
            
            TeamView()
                .tabItem {
                    Image(systemName: "person.3.fill")
                    Text("Team")
                }
            
            SettingsView()
                .tabItem {
                    Image(systemName: "gearshape.fill")
                    Text("Settings")
                }
        }
        .accentColor(.blue) // เปลี่ยนสีของ Tab Bar
    }
}

struct HomeView: View {
    var body: some View {
        ZStack {
            Image("background_home") // ใช้ภาพพื้นหลัง
                .resizable()
                .scaledToFill()
                .edgesIgnoringSafeArea(.all)
            
            VStack {
                Text("Welcome to Blue Archive Clone")
                    .font(.title)
                    .fontWeight(.bold)
                    .foregroundColor(.white)
                    .padding()
                
                Spacer()
                
                Button(action: {
                    print("Go to Battle!")
                }) {
                    Text("Battle")
                        .font(.title2)
                        .padding()
                        .frame(maxWidth: .infinity)
                        .background(Color.blue)
                        .foregroundColor(.white)
                        .cornerRadius(10)
                        .padding(.horizontal, 20)
                }
                
                Spacer()
            }
        }
    }
}

// สร้างโครงหน้ากาชา
struct GachaView: View {
    var body: some View {
        Text("Gacha System")
            .font(.title)
    }
}

// สร้างโครงหน้าทีม
struct TeamView: View {
    var body: some View {
        Text("Team Management")
            .font(.title)
    }
}

// สร้างโครงหน้าตั้งค่า
struct SettingsView: View {
    var body: some View {
        Text("Settings")
            .font(.title)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
import SwiftUI
import SceneKit

struct BattleView: View {
    var scene = SCNScene(named: "BattleScene.scn")!
    
    var body: some View {
        SceneView(
            scene: scene,
            options: [.allowsCameraControl, .autoenablesDefaultLighting]
        )
        .edgesIgnoringSafeArea(.all)
    }
}
let player = SCNNode()
player.geometry = SCNSphere(radius: 0.5) // ใช้ Sphere แทนตัวละครชั่วคราว
player.position = SCNVector3(x: -2, y: 0, z: 0)

let enemy = SCNNode()
enemy.geometry = SCNSphere(radius: 0.5)
enemy.position = SCNVector3(x: 2, y: 0, z: 0)

scene.rootNode.addChildNode(player)
scene.rootNode.addChildNode(enemy)
func attackAction() {
    let attackMove = SCNAction.move(to: SCNVector3(1, 0, 0), duration: 0.5)
    let returnMove = SCNAction.move(to: SCNVector3(-2, 0, 0), duration: 0.5)
    let attackSequence = SCNAction.sequence([attackMove, returnMove])
    
    player.runAction(attackSequence)
}
struct BattleView: View {
    var scene = SCNScene(named: "BattleScene.scn")!
    
    var body: some View {
        ZStack {
            SceneView(
                scene: scene,
                options: [.allowsCameraControl, .autoenablesDefaultLighting]
            )
            .edgesIgnoringSafeArea(.all)
            
            VStack {
                Spacer()
                Button("Attack") {
                    attackAction()
                }
                .padding()
                .background(Color.red)
                .foregroundColor(.white)
                .cornerRadius(10)
            }
        }
    }
}