implemented touch functionality

This commit is contained in:
Niko 2020-05-03 15:46:48 +02:00
parent 44beb7ba4a
commit 9b3bdbf34b
6 changed files with 116 additions and 216 deletions

View File

@ -14,12 +14,12 @@
110360E0244B101B008610AF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 110360DF244B101B008610AF /* Assets.xcassets */; };
110360E3244B101B008610AF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 110360E1244B101B008610AF /* LaunchScreen.storyboard */; };
110360EE244B101B008610AF /* GoldWarsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360ED244B101B008610AF /* GoldWarsTests.swift */; };
110360F9244B101B008610AF /* GoldWarsUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360F8244B101B008610AF /* GoldWarsUITests.swift */; };
11036113244B3E30008610AF /* MenuScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11036112244B3E30008610AF /* MenuScene.swift */; };
116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116060F6245C57D2004E5A36 /* EntityManager.swift */; };
11738A3B24508F68004426F1 /* Unit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11738A3A24508F68004426F1 /* Unit.swift */; };
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */; };
3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; };
9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */; };
9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; };
9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C81245DD81D00209FF0 /* ButtonNode.swift */; };
9E174C84245DD8CE00209FF0 /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C83245DD8CE00209FF0 /* Button.swift */; };
@ -52,13 +52,6 @@
remoteGlobalIDString = 110360CE244B101A008610AF;
remoteInfo = GoldWars;
};
110360F5244B101B008610AF /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 110360C7244B101A008610AF /* Project object */;
proxyType = 1;
remoteGlobalIDString = 110360CE244B101A008610AF;
remoteInfo = GoldWars;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
@ -73,14 +66,12 @@
110360E9244B101B008610AF /* GoldWarsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GoldWarsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
110360ED244B101B008610AF /* GoldWarsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoldWarsTests.swift; sourceTree = "<group>"; };
110360EF244B101B008610AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
110360F4244B101B008610AF /* GoldWarsUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GoldWarsUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
110360F8244B101B008610AF /* GoldWarsUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoldWarsUITests.swift; sourceTree = "<group>"; };
110360FA244B101B008610AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
11036112244B3E30008610AF /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = "<group>"; };
116060F6245C57D2004E5A36 /* EntityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityManager.swift; sourceTree = "<group>"; };
11738A3A24508F68004426F1 /* Unit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Unit.swift; sourceTree = "<group>"; };
3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCenterHelper.swift; sourceTree = "<group>"; };
3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = "<group>"; };
9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttackActionComponent.swift; sourceTree = "<group>"; };
9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = "<group>"; };
9E174C81245DD81D00209FF0 /* ButtonNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonNode.swift; sourceTree = "<group>"; };
9E174C83245DD8CE00209FF0 /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = "<group>"; };
@ -122,13 +113,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
110360F1244B101B008610AF /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
@ -137,7 +121,6 @@
children = (
110360D1244B101A008610AF /* GoldWars */,
110360EC244B101B008610AF /* GoldWarsTests */,
110360F7244B101B008610AF /* GoldWarsUITests */,
110360D0244B101A008610AF /* Products */,
9E78ACB4245C9A5300526FF7 /* Frameworks */,
);
@ -148,7 +131,6 @@
children = (
110360CF244B101A008610AF /* GoldWars.app */,
110360E9244B101B008610AF /* GoldWarsTests.xctest */,
110360F4244B101B008610AF /* GoldWarsUITests.xctest */,
);
name = Products;
sourceTree = "<group>";
@ -182,15 +164,6 @@
path = GoldWarsTests;
sourceTree = "<group>";
};
110360F7244B101B008610AF /* GoldWarsUITests */ = {
isa = PBXGroup;
children = (
110360F8244B101B008610AF /* GoldWarsUITests.swift */,
110360FA244B101B008610AF /* Info.plist */,
);
path = GoldWarsUITests;
sourceTree = "<group>";
};
116060F4245C56EA004E5A36 /* Components */ = {
isa = PBXGroup;
children = (
@ -205,6 +178,7 @@
9E78ACC1245CC9EE00526FF7 /* DefBoostSkillComponent.swift */,
9E174C85245DD91500209FF0 /* ButtonComponent.swift */,
9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */,
9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */,
);
path = Components;
sourceTree = "<group>";
@ -314,24 +288,6 @@
productReference = 110360E9244B101B008610AF /* GoldWarsTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
110360F3244B101B008610AF /* GoldWarsUITests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 11036103244B101B008610AF /* Build configuration list for PBXNativeTarget "GoldWarsUITests" */;
buildPhases = (
110360F0244B101B008610AF /* Sources */,
110360F1244B101B008610AF /* Frameworks */,
110360F2244B101B008610AF /* Resources */,
);
buildRules = (
);
dependencies = (
110360F6244B101B008610AF /* PBXTargetDependency */,
);
name = GoldWarsUITests;
productName = GoldWarsUITests;
productReference = 110360F4244B101B008610AF /* GoldWarsUITests.xctest */;
productType = "com.apple.product-type.bundle.ui-testing";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
@ -349,10 +305,6 @@
CreatedOnToolsVersion = 11.3.1;
TestTargetID = 110360CE244B101A008610AF;
};
110360F3244B101B008610AF = {
CreatedOnToolsVersion = 11.3.1;
TestTargetID = 110360CE244B101A008610AF;
};
};
};
buildConfigurationList = 110360CA244B101A008610AF /* Build configuration list for PBXProject "GoldWars" */;
@ -370,7 +322,6 @@
targets = (
110360CE244B101A008610AF /* GoldWars */,
110360E8244B101B008610AF /* GoldWarsTests */,
110360F3244B101B008610AF /* GoldWarsUITests */,
);
};
/* End PBXProject section */
@ -394,13 +345,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
110360F2244B101B008610AF /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@ -414,6 +358,7 @@
9E78ACBE245CC9C000526FF7 /* AtkBoostSkillComponent.swift in Sources */,
9E78ACC4245CCA3600526FF7 /* SpySkillComponent.swift in Sources */,
9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */,
9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */,
110360D9244B101A008610AF /* GameScene.swift in Sources */,
116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */,
3EBD242E245D9332003CECE7 /* Team.swift in Sources */,
@ -447,14 +392,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
110360F0244B101B008610AF /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
110360F9244B101B008610AF /* GoldWarsUITests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
@ -463,11 +400,6 @@
target = 110360CE244B101A008610AF /* GoldWars */;
targetProxy = 110360EA244B101B008610AF /* PBXContainerItemProxy */;
};
110360F6244B101B008610AF /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 110360CE244B101A008610AF /* GoldWars */;
targetProxy = 110360F5244B101B008610AF /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
@ -696,44 +628,6 @@
};
name = Release;
};
11036104244B101B008610AF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = GoldWarsUITests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.hft.stuttgart.GoldWarsUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = GoldWars;
};
name = Debug;
};
11036105244B101B008610AF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = GoldWarsUITests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.hft.stuttgart.GoldWarsUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = GoldWars;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
@ -764,15 +658,6 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
11036103244B101B008610AF /* Build configuration list for PBXNativeTarget "GoldWarsUITests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
11036104244B101B008610AF /* Debug */,
11036105244B101B008610AF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 110360C7244B101A008610AF /* Project object */;

