Merge branch '60-global-accessible-entitymanager'

Conflicts:
	GoldWars/GoldWars/Scenes/GameScene.swift
This commit is contained in:
Aldin Duraki 2020-05-17 21:43:41 +02:00
commit 69e41a9cd3
23 changed files with 222 additions and 49 deletions

8
GoldWars/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

2
GoldWars/.idea/GoldWars.iml generated Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="AppCode" type="CIDR_MODULE" version="4" />

6
GoldWars/.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>

8
GoldWars/.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/GoldWars.iml" filepath="$PROJECT_DIR$/.idea/GoldWars.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="GoldWars" type="AppleRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="GoldWars" TARGET_NAME="GoldWars" CONFIG_NAME="Debug" SCHEME_NAME="GoldWars" IS_LOCATION_SIMULATION_ALLOWED="true" APPLICATION_LANGUAGE="IDELaunchSchemeLanguageUseSystemLanguage" APPLICATION_REGION="" RUN_TARGET_PROJECT_NAME="GoldWars" RUN_TARGET_NAME="GoldWars" MAKE_ACTIVE="TRUE" SHOULD_DEBUG_EXTENSIONS="false">
<EXTENSION ID="org.jetbrains.appcode.reveal.RevealRunConfigurationExtension">
<REVEAL_SETTINGS autoInject="false" autoInstall="true" askToEnableAutoInstall="true" />
</EXTENSION>
<embedded_app_extension_list />
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>

6
GoldWars/.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

4
GoldWars/.idea/xcode.xml generated Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="XcodeMetaData" PROJECT_FILE="$PROJECT_DIR$/GoldWars.xcodeproj" />
</project>

View File

