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
/
Copy pathTile.swift
61 lines (45 loc) · 1.93 KB
/
Tile.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
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Tile.swift
// Bomberman
//
// Created by Wolfgang Schreurs on 25/04/16.
//
//
import GameplayKit
import SpriteKit
class Tile : Entity {
let tileType: TileType
// MARK: - Initialization
convenience init(gridPosition: Point, configComponent: ConfigComponent, tileType: TileType) {
// TODO: make more safe, currently will crash if no config exists.
let basePath = configComponent.configFilePath
let filePath = basePath.stringByAppendingPathComponent(configComponent.textureFile)
let imageData = try? Data(contentsOf: URL(fileURLWithPath: filePath))
let image = Image(data: imageData!)
let texture = SKTexture(image: image!)
let sprites = SpriteLoader.spritesFromTexture(texture, withSpriteSize: configComponent.spriteSize)
let visualComponent = VisualComponent(sprites: sprites)
self.init(gridPosition: gridPosition, visualComponent: visualComponent, tileType: tileType)
addComponent(configComponent)
}
init(gridPosition: Point, visualComponent: VisualComponent, tileType: TileType) {
self.tileType = tileType
super.init(visualComponent: visualComponent)
visualComponent.spriteNode.zPosition = EntityLayer.tile.rawValue
let category = (tileType == .wall) ? EntityCategory.Wall : EntityCategory.Block
if let physicsBody = visualComponent.spriteNode.physicsBody {
physicsBody.categoryBitMask = category
physicsBody.collisionBitMask = EntityCategory.Nothing
physicsBody.contactTestBitMask = EntityCategory.Nothing
}
self.gridPosition = gridPosition
self.value = PointsType.fifty
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func destroy() {
removePhysicsBody()
super.destroy()
}
}