diff --git a/Privyet/Base.lproj/Main.storyboard b/Privyet/Base.lproj/Main.storyboard
index 744732f..0924d44 100644
--- a/Privyet/Base.lproj/Main.storyboard
+++ b/Privyet/Base.lproj/Main.storyboard
@@ -16,21 +16,21 @@
-
+
-
-
+
-
+
-
+
diff --git a/Privyet/Block.swift b/Privyet/Block.swift
index 0e32bbb..aee499e 100644
--- a/Privyet/Block.swift
+++ b/Privyet/Block.swift
@@ -35,10 +35,6 @@ enum BlockColor: Int, CustomStringConvertible, CaseIterable {
var description: String {
return self.spriteName
}
-
- static func random() -> BlockColor {
- return BlockColor.allCases.shuffled().first!
- }
}
// Represents a single block in the game.
diff --git a/Privyet/GameScene.swift b/Privyet/GameScene.swift
index e1c9639..e176466 100644
--- a/Privyet/GameScene.swift
+++ b/Privyet/GameScene.swift
@@ -31,25 +31,31 @@ class GameScene: SKScene {
override init(size: CGSize) {
super.init(size: size)
- print("Init scene with size \(size)")
+ //print("Init scene with size \(size)")
textureAtlas = SKTextureAtlas(named: "Sprites")
anchorPoint = CGPoint(x: 0, y: 1.0)
let background = SKSpriteNode(imageNamed: "background")
- print("Background is sized \(background.size)")
+ //print("Background is sized \(background.size)")
+
+ // Scale computations
+ let scaleFactor = min(size.width / background.size.width, size.height / background.size.height)
+
background.position = CGPoint(x: 0, y: 0)
background.anchorPoint = CGPoint(x: 0, y: 1.0)
+ background.setScale(scaleFactor)
addChild(background)
+ gameLayer.setScale(scaleFactor)
addChild(gameLayer)
+ // Load and add the game board and shape layer
let gameBoardTexture = SKTexture(imageNamed: "gameboard")
let gameBoard = SKSpriteNode(texture: gameBoardTexture, size: CGSize(width: BlockSize * CGFloat(NumColumns), height: BlockSize * CGFloat(NumRows)))
gameBoard.anchorPoint = CGPoint(x: 0, y: 1.0)
gameBoard.position = LayerPosition
-
shapeLayer.position = LayerPosition
shapeLayer.addChild(gameBoard)
gameLayer.addChild(shapeLayer)
diff --git a/Privyet/JShape.swift b/Privyet/JShape.swift
index d2ceb2b..95860f8 100644
--- a/Privyet/JShape.swift
+++ b/Privyet/JShape.swift
@@ -31,6 +31,10 @@ class JShape: Shape {
*/
// Rotates around block #1
+ override var color: BlockColor? {
+ return .Blue
+ }
+
override var blockRowColumnPositions: [Orientation : Array<(columnDiff: Int, rowDiff: Int)>] {
return [
Orientation.Zero: [(1, 0), (1, 1), (1, 2), (0, 2)],
diff --git a/Privyet/LShape.swift b/Privyet/LShape.swift
index ba7f0a8..3762c80 100644
--- a/Privyet/LShape.swift
+++ b/Privyet/LShape.swift
@@ -32,6 +32,10 @@ class LShape: Shape {
*/
// Pivots about block #1
+ override var color: BlockColor? {
+ return .Green
+ }
+
override var blockRowColumnPositions: [Orientation : Array<(columnDiff: Int, rowDiff: Int)>] {
return [
Orientation.Zero: [(0, 0), (0, 1), (0, 2), (1, 2)],
diff --git a/Privyet/LineShape.swift b/Privyet/LineShape.swift
index 55fafe0..deadc9f 100644
--- a/Privyet/LineShape.swift
+++ b/Privyet/LineShape.swift
@@ -22,6 +22,10 @@ class LineShape: Shape {
*/
// Hinges about the second block
+ override var color: BlockColor? {
+ return .Teal
+ }
+
override var blockRowColumnPositions: [Orientation : Array<(columnDiff: Int, rowDiff: Int)>] {
return [
Orientation.Zero: [(0, 0), (0, 1), (0, 2), (0, 3)],
diff --git a/Privyet/SShape.swift b/Privyet/SShape.swift
index 4600dc1..4195d64 100644
--- a/Privyet/SShape.swift
+++ b/Privyet/SShape.swift
@@ -21,6 +21,10 @@ class SShape: Shape {
* marks the row/column indicator for the shape
*/
+ override var color: BlockColor? {
+ return .Purple
+ }
+
override var blockRowColumnPositions: [Orientation : Array<(columnDiff: Int, rowDiff: Int)>] {
return [
Orientation.Zero: [(0, 0), (0, 1), (1, 1), (1, 2)],
diff --git a/Privyet/Shape.swift b/Privyet/Shape.swift
index 47fd7ea..77ca24c 100644
--- a/Privyet/Shape.swift
+++ b/Privyet/Shape.swift
@@ -9,8 +9,6 @@
import Foundation
import SpriteKit
-//let NumOrientations: UInt32 = 4
-
// Represents the orientation of a shape in increments of 90 degrees
enum Orientation: Int, CustomStringConvertible, CaseIterable {
case Zero = 0, Ninety, OneEighty, TwoSeventy
@@ -56,9 +54,6 @@ let FourthBlockIdx: Int = 3
// Base class representing a shape consisting of four blocks. Derived classes represent the different
// tetramino shapes.
class Shape: Hashable, CustomStringConvertible {
- // The color of the shape
- let color: BlockColor
-
// The blocks comprising the shape
var blocks = Array()
// The current orientation of the shape
@@ -68,6 +63,12 @@ class Shape: Hashable, CustomStringConvertible {
// Required overrides
+ // Subclasses must override this property
+ // The color of the shape
+ var color: BlockColor? {
+ return nil
+ }
+
// Subclasses must override this property
// Returns the relative positions of the shape blocks based on the shape orientation
var blockRowColumnPositions: [Orientation: Array<(columnDiff: Int, rowDiff: Int)>] {
@@ -102,11 +103,13 @@ class Shape: Hashable, CustomStringConvertible {
// CustomStringConvertible
var description: String {
+ guard let color = color else {
+ return " block facing \(orientation): \(blocks[FirstBlockIdx]), \(blocks[SecondBlockIdx]), \(blocks[ThirdBlockIdx]), \(blocks[FourthBlockIdx])"
+ }
return "\(color) block facing \(orientation): \(blocks[FirstBlockIdx]), \(blocks[SecondBlockIdx]), \(blocks[ThirdBlockIdx]), \(blocks[FourthBlockIdx])"
}
- init(column: Int, row: Int, color: BlockColor, orientation: Orientation) {
- self.color = color
+ init(column: Int, row: Int, orientation: Orientation) {
self.column = column
self.row = row
self.orientation = orientation
@@ -114,7 +117,7 @@ class Shape: Hashable, CustomStringConvertible {
}
convenience init(column: Int, row: Int) {
- self.init(column: column, row: row, color: BlockColor.random(), orientation: Orientation.random())
+ self.init(column: column, row: row, orientation: Orientation.random())
}
// Initialize the blocks of the shape based on the current position, color, and orientation.
@@ -124,7 +127,7 @@ class Shape: Hashable, CustomStringConvertible {
}
blocks = blockRowColumnTranslations.map { (diff) -> Block in
- return Block(column: column + diff.columnDiff, row: row + diff.rowDiff, color: color)
+ return Block(column: column + diff.columnDiff, row: row + diff.rowDiff, color: color!)
}
}
diff --git a/Privyet/SquareShape.swift b/Privyet/SquareShape.swift
index 4fd0e3e..3f6b484 100644
--- a/Privyet/SquareShape.swift
+++ b/Privyet/SquareShape.swift
@@ -16,6 +16,10 @@ class SquareShape: Shape {
*/
// The square shape wll not rotate
+ override var color: BlockColor? {
+ return .Red
+ }
+
override var blockRowColumnPositions: [Orientation : Array<(columnDiff: Int, rowDiff: Int)>] {
return [
Orientation.Zero: [(0, 0), (1, 0), (0, 1), (1, 1)],
diff --git a/Privyet/TShape.swift b/Privyet/TShape.swift
index f319979..73f2102 100644
--- a/Privyet/TShape.swift
+++ b/Privyet/TShape.swift
@@ -31,6 +31,10 @@ class TShape: Shape {
* marks the row/column indicator for the shape
*/
+ override var color: BlockColor? {
+ return .Yellow
+ }
+
override var blockRowColumnPositions: [Orientation : Array<(columnDiff: Int, rowDiff: Int)>] {
return [
Orientation.Zero: [(1, 0), (0, 1), (1, 1), (2, 1)],
diff --git a/Privyet/ZShape.swift b/Privyet/ZShape.swift
index a7740bd..ec729f5 100644
--- a/Privyet/ZShape.swift
+++ b/Privyet/ZShape.swift
@@ -21,6 +21,10 @@ class ZShape: Shape {
* marks the row/column indicator for the shape
*/
+ override var color: BlockColor? {
+ return .Orange
+ }
+
override var blockRowColumnPositions: [Orientation : Array<(columnDiff: Int, rowDiff: Int)>] {
return [
Orientation.Zero: [(1, 0), (1, 1), (0, 1), (0, 2)],