View File

@ -0,0 +1,31 @@
//
// AttackActionComponent.swift
// GoldWars
//
// Created by Niko Jochim on 03.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import GameplayKit
class AttackActionComponent : GKComponent {
init(unitCount: Int, adjacencyList: Array<Base>, position: CGPoint) {
super.init()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func action() {
}
}

View File

@ -61,7 +61,6 @@ class EntityManager {
}
func remove(_ entity: GKEntity) {
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode {
spriteNode.removeFromParent()
@ -88,7 +87,11 @@ class EntityManager {
}
}
return nil
}
}
func getBasesByTeam(for team: Team) -> Set<Base> {
return entities.filter{$0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.team == team } as! Set<Base>
}
func getBackground() -> GKEntity? {
return entities.filter{$0 is Background}[0]

View File

@ -12,6 +12,9 @@ import GameplayKit
class GameScene: SKScene{
var entityManager: EntityManager!
var isMoveTouch = false
var currentDraggedBasePos = CGPoint()
var currentDraggedBase : Base?
override func sceneDidLoad() {
entityManager = EntityManager(scene: self)
@ -20,52 +23,95 @@ class GameScene: SKScene{
initMap()
}
func initMap() {
MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {
return
}
let touchLocation = touch.location(in: self)
for entity in entityManager.entities {
if !isMoveTouch {
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
for entity in entityManager.entities {
if entityManager.isModal && entity.isMember(of: Modal.self) {
entityManager.remove(entity)
for child in self.children {
if(child.name != "fire"){
child.alpha = 1
}
}
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
}
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
spriteNode?.touchesBegan(touches, with: event)
if !entityManager.isModal {
if entityManager.isModal && entity.isMember(of: Modal.self) {
entityManager.remove(entity)
for child in self.children {
if(child.name != "fire"){
child.alpha = 0.3
child.alpha = 1
}
}
entityManager.add(Modal(modaltype: .BaseDetails,
base: entity as! Base,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2)))
}
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)))
}
}
}
}
else {
isMoveTouch = false
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {
return
}
let touchLocation = touch.location(in: self)
let bases = entityManager.getBasesByTeam(for: .team1)
for base in bases {
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
if !isMoveTouch {
currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position
currentDraggedBase = base
}
isMoveTouch = true
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
base.component(ofType: TeamComponent.self)?.fire.position = touchLocation
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) {
entityManager.getBackground()?.update(deltaTime: currentTime)

View File

@ -1,43 +0,0 @@
//
// GoldWarsUITests.swift
// GoldWarsUITests
//
// Created by Aldin Duraki on 18.04.20.
// Copyright © 2020 SP2. All rights reserved.
//
import XCTest
class GoldWarsUITests: XCTestCase {
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false
// In UI tests its important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testLaunchPerformance() {
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) {
// This measures how long it takes to launch your application.
measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) {
XCUIApplication().launch()
}
}
}
}

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>