This repository was archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropLoader.swift
More file actions
72 lines (55 loc) · 2.56 KB
/
PropLoader.swift
File metadata and controls
72 lines (55 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// PropLoader.swift
// Bomberman
//
// Created by Wolfgang Schreurs on 29/04/16.
//
//
import CoreGraphics
class PropLoader: ConfigurationLoader {
fileprivate let configFile = "config.json"
func explosionWithGridPosition(_ gridPosition: Point, direction: Direction) throws -> Explosion? {
var explosion: Explosion?
let directory = "Props/Explosion"
if let configComponent = try loadConfiguration(configFile, bundleSupportSubDirectory: directory) {
explosion = Explosion(forGame: self.game, configComponent: configComponent, gridPosition: gridPosition)
explosion?.direction = direction
}
return explosion
}
func bombWithGridPosition(_ gridPosition: Point, player: PlayerIndex) throws -> Bomb? {
var bomb: Bomb? = nil
let directory = "Props/Bomb"
if let configComponent = try loadConfiguration(configFile, bundleSupportSubDirectory: directory) {
bomb = Bomb(forGame: self.game,
player: player,
configComponent: configComponent,
gridPosition: gridPosition)
}
return bomb
}
func projectileWithName(_ name: String, gridPosition: Point, force: CGVector) throws -> Projectile? {
var projectile: Projectile? = nil
let directory = "Projectiles/\(name)"
if let configComponent = try loadConfiguration(configFile, bundleSupportSubDirectory: directory) {
projectile = Projectile(forGame: self.game, configComponent: configComponent, gridPosition: gridPosition, force: force)
}
return projectile
}
func pointsWithType(_ pointsType: PointsType, gridPosition: Point) throws -> Points? {
var points: Points? = nil
let directory = "Props/Points10"
if let configComponent = try loadConfiguration(configFile, bundleSupportSubDirectory: directory) {
points = Points(forGame: self.game, configComponent: configComponent, gridPosition: gridPosition, type: pointsType)
}
return points
}
func propWithName(_ propName: String, gridPosition: Point) throws -> Prop? {
var prop: Prop? = nil
let directory = "Props/\(propName)"
if let configComponent = try loadConfiguration(configFile, bundleSupportSubDirectory: directory) {
prop = Prop(forGame: self.game, configComponent: configComponent, gridPosition: gridPosition)
}
return prop
}
}