From 78ae9a72d30cac9c21d7775a4b622c1a9ae6a828 Mon Sep 17 00:00:00 2001 From: FloPeters Date: Thu, 13 Apr 2017 13:18:37 +0200 Subject: [PATCH] V1 --- FlappySwift.xcodeproj/project.pbxproj | 15 ++- .../AppIcon.appiconset/Contents.json | 20 ++++ .../Base.lproj/LaunchScreen.storyboard | 16 ++- FlappySwift/Base.lproj/Main.storyboard | 14 ++- FlappySwift/FlyScene.sks | Bin 0 -> 3428 bytes FlappySwift/FlyScene.swift | 105 ++++++++++++++++++ FlappySwift/ViewController.swift | 11 +- 7 files changed, 167 insertions(+), 14 deletions(-) create mode 100644 FlappySwift/FlyScene.sks create mode 100644 FlappySwift/FlyScene.swift diff --git a/FlappySwift.xcodeproj/project.pbxproj b/FlappySwift.xcodeproj/project.pbxproj index d3612a2..a68bf8c 100644 --- a/FlappySwift.xcodeproj/project.pbxproj +++ b/FlappySwift.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 1763B3CF1E9F7AA600FF0B0D /* FlyScene.sks in Resources */ = {isa = PBXBuildFile; fileRef = 1763B3CE1E9F7AA600FF0B0D /* FlyScene.sks */; }; + 1763B3D11E9F7AC400FF0B0D /* FlyScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1763B3D01E9F7AC400FF0B0D /* FlyScene.swift */; }; 873BE29B1D06195B00A69FF5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873BE29A1D06195B00A69FF5 /* AppDelegate.swift */; }; 873BE2A11D06195B00A69FF5 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873BE2A01D06195B00A69FF5 /* ViewController.swift */; }; 873BE2A41D06195B00A69FF5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873BE2A21D06195B00A69FF5 /* Main.storyboard */; }; @@ -16,6 +18,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 1763B3CE1E9F7AA600FF0B0D /* FlyScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = FlyScene.sks; sourceTree = ""; }; + 1763B3D01E9F7AC400FF0B0D /* FlyScene.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlyScene.swift; sourceTree = ""; }; 873BE2971D06195B00A69FF5 /* FlappySwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FlappySwift.app; sourceTree = BUILT_PRODUCTS_DIR; }; 873BE29A1D06195B00A69FF5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 873BE2A01D06195B00A69FF5 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -58,6 +62,8 @@ children = ( 873BE29A1D06195B00A69FF5 /* AppDelegate.swift */, 873BE2A21D06195B00A69FF5 /* Main.storyboard */, + 1763B3CE1E9F7AA600FF0B0D /* FlyScene.sks */, + 1763B3D01E9F7AC400FF0B0D /* FlyScene.swift */, 873BE2A01D06195B00A69FF5 /* ViewController.swift */, 873BE2A51D06195B00A69FF5 /* Assets.xcassets */, 87AA11DB1D0B4D6E006C614F /* bird.atlas */, @@ -107,6 +113,7 @@ TargetAttributes = { 873BE2961D06195B00A69FF5 = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = 9N294DEXYZ; LastSwiftMigration = 0830; }; }; @@ -137,6 +144,7 @@ 873BE2A91D06195B00A69FF5 /* LaunchScreen.storyboard in Resources */, 873BE2A61D06195B00A69FF5 /* Assets.xcassets in Resources */, 87AA11DC1D0B4D6E006C614F /* bird.atlas in Resources */, + 1763B3CF1E9F7AA600FF0B0D /* FlyScene.sks in Resources */, 873BE2A41D06195B00A69FF5 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -149,6 +157,7 @@ buildActionMask = 2147483647; files = ( 873BE2A11D06195B00A69FF5 /* ViewController.swift in Sources */, + 1763B3D11E9F7AC400FF0B0D /* FlyScene.swift in Sources */, 873BE29B1D06195B00A69FF5 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -269,9 +278,10 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 9N294DEXYZ; INFOPLIST_FILE = FlappySwift/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.FlappySwift"; + PRODUCT_BUNDLE_IDENTIFIER = Wurstsalat; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 3.0; }; @@ -281,9 +291,10 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 9N294DEXYZ; INFOPLIST_FILE = FlappySwift/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.FlappySwift"; + PRODUCT_BUNDLE_IDENTIFIER = Wurstsalat; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 3.0; }; diff --git a/FlappySwift/Assets.xcassets/AppIcon.appiconset/Contents.json b/FlappySwift/Assets.xcassets/AppIcon.appiconset/Contents.json index eeea76c..1d060ed 100644 --- a/FlappySwift/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/FlappySwift/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", diff --git a/FlappySwift/Base.lproj/LaunchScreen.storyboard b/FlappySwift/Base.lproj/LaunchScreen.storyboard index a9a24c1..5cfb086 100644 --- a/FlappySwift/Base.lproj/LaunchScreen.storyboard +++ b/FlappySwift/Base.lproj/LaunchScreen.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,14 +18,14 @@ - + - + - + diff --git a/FlappySwift/Base.lproj/Main.storyboard b/FlappySwift/Base.lproj/Main.storyboard index af837b3..4a56362 100644 --- a/FlappySwift/Base.lproj/Main.storyboard +++ b/FlappySwift/Base.lproj/Main.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,9 +18,9 @@ - + - + diff --git a/FlappySwift/FlyScene.sks b/FlappySwift/FlyScene.sks new file mode 100644 index 0000000000000000000000000000000000000000..4ae85eee3bb2b63a0188cec7837f0379e2bc338b GIT binary patch literal 3428 zcmaJ@4RjRM6~1rZ?EE2QNn-ei{DCMTF2wNX@gO09$22jpB%A+nvOC!fnar#+v%nfC zPp$v;uhv>>)tLBqw5QtETD4WFRZp!4K@^l)i=bGoR8i5EBGNlEo2b-w&Uy3R-1qLg z@80?DcVBnf&>c4#eH93VfC2|$;K@`nt)+auW;?oNwv=1l>$HUHw3e%OqE|=p+H%)Q z=L5N7@S(_J5I}@hXoCwug%tFH4jEVv8(~2@Jsj={04ptPr|)$ zA3P1);U(AsJ7G8MfxYl5{230yd+-nV5I%v=;Bz>kx&4=?) zdcObdXS9P+m9*vP-bjgzSGv_i zU&{8@EVm5HUKUrJUNx!N9g1oudM&%r(oMHh>C>`Wa#_ODa+F9U_>N_|V`*D=H5C2V zPBn3*S5GE2vrDmTJ*AtfvD{D{r$teNZJHF_?6KlXLhaXVwN2?ZG&5OmCABW4v97T< z>*xum#!6<}l#3fj4_tu9voc0s)KUQEBst!t|o0bJ{NHoWu2m5si=xRO>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9PyM3B8P7POqd_(`)H<^agqpy_w!ZZ>3x5ZS;0}C%uaf(|hQB^bxv^ zzDT#z9rR`TI^9nX(a-2{F2s%D3b|?A8QgsC9IlpI$(_fY&#mTSToV`PTDbvkkb9Qf z&b`F#H%s<6H$8YEN@UQcG`2+k1{2~5B{xJUue~kZv|55;f z2(nNh6bfZRg|I|eD%1;YLc7o*bO|ZJ5L_W6>=a%X_6i4tw}pek--N@$$HJ$=XTs;g z2@ym|%onGKv&Aa0T3jeD7FUa1;)Pa4SA0W!Q`{%MC%!L! zARZBqipRv`;t5HT@}&}KmQ*d(NVU>RX|>cQX_75vrOTzeq@PQVN!z4nq-Uk)r5(~v zX_vH5dP~|by)7M*jz~vkULGsw$>Ze$d9plJo-P;5rSby#JF+I5vLkPjua}4AU&wpp fH{^HZzsrZ@59P!1Cmw48ghD}2W(WPqTR!q1k8LXK literal 0 HcmV?d00001 diff --git a/FlappySwift/FlyScene.swift b/FlappySwift/FlyScene.swift new file mode 100644 index 0000000..aee9844 --- /dev/null +++ b/FlappySwift/FlyScene.swift @@ -0,0 +1,105 @@ +// +// FlyScene.swift +// FlappySwift +// +// Created by Florian Petatz on 13.04.17. +// Copyright © 2017 iOS Dev Kurs Universität Heidelberg. All rights reserved. +// + +import Foundation +import SpriteKit + +let worldCollisionCategory: UInt32 = 1 << 1 +let obstacleCollisionCategory: UInt32 = 1 << 2 +let birdCollisionCategory: UInt32 = 1 << 3 + +class FlyScene: SKScene, SKPhysicsContactDelegate { + + let impulseOnFlap: CGFloat = 500 + + let bird: SKSpriteNode = { + let spriteNote = SKSpriteNode (imageNamed: "bird-01") + let physicsBody = SKPhysicsBody(circleOfRadius: spriteNote.size.width / 2) + physicsBody.mass = 1 + physicsBody.linearDamping = 0 + physicsBody.restitution = 1 + physicsBody.collisionBitMask = worldCollisionCategory | obstacleCollisionCategory + physicsBody.categoryBitMask = birdCollisionCategory + physicsBody.contactTestBitMask = obstacleCollisionCategory + spriteNote.physicsBody = physicsBody + return spriteNote + }() + + let obstacles: SKNode = { + let node = SKNode() + return node + }() + + override func didMove(to view: SKView) { + super.didMove(to: view) + + self.physicsWorld.contactDelegate = self + + self.addChild(bird) + bird.position = CGPoint(x: 0, y: 0) + + let physicsBody = SKPhysicsBody(edgeLoopFrom: CGRect(x: -self.size.width / 2, y: -self.size.height / 2, width: self.size.width, height: self.size.height)) + physicsBody.categoryBitMask = worldCollisionCategory + self.physicsBody = physicsBody + + self.addChild(obstacles) + + self.obstacles.run(.repeatForever(.sequence([ + .wait(forDuration: 2), + self.spawnObstacle, + + ]))) + } + + + lazy var spawnObstacle: SKAction = { + let action = SKAction.run { + let upperObstacle = SKSpriteNode(imageNamed: "PipeDown") + let upperPhysicsBody = SKPhysicsBody(edgeLoopFrom: upperObstacle.frame) + upperPhysicsBody.categoryBitMask = obstacleCollisionCategory + upperObstacle.physicsBody = upperPhysicsBody + self.obstacles.addChild(upperObstacle) + upperObstacle.run(self.moveObstacle) + + } + return action + }() + + lazy var moveObstacle: SKAction = { + let distance: CGFloat = self.size.width + return .sequence([ + .move(to: CGPoint(x: self.size.width / 2, y: 0), duration: 0), + .move(by: CGVector(dx: -distance, dy: 0), duration: 3), + .removeFromParent() + ]) + }() + + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + + + if self.speed == 0 { + self.speed = 1 + self.physicsWorld.speed = 1 + bird.physicsBody?.velocity = CGVector(dx: 0, dy: 0) + bird.position = CGPoint(x: -100, y: -100) + for obstacle in obstacles.children { + obstacle.removeFromParent() + } + } + + bird.physicsBody?.applyImpulse(CGVector (dx: 0, dy: impulseOnFlap)) + + } + + func didBegin(_ contact: SKPhysicsContact) { + print("Game over!") + self.speed = 0 + + } + +} diff --git a/FlappySwift/ViewController.swift b/FlappySwift/ViewController.swift index f2baeaa..f33c338 100644 --- a/FlappySwift/ViewController.swift +++ b/FlappySwift/ViewController.swift @@ -18,7 +18,16 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - // Configure scene view + // Configure scene view + + guard let scene = FlyScene(fileNamed: "FlyScene") else { + return + } + + scene.size = self.view.bounds.size + + sceneView.presentScene(scene) + sceneView.showsFPS = true sceneView.showsNodeCount = true sceneView.showsDrawCount = true