-
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.
Merge pull request #120 from keith-gan/main
Add powerups and cooldown
- Loading branch information
Showing
16 changed files
with
214 additions
and
5 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
TowerForge/Assets.xcassets/Sprites.spriteatlas/damage.imageset/Contents.json
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,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "damage.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "damage 1.png", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "damage 2.png", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+14.4 KB
TowerForge/Assets.xcassets/Sprites.spriteatlas/damage.imageset/damage 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.4 KB
TowerForge/Assets.xcassets/Sprites.spriteatlas/damage.imageset/damage 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.4 KB
TowerForge/Assets.xcassets/Sprites.spriteatlas/damage.imageset/damage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
TowerForge/Assets.xcassets/Sprites.spriteatlas/nocost.imageset/Contents.json
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,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "nocost.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "nocost 1.png", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "nocost 2.png", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+19.2 KB
TowerForge/Assets.xcassets/Sprites.spriteatlas/nocost.imageset/nocost 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.2 KB
TowerForge/Assets.xcassets/Sprites.spriteatlas/nocost.imageset/nocost 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.2 KB
TowerForge/Assets.xcassets/Sprites.spriteatlas/nocost.imageset/nocost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
29 changes: 29 additions & 0 deletions
29
TowerForge/TowerForge/GameModule/PowerUps/DamagePowerUp.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,29 @@ | ||
// | ||
// DamagePowerUp.swift | ||
// TowerForge | ||
// | ||
// Created by Keith Gan on 19/4/24. | ||
// | ||
|
||
import Foundation | ||
|
||
class DamagePowerUp: EventTransformation { | ||
let DURATION = CGFloat(5) | ||
let DAMAGE_SCALE = CGFloat(2) | ||
let id: UUID | ||
let player: Player | ||
|
||
required init(player: Player = .ownPlayer) { | ||
self.id = UUID() | ||
self.player = player | ||
} | ||
|
||
func transformEvent(event: TFEvent) -> TFEvent { | ||
guard let damageEvent = event as? DamageEvent, damageEvent.player == player else { | ||
return event | ||
} | ||
|
||
return DamageEvent(on: damageEvent.entityId, at: damageEvent.timestamp, with: damageEvent.damage * DAMAGE_SCALE, | ||
player: damageEvent.player) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
TowerForge/TowerForge/GameModule/PowerUps/DamagePowerUpDelegate.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,25 @@ | ||
// | ||
// DamagePowerUpDelegate.swift | ||
// TowerForge | ||
// | ||
// Created by Keith Gan on 19/4/24. | ||
// | ||
|
||
import Foundation | ||
|
||
class DamagePowerUpDelegate: PowerUpNodeDelegate { | ||
let eventManager: EventManager | ||
|
||
init(eventManager: EventManager) { | ||
self.eventManager = eventManager | ||
} | ||
|
||
func powerUpNodeDidSelect() { | ||
let damagePowerUp = DamagePowerUp() | ||
eventManager.addTransformation(eventTransformation: damagePowerUp) | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + damagePowerUp.DURATION) { | ||
self.eventManager.removeTransformation(eventTransformation: damagePowerUp) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
TowerForge/TowerForge/GameModule/PowerUps/NoCostPowerUp.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,28 @@ | ||
// | ||
// NoCostPowerUp.swift | ||
// TowerForge | ||
// | ||
// Created by Keith Gan on 19/4/24. | ||
// | ||
|
||
import Foundation | ||
|
||
class NoCostPowerUp: EventTransformation { | ||
let DURATION = CGFloat(3) | ||
let id: UUID | ||
let player: Player | ||
|
||
required init(player: Player = .ownPlayer) { | ||
self.id = UUID() | ||
self.player = player | ||
} | ||
|
||
func transformEvent(event: TFEvent) -> TFEvent { | ||
guard let requestSpawnEvent = event as? RequestSpawnEvent, requestSpawnEvent.player == player else { | ||
return event | ||
} | ||
|
||
return WaveSpawnEvent(ofType: requestSpawnEvent.entityType, timestamp: requestSpawnEvent.timestamp, position: | ||
requestSpawnEvent.position, player: requestSpawnEvent.player) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
TowerForge/TowerForge/GameModule/PowerUps/NoCostPowerUpDelegate.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,25 @@ | ||
// | ||
// NoCostPowerUpDelegate.swift | ||
// TowerForge | ||
// | ||
// Created by Keith Gan on 19/4/24. | ||
// | ||
|
||
import Foundation | ||
|
||
class NoCostPowerUpDelegate: PowerUpNodeDelegate { | ||
let eventManager: EventManager | ||
|
||
init(eventManager: EventManager) { | ||
self.eventManager = eventManager | ||
} | ||
|
||
func powerUpNodeDidSelect() { | ||
let noCostPowerUp = NoCostPowerUp() | ||
eventManager.addTransformation(eventTransformation: noCostPowerUp) | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + noCostPowerUp.DURATION) { | ||
self.eventManager.removeTransformation(eventTransformation: noCostPowerUp) | ||
} | ||
} | ||
} |
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