Skip to content

Commit

Permalink
Merge pull request #76 from zheng-ze/main
Browse files Browse the repository at this point in the history
Add UI for Powerup, Rework Events to not use optionals and Add RemoteEvents
  • Loading branch information
Vanessamae23 authored Apr 4, 2024
2 parents b2fe3be + 2d27df2 commit c104e25
Show file tree
Hide file tree
Showing 55 changed files with 511 additions and 235 deletions.
64 changes: 54 additions & 10 deletions TowerForge/TowerForge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,19 @@
3CAC4A712BB6AB3100A5D22E /* TFLabelNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CAC4A702BB6AB3100A5D22E /* TFLabelNode.swift */; };
3CAC4A732BB6B61C00A5D22E /* PlayerRenderStage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CAC4A722BB6B61C00A5D22E /* PlayerRenderStage.swift */; };
3CAC4A752BB6BDD500A5D22E /* HealthRenderStage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CAC4A742BB6BDD500A5D22E /* HealthRenderStage.swift */; };
3CBECF892BBE9797005EF39B /* TFNetworkCoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CBECF882BBE9797005EF39B /* TFNetworkCoder.swift */; };
3CBECF8C2BBE9A41005EF39B /* TFRemoteEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CBECF8B2BBE9A41005EF39B /* TFRemoteEvent.swift */; };
3CBECF8E2BBE9EAC005EF39B /* RemoteSpawnEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CBECF8D2BBE9EAC005EF39B /* RemoteSpawnEvent.swift */; };
3CCF9CAF2BAB1A96004D170E /* SceneUpdateDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CCF9CAE2BAB1A96004D170E /* SceneUpdateDelegate.swift */; };
3CCF9CB12BAB1BCE004D170E /* GameWorld.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CCF9CB02BAB1BCE004D170E /* GameWorld.swift */; };
3CCF9CB32BAB1F42004D170E /* SystemManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CCF9CB22BAB1F42004D170E /* SystemManager.swift */; };
3CCF9CB72BAB2877004D170E /* MainMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CCF9CB62BAB2877004D170E /* MainMenuViewController.swift */; };
3CD37A9D2BBEBD1600222D8A /* RemoteSpawnable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD37A9C2BBEBD1600222D8A /* RemoteSpawnable.swift */; };
3CD37A9F2BBEBFFB00222D8A /* TFRemoteEventPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD37A9E2BBEBFFB00222D8A /* TFRemoteEventPublisher.swift */; };
3CD37AA12BBEC00C00222D8A /* TFRemoteEventSubscriber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD37AA02BBEC00C00222D8A /* TFRemoteEventSubscriber.swift */; };
3CD37AA32BBEC0F900222D8A /* FirebaseRemoteEventPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD37AA22BBEC0F900222D8A /* FirebaseRemoteEventPublisher.swift */; };
3CD37AA52BBEC10700222D8A /* FirebaseRemoteEventSubscriber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD37AA42BBEC10700222D8A /* FirebaseRemoteEventSubscriber.swift */; };
3CD37AA72BBEC5EF00222D8A /* BaseRemoteEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD37AA62BBEC5EF00222D8A /* BaseRemoteEvent.swift */; };
3CE9514B2BAC83FA008B2785 /* SpawnableEntities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CE9514A2BAC83FA008B2785 /* SpawnableEntities.swift */; };
3CE9514F2BAC8936008B2785 /* Renderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CE9514E2BAC8936008B2785 /* Renderer.swift */; };
3CE951512BAC8955008B2785 /* Renderable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CE951502BAC8955008B2785 /* Renderable.swift */; };
Expand Down Expand Up @@ -227,10 +236,19 @@
3CAC4A702BB6AB3100A5D22E /* TFLabelNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TFLabelNode.swift; sourceTree = "<group>"; };
3CAC4A722BB6B61C00A5D22E /* PlayerRenderStage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerRenderStage.swift; sourceTree = "<group>"; };
3CAC4A742BB6BDD500A5D22E /* HealthRenderStage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthRenderStage.swift; sourceTree = "<group>"; };
3CBECF882BBE9797005EF39B /* TFNetworkCoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TFNetworkCoder.swift; sourceTree = "<group>"; };
3CBECF8B2BBE9A41005EF39B /* TFRemoteEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TFRemoteEvent.swift; sourceTree = "<group>"; };
3CBECF8D2BBE9EAC005EF39B /* RemoteSpawnEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteSpawnEvent.swift; sourceTree = "<group>"; };
3CCF9CAE2BAB1A96004D170E /* SceneUpdateDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneUpdateDelegate.swift; sourceTree = "<group>"; };
3CCF9CB02BAB1BCE004D170E /* GameWorld.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameWorld.swift; sourceTree = "<group>"; };
3CCF9CB22BAB1F42004D170E /* SystemManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemManager.swift; sourceTree = "<group>"; };
3CCF9CB62BAB2877004D170E /* MainMenuViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenuViewController.swift; sourceTree = "<group>"; };
3CD37A9C2BBEBD1600222D8A /* RemoteSpawnable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteSpawnable.swift; sourceTree = "<group>"; };
3CD37A9E2BBEBFFB00222D8A /* TFRemoteEventPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TFRemoteEventPublisher.swift; sourceTree = "<group>"; };
3CD37AA02BBEC00C00222D8A /* TFRemoteEventSubscriber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TFRemoteEventSubscriber.swift; sourceTree = "<group>"; };
3CD37AA22BBEC0F900222D8A /* FirebaseRemoteEventPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseRemoteEventPublisher.swift; sourceTree = "<group>"; };
3CD37AA42BBEC10700222D8A /* FirebaseRemoteEventSubscriber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseRemoteEventSubscriber.swift; sourceTree = "<group>"; };
3CD37AA62BBEC5EF00222D8A /* BaseRemoteEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseRemoteEvent.swift; sourceTree = "<group>"; };
3CE9514A2BAC83FA008B2785 /* SpawnableEntities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpawnableEntities.swift; sourceTree = "<group>"; };
3CE9514E2BAC8936008B2785 /* Renderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Renderer.swift; sourceTree = "<group>"; };
3CE951502BAC8955008B2785 /* Renderable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Renderable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -393,15 +411,6 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
3C3CBDFD2BB870770001B8A9 /* Extensions */ = {
isa = PBXGroup;
children = (
3C3CBDFE2BB8708A0001B8A9 /* CGPoint+Extensions.swift */,
3C3CBE002BB870950001B8A9 /* CGVector+Extensions.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
3C99559F2BA47D3E00D33FA5 /* Entities */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -454,6 +463,28 @@
path = RenderStages;
sourceTree = "<group>";
};
3CBECF822BBDC36A005EF39B /* GameNetwork */ = {
isa = PBXGroup;
children = (
3CBECF8A2BBE9A30005EF39B /* RemoteEvents */,
3CD37A9E2BBEBFFB00222D8A /* TFRemoteEventPublisher.swift */,
3CD37AA22BBEC0F900222D8A /* FirebaseRemoteEventPublisher.swift */,
3CD37AA02BBEC00C00222D8A /* TFRemoteEventSubscriber.swift */,
3CD37AA42BBEC10700222D8A /* FirebaseRemoteEventSubscriber.swift */,
);
path = GameNetwork;
sourceTree = "<group>";
};
3CBECF8A2BBE9A30005EF39B /* RemoteEvents */ = {
isa = PBXGroup;
children = (
3CBECF8B2BBE9A41005EF39B /* TFRemoteEvent.swift */,
3CBECF8D2BBE9EAC005EF39B /* RemoteSpawnEvent.swift */,
3CD37AA62BBEC5EF00222D8A /* BaseRemoteEvent.swift */,
);
path = RemoteEvents;
sourceTree = "<group>";
};
3CE9514C2BAC8668008B2785 /* BaseEntities */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -596,8 +627,10 @@
52A7940E2BBC476B0083C976 /* Networking */ = {
isa = PBXGroup;
children = (
3CBECF822BBDC36A005EF39B /* GameNetwork */,
52A7940F2BBC47770083C976 /* RoomNetwork */,
52A794162BBC4F690083C976 /* GamePlayer.swift */,
3CBECF882BBE9797005EF39B /* TFNetworkCoder.swift */,
);
path = Networking;
sourceTree = "<group>";
Expand Down Expand Up @@ -651,7 +684,6 @@
52A7940E2BBC476B0083C976 /* Networking */,
52A794072BBC35E30083C976 /* Constants */,
52A794002BBC2E940083C976 /* Firebase */,
3C3CBDFD2BB870770001B8A9 /* Extensions */,
BAFFB92F2BB0A01700D8301F /* Commons */,
5295A2052BAA0208005018A8 /* Nodes */,
BAFFB9462BB0AABF00D8301F /* TFCore */,
Expand Down Expand Up @@ -707,6 +739,7 @@
children = (
52DF5FE82BA33F9700135367 /* Animatable.swift */,
3CE951602BADE881008B2785 /* Spawnable.swift */,
3CD37A9C2BBEBD1600222D8A /* RemoteSpawnable.swift */,
520062552BA8E026000DBA30 /* PlayerSpawnable.swift */,
5295A20E2BAAE7CF005018A8 /* TeamController.swift */,
);
Expand Down Expand Up @@ -929,6 +962,8 @@
BAFFB93E2BB0A67000D8301F /* Extensions */ = {
isa = PBXGroup;
children = (
3C3CBDFE2BB8708A0001B8A9 /* CGPoint+Extensions.swift */,
3C3CBE002BB870950001B8A9 /* CGVector+Extensions.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1216,10 +1251,12 @@
BAFFB9532BB342F100D8301F /* StorageManager.swift in Sources */,
BAFFB9682BB9981700D8301F /* TotalGamesAchievement.swift in Sources */,
BAFFB9732BBAC14500D8301F /* AchievementManager.swift in Sources */,
3CBECF8E2BBE9EAC005EF39B /* RemoteSpawnEvent.swift in Sources */,
3CAC4A752BB6BDD500A5D22E /* HealthRenderStage.swift in Sources */,
3CCF9CB72BAB2877004D170E /* MainMenuViewController.swift in Sources */,
5240D0A72BB33356004F1486 /* LifeProp.swift in Sources */,
3CA829C42BB70C5E00D8E72A /* ButtonComponent.swift in Sources */,
3CBECF892BBE9797005EF39B /* TFNetworkCoder.swift in Sources */,
52DF5FFF2BA3656500135367 /* ShootingComponent.swift in Sources */,
BA443D3D2BAD9557009F0FFB /* RemoveSystem.swift in Sources */,
3C9955CC2BA5889800D33FA5 /* MoveEvent.swift in Sources */,
Expand All @@ -1238,10 +1275,12 @@
523AA3BD2BB88ED10041E60D /* WizardBall.swift in Sources */,
527A07782BB3F31100CD9D08 /* Death.swift in Sources */,
3C9955BA2BA5637200D33FA5 /* DamageEvent.swift in Sources */,
3CD37AA52BBEC10700222D8A /* FirebaseRemoteEventSubscriber.swift in Sources */,
52A794172BBC4F690083C976 /* GamePlayer.swift in Sources */,
3CE951632BAE037C008B2785 /* AiSystem.swift in Sources */,
3CE9515F2BADE2C5008B2785 /* ShootingSystem.swift in Sources */,
5240D0AB2BB3340F004F1486 /* CaptureTheFlagMode.swift in Sources */,
3CD37A9D2BBEBD1600222D8A /* RemoteSpawnable.swift in Sources */,
3C9955CA2BA5888F00D33FA5 /* SpawnEvent.swift in Sources */,
3CE951582BAD724D008B2785 /* TFContact.swift in Sources */,
5295A2132BAAEA16005018A8 /* UnitNode.swift in Sources */,
Expand All @@ -1252,6 +1291,7 @@
527A077E2BB3F75700CD9D08 /* Timer.swift in Sources */,
52578B872BA6209700B4D76C /* DamageComponent.swift in Sources */,
9B0406182BB8A1E10026E903 /* PowerUpDelegateFactory.swift in Sources */,
3CD37AA12BBEC00C00222D8A /* TFRemoteEventSubscriber.swift in Sources */,
52A794152BBC4EF50083C976 /* GameRoomDelegate.swift in Sources */,
52DF5FB02BA32B2300135367 /* GameViewController.swift in Sources */,
3CE951512BAC8955008B2785 /* Renderable.swift in Sources */,
Expand All @@ -1269,6 +1309,7 @@
527A07822BB3F8D300CD9D08 /* TimerProp.swift in Sources */,
52DF5FDE2BA32D7E00135367 /* EntityManager.swift in Sources */,
52A794112BBC48FE0083C976 /* GameRoom.swift in Sources */,
3CD37AA72BBEC5EF00222D8A /* BaseRemoteEvent.swift in Sources */,
527A077C2BB3F4CC00CD9D08 /* KillEvent.swift in Sources */,
3C3CBE012BB870950001B8A9 /* CGVector+Extensions.swift in Sources */,
52A794092BBC35F20083C976 /* Constant.swift in Sources */,
Expand All @@ -1282,6 +1323,7 @@
527A07842BB3FD9A00CD9D08 /* TimerSystem.swift in Sources */,
3C3CBDF72BB81D970001B8A9 /* TFCameraNode.swift in Sources */,
3CE951562BACA0CF008B2785 /* Collidable.swift in Sources */,
3CBECF8C2BBE9A41005EF39B /* TFRemoteEvent.swift in Sources */,
5240D0A92BB333B5004F1486 /* PointProp.swift in Sources */,
52DF5FE62BA33AF300135367 /* TFSpriteNode.swift in Sources */,
BAFFB94B2BB11F9800D8301F /* GameEngine.swift in Sources */,
Expand Down Expand Up @@ -1321,6 +1363,7 @@
9B0406142BB89BE00026E903 /* PowerUpSelectionNode.swift in Sources */,
5240D0A22BB33183004F1486 /* DeathMatchMode.swift in Sources */,
3CAC4A6F2BB6A4F200A5D22E /* LabelRenderStage.swift in Sources */,
3CD37A9F2BBEBFFB00222D8A /* TFRemoteEventPublisher.swift in Sources */,
3C0B608D2BB2B84000FFECB4 /* ContactComponent.swift in Sources */,
3CE951652BAE0A04008B2785 /* HomeSystem.swift in Sources */,
BAFFB9752BBD833400D8301F /* AudioManager.swift in Sources */,
Expand All @@ -1333,6 +1376,7 @@
5240D0AF2BB3B415004F1486 /* LifeEvent.swift in Sources */,
5295A2072BAA02FD005018A8 /* TFButtonNode.swift in Sources */,
BAFFB96A2BB9A64000D8301F /* ObjectSet.swift in Sources */,
3CD37AA32BBEC0F900222D8A /* FirebaseRemoteEventPublisher.swift in Sources */,
3CAC4A6B2BB6992F00A5D22E /* TFNode.swift in Sources */,
3CAC4A6D2BB6A13B00A5D22E /* PositionRenderStage.swift in Sources */,
3CE951672BAEAB0E008B2785 /* ContactSystem.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

protocol PlayerSpawnable: Spawnable {
protocol PlayerSpawnable: RemoteSpawnable {
static var cost: Int { get set }
static var title: String { get }
}
12 changes: 12 additions & 0 deletions TowerForge/TowerForge/Commons/Protocols/RemoteSpawnable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// RemoteSpawnable.swift
// TowerForge
//
// Created by Zheng Ze on 4/4/24.
//

import Foundation

protocol RemoteSpawnable: Spawnable {
init(position: CGPoint, player: Player, id: UUID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class DamageComponent: TFComponent {
CACurrentMediaTime() - lastAttackTime >= attackRate
}

func damage(_ healthComponent: HealthComponent) -> TFEvent? {
func damage(_ healthComponent: HealthComponent) -> TFEvent {
guard canDamage, let enemyId = healthComponent.entity?.id, let entityId = entity?.id else {
return nil
return DisabledEvent()
}

guard let teamA = self.entity?.component(ofType: PlayerComponent.self)?.player,
let teamB = healthComponent.entity?.component(ofType: PlayerComponent.self)?.player,
teamA != teamB else {
return nil
return DisabledEvent()
}

lastAttackTime = CACurrentMediaTime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class BaseTower: TFEntity {
key: String,
position: CGPoint,
maxHealth: CGFloat,
player: Player) {
player: Player,
id: UUID = UUID()) {
super.init()
// Core Components
self.addComponent(SpriteComponent(textureNames: textureNames, size: size, animatableKey: key))
Expand All @@ -25,34 +26,29 @@ class BaseTower: TFEntity {
self.addComponent(ContactComponent(hitboxSize: size))
}

override func collide(with other: any Collidable) -> TFEvent? {
override func collide(with other: any Collidable) -> TFEvent {
let superEvent = super.collide(with: other)
guard let healthComponent = self.component(ofType: HealthComponent.self) else {
return superEvent
}

if let superEvent = superEvent {
return superEvent.concurrentlyWith(other.collide(with: healthComponent))
}
return other.collide(with: healthComponent)
return superEvent.concurrentlyWith(other.collide(with: healthComponent))
}

override func collide(with damageComponent: DamageComponent) -> TFEvent? {
override func collide(with damageComponent: DamageComponent) -> TFEvent {
guard let healthComponent = self.component(ofType: HealthComponent.self) else {
return nil
return DisabledEvent()
}
// No call to super here as super is done on collide with Collidable above.
return damageComponent.damage(healthComponent)
}

override func collide(with movableComponent: MovableComponent) -> (any TFEvent)? {
guard let playerA = self.component(ofType: PlayerComponent.self)?.player,
override func collide(with movableComponent: MovableComponent) -> (any TFEvent) {
if let playerA = self.component(ofType: PlayerComponent.self)?.player,
let playerB = movableComponent.entity?.component(ofType: PlayerComponent.self)?.player,
playerA != playerB else {
return nil
playerA != playerB {
movableComponent.shouldMove = false
}

movableComponent.shouldMove = true
return nil
return DisabledEvent()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class BaseUnit: TFEntity {
position: CGPoint,
maxHealth: CGFloat,
velocity: CGVector,
player: Player) {
super.init()
player: Player,
id: UUID = UUID()) {
super.init(id: id)
// Core Components
self.addComponent(SpriteComponent(textureNames: textureNames, size: size, animatableKey: key))
self.addComponent(PositionComponent(position: position))
Expand All @@ -27,17 +28,17 @@ class BaseUnit: TFEntity {
self.addComponent(ContactComponent(hitboxSize: size))
}

override func collide(with other: any Collidable) -> TFEvent? {
override func collide(with other: any Collidable) -> TFEvent {
let superEvent = super.collide(with: other)
guard let healthComponent = self.component(ofType: HealthComponent.self),
let movableComponent = self.component(ofType: MovableComponent.self) else {
return superEvent
}

let event = other.collide(with: healthComponent)?
.concurrentlyWith(other.collide(with: movableComponent)) ?? other.collide(with: movableComponent)
let event = other.collide(with: healthComponent)
.concurrentlyWith(other.collide(with: movableComponent))

return superEvent?.concurrentlyWith(event) ?? event
return superEvent.concurrentlyWith(event)
}

override func onSeparate() {
Expand All @@ -47,25 +48,21 @@ class BaseUnit: TFEntity {
movableComponent.shouldMove = true
}

override func collide(with damageComponent: DamageComponent) -> TFEvent? {
override func collide(with damageComponent: DamageComponent) -> TFEvent {
guard let healthComponent = self.component(ofType: HealthComponent.self) else {
return nil
return DisabledEvent()
}
// No call to super here as super is done on collide with Collidable above.
return damageComponent.damage(healthComponent)
}

override func collide(with movableComponent: MovableComponent) -> TFEvent? {
guard let playerA = self.component(ofType: PlayerComponent.self)?.player,
override func collide(with movableComponent: MovableComponent) -> TFEvent {
if let playerA = self.component(ofType: PlayerComponent.self)?.player,
let playerB = movableComponent.entity?.component(ofType: PlayerComponent.self)?.player,
playerA != playerB else {
return nil
playerA != playerB {
movableComponent.shouldMove = false
}

movableComponent.shouldMove = false
if let ownMovableComponent = self.component(ofType: MovableComponent.self) {
ownMovableComponent.shouldMove = false
}
return nil
return DisabledEvent()
}
}
Loading

0 comments on commit c104e25

Please sign in to comment.