-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroup.swift
104 lines (93 loc) · 3.24 KB
/
Group.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// Group.swift
// Jikoku
//
// Created by Raphaël Calabro on 28/07/2017.
// Copyright © 2017 Raphaël Calabro. All rights reserved.
//
import Foundation
import Melisse
struct Group : Hashable {
var kanji: Kanji
var count: Int
var shape: Shape
var size: ShapeSize
var formation: Formation
var isFlying: Bool
var spriteDefinition: Int?
var shadowDefinition: Int?
var shootingStyleDefinition: ShootingStyleDefinition?
var isPersistent: Bool {
return size == .bigger
}
init(kanji: Kanji, count: Int = 1, shape: Shape = .round, size: ShapeSize = .medium, formation: Formation = .none, isFlying: Bool = true, spriteDefinition: Int? = nil, shadowDefinition: Int? = nil, shootingStyleDefinition: ShootingStyleDefinition? = nil) {
self.kanji = kanji
self.count = count
self.shape = shape
self.size = size
self.formation = formation
self.isFlying = isFlying
self.spriteDefinition = spriteDefinition
self.shadowDefinition = shadowDefinition
self.shootingStyleDefinition = shootingStyleDefinition
}
var hashValue: Int {
return kanji.hashValue &* 3
&+ count.hashValue &* 7
&+ shape.hashValue &* 11
&+ size.hashValue &* 13
&+ formation.hashValue &* 17
}
var formationDefinition: FormationDefinition {
switch formation {
case .topLeftQuarterCircle:
fallthrough
case .topRightQuarterCircle:
return QuarterCircleFormationDefinition(group: self)
case .stationary:
return StationaryFormationDefinition(group: self)
default:
return NoFormationDefinition()
}
}
static func random(with kanjis: [Kanji]) -> Group {
let size = ShapeSize.random
let shootingStyleDefinition: ShootingStyleDefinition
if size == .bigger {
shootingStyleDefinition = CircularShootingStyleDefinition(
shotAmount: 18,
shotAmountVariation: 0,
shotSpeed: 50,
shootInterval: 2,
inversions: [],
inversionInterval: 0,
spriteDefinition: 2,
baseAngle: 0,
baseAngleVariation: 0)
} else {
shootingStyleDefinition = AimedShootingStyleDefinition(
shotAmount: 1,
shotAmountVariation: 0,
shotSpeed: 100,
shootInterval: 1,
inversions: [],
inversionInterval: 0,
spriteDefinition: 1,
targetType: .player)
}
return Group(
kanji: Melisse.random(itemFrom: kanjis),
count: size.randomCount,
shape: Melisse.random(itemFrom: [Shape.round, .pentagonal]),
size: size,
formation: .stationary,
shootingStyleDefinition: shootingStyleDefinition)
}
static func ==(lhs: Group, rhs: Group) -> Bool {
return lhs.kanji == rhs.kanji
&& lhs.count == rhs.count
&& lhs.shape == rhs.shape
&& lhs.size == rhs.size
&& lhs.formation == rhs.formation
}
}