Skip to content

Commit

Permalink
Merge pull request #28 from Vanessamae23/main
Browse files Browse the repository at this point in the history
Add heart HUD
  • Loading branch information
zheng-ze authored Mar 23, 2024
2 parents 33f7270 + d4c8dab commit 135e29e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
6 changes: 4 additions & 2 deletions TowerForge/TowerForge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
520062582BA8ED73000DBA30 /* HomeComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 520062572BA8ED73000DBA30 /* HomeComponent.swift */; };
523923E72BADC8530044BA61 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 523923E62BADC8530044BA61 /* Launch Screen.storyboard */; };
5240D08F2BAE6D0A004F1486 /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5240D08E2BAE6D0A004F1486 /* Point.swift */; };
5250B42F2BAE0DB000F16CF6 /* LabelComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5250B42E2BAE0DB000F16CF6 /* LabelComponent.swift */; };
5240D08F2BAE6D0A004F1486 /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5240D08E2BAE6D0A004F1486 /* Point.swift */; };
5240D0912BAF3453004F1486 /* Life.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5240D0902BAF3453004F1486 /* Life.swift */; };
5250B42F2BAE0DB000F16CF6 /* LabelComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5250B42E2BAE0DB000F16CF6 /* LabelComponent.swift */; };
52578B822BA61AAF00B4D76C /* PositionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52578B812BA61AAF00B4D76C /* PositionComponent.swift */; };
52578B872BA6209700B4D76C /* DamageComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52578B862BA6209700B4D76C /* DamageComponent.swift */; };
Expand Down Expand Up @@ -146,6 +145,7 @@
520062572BA8ED73000DBA30 /* HomeComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeComponent.swift; sourceTree = "<group>"; };
523923E62BADC8530044BA61 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
5240D08E2BAE6D0A004F1486 /* Point.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Point.swift; sourceTree = "<group>"; };
5240D0902BAF3453004F1486 /* Life.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Life.swift; sourceTree = "<group>"; };
5250B42E2BAE0DB000F16CF6 /* LabelComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelComponent.swift; sourceTree = "<group>"; };
52578B812BA61AAF00B4D76C /* PositionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PositionComponent.swift; sourceTree = "<group>"; };
52578B862BA6209700B4D76C /* DamageComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamageComponent.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -227,6 +227,7 @@
529F91872BA6D7A7009551D9 /* SoldierUnit.swift */,
3CE9514A2BAC83FA008B2785 /* SpawnableEntities.swift */,
5240D08E2BAE6D0A004F1486 /* Point.swift */,
5240D0902BAF3453004F1486 /* Life.swift */,
);
path = Entities;
sourceTree = "<group>";
Expand Down Expand Up @@ -665,6 +666,7 @@
3C9955CC2BA5889800D33FA5 /* MoveEvent.swift in Sources */,
5200624E2BA8D597000DBA30 /* AiComponent.swift in Sources */,
3C9955C22BA5838900D33FA5 /* EventOutput.swift in Sources */,
5240D0912BAF3453004F1486 /* Life.swift in Sources */,
52DF5FAE2BA32B2300135367 /* GameScene.swift in Sources */,
52578B822BA61AAF00B4D76C /* PositionComponent.swift in Sources */,
3C9955A32BA47DBB00D33FA5 /* BaseUnit.swift in Sources */,
Expand Down
Binary file not shown.
4 changes: 3 additions & 1 deletion TowerForge/TowerForge/GameWorld.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class GameWorld {
func setupPlayerInfo() {
let point = Point(initialPoint: 0)
entityManager.add(point)
// renderer?.addNodeToScene(entity: point)

let life = Life(initialLife: Team.lifeCount)
entityManager.add(life)
}
func contactDidBegin(between idA: UUID, and idB: UUID) {
systemManager.system(ofType: ContactSystem.self)?.insert(contact: TFContact(entityIdA: idA, entityIdB: idB))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import SpriteKit

class LabelComponent: TFComponent {
var text: String
init(text: String) {
var name: String
init(text: String, name: String) {
self.text = text
self.name = name
super.init()
}
func changeText(_ text: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HomeComponent: TFComponent {
var lifeLeft: Int {
didSet {
// Update the life left in the LabelComponent when it changes
guard let labelComponent = entity?.component(ofType: LabelComponent.self) else {
guard let labelComponent = entity?.component(ofType: LabelComponent.self), labelComponent.name == "life" else {
return
}
labelComponent.changeText(String(lifeLeft))
Expand All @@ -21,10 +21,9 @@ class HomeComponent: TFComponent {
var points = 0 {
didSet {
// Update the points in the LabelComponent when it changes
guard let labelComponent = entity?.component(ofType: LabelComponent.self) else {
guard let labelComponent = entity?.component(ofType: LabelComponent.self), labelComponent.name == "point" else {
return
}
print(points)
labelComponent.changeText(String(points))
}
}
Expand Down
24 changes: 24 additions & 0 deletions TowerForge/TowerForge/LevelManager/Entities/Life.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Life.swift
// TowerForge
//
// Created by Vanessa Mae on 24/03/24.
//

import Foundation

class Life: TFEntity {
static let position = CGPoint(x: 300, y: 100)
init(initialLife: Int) {
super.init()
self.addComponent(SpriteComponent(textureNames: ["Life"],
height: 100,
width: 100,
position: Life.position,
animatableKey: "life"))
self.addComponent(HomeComponent(initialLifeCount: Team.lifeCount, pointInterval: Team.pointsInterval))
self.addComponent(LabelComponent(text: String(initialLife), name: "life"))
self.addComponent(PositionComponent(position: Life.position))
self.addComponent(PlayerComponent(player: .ownPlayer))
}
}
2 changes: 1 addition & 1 deletion TowerForge/TowerForge/LevelManager/Entities/Point.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Point: TFEntity {
width: 100,
position: Point.position, animatableKey: "point"))
self.addComponent(HomeComponent(initialLifeCount: Team.lifeCount, pointInterval: Team.pointsInterval))
self.addComponent(LabelComponent(text: String(initialPoint)))
self.addComponent(LabelComponent(text: String(initialPoint), name: "point"))
self.addComponent(PositionComponent(position: Point.position))
self.addComponent(PlayerComponent(player: .ownPlayer))
}
Expand Down

0 comments on commit 135e29e

Please sign in to comment.