diff --git a/Pacman3D-iOS.xcodeproj/project.pbxproj b/Pacman3D-iOS.xcodeproj/project.pbxproj index f61ba547a1aa016ebae7d6edba63996757b6f6bc..eac038b3a29accda43547801c4f2cd93c1ffdcd1 100644 --- a/Pacman3D-iOS.xcodeproj/project.pbxproj +++ b/Pacman3D-iOS.xcodeproj/project.pbxproj @@ -17,12 +17,15 @@ F6BEB8131EF7F99B00EDAA66 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F6BEB8111EF7F99B00EDAA66 /* LaunchScreen.storyboard */; }; F6BEB81E1EF7F99B00EDAA66 /* Pacman3D_iOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6BEB81D1EF7F99B00EDAA66 /* Pacman3D_iOSTests.swift */; }; F6BEB8291EF7F99C00EDAA66 /* Pacman3D_iOSUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6BEB8281EF7F99C00EDAA66 /* Pacman3D_iOSUITests.swift */; }; + F6E39CE21F1A56E500A3E7D1 /* wall.jpg in Resources */ = {isa = PBXBuildFile; fileRef = F6E39CE11F1A56E500A3E7D1 /* wall.jpg */; }; + F6E39CE41F1A583B00A3E7D1 /* floor.jpg in Resources */ = {isa = PBXBuildFile; fileRef = F6E39CE31F1A583B00A3E7D1 /* floor.jpg */; }; + F6E39CEA1F1A7C2C00A3E7D1 /* background.jpg in Resources */ = {isa = PBXBuildFile; fileRef = F6E39CE91F1A7C2C00A3E7D1 /* background.jpg */; }; + F6E39CEC1F1A7D5500A3E7D1 /* BorderButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6E39CEB1F1A7D5500A3E7D1 /* BorderButton.swift */; }; F6E4AE431F0CEC6C004BFDBF /* Monster.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6E4AE421F0CEC6C004BFDBF /* Monster.swift */; }; F6E4AE451F0CF1DF004BFDBF /* Direction.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6E4AE441F0CF1DF004BFDBF /* Direction.swift */; }; F6FEE7161EF80AD500C1DE35 /* Level.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6FEE7151EF80AD500C1DE35 /* Level.swift */; }; F6FEE7181EF80C1500C1DE35 /* StreamReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6FEE7171EF80C1500C1DE35 /* StreamReader.swift */; }; F6FEE71B1EF8135200C1DE35 /* level.plv in Resources */ = {isa = PBXBuildFile; fileRef = F6FEE71A1EF8135200C1DE35 /* level.plv */; }; - F6FEE71F1EF8379600C1DE35 /* run.png in Resources */ = {isa = PBXBuildFile; fileRef = F6FEE71E1EF8379600C1DE35 /* run.png */; }; F6FEE7231EF83DAF00C1DE35 /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6FEE7221EF83DAF00C1DE35 /* Player.swift */; }; /* End PBXBuildFile section */ @@ -60,12 +63,15 @@ F6BEB8241EF7F99C00EDAA66 /* Pacman3D-iOSUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Pacman3D-iOSUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; F6BEB8281EF7F99C00EDAA66 /* Pacman3D_iOSUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pacman3D_iOSUITests.swift; sourceTree = "<group>"; }; F6BEB82A1EF7F99C00EDAA66 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; + F6E39CE11F1A56E500A3E7D1 /* wall.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = wall.jpg; sourceTree = "<group>"; }; + F6E39CE31F1A583B00A3E7D1 /* floor.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = floor.jpg; sourceTree = "<group>"; }; + F6E39CE91F1A7C2C00A3E7D1 /* background.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = background.jpg; sourceTree = "<group>"; }; + F6E39CEB1F1A7D5500A3E7D1 /* BorderButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BorderButton.swift; sourceTree = "<group>"; }; F6E4AE421F0CEC6C004BFDBF /* Monster.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Monster.swift; sourceTree = "<group>"; }; F6E4AE441F0CF1DF004BFDBF /* Direction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Direction.swift; sourceTree = "<group>"; }; F6FEE7151EF80AD500C1DE35 /* Level.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Level.swift; sourceTree = "<group>"; }; F6FEE7171EF80C1500C1DE35 /* StreamReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StreamReader.swift; sourceTree = "<group>"; }; F6FEE71A1EF8135200C1DE35 /* level.plv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = level.plv; sourceTree = "<group>"; }; - F6FEE71E1EF8379600C1DE35 /* run.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = run.png; sourceTree = "<group>"; }; F6FEE7221EF83DAF00C1DE35 /* Player.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Player.swift; sourceTree = "<group>"; }; /* End PBXFileReference section */ @@ -123,13 +129,16 @@ F6BEB80A1EF7F99B00EDAA66 /* GameViewController.swift */, F6621DF31F12B09800F9E486 /* TouchInputHandler.swift */, F6621DF51F12B82200F9E486 /* MotionInput.swift */, + F6E39CEB1F1A7D5500A3E7D1 /* BorderButton.swift */, F6BEB8081EF7F99B00EDAA66 /* art.scnassets */, F6BEB80F1EF7F99B00EDAA66 /* Assets.xcassets */, F6BEB80C1EF7F99B00EDAA66 /* Main.storyboard */, F6BEB8111EF7F99B00EDAA66 /* LaunchScreen.storyboard */, F6BEB8141EF7F99B00EDAA66 /* Info.plist */, F6FEE71A1EF8135200C1DE35 /* level.plv */, - F6FEE71E1EF8379600C1DE35 /* run.png */, + F6E39CE11F1A56E500A3E7D1 /* wall.jpg */, + F6E39CE31F1A583B00A3E7D1 /* floor.jpg */, + F6E39CE91F1A7C2C00A3E7D1 /* background.jpg */, ); path = "Pacman3D-iOS"; sourceTree = "<group>"; @@ -282,11 +291,13 @@ buildActionMask = 2147483647; files = ( F6BEB8091EF7F99B00EDAA66 /* art.scnassets in Resources */, - F6FEE71F1EF8379600C1DE35 /* run.png in Resources */, + F6E39CE41F1A583B00A3E7D1 /* floor.jpg in Resources */, F6BEB8131EF7F99B00EDAA66 /* LaunchScreen.storyboard in Resources */, F6BEB8101EF7F99B00EDAA66 /* Assets.xcassets in Resources */, F6BEB80E1EF7F99B00EDAA66 /* Main.storyboard in Resources */, F6FEE71B1EF8135200C1DE35 /* level.plv in Resources */, + F6E39CEA1F1A7C2C00A3E7D1 /* background.jpg in Resources */, + F6E39CE21F1A56E500A3E7D1 /* wall.jpg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -314,6 +325,7 @@ F6621DF61F12B82200F9E486 /* MotionInput.swift in Sources */, F6E4AE451F0CF1DF004BFDBF /* Direction.swift in Sources */, F6FEE7181EF80C1500C1DE35 /* StreamReader.swift in Sources */, + F6E39CEC1F1A7D5500A3E7D1 /* BorderButton.swift in Sources */, F6FEE7161EF80AD500C1DE35 /* Level.swift in Sources */, F6621DF41F12B09800F9E486 /* TouchInputHandler.swift in Sources */, F6BEB80B1EF7F99B00EDAA66 /* GameViewController.swift in Sources */, diff --git a/Pacman3D-iOS/Assets.xcassets/Contents.json b/Pacman3D-iOS/Assets.xcassets/Contents.json new file mode 100644 index 0000000000000000000000000000000000000000..da4a164c918651cdd1e11dca5cc62c333f097601 --- /dev/null +++ b/Pacman3D-iOS/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Pacman3D-iOS/Assets.xcassets/LaunchScreen.imageset/Contents.json b/Pacman3D-iOS/Assets.xcassets/LaunchScreen.imageset/Contents.json new file mode 100644 index 0000000000000000000000000000000000000000..cc9d3fc4e2ceaba7200c95d739651c7a4b50c9bc --- /dev/null +++ b/Pacman3D-iOS/Assets.xcassets/LaunchScreen.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "LaunchScreen.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Pacman3D-iOS/Assets.xcassets/LaunchScreen.imageset/LaunchScreen.png b/Pacman3D-iOS/Assets.xcassets/LaunchScreen.imageset/LaunchScreen.png new file mode 100644 index 0000000000000000000000000000000000000000..8e2a12ba3cbafd15eaa519a055f22d5032a7bdb5 Binary files /dev/null and b/Pacman3D-iOS/Assets.xcassets/LaunchScreen.imageset/LaunchScreen.png differ diff --git a/Pacman3D-iOS/Base.lproj/Main.storyboard b/Pacman3D-iOS/Base.lproj/Main.storyboard index a8489504c3f465dc5551a8d50b26eedf4fe9b3d1..267bae163667b2534e8ef15a4355bb374df3cc46 100644 --- a/Pacman3D-iOS/Base.lproj/Main.storyboard +++ b/Pacman3D-iOS/Base.lproj/Main.storyboard @@ -1,20 +1,71 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BV1-FR-VrT"> +<?xml version="1.0" encoding="UTF-8"?> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="uj1-yy-esL"> + <device id="retina4_7" orientation="landscape"> + <adaptation id="fullscreen"/> + </device> <dependencies> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/> + <deployment identifier="iOS"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> </dependencies> <scenes> - <!--Game View Controller--> - <scene sceneID="tXr-a1-R10"> + <!--View Controller--> + <scene sceneID="p6t-FQ-akW"> <objects> - <viewController id="BV1-FR-VrT" customClass="GameViewController" customModuleProvider="target" sceneMemberID="viewController"> + <viewController id="uj1-yy-esL" sceneMemberID="viewController"> <layoutGuides> - <viewControllerLayoutGuide type="top" id="Cei-gA-s71"/> - <viewControllerLayoutGuide type="bottom" id="O1X-57-Ctf"/> + <viewControllerLayoutGuide type="top" id="YLp-lV-ETO"/> + <viewControllerLayoutGuide type="bottom" id="h1R-Z6-Vqf"/> </layoutGuides> + <view key="view" contentMode="scaleToFill" id="TCv-Se-adc"> + <rect key="frame" x="0.0" y="0.0" width="667" height="375"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <subviews> + <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="background.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="zYz-H3-5Ds"> + <rect key="frame" x="0.0" y="0.0" width="666" height="375"/> + </imageView> + <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RAb-CX-EkL" customClass="BorderButton" customModule="Pacman3D_iOS" customModuleProvider="target"> + <rect key="frame" x="233" y="240" width="200" height="42"/> + <color key="backgroundColor" red="0.96470588235294119" green="1" blue="0.14195293351715688" alpha="1" colorSpace="calibratedRGB"/> + <constraints> + <constraint firstAttribute="width" constant="200" id="BvE-zD-mzc"/> + <constraint firstAttribute="height" constant="42" id="oKh-NP-I52"/> + </constraints> + <fontDescription key="fontDescription" type="boldSystem" pointSize="15"/> + <state key="normal" title="Start"> + <color key="titleColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> + </state> + <userDefinedRuntimeAttributes> + <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius"> + <real key="value" value="10"/> + </userDefinedRuntimeAttribute> + </userDefinedRuntimeAttributes> + <connections> + <segue destination="BV1-FR-VrT" kind="presentation" modalTransitionStyle="flipHorizontal" id="Eun-P3-is3"/> + </connections> + </button> + </subviews> + <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> + <constraints> + <constraint firstItem="RAb-CX-EkL" firstAttribute="centerY" secondItem="TCv-Se-adc" secondAttribute="centerY" constant="73.5" id="2S4-Xb-Hwe"/> + <constraint firstItem="zYz-H3-5Ds" firstAttribute="leading" secondItem="TCv-Se-adc" secondAttribute="leading" id="4GM-1v-0v2"/> + <constraint firstItem="RAb-CX-EkL" firstAttribute="centerX" secondItem="TCv-Se-adc" secondAttribute="centerX" id="Oej-f7-YP9"/> + <constraint firstItem="zYz-H3-5Ds" firstAttribute="centerX" secondItem="RAb-CX-EkL" secondAttribute="centerX" id="cHc-Is-wG5"/> + <constraint firstItem="zYz-H3-5Ds" firstAttribute="bottom" secondItem="h1R-Z6-Vqf" secondAttribute="top" id="foo-ju-cTx"/> + <constraint firstItem="zYz-H3-5Ds" firstAttribute="centerY" secondItem="RAb-CX-EkL" secondAttribute="centerY" constant="-73.5" id="san-mB-ZVk"/> + </constraints> + </view> + </viewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="4f0-XF-f7U" userLabel="First Responder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="-780.35982008995506" y="55.200000000000003"/> + </scene> + <!--Game View Controller--> + <scene sceneID="tXr-a1-R10"> + <objects> + <viewController id="BV1-FR-VrT" customClass="GameViewController" customModule="Pacman3D_iOS" customModuleProvider="target" sceneMemberID="viewController"> <sceneKitView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="3se-qz-xqx"> - <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> + <rect key="frame" x="0.0" y="0.0" width="667" height="375"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> </sceneKitView> @@ -23,4 +74,7 @@ </objects> </scene> </scenes> + <resources> + <image name="background.jpg" width="799" height="449"/> + </resources> </document> diff --git a/Pacman3D-iOS/BorderButton.swift b/Pacman3D-iOS/BorderButton.swift new file mode 100644 index 0000000000000000000000000000000000000000..f97198a1a8eb80c44e0939e577bd9db2644c5308 --- /dev/null +++ b/Pacman3D-iOS/BorderButton.swift @@ -0,0 +1,36 @@ +// +// BorderButton.swift +// CookNow +// +// Created by Tobias on 21.06.17. +// Copyright © 2017 Tobias. All rights reserved. +// + +import UIKit + +class BorderButton: UIButton { + + @IBInspectable var borderColor: UIColor? + @IBInspectable var borderWidth: CGFloat = 0 + @IBInspectable var cornerRadius: CGFloat = 0 + + @IBInspectable var dashed: Bool = false + + override func awakeFromNib() { + self.layer.backgroundColor = self.backgroundColor?.cgColor + self.layer.borderColor = borderColor?.cgColor + + if !dashed { + self.layer.borderWidth = borderWidth + self.layer.cornerRadius = cornerRadius + } else { + let dashedBorder = CAShapeLayer() + dashedBorder.fillColor = self.backgroundColor?.cgColor + dashedBorder.strokeColor = borderColor?.cgColor + dashedBorder.lineDashPattern = [2, 2] + dashedBorder.frame = self.bounds + dashedBorder.path = UIBezierPath(rect: self.bounds).cgPath + self.layer.addSublayer(dashedBorder) + } + } +} diff --git a/Pacman3D-iOS/GameViewController.swift b/Pacman3D-iOS/GameViewController.swift index 81a76e88ad8ae336cedc93d03d0c83b3ae13b381..502f4038c92cd18add05176f059d2e4a54099181 100644 --- a/Pacman3D-iOS/GameViewController.swift +++ b/Pacman3D-iOS/GameViewController.swift @@ -26,9 +26,14 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe var pointsLabel: SKLabelNode! var lifeLabel: SKLabelNode! + var backButton: SKSpriteNode! + + var restartButton: SKLabelNode! // MARK: - Game Objects + let monsterCount = 6 + var player: Player! var monsters: [Monster] = [] @@ -60,21 +65,6 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe level.createLevelEnviroment(scene: scene) -// // create and add a light to the scene -// let lightNode = SCNNode() -// lightNode.light = SCNLight() -// lightNode.light!.type = .omni -// lightNode.position = SCNVector3(x: 0, y: 10, z: 10) -// scene.rootNode.addChildNode(lightNode) -// -// // create and add an ambient light to the scene -// let ambientLightNode = SCNNode() -// ambientLightNode.light = SCNLight() -// ambientLightNode.light!.type = .ambient -// ambientLightNode.light!.color = UIColor.darkGray -// scene.rootNode.addChildNode(ambientLightNode) - - // retrieve the SCNView let scnView = self.view as! SCNView scnView.delegate = self @@ -92,8 +82,15 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe // configure the view scnView.backgroundColor = UIColor.black + // Create overlay + if let view = self.view as? SCNView { + view.overlaySKScene = createOverlay() + } + // add a tap gesture recognizer touchInputHandler = TouchInputHandler(target: self, action: #selector(handleTap(_:))) + touchInputHandler.scene = (self.view as? SCNView)?.overlaySKScene + touchInputHandler.gameController = self scnView.addGestureRecognizer(touchInputHandler) self.motionInput = MotionInput(gameScene: self) @@ -119,16 +116,12 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe }) } - for _ in 1...10 { + for _ in 1...monsterCount { let postion = level.nextFreeSpace() let monster = Monster(position: SCNVector3(5 * postion.x, 1, 5 * postion.z), level: level, scene: scene) monster.addToScene(rootScene: self.scene) monsters.append(monster) } - - if let view = self.view as? SCNView { - view.overlaySKScene = createOverlay() - } } private var lastRotation: Float = 0 @@ -154,11 +147,12 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe lifeLabel.text = String(repeating: "♥️", count: player.life) } - pacman.position = SCNVector3(5, 2, 5) - // TODO Restart + let monster = contact.nodeA.name ?? "" == "Monster" ? contact.nodeA : contact.nodeB + monster.removeFromParentNode() - if player.life == 0 { - //exit(0) // TODO Game Menu + if player.life <= 0 { + self.scene.isPaused = true + restartButton.isHidden = false } } } @@ -176,34 +170,57 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe private var lastTime: TimeInterval = 0 func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { - for monster in monsters { - monster.move() - } - - - if time - lastTime > 0.25 { - if touchInputHandler.isTouchDown { - player.move() + if !scene.isPaused { + for monster in monsters { + monster.move() + } + + if time - lastTime > 0.25 { + if touchInputHandler.isTouchDown { + player.move() + } + lastTime = time } - lastTime = time } } func createOverlay() -> SKScene { - let scene = SKScene(size: CGSize(width: self.view.frame.size.height, height: self.view.frame.size.width)) + let scene = SKScene(size: CGSize(width: self.view.frame.size.width, height: self.view.frame.size.height)) pointsLabel = SKLabelNode(fontNamed: "Chalkduster") pointsLabel.text = "0 Punkte" + pointsLabel.fontSize = 20 pointsLabel.fontColor = UIColor.red - pointsLabel.position = CGPoint(x: 100, y: self.view.frame.width - 30) + pointsLabel.position = CGPoint(x: 100, y: self.view.frame.height - 30) scene.addChild(pointsLabel) lifeLabel = SKLabelNode(fontNamed: "Chalkduster") lifeLabel.text = "♥️♥️♥️" lifeLabel.fontColor = UIColor.red - lifeLabel.position = CGPoint(x: self.view.frame.height - 50, y: 5) + lifeLabel.position = CGPoint(x: self.view.frame.width - 50, y: 5) scene.addChild(lifeLabel) + + backButton = SKSpriteNode(color: UIColor.purple, size: CGSize(width: 40, height: 40)) + backButton.position = CGPoint(x: backButton.size.width / 2, y: backButton.size.height / 2) + backButton.name = "Back" + scene.addChild(backButton) + + restartButton = SKLabelNode(fontNamed: "Chalkduster") + restartButton.text = "Restart" + restartButton.fontSize = 40 + restartButton.fontColor = UIColor.red + restartButton.position = CGPoint(x: self.view.frame.width / 2, y: self.view.frame.height / 2) + restartButton.isHidden = true + restartButton.name = "Restart" + scene.addChild(restartButton) + return scene } + + + func restart() { + viewDidLoad() + } + func handleTap(_ gestureRecognize: UIGestureRecognizer) { } @@ -218,7 +235,7 @@ class GameViewController: UIViewController, SKSceneDelegate, SCNPhysicsContactDe override var supportedInterfaceOrientations: UIInterfaceOrientationMask { if UIDevice.current.userInterfaceIdiom == .phone { - return .landscape + return .landscapeLeft } else { return .all } diff --git a/Pacman3D-iOS/Info.plist b/Pacman3D-iOS/Info.plist index aaaf8a572fc11e4b69419617370a83b9f9105c2a..82ef659cb93d9de6b3658db2d3e4370005c8ac51 100644 --- a/Pacman3D-iOS/Info.plist +++ b/Pacman3D-iOS/Info.plist @@ -34,9 +34,7 @@ <true/> <key>UISupportedInterfaceOrientations</key> <array> - <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> - <string>UIInterfaceOrientationLandscapeRight</string> </array> <key>UISupportedInterfaceOrientations~ipad</key> <array> diff --git a/Pacman3D-iOS/Level.swift b/Pacman3D-iOS/Level.swift index d467f1257634946738b4d083f87598791e31fcfe..bb1262177aee18a2834a9451209fc053837faad2 100644 --- a/Pacman3D-iOS/Level.swift +++ b/Pacman3D-iOS/Level.swift @@ -67,12 +67,14 @@ class Level { return false } - private func addBlock(toScene scene: SCNScene, at point: (x: Int, z: Int)) { - let box = SCNBox(width: 5, height: 2, length: 5, chamferRadius: 0) - let node = SCNNode(geometry: box) - node.position = SCNVector3(x: Float(point.x * 5), y: 1, z: Float(point.z * 5)) - node.name = "\(point.x) \(point.z)" - scene.rootNode.addChildNode(node) + private func addBlock(toScene rootScene: SCNScene, at point: (x: Int, z: Int)) { + let scene = SCNScene(named: "art.scnassets/Wall.dae") + if let node = scene?.rootNode.childNodes.first { + node.scale = SCNVector3(x: 2.5, y: 1, z: 2.5) + node.position = SCNVector3(x: Float(point.x * 5), y: 1, z: Float(point.z * 5)) + node.name = "\(point.x) \(point.z)" + rootScene.rootNode.addChildNode(node) + } } private func addPointObject(toScene scene: SCNScene, at point: (x: Int, z: Int)) { diff --git a/Pacman3D-iOS/Player.swift b/Pacman3D-iOS/Player.swift index fd13e4dadef33e15d850dda5b7700a5d591ae7e7..8f59e72607255bc340d7c54f50a483d2a49f01ea 100644 --- a/Pacman3D-iOS/Player.swift +++ b/Pacman3D-iOS/Player.swift @@ -76,9 +76,7 @@ class Player { let x: Int = Int(position.x / 5) let z: Int = Int(position.z / 5) - - print("\(x) \(z)") - + if level.data[x - 1][z] != .wall { directions.append(.south) } diff --git a/Pacman3D-iOS/TouchInputHandler.swift b/Pacman3D-iOS/TouchInputHandler.swift index 0927f2d943c72807d86b73e4278229d4df01a8ba..63c11ad4bd29e34f65e61e389a7194fbca596754 100644 --- a/Pacman3D-iOS/TouchInputHandler.swift +++ b/Pacman3D-iOS/TouchInputHandler.swift @@ -8,6 +8,7 @@ import UIKit import UIKit.UIGestureRecognizerSubclass +import SpriteKit import SceneKit @@ -15,7 +16,23 @@ class TouchInputHandler: UIGestureRecognizer { var isTouchDown: Bool = false + var gameController: GameViewController! + var scene: SKScene! + override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) { + let touch = touches.first! + let viewTouchLocation = touch.location(in: gameController.view) + let sceneTouchPoint = scene.convertPoint(fromView: viewTouchLocation) + let touchedNode = scene.atPoint(sceneTouchPoint) + + if touchedNode.name == "Back" { + gameController.scene.isPaused = !gameController.scene.isPaused + + return + } else if touchedNode.name == "Restart" { + gameController.restart() + } + self.isTouchDown = true } diff --git a/Pacman3D-iOS/art.scnassets/Pacman.dae b/Pacman3D-iOS/art.scnassets/Pacman.dae index c30c9d6b2d8e493b34995dcfd066545bd197b9fe..2f8c761b982176b6b9ba76a1398cd457353bf9b4 100755 --- a/Pacman3D-iOS/art.scnassets/Pacman.dae +++ b/Pacman3D-iOS/art.scnassets/Pacman.dae @@ -4,8 +4,8 @@ <contributor> <authoring_tool>SceneKit Collada Exporter v1.0</authoring_tool> </contributor> - <created>2017-06-25T12:19:42Z</created> - <modified>2017-06-25T12:19:42Z</modified> + <created>2017-07-15T14:59:24Z</created> + <modified>2017-07-15T14:59:24Z</modified> <unit meter="1.000000"/> <up_axis>Z_UP</up_axis> </asset> @@ -32,6 +32,26 @@ </extra> </camera> </library_cameras> + <library_lights> + <light id="omni" name="omni"> + <technique_common> + <point> + <color>1 1 1</color> + <constant_attenuation>0</constant_attenuation> + <linear_attenuation>0</linear_attenuation> + <quadratic_attenuation>1</quadratic_attenuation> + </point> + </technique_common> + <extra> + <technique profile="SceneKit"> + <attenuationStart>0</attenuationStart> + <attenuationEnd>0</attenuationEnd> + <attenuationFalloffExponent>2</attenuationFalloffExponent> + <intensity>800</intensity> + </technique> + </extra> + </light> + </library_lights> <library_materials> <material id="Material_001-material" name="Material_001"> <instance_effect url="#effect_Material_001-material"/> @@ -159,8 +179,12 @@ </instance_geometry> </node> <node id="Camera_001" name="Camera_001"> - <matrix>0.009426713 0.2029489 -0.9791163 -8.764185 -0.9999417 0.001911938 -0.009230762 -0.01355593 -1.281482e-06 0.9792057 0.2029483 3.996047 0 0 0 1 </matrix> + <matrix>0.009426475 0.2029488 -0.9791164 -8.764185 -0.9999418 0.001911759 -0.009230614 0 -1.40069e-06 0.9792058 0.2029482 4 0 0 0 1 </matrix> <instance_camera url="#Camera_001-camera"/> + <node id="node6" name="omni"> + <matrix>0.009433985 -0.5744383 -0.8184869 -0.05372059 0.2029588 -0.8003826 0.5640805 3.959687 -0.979173 -0.1714358 0.1090278 6.639687 0 0 0 1 </matrix> + <instance_light url="#omni"/> + </node> </node> </visual_scene> </library_visual_scenes> diff --git a/Pacman3D-iOS/art.scnassets/Wall.dae b/Pacman3D-iOS/art.scnassets/Wall.dae new file mode 100644 index 0000000000000000000000000000000000000000..e59bf92bacd98786ceddf499c20381fa32018da1 --- /dev/null +++ b/Pacman3D-iOS/art.scnassets/Wall.dae @@ -0,0 +1,134 @@ +<?xml version="1.0" encoding="UTF-8"?> +<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1"> + <asset> + <contributor> + <authoring_tool>SceneKit Collada Exporter v1.0</authoring_tool> + </contributor> + <created>2017-07-15T13:58:14Z</created> + <modified>2017-07-15T13:58:14Z</modified> + <unit meter="1.000000"/> + <up_axis>Z_UP</up_axis> + </asset> + <library_images> + <image id="image1"> + <init_from>../wall.jpg</init_from> + </image> + </library_images> + <library_materials> + <material id="Material-material" name="Material"> + <instance_effect url="#effect_Material-material"/> + </material> + </library_materials> + <library_effects> + <effect id="effect_Material-material"> + <profile_COMMON> + <newparam sid="ID2_image1_surface"> + <surface type="2D"> + <init_from>image1</init_from> + </surface> + </newparam> + <newparam sid="ID2_image1"> + <sampler2D> + <source>ID2_image1_surface</source> + <wrap_s>WRAP</wrap_s> + <wrap_t>WRAP</wrap_t> + <minfilter>LINEAR</minfilter> + <magfilter>LINEAR</magfilter> + <mipfilter>LINEAR</mipfilter> + </sampler2D> + </newparam> + <technique sid="common"> + <phong> + <ambient> + <color>0 0 0 1</color> + </ambient> + <diffuse> + <texture texture="ID2_image1" texcoord="CHANNEL2"/> + </diffuse> + <specular> + <color>0.5 0.5 0.5 1</color> + </specular> + <shininess> + <float>50</float> + </shininess> + <transparency> + <float>1</float> + </transparency> + <index_of_refraction> + <float>1</float> + </index_of_refraction> + </phong> + </technique> + </profile_COMMON> + <extra> + <technique profile="SceneKit"> + <litPerPixel>1</litPerPixel> + <ambient_diffuse_lock>1</ambient_diffuse_lock> + </technique> + </extra> + </effect> + </library_effects> + <library_geometries> + <geometry id="Cube-mesh" name="Cube"> + <mesh> + <source id="Cube-mesh-positions"> + <float_array id="ID3-array" count="108">1 1 -1 -1 -1 -1 -1 1 -1 -1 1 1 0.999999 -1 1 1 1 1 1 1 1 1 -1 -1 1 1 -1 0.999999 -1 1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 1 1 -1 1 -1 1 1 -1 -1 1 1 1 1 1 1 1 -1 1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 0.999999 -1 1 1 1 1 0.999999 -1 1 1 -1 -1 0.999999 -1 1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 1 -1 -1 1 -1 -1 1 1 </float_array> + <technique_common> + <accessor source="#ID3-array" count="36" stride="3"> + <param name="X" type="float"/> + <param name="Y" type="float"/> + <param name="Z" type="float"/> + </accessor> + </technique_common> + </source> + <source id="Cube-mesh-normals"> + <float_array id="ID4-array" count="108">0 0 -1 0 0 -1 0 0 -1 0 0 1 0 0 1 0 0 1 1 0 -2.38419e-07 1 0 -2.38419e-07 1 0 -2.38419e-07 0 -1 -4.76837e-07 0 -1 -4.76837e-07 0 -1 -4.76837e-07 -1 2.38419e-07 -1.49012e-07 -1 2.38419e-07 -1.49012e-07 -1 2.38419e-07 -1.49012e-07 2.68221e-07 1 2.38419e-07 2.68221e-07 1 2.38419e-07 2.68221e-07 1 2.38419e-07 0 0 -1 0 0 -1 0 0 -1 0 0 1 0 0 1 0 0 1 1 -5.96046e-07 3.27825e-07 1 -5.96046e-07 3.27825e-07 1 -5.96046e-07 3.27825e-07 -4.76837e-07 -1 0 -4.76837e-07 -1 0 -4.76837e-07 -1 0 -1 2.38419e-07 -1.19209e-07 -1 2.38419e-07 -1.19209e-07 -1 2.38419e-07 -1.19209e-07 2.08616e-07 1 0 2.08616e-07 1 0 2.08616e-07 1 0 </float_array> + <technique_common> + <accessor source="#ID4-array" count="36" stride="3"> + <param name="X" type="float"/> + <param name="Y" type="float"/> + <param name="Z" type="float"/> + </accessor> + </technique_common> + </source> + <source id="Cube-mesh-map-0"> + <float_array id="ID5-array" count="72">0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 1 0 1 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 0 0 1 0 1 1 1 0 1 1 0 1 </float_array> + <technique_common> + <accessor source="#ID5-array" count="36" stride="2"> + <param name="S" type="float"/> + <param name="T" type="float"/> + </accessor> + </technique_common> + </source> + <vertices id="Cube-mesh-positions-vertices"> + <input semantic="POSITION" source="#Cube-mesh-positions"/> + </vertices> + <triangles count="12" material="geometryElement6"> + <input semantic="VERTEX" offset="0" source="#Cube-mesh-positions-vertices"/> + <input semantic="NORMAL" offset="0" source="#Cube-mesh-normals"/> + <input semantic="TEXCOORD" offset="0" source="#Cube-mesh-map-0" set="1"/> + <p>0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 </p> + </triangles> + </mesh> + </geometry> + </library_geometries> + <library_visual_scenes> + <visual_scene id="scene7"> + <node id="Cube" name="Cube"> + <matrix>5 0 0 0 0 5 0 0 0 0 2 0 0 0 0 1 </matrix> + <instance_geometry url="#Cube-mesh"> + <bind_material> + <technique_common> + <instance_material symbol="geometryElement6" target="#Material-material"> + <bind_vertex_input semantic="CHANNEL2" input_semantic="TEXCOORD" input_set="1"/> + </instance_material> + </technique_common> + </bind_material> + </instance_geometry> + </node> + </visual_scene> + </library_visual_scenes> + <scene> + <instance_visual_scene url="#scene7"/> + </scene> +</COLLADA> diff --git a/Pacman3D-iOS/art.scnassets/ship.scn b/Pacman3D-iOS/art.scnassets/ship.scn index e0ccee6004c3b3af27b8977878841a81cd6e3318..39103dc2e2534095ffce117d9416266ef35e70fa 100644 Binary files a/Pacman3D-iOS/art.scnassets/ship.scn and b/Pacman3D-iOS/art.scnassets/ship.scn differ diff --git a/Pacman3D-iOS/background.jpg b/Pacman3D-iOS/background.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b01a51d4329f7b1f31c616c99b1f87d1d95972e8 Binary files /dev/null and b/Pacman3D-iOS/background.jpg differ diff --git a/Pacman3D-iOS/floor.jpg b/Pacman3D-iOS/floor.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7863c576f3f70f9152a9afe443f4ad3b74a0f068 Binary files /dev/null and b/Pacman3D-iOS/floor.jpg differ diff --git a/Pacman3D-iOS/run.png b/Pacman3D-iOS/run.png deleted file mode 100644 index f09b7ec7f076aff1f5d19bd7620dab2af8867aff..0000000000000000000000000000000000000000 Binary files a/Pacman3D-iOS/run.png and /dev/null differ diff --git a/Pacman3D-iOS/wall.jpg b/Pacman3D-iOS/wall.jpg new file mode 100644 index 0000000000000000000000000000000000000000..47ecda3be2f2e5003bf5c0d728770b3efdfbac6a Binary files /dev/null and b/Pacman3D-iOS/wall.jpg differ