This repository has been 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
/
CreatureLoader.swift
48 lines (38 loc) · 1.62 KB
/
CreatureLoader.swift
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
//
// CreatureLoader.swift
// Bomberman
//
// Created by Wolfgang Schreurs on 27/04/16.
//
//
import Foundation
class CreatureLoader: ConfigurationLoader {
fileprivate let configFile = "config.json"
func monsterWithName(_ name: String, gridPosition: Point) throws -> Creature? {
var entity: Creature? = nil
let directory = "Creatures/\(name)"
if let configComponent = try loadConfiguration(configFile, bundleSupportSubDirectory: directory) {
switch configComponent.creatureType {
case .boss:
entity = Monster(forGame: self.game, configComponent: configComponent, gridPosition: gridPosition, createPhysicsBody: true, collidesWithPlayer: true)
case .monster: fallthrough
default:
entity = Monster(forGame: self.game, configComponent: configComponent, gridPosition: gridPosition, createPhysicsBody: false, collidesWithPlayer: false)
}
}
return entity
}
func playerWithIndex(_ index: PlayerIndex, gridPosition: Point) throws -> Player? {
var entity: Player? = nil
var name: String
switch index {
case .player1: name = "Player1"
case .player2: name = "Player2"
}
let directory = "Creatures/\(name)"
if let configComponent = try loadConfiguration(configFile, bundleSupportSubDirectory: directory) {
entity = Player(forGame: self.game, configComponent: configComponent, gridPosition: gridPosition, playerIndex: index)
}
return entity
}
}