Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UI, GameMode, Add alerts #104

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions TowerForge/TowerForge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
523C29282BBCFD93004C6EAC /* Nosifer-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 5240D0952BB04E57004F1486 /* Nosifer-Regular.ttf */; };
523C29302BBD0916004C6EAC /* GameWaitingRoomViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523C292F2BBD0916004C6EAC /* GameWaitingRoomViewController.swift */; };
523E5C4C2BC53F70007444DA /* WaveSpawnEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523E5C4B2BC53F70007444DA /* WaveSpawnEvent.swift */; };
523E5C512BC60563007444DA /* SurvivalModeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523E5C502BC60563007444DA /* SurvivalModeTests.swift */; };
523E5C532BC60A15007444DA /* DeathMatchModeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523E5C522BC60A15007444DA /* DeathMatchModeTests.swift */; };
5240D08F2BAE6D0A004F1486 /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5240D08E2BAE6D0A004F1486 /* Point.swift */; };
5240D0912BAF3453004F1486 /* Life.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5240D0902BAF3453004F1486 /* Life.swift */; };
5240D0A02BB330B5004F1486 /* GameMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5240D09F2BB330B4004F1486 /* GameMode.swift */; };
Expand Down Expand Up @@ -112,7 +114,6 @@
527E3A242BA613F000FE1628 /* PlayerComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 527E3A232BA613EF00FE1628 /* PlayerComponent.swift */; };
529190E32BBFB59B001D8821 /* StatePopupNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529190E22BBFB59B001D8821 /* StatePopupNode.swift */; };
5295A2022BA9FBD9005018A8 /* SceneManagerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5295A2012BA9FBD9005018A8 /* SceneManagerDelegate.swift */; };
5295A2042BA9FED4005018A8 /* MenuScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5295A2032BA9FED4005018A8 /* MenuScene.swift */; };
5295A2072BAA02FD005018A8 /* TFButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5295A2062BAA02FD005018A8 /* TFButtonNode.swift */; };
5295A20F2BAAE7CF005018A8 /* TeamController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5295A20E2BAAE7CF005018A8 /* TeamController.swift */; };
5295A2132BAAEA16005018A8 /* UnitNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5295A2122BAAEA16005018A8 /* UnitNode.swift */; };
Expand Down Expand Up @@ -298,6 +299,8 @@
523AA3BE2BB88FBF0041E60D /* WizardUnit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WizardUnit.swift; sourceTree = "<group>"; };
523C292F2BBD0916004C6EAC /* GameWaitingRoomViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameWaitingRoomViewController.swift; sourceTree = "<group>"; };
523E5C4B2BC53F70007444DA /* WaveSpawnEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaveSpawnEvent.swift; sourceTree = "<group>"; };
523E5C502BC60563007444DA /* SurvivalModeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurvivalModeTests.swift; sourceTree = "<group>"; };
523E5C522BC60A15007444DA /* DeathMatchModeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeathMatchModeTests.swift; 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>"; };
5240D0952BB04E57004F1486 /* Nosifer-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Nosifer-Regular.ttf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -327,7 +330,6 @@
527E3A232BA613EF00FE1628 /* PlayerComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerComponent.swift; sourceTree = "<group>"; };
529190E22BBFB59B001D8821 /* StatePopupNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatePopupNode.swift; sourceTree = "<group>"; };
5295A2012BA9FBD9005018A8 /* SceneManagerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneManagerDelegate.swift; sourceTree = "<group>"; };
5295A2032BA9FED4005018A8 /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = "<group>"; };
5295A2062BAA02FD005018A8 /* TFButtonNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TFButtonNode.swift; sourceTree = "<group>"; };
5295A20E2BAAE7CF005018A8 /* TeamController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeamController.swift; sourceTree = "<group>"; };
5295A2122BAAEA16005018A8 /* UnitNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitNode.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -579,6 +581,15 @@
path = GameComponents;
sourceTree = "<group>";
};
523E5C4F2BC6054F007444DA /* GameModeTests */ = {
isa = PBXGroup;
children = (
523E5C502BC60563007444DA /* SurvivalModeTests.swift */,
523E5C522BC60A15007444DA /* DeathMatchModeTests.swift */,
);
path = GameModeTests;
sourceTree = "<group>";
};
5240D0942BB04E2B004F1486 /* Fonts */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -628,7 +639,6 @@
isa = PBXGroup;
children = (
52DF5FAD2BA32B2300135367 /* GameScene.swift */,
5295A2032BA9FED4005018A8 /* MenuScene.swift */,
527A07852BB411FB00CD9D08 /* GameOverScene.swift */,
BAFFB9422BB0A79B00D8301F /* SpriteKitScenes */,
BAFFB9322BB0A10C00D8301F /* SceneDelegates */,
Expand Down Expand Up @@ -779,6 +789,7 @@
52DF5FC02BA32B2600135367 /* TowerForgeTests */ = {
isa = PBXGroup;
children = (
523E5C4F2BC6054F007444DA /* GameModeTests */,
BAFFB94C2BB12F7D00D8301F /* GameModuleTests */,
BA443D402BAD9872009F0FFB /* EventTests */,
52DF5FE22BA3386400135367 /* CoreUITests */,
Expand Down Expand Up @@ -1450,7 +1461,6 @@
5299D1412BC3AA3A003EF746 /* GameRankData.swift in Sources */,
9BD669682BAFDE5E00DC8C4C /* GridDelegate.swift in Sources */,
52DF5FEB2BA3400C00135367 /* TFAnimatableNode.swift in Sources */,
5295A2042BA9FED4005018A8 /* MenuScene.swift in Sources */,
3C3CBDFF2BB8708A0001B8A9 /* CGPoint+Extensions.swift in Sources */,
52DF5FEF2BA34EA000135367 /* TFEntity.swift in Sources */,
BAFFB95D2BB978E500D8301F /* StorageEnums.swift in Sources */,
Expand Down Expand Up @@ -1501,7 +1511,9 @@
3C07CB272BC2990E00207C38 /* TFComponentTests.swift in Sources */,
BAFFB9502BB12F9D00D8301F /* GameEngineTests.swift in Sources */,
BA443D4B2BB05F73009F0FFB /* RequestSpawnEventTests.swift in Sources */,
523E5C532BC60A15007444DA /* DeathMatchModeTests.swift in Sources */,
BA443D452BB05A3C009F0FFB /* SpawnEventTests.swift in Sources */,
523E5C512BC60563007444DA /* SurvivalModeTests.swift in Sources */,
3C07CB212BC287DD00207C38 /* GameModuleTestsUtils.swift in Sources */,
BA443D492BB05EF0009F0FFB /* RemoveEventTests.swift in Sources */,
BA443D422BAD9885009F0FFB /* DamageEventTests.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<navigationItem key="navigationItem" id="9Rh-a0-sTy"/>
<connections>
<outlet property="gamePopupButton" destination="FRf-Sx-cuP" id="9ja-00-9KT"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="SZV-WD-TEh" sceneMemberID="firstResponder"/>
</objects>
Expand All @@ -47,7 +50,7 @@
<!--MainMenuViewController-->
<scene sceneID="vFw-SO-Nq3">
<objects>
<viewController storyboardIdentifier="MainMenuViewController" title="MainMenuViewController" id="NJ9-hN-4Nf" customClass="MainMenuViewController" customModule="TowerForge" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="MainMenuViewController" title="MainMenuViewController" modalPresentationStyle="fullScreen" useStoryboardIdentifierAsRestorationIdentifier="YES" id="NJ9-hN-4Nf" customClass="MainMenuViewController" customModule="TowerForge" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleAspectFill" id="QTh-pm-dcu">
<rect key="frame" x="0.0" y="0.0" width="1366" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -148,7 +151,6 @@
</buttonConfiguration>
<connections>
<action selector="onLoginPressed:" destination="n8I-SW-Wif" eventType="touchUpInside" id="dkv-Wu-Nb7"/>
<segue destination="bL0-ag-pcs" kind="showDetail" identifier="segueToMenuGame" id="1ej-FD-YqB"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Login" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bDM-Xl-gio">
Expand Down Expand Up @@ -333,7 +335,7 @@
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ewd-d2-Lxq">
<rect key="frame" x="205" y="124" width="257.5" height="198"/>
<rect key="frame" x="205" y="194" width="257.5" height="128"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9Ao-cU-Ulr">
<rect key="frame" x="-38" y="3" width="315" height="122"/>
Expand Down Expand Up @@ -845,9 +847,6 @@ Match</string>
<point key="canvasLocation" x="139.67789165446558" y="722.4609375"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="1ej-FD-YqB"/>
</inferredMetricsTieBreakers>
<resources>
<image name="Flag" width="500" height="500"/>
<image name="Sword" width="500" height="500"/>
Expand Down
14 changes: 13 additions & 1 deletion TowerForge/TowerForge/Commons/Constants/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import UIKit

/// A class to encapsulate application wide constants to ensure a single source of truth
/// across the entire application.
Expand Down Expand Up @@ -39,21 +40,32 @@ struct PositionConstants {
static let CTF_POINT_OWN = CGPoint(x: 300, y: 50)
static let CTF_POINT_OPP = CGPoint(x: 300, y: 110)

// Survival Mode Properties
static let SURVIVAL_POINT_OWN = CGPoint(x: 300, y: 100)

static let SUBTITLE_LABEL_OFFSET = CGPoint(x: 0, y: -30)
}

struct SizeConstants {

// Death Match Mode Properties Size
static let DEATH_MATCH_POINT_SIZE = CGSize(width: 50, height: 50)

// Capture the Flag Mode Properties Size
static let CTF_POINT_SIZE = CGSize(width: 50, height: 50)

// Survival Mode Properties Size
static let SURVIVAL_POINT_SIZE = CGSize(width: 100, height: 100)

static let SCREEN_SIZE = CGSize(width: UIScreen.main.bounds.width,
height: UIScreen.main.bounds.height)
}

struct FontConstants {
static let GAME_FONT_SIZE: CGFloat = 40.0
}

struct GameModeSettingsConstants {
// static let LEVEL_ONE_WAVE
// Survival Mode Settings

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AuthenticationManager: AuthenticationProtocol {
}
Auth.auth().createUser(withEmail: email, password: password) { _, error in
if error != nil {
print("Error in creating user \(error)")
onFinish(nil, error)
} else {
Auth.auth().signIn(withEmail: email, password: password)
let user = Auth.auth().currentUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import Foundation

class Life: TFEntity {
init(initialLife: Int, position: CGPoint, player: Player) {
init(initialLife: Int, position: CGPoint, player: Player, size: CGSize) {
super.init()
let spriteComponent = SpriteComponent(textureNames: ["Life"],
size: SizeConstants.CTF_POINT_SIZE,
size: size,
animatableKey: "life")
self.addComponent(spriteComponent)
self.addComponent(HomeComponent(initialLifeCount: Team.lifeCount, pointInterval: Team.pointsInterval))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CaptureTheFlagMode: GameMode {
static let INITIAL_POINT = 5

var modeName: String = "Capture The Flag"
var modeDescription: String = "Destroy the enemy base!"
static var modeDescription: String = "Destroy the enemy base!"
var gameProps: [any GameProp] = [PointProp(initialPoint: 0)]
var gameState = GameState.IDLE
var currentOwnLife: Int
Expand All @@ -21,13 +21,16 @@ class CaptureTheFlagMode: GameMode {
init(initialLife: Int, eventManager: EventManager) {
self.gameProps.append(LifeProp(initialLife: initialLife,
position: PositionConstants.CTF_POINT_OWN,
player: .ownPlayer))
player: .ownPlayer,
size: SizeConstants.CTF_POINT_SIZE))
self.gameProps.append(LifeProp(initialLife: initialLife,
position: PositionConstants.CTF_POINT_OPP,
player: .oppositePlayer))
player: .oppositePlayer,
size: SizeConstants.CTF_POINT_SIZE))
self.currentOwnLife = initialLife
self.currentOpponentLife = initialLife
self.eventManager = eventManager
self.gameState = .PLAYING
eventManager.registerHandler(forEvent: LifeEvent.self) { event in
if let lifeEvent = event as? LifeEvent {
// Check if the event reduces life
Expand Down
13 changes: 10 additions & 3 deletions TowerForge/TowerForge/GameModule/GameModes/DeathMatchMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,30 @@
import Foundation

class DeathMatchMode: GameMode {

static var modeDescription: String = "Kill as many units within the time limit"
static let DEATH_MATCH_MODE_TIMER = TimeInterval(120)

var eventManager: EventManager
var modeName: String = "Death Match Mode"
var modeDescription: String = "Kill as many units within the time limit"
var gameProps: [any GameProp] = [DeathProp(position: PositionConstants.DEATH_MATCH_POINT_OWN,
player: .ownPlayer),
DeathProp(position: PositionConstants.DEATH_MATCH_POINT_OPP,
player: .oppositePlayer),
PointProp(initialPoint: 0)]
var timer = TimerProp(timeLength: TimeInterval(60))
var timer = TimerProp(timeLength: DeathMatchMode.DEATH_MATCH_MODE_TIMER)
var gameState = GameState.IDLE
var currentOwnKillCounter: Int
var currentOpponentKillCounter: Int
var remainingTime: TimeInterval

init(eventManager: EventManager) {
self.currentOwnKillCounter = 0
self.currentOpponentKillCounter = 0
self.eventManager = eventManager
self.gameProps.append(timer)
self.gameState = .PLAYING
self.remainingTime = timer.time
eventManager.registerHandler(forEvent: KillEvent.self) { event in
if let killEvent = event as? KillEvent {
// Check if the event reduces life
Expand All @@ -38,7 +44,8 @@ class DeathMatchMode: GameMode {
}
}
func updateGame(deltaTime: TimeInterval) {
if timer.time < 0 {
self.remainingTime = timer.time
if remainingTime <= 0 {
if currentOwnKillCounter > currentOpponentKillCounter {
gameState = .WIN
} else if currentOwnKillCounter < currentOpponentKillCounter {
Expand Down
2 changes: 1 addition & 1 deletion TowerForge/TowerForge/GameModule/GameModes/GameMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct GameResult {

protocol GameMode {
var modeName: String { get }
var modeDescription: String { get }
static var modeDescription: String { get }
var gameProps: [any GameProp] { get }
var gameState: GameState { get set }
var eventManager: EventManager { get set }
Expand Down
23 changes: 15 additions & 8 deletions TowerForge/TowerForge/GameModule/GameModes/SurvivalGameMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
// SurvivalGameMode.swift
// TowerForge
//
// Created by MacBook Pro on 09/04/24.
// Created by Vanessa Mae on 09/04/24.
//

import Foundation
import UIKit

class SurvivalGameMode: GameMode {

static let WAVE_TIME_INTERVAL = TimeInterval(50)

var modeName: String = "Survival Game Mode"

var modeDescription: String = "Don't let the enemy invade your base!"
static var modeDescription: String = "Don't let the enemy invade your base!"

var gameProps: [any GameProp] = [PointProp(initialPoint: 0)]
var gameProps: [any GameProp] = [PointProp(initialPoint: 0),
LifeProp(initialLife: 1,
position: PositionConstants.SURVIVAL_POINT_OWN,
player: .ownPlayer,
size: SizeConstants.SURVIVAL_POINT_SIZE)]

var gameState = GameState.IDLE

Expand All @@ -24,12 +31,13 @@ class SurvivalGameMode: GameMode {
private var currentLevel: Int = 1
private var maxLevel: Int

private var nextWaveTime = TimeInterval(50)
private var waveTimeInterval = TimeInterval(50)
private var nextWaveTime = SurvivalGameMode.WAVE_TIME_INTERVAL
private var waveTimeInterval = SurvivalGameMode.WAVE_TIME_INTERVAL

init(eventManager: EventManager, maxLevel: Int) {
self.eventManager = eventManager
self.maxLevel = maxLevel
self.gameState = .PLAYING

let timer = TimerProp(timeLength: waveTimeInterval * Double(maxLevel))
self.gameProps.append(timer)
Expand All @@ -38,7 +46,6 @@ class SurvivalGameMode: GameMode {
if let lifeEvent = event as? LifeEvent {
// Check if the event reduces life
if lifeEvent.player == .oppositePlayer && lifeEvent.lifeDecrease > 0 {
print("Triggered?")
self.currentOwnLife -= lifeEvent.lifeDecrease
}
}
Expand All @@ -47,7 +54,7 @@ class SurvivalGameMode: GameMode {

func updateGame(deltaTime: TimeInterval) {
nextWaveTime -= deltaTime
if nextWaveTime < 0 && self.currentLevel <= self.maxLevel {
if nextWaveTime <= 0 && self.currentLevel <= self.maxLevel {
nextWaveTime = waveTimeInterval
self.currentLevel += 1
self.generateWaveSpawns(enemyCount: 5 * self.currentLevel)
Expand All @@ -61,7 +68,7 @@ class SurvivalGameMode: GameMode {
}

func getGameResults() -> [GameResult] {
[GameResult(variable: "Finished Waves", value: String(currentLevel))]
[GameResult(variable: "Finished Waves", value: String(currentLevel - 1))]
}

private func generateWaveSpawns(enemyCount: Int) {
Expand Down
7 changes: 5 additions & 2 deletions TowerForge/TowerForge/GameModule/GameProps/LifeProp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import Foundation
class LifeProp: GameProp {
var renderableEntity: Life

init(initialLife: Int, position: CGPoint, player: Player) {
self.renderableEntity = Life(initialLife: initialLife, position: position, player: player)
init(initialLife: Int, position: CGPoint, player: Player, size: CGSize) {
self.renderableEntity = Life(initialLife: initialLife,
position: position,
player: player,
size: size)
}
}
Loading