@ -45,6 +45,8 @@
9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC7E48A2461FBF700396BCD /* SliderNode.swift */; };
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; };
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; };
9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */; };
9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */; };
AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocol.swift */; };
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */; };
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759F245DEC0500671525 /* MapFactory.swift */; };
@ -113,6 +115,8 @@
9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; };
9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; };
9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoEntity.swift; sourceTree = "<group>"; };
9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoComponent.swift; sourceTree = "<group>"; };
AB1D759A245DD18100671525 /* MapProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocol.swift; sourceTree = "<group>"; };
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = "<group>"; };
AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = "<group>"; };
@ -207,6 +211,7 @@
116060F4245C56EA004E5A36 /* Components */ = {
isa = PBXGroup;
children = (
9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */,
9E174C81245DD81D00209FF0 /* ButtonNode.swift */,
9EA3ABE8245C6DAA006BC61D /* DefaultBaseComponent.swift */,
9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */,
@ -229,6 +234,7 @@
116060F5245C5709004E5A36 /* Entities */ = {
isa = PBXGroup;
children = (
9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */,
ABA03D9F244BD54F00A66916 /* Base.swift */,
9EC86B9E245C88A300796EF3 /* Modal.swift */,
116060F6245C57D2004E5A36 /* EntityManager.swift */,
@ -415,6 +421,7 @@
3EBD242E245D9332003CECE7 /* Team.swift in Sources */,
9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */,
9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */,
9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */,
11738A3B24508F68004426F1 /* Unit.swift in Sources */,
9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */,
AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */,
@ -434,6 +441,7 @@
C064E9AC246C151F0022B228 /* Label.swift in Sources */,
9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */,
9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */,
9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */,
9E174C84245DD8CE00209FF0 /* Button.swift in Sources */,
110360DB244B101A008610AF /* GameViewController.swift in Sources */,
2086465C2461B66200817C23 /* TimerComponent.swift in Sources */,

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "logo_kante.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "logo_kante-1.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "logo_kante-2.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "logo_no_background.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "logo_no_background-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "logo_no_background-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -0,0 +1,45 @@
//
// SpinningLogoComponent.swift
// GoldWars
//
// Created by Niko Jochim on 15.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import GameKit
class SpinningLogoComponent: GKComponent{
var node : SK3DNode
init(position: CGPoint) {
let scnScene: SCNScene = {
let scnScene = SCNScene()
let cylinder = SCNCylinder(radius: 250, height: 50)
let logoMaterial = SCNMaterial()
let colorMaterial = SCNMaterial()
logoMaterial.diffuse.contents = UIImage(named: "logo_no_background")
colorMaterial.diffuse.contents = UIColor(red: 0.852, green: 0.649, blue: 0.123, alpha: 1)
cylinder.materials = [colorMaterial,logoMaterial,logoMaterial]
let cylinderNode = SCNNode(geometry: cylinder)
cylinderNode.eulerAngles = SCNVector3(x: Float(CGFloat.pi / 2), y: 0, z: Float(CGFloat.pi / 2))
let action = SCNAction.rotateBy(x: CGFloat(GLKMathDegreesToRadians(360)), y:0 , z: 0, duration: 8)
let forever = SCNAction.repeatForever(action)
cylinderNode.runAction(forever)
scnScene.rootNode.addChildNode(cylinderNode)
return scnScene
}()
self.node = SK3DNode(viewportSize: CGSize(width: 250, height: 250))
node.scnScene = scnScene
node.position = position
super.init()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@ -12,15 +12,22 @@ import GameKit
class EntityManager {
static let sharedInstance = EntityManager()
var entities = Set<GKEntity>()
let scene: SKScene
var scene: SKScene
var isModal: Bool
init(scene: SKScene) {
self.scene = scene
private init() {
isModal = false
scene = SKScene.init()
}
func setScene(scene: SKScene){
self.scene = scene
}
func add(_ entity: GKEntity) {
entities.insert(entity)
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode {
@ -68,6 +75,9 @@ class EntityManager {
if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode {
scene.addChild(labelNode)
}
if let node = entity.component(ofType: SpinningLogoComponent.self)?.node {
scene.addChild(node)
}
}
func remove(_ entity: GKEntity) {
@ -100,9 +110,9 @@ class EntityManager {
if base.changeOwnership {
base.addComponent(TeamComponent(
team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team,
player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player,
position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team,
player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player,
position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
)
)
base.changeOwnership = false

View File

@ -0,0 +1,22 @@
//
// SpinningLogoEntity.swift
// GoldWars
//
// Created by Niko Jochim on 15.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import GameplayKit
class SpinningLogoEntity: GKEntity {
init(position: CGPoint) {
super.init()
self.addComponent(SpinningLogoComponent(position: position))
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@ -11,7 +11,7 @@ import SpriteKit
import GameplayKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

View File

@ -12,15 +12,14 @@ import GameKit
class GameScene: SKScene{
var entityManager: EntityManager!
var isMoveTouch = false
var currentDraggedBasePos = CGPoint()
var currentDraggedBase : Base?
override func sceneDidLoad() {
entityManager = EntityManager(scene: self)
entityManager.add(HUD(size: self.size))
entityManager.add(Background(size: self.size))
EntityManager.sharedInstance.setScene(scene: self)
EntityManager.sharedInstance.add(HUD(size: self.size))
EntityManager.sharedInstance.add(Background(size: self.size))
initMap()
}
@ -45,14 +44,14 @@ class GameScene: SKScene{
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
// TODO: change interaction based on collision instead of touchlocation
if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){
entityManager.add(Modal(modaltype: .BaseAttack,
if !(EntityManager.sharedInstance.getTeamByBase(base: currentDraggedBase!) == EntityManager.sharedInstance.getTeamByBase(base: base)){
EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack,
base: currentDraggedBase!,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
entityManager: entityManager, gameScene: self))
entityManager.update((currentDraggedBase?.doPlayerMoveTypeToBase(base: base, playerMoveType: PlayerMoveType.AtkMove, units: 100))!)
entityManager: EntityManager.sharedInstance, gameScene: self))
EntityManager.sharedInstance.update((currentDraggedBase?.attackBase(base: base, units: 100))!)
}else {
entityManager.add(Modal(modaltype: .BaseAttack,
EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack,
base: currentDraggedBase!,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
entityManager: entityManager, gameScene: self))
@ -63,21 +62,21 @@ class GameScene: SKScene{
}
}
else {
for entity in entityManager.entities {
for entity in EntityManager.sharedInstance.entities {
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
if atPoint(touchLocation) == spriteNode && !EntityManager.sharedInstance.isModal {
spriteNode?.touchesBegan(touches, with: event)
if !entityManager.isModal {
if !EntityManager.sharedInstance.isModal {
for child in self.children {
if(child.name != "fire"){
child.alpha = 0.3
}
}
entityManager.add(Modal(modaltype: .BaseDetails,
EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails,
base: entity as! Base,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
entityManager: entityManager, gameScene: self))
entityManager: EntityManager.sharedInstance, gameScene: self))
}
}
}
@ -97,12 +96,12 @@ class GameScene: SKScene{
}
}
for e in entityManager.entities{
for e in EntityManager.sharedInstance.entities{
if let body = e.component(ofType: ModalContentComponent.self)?.body{
body.text = "Schicke \( ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)) Einheiten "
} }
let bases = entityManager.getBasesByPlayer(for: GKLocalPlayer.local)
let bases = EntityManager.sharedInstance.getBasesByPlayer(for: GKLocalPlayer.local)
for base in bases {
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
@ -126,7 +125,7 @@ class GameScene: SKScene{
}
override func update(_ currentTime: TimeInterval) {
entityManager.getBackground()?.update(deltaTime: currentTime)
entityManager.getHUD()?.component(ofType: TimerComponent.self)?.update()
EntityManager.sharedInstance.getBackground()?.update(deltaTime: currentTime)
EntityManager.sharedInstance.getHUD()?.component(ofType: TimerComponent.self)?.update()
}
}

View File

@ -7,16 +7,14 @@
//
import SpriteKit
import SceneKit
class MenuScene: SKScene {
var entityManager: EntityManager!
override func sceneDidLoad() {
entityManager = EntityManager(scene: self)
EntityManager.sharedInstance.setScene(scene: self)
let midX = self.size.width / 2
let midY = self.size.height / 2
entityManager.add(Button(name: "startGameButton",
EntityManager.sharedInstance.add(Button(name: "startGameButton",
iconName: "",
text: "Start Game",
position: CGPoint(x: midX, y: midY),
@ -25,30 +23,31 @@ class MenuScene: SKScene {
self.loadScene(scene: GameScene(size: self.size))
SoundManager.sharedInstance.stopMenuMusic()
} else {
MatchmakingHelper.sharedInstance.presentMatchmaker(scene: self)
MatchmakingHelper.sharedInstance.presentMatchmaker(scene: self)
}
}))
entityManager.add(Button(name: "settingsButton",
}))
EntityManager.sharedInstance.add(Button(name: "settingsButton",
iconName: "",
text: "Settings",
position: CGPoint(x: midX, y: midY - 80 ),
onButtonPress: {
self.loadScene(scene: SettingsScene(size: self.size))
}))
entityManager.add(Background(size: self.size))
EntityManager.sharedInstance.add(Background(size: self.size))
EntityManager.sharedInstance.add(SpinningLogoEntity(position: CGPoint(x: midX, y: midY + 200)))
if SoundManager.sharedInstance.isMusicPlaying == false && SoundManager.sharedInstance.isMusicEnabled == true {
SoundManager.sharedInstance.startMenuMusic()
}
}
func loadScene(scene: SKScene) {
let transition = SKTransition.flipVertical(withDuration: 0.5)
self.view?.presentScene(scene, transition: transition)
}
override func update(_ currentTime: TimeInterval) {
entityManager.getBackground()!.update(deltaTime: currentTime)
entityManager.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterHelper.isAuthenticated
EntityManager.sharedInstance.getBackground()!.update(deltaTime: currentTime)
EntityManager.sharedInstance.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterHelper.isAuthenticated
}
}

View File

@ -9,21 +9,20 @@
import SpriteKit
class SettingsScene: SKScene {
var entityManager: EntityManager!
override func sceneDidLoad() {
entityManager = EntityManager(scene: self)
EntityManager.sharedInstance.setScene(scene: self)
let positionX = self.size.width * 0.1
let positionY = self.size.height * 0.05
entityManager.add(Button(name: "backToMenuScene",
EntityManager.sharedInstance.add(Button(name: "backToMenuScene",
iconName: "",
text: "Back",
position: CGPoint(x: positionX, y: positionY),
onButtonPress: {
self.loadScene(scene: MenuScene(size: self.size))
}))
entityManager.add(Button(name: "StopMenuMusic",
EntityManager.sharedInstance.add(Button(name: "StopMenuMusic",
iconName: "",
text: "ON/OFF",
position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2),
@ -36,7 +35,7 @@ class SettingsScene: SKScene {
SoundManager.sharedInstance.startMenuMusic()
}
}))
entityManager.add(Button(name: "StopMovingBackground",
EntityManager.sharedInstance.add(Button(name: "StopMovingBackground",
iconName: "",
text: "MOVE/STOP",
position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2 - 100),
@ -47,7 +46,7 @@ class SettingsScene: SKScene {
BackgroundComponent.isMovingBackgroundEnabled = true
}
}))
entityManager.add(Label(fontnamed: "Courier-Bold",
EntityManager.sharedInstance.add(Label(fontnamed: "Courier-Bold",
name: "SettingsLabel",
text: "Settings",
fontSize: 200.0,
@ -58,7 +57,7 @@ class SettingsScene: SKScene {
isAnimationEnabled: true,
isAnimationInfinite: true)
)
entityManager.add(Label(fontnamed: "Courier-Bold",
EntityManager.sharedInstance.add(Label(fontnamed: "Courier-Bold",
name: "LabelMusic",
text: "Music", fontSize: 50.0,
fontColor: .black,
@ -68,7 +67,7 @@ class SettingsScene: SKScene {
isAnimationEnabled: true,
isAnimationInfinite: false)
)
entityManager.add(Label(fontnamed: "Courier-Bold",
EntityManager.sharedInstance.add(Label(fontnamed: "Courier-Bold",
name: "LabelBackground",
text: "Background",
fontSize: 50.0,
@ -79,7 +78,7 @@ class SettingsScene: SKScene {
isAnimationEnabled: true,
isAnimationInfinite: false)
)
entityManager.add(Background(size: self.size))
EntityManager.sharedInstance.add(Background(size: self.size))
}
func loadScene(scene: SKScene) {
@ -88,7 +87,7 @@ class SettingsScene: SKScene {
}
override func update(_ currentTime: TimeInterval) {
entityManager.getBackground()!.update(deltaTime: currentTime)
EntityManager.sharedInstance.getBackground()!.update(deltaTime: currentTime)
}
}