making smaller funcs in GameScene for betterUnderstanding
This commit is contained in:
parent
8db0b14b7f
commit
9b57a1bcea
@ -41,34 +41,13 @@ class GameScene: SKScene{
|
||||
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
|
||||
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
|
||||
|
||||
for base in currentDraggedBase!.adjacencyList {
|
||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
||||
// TODO: change interaction based on collision instead of touchlocation
|
||||
entityManager.add(Modal(modaltype: .BaseAttack,
|
||||
base: currentDraggedBase!,
|
||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
||||
entityManager: entityManager, gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation))
|
||||
}
|
||||
}
|
||||
addAttackDetails(touchLocation: touchLocation)
|
||||
}
|
||||
else {
|
||||
for entity in entityManager.entities {
|
||||
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
||||
|
||||
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
|
||||
spriteNode?.touchesBegan(touches, with: event)
|
||||
if !entityManager.isModal {
|
||||
for child in self.children {
|
||||
if(child.name != "fire"){
|
||||
child.alpha = 0.3
|
||||
}
|
||||
}
|
||||
entityManager.add(Modal(modaltype: .BaseDetails,
|
||||
base: entity as! Base,
|
||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
||||
entityManager: entityManager, gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation))
|
||||
}
|
||||
}
|
||||
addBaseDetails(touchLocation: touchLocation, spriteNode: spriteNode, touches: touches, event: event, entity: entity)
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,16 +64,57 @@ class GameScene: SKScene{
|
||||
child.touchesMoved(touches, with: event)
|
||||
}
|
||||
}
|
||||
checkSlider()
|
||||
|
||||
let bases = entityManager.getBasesByPlayer(for: GKLocalPlayer.local)
|
||||
|
||||
checkBases(bases: bases, touchLocation: touchLocation)
|
||||
}
|
||||
|
||||
override func update(_ currentTime: TimeInterval) {
|
||||
entityManager.getBackground()?.update(deltaTime: currentTime)
|
||||
entityManager.getHUD()?.component(ofType: TimerComponent.self)?.update()
|
||||
}
|
||||
|
||||
func addBaseDetails(touchLocation: CGPoint, spriteNode: SKNode?, touches: Set<UITouch>, event: UIEvent?, entity: GKEntity){
|
||||
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
|
||||
spriteNode?.touchesBegan(touches, with: event)
|
||||
if !entityManager.isModal {
|
||||
for child in self.children {
|
||||
if(child.name != "fire"){
|
||||
child.alpha = 0.3
|
||||
}
|
||||
}
|
||||
entityManager.add(Modal(modaltype: .BaseDetails,
|
||||
base: entity as! Base,
|
||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
||||
entityManager: entityManager, gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addAttackDetails(touchLocation: CGPoint){
|
||||
for base in currentDraggedBase!.adjacencyList {
|
||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
||||
// TODO: change interaction based on collision instead of touchlocation
|
||||
entityManager.add(Modal(modaltype: .BaseAttack,
|
||||
base: currentDraggedBase!,
|
||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
||||
entityManager: entityManager, gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkSlider(){
|
||||
for e in entityManager.entities{
|
||||
if let body = e.component(ofType: ModalContentComponent.self)?.body{
|
||||
GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)
|
||||
body.text = "Schicke \(GameScene.sendUnits) Einheiten "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let bases = entityManager.getBasesByPlayer(for: GKLocalPlayer.local)
|
||||
|
||||
func checkBases(bases: Set<Base>, touchLocation: CGPoint){
|
||||
for base in bases {
|
||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
|
||||
if !isMoveTouch {
|
||||
@ -103,9 +123,18 @@ class GameScene: SKScene{
|
||||
}
|
||||
isMoveTouch = true
|
||||
|
||||
moveFireAndBase(base: base, touchLocation: touchLocation)
|
||||
showNearestBases(base: base)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func moveFireAndBase(base: Base, touchLocation: CGPoint){
|
||||
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
||||
base.component(ofType: TeamComponent.self)?.fire.position = touchLocation
|
||||
}
|
||||
|
||||
func showNearestBases(base: Base){
|
||||
for adjacencyBase in base.adjacencyList {
|
||||
let node = adjacencyBase.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
||||
node?.run(SKAction.sequence([
|
||||
@ -115,10 +144,3 @@ class GameScene: SKScene{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func update(_ currentTime: TimeInterval) {
|
||||
entityManager.getBackground()?.update(deltaTime: currentTime)
|
||||
entityManager.getHUD()?.component(ofType: TimerComponent.self)?.update()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user