diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 4982277..2d47daa 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -18,7 +18,6 @@ 116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116060F6245C57D2004E5A36 /* EntityManager.swift */; }; 3E67854024728368007B9DE4 /* CElements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E67853F24728368007B9DE4 /* CElements.swift */; }; 3E6785422472CBEC007B9DE4 /* Way.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E6785412472CBEC007B9DE4 /* Way.swift */; }; - 3E6785442472CC27007B9DE4 /* DefaultWayComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E6785432472CC27007B9DE4 /* DefaultWayComponent.swift */; }; 3EAD889524801B6A0048A10A /* RoundTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EAD889424801B6A0048A10A /* RoundTimer.swift */; }; 3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; }; 3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */; }; @@ -82,7 +81,6 @@ 116060F6245C57D2004E5A36 /* EntityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityManager.swift; sourceTree = ""; }; 3E67853F24728368007B9DE4 /* CElements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CElements.swift; sourceTree = ""; }; 3E6785412472CBEC007B9DE4 /* Way.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Way.swift; sourceTree = ""; }; - 3E6785432472CC27007B9DE4 /* DefaultWayComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultWayComponent.swift; sourceTree = ""; }; 3EAD889424801B6A0048A10A /* RoundTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundTimer.swift; sourceTree = ""; }; 3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = ""; }; 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerMoveType.swift; sourceTree = ""; }; @@ -203,7 +201,6 @@ 9E174C85245DD91500209FF0 /* ButtonComponent.swift */, 9E174C81245DD81D00209FF0 /* ButtonNode.swift */, 9EA3ABE8245C6DAA006BC61D /* DefaultBaseComponent.swift */, - 3E6785432472CC27007B9DE4 /* DefaultWayComponent.swift */, C064E9A9246C114C0022B228 /* LabelComponent.swift */, C064E9A7246C0EA50022B228 /* LabelNode.swift */, 9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */, @@ -424,7 +421,6 @@ 9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */, 9E174C84245DD8CE00209FF0 /* Button.swift in Sources */, 110360DB244B101A008610AF /* GameViewController.swift in Sources */, - 3E6785442472CC27007B9DE4 /* DefaultWayComponent.swift in Sources */, C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */, 110360D3244B101A008610AF /* AppDelegate.swift in Sources */, 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */, diff --git a/GoldWars/GoldWars/Components/AttackActionComponent.swift b/GoldWars/GoldWars/Components/AttackActionComponent.swift deleted file mode 100644 index ba46e1a..0000000 --- a/GoldWars/GoldWars/Components/AttackActionComponent.swift +++ /dev/null @@ -1,27 +0,0 @@ -// -// AttackActionComponent.swift -// GoldWars -// -// Created by Niko Jochim on 03.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import GameplayKit - -class AttackActionComponent: GKComponent { - - - init(unitCount: Int, adjacencyList: Array, position: CGPoint) { - super.init() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - - func action() { - // Not implemented yet - } - -} diff --git a/GoldWars/GoldWars/Components/DefaultWayComponent.swift b/GoldWars/GoldWars/Components/DefaultWayComponent.swift deleted file mode 100644 index 045ac04..0000000 --- a/GoldWars/GoldWars/Components/DefaultWayComponent.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// DefaultWayComponent.swift -// GoldWars -// -// Created by Jakob Haag on 18.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import Foundation -import GameplayKit -import SpriteKit - -class DefaultWayComponent: GKComponent { - var shapeNode: SKShapeNode - - init(pathToDraw: CGMutablePath) { - self.shapeNode = SKShapeNode() - shapeNode.path = pathToDraw - shapeNode.strokeColor = UIColor(red: 0.852, green: 0.649, blue: 0.123, alpha: 1) - shapeNode.lineWidth = 10 - shapeNode.zPosition = 0 - super.init() - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} diff --git a/GoldWars/GoldWars/Components/SkillComponent.swift b/GoldWars/GoldWars/Components/SkillComponent.swift deleted file mode 100644 index 001aa2a..0000000 --- a/GoldWars/GoldWars/Components/SkillComponent.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// SkillComponent.swift -// GoldWars -// -// Created by Marcel Schwarz on 24.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import Foundation -import GameKit -import GameplayKit - -class SkillComponent: GKComponent { - var skillButtonNode: SingeClickButtonNode - - init(textureName: String, text: String, position: CGPoint, isEnabled: Bool, onButtonPress: @escaping () -> ()) { - skillButtonNode = SingeClickButtonNode(textureName: textureName, text: text, isEnabled: isEnabled, position: position, onButtonPress: onButtonPress) - super.init() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} - diff --git a/GoldWars/GoldWars/Components/TimerComponent.swift b/GoldWars/GoldWars/Components/TimerComponent.swift deleted file mode 100644 index e69de29..0000000 diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 6987fb9..1e6e383 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -59,6 +59,10 @@ class EntityManager { scene.addChild(hudEntitiy.roundLabel) } + if let wayEntity = entity as? Way { + scene.addChild(wayEntity.localWayComponent) + } + if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) { scene.addChild(spriteNode.labelNode) scene.addChild(spriteNode.spriteNode) @@ -84,9 +88,6 @@ class EntityManager { if let node = entity.component(ofType: SpinningLogoComponent.self)?.node { scene.addChild(node) } - if let wayNode = entity.component(ofType: DefaultWayComponent.self)?.shapeNode { - scene.addChild(wayNode) - } } func remove(_ entity: GKEntity) { diff --git a/GoldWars/GoldWars/Entities/Way.swift b/GoldWars/GoldWars/Entities/Way.swift index 6a64eb6..9ecc667 100644 --- a/GoldWars/GoldWars/Entities/Way.swift +++ b/GoldWars/GoldWars/Entities/Way.swift @@ -11,20 +11,53 @@ import SpriteKit import GameplayKit class Way: GKEntity { - + + var localWayComponent: SKShapeNode + required init(fromBase: Base, toBase: Base) { - super.init() + let fromBaseX = fromBase.position.x + let fromBaseY = fromBase.position.y + let toBaseX = toBase.position.x + let toBaseY = toBase.position.y + + let xControll1 = Way.computeX(x1: fromBaseX, x2: toBaseX, y1: fromBaseY, y2: toBaseY, factor: 2/5) + let yControll1 = Way.computeY(x1: fromBaseX, x2: toBaseX, y1: fromBaseY, y2: toBaseY, factor: 2/5) + let xControll2 = Way.computeX(x1: fromBaseX, x2: toBaseX, y1: fromBaseY, y2: toBaseY, factor: 3/5) + let yControll2 = Way.computeY(x1: fromBaseX, x2: toBaseX, y1: fromBaseY, y2: toBaseY, factor: 3/5) + let pathToDraw = CGMutablePath() pathToDraw.move(to: fromBase.position) - pathToDraw.addLine(to: toBase.position) - - - addComponent(DefaultWayComponent(pathToDraw: pathToDraw)) + pathToDraw.addCurve( + to: toBase.position, + control1: CGPoint(x: xControll1, y: yControll1), + control2: CGPoint(x: xControll2, y: yControll2) + ) + + self.localWayComponent = SKShapeNode() + self.localWayComponent.path = pathToDraw + self.localWayComponent.strokeColor = UIColor(red: 0.852, green: 0.649, blue: 0.123, alpha: 1) + self.localWayComponent.lineWidth = 10 + self.localWayComponent.zPosition = 0 + + super.init() } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + static var wayDelta: CGFloat = 5 + + static func computeX(x1: CGFloat, x2: CGFloat, y1: CGFloat, y2: CGFloat, factor: CGFloat) -> CGFloat { + let mix:CGFloat = Bool.random() ? -1/wayDelta : 1/wayDelta + let x = x1 + factor * (x2 - x1) + mix * -(y2-y1) + return x + } + + static func computeY(x1: CGFloat, x2: CGFloat, y1: CGFloat, y2: CGFloat, factor: CGFloat) -> CGFloat { + let mix:CGFloat = Bool.random() ? -1/wayDelta : 1/wayDelta + let y = y1 + factor * (y2 - y1) + mix * (x2-x1) + return y + } } - diff --git a/GoldWars/GoldWars/Map/CElements.swift b/GoldWars/GoldWars/Map/CElements.swift index 1e158be..588d328 100644 --- a/GoldWars/GoldWars/Map/CElements.swift +++ b/GoldWars/GoldWars/Map/CElements.swift @@ -183,24 +183,25 @@ class CElement3: CenterElementProtocol { var id: Int = 3 required init(frame: CGRect) { + let delta = (frame.maxY - frame.minY) * 0.15 self.centerBase = Base( position: CGPoint( x: frame.midX, - y: frame.maxY + y: frame.maxY - delta ) ) self.leftBase = Base( position: CGPoint( x: frame.minX, - y: frame.minY + y: frame.minY + delta ) ) self.rightBase = Base( position: CGPoint( x: frame.maxX, - y: frame.minY + y: frame.minY + delta ) ) self.bases.append(centerBase) @@ -260,24 +261,25 @@ class CElement4: CenterElementProtocol { var id: Int = 4 required init(frame: CGRect) { + let delta = (frame.maxY - frame.minY) * 0.15 self.centerBase = Base( position: CGPoint( x: frame.midX, - y: frame.maxY + y: frame.maxY - delta ) ) self.leftBase = Base( position: CGPoint( x: frame.minX, - y: frame.minY + y: frame.minY + delta ) ) self.rightBase = Base( position: CGPoint( x: frame.maxX, - y: frame.minY + y: frame.minY + delta ) ) self.bases.append(centerBase) @@ -337,24 +339,25 @@ class CElement5: CenterElementProtocol { var id: Int = 5 required init(frame: CGRect) { + let delta = (frame.maxY - frame.minY) * 0.15 self.centerBase = Base( position: CGPoint( x: frame.midX, - y: frame.minY + y: frame.minY + delta ) ) self.leftBase = Base( position: CGPoint( x: frame.minX, - y: frame.maxY + y: frame.maxY - delta ) ) self.rightBase = Base( position: CGPoint( x: frame.maxX, - y: frame.maxY + y: frame.maxY - delta ) ) self.bases.append(centerBase) @@ -414,24 +417,25 @@ class CElement6: CenterElementProtocol { var id: Int = 6 required init(frame: CGRect) { + let delta = (frame.maxY - frame.minY) * 0.15 self.centerBase = Base( position: CGPoint( x: frame.midX, - y: frame.minY + y: frame.minY + delta ) ) self.leftBase = Base( position: CGPoint( x: frame.minX, - y: frame.maxY + y: frame.maxY - delta ) ) self.rightBase = Base( position: CGPoint( x: frame.maxX, - y: frame.maxY + y: frame.maxY - delta ) ) self.bases.append(centerBase) @@ -766,24 +770,25 @@ class CElement11: CenterElementProtocol { var id: Int = 11 required init(frame: CGRect) { + let delta = (frame.maxY - frame.minY) * 0.15 self.centerBase = Base( position: CGPoint( x: frame.midX, - y: frame.maxY + y: frame.maxY - delta ) ) self.leftBase = Base( position: CGPoint( x: frame.minX, - y: frame.minY + y: frame.minY + delta ) ) self.rightBase = Base( position: CGPoint( x: frame.maxX, - y: frame.minY + y: frame.minY + delta ) ) self.bases.append(centerBase) @@ -843,24 +848,25 @@ class CElement12: CenterElementProtocol { var id: Int = 12 required init(frame: CGRect) { + let delta = (frame.maxY - frame.minY) * 0.15 self.centerBase = Base( position: CGPoint( x: frame.midX, - y: frame.maxY + y: frame.maxY - delta ) ) self.leftBase = Base( position: CGPoint( x: frame.minX, - y: frame.minY + y: frame.minY + delta ) ) self.rightBase = Base( position: CGPoint( x: frame.maxX, - y: frame.minY + y: frame.minY + delta ) ) self.bases.append(centerBase) @@ -920,24 +926,25 @@ class CElement13: CenterElementProtocol { var id: Int = 13 required init(frame: CGRect) { + let delta = (frame.maxY - frame.minY) * 0.15 self.centerBase = Base( position: CGPoint( x: frame.midX, - y: frame.minY + y: frame.minY + delta ) ) self.leftBase = Base( position: CGPoint( x: frame.minX, - y: frame.maxY + y: frame.maxY - delta ) ) self.rightBase = Base( position: CGPoint( x: frame.maxX, - y: frame.maxY + y: frame.maxY - delta ) ) self.bases.append(centerBase) @@ -997,24 +1004,25 @@ class CElement14: CenterElementProtocol { var id: Int = 14 required init(frame: CGRect) { + let delta = (frame.maxY - frame.minY) * 0.15 self.centerBase = Base( position: CGPoint( x: frame.midX, - y: frame.minY + y: frame.minY + delta ) ) self.leftBase = Base( position: CGPoint( x: frame.minX, - y: frame.maxY + y: frame.maxY - delta ) ) self.rightBase = Base( position: CGPoint( x: frame.maxX, - y: frame.maxY + y: frame.maxY - delta ) ) self.bases.append(centerBase) diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 3158ca6..9bb380c 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -86,7 +86,7 @@ class GameScene: SKScene{ if let baseEntity = entity as? Base { if baseEntity.ownershipPlayer == GKLocalPlayer.local { entityManager.add(Modal(modaltype: .BaseDetails, - base: entity as! Base, + base: entity as? Base, anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))