-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AiSystem to update AiComponent and HomeComponent
- Loading branch information
Showing
5 changed files
with
56 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// AiSystem.swift | ||
// TowerForge | ||
// | ||
// Created by Zheng Ze on 23/3/24. | ||
// | ||
|
||
import Foundation | ||
|
||
class AiSystem: TFSystem { | ||
var isActive = true | ||
weak var entityManager: EntityManager? | ||
weak var eventManager: EventManager? | ||
|
||
init(entityManager: EntityManager, eventManager: EventManager) { | ||
self.entityManager = entityManager | ||
self.eventManager = eventManager | ||
} | ||
|
||
func update(within time: CGFloat) { | ||
guard let entityManager = entityManager, let eventManager = eventManager else { | ||
return | ||
} | ||
|
||
let homeComponents = entityManager.components(ofType: HomeComponent.self) | ||
for homeComponent in homeComponents { | ||
homeComponent.update(deltaTime: time) | ||
} | ||
|
||
let aiComponents = entityManager.components(ofType: AiComponent.self) | ||
for aiComponent in aiComponents { | ||
aiComponent.update(deltaTime: time) | ||
} | ||
} | ||
} |