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: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
|
||||||
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
|
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
|
||||||
|
|
||||||
for base in currentDraggedBase!.adjacencyList {
|
addAttackDetails(touchLocation: touchLocation)
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for entity in entityManager.entities {
|
for entity in entityManager.entities {
|
||||||
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
||||||
|
|
||||||
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
|
addBaseDetails(touchLocation: touchLocation, spriteNode: spriteNode, touches: touches, event: event, entity: entity)
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,16 +64,57 @@ class GameScene: SKScene{
|
|||||||
child.touchesMoved(touches, with: event)
|
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{
|
for e in entityManager.entities{
|
||||||
if let body = e.component(ofType: ModalContentComponent.self)?.body{
|
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)
|
GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)
|
||||||
body.text = "Schicke \(GameScene.sendUnits) Einheiten "
|
body.text = "Schicke \(GameScene.sendUnits) Einheiten "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let bases = entityManager.getBasesByPlayer(for: GKLocalPlayer.local)
|
func checkBases(bases: Set<Base>, touchLocation: CGPoint){
|
||||||
|
|
||||||
for base in bases {
|
for base in bases {
|
||||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
|
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
|
||||||
if !isMoveTouch {
|
if !isMoveTouch {
|
||||||
@ -103,22 +123,24 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
isMoveTouch = true
|
isMoveTouch = true
|
||||||
|
|
||||||
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
moveFireAndBase(base: base, touchLocation: touchLocation)
|
||||||
base.component(ofType: TeamComponent.self)?.fire.position = touchLocation
|
showNearestBases(base: base)
|
||||||
|
|
||||||
for adjacencyBase in base.adjacencyList {
|
|
||||||
let node = adjacencyBase.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
|
||||||
node?.run(SKAction.sequence([
|
|
||||||
SKAction.resize(byWidth: 2, height: 2, duration: 0.5),
|
|
||||||
SKAction.resize(byWidth: -2, height: -2, duration: 0.5)
|
|
||||||
]))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func update(_ currentTime: TimeInterval) {
|
func moveFireAndBase(base: Base, touchLocation: CGPoint){
|
||||||
entityManager.getBackground()?.update(deltaTime: currentTime)
|
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
||||||
entityManager.getHUD()?.component(ofType: TimerComponent.self)?.update()
|
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([
|
||||||
|
SKAction.resize(byWidth: 2, height: 2, duration: 0.5),
|
||||||
|
SKAction.resize(byWidth: -2, height: -2, duration: 0.5)
|
||||||
|
]))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user