Skip to content

Commit

Permalink
Add Logo, Close instantly
Browse files Browse the repository at this point in the history
  • Loading branch information
krayc425 committed Nov 18, 2017
1 parent 0e0611f commit 794e82d
Show file tree
Hide file tree
Showing 27 changed files with 111 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -65,3 +65,5 @@ fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output

*.sketch
8 changes: 4 additions & 4 deletions TouchBreakout.xcodeproj/project.pbxproj
Expand Up @@ -10,6 +10,7 @@
24A4A8A11FBDCB2E00AECE80 /* NSColorExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A4A8A01FBDCB2E00AECE80 /* NSColorExtensions.swift */; };
24A4A8A31FBE973F00AECE80 /* GameState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A4A8A21FBE973F00AECE80 /* GameState.swift */; };
24A4A8A51FBEC09700AECE80 /* GameHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A4A8A41FBEC09700AECE80 /* GameHelper.swift */; };
24A7CCF41FC020A000D4A109 /* BrokenPlatform.sks in Resources */ = {isa = PBXBuildFile; fileRef = 24A7CCF31FC0209F00D4A109 /* BrokenPlatform.sks */; };
24C698931FBD7866000B8592 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24C698921FBD7866000B8592 /* AppDelegate.swift */; };
24C698951FBD7866000B8592 /* GameScene.sks in Resources */ = {isa = PBXBuildFile; fileRef = 24C698941FBD7866000B8592 /* GameScene.sks */; };
24C698991FBD7866000B8592 /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24C698981FBD7866000B8592 /* GameScene.swift */; };
Expand All @@ -18,14 +19,14 @@
24C698A01FBD7866000B8592 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 24C6989E1FBD7866000B8592 /* Main.storyboard */; };
24CD83461FBDACE4005B3BE0 /* SKSpriteNodeExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24CD83451FBDACE4005B3BE0 /* SKSpriteNodeExtensions.swift */; };
24CD83491FBDB556005B3BE0 /* BallTrail.sks in Resources */ = {isa = PBXBuildFile; fileRef = 24CD83471FBDB555005B3BE0 /* BallTrail.sks */; };
24CD834A1FBDB556005B3BE0 /* BrokenPlatform.sks in Resources */ = {isa = PBXBuildFile; fileRef = 24CD83481FBDB556005B3BE0 /* BrokenPlatform.sks */; };
24CD834C1FBDBDDF005B3BE0 /* TouchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24CD834B1FBDBDDF005B3BE0 /* TouchBarView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
24A4A8A01FBDCB2E00AECE80 /* NSColorExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSColorExtensions.swift; sourceTree = "<group>"; };
24A4A8A21FBE973F00AECE80 /* GameState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameState.swift; sourceTree = "<group>"; };
24A4A8A41FBEC09700AECE80 /* GameHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameHelper.swift; sourceTree = "<group>"; };
24A7CCF31FC0209F00D4A109 /* BrokenPlatform.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = BrokenPlatform.sks; sourceTree = "<group>"; };
24C6988F1FBD7866000B8592 /* TouchBreakout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TouchBreakout.app; sourceTree = BUILT_PRODUCTS_DIR; };
24C698921FBD7866000B8592 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
24C698941FBD7866000B8592 /* GameScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = GameScene.sks; sourceTree = "<group>"; };
Expand All @@ -37,7 +38,6 @@
24C698A21FBD7866000B8592 /* TouchBreakout.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TouchBreakout.entitlements; sourceTree = "<group>"; };
24CD83451FBDACE4005B3BE0 /* SKSpriteNodeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SKSpriteNodeExtensions.swift; sourceTree = "<group>"; };
24CD83471FBDB555005B3BE0 /* BallTrail.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = BallTrail.sks; sourceTree = "<group>"; };
24CD83481FBDB556005B3BE0 /* BrokenPlatform.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = BrokenPlatform.sks; sourceTree = "<group>"; };
24CD834B1FBDBDDF005B3BE0 /* TouchBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchBarView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -74,7 +74,7 @@
24C698921FBD7866000B8592 /* AppDelegate.swift */,
24C698941FBD7866000B8592 /* GameScene.sks */,
24CD83471FBDB555005B3BE0 /* BallTrail.sks */,
24CD83481FBDB556005B3BE0 /* BrokenPlatform.sks */,
24A7CCF31FC0209F00D4A109 /* BrokenPlatform.sks */,
24A4A8A21FBE973F00AECE80 /* GameState.swift */,
24A4A8A41FBEC09700AECE80 /* GameHelper.swift */,
24C698981FBD7866000B8592 /* GameScene.swift */,
Expand Down Expand Up @@ -150,8 +150,8 @@
buildActionMask = 2147483647;
files = (
24C698951FBD7866000B8592 /* GameScene.sks in Resources */,
24CD834A1FBDB556005B3BE0 /* BrokenPlatform.sks in Resources */,
24CD83491FBDB556005B3BE0 /* BallTrail.sks in Resources */,
24A7CCF41FC020A000D4A109 /* BrokenPlatform.sks in Resources */,
24C6989D1FBD7866000B8592 /* Assets.xcassets in Resources */,
24C698A01FBD7866000B8592 /* Main.storyboard in Resources */,
);
Expand Down
4 changes: 3 additions & 1 deletion TouchBreakout/AppDelegate.swift
Expand Up @@ -12,7 +12,6 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {


func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application

Expand All @@ -24,5 +23,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// Insert code here to tear down your application
}

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}

}
30 changes: 20 additions & 10 deletions TouchBreakout/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -1,53 +1,63 @@
{
"images" : [
{
"idiom" : "mac",
"size" : "16x16",
"idiom" : "mac",
"filename" : "icon_16x16.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "16x16",
"idiom" : "mac",
"filename" : "icon_16x16@2x.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "32x32",
"idiom" : "mac",
"filename" : "icon_32x32.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "32x32",
"idiom" : "mac",
"filename" : "icon_32x32@2x.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "128x128",
"idiom" : "mac",
"filename" : "icon_128x128.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "128x128",
"idiom" : "mac",
"filename" : "icon_128x128@2x.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "256x256",
"idiom" : "mac",
"filename" : "icon_256x256.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "256x256",
"idiom" : "mac",
"filename" : "icon_256x256@2x.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "icon_512x512.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "icon_512x512@2x.png",
"scale" : "2x"
}
],
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "bokeh.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "spark.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified TouchBreakout/Assets.xcassets/ball.imageset/ball.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified TouchBreakout/Assets.xcassets/ball.imageset/ball@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified TouchBreakout/Assets.xcassets/ball.imageset/ball@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified TouchBreakout/BallTrail.sks
Binary file not shown.
Binary file modified TouchBreakout/BrokenPlatform.sks
Binary file not shown.
Binary file modified TouchBreakout/GameScene.sks
Binary file not shown.
43 changes: 28 additions & 15 deletions TouchBreakout/GameScene.swift
Expand Up @@ -25,8 +25,10 @@ class GameScene: SKScene {
private let kLeftKeyCode : UInt16 = 123
private let kRightKeyCode : UInt16 = 124

private let kBasicBallSpeed = 30.0
private var kBallSpeed = 30.0
private let kBasicBallSpeed = 30.0
private var kBallSpeed = 30.0
private var kBallRadius: CGFloat = 12.0

private let kBallNodeName = "Ball"
private let kPaddleNodeName = "Paddle"
private let kBlockNodeName = "Block"
Expand All @@ -40,11 +42,11 @@ class GameScene: SKScene {
private let kBorderCategory : UInt32 = 0x1 << 4
private let kHiddenCategory : UInt32 = 0x1 << 5

private let kBlockWidth: CGFloat = 100.0
private let kBlockWidth: CGFloat = 90.0
private let kBlockHeight: CGFloat = 25.0
private let kBlockRows = 8
private let kBlockColumns = 8
private var kBlockRecoverTime = 5.0
private var kBlockRecoverTime = 10.0

fileprivate var paddle: SKSpriteNode!
fileprivate var ball: SKSpriteNode!
Expand Down Expand Up @@ -94,35 +96,35 @@ class GameScene: SKScene {
bestLabel = childNode(withName: kBestNodeName) as! SKLabelNode
bestLabel.text = "Best: \(GameHelper.shared.loadBestScore())"
// Border
let borderBody = SKPhysicsBody(edgeLoopFrom: self.frame)
let roundedRectPath = CGPath(roundedRect: self.frame,
cornerWidth: kBallRadius / 2,
cornerHeight: kBallRadius / 2,
transform: nil)
let borderBody = SKPhysicsBody(edgeLoopFrom: roundedRectPath)
view.frame = roundedRectPath.boundingBoxOfPath
borderBody.friction = 0
borderBody.restitution = 1
borderBody.usesPreciseCollisionDetection = true
self.physicsBody = borderBody
physicsWorld.gravity = CGVector.zero
physicsWorld.gravity = .zero
physicsWorld.contactDelegate = self
// Ball
ball = childNode(withName: kBallNodeName) as! SKSpriteNode
ball.physicsBody?.usesPreciseCollisionDetection = true
let trailNode = SKNode()
trailNode.zPosition = 1
addChild(trailNode)
let trail = SKEmitterNode(fileNamed: "BallTrail")!
trail.targetNode = trailNode
ball.addChild(trail)
// Bottom
let bottomRect = CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.size.width, height: 1)
let bottomRect = CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.size.width, height: kBallRadius)
let bottom = SKNode()
bottom.physicsBody = SKPhysicsBody(edgeLoopFrom: bottomRect)
addChild(bottom)
// Paddle
paddle = childNode(withName: kPaddleNodeName) as! SKSpriteNode

// BitMasks
bottom.physicsBody!.categoryBitMask = kBottomCategory
ball.physicsBody!.categoryBitMask = kBallCategory
paddle.physicsBody!.categoryBitMask = kPaddleCategory
borderBody.categoryBitMask = kBorderCategory

ball.physicsBody!.contactTestBitMask = kBottomCategory | kBlockCategory

// Blocks
let totalBlocksWidth = kBlockWidth * CGFloat(kBlockColumns)
let xOffset = -totalBlocksWidth / 2
Expand All @@ -144,6 +146,13 @@ class GameScene: SKScene {
addChild(block)
}
}

// BitMasks
bottom.physicsBody!.categoryBitMask = kBottomCategory
ball.physicsBody!.categoryBitMask = kBallCategory
paddle.physicsBody!.categoryBitMask = kPaddleCategory
borderBody.categoryBitMask = kBorderCategory
ball.physicsBody!.contactTestBitMask = kBottomCategory | kBlockCategory
}

// MARK: - Event Handler
Expand Down Expand Up @@ -202,6 +211,10 @@ extension GameScene: SKPhysicsContactDelegate {
secondBody = contact.bodyA
}

// if firstBody.categoryBitMask == kBallCategory && secondBody.categoryBitMask == kBorderCategory {
// firstBody.applyForce(CGVector(dx: -firstBody.velocity.dx, dy: firstBody.velocity.dy))
// }

if firstBody.categoryBitMask == kBallCategory && secondBody.categoryBitMask == kBottomCategory {
gameState = .new
return
Expand Down
8 changes: 6 additions & 2 deletions TouchBreakout/ViewController.swift
Expand Up @@ -38,10 +38,14 @@ class ViewController: NSViewController {
view.addSubview(restartButton)
}

override func viewDidAppear() {
super.viewDidAppear()

view.window!.styleMask.remove(NSWindow.StyleMask.resizable)
}

@objc func restartGame() {
gameScene?.gameState = .new

// GameHelper.shared.setBestScore(score: 0)
}

override func makeTouchBar() -> NSTouchBar? {
Expand Down

0 comments on commit 794e82d

Please sign in to comment.