diff --git a/star-dash/star-dash/AppDelegate.swift b/star-dash/star-dash/AppDelegate.swift index 494b9c4e..49fd0c8d 100644 --- a/star-dash/star-dash/AppDelegate.swift +++ b/star-dash/star-dash/AppDelegate.swift @@ -10,27 +10,26 @@ import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { - - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - return true + true } // MARK: UISceneSession Lifecycle - func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, + options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. - return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { // Called when the user discards a scene session. - // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // If any sessions were discarded while the application was not running, this will be called shortly + // after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } - } - diff --git a/star-dash/star-dash/Constants/PhysicsConstants.swift b/star-dash/star-dash/Constants/PhysicsConstants.swift index 167ee060..fee6dd8f 100644 --- a/star-dash/star-dash/Constants/PhysicsConstants.swift +++ b/star-dash/star-dash/Constants/PhysicsConstants.swift @@ -15,15 +15,17 @@ struct PhysicsConstants { static let obstacle: UInt32 = 0b01000 static let tool: UInt32 = 0b10000 } + struct CollisionMask { - static let playerCollisionMask = CollisionCategory.monster | CollisionCategory.collectible | CollisionCategory.obstacle | CollisionCategory.tool - + static let playerCollisionMask = CollisionCategory.monster + | CollisionCategory.collectible | CollisionCategory.obstacle | CollisionCategory.tool + static let monsterCollisionMask = CollisionCategory.player | CollisionCategory.tool - + static let collectibleCollisionMask = CollisionCategory.player - + static let obstacleCollisionMask = CollisionCategory.player - + static let toolCollisionMask = CollisionCategory.player | CollisionCategory.monster } } diff --git a/star-dash/star-dash/Entities/Components/Component.swift b/star-dash/star-dash/Entities/Components/Component.swift index bf9f02af..90756b15 100644 --- a/star-dash/star-dash/Entities/Components/Component.swift +++ b/star-dash/star-dash/Entities/Components/Component.swift @@ -6,15 +6,15 @@ // import Foundation + typealias ComponentId = UUID + class Component { var entityId: EntityId var id: ComponentId - + init(id: ComponentId, entityId: EntityId) { self.id = id self.entityId = entityId - } - } diff --git a/star-dash/star-dash/Entities/Components/HealthComponent.swift b/star-dash/star-dash/Entities/Components/HealthComponent.swift index 5fab595e..bd133179 100644 --- a/star-dash/star-dash/Entities/Components/HealthComponent.swift +++ b/star-dash/star-dash/Entities/Components/HealthComponent.swift @@ -9,12 +9,12 @@ import Foundation class HealthComponent: Component { var health: Int - + init(id: ComponentId, entityId: EntityId, health: Int) { self.health = health super.init(id: id, entityId: entityId) } - + convenience init(entityId: EntityId, health: Int) { self.init(id: UUID(), entityId: entityId, health: health) } diff --git a/star-dash/star-dash/Entities/Components/PhysicsComponent.swift b/star-dash/star-dash/Entities/Components/PhysicsComponent.swift index 043a0b8f..a3367fed 100644 --- a/star-dash/star-dash/Entities/Components/PhysicsComponent.swift +++ b/star-dash/star-dash/Entities/Components/PhysicsComponent.swift @@ -13,8 +13,9 @@ class PhysicsComponent: Component { var force: CGVector var collisionMask: UInt32 var affectedByGravity: Bool - - init(id: ComponentId, entityId: EntityId, mass: CGFloat, velocity: CGVector, force: CGVector, collisionMask: UInt32, affectedByGravity: Bool) { + + init(id: ComponentId, entityId: EntityId, mass: CGFloat, velocity: CGVector, + force: CGVector, collisionMask: UInt32, affectedByGravity: Bool) { self.mass = mass self.velocity = velocity self.force = force @@ -22,8 +23,10 @@ class PhysicsComponent: Component { self.affectedByGravity = affectedByGravity super.init(id: id, entityId: entityId) } - - convenience init(entityId: EntityId, mass: CGFloat, velocity: CGVector, force: CGVector, collisionMask: UInt32, affectedByGravity: Bool) { - self.init(id: UUID(), entityId: entityId, mass: mass, velocity: velocity, force: force, collisionMask: collisionMask, affectedByGravity: affectedByGravity) + + convenience init(entityId: EntityId, mass: CGFloat, velocity: CGVector, + force: CGVector, collisionMask: UInt32, affectedByGravity: Bool) { + self.init(id: UUID(), entityId: entityId, mass: mass, velocity: velocity, + force: force, collisionMask: collisionMask, affectedByGravity: affectedByGravity) } } diff --git a/star-dash/star-dash/Entities/Components/PositionComponent.swift b/star-dash/star-dash/Entities/Components/PositionComponent.swift index 2404ec7d..0c162dc7 100644 --- a/star-dash/star-dash/Entities/Components/PositionComponent.swift +++ b/star-dash/star-dash/Entities/Components/PositionComponent.swift @@ -7,27 +7,25 @@ import Foundation - class PositionComponent: Component { var position: CGPoint var rotation: Float - + init(id: UUID, entityId: UUID, position: CGPoint, rotation: Float) { self.position = position self.rotation = rotation super.init(id: id, entityId: entityId) } - + convenience init(entityId: UUID, position: CGPoint, rotation: Float) { self.init(id: UUID(), entityId: entityId, position: position, rotation: rotation) } - + func setPosition(position: CGPoint) { self.position = position } - + func setRotation(rotation: Float) { self.rotation = rotation } - } diff --git a/star-dash/star-dash/Entities/Components/SpriteComponent.swift b/star-dash/star-dash/Entities/Components/SpriteComponent.swift index 56d1f19c..f9733f4f 100644 --- a/star-dash/star-dash/Entities/Components/SpriteComponent.swift +++ b/star-dash/star-dash/Entities/Components/SpriteComponent.swift @@ -6,19 +6,21 @@ // import Foundation + class SpriteComponent: Component { - // sprite could be single image or sprite set, could use enum to seperate, for sprite set will need to discuss how to rep animation + // TODO: sprite could be single image or sprite set, could use enum to seperate, + // for sprite set will need to discuss how to rep animation var image: String var size: CGSize - + init(id: ComponentId, entityId: EntityId, image: String, size: CGSize) { self.image = image self.size = size super.init(id: id, entityId: entityId) } - + convenience init(entityId: EntityId, image: String, size: CGSize) { self.init(id: UUID(), entityId: entityId, image: image, size: size) } - + } diff --git a/star-dash/star-dash/Entities/Entity.swift b/star-dash/star-dash/Entities/Entity.swift index 09596fbb..75d7cb12 100644 --- a/star-dash/star-dash/Entities/Entity.swift +++ b/star-dash/star-dash/Entities/Entity.swift @@ -6,10 +6,11 @@ // import Foundation + typealias EntityId = UUID protocol Entity { var id: EntityId {get} - + func setUpAndAdd(to: EntityManager) } diff --git a/star-dash/star-dash/Entities/EntityManager.swift b/star-dash/star-dash/Entities/EntityManager.swift index 41de9a02..c9706778 100644 --- a/star-dash/star-dash/Entities/EntityManager.swift +++ b/star-dash/star-dash/Entities/EntityManager.swift @@ -6,24 +6,27 @@ // import Foundation + typealias ComponentSet = Set typealias ComponentMap = [ComponentId: Component] typealias EntityMap = [EntityId: Entity] typealias EntityComponentMap = [EntityId: ComponentSet] + class EntityManager { var componentMap: ComponentMap var entityMap: EntityMap var entityComponentMap: EntityComponentMap + init(componentMap: ComponentMap, entityMap: EntityMap, entityComponentMap: EntityComponentMap) { self.componentMap = componentMap self.entityMap = entityMap self.entityComponentMap = entityComponentMap } - + convenience init() { self.init(componentMap: .init(), entityMap: .init(), entityComponentMap: .init()) } - + func add(component: Component) { guard self.componentMap[component.id] != nil else { return @@ -31,7 +34,7 @@ class EntityManager { self.componentMap[component.id] = component self.entityComponentMap[component.entityId]?.insert(component.id) } - + func add(entity: Entity) { guard self.entityMap[entity.id] != nil else { return diff --git a/star-dash/star-dash/Entities/GameEntities/Collectible.swift b/star-dash/star-dash/Entities/GameEntities/Collectible.swift index fcc02923..bdafa3d5 100644 --- a/star-dash/star-dash/Entities/GameEntities/Collectible.swift +++ b/star-dash/star-dash/Entities/GameEntities/Collectible.swift @@ -10,17 +10,16 @@ import Foundation class Collectible: Entity { let id: EntityId private let position: CGPoint - + init(id: EntityId, position: CGPoint) { self.id = id self.position = position } - + convenience init(position: CGPoint) { self.init(id: UUID(), position: position) } - - + func setUpAndAdd(to: EntityManager) { let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero) let physicsComponent = PhysicsComponent( @@ -30,7 +29,7 @@ class Collectible: Entity { force: .zero, collisionMask: PhysicsConstants.CollisionMask.collectibleCollisionMask, affectedByGravity: false) - + to.add(entity: self) to.add(component: positionComponent) to.add(component: physicsComponent) diff --git a/star-dash/star-dash/Entities/GameEntities/Monster.swift b/star-dash/star-dash/Entities/GameEntities/Monster.swift index b521e726..ebcf6301 100644 --- a/star-dash/star-dash/Entities/GameEntities/Monster.swift +++ b/star-dash/star-dash/Entities/GameEntities/Monster.swift @@ -6,20 +6,20 @@ // import Foundation + class Monster: Entity { let id: EntityId private let position: CGPoint - + init(id: EntityId, position: CGPoint) { self.id = id self.position = position } - + convenience init(position: CGPoint) { self.init(id: UUID(), position: position) } - - + func setUpAndAdd(to: EntityManager) { let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero) let healthComponent = HealthComponent(entityId: self.id, health: 100) @@ -30,8 +30,7 @@ class Monster: Entity { force: .zero, collisionMask: PhysicsConstants.CollisionMask.monsterCollisionMask, affectedByGravity: false) - - + to.add(entity: self) to.add(component: positionComponent) to.add(component: healthComponent) diff --git a/star-dash/star-dash/Entities/GameEntities/Obstacle.swift b/star-dash/star-dash/Entities/GameEntities/Obstacle.swift index 70e2b5d9..495394a7 100644 --- a/star-dash/star-dash/Entities/GameEntities/Obstacle.swift +++ b/star-dash/star-dash/Entities/GameEntities/Obstacle.swift @@ -10,17 +10,16 @@ import Foundation class Obstacle: Entity { let id: EntityId private let position: CGPoint - + init(id: EntityId, position: CGPoint) { self.id = id self.position = position } - + convenience init(position: CGPoint) { self.init(id: UUID(), position: position) } - - + func setUpAndAdd(to: EntityManager) { let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero) let physicsComponent = PhysicsComponent( @@ -30,7 +29,7 @@ class Obstacle: Entity { force: .zero, collisionMask: PhysicsConstants.CollisionMask.obstacleCollisionMask, affectedByGravity: false) - + to.add(entity: self) to.add(component: positionComponent) to.add(component: physicsComponent) diff --git a/star-dash/star-dash/Entities/GameEntities/Player.swift b/star-dash/star-dash/Entities/GameEntities/Player.swift index 853c4b33..b9b922f4 100644 --- a/star-dash/star-dash/Entities/GameEntities/Player.swift +++ b/star-dash/star-dash/Entities/GameEntities/Player.swift @@ -6,21 +6,22 @@ // import Foundation + class Player: Entity { let id: EntityId private let position: CGPoint private let playerSprite: PlayerSprite + init(id: EntityId, position: CGPoint, playerSprite: PlayerSprite) { self.id = id self.position = position self.playerSprite = playerSprite } - + convenience init(position: CGPoint, playerSprite: PlayerSprite) { self.init(id: UUID(), position: position, playerSprite: playerSprite) } - - + func setUpAndAdd(to: EntityManager) { let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero) let healthComponent = HealthComponent(entityId: self.id, health: 100) @@ -31,9 +32,9 @@ class Player: Entity { force: .zero, collisionMask: PhysicsConstants.CollisionMask.playerCollisionMask, affectedByGravity: true) - + let spriteComponent = SpriteComponent(entityId: self.id, image: "", size: .zero) - + to.add(entity: self) to.add(component: positionComponent) to.add(component: healthComponent) diff --git a/star-dash/star-dash/Entities/GameEntities/Tool.swift b/star-dash/star-dash/Entities/GameEntities/Tool.swift index ecd6bc7c..528c513b 100644 --- a/star-dash/star-dash/Entities/GameEntities/Tool.swift +++ b/star-dash/star-dash/Entities/GameEntities/Tool.swift @@ -10,17 +10,16 @@ import Foundation class Tool: Entity { let id: EntityId private let position: CGPoint - + init(id: EntityId, position: CGPoint) { self.id = id self.position = position } - + convenience init(position: CGPoint) { self.init(id: UUID(), position: position) } - - + func setUpAndAdd(to: EntityManager) { let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero) let physicsComponent = PhysicsComponent( @@ -30,7 +29,7 @@ class Tool: Entity { force: .zero, collisionMask: PhysicsConstants.CollisionMask.toolCollisionMask, affectedByGravity: false) - + to.add(entity: self) to.add(component: positionComponent) to.add(component: physicsComponent) diff --git a/star-dash/star-dash/Enums/PlayerSprite.swift b/star-dash/star-dash/Enums/PlayerSprite.swift index f43a8db9..8e18c6ee 100644 --- a/star-dash/star-dash/Enums/PlayerSprite.swift +++ b/star-dash/star-dash/Enums/PlayerSprite.swift @@ -6,6 +6,7 @@ // import Foundation + enum PlayerSprite: String { case RedNose = "red-nose" } diff --git a/star-dash/star-dash/SceneDelegate.swift b/star-dash/star-dash/SceneDelegate.swift index ce5c0e6d..9fd4098f 100644 --- a/star-dash/star-dash/SceneDelegate.swift +++ b/star-dash/star-dash/SceneDelegate.swift @@ -11,19 +11,24 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? - - func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { - // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, + options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided + // UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. - // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). - guard let _ = (scene as? UIWindowScene) else { return } + // This delegate does not imply the connecting scene or session are new + // (see `application:configurationForConnectingSceneSession` instead). + guard (scene as? UIWindowScene) != nil else { + return + } } func sceneDidDisconnect(_ scene: UIScene) { // Called as the scene is being released by the system. // This occurs shortly after the scene enters the background, or when its session is discarded. // Release any resources associated with this scene that can be re-created the next time the scene connects. - // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). + // The scene may re-connect later, as its session was not necessarily discarded + // (see `application:didDiscardSceneSessions` instead). } func sceneDidBecomeActive(_ scene: UIScene) { @@ -46,7 +51,4 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // Use this method to save data, release shared resources, and store enough scene-specific state information // to restore the scene back to its current state. } - - } - diff --git a/star-dash/star-dash/ViewController.swift b/star-dash/star-dash/ViewController.swift index 978bebb0..5dc0e960 100644 --- a/star-dash/star-dash/ViewController.swift +++ b/star-dash/star-dash/ViewController.swift @@ -9,11 +9,4 @@ import UIKit class ViewController: UIViewController { - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } - - } - diff --git a/star-dash/star-dashTests/star_dashTests.swift b/star-dash/star-dashTests/star_dashTests.swift index a169f3cf..d03ea1c2 100644 --- a/star-dash/star-dashTests/star_dashTests.swift +++ b/star-dash/star-dashTests/star_dashTests.swift @@ -10,21 +10,22 @@ import XCTest final class star_dashTests: XCTestCase { - override func setUpWithError() throws { - // Put setup code here. This method is called before the invocation of each test method in the class. - } +// override func setUpWithError() throws { +// // Put setup code here. This method is called before the invocation of each test method in the class. +// } - override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. - } +// override func tearDownWithError() throws { +// // Put teardown code here. This method is called after the invocation of each test method in the class. +// } - func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - // Any test you write for XCTest can be annotated as throws and async. - // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. - // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. - } +// func testExample() throws { +// // This is an example of a functional test case. +// // Use XCTAssert and related functions to verify your tests produce the correct results. +// // Any test you write for XCTest can be annotated as throws and async. +// // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. +// // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with +// // assertions afterwards. +// } func testPerformanceExample() throws { // This is an example of a performance test case. diff --git a/star-dash/star-dashUITests/star_dashUITests.swift b/star-dash/star-dashUITests/star_dashUITests.swift index b49ccd08..44bbcb08 100644 --- a/star-dash/star-dashUITests/star_dashUITests.swift +++ b/star-dash/star-dashUITests/star_dashUITests.swift @@ -15,12 +15,13 @@ final class star_dashUITests: XCTestCase { // In UI tests it is usually best to stop immediately when a failure occurs. continueAfterFailure = false - // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + // In UI tests it’s important to set the initial state - such as interface orientation - + // required for your tests before they run. The setUp method is a good place to do this. } - override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. - } +// override func tearDownWithError() throws { +// // Put teardown code here. This method is called after the invocation of each test method in the class. +// } func testExample() throws { // UI tests must launch the application that they test.