Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

V1 #2

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions FlappySwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -16,6 +18,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
1763B3CE1E9F7AA600FF0B0D /* FlyScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = FlyScene.sks; sourceTree = "<group>"; };
1763B3D01E9F7AC400FF0B0D /* FlyScene.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlyScene.swift; sourceTree = "<group>"; };
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 = "<group>"; };
873BE2A01D06195B00A69FF5 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -107,6 +113,7 @@
TargetAttributes = {
873BE2961D06195B00A69FF5 = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 9N294DEXYZ;
LastSwiftMigration = 0830;
};
};
Expand Down Expand Up @@ -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;
Expand All @@ -149,6 +157,7 @@
buildActionMask = 2147483647;
files = (
873BE2A11D06195B00A69FF5 /* ViewController.swift in Sources */,
1763B3D11E9F7AC400FF0B0D /* FlyScene.swift in Sources */,
873BE29B1D06195B00A69FF5 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
20 changes: 20 additions & 0 deletions FlappySwift/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down
16 changes: 10 additions & 6 deletions FlappySwift/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -14,14 +18,14 @@
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="bird-01.png" translatesAutoresizingMaskIntoConstraints="NO" id="RCH-bS-FlW">
<rect key="frame" x="283" y="288" width="34" height="24"/>
<rect key="frame" x="170.5" y="321.5" width="34" height="24"/>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="RCH-bS-FlW" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="fa2-ke-B8v"/>
<constraint firstItem="RCH-bS-FlW" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="grw-8U-ygI"/>
Expand Down
14 changes: 9 additions & 5 deletions FlappySwift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BV1-FR-VrT">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BV1-FR-VrT">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -14,9 +18,9 @@
<viewControllerLayoutGuide type="bottom" id="qHh-Mt-9TT"/>
</layoutGuides>
<view key="view" multipleTouchEnabled="YES" contentMode="scaleToFill" id="3se-qz-xqx" customClass="SKView">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="SZV-WD-TEh" sceneMemberID="firstResponder"/>
Expand Down
Binary file added FlappySwift/FlyScene.sks
Binary file not shown.
105 changes: 105 additions & 0 deletions FlappySwift/FlyScene.swift
Original file line number Diff line number Diff line change
@@ -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<UITouch>, 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

}

}
11 changes: 10 additions & 1 deletion FlappySwift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down