diff --git a/Pacman3D-iOS.xcodeproj/project.pbxproj b/Pacman3D-iOS.xcodeproj/project.pbxproj index 41a9bbe00b4cde4b7c7e386b02872fefee2f4044..85c89ba3efa3832622f36a74372d62f9294a63e9 100644 --- a/Pacman3D-iOS.xcodeproj/project.pbxproj +++ b/Pacman3D-iOS.xcodeproj/project.pbxproj @@ -8,6 +8,10 @@ /* Begin PBXBuildFile section */ F6090F531F1AA9270003F688 /* pause.png in Resources */ = {isa = PBXBuildFile; fileRef = F6090F521F1AA9270003F688 /* pause.png */; }; + F6090F561F1AAEB40003F688 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6090F551F1AAEB40003F688 /* MainViewController.swift */; }; + F6090F5A1F1AAEED0003F688 /* pacman_beginning.wav in Resources */ = {isa = PBXBuildFile; fileRef = F6090F571F1AAEED0003F688 /* pacman_beginning.wav */; }; + F6090F5B1F1AAEED0003F688 /* pacman_chomp.wav in Resources */ = {isa = PBXBuildFile; fileRef = F6090F581F1AAEED0003F688 /* pacman_chomp.wav */; }; + F6090F5C1F1AAEED0003F688 /* pacman_death.wav in Resources */ = {isa = PBXBuildFile; fileRef = F6090F591F1AAEED0003F688 /* pacman_death.wav */; }; F6621DF41F12B09800F9E486 /* TouchInputHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6621DF31F12B09800F9E486 /* TouchInputHandler.swift */; }; F6621DF61F12B82200F9E486 /* MotionInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6621DF51F12B82200F9E486 /* MotionInput.swift */; }; F6BEB8071EF7F99B00EDAA66 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6BEB8061EF7F99B00EDAA66 /* AppDelegate.swift */; }; @@ -49,6 +53,10 @@ /* Begin PBXFileReference section */ F6090F521F1AA9270003F688 /* pause.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pause.png; sourceTree = "<group>"; }; + F6090F551F1AAEB40003F688 /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; }; + F6090F571F1AAEED0003F688 /* pacman_beginning.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = pacman_beginning.wav; sourceTree = "<group>"; }; + F6090F581F1AAEED0003F688 /* pacman_chomp.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = pacman_chomp.wav; sourceTree = "<group>"; }; + F6090F591F1AAEED0003F688 /* pacman_death.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = pacman_death.wav; sourceTree = "<group>"; }; F6621DF31F12B09800F9E486 /* TouchInputHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TouchInputHandler.swift; sourceTree = "<group>"; }; F6621DF51F12B82200F9E486 /* MotionInput.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MotionInput.swift; sourceTree = "<group>"; }; F6BEB8031EF7F99B00EDAA66 /* Pacman3D-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Pacman3D-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -105,6 +113,9 @@ F6090F541F1AA92D0003F688 /* Resources */ = { isa = PBXGroup; children = ( + F6090F571F1AAEED0003F688 /* pacman_beginning.wav */, + F6090F581F1AAEED0003F688 /* pacman_chomp.wav */, + F6090F591F1AAEED0003F688 /* pacman_death.wav */, F6FEE71A1EF8135200C1DE35 /* level.plv */, F6E39CE11F1A56E500A3E7D1 /* wall.jpg */, F6E39CE31F1A583B00A3E7D1 /* floor.jpg */, @@ -140,6 +151,7 @@ F6FEE7141EF80AB900C1DE35 /* Level */, F6FEE7191EF80C1900C1DE35 /* Uilts */, F6BEB8061EF7F99B00EDAA66 /* AppDelegate.swift */, + F6090F551F1AAEB40003F688 /* MainViewController.swift */, F6BEB80A1EF7F99B00EDAA66 /* GameViewController.swift */, F6621DF31F12B09800F9E486 /* TouchInputHandler.swift */, F6621DF51F12B82200F9E486 /* MotionInput.swift */, @@ -301,8 +313,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + F6090F5B1F1AAEED0003F688 /* pacman_chomp.wav in Resources */, + F6090F5C1F1AAEED0003F688 /* pacman_death.wav in Resources */, F6BEB8091EF7F99B00EDAA66 /* art.scnassets in Resources */, F6E39CE41F1A583B00A3E7D1 /* floor.jpg in Resources */, + F6090F5A1F1AAEED0003F688 /* pacman_beginning.wav in Resources */, F6BEB8131EF7F99B00EDAA66 /* LaunchScreen.storyboard in Resources */, F6BEB8101EF7F99B00EDAA66 /* Assets.xcassets in Resources */, F6BEB80E1EF7F99B00EDAA66 /* Main.storyboard in Resources */, @@ -335,6 +350,7 @@ buildActionMask = 2147483647; files = ( F6621DF61F12B82200F9E486 /* MotionInput.swift in Sources */, + F6090F561F1AAEB40003F688 /* MainViewController.swift in Sources */, F6E4AE451F0CF1DF004BFDBF /* Direction.swift in Sources */, F6FEE7181EF80C1500C1DE35 /* StreamReader.swift in Sources */, F6E39CEC1F1A7D5500A3E7D1 /* BorderButton.swift in Sources */, diff --git a/Pacman3D-iOS/Base.lproj/Main.storyboard b/Pacman3D-iOS/Base.lproj/Main.storyboard index 267bae163667b2534e8ef15a4355bb374df3cc46..d6bf6a1356cfd3dda1266e7375ddc7c652d2151e 100644 --- a/Pacman3D-iOS/Base.lproj/Main.storyboard +++ b/Pacman3D-iOS/Base.lproj/Main.storyboard @@ -9,10 +9,10 @@ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> </dependencies> <scenes> - <!--View Controller--> + <!--Main View Controller--> <scene sceneID="p6t-FQ-akW"> <objects> - <viewController id="uj1-yy-esL" sceneMemberID="viewController"> + <viewController id="uj1-yy-esL" customClass="MainViewController" customModule="Pacman3D_iOS" customModuleProvider="target" sceneMemberID="viewController"> <layoutGuides> <viewControllerLayoutGuide type="top" id="YLp-lV-ETO"/> <viewControllerLayoutGuide type="bottom" id="h1R-Z6-Vqf"/> diff --git a/Pacman3D-iOS/GameViewController.swift b/Pacman3D-iOS/GameViewController.swift index dc91c2a9305b46ddbe9ef77d1b0411a3083bbd57..56faf161da97bc8a3a5386f82fe4d64617297550 100644 --- a/Pacman3D-iOS/GameViewController.swift +++ b/Pacman3D-iOS/GameViewController.swift @@ -11,6 +11,7 @@ import QuartzCore import SceneKit import SpriteKit import CoreMotion +import AVFoundation class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDelegate, SCNSceneRendererDelegate, PlayerDelegate { @@ -40,6 +41,10 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe var player: Player! var monsters: [Monster]! + // MARK: - Sounds + var soundChomp: AVAudioPlayer? + var soundDeath: AVAudioPlayer? + // MARK: - Input Handler private var touchInputHandler: TouchInputHandler! private var motionInput: MotionInput? @@ -47,6 +52,15 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe override func viewDidLoad() { super.viewDidLoad() + if let url = Bundle.main.url(forResource: "pacman_chomp", withExtension: "wav") { + soundChomp = try? AVAudioPlayer(contentsOf: url) + soundChomp?.prepareToPlay() + } + if let url = Bundle.main.url(forResource: "pacman_death", withExtension: "wav") { + soundDeath = try? AVAudioPlayer(contentsOf: url) + soundDeath?.prepareToPlay() + } + monsters = [] level = Level(named: "level") @@ -158,6 +172,8 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe let monster = contact.nodeA.name ?? "" == "Monster" ? contact.nodeA : contact.nodeB monster.removeFromParentNode() + soundDeath?.play() + for m in monsters { if let n = m.node { if n == monster { @@ -176,6 +192,7 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe func player(_ player: Player, scoreDidUpdate score: Int) { pointsLabel.text = "\(player.points) Punkte" + soundChomp?.play() } func player(_ player: Player, didCollectScoreAt position: (x: Int, z: Int)) { diff --git a/Pacman3D-iOS/MainViewController.swift b/Pacman3D-iOS/MainViewController.swift new file mode 100644 index 0000000000000000000000000000000000000000..18df7771234a5906bcbf97c5de3762db76514561 --- /dev/null +++ b/Pacman3D-iOS/MainViewController.swift @@ -0,0 +1,50 @@ +// +// MainViewController.swift +// Pacman3D-iOS +// +// Created by Tobias on 15.07.17. +// Copyright © 2017 Tobias. All rights reserved. +// + +import UIKit +import AVFoundation + +class MainViewController: UIViewController { + + var player: AVAudioPlayer? + + override func viewDidLoad() { + super.viewDidLoad() + + if let url = Bundle.main.url(forResource: "pacman_beginning", withExtension: "wav") { + player = try? AVAudioPlayer(contentsOf: url) + player?.numberOfLoops = -1 + player?.prepareToPlay() + } + } + + override func viewDidAppear(_ animated: Bool) { + player?.play() + } + + override func viewWillDisappear(_ animated: Bool) { + player?.stop() + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destinationViewController. + // Pass the selected object to the new view controller. + } + */ + +} diff --git a/Pacman3D-iOS/pacman_beginning.wav b/Pacman3D-iOS/pacman_beginning.wav new file mode 100644 index 0000000000000000000000000000000000000000..5303fb1048f96f5c291067c4a8bbeac3acc6f0c6 Binary files /dev/null and b/Pacman3D-iOS/pacman_beginning.wav differ diff --git a/Pacman3D-iOS/pacman_chomp.wav b/Pacman3D-iOS/pacman_chomp.wav new file mode 100644 index 0000000000000000000000000000000000000000..993b08ead95aa8b78dc270aefdca7edb26cf26b8 Binary files /dev/null and b/Pacman3D-iOS/pacman_chomp.wav differ diff --git a/Pacman3D-iOS/pacman_death.wav b/Pacman3D-iOS/pacman_death.wav new file mode 100644 index 0000000000000000000000000000000000000000..153019e9c717bbe27c5486448a85f4654c7e4bd5 Binary files /dev/null and b/Pacman3D-iOS/pacman_death.wav differ