-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
c6b3edf
commit de28dd9
Showing
16 changed files
with
337 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Font.swift | ||
// Engine | ||
// | ||
// Created by Nick Lockwood on 21/04/2020. | ||
// Copyright © 2020 Nick Lockwood. All rights reserved. | ||
// | ||
|
||
public struct Font: Decodable { | ||
public let texture: Texture | ||
public let characters: [String] | ||
} |
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,78 @@ | ||
// | ||
// Game.swift | ||
// Engine | ||
// | ||
// Created by Nick Lockwood on 07/10/2019. | ||
// Copyright © 2019 Nick Lockwood. All rights reserved. | ||
// | ||
|
||
public protocol GameDelegate: AnyObject { | ||
func playSound(_ sound: Sound) | ||
func clearSounds() | ||
} | ||
|
||
public enum GameState { | ||
case title | ||
case starting | ||
case playing | ||
} | ||
|
||
public struct Game { | ||
public weak var delegate: GameDelegate? | ||
public let levels: [Tilemap] | ||
public private(set) var world: World | ||
public private(set) var state: GameState | ||
public private(set) var transition: Effect? | ||
public let font: Font | ||
public var titleText = "TAP TO START" | ||
|
||
public init(levels: [Tilemap], font: Font) { | ||
self.state = .title | ||
self.levels = levels | ||
self.world = World(map: levels[0]) | ||
self.font = font | ||
} | ||
} | ||
|
||
public extension Game { | ||
var hud: HUD { | ||
return HUD(player: world.player, font: font) | ||
} | ||
|
||
mutating func update(timeStep: Double, input: Input) { | ||
guard let delegate = delegate else { | ||
return | ||
} | ||
|
||
// Update transition | ||
if var effect = transition { | ||
effect.time += timeStep | ||
transition = effect | ||
} | ||
|
||
// Update state | ||
switch state { | ||
case .title: | ||
if input.isFiring { | ||
transition = Effect(type: .fadeOut, color: .black, duration: 0.5) | ||
state = .starting | ||
} | ||
case .starting: | ||
if transition?.isCompleted == true { | ||
transition = Effect(type: .fadeIn, color: .black, duration: 0.5) | ||
state = .playing | ||
} | ||
case .playing: | ||
if let action = world.update(timeStep: timeStep, input: input) { | ||
switch action { | ||
case .loadLevel(let index): | ||
let index = index % levels.count | ||
world.setLevel(levels[index]) | ||
delegate.clearSounds() | ||
case .playSounds(let sounds): | ||
sounds.forEach(delegate.playSound) | ||
} | ||
} | ||
} | ||
} | ||
} |
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,33 @@ | ||
// | ||
// HUD.swift | ||
// Engine | ||
// | ||
// Created by Nick Lockwood on 19/04/2020. | ||
// Copyright © 2020 Nick Lockwood. All rights reserved. | ||
// | ||
|
||
public struct HUD { | ||
public let healthString: String | ||
public let healthTint: Color | ||
public let ammoString: String | ||
public let playerWeapon: Texture | ||
public let weaponIcon: Texture | ||
public let font: Font | ||
|
||
public init(player: Player, font: Font) { | ||
let health = Int(max(0, player.health)) | ||
switch health { | ||
case ...10: | ||
self.healthTint = .red | ||
case 10 ... 30: | ||
self.healthTint = .yellow | ||
default: | ||
self.healthTint = .green | ||
} | ||
self.healthString = String(health) | ||
self.ammoString = String(Int(max(0, min(99, player.ammo)))) | ||
self.playerWeapon = player.animation.texture | ||
self.weaponIcon = player.weapon.attributes.hudIcon | ||
self.font = font | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
Source/Rampage.xcodeproj/xcshareddata/xcschemes/Rampage.xcscheme
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions
21
Source/Rampage/Assets.xcassets/titleBackground.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,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "titleBackground.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Binary file added
BIN
+92 KB
Source/Rampage/Assets.xcassets/titleBackground.imageset/titleBackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions
21
Source/Rampage/Assets.xcassets/titleLogo.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,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "titleLogo.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"texture": "font", | ||
"characters": [ | ||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", | ||
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", | ||
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", | ||
"U", "V", "W", "X", "Y", "Z", " " | ||
] | ||
} |
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