-
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.
- Loading branch information
Showing
33 changed files
with
246 additions
and
85 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
Binary file modified
BIN
+33.5 KB
(120%)
...proj/project.xcworkspace/xcuserdata/macbookpro.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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
File renamed without changes.
File renamed without changes
Binary file not shown.
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
40 changes: 40 additions & 0 deletions
40
TowerForge/TowerForge/LevelManager/Components/AiComponent.swift
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,40 @@ | ||
// | ||
// AiComponent.swift | ||
// TowerForge | ||
// | ||
// Created by Vanessa Mae on 19/03/24. | ||
// | ||
|
||
import Foundation | ||
|
||
enum UnitType { | ||
case melee | ||
case soldier | ||
static let possibleUnits = [melee, soldier] | ||
} | ||
|
||
class AiComponent: TFComponent { | ||
private var entityManager: EntityManager | ||
private var chosenUnit: UnitType | ||
init(entityManager: EntityManager) { | ||
self.entityManager = entityManager | ||
self.chosenUnit = UnitType.possibleUnits.randomElement() ?? .melee | ||
super.init() | ||
} | ||
|
||
override func update(deltaTime: TimeInterval) { | ||
guard let homeComponent = entity?.component(ofType: HomeComponent.self) else { | ||
return | ||
} | ||
if chosenUnit == .melee && homeComponent.points >= MeleeUnit.cost { | ||
// TODO: Remove hard code of CGPoints | ||
UnitGenerator.spawnMelee(at: CGPoint(x: 0, y: 10), player: .oppositePlayer, entityManager: entityManager) | ||
self.chosenUnit = UnitType.possibleUnits.randomElement() ?? .melee | ||
} | ||
if chosenUnit == .soldier && homeComponent.points >= SoldierUnit.cost { | ||
// TODO: Remove hard code of CGPoints | ||
UnitGenerator.spawnSoldier(at: CGPoint(x: 0, y: 10), player: .oppositePlayer, entityManager: entityManager) | ||
self.chosenUnit = UnitType.possibleUnits.randomElement() ?? .melee | ||
} | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
TowerForge/TowerForge/LevelManager/Components/GameComponents/CostComponent.swift
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,15 @@ | ||
// | ||
// CostComponent.swift | ||
// TowerForge | ||
// | ||
// Created by MacBook Pro on 19/03/24. | ||
// | ||
|
||
import Foundation | ||
|
||
class CostComponent: TFComponent { | ||
var cost: CGFloat | ||
init(cost: CGFloat) { | ||
self.cost = cost | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
TowerForge/TowerForge/LevelManager/Components/HomeComponent.swift
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,38 @@ | ||
// | ||
// HomeComponent.swift | ||
// TowerForge | ||
// | ||
// Created by Vanessa Mae on 19/03/24. | ||
// | ||
|
||
import Foundation | ||
import SpriteKit | ||
|
||
class HomeComponent: TFComponent { | ||
var lifeLeft: Int | ||
var points = 0 | ||
private var lastPointIncrease = TimeInterval(0) | ||
private var pointInterval: TimeInterval | ||
private var pointsPerInterval: Int = 10 | ||
init(initialLifeCount: Int, pointInterval: TimeInterval) { | ||
self.lifeLeft = initialLifeCount | ||
self.pointInterval = pointInterval | ||
super.init() | ||
} | ||
func decreaseLife() -> Int { | ||
self.lifeLeft -= 1 | ||
return self.lifeLeft | ||
} | ||
func increaseLife() -> Int { | ||
self.lifeLeft += 1 | ||
return self.lifeLeft | ||
} | ||
override func update(deltaTime: TimeInterval) { | ||
super.update(deltaTime: deltaTime) | ||
// Points update | ||
if CACurrentMediaTime() - lastPointIncrease > pointInterval { | ||
lastPointIncrease = CACurrentMediaTime() | ||
points += self.pointsPerInterval | ||
} | ||
} | ||
} |
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
Oops, something went wrong.