/
Monster.swift
39 lines (33 loc) · 1.04 KB
/
Monster.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
//
// Monster.swift
// star-dash
//
// Created by Lau Rui han on 12/3/24.
//
import Foundation
class Monster: Entity {
let id: EntityId
private let position: CGPoint
init(id: EntityId, position: CGPoint) {
self.id = id
self.position = position
}
convenience init(position: CGPoint) {
self.init(id: UUID(), position: position)
}
func setUpAndAdd(to: EntityManager) {
let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero)
let healthComponent = HealthComponent(entityId: self.id, health: 100)
let physicsComponent = PhysicsComponent(
entityId: self.id,
mass: .zero,
velocity: .zero,
force: .zero,
collisionMask: PhysicsConstants.CollisionMask.monsterCollisionMask,
affectedByGravity: false)
to.add(entity: self)
to.add(component: positionComponent)
to.add(component: healthComponent)
to.add(component: physicsComponent)
}